1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3 * GtkToolbar copyright (C) Federico Mena
5 * Copyright (C) 2002 Anders Carlsson <andersca@gnome.org>
6 * Copyright (C) 2002 James Henstridge <james@daa.com.au>
7 * Copyright (C) 2003, 2004 Soeren Sandmann <sandmann@daimi.au.dk>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the
21 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 * Boston, MA 02111-1307, USA.
26 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
27 * file for a list of people on the GTK+ Team. See the ChangeLog
28 * files for a list of changes. These files are distributed with
29 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
32 #undef GTK_DISABLE_DEPRECATED
39 #include <gdk/gdkkeysyms.h>
42 #include "gtkbindings.h"
47 #include "gtkmarshalers.h"
49 #include "gtkorientable.h"
50 #include "gtkradiobutton.h"
51 #include "gtkradiotoolbutton.h"
52 #include "gtkseparatormenuitem.h"
53 #include "gtkseparatortoolitem.h"
55 #include "gtktoolbar.h"
56 #include "gtktoolshell.h"
58 #include "gtkprivate.h"
62 typedef struct _ToolbarContent ToolbarContent;
64 #define DEFAULT_IPADDING 0
66 #define DEFAULT_SPACE_SIZE 12
67 #define DEFAULT_SPACE_STYLE GTK_TOOLBAR_SPACE_LINE
68 #define SPACE_LINE_DIVISION 10.0
69 #define SPACE_LINE_START 2.0
70 #define SPACE_LINE_END 8.0
72 #define DEFAULT_ICON_SIZE GTK_ICON_SIZE_LARGE_TOOLBAR
73 #define DEFAULT_TOOLBAR_STYLE GTK_TOOLBAR_BOTH
74 #define DEFAULT_ANIMATION_STATE TRUE
76 #define MAX_HOMOGENEOUS_N_CHARS 13 /* Items that are wider than this do not participate
77 * in the homogeneous game. In units of
78 * pango_font_get_estimated_char_width().
80 #define SLIDE_SPEED 600.0 /* How fast the items slide, in pixels per second */
81 #define ACCEL_THRESHOLD 0.18 /* After how much time in seconds will items start speeding up */
83 #define MIXED_API_WARNING \
84 "Mixing deprecated and non-deprecated GtkToolbar API is not allowed"
98 /* Child properties */
102 CHILD_PROP_HOMOGENEOUS
133 struct _GtkToolbarPrivate
138 GtkWidget * arrow_button;
141 GdkWindow * event_window;
143 GtkSettings * settings;
145 GtkToolItem * highlight_tool_item;
146 gint max_homogeneous_pixels;
150 gulong settings_connection;
152 guint show_arrow : 1;
154 guint is_sliding : 1;
155 guint need_rebuild : 1; /* whether the overflow menu should be regenerated */
159 static void gtk_toolbar_set_property (GObject *object,
163 static void gtk_toolbar_get_property (GObject *object,
167 static gint gtk_toolbar_expose (GtkWidget *widget,
168 GdkEventExpose *event);
169 static void gtk_toolbar_realize (GtkWidget *widget);
170 static void gtk_toolbar_unrealize (GtkWidget *widget);
171 static void gtk_toolbar_size_request (GtkWidget *widget,
172 GtkRequisition *requisition);
173 static void gtk_toolbar_size_allocate (GtkWidget *widget,
174 GtkAllocation *allocation);
175 static void gtk_toolbar_style_set (GtkWidget *widget,
176 GtkStyle *prev_style);
177 static gboolean gtk_toolbar_focus (GtkWidget *widget,
178 GtkDirectionType dir);
179 static void gtk_toolbar_move_focus (GtkWidget *widget,
180 GtkDirectionType dir);
181 static void gtk_toolbar_screen_changed (GtkWidget *widget,
182 GdkScreen *previous_screen);
183 static void gtk_toolbar_map (GtkWidget *widget);
184 static void gtk_toolbar_unmap (GtkWidget *widget);
185 static void gtk_toolbar_set_child_property (GtkContainer *container,
190 static void gtk_toolbar_get_child_property (GtkContainer *container,
195 static void gtk_toolbar_finalize (GObject *object);
196 static void gtk_toolbar_show_all (GtkWidget *widget);
197 static void gtk_toolbar_hide_all (GtkWidget *widget);
198 static void gtk_toolbar_add (GtkContainer *container,
200 static void gtk_toolbar_remove (GtkContainer *container,
202 static void gtk_toolbar_forall (GtkContainer *container,
203 gboolean include_internals,
204 GtkCallback callback,
205 gpointer callback_data);
206 static GType gtk_toolbar_child_type (GtkContainer *container);
207 static void gtk_toolbar_orientation_changed (GtkToolbar *toolbar,
208 GtkOrientation orientation);
209 static void gtk_toolbar_real_style_changed (GtkToolbar *toolbar,
210 GtkToolbarStyle style);
211 static gboolean gtk_toolbar_focus_home_or_end (GtkToolbar *toolbar,
212 gboolean focus_home);
213 static gboolean gtk_toolbar_button_press (GtkWidget *toolbar,
214 GdkEventButton *event);
215 static gboolean gtk_toolbar_arrow_button_press (GtkWidget *button,
216 GdkEventButton *event,
217 GtkToolbar *toolbar);
218 static void gtk_toolbar_arrow_button_clicked (GtkWidget *button,
219 GtkToolbar *toolbar);
220 static void gtk_toolbar_update_button_relief (GtkToolbar *toolbar);
221 static gboolean gtk_toolbar_popup_menu (GtkWidget *toolbar);
222 static GtkWidget *internal_insert_element (GtkToolbar *toolbar,
223 GtkToolbarChildType type,
226 const char *tooltip_text,
227 const char *tooltip_private_text,
233 static void gtk_toolbar_reconfigured (GtkToolbar *toolbar);
234 static gboolean gtk_toolbar_check_new_api (GtkToolbar *toolbar);
235 static gboolean gtk_toolbar_check_old_api (GtkToolbar *toolbar);
237 static GtkReliefStyle get_button_relief (GtkToolbar *toolbar);
238 static gint get_internal_padding (GtkToolbar *toolbar);
239 static gint get_max_child_expand (GtkToolbar *toolbar);
240 static GtkShadowType get_shadow_type (GtkToolbar *toolbar);
241 static gint get_space_size (GtkToolbar *toolbar);
242 static GtkToolbarSpaceStyle get_space_style (GtkToolbar *toolbar);
244 /* methods on ToolbarContent 'class' */
245 static ToolbarContent *toolbar_content_new_tool_item (GtkToolbar *toolbar,
247 gboolean is_placeholder,
249 static ToolbarContent *toolbar_content_new_compatibility (GtkToolbar *toolbar,
250 GtkToolbarChildType type,
255 static void toolbar_content_remove (ToolbarContent *content,
256 GtkToolbar *toolbar);
257 static void toolbar_content_free (ToolbarContent *content);
258 static void toolbar_content_expose (ToolbarContent *content,
259 GtkContainer *container,
260 GdkEventExpose *expose);
261 static gboolean toolbar_content_visible (ToolbarContent *content,
262 GtkToolbar *toolbar);
263 static void toolbar_content_size_request (ToolbarContent *content,
265 GtkRequisition *requisition);
266 static gboolean toolbar_content_is_homogeneous (ToolbarContent *content,
267 GtkToolbar *toolbar);
268 static gboolean toolbar_content_is_placeholder (ToolbarContent *content);
269 static gboolean toolbar_content_disappearing (ToolbarContent *content);
270 static ItemState toolbar_content_get_state (ToolbarContent *content);
271 static gboolean toolbar_content_child_visible (ToolbarContent *content);
272 static void toolbar_content_get_goal_allocation (ToolbarContent *content,
273 GtkAllocation *allocation);
274 static void toolbar_content_get_allocation (ToolbarContent *content,
275 GtkAllocation *allocation);
276 static void toolbar_content_set_start_allocation (ToolbarContent *content,
277 GtkAllocation *new_start_allocation);
278 static void toolbar_content_get_start_allocation (ToolbarContent *content,
279 GtkAllocation *start_allocation);
280 static gboolean toolbar_content_get_expand (ToolbarContent *content);
281 static void toolbar_content_set_goal_allocation (ToolbarContent *content,
282 GtkAllocation *allocation);
283 static void toolbar_content_set_child_visible (ToolbarContent *content,
286 static void toolbar_content_size_allocate (ToolbarContent *content,
287 GtkAllocation *allocation);
288 static void toolbar_content_set_state (ToolbarContent *content,
289 ItemState new_state);
290 static GtkWidget * toolbar_content_get_widget (ToolbarContent *content);
291 static void toolbar_content_set_disappearing (ToolbarContent *content,
292 gboolean disappearing);
293 static void toolbar_content_set_size_request (ToolbarContent *content,
296 static void toolbar_content_toolbar_reconfigured (ToolbarContent *content,
297 GtkToolbar *toolbar);
298 static GtkWidget * toolbar_content_retrieve_menu_item (ToolbarContent *content);
299 static gboolean toolbar_content_has_proxy_menu_item (ToolbarContent *content);
300 static gboolean toolbar_content_is_separator (ToolbarContent *content);
301 static void toolbar_content_show_all (ToolbarContent *content);
302 static void toolbar_content_hide_all (ToolbarContent *content);
303 static void toolbar_content_set_expand (ToolbarContent *content,
306 static void toolbar_tool_shell_iface_init (GtkToolShellIface *iface);
307 static GtkIconSize toolbar_get_icon_size (GtkToolShell *shell);
308 static GtkOrientation toolbar_get_orientation (GtkToolShell *shell);
309 static GtkToolbarStyle toolbar_get_style (GtkToolShell *shell);
310 static GtkReliefStyle toolbar_get_relief_style (GtkToolShell *shell);
311 static void toolbar_rebuild_menu (GtkToolShell *shell);
313 #define GTK_TOOLBAR_GET_PRIVATE(o) \
314 (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_TOOLBAR, GtkToolbarPrivate))
317 G_DEFINE_TYPE_WITH_CODE (GtkToolbar, gtk_toolbar, GTK_TYPE_CONTAINER,
318 G_IMPLEMENT_INTERFACE (GTK_TYPE_TOOL_SHELL,
319 toolbar_tool_shell_iface_init)
320 G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE,
323 static guint toolbar_signals[LAST_SIGNAL] = { 0 };
327 add_arrow_bindings (GtkBindingSet *binding_set,
329 GtkDirectionType dir)
331 guint keypad_keysym = keysym - GDK_Left + GDK_KP_Left;
333 gtk_binding_entry_add_signal (binding_set, keysym, 0,
335 GTK_TYPE_DIRECTION_TYPE, dir);
336 gtk_binding_entry_add_signal (binding_set, keypad_keysym, 0,
338 GTK_TYPE_DIRECTION_TYPE, dir);
342 add_ctrl_tab_bindings (GtkBindingSet *binding_set,
343 GdkModifierType modifiers,
344 GtkDirectionType direction)
346 gtk_binding_entry_add_signal (binding_set,
347 GDK_Tab, GDK_CONTROL_MASK | modifiers,
349 GTK_TYPE_DIRECTION_TYPE, direction);
350 gtk_binding_entry_add_signal (binding_set,
351 GDK_KP_Tab, GDK_CONTROL_MASK | modifiers,
353 GTK_TYPE_DIRECTION_TYPE, direction);
357 gtk_toolbar_class_init (GtkToolbarClass *klass)
359 GObjectClass *gobject_class;
360 GtkWidgetClass *widget_class;
361 GtkContainerClass *container_class;
362 GtkBindingSet *binding_set;
364 gobject_class = (GObjectClass *)klass;
365 widget_class = (GtkWidgetClass *)klass;
366 container_class = (GtkContainerClass *)klass;
368 gobject_class->set_property = gtk_toolbar_set_property;
369 gobject_class->get_property = gtk_toolbar_get_property;
370 gobject_class->finalize = gtk_toolbar_finalize;
372 widget_class->button_press_event = gtk_toolbar_button_press;
373 widget_class->expose_event = gtk_toolbar_expose;
374 widget_class->size_request = gtk_toolbar_size_request;
375 widget_class->size_allocate = gtk_toolbar_size_allocate;
376 widget_class->style_set = gtk_toolbar_style_set;
377 widget_class->focus = gtk_toolbar_focus;
379 /* need to override the base class function via override_class_handler,
380 * because the signal slot is not available in GtkWidgetClass
382 g_signal_override_class_handler ("move-focus",
384 G_CALLBACK (gtk_toolbar_move_focus));
386 widget_class->screen_changed = gtk_toolbar_screen_changed;
387 widget_class->realize = gtk_toolbar_realize;
388 widget_class->unrealize = gtk_toolbar_unrealize;
389 widget_class->map = gtk_toolbar_map;
390 widget_class->unmap = gtk_toolbar_unmap;
391 widget_class->popup_menu = gtk_toolbar_popup_menu;
392 widget_class->show_all = gtk_toolbar_show_all;
393 widget_class->hide_all = gtk_toolbar_hide_all;
395 container_class->add = gtk_toolbar_add;
396 container_class->remove = gtk_toolbar_remove;
397 container_class->forall = gtk_toolbar_forall;
398 container_class->child_type = gtk_toolbar_child_type;
399 container_class->get_child_property = gtk_toolbar_get_child_property;
400 container_class->set_child_property = gtk_toolbar_set_child_property;
402 klass->orientation_changed = gtk_toolbar_orientation_changed;
403 klass->style_changed = gtk_toolbar_real_style_changed;
406 * GtkToolbar::orientation-changed:
407 * @toolbar: the object which emitted the signal
408 * @orientation: the new #GtkOrientation of the toolbar
410 * Emitted when the orientation of the toolbar changes.
412 toolbar_signals[ORIENTATION_CHANGED] =
413 g_signal_new (I_("orientation-changed"),
414 G_OBJECT_CLASS_TYPE (klass),
416 G_STRUCT_OFFSET (GtkToolbarClass, orientation_changed),
418 g_cclosure_marshal_VOID__ENUM,
420 GTK_TYPE_ORIENTATION);
422 * GtkToolbar::style-changed:
423 * @toolbar: The #GtkToolbar which emitted the signal
424 * @style: the new #GtkToolbarStyle of the toolbar
426 * Emitted when the style of the toolbar changes.
428 toolbar_signals[STYLE_CHANGED] =
429 g_signal_new (I_("style-changed"),
430 G_OBJECT_CLASS_TYPE (klass),
432 G_STRUCT_OFFSET (GtkToolbarClass, style_changed),
434 g_cclosure_marshal_VOID__ENUM,
436 GTK_TYPE_TOOLBAR_STYLE);
438 * GtkToolbar::popup-context-menu:
439 * @toolbar: the #GtkToolbar which emitted the signal
440 * @x: the x coordinate of the point where the menu should appear
441 * @y: the y coordinate of the point where the menu should appear
442 * @button: the mouse button the user pressed, or -1
444 * Emitted when the user right-clicks the toolbar or uses the
445 * keybinding to display a popup menu.
447 * Application developers should handle this signal if they want
448 * to display a context menu on the toolbar. The context-menu should
449 * appear at the coordinates given by @x and @y. The mouse button
450 * number is given by the @button parameter. If the menu was popped
451 * up using the keybaord, @button is -1.
453 * Return value: return %TRUE if the signal was handled, %FALSE if not
455 toolbar_signals[POPUP_CONTEXT_MENU] =
456 g_signal_new (I_("popup-context-menu"),
457 G_OBJECT_CLASS_TYPE (klass),
459 G_STRUCT_OFFSET (GtkToolbarClass, popup_context_menu),
460 _gtk_boolean_handled_accumulator, NULL,
461 _gtk_marshal_BOOLEAN__INT_INT_INT,
463 G_TYPE_INT, G_TYPE_INT,
467 * GtkToolbar::focus-home-or-end:
468 * @toolbar: the #GtkToolbar which emitted the signal
469 * @focus_home: %TRUE if the first item should be focused
471 * A keybinding signal used internally by GTK+. This signal can't
472 * be used in application code
474 * Return value: %TRUE if the signal was handled, %FALSE if not
476 toolbar_signals[FOCUS_HOME_OR_END] =
477 g_signal_new_class_handler (I_("focus-home-or-end"),
478 G_OBJECT_CLASS_TYPE (klass),
479 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
480 G_CALLBACK (gtk_toolbar_focus_home_or_end),
482 _gtk_marshal_BOOLEAN__BOOLEAN,
487 g_object_class_override_property (gobject_class,
491 g_object_class_install_property (gobject_class,
493 g_param_spec_enum ("toolbar-style",
495 P_("How to draw the toolbar"),
496 GTK_TYPE_TOOLBAR_STYLE,
497 DEFAULT_TOOLBAR_STYLE,
498 GTK_PARAM_READWRITE));
499 g_object_class_install_property (gobject_class,
501 g_param_spec_boolean ("show-arrow",
503 P_("If an arrow should be shown if the toolbar doesn't fit"),
505 GTK_PARAM_READWRITE));
509 * GtkToolbar:tooltips:
511 * If the tooltips of the toolbar should be active or not.
515 g_object_class_install_property (gobject_class,
517 g_param_spec_boolean ("tooltips",
519 P_("If the tooltips of the toolbar should be active or not"),
521 GTK_PARAM_READWRITE));
525 * GtkToolbar:icon-size:
527 * The size of the icons in a toolbar is normally determined by
528 * the toolbar-icon-size setting. When this property is set, it
529 * overrides the setting.
531 * This should only be used for special-purpose toolbars, normal
532 * application toolbars should respect the user preferences for the
537 g_object_class_install_property (gobject_class,
539 g_param_spec_int ("icon-size",
541 P_("Size of icons in this toolbar"),
544 GTK_PARAM_READWRITE));
547 * GtkToolbar:icon-size-set:
549 * Is %TRUE if the icon-size property has been set.
553 g_object_class_install_property (gobject_class,
555 g_param_spec_boolean ("icon-size-set",
557 P_("Whether the icon-size property has been set"),
559 GTK_PARAM_READWRITE));
561 /* child properties */
562 gtk_container_class_install_child_property (container_class,
564 g_param_spec_boolean ("expand",
566 P_("Whether the item should receive extra space when the toolbar grows"),
568 GTK_PARAM_READWRITE));
570 gtk_container_class_install_child_property (container_class,
571 CHILD_PROP_HOMOGENEOUS,
572 g_param_spec_boolean ("homogeneous",
574 P_("Whether the item should be the same size as other homogeneous items"),
576 GTK_PARAM_READWRITE));
578 /* style properties */
579 gtk_widget_class_install_style_property (widget_class,
580 g_param_spec_int ("space-size",
582 P_("Size of spacers"),
586 GTK_PARAM_READABLE));
588 gtk_widget_class_install_style_property (widget_class,
589 g_param_spec_int ("internal-padding",
590 P_("Internal padding"),
591 P_("Amount of border space between the toolbar shadow and the buttons"),
595 GTK_PARAM_READABLE));
597 gtk_widget_class_install_style_property (widget_class,
598 g_param_spec_int ("max-child-expand",
599 P_("Maximum child expand"),
600 P_("Maximum amount of space an expandable item will be given"),
604 GTK_PARAM_READABLE));
606 gtk_widget_class_install_style_property (widget_class,
607 g_param_spec_enum ("space-style",
609 P_("Whether spacers are vertical lines or just blank"),
610 GTK_TYPE_TOOLBAR_SPACE_STYLE,
612 GTK_PARAM_READABLE));
614 gtk_widget_class_install_style_property (widget_class,
615 g_param_spec_enum ("button-relief",
617 P_("Type of bevel around toolbar buttons"),
618 GTK_TYPE_RELIEF_STYLE,
620 GTK_PARAM_READABLE));
621 gtk_widget_class_install_style_property (widget_class,
622 g_param_spec_enum ("shadow-type",
624 P_("Style of bevel around the toolbar"),
625 GTK_TYPE_SHADOW_TYPE,
627 GTK_PARAM_READABLE));
629 binding_set = gtk_binding_set_by_class (klass);
631 add_arrow_bindings (binding_set, GDK_Left, GTK_DIR_LEFT);
632 add_arrow_bindings (binding_set, GDK_Right, GTK_DIR_RIGHT);
633 add_arrow_bindings (binding_set, GDK_Up, GTK_DIR_UP);
634 add_arrow_bindings (binding_set, GDK_Down, GTK_DIR_DOWN);
636 gtk_binding_entry_add_signal (binding_set, GDK_KP_Home, 0,
637 "focus-home-or-end", 1,
638 G_TYPE_BOOLEAN, TRUE);
639 gtk_binding_entry_add_signal (binding_set, GDK_Home, 0,
640 "focus-home-or-end", 1,
641 G_TYPE_BOOLEAN, TRUE);
642 gtk_binding_entry_add_signal (binding_set, GDK_KP_End, 0,
643 "focus-home-or-end", 1,
644 G_TYPE_BOOLEAN, FALSE);
645 gtk_binding_entry_add_signal (binding_set, GDK_End, 0,
646 "focus-home-or-end", 1,
647 G_TYPE_BOOLEAN, FALSE);
649 add_ctrl_tab_bindings (binding_set, 0, GTK_DIR_TAB_FORWARD);
650 add_ctrl_tab_bindings (binding_set, GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
652 g_type_class_add_private (gobject_class, sizeof (GtkToolbarPrivate));
656 toolbar_tool_shell_iface_init (GtkToolShellIface *iface)
658 iface->get_icon_size = toolbar_get_icon_size;
659 iface->get_orientation = toolbar_get_orientation;
660 iface->get_style = toolbar_get_style;
661 iface->get_relief_style = toolbar_get_relief_style;
662 iface->rebuild_menu = toolbar_rebuild_menu;
666 gtk_toolbar_init (GtkToolbar *toolbar)
668 GtkToolbarPrivate *priv;
670 GTK_WIDGET_UNSET_FLAGS (toolbar, GTK_CAN_FOCUS);
671 GTK_WIDGET_SET_FLAGS (toolbar, GTK_NO_WINDOW);
673 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
675 toolbar->orientation = GTK_ORIENTATION_HORIZONTAL;
676 toolbar->style = DEFAULT_TOOLBAR_STYLE;
677 toolbar->icon_size = DEFAULT_ICON_SIZE;
678 priv->animation = DEFAULT_ANIMATION_STATE;
679 toolbar->tooltips = gtk_tooltips_new ();
680 g_object_ref_sink (toolbar->tooltips);
682 priv->arrow_button = gtk_toggle_button_new ();
683 g_signal_connect (priv->arrow_button, "button-press-event",
684 G_CALLBACK (gtk_toolbar_arrow_button_press), toolbar);
685 g_signal_connect (priv->arrow_button, "clicked",
686 G_CALLBACK (gtk_toolbar_arrow_button_clicked), toolbar);
687 gtk_button_set_relief (GTK_BUTTON (priv->arrow_button),
688 get_button_relief (toolbar));
690 priv->api_mode = DONT_KNOW;
692 gtk_button_set_focus_on_click (GTK_BUTTON (priv->arrow_button), FALSE);
694 priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
695 gtk_widget_set_name (priv->arrow, "gtk-toolbar-arrow");
696 gtk_widget_show (priv->arrow);
697 gtk_container_add (GTK_CONTAINER (priv->arrow_button), priv->arrow);
699 gtk_widget_set_parent (priv->arrow_button, GTK_WIDGET (toolbar));
701 /* which child position a drop will occur at */
703 priv->show_arrow = TRUE;
704 priv->settings = NULL;
706 priv->max_homogeneous_pixels = -1;
708 priv->timer = g_timer_new ();
712 gtk_toolbar_set_property (GObject *object,
717 GtkToolbar *toolbar = GTK_TOOLBAR (object);
721 case PROP_ORIENTATION:
722 g_signal_emit (toolbar, toolbar_signals[ORIENTATION_CHANGED], 0,
723 g_value_get_enum (value));
725 case PROP_TOOLBAR_STYLE:
726 gtk_toolbar_set_style (toolbar, g_value_get_enum (value));
728 case PROP_SHOW_ARROW:
729 gtk_toolbar_set_show_arrow (toolbar, g_value_get_boolean (value));
732 gtk_toolbar_set_tooltips (toolbar, g_value_get_boolean (value));
735 gtk_toolbar_set_icon_size (toolbar, g_value_get_int (value));
737 case PROP_ICON_SIZE_SET:
738 if (g_value_get_boolean (value))
739 toolbar->icon_size_set = TRUE;
741 gtk_toolbar_unset_icon_size (toolbar);
744 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
750 gtk_toolbar_get_property (GObject *object,
755 GtkToolbar *toolbar = GTK_TOOLBAR (object);
756 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
760 case PROP_ORIENTATION:
761 g_value_set_enum (value, toolbar->orientation);
763 case PROP_TOOLBAR_STYLE:
764 g_value_set_enum (value, toolbar->style);
766 case PROP_SHOW_ARROW:
767 g_value_set_boolean (value, priv->show_arrow);
770 g_value_set_boolean (value, gtk_toolbar_get_tooltips (toolbar));
773 g_value_set_int (value, gtk_toolbar_get_icon_size (toolbar));
775 case PROP_ICON_SIZE_SET:
776 g_value_set_boolean (value, toolbar->icon_size_set);
779 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
785 gtk_toolbar_map (GtkWidget *widget)
787 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
789 GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->map (widget);
791 if (priv->event_window)
792 gdk_window_show_unraised (priv->event_window);
796 gtk_toolbar_unmap (GtkWidget *widget)
798 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
800 if (priv->event_window)
801 gdk_window_hide (priv->event_window);
803 GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unmap (widget);
807 gtk_toolbar_realize (GtkWidget *widget)
809 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
810 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
812 GdkWindowAttr attributes;
813 gint attributes_mask;
816 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
818 border_width = GTK_CONTAINER (widget)->border_width;
820 attributes.wclass = GDK_INPUT_ONLY;
821 attributes.window_type = GDK_WINDOW_CHILD;
822 attributes.x = widget->allocation.x + border_width;
823 attributes.y = widget->allocation.y + border_width;
824 attributes.width = widget->allocation.width - border_width * 2;
825 attributes.height = widget->allocation.height - border_width * 2;
826 attributes.event_mask = gtk_widget_get_events (widget);
827 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
828 GDK_BUTTON_RELEASE_MASK |
829 GDK_ENTER_NOTIFY_MASK |
830 GDK_LEAVE_NOTIFY_MASK);
832 attributes_mask = GDK_WA_X | GDK_WA_Y;
834 widget->window = gtk_widget_get_parent_window (widget);
835 g_object_ref (widget->window);
836 widget->style = gtk_style_attach (widget->style, widget->window);
838 priv->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
839 &attributes, attributes_mask);
840 gdk_window_set_user_data (priv->event_window, toolbar);
844 gtk_toolbar_unrealize (GtkWidget *widget)
846 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
848 if (priv->event_window)
850 gdk_window_set_user_data (priv->event_window, NULL);
851 gdk_window_destroy (priv->event_window);
852 priv->event_window = NULL;
855 GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unrealize (widget);
859 gtk_toolbar_expose (GtkWidget *widget,
860 GdkEventExpose *event)
862 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
863 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
868 border_width = GTK_CONTAINER (widget)->border_width;
870 if (GTK_WIDGET_DRAWABLE (widget))
872 gtk_paint_box (widget->style,
874 GTK_WIDGET_STATE (widget),
875 get_shadow_type (toolbar),
876 &event->area, widget, "toolbar",
877 border_width + widget->allocation.x,
878 border_width + widget->allocation.y,
879 widget->allocation.width - 2 * border_width,
880 widget->allocation.height - 2 * border_width);
883 for (list = priv->content; list != NULL; list = list->next)
885 ToolbarContent *content = list->data;
887 toolbar_content_expose (content, GTK_CONTAINER (widget), event);
890 gtk_container_propagate_expose (GTK_CONTAINER (widget),
898 gtk_toolbar_size_request (GtkWidget *widget,
899 GtkRequisition *requisition)
901 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
902 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
904 gint max_child_height;
905 gint max_child_width;
906 gint max_homogeneous_child_width;
907 gint max_homogeneous_child_height;
908 gint homogeneous_size;
910 gint pack_front_size;
912 GtkRequisition arrow_requisition;
914 max_homogeneous_child_width = 0;
915 max_homogeneous_child_height = 0;
917 max_child_height = 0;
918 for (list = priv->content; list != NULL; list = list->next)
920 GtkRequisition requisition;
921 ToolbarContent *content = list->data;
923 if (!toolbar_content_visible (content, toolbar))
926 toolbar_content_size_request (content, toolbar, &requisition);
928 max_child_width = MAX (max_child_width, requisition.width);
929 max_child_height = MAX (max_child_height, requisition.height);
931 if (toolbar_content_is_homogeneous (content, toolbar))
933 max_homogeneous_child_width = MAX (max_homogeneous_child_width, requisition.width);
934 max_homogeneous_child_height = MAX (max_homogeneous_child_height, requisition.height);
938 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
939 homogeneous_size = max_homogeneous_child_width;
941 homogeneous_size = max_homogeneous_child_height;
944 for (list = priv->content; list != NULL; list = list->next)
946 ToolbarContent *content = list->data;
949 if (!toolbar_content_visible (content, toolbar))
952 if (toolbar_content_is_homogeneous (content, toolbar))
954 size = homogeneous_size;
958 GtkRequisition requisition;
960 toolbar_content_size_request (content, toolbar, &requisition);
962 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
963 size = requisition.width;
965 size = requisition.height;
968 pack_front_size += size;
971 if (priv->show_arrow && priv->api_mode == NEW_API)
973 gtk_widget_size_request (priv->arrow_button, &arrow_requisition);
975 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
976 long_req = arrow_requisition.width;
978 long_req = arrow_requisition.height;
980 /* There is no point requesting space for the arrow if that would take
981 * up more space than all the items combined
983 long_req = MIN (long_req, pack_front_size);
987 arrow_requisition.height = 0;
988 arrow_requisition.width = 0;
990 long_req = pack_front_size;
993 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
995 requisition->width = long_req;
996 requisition->height = MAX (max_child_height, arrow_requisition.height);
1000 requisition->height = long_req;
1001 requisition->width = MAX (max_child_width, arrow_requisition.width);
1005 ipadding = get_internal_padding (toolbar);
1007 requisition->width += 2 * (ipadding + GTK_CONTAINER (toolbar)->border_width);
1008 requisition->height += 2 * (ipadding + GTK_CONTAINER (toolbar)->border_width);
1010 if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
1012 requisition->width += 2 * widget->style->xthickness;
1013 requisition->height += 2 * widget->style->ythickness;
1016 toolbar->button_maxw = max_homogeneous_child_width;
1017 toolbar->button_maxh = max_homogeneous_child_height;
1021 position (GtkToolbar *toolbar,
1028 if (! GTK_TOOLBAR_GET_PRIVATE (toolbar)->animation)
1031 if (elapsed <= ACCEL_THRESHOLD)
1033 n_pixels = SLIDE_SPEED * elapsed;
1037 /* The formula is a second degree polynomial in
1038 * @elapsed that has the line SLIDE_SPEED * @elapsed
1039 * as tangent for @elapsed == ACCEL_THRESHOLD.
1040 * This makes @n_pixels a smooth function of elapsed time.
1042 n_pixels = (SLIDE_SPEED / ACCEL_THRESHOLD) * elapsed * elapsed -
1043 SLIDE_SPEED * elapsed + SLIDE_SPEED * ACCEL_THRESHOLD;
1047 return MIN (from + n_pixels, to);
1049 return MAX (from - n_pixels, to);
1053 compute_intermediate_allocation (GtkToolbar *toolbar,
1054 const GtkAllocation *start,
1055 const GtkAllocation *goal,
1056 GtkAllocation *intermediate)
1058 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1059 gdouble elapsed = g_timer_elapsed (priv->timer, NULL);
1061 intermediate->x = position (toolbar, start->x, goal->x, elapsed);
1062 intermediate->y = position (toolbar, start->y, goal->y, elapsed);
1063 intermediate->width = position (toolbar, start->x + start->width,
1064 goal->x + goal->width,
1065 elapsed) - intermediate->x;
1066 intermediate->height = position (toolbar, start->y + start->height,
1067 goal->y + goal->height,
1068 elapsed) - intermediate->y;
1072 fixup_allocation_for_rtl (gint total_size,
1073 GtkAllocation *allocation)
1075 allocation->x += (total_size - (2 * allocation->x + allocation->width));
1079 fixup_allocation_for_vertical (GtkAllocation *allocation)
1083 tmp = allocation->x;
1084 allocation->x = allocation->y;
1085 allocation->y = tmp;
1087 tmp = allocation->width;
1088 allocation->width = allocation->height;
1089 allocation->height = tmp;
1093 get_item_size (GtkToolbar *toolbar,
1094 ToolbarContent *content)
1096 GtkRequisition requisition;
1098 toolbar_content_size_request (content, toolbar, &requisition);
1100 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
1102 if (toolbar_content_is_homogeneous (content, toolbar))
1103 return toolbar->button_maxw;
1105 return requisition.width;
1109 if (toolbar_content_is_homogeneous (content, toolbar))
1110 return toolbar->button_maxh;
1112 return requisition.height;
1117 slide_idle_handler (gpointer data)
1119 GtkToolbar *toolbar = data;
1120 GtkToolbarPrivate *priv;
1123 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1125 if (priv->need_sync)
1128 priv->need_sync = FALSE;
1131 for (list = priv->content; list != NULL; list = list->next)
1133 ToolbarContent *content = list->data;
1135 GtkAllocation goal_allocation;
1136 GtkAllocation allocation;
1139 state = toolbar_content_get_state (content);
1140 toolbar_content_get_goal_allocation (content, &goal_allocation);
1141 toolbar_content_get_allocation (content, &allocation);
1145 if (state == NOT_ALLOCATED)
1147 /* an unallocated item means that size allocate has to
1148 * called at least once more
1153 /* An invisible item with a goal allocation of
1154 * 0 is already at its goal.
1156 if ((state == NORMAL || state == OVERFLOWN) &&
1157 ((goal_allocation.width != 0 &&
1158 goal_allocation.height != 0) ||
1159 toolbar_content_child_visible (content)))
1161 if ((goal_allocation.x != allocation.x ||
1162 goal_allocation.y != allocation.y ||
1163 goal_allocation.width != allocation.width ||
1164 goal_allocation.height != allocation.height))
1166 /* An item is not in its right position yet. Note
1167 * that OVERFLOWN items do get an allocation in
1168 * gtk_toolbar_size_allocate(). This way you can see
1169 * them slide back in when you drag an item off the
1176 if (toolbar_content_is_placeholder (content) &&
1177 toolbar_content_disappearing (content) &&
1178 toolbar_content_child_visible (content))
1180 /* A disappearing placeholder is still visible.
1188 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1194 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1196 priv->is_sliding = FALSE;
1203 rect_within (GtkAllocation *a1,
1206 return (a1->x >= a2->x &&
1207 a1->x + a1->width <= a2->x + a2->width &&
1209 a1->y + a1->height <= a2->y + a2->height);
1213 gtk_toolbar_begin_sliding (GtkToolbar *toolbar)
1215 GtkWidget *widget = GTK_WIDGET (toolbar);
1216 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1224 /* Start the sliding. This function copies the allocation of every
1225 * item into content->start_allocation. For items that haven't
1226 * been allocated yet, we calculate their position and save that
1227 * in start_allocatino along with zero width and zero height.
1229 * FIXME: It would be nice if we could share this code with
1230 * the equivalent in gtk_widget_size_allocate().
1232 priv->is_sliding = TRUE;
1235 priv->idle_id = gdk_threads_add_idle (slide_idle_handler, toolbar);
1237 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1238 vertical = (toolbar->orientation == GTK_ORIENTATION_VERTICAL);
1239 border_width = get_internal_padding (toolbar) + GTK_CONTAINER (toolbar)->border_width;
1243 cur_x = widget->allocation.width - border_width - widget->style->xthickness;
1244 cur_y = widget->allocation.height - border_width - widget->style->ythickness;
1248 cur_x = border_width + widget->style->xthickness;
1249 cur_y = border_width + widget->style->ythickness;
1252 cur_x += widget->allocation.x;
1253 cur_y += widget->allocation.y;
1255 for (list = priv->content; list != NULL; list = list->next)
1257 ToolbarContent *content = list->data;
1258 GtkAllocation new_start_allocation;
1259 GtkAllocation item_allocation;
1262 state = toolbar_content_get_state (content);
1263 toolbar_content_get_allocation (content, &item_allocation);
1265 if ((state == NORMAL &&
1266 rect_within (&item_allocation, &(widget->allocation))) ||
1269 new_start_allocation = item_allocation;
1273 new_start_allocation.x = cur_x;
1274 new_start_allocation.y = cur_y;
1278 new_start_allocation.width = widget->allocation.width -
1279 2 * border_width - 2 * widget->style->xthickness;
1280 new_start_allocation.height = 0;
1284 new_start_allocation.width = 0;
1285 new_start_allocation.height = widget->allocation.height -
1286 2 * border_width - 2 * widget->style->ythickness;
1291 cur_y = new_start_allocation.y + new_start_allocation.height;
1293 cur_x = new_start_allocation.x;
1295 cur_x = new_start_allocation.x + new_start_allocation.width;
1297 toolbar_content_set_start_allocation (content, &new_start_allocation);
1300 /* This resize will run before the first idle handler. This
1301 * will make sure that items get the right goal allocation
1302 * so that the idle handler will not immediately return
1305 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1306 g_timer_reset (priv->timer);
1310 gtk_toolbar_stop_sliding (GtkToolbar *toolbar)
1312 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1314 if (priv->is_sliding)
1318 priv->is_sliding = FALSE;
1322 g_source_remove (priv->idle_id);
1326 list = priv->content;
1329 ToolbarContent *content = list->data;
1332 if (toolbar_content_is_placeholder (content))
1334 toolbar_content_remove (content, toolbar);
1335 toolbar_content_free (content);
1339 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1344 remove_item (GtkWidget *menu_item,
1347 gtk_container_remove (GTK_CONTAINER (menu_item->parent), menu_item);
1351 menu_deactivated (GtkWidget *menu,
1352 GtkToolbar *toolbar)
1354 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1355 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->arrow_button), FALSE);
1359 menu_detached (GtkWidget *toolbar,
1362 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1367 rebuild_menu (GtkToolbar *toolbar)
1369 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1370 GList *list, *children;
1374 priv->menu = GTK_MENU (gtk_menu_new());
1375 gtk_menu_attach_to_widget (priv->menu,
1376 GTK_WIDGET (toolbar),
1379 g_signal_connect (priv->menu, "deactivate",
1380 G_CALLBACK (menu_deactivated), toolbar);
1383 gtk_container_foreach (GTK_CONTAINER (priv->menu), remove_item, NULL);
1385 for (list = priv->content; list != NULL; list = list->next)
1387 ToolbarContent *content = list->data;
1389 if (toolbar_content_get_state (content) == OVERFLOWN &&
1390 !toolbar_content_is_placeholder (content))
1392 GtkWidget *menu_item = toolbar_content_retrieve_menu_item (content);
1396 g_assert (GTK_IS_MENU_ITEM (menu_item));
1397 gtk_menu_shell_append (GTK_MENU_SHELL (priv->menu), menu_item);
1402 /* Remove leading and trailing separator items */
1403 children = gtk_container_get_children (GTK_CONTAINER (priv->menu));
1406 while (list && GTK_IS_SEPARATOR_MENU_ITEM (list->data))
1408 GtkWidget *child = list->data;
1410 gtk_container_remove (GTK_CONTAINER (priv->menu), child);
1413 g_list_free (children);
1415 /* Regenerate the list of children so we don't try to remove items twice */
1416 children = gtk_container_get_children (GTK_CONTAINER (priv->menu));
1418 list = g_list_last (children);
1419 while (list && GTK_IS_SEPARATOR_MENU_ITEM (list->data))
1421 GtkWidget *child = list->data;
1423 gtk_container_remove (GTK_CONTAINER (priv->menu), child);
1426 g_list_free (children);
1428 priv->need_rebuild = FALSE;
1432 gtk_toolbar_size_allocate (GtkWidget *widget,
1433 GtkAllocation *allocation)
1435 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1436 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1437 GtkAllocation *allocations;
1438 ItemState *new_states;
1439 GtkAllocation arrow_allocation;
1441 gint size, pos, short_size;
1444 gboolean need_arrow;
1445 gint n_expand_items;
1447 gint available_size;
1450 GtkRequisition arrow_requisition;
1451 gboolean overflowing;
1452 gboolean size_changed;
1454 GtkAllocation item_area;
1455 GtkShadowType shadow_type;
1457 size_changed = FALSE;
1458 if (widget->allocation.x != allocation->x ||
1459 widget->allocation.y != allocation->y ||
1460 widget->allocation.width != allocation->width ||
1461 widget->allocation.height != allocation->height)
1463 size_changed = TRUE;
1467 gtk_toolbar_stop_sliding (toolbar);
1469 widget->allocation = *allocation;
1471 border_width = GTK_CONTAINER (toolbar)->border_width;
1473 if (GTK_WIDGET_REALIZED (widget))
1475 gdk_window_move_resize (priv->event_window,
1476 allocation->x + border_width,
1477 allocation->y + border_width,
1478 allocation->width - border_width * 2,
1479 allocation->height - border_width * 2);
1482 border_width += get_internal_padding (toolbar);
1484 gtk_widget_get_child_requisition (GTK_WIDGET (priv->arrow_button),
1485 &arrow_requisition);
1487 shadow_type = get_shadow_type (toolbar);
1489 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
1491 available_size = size = allocation->width - 2 * border_width;
1492 short_size = allocation->height - 2 * border_width;
1493 arrow_size = arrow_requisition.width;
1495 if (shadow_type != GTK_SHADOW_NONE)
1497 available_size -= 2 * widget->style->xthickness;
1498 short_size -= 2 * widget->style->ythickness;
1503 available_size = size = allocation->height - 2 * border_width;
1504 short_size = allocation->width - 2 * border_width;
1505 arrow_size = arrow_requisition.height;
1507 if (shadow_type != GTK_SHADOW_NONE)
1509 available_size -= 2 * widget->style->ythickness;
1510 short_size -= 2 * widget->style->xthickness;
1514 n_items = g_list_length (priv->content);
1515 allocations = g_new0 (GtkAllocation, n_items);
1516 new_states = g_new0 (ItemState, n_items);
1520 for (list = priv->content; list != NULL; list = list->next)
1522 ToolbarContent *content = list->data;
1524 if (toolbar_content_visible (content, toolbar))
1526 needed_size += get_item_size (toolbar, content);
1528 /* Do we need an arrow?
1530 * Assume we don't, and see if any non-separator item with a
1531 * proxy menu item is then going to overflow.
1533 if (needed_size > available_size &&
1536 priv->api_mode == NEW_API &&
1537 toolbar_content_has_proxy_menu_item (content) &&
1538 !toolbar_content_is_separator (content))
1546 size = available_size - arrow_size;
1548 size = available_size;
1550 /* calculate widths and states of items */
1551 overflowing = FALSE;
1552 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1554 ToolbarContent *content = list->data;
1557 if (!toolbar_content_visible (content, toolbar))
1559 new_states[i] = HIDDEN;
1563 item_size = get_item_size (toolbar, content);
1564 if (item_size <= size && !overflowing)
1567 allocations[i].width = item_size;
1568 new_states[i] = NORMAL;
1573 new_states[i] = OVERFLOWN;
1574 allocations[i].width = item_size;
1578 /* calculate width of arrow */
1581 arrow_allocation.width = arrow_size;
1582 arrow_allocation.height = MAX (short_size, 1);
1585 /* expand expandable items */
1587 /* We don't expand when there is an overflow menu, because that leads to
1588 * weird jumps when items get moved to the overflow menu and the expanding
1589 * items suddenly get a lot of extra space
1593 gint max_child_expand;
1596 for (i = 0, list = priv->content; list != NULL; list = list->next, ++i)
1598 ToolbarContent *content = list->data;
1600 if (toolbar_content_get_expand (content) && new_states[i] == NORMAL)
1604 max_child_expand = get_max_child_expand (toolbar);
1605 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1607 ToolbarContent *content = list->data;
1609 if (toolbar_content_get_expand (content) && new_states[i] == NORMAL)
1611 gint extra = size / n_expand_items;
1612 if (size % n_expand_items != 0)
1615 if (extra > max_child_expand)
1616 extra = max_child_expand;
1618 allocations[i].width += extra;
1624 g_assert (n_expand_items == 0);
1627 /* position items */
1629 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1631 /* both NORMAL and OVERFLOWN items get a position. This ensures
1632 * that sliding will work for OVERFLOWN items too
1634 if (new_states[i] == NORMAL ||
1635 new_states[i] == OVERFLOWN)
1637 allocations[i].x = pos;
1638 allocations[i].y = border_width;
1639 allocations[i].height = short_size;
1641 pos += allocations[i].width;
1645 /* position arrow */
1648 arrow_allocation.x = available_size - border_width - arrow_allocation.width;
1649 arrow_allocation.y = border_width;
1652 item_area.x = border_width;
1653 item_area.y = border_width;
1654 item_area.width = available_size - (need_arrow? arrow_size : 0);
1655 item_area.height = short_size;
1657 /* fix up allocations in the vertical or RTL cases */
1658 if (toolbar->orientation == GTK_ORIENTATION_VERTICAL)
1660 for (i = 0; i < n_items; ++i)
1661 fixup_allocation_for_vertical (&(allocations[i]));
1664 fixup_allocation_for_vertical (&arrow_allocation);
1666 fixup_allocation_for_vertical (&item_area);
1668 else if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL)
1670 for (i = 0; i < n_items; ++i)
1671 fixup_allocation_for_rtl (available_size, &(allocations[i]));
1674 fixup_allocation_for_rtl (available_size, &arrow_allocation);
1676 fixup_allocation_for_rtl (available_size, &item_area);
1679 /* translate the items by allocation->(x,y) */
1680 for (i = 0; i < n_items; ++i)
1682 allocations[i].x += allocation->x;
1683 allocations[i].y += allocation->y;
1685 if (shadow_type != GTK_SHADOW_NONE)
1687 allocations[i].x += widget->style->xthickness;
1688 allocations[i].y += widget->style->ythickness;
1694 arrow_allocation.x += allocation->x;
1695 arrow_allocation.y += allocation->y;
1697 if (shadow_type != GTK_SHADOW_NONE)
1699 arrow_allocation.x += widget->style->xthickness;
1700 arrow_allocation.y += widget->style->ythickness;
1704 item_area.x += allocation->x;
1705 item_area.y += allocation->y;
1706 if (shadow_type != GTK_SHADOW_NONE)
1708 item_area.x += widget->style->xthickness;
1709 item_area.y += widget->style->ythickness;
1712 /* did anything change? */
1713 for (list = priv->content, i = 0; list != NULL; list = list->next, i++)
1715 ToolbarContent *content = list->data;
1717 if (toolbar_content_get_state (content) == NORMAL &&
1718 new_states[i] != NORMAL)
1720 /* an item disappeared and we didn't change size, so begin sliding */
1721 if (!size_changed && priv->api_mode == NEW_API)
1722 gtk_toolbar_begin_sliding (toolbar);
1726 /* finally allocate the items */
1727 if (priv->is_sliding)
1729 for (list = priv->content, i = 0; list != NULL; list = list->next, i++)
1731 ToolbarContent *content = list->data;
1733 toolbar_content_set_goal_allocation (content, &(allocations[i]));
1737 elapsed = g_timer_elapsed (priv->timer, NULL);
1738 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1740 ToolbarContent *content = list->data;
1742 if (new_states[i] == OVERFLOWN ||
1743 new_states[i] == NORMAL)
1745 GtkAllocation alloc;
1746 GtkAllocation start_allocation = { 0, };
1747 GtkAllocation goal_allocation;
1749 if (priv->is_sliding)
1751 toolbar_content_get_start_allocation (content, &start_allocation);
1752 toolbar_content_get_goal_allocation (content, &goal_allocation);
1754 compute_intermediate_allocation (toolbar,
1759 priv->need_sync = TRUE;
1763 alloc = allocations[i];
1766 if (alloc.width <= 0 || alloc.height <= 0)
1768 toolbar_content_set_child_visible (content, toolbar, FALSE);
1772 if (!rect_within (&alloc, &item_area))
1774 toolbar_content_set_child_visible (content, toolbar, FALSE);
1775 toolbar_content_size_allocate (content, &alloc);
1779 toolbar_content_set_child_visible (content, toolbar, TRUE);
1780 toolbar_content_size_allocate (content, &alloc);
1786 toolbar_content_set_child_visible (content, toolbar, FALSE);
1789 toolbar_content_set_state (content, new_states[i]);
1792 if (priv->menu && priv->need_rebuild)
1793 rebuild_menu (toolbar);
1797 gtk_widget_size_allocate (GTK_WIDGET (priv->arrow_button),
1799 gtk_widget_show (GTK_WIDGET (priv->arrow_button));
1803 gtk_widget_hide (GTK_WIDGET (priv->arrow_button));
1805 if (priv->menu && GTK_WIDGET_VISIBLE (priv->menu))
1806 gtk_menu_shell_deactivate (GTK_MENU_SHELL (priv->menu));
1809 g_free (allocations);
1810 g_free (new_states);
1814 gtk_toolbar_update_button_relief (GtkToolbar *toolbar)
1816 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1817 GtkReliefStyle relief;
1819 relief = get_button_relief (toolbar);
1821 if (relief != gtk_button_get_relief (GTK_BUTTON (priv->arrow_button)))
1823 gtk_toolbar_reconfigured (toolbar);
1825 gtk_button_set_relief (GTK_BUTTON (priv->arrow_button), relief);
1830 gtk_toolbar_style_set (GtkWidget *widget,
1831 GtkStyle *prev_style)
1833 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
1835 priv->max_homogeneous_pixels = -1;
1837 if (GTK_WIDGET_REALIZED (widget))
1838 gtk_style_set_background (widget->style, widget->window, widget->state);
1841 gtk_toolbar_update_button_relief (GTK_TOOLBAR (widget));
1845 gtk_toolbar_list_children_in_focus_order (GtkToolbar *toolbar,
1846 GtkDirectionType dir)
1848 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1849 GList *result = NULL;
1853 /* generate list of children in reverse logical order */
1855 for (list = priv->content; list != NULL; list = list->next)
1857 ToolbarContent *content = list->data;
1860 widget = toolbar_content_get_widget (content);
1863 result = g_list_prepend (result, widget);
1866 result = g_list_prepend (result, priv->arrow_button);
1868 rtl = (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL);
1870 /* move in logical order when
1872 * - dir is TAB_FORWARD
1874 * - in RTL mode and moving left or up
1876 * - in LTR mode and moving right or down
1878 if (dir == GTK_DIR_TAB_FORWARD ||
1879 (rtl && (dir == GTK_DIR_UP || dir == GTK_DIR_LEFT)) ||
1880 (!rtl && (dir == GTK_DIR_DOWN || dir == GTK_DIR_RIGHT)))
1882 result = g_list_reverse (result);
1889 gtk_toolbar_focus_home_or_end (GtkToolbar *toolbar,
1890 gboolean focus_home)
1892 GList *children, *list;
1893 GtkDirectionType dir = focus_home? GTK_DIR_RIGHT : GTK_DIR_LEFT;
1895 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1897 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL)
1899 children = g_list_reverse (children);
1901 dir = (dir == GTK_DIR_RIGHT)? GTK_DIR_LEFT : GTK_DIR_RIGHT;
1904 for (list = children; list != NULL; list = list->next)
1906 GtkWidget *child = list->data;
1908 if (GTK_CONTAINER (toolbar)->focus_child == child)
1911 if (GTK_WIDGET_MAPPED (child) && gtk_widget_child_focus (child, dir))
1915 g_list_free (children);
1920 /* Keybinding handler. This function is called when the user presses
1921 * Ctrl TAB or an arrow key.
1924 gtk_toolbar_move_focus (GtkWidget *widget,
1925 GtkDirectionType dir)
1927 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1928 GtkContainer *container = GTK_CONTAINER (toolbar);
1930 gboolean try_focus = FALSE;
1933 if (container->focus_child &&
1934 gtk_widget_child_focus (container->focus_child, dir))
1939 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1941 for (list = children; list != NULL; list = list->next)
1943 GtkWidget *child = list->data;
1945 if (try_focus && GTK_WIDGET_MAPPED (child) && gtk_widget_child_focus (child, dir))
1948 if (child == GTK_CONTAINER (toolbar)->focus_child)
1952 g_list_free (children);
1955 /* The focus handler for the toolbar. It called when the user presses
1956 * TAB or otherwise tries to focus the toolbar.
1959 gtk_toolbar_focus (GtkWidget *widget,
1960 GtkDirectionType dir)
1962 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1963 GList *children, *list;
1964 gboolean result = FALSE;
1966 /* if focus is already somewhere inside the toolbar then return FALSE.
1967 * The only way focus can stay inside the toolbar is when the user presses
1968 * arrow keys or Ctrl TAB (both of which are handled by the
1969 * gtk_toolbar_move_focus() keybinding function.
1971 if (GTK_CONTAINER (widget)->focus_child)
1974 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1976 for (list = children; list != NULL; list = list->next)
1978 GtkWidget *child = list->data;
1980 if (GTK_WIDGET_MAPPED (child) && gtk_widget_child_focus (child, dir))
1987 g_list_free (children);
1992 static GtkSettings *
1993 toolbar_get_settings (GtkToolbar *toolbar)
1995 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1996 return priv->settings;
2000 style_change_notify (GtkToolbar *toolbar)
2002 if (!toolbar->style_set)
2004 /* pretend it was set, then unset, thus reverting to new default */
2005 toolbar->style_set = TRUE;
2006 gtk_toolbar_unset_style (toolbar);
2011 icon_size_change_notify (GtkToolbar *toolbar)
2013 if (!toolbar->icon_size_set)
2015 /* pretend it was set, then unset, thus reverting to new default */
2016 toolbar->icon_size_set = TRUE;
2017 gtk_toolbar_unset_icon_size (toolbar);
2022 animation_change_notify (GtkToolbar *toolbar)
2024 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2025 GtkSettings *settings = toolbar_get_settings (toolbar);
2029 g_object_get (settings,
2030 "gtk-enable-animations", &animation,
2033 animation = DEFAULT_ANIMATION_STATE;
2035 priv->animation = animation;
2039 settings_change_notify (GtkSettings *settings,
2040 const GParamSpec *pspec,
2041 GtkToolbar *toolbar)
2043 if (! strcmp (pspec->name, "gtk-toolbar-style"))
2044 style_change_notify (toolbar);
2045 else if (! strcmp (pspec->name, "gtk-toolbar-icon-size"))
2046 icon_size_change_notify (toolbar);
2047 else if (! strcmp (pspec->name, "gtk-enable-animations"))
2048 animation_change_notify (toolbar);
2052 gtk_toolbar_screen_changed (GtkWidget *widget,
2053 GdkScreen *previous_screen)
2055 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
2056 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
2057 GtkSettings *old_settings = toolbar_get_settings (toolbar);
2058 GtkSettings *settings;
2060 if (gtk_widget_has_screen (GTK_WIDGET (toolbar)))
2061 settings = gtk_widget_get_settings (GTK_WIDGET (toolbar));
2065 if (settings == old_settings)
2070 g_signal_handler_disconnect (old_settings, priv->settings_connection);
2072 g_object_unref (old_settings);
2077 priv->settings_connection =
2078 g_signal_connect (settings, "notify",
2079 G_CALLBACK (settings_change_notify),
2082 priv->settings = g_object_ref (settings);
2085 priv->settings = NULL;
2087 style_change_notify (toolbar);
2088 icon_size_change_notify (toolbar);
2089 animation_change_notify (toolbar);
2093 find_drop_index (GtkToolbar *toolbar,
2097 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2098 GList *interesting_content;
2100 GtkOrientation orientation;
2101 GtkTextDirection direction;
2102 gint best_distance = G_MAXINT;
2106 ToolbarContent *best_content;
2107 GtkAllocation allocation;
2109 /* list items we care about wrt. drag and drop */
2110 interesting_content = NULL;
2111 for (list = priv->content; list != NULL; list = list->next)
2113 ToolbarContent *content = list->data;
2115 if (toolbar_content_get_state (content) == NORMAL)
2116 interesting_content = g_list_prepend (interesting_content, content);
2118 interesting_content = g_list_reverse (interesting_content);
2120 if (!interesting_content)
2123 orientation = toolbar->orientation;
2124 direction = gtk_widget_get_direction (GTK_WIDGET (toolbar));
2126 /* distance to first interesting item */
2127 best_content = interesting_content->data;
2128 toolbar_content_get_allocation (best_content, &allocation);
2130 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2134 if (direction == GTK_TEXT_DIR_LTR)
2137 pos = allocation.x + allocation.width;
2145 best_content = NULL;
2146 best_distance = ABS (pos - cursor);
2148 /* distance to far end of each item */
2149 for (list = interesting_content; list != NULL; list = list->next)
2151 ToolbarContent *content = list->data;
2153 toolbar_content_get_allocation (content, &allocation);
2155 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2157 if (direction == GTK_TEXT_DIR_LTR)
2158 pos = allocation.x + allocation.width;
2164 pos = allocation.y + allocation.height;
2167 distance = ABS (pos - cursor);
2169 if (distance < best_distance)
2171 best_distance = distance;
2172 best_content = content;
2176 g_list_free (interesting_content);
2181 return g_list_index (priv->content, best_content) + 1;
2185 reset_all_placeholders (GtkToolbar *toolbar)
2187 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2190 for (list = priv->content; list != NULL; list = list->next)
2192 ToolbarContent *content = list->data;
2193 if (toolbar_content_is_placeholder (content))
2194 toolbar_content_set_disappearing (content, TRUE);
2199 physical_to_logical (GtkToolbar *toolbar,
2202 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2206 g_assert (physical >= 0);
2209 for (list = priv->content; list && physical > 0; list = list->next)
2211 ToolbarContent *content = list->data;
2213 if (!toolbar_content_is_placeholder (content))
2218 g_assert (physical == 0);
2224 logical_to_physical (GtkToolbar *toolbar,
2227 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2231 g_assert (logical >= 0);
2234 for (list = priv->content; list; list = list->next)
2236 ToolbarContent *content = list->data;
2238 if (!toolbar_content_is_placeholder (content))
2248 g_assert (logical == 0);
2254 * gtk_toolbar_set_drop_highlight_item:
2255 * @toolbar: a #GtkToolbar
2256 * @tool_item: (allow-none): a #GtkToolItem, or %NULL to turn of highlighting
2257 * @index_: a position on @toolbar
2259 * Highlights @toolbar to give an idea of what it would look like
2260 * if @item was added to @toolbar at the position indicated by @index_.
2261 * If @item is %NULL, highlighting is turned off. In that case @index_
2264 * The @tool_item passed to this function must not be part of any widget
2265 * hierarchy. When an item is set as drop highlight item it can not
2266 * added to any widget hierarchy or used as highlight item for another
2272 gtk_toolbar_set_drop_highlight_item (GtkToolbar *toolbar,
2273 GtkToolItem *tool_item,
2276 ToolbarContent *content;
2277 GtkToolbarPrivate *priv;
2279 GtkRequisition requisition;
2280 GtkRequisition old_requisition;
2281 gboolean restart_sliding;
2283 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2284 g_return_if_fail (tool_item == NULL || GTK_IS_TOOL_ITEM (tool_item));
2286 gtk_toolbar_check_new_api (toolbar);
2288 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2292 if (priv->highlight_tool_item)
2294 gtk_widget_unparent (GTK_WIDGET (priv->highlight_tool_item));
2295 g_object_unref (priv->highlight_tool_item);
2296 priv->highlight_tool_item = NULL;
2299 reset_all_placeholders (toolbar);
2300 gtk_toolbar_begin_sliding (toolbar);
2304 n_items = gtk_toolbar_get_n_items (toolbar);
2305 if (index_ < 0 || index_ > n_items)
2308 if (tool_item != priv->highlight_tool_item)
2310 if (priv->highlight_tool_item)
2311 g_object_unref (priv->highlight_tool_item);
2313 g_object_ref_sink (tool_item);
2315 priv->highlight_tool_item = tool_item;
2317 gtk_widget_set_parent (GTK_WIDGET (priv->highlight_tool_item),
2318 GTK_WIDGET (toolbar));
2321 index_ = logical_to_physical (toolbar, index_);
2323 content = g_list_nth_data (priv->content, index_);
2327 ToolbarContent *prev_content;
2329 prev_content = g_list_nth_data (priv->content, index_ - 1);
2331 if (prev_content && toolbar_content_is_placeholder (prev_content))
2332 content = prev_content;
2335 if (!content || !toolbar_content_is_placeholder (content))
2337 GtkWidget *placeholder;
2339 placeholder = GTK_WIDGET (gtk_separator_tool_item_new ());
2341 content = toolbar_content_new_tool_item (toolbar,
2342 GTK_TOOL_ITEM (placeholder),
2344 gtk_widget_show (placeholder);
2348 g_assert (toolbar_content_is_placeholder (content));
2350 gtk_widget_size_request (GTK_WIDGET (priv->highlight_tool_item),
2353 toolbar_content_set_expand (content, gtk_tool_item_get_expand (tool_item));
2355 restart_sliding = FALSE;
2356 toolbar_content_size_request (content, toolbar, &old_requisition);
2357 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
2359 requisition.height = -1;
2360 if (requisition.width != old_requisition.width)
2361 restart_sliding = TRUE;
2365 requisition.width = -1;
2366 if (requisition.height != old_requisition.height)
2367 restart_sliding = TRUE;
2370 if (toolbar_content_disappearing (content))
2371 restart_sliding = TRUE;
2373 reset_all_placeholders (toolbar);
2374 toolbar_content_set_disappearing (content, FALSE);
2376 toolbar_content_set_size_request (content,
2377 requisition.width, requisition.height);
2379 if (restart_sliding)
2380 gtk_toolbar_begin_sliding (toolbar);
2384 gtk_toolbar_get_child_property (GtkContainer *container,
2390 GtkToolItem *item = GTK_TOOL_ITEM (child);
2392 switch (property_id)
2394 case CHILD_PROP_HOMOGENEOUS:
2395 g_value_set_boolean (value, gtk_tool_item_get_homogeneous (item));
2398 case CHILD_PROP_EXPAND:
2399 g_value_set_boolean (value, gtk_tool_item_get_expand (item));
2403 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
2409 gtk_toolbar_set_child_property (GtkContainer *container,
2412 const GValue *value,
2415 switch (property_id)
2417 case CHILD_PROP_HOMOGENEOUS:
2418 gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (child), g_value_get_boolean (value));
2421 case CHILD_PROP_EXPAND:
2422 gtk_tool_item_set_expand (GTK_TOOL_ITEM (child), g_value_get_boolean (value));
2426 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
2432 gtk_toolbar_show_all (GtkWidget *widget)
2434 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
2437 for (list = priv->content; list != NULL; list = list->next)
2439 ToolbarContent *content = list->data;
2441 toolbar_content_show_all (content);
2444 gtk_widget_show (widget);
2448 gtk_toolbar_hide_all (GtkWidget *widget)
2450 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
2453 for (list = priv->content; list != NULL; list = list->next)
2455 ToolbarContent *content = list->data;
2457 toolbar_content_hide_all (content);
2460 gtk_widget_hide (widget);
2464 gtk_toolbar_add (GtkContainer *container,
2467 GtkToolbar *toolbar = GTK_TOOLBAR (container);
2469 if (GTK_IS_TOOL_ITEM (widget))
2470 gtk_toolbar_insert (toolbar, GTK_TOOL_ITEM (widget), -1);
2472 gtk_toolbar_append_widget (toolbar, widget, NULL, NULL);
2476 gtk_toolbar_remove (GtkContainer *container,
2479 GtkToolbar *toolbar = GTK_TOOLBAR (container);
2480 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2481 ToolbarContent *content_to_remove;
2484 content_to_remove = NULL;
2485 for (list = priv->content; list != NULL; list = list->next)
2487 ToolbarContent *content = list->data;
2490 child = toolbar_content_get_widget (content);
2491 if (child && child == widget)
2493 content_to_remove = content;
2498 g_return_if_fail (content_to_remove != NULL);
2500 toolbar_content_remove (content_to_remove, toolbar);
2501 toolbar_content_free (content_to_remove);
2505 gtk_toolbar_forall (GtkContainer *container,
2506 gboolean include_internals,
2507 GtkCallback callback,
2508 gpointer callback_data)
2510 GtkToolbar *toolbar = GTK_TOOLBAR (container);
2511 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2514 g_return_if_fail (callback != NULL);
2516 list = priv->content;
2519 ToolbarContent *content = list->data;
2520 GList *next = list->next;
2522 if (include_internals || !toolbar_content_is_placeholder (content))
2524 GtkWidget *child = toolbar_content_get_widget (content);
2527 callback (child, callback_data);
2533 if (include_internals)
2534 callback (priv->arrow_button, callback_data);
2538 gtk_toolbar_child_type (GtkContainer *container)
2540 return GTK_TYPE_TOOL_ITEM;
2544 gtk_toolbar_reconfigured (GtkToolbar *toolbar)
2546 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2549 list = priv->content;
2552 ToolbarContent *content = list->data;
2553 GList *next = list->next;
2555 toolbar_content_toolbar_reconfigured (content, toolbar);
2562 gtk_toolbar_orientation_changed (GtkToolbar *toolbar,
2563 GtkOrientation orientation)
2565 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2566 if (toolbar->orientation != orientation)
2568 toolbar->orientation = orientation;
2570 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2571 gtk_arrow_set (GTK_ARROW (priv->arrow), GTK_ARROW_DOWN, GTK_SHADOW_NONE);
2573 gtk_arrow_set (GTK_ARROW (priv->arrow), GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
2575 gtk_toolbar_reconfigured (toolbar);
2577 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
2578 g_object_notify (G_OBJECT (toolbar), "orientation");
2583 gtk_toolbar_real_style_changed (GtkToolbar *toolbar,
2584 GtkToolbarStyle style)
2586 if (toolbar->style != style)
2588 toolbar->style = style;
2590 gtk_toolbar_reconfigured (toolbar);
2592 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
2593 g_object_notify (G_OBJECT (toolbar), "toolbar-style");
2598 menu_position_func (GtkMenu *menu,
2604 GtkToolbar *toolbar = GTK_TOOLBAR (user_data);
2605 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2607 GtkRequisition menu_req;
2608 GdkRectangle monitor;
2612 gtk_widget_size_request (priv->arrow_button, &req);
2613 gtk_widget_size_request (GTK_WIDGET (menu), &menu_req);
2615 screen = gtk_widget_get_screen (GTK_WIDGET (menu));
2616 monitor_num = gdk_screen_get_monitor_at_window (screen, priv->arrow_button->window);
2617 if (monitor_num < 0)
2619 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
2621 gdk_window_get_origin (GTK_BUTTON (priv->arrow_button)->event_window, x, y);
2622 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
2624 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
2625 *x += priv->arrow_button->allocation.width - req.width;
2627 *x += req.width - menu_req.width;
2629 if ((*y + priv->arrow_button->allocation.height + menu_req.height) <= monitor.y + monitor.height)
2630 *y += priv->arrow_button->allocation.height;
2631 else if ((*y - menu_req.height) >= monitor.y)
2632 *y -= menu_req.height;
2633 else if (monitor.y + monitor.height - (*y + priv->arrow_button->allocation.height) > *y)
2634 *y += priv->arrow_button->allocation.height;
2636 *y -= menu_req.height;
2640 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
2641 *x += priv->arrow_button->allocation.width;
2643 *x -= menu_req.width;
2645 if (*y + menu_req.height > monitor.y + monitor.height &&
2646 *y + priv->arrow_button->allocation.height - monitor.y > monitor.y + monitor.height - *y)
2647 *y += priv->arrow_button->allocation.height - menu_req.height;
2654 show_menu (GtkToolbar *toolbar,
2655 GdkEventButton *event)
2657 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2659 rebuild_menu (toolbar);
2661 gtk_widget_show_all (GTK_WIDGET (priv->menu));
2663 gtk_menu_popup (priv->menu, NULL, NULL,
2664 menu_position_func, toolbar,
2665 event? event->button : 0,
2666 event? event->time : gtk_get_current_event_time());
2670 gtk_toolbar_arrow_button_clicked (GtkWidget *button,
2671 GtkToolbar *toolbar)
2673 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2675 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->arrow_button)) &&
2676 (!priv->menu || !GTK_WIDGET_VISIBLE (priv->menu)))
2678 /* We only get here when the button is clicked with the keyboard,
2679 * because mouse button presses result in the menu being shown so
2680 * that priv->menu would be non-NULL and visible.
2682 show_menu (toolbar, NULL);
2683 gtk_menu_shell_select_first (GTK_MENU_SHELL (priv->menu), FALSE);
2688 gtk_toolbar_arrow_button_press (GtkWidget *button,
2689 GdkEventButton *event,
2690 GtkToolbar *toolbar)
2692 show_menu (toolbar, event);
2693 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
2699 gtk_toolbar_button_press (GtkWidget *toolbar,
2700 GdkEventButton *event)
2702 if (event->button == 3)
2704 gboolean return_value;
2706 g_signal_emit (toolbar, toolbar_signals[POPUP_CONTEXT_MENU], 0,
2707 (int)event->x_root, (int)event->y_root, event->button,
2710 return return_value;
2717 gtk_toolbar_popup_menu (GtkWidget *toolbar)
2719 gboolean return_value;
2720 /* This function is the handler for the "popup menu" keybinding,
2721 * ie., it is called when the user presses Shift F10
2723 g_signal_emit (toolbar, toolbar_signals[POPUP_CONTEXT_MENU], 0,
2724 -1, -1, -1, &return_value);
2726 return return_value;
2732 * Creates a new toolbar.
2734 * Return Value: the newly-created toolbar.
2737 gtk_toolbar_new (void)
2739 GtkToolbar *toolbar;
2741 toolbar = g_object_new (GTK_TYPE_TOOLBAR, NULL);
2743 return GTK_WIDGET (toolbar);
2747 * gtk_toolbar_insert:
2748 * @toolbar: a #GtkToolbar
2749 * @item: a #GtkToolItem
2750 * @pos: the position of the new item
2752 * Insert a #GtkToolItem into the toolbar at position @pos. If @pos is
2753 * 0 the item is prepended to the start of the toolbar. If @pos is
2754 * negative, the item is appended to the end of the toolbar.
2759 gtk_toolbar_insert (GtkToolbar *toolbar,
2763 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2764 g_return_if_fail (GTK_IS_TOOL_ITEM (item));
2766 if (!gtk_toolbar_check_new_api (toolbar))
2770 pos = logical_to_physical (toolbar, pos);
2772 toolbar_content_new_tool_item (toolbar, item, FALSE, pos);
2776 * gtk_toolbar_get_item_index:
2777 * @toolbar: a #GtkToolbar
2778 * @item: a #GtkToolItem that is a child of @toolbar
2780 * Returns the position of @item on the toolbar, starting from 0.
2781 * It is an error if @item is not a child of the toolbar.
2783 * Return value: the position of item on the toolbar.
2788 gtk_toolbar_get_item_index (GtkToolbar *toolbar,
2791 GtkToolbarPrivate *priv;
2795 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
2796 g_return_val_if_fail (GTK_IS_TOOL_ITEM (item), -1);
2797 g_return_val_if_fail (GTK_WIDGET (item)->parent == GTK_WIDGET (toolbar), -1);
2799 if (!gtk_toolbar_check_new_api (toolbar))
2802 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2805 for (list = priv->content; list != NULL; list = list->next)
2807 ToolbarContent *content = list->data;
2810 widget = toolbar_content_get_widget (content);
2812 if (item == GTK_TOOL_ITEM (widget))
2818 return physical_to_logical (toolbar, n);
2822 * gtk_toolbar_set_orientation:
2823 * @toolbar: a #GtkToolbar.
2824 * @orientation: a new #GtkOrientation.
2826 * Sets whether a toolbar should appear horizontally or vertically.
2828 * Deprecated: 2.16: Use gtk_orientable_set_orientation() instead.
2831 gtk_toolbar_set_orientation (GtkToolbar *toolbar,
2832 GtkOrientation orientation)
2834 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2836 g_signal_emit (toolbar, toolbar_signals[ORIENTATION_CHANGED], 0, orientation);
2840 * gtk_toolbar_get_orientation:
2841 * @toolbar: a #GtkToolbar
2843 * Retrieves the current orientation of the toolbar. See
2844 * gtk_toolbar_set_orientation().
2846 * Return value: the orientation
2848 * Deprecated: 2.16: Use gtk_orientable_get_orientation() instead.
2851 gtk_toolbar_get_orientation (GtkToolbar *toolbar)
2853 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), GTK_ORIENTATION_HORIZONTAL);
2855 return toolbar->orientation;
2859 * gtk_toolbar_set_style:
2860 * @toolbar: a #GtkToolbar.
2861 * @style: the new style for @toolbar.
2863 * Alters the view of @toolbar to display either icons only, text only, or both.
2866 gtk_toolbar_set_style (GtkToolbar *toolbar,
2867 GtkToolbarStyle style)
2869 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2871 toolbar->style_set = TRUE;
2872 g_signal_emit (toolbar, toolbar_signals[STYLE_CHANGED], 0, style);
2876 * gtk_toolbar_get_style:
2877 * @toolbar: a #GtkToolbar
2879 * Retrieves whether the toolbar has text, icons, or both . See
2880 * gtk_toolbar_set_style().
2882 * Return value: the current style of @toolbar
2885 gtk_toolbar_get_style (GtkToolbar *toolbar)
2887 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), DEFAULT_TOOLBAR_STYLE);
2889 return toolbar->style;
2893 * gtk_toolbar_unset_style:
2894 * @toolbar: a #GtkToolbar
2896 * Unsets a toolbar style set with gtk_toolbar_set_style(), so that
2897 * user preferences will be used to determine the toolbar style.
2900 gtk_toolbar_unset_style (GtkToolbar *toolbar)
2902 GtkToolbarStyle style;
2904 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2906 if (toolbar->style_set)
2908 GtkSettings *settings = toolbar_get_settings (toolbar);
2911 g_object_get (settings,
2912 "gtk-toolbar-style", &style,
2915 style = DEFAULT_TOOLBAR_STYLE;
2917 if (style != toolbar->style)
2918 g_signal_emit (toolbar, toolbar_signals[STYLE_CHANGED], 0, style);
2920 toolbar->style_set = FALSE;
2925 * gtk_toolbar_set_tooltips:
2926 * @toolbar: a #GtkToolbar.
2927 * @enable: set to %FALSE to disable the tooltips, or %TRUE to enable them.
2929 * Sets if the tooltips of a toolbar should be active or not.
2931 * Deprecated: 2.14: The toolkit-wide #GtkSettings:gtk-enable-tooltips property
2932 * is now used instead.
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
2957 * Deprecated: 2.14: The toolkit-wide #GtkSettings:gtk-enable-tooltips property
2958 * is now used instead.
2961 gtk_toolbar_get_tooltips (GtkToolbar *toolbar)
2963 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), FALSE);
2969 * gtk_toolbar_get_n_items:
2970 * @toolbar: a #GtkToolbar
2972 * Returns the number of items on the toolbar.
2974 * Return value: the number of items on the toolbar
2979 gtk_toolbar_get_n_items (GtkToolbar *toolbar)
2981 GtkToolbarPrivate *priv;
2983 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
2985 if (!gtk_toolbar_check_new_api (toolbar))
2988 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2990 return physical_to_logical (toolbar, g_list_length (priv->content));
2994 * gtk_toolbar_get_nth_item:
2995 * @toolbar: a #GtkToolbar
2996 * @n: A position on the toolbar
2998 * Returns the @n<!-- -->'th item on @toolbar, or %NULL if the
2999 * toolbar does not contain an @n<!-- -->'th item.
3001 * Return value: The @n<!-- -->'th #GtkToolItem on @toolbar, or %NULL if there
3002 * isn't an @n<!-- -->'th item.
3007 gtk_toolbar_get_nth_item (GtkToolbar *toolbar,
3010 GtkToolbarPrivate *priv;
3011 ToolbarContent *content;
3014 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), NULL);
3016 if (!gtk_toolbar_check_new_api (toolbar))
3019 n_items = gtk_toolbar_get_n_items (toolbar);
3021 if (n < 0 || n >= n_items)
3024 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3026 content = g_list_nth_data (priv->content, logical_to_physical (toolbar, n));
3029 g_assert (!toolbar_content_is_placeholder (content));
3031 return GTK_TOOL_ITEM (toolbar_content_get_widget (content));
3035 * gtk_toolbar_get_icon_size:
3036 * @toolbar: a #GtkToolbar
3038 * Retrieves the icon size for the toolbar. See gtk_toolbar_set_icon_size().
3040 * Return value: the current icon size for the icons on the toolbar.
3043 gtk_toolbar_get_icon_size (GtkToolbar *toolbar)
3045 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), DEFAULT_ICON_SIZE);
3047 return toolbar->icon_size;
3051 * gtk_toolbar_get_relief_style:
3052 * @toolbar: a #GtkToolbar
3054 * Returns the relief style of buttons on @toolbar. See
3055 * gtk_button_set_relief().
3057 * Return value: The relief style of buttons on @toolbar.
3062 gtk_toolbar_get_relief_style (GtkToolbar *toolbar)
3064 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), GTK_RELIEF_NONE);
3066 return get_button_relief (toolbar);
3070 * gtk_toolbar_set_show_arrow:
3071 * @toolbar: a #GtkToolbar
3072 * @show_arrow: Whether to show an overflow menu
3074 * Sets whether to show an overflow menu when
3075 * @toolbar doesn't have room for all items on it. If %TRUE,
3076 * items that there are not room are available through an
3082 gtk_toolbar_set_show_arrow (GtkToolbar *toolbar,
3083 gboolean show_arrow)
3085 GtkToolbarPrivate *priv;
3087 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3089 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3090 show_arrow = show_arrow != FALSE;
3092 if (priv->show_arrow != show_arrow)
3094 priv->show_arrow = show_arrow;
3096 if (!priv->show_arrow)
3097 gtk_widget_hide (priv->arrow_button);
3099 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3100 g_object_notify (G_OBJECT (toolbar), "show-arrow");
3105 * gtk_toolbar_get_show_arrow:
3106 * @toolbar: a #GtkToolbar
3108 * Returns whether the toolbar has an overflow menu.
3109 * See gtk_toolbar_set_show_arrow().
3111 * Return value: %TRUE if the toolbar has an overflow menu.
3116 gtk_toolbar_get_show_arrow (GtkToolbar *toolbar)
3118 GtkToolbarPrivate *priv;
3120 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), FALSE);
3122 if (!gtk_toolbar_check_new_api (toolbar))
3125 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3127 return priv->show_arrow;
3131 * gtk_toolbar_get_drop_index:
3132 * @toolbar: a #GtkToolbar
3133 * @x: x coordinate of a point on the toolbar
3134 * @y: y coordinate of a point on the toolbar
3136 * Returns the position corresponding to the indicated point on
3137 * @toolbar. This is useful when dragging items to the toolbar:
3138 * this function returns the position a new item should be
3141 * @x and @y are in @toolbar coordinates.
3143 * Return value: The position corresponding to the point (@x, @y) on the toolbar.
3148 gtk_toolbar_get_drop_index (GtkToolbar *toolbar,
3152 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
3154 if (!gtk_toolbar_check_new_api (toolbar))
3157 return physical_to_logical (toolbar, find_drop_index (toolbar, x, y));
3161 gtk_toolbar_finalize (GObject *object)
3164 GtkToolbar *toolbar = GTK_TOOLBAR (object);
3165 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3167 if (toolbar->tooltips)
3168 g_object_unref (toolbar->tooltips);
3170 if (priv->arrow_button)
3171 gtk_widget_unparent (priv->arrow_button);
3173 for (list = priv->content; list != NULL; list = list->next)
3175 ToolbarContent *content = list->data;
3177 toolbar_content_free (content);
3180 g_list_free (priv->content);
3181 g_list_free (toolbar->children);
3183 g_timer_destroy (priv->timer);
3186 gtk_widget_destroy (GTK_WIDGET (priv->menu));
3189 g_source_remove (priv->idle_id);
3191 G_OBJECT_CLASS (gtk_toolbar_parent_class)->finalize (object);
3195 * gtk_toolbar_set_icon_size:
3196 * @toolbar: A #GtkToolbar
3197 * @icon_size: The #GtkIconSize that stock icons in the toolbar shall have.
3199 * This function sets the size of stock icons in the toolbar. You
3200 * can call it both before you add the icons and after they've been
3201 * added. The size you set will override user preferences for the default
3204 * This should only be used for special-purpose toolbars, normal
3205 * application toolbars should respect the user preferences for the
3209 gtk_toolbar_set_icon_size (GtkToolbar *toolbar,
3210 GtkIconSize icon_size)
3212 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3213 g_return_if_fail (icon_size != GTK_ICON_SIZE_INVALID);
3215 if (!toolbar->icon_size_set)
3217 toolbar->icon_size_set = TRUE;
3218 g_object_notify (G_OBJECT (toolbar), "icon-size-set");
3221 if (toolbar->icon_size == icon_size)
3224 toolbar->icon_size = icon_size;
3225 g_object_notify (G_OBJECT (toolbar), "icon-size");
3227 gtk_toolbar_reconfigured (toolbar);
3229 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3233 * gtk_toolbar_unset_icon_size:
3234 * @toolbar: a #GtkToolbar
3236 * Unsets toolbar icon size set with gtk_toolbar_set_icon_size(), so that
3237 * user preferences will be used to determine the icon size.
3240 gtk_toolbar_unset_icon_size (GtkToolbar *toolbar)
3244 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3246 if (toolbar->icon_size_set)
3248 GtkSettings *settings = toolbar_get_settings (toolbar);
3252 g_object_get (settings,
3253 "gtk-toolbar-icon-size", &size,
3257 size = DEFAULT_ICON_SIZE;
3259 if (size != toolbar->icon_size)
3261 gtk_toolbar_set_icon_size (toolbar, size);
3262 g_object_notify (G_OBJECT (toolbar), "icon-size");
3265 toolbar->icon_size_set = FALSE;
3266 g_object_notify (G_OBJECT (toolbar), "icon-size-set");
3275 * gtk_toolbar_append_item:
3276 * @toolbar: a #GtkToolbar.
3277 * @text: give your toolbar button a label.
3278 * @tooltip_text: a string that appears when the user holds the mouse over this item.
3279 * @tooltip_private_text: use with #GtkTipsQuery.
3280 * @icon: a #GtkWidget that should be used as the button's icon.
3281 * @callback: the function to be executed when the button is pressed.
3282 * @user_data: a pointer to any data you wish to be passed to the callback.
3284 * Inserts a new item into the toolbar. You must specify the position
3285 * in the toolbar where it will be inserted.
3287 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3288 * arguments. Use G_CALLBACK() to cast the function to #GCallback.
3290 * Return value: the new toolbar item as a #GtkWidget.
3292 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3295 gtk_toolbar_append_item (GtkToolbar *toolbar,
3297 const char *tooltip_text,
3298 const char *tooltip_private_text,
3303 return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
3305 tooltip_text, tooltip_private_text,
3306 icon, callback, user_data,
3307 toolbar->num_children);
3311 * gtk_toolbar_prepend_item:
3312 * @toolbar: a #GtkToolbar.
3313 * @text: give your toolbar button a label.
3314 * @tooltip_text: a string that appears when the user holds the mouse over this item.
3315 * @tooltip_private_text: use with #GtkTipsQuery.
3316 * @icon: a #GtkWidget that should be used as the button's icon.
3317 * @callback: the function to be executed when the button is pressed.
3318 * @user_data: a pointer to any data you wish to be passed to the callback.
3320 * Adds a new button to the beginning (top or left edges) of the given toolbar.
3322 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3323 * arguments. Use G_CALLBACK() to cast the function to #GCallback.
3325 * Return value: the new toolbar item as a #GtkWidget.
3327 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3330 gtk_toolbar_prepend_item (GtkToolbar *toolbar,
3332 const char *tooltip_text,
3333 const char *tooltip_private_text,
3338 return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
3340 tooltip_text, tooltip_private_text,
3341 icon, callback, user_data,
3346 * gtk_toolbar_insert_item:
3347 * @toolbar: a #GtkToolbar.
3348 * @text: give your toolbar button a label.
3349 * @tooltip_text: a string that appears when the user holds the mouse over this item.
3350 * @tooltip_private_text: use with #GtkTipsQuery.
3351 * @icon: a #GtkWidget that should be used as the button's icon.
3352 * @callback: the function to be executed when the button is pressed.
3353 * @user_data: a pointer to any data you wish to be passed to the callback.
3354 * @position: the number of widgets to insert this item after.
3356 * Inserts a new item into the toolbar. You must specify the position in the
3357 * toolbar where it will be inserted.
3359 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3360 * arguments. Use G_CALLBACK() to cast the function to #GCallback.
3362 * Return value: the new toolbar item as a #GtkWidget.
3364 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3367 gtk_toolbar_insert_item (GtkToolbar *toolbar,
3369 const char *tooltip_text,
3370 const char *tooltip_private_text,
3376 return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
3378 tooltip_text, tooltip_private_text,
3379 icon, callback, user_data,
3384 * gtk_toolbar_insert_stock:
3385 * @toolbar: A #GtkToolbar
3386 * @stock_id: The id of the stock item you want to insert
3387 * @tooltip_text: The text in the tooltip of the toolbar button
3388 * @tooltip_private_text: The private text of the tooltip
3389 * @callback: The callback called when the toolbar button is clicked.
3390 * @user_data: user data passed to callback
3391 * @position: The position the button shall be inserted at.
3392 * -1 means at the end.
3394 * Inserts a stock item at the specified position of the toolbar. If
3395 * @stock_id is not a known stock item ID, it's inserted verbatim,
3396 * except that underscores used to mark mnemonics are removed.
3398 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3399 * arguments. Use G_CALLBACK() to cast the function to #GCallback.
3401 * Returns: the inserted widget
3403 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3406 gtk_toolbar_insert_stock (GtkToolbar *toolbar,
3407 const gchar *stock_id,
3408 const char *tooltip_text,
3409 const char *tooltip_private_text,
3414 return internal_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
3416 tooltip_text, tooltip_private_text,
3417 NULL, callback, user_data,
3422 * gtk_toolbar_append_space:
3423 * @toolbar: a #GtkToolbar.
3425 * Adds a new space to the end of the toolbar.
3427 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3430 gtk_toolbar_append_space (GtkToolbar *toolbar)
3432 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_SPACE,
3436 toolbar->num_children);
3440 * gtk_toolbar_prepend_space:
3441 * @toolbar: a #GtkToolbar.
3443 * Adds a new space to the beginning of the toolbar.
3445 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3448 gtk_toolbar_prepend_space (GtkToolbar *toolbar)
3450 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_SPACE,
3458 * gtk_toolbar_insert_space:
3459 * @toolbar: a #GtkToolbar
3460 * @position: the number of widgets after which a space should be inserted.
3462 * Inserts a new space in the toolbar at the specified position.
3464 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3467 gtk_toolbar_insert_space (GtkToolbar *toolbar,
3470 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_SPACE,
3478 * gtk_toolbar_remove_space:
3479 * @toolbar: a #GtkToolbar.
3480 * @position: the index of the space to remove.
3482 * Removes a space from the specified position.
3484 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3487 gtk_toolbar_remove_space (GtkToolbar *toolbar,
3490 GtkToolbarPrivate *priv;
3491 ToolbarContent *content;
3493 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3495 if (!gtk_toolbar_check_old_api (toolbar))
3498 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3500 content = g_list_nth_data (priv->content, position);
3504 g_warning ("Toolbar position %d doesn't exist", position);
3508 if (!toolbar_content_is_separator (content))
3510 g_warning ("Toolbar position %d is not a space", position);
3514 toolbar_content_remove (content, toolbar);
3515 toolbar_content_free (content);
3519 * gtk_toolbar_append_widget:
3520 * @toolbar: a #GtkToolbar.
3521 * @widget: a #GtkWidget to add to the toolbar.
3522 * @tooltip_text: (allow-none): the element's tooltip.
3523 * @tooltip_private_text: (allow-none): used for context-sensitive help about this toolbar element.
3525 * Adds a widget to the end of the given toolbar.
3527 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3530 gtk_toolbar_append_widget (GtkToolbar *toolbar,
3532 const gchar *tooltip_text,
3533 const gchar *tooltip_private_text)
3535 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_WIDGET,
3537 tooltip_text, tooltip_private_text,
3539 toolbar->num_children);
3543 * gtk_toolbar_prepend_widget:
3544 * @toolbar: a #GtkToolbar.
3545 * @widget: a #GtkWidget to add to the toolbar.
3546 * @tooltip_text: (allow-none): the element's tooltip.
3547 * @tooltip_private_text: (allow-none): used for context-sensitive help about this toolbar element.
3549 * Adds a widget to the beginning of the given toolbar.
3551 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3554 gtk_toolbar_prepend_widget (GtkToolbar *toolbar,
3556 const gchar *tooltip_text,
3557 const gchar *tooltip_private_text)
3559 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_WIDGET,
3561 tooltip_text, tooltip_private_text,
3567 * gtk_toolbar_insert_widget:
3568 * @toolbar: a #GtkToolbar.
3569 * @widget: a #GtkWidget to add to the toolbar.
3570 * @tooltip_text: (allow-none): the element's tooltip.
3571 * @tooltip_private_text: (allow-none): used for context-sensitive help about this toolbar element.
3572 * @position: the number of widgets to insert this widget after.
3574 * Inserts a widget in the toolbar at the given position.
3576 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3579 gtk_toolbar_insert_widget (GtkToolbar *toolbar,
3581 const char *tooltip_text,
3582 const char *tooltip_private_text,
3585 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_WIDGET,
3587 tooltip_text, tooltip_private_text,
3593 * gtk_toolbar_append_element:
3594 * @toolbar: a #GtkToolbar.
3595 * @type: a value of type #GtkToolbarChildType that determines what @widget will be.
3596 * @widget: a #GtkWidget, or %NULL.
3597 * @text: the element's label.
3598 * @tooltip_text: the element's tooltip.
3599 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3600 * @icon: a #GtkWidget that provides pictorial representation of the element's function.
3601 * @callback: the function to be executed when the button is pressed.
3602 * @user_data: any data you wish to pass to the callback.
3604 * Adds a new element to the end of a toolbar.
3606 * If @type == %GTK_TOOLBAR_CHILD_WIDGET, @widget is used as the new element.
3607 * If @type == %GTK_TOOLBAR_CHILD_RADIOBUTTON, @widget is used to determine
3608 * the radio group for the new element. In all other cases, @widget must
3611 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3612 * arguments. Use G_CALLBACK() to cast the function to #GCallback.
3614 * Return value: the new toolbar element as a #GtkWidget.
3616 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3619 gtk_toolbar_append_element (GtkToolbar *toolbar,
3620 GtkToolbarChildType type,
3623 const char *tooltip_text,
3624 const char *tooltip_private_text,
3629 return gtk_toolbar_insert_element (toolbar, type, widget, text,
3630 tooltip_text, tooltip_private_text,
3631 icon, callback, user_data,
3632 toolbar->num_children);
3636 * gtk_toolbar_prepend_element:
3637 * @toolbar: a #GtkToolbar.
3638 * @type: a value of type #GtkToolbarChildType that determines what @widget will be.
3639 * @widget: a #GtkWidget, or %NULL
3640 * @text: the element's label.
3641 * @tooltip_text: the element's tooltip.
3642 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3643 * @icon: a #GtkWidget that provides pictorial representation of the element's function.
3644 * @callback: the function to be executed when the button is pressed.
3645 * @user_data: any data you wish to pass to the callback.
3647 * Adds a new element to the beginning of a toolbar.
3649 * If @type == %GTK_TOOLBAR_CHILD_WIDGET, @widget is used as the new element.
3650 * If @type == %GTK_TOOLBAR_CHILD_RADIOBUTTON, @widget is used to determine
3651 * the radio group for the new element. In all other cases, @widget must
3654 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3655 * arguments. Use G_CALLBACK() to cast the function to #GCallback.
3657 * Return value: the new toolbar element as a #GtkWidget.
3659 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3662 gtk_toolbar_prepend_element (GtkToolbar *toolbar,
3663 GtkToolbarChildType type,
3666 const char *tooltip_text,
3667 const char *tooltip_private_text,
3672 return gtk_toolbar_insert_element (toolbar, type, widget, text,
3673 tooltip_text, tooltip_private_text,
3674 icon, callback, user_data, 0);
3678 * gtk_toolbar_insert_element:
3679 * @toolbar: a #GtkToolbar.
3680 * @type: a value of type #GtkToolbarChildType that determines what @widget
3682 * @widget: a #GtkWidget, or %NULL.
3683 * @text: the element's label.
3684 * @tooltip_text: the element's tooltip.
3685 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3686 * @icon: a #GtkWidget that provides pictorial representation of the element's function.
3687 * @callback: the function to be executed when the button is pressed.
3688 * @user_data: any data you wish to pass to the callback.
3689 * @position: the number of widgets to insert this element after.
3691 * Inserts a new element in the toolbar at the given position.
3693 * If @type == %GTK_TOOLBAR_CHILD_WIDGET, @widget is used as the new element.
3694 * If @type == %GTK_TOOLBAR_CHILD_RADIOBUTTON, @widget is used to determine
3695 * the radio group for the new element. In all other cases, @widget must
3698 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3699 * arguments. Use G_CALLBACK() to cast the function to #GCallback.
3701 * Return value: the new toolbar element as a #GtkWidget.
3703 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3706 gtk_toolbar_insert_element (GtkToolbar *toolbar,
3707 GtkToolbarChildType type,
3710 const char *tooltip_text,
3711 const char *tooltip_private_text,
3717 return internal_insert_element (toolbar, type, widget, text,
3718 tooltip_text, tooltip_private_text,
3719 icon, callback, user_data, position, FALSE);
3723 set_child_packing_and_visibility(GtkToolbar *toolbar,
3724 GtkToolbarChild *child)
3729 box = gtk_bin_get_child (GTK_BIN (child->widget));
3731 g_return_if_fail (GTK_IS_BOX (box));
3735 expand = (toolbar->style != GTK_TOOLBAR_BOTH);
3737 gtk_box_set_child_packing (GTK_BOX (box), child->label,
3738 expand, expand, 0, GTK_PACK_END);
3740 if (toolbar->style != GTK_TOOLBAR_ICONS)
3741 gtk_widget_show (child->label);
3743 gtk_widget_hide (child->label);
3748 expand = (toolbar->style != GTK_TOOLBAR_BOTH_HORIZ);
3750 gtk_box_set_child_packing (GTK_BOX (box), child->icon,
3751 expand, expand, 0, GTK_PACK_END);
3753 if (toolbar->style != GTK_TOOLBAR_TEXT)
3754 gtk_widget_show (child->icon);
3756 gtk_widget_hide (child->icon);
3761 internal_insert_element (GtkToolbar *toolbar,
3762 GtkToolbarChildType type,
3765 const char *tooltip_text,
3766 const char *tooltip_private_text,
3774 ToolbarContent *content;
3775 char *free_me = NULL;
3777 GtkWidget *child_widget;
3778 GtkWidget *child_label;
3779 GtkWidget *child_icon;
3781 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), NULL);
3782 if (type == GTK_TOOLBAR_CHILD_WIDGET)
3783 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3784 else if (type != GTK_TOOLBAR_CHILD_RADIOBUTTON)
3785 g_return_val_if_fail (widget == NULL, NULL);
3786 if (GTK_IS_TOOL_ITEM (widget))
3787 g_warning (MIXED_API_WARNING);
3789 if (!gtk_toolbar_check_old_api (toolbar))
3792 child_widget = NULL;
3798 case GTK_TOOLBAR_CHILD_SPACE:
3801 case GTK_TOOLBAR_CHILD_WIDGET:
3802 child_widget = widget;
3805 case GTK_TOOLBAR_CHILD_BUTTON:
3806 case GTK_TOOLBAR_CHILD_TOGGLEBUTTON:
3807 case GTK_TOOLBAR_CHILD_RADIOBUTTON:
3808 if (type == GTK_TOOLBAR_CHILD_BUTTON)
3810 child_widget = gtk_button_new ();
3812 else if (type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
3814 child_widget = gtk_toggle_button_new ();
3815 gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (child_widget), FALSE);
3817 else /* type == GTK_TOOLBAR_CHILD_RADIOBUTTON */
3819 GSList *group = NULL;
3822 group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (widget));
3824 child_widget = gtk_radio_button_new (group);
3825 gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (child_widget), FALSE);
3828 gtk_button_set_relief (GTK_BUTTON (child_widget), get_button_relief (toolbar));
3829 gtk_button_set_focus_on_click (GTK_BUTTON (child_widget), FALSE);
3833 g_signal_connect (child_widget, "clicked",
3834 callback, user_data);
3837 if (toolbar->style == GTK_TOOLBAR_BOTH_HORIZ)
3838 box = gtk_hbox_new (FALSE, 0);
3840 box = gtk_vbox_new (FALSE, 0);
3842 gtk_container_add (GTK_CONTAINER (child_widget), box);
3843 gtk_widget_show (box);
3845 if (text && use_stock)
3847 GtkStockItem stock_item;
3848 if (gtk_stock_lookup (text, &stock_item))
3851 icon = gtk_image_new_from_stock (text, toolbar->icon_size);
3853 text = free_me = _gtk_toolbar_elide_underscores (stock_item.label);
3859 child_label = gtk_label_new (text);
3861 gtk_container_add (GTK_CONTAINER (box), child_label);
3866 child_icon = GTK_WIDGET (icon);
3867 gtk_container_add (GTK_CONTAINER (box), child_icon);
3870 gtk_widget_show (child_widget);
3874 g_assert_not_reached ();
3878 if ((type != GTK_TOOLBAR_CHILD_SPACE) && tooltip_text)
3880 gtk_tooltips_set_tip (toolbar->tooltips, child_widget,
3881 tooltip_text, tooltip_private_text);
3884 content = toolbar_content_new_compatibility (toolbar, type, child_widget,
3885 child_icon, child_label, position);
3889 return child_widget;
3893 * ToolbarContent methods
3901 struct _ToolbarContent
3911 GtkAllocation start_allocation;
3912 GtkAllocation goal_allocation;
3913 guint is_placeholder : 1;
3914 guint disappearing : 1;
3920 GtkToolbarChild child;
3921 GtkAllocation space_allocation;
3922 guint space_visible : 1;
3927 static ToolbarContent *
3928 toolbar_content_new_tool_item (GtkToolbar *toolbar,
3930 gboolean is_placeholder,
3933 ToolbarContent *content;
3934 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3936 content = g_slice_new0 (ToolbarContent);
3938 content->type = TOOL_ITEM;
3939 content->state = NOT_ALLOCATED;
3940 content->u.tool_item.item = item;
3941 content->u.tool_item.is_placeholder = is_placeholder;
3943 gtk_widget_set_parent (GTK_WIDGET (item), GTK_WIDGET (toolbar));
3945 priv->content = g_list_insert (priv->content, content, pos);
3947 if (!is_placeholder)
3949 toolbar->num_children++;
3951 gtk_toolbar_stop_sliding (toolbar);
3954 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3955 priv->need_rebuild = TRUE;
3960 static ToolbarContent *
3961 toolbar_content_new_compatibility (GtkToolbar *toolbar,
3962 GtkToolbarChildType type,
3968 ToolbarContent *content;
3969 GtkToolbarChild *child;
3970 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3972 content = g_slice_new0 (ToolbarContent);
3974 child = &(content->u.compatibility.child);
3976 content->type = COMPATIBILITY;
3978 child->widget = widget;
3980 child->label = label;
3982 if (type != GTK_TOOLBAR_CHILD_SPACE)
3984 gtk_widget_set_parent (child->widget, GTK_WIDGET (toolbar));
3988 content->u.compatibility.space_visible = TRUE;
3989 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3992 if (type == GTK_TOOLBAR_CHILD_BUTTON ||
3993 type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON ||
3994 type == GTK_TOOLBAR_CHILD_RADIOBUTTON)
3996 set_child_packing_and_visibility (toolbar, child);
3999 priv->content = g_list_insert (priv->content, content, pos);
4000 toolbar->children = g_list_insert (toolbar->children, child, pos);
4001 priv->need_rebuild = TRUE;
4003 toolbar->num_children++;
4009 toolbar_content_remove (ToolbarContent *content,
4010 GtkToolbar *toolbar)
4012 GtkToolbarChild *child;
4013 GtkToolbarPrivate *priv;
4015 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
4017 switch (content->type)
4020 gtk_widget_unparent (GTK_WIDGET (content->u.tool_item.item));
4024 child = &(content->u.compatibility.child);
4026 if (child->type != GTK_TOOLBAR_CHILD_SPACE)
4028 g_object_ref (child->widget);
4029 gtk_widget_unparent (child->widget);
4030 gtk_widget_destroy (child->widget);
4031 g_object_unref (child->widget);
4034 toolbar->children = g_list_remove (toolbar->children, child);
4038 priv->content = g_list_remove (priv->content, content);
4040 if (!toolbar_content_is_placeholder (content))
4041 toolbar->num_children--;
4043 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
4044 priv->need_rebuild = TRUE;
4048 toolbar_content_free (ToolbarContent *content)
4050 g_slice_free (ToolbarContent, content);
4054 calculate_max_homogeneous_pixels (GtkWidget *widget)
4056 PangoContext *context;
4057 PangoFontMetrics *metrics;
4060 context = gtk_widget_get_pango_context (widget);
4061 metrics = pango_context_get_metrics (context,
4062 widget->style->font_desc,
4063 pango_context_get_language (context));
4064 char_width = pango_font_metrics_get_approximate_char_width (metrics);
4065 pango_font_metrics_unref (metrics);
4067 return PANGO_PIXELS (MAX_HOMOGENEOUS_N_CHARS * char_width);
4071 toolbar_content_expose (ToolbarContent *content,
4072 GtkContainer *container,
4073 GdkEventExpose *expose)
4075 GtkToolbar *toolbar = GTK_TOOLBAR (container);
4076 GtkToolbarChild *child;
4077 GtkWidget *widget = NULL; /* quiet gcc */
4079 switch (content->type)
4082 if (!content->u.tool_item.is_placeholder)
4083 widget = GTK_WIDGET (content->u.tool_item.item);
4087 child = &(content->u.compatibility.child);
4089 if (child->type == GTK_TOOLBAR_CHILD_SPACE)
4091 if (content->u.compatibility.space_visible &&
4092 get_space_style (toolbar) == GTK_TOOLBAR_SPACE_LINE)
4093 _gtk_toolbar_paint_space_line (GTK_WIDGET (toolbar), toolbar,
4095 &content->u.compatibility.space_allocation);
4099 widget = child->widget;
4104 gtk_container_propagate_expose (container, widget, expose);
4108 toolbar_content_visible (ToolbarContent *content,
4109 GtkToolbar *toolbar)
4113 switch (content->type)
4116 item = content->u.tool_item.item;
4118 if (!GTK_WIDGET_VISIBLE (item))
4121 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL &&
4122 gtk_tool_item_get_visible_horizontal (item))
4125 if ((toolbar->orientation == GTK_ORIENTATION_VERTICAL &&
4126 gtk_tool_item_get_visible_vertical (item)))
4133 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
4134 return GTK_WIDGET_VISIBLE (content->u.compatibility.child.widget);
4140 g_assert_not_reached ();
4145 toolbar_content_size_request (ToolbarContent *content,
4146 GtkToolbar *toolbar,
4147 GtkRequisition *requisition)
4151 switch (content->type)
4154 gtk_widget_size_request (GTK_WIDGET (content->u.tool_item.item),
4156 if (content->u.tool_item.is_placeholder &&
4157 content->u.tool_item.disappearing)
4159 requisition->width = 0;
4160 requisition->height = 0;
4165 space_size = get_space_size (toolbar);
4167 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
4169 gtk_widget_size_request (content->u.compatibility.child.widget,
4174 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
4176 requisition->width = space_size;
4177 requisition->height = 0;
4181 requisition->height = space_size;
4182 requisition->width = 0;
4191 toolbar_content_is_homogeneous (ToolbarContent *content,
4192 GtkToolbar *toolbar)
4194 gboolean result = FALSE; /* quiet gcc */
4195 GtkRequisition requisition;
4196 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
4198 if (priv->max_homogeneous_pixels < 0)
4200 priv->max_homogeneous_pixels =
4201 calculate_max_homogeneous_pixels (GTK_WIDGET (toolbar));
4204 toolbar_content_size_request (content, toolbar, &requisition);
4206 if (requisition.width > priv->max_homogeneous_pixels)
4209 switch (content->type)
4212 result = gtk_tool_item_get_homogeneous (content->u.tool_item.item) &&
4213 !GTK_IS_SEPARATOR_TOOL_ITEM (content->u.tool_item.item);
4215 if (gtk_tool_item_get_is_important (content->u.tool_item.item) &&
4216 toolbar->style == GTK_TOOLBAR_BOTH_HORIZ &&
4217 toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
4224 if (content->u.compatibility.child.type == GTK_TOOLBAR_CHILD_BUTTON ||
4225 content->u.compatibility.child.type == GTK_TOOLBAR_CHILD_RADIOBUTTON ||
4226 content->u.compatibility.child.type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
4241 toolbar_content_is_placeholder (ToolbarContent *content)
4243 if (content->type == TOOL_ITEM && content->u.tool_item.is_placeholder)
4250 toolbar_content_disappearing (ToolbarContent *content)
4252 if (content->type == TOOL_ITEM && content->u.tool_item.disappearing)
4259 toolbar_content_get_state (ToolbarContent *content)
4261 return content->state;
4265 toolbar_content_child_visible (ToolbarContent *content)
4267 switch (content->type)
4270 return GTK_WIDGET_CHILD_VISIBLE (content->u.tool_item.item);
4274 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
4276 return GTK_WIDGET_CHILD_VISIBLE (content->u.compatibility.child.widget);
4280 return content->u.compatibility.space_visible;
4285 return FALSE; /* quiet gcc */
4289 toolbar_content_get_goal_allocation (ToolbarContent *content,
4290 GtkAllocation *allocation)
4292 switch (content->type)
4295 *allocation = content->u.tool_item.goal_allocation;
4299 /* Goal allocations are only relevant when we are
4300 * using the new API, so we should never get here
4302 g_assert_not_reached ();
4308 toolbar_content_get_allocation (ToolbarContent *content,
4309 GtkAllocation *allocation)
4311 GtkToolbarChild *child;
4313 switch (content->type)
4316 *allocation = GTK_WIDGET (content->u.tool_item.item)->allocation;
4320 child = &(content->u.compatibility.child);
4322 if (child->type == GTK_TOOLBAR_CHILD_SPACE)
4323 *allocation = content->u.compatibility.space_allocation;
4325 *allocation = child->widget->allocation;
4331 toolbar_content_set_start_allocation (ToolbarContent *content,
4332 GtkAllocation *allocation)
4334 switch (content->type)
4337 content->u.tool_item.start_allocation = *allocation;
4341 /* start_allocation is only relevant when using the new API */
4342 g_assert_not_reached ();
4348 toolbar_content_get_expand (ToolbarContent *content)
4350 if (content->type == TOOL_ITEM &&
4351 gtk_tool_item_get_expand (content->u.tool_item.item) &&
4352 !content->u.tool_item.disappearing)
4361 toolbar_content_set_goal_allocation (ToolbarContent *content,
4362 GtkAllocation *allocation)
4364 switch (content->type)
4367 content->u.tool_item.goal_allocation = *allocation;
4371 /* Only relevant when using new API */
4372 g_assert_not_reached ();
4378 toolbar_content_set_child_visible (ToolbarContent *content,
4379 GtkToolbar *toolbar,
4382 GtkToolbarChild *child;
4384 switch (content->type)
4387 gtk_widget_set_child_visible (GTK_WIDGET (content->u.tool_item.item),
4392 child = &(content->u.compatibility.child);
4394 if (child->type != GTK_TOOLBAR_CHILD_SPACE)
4396 gtk_widget_set_child_visible (child->widget, visible);
4400 if (content->u.compatibility.space_visible != visible)
4402 content->u.compatibility.space_visible = visible;
4403 gtk_widget_queue_draw (GTK_WIDGET (toolbar));
4411 toolbar_content_get_start_allocation (ToolbarContent *content,
4412 GtkAllocation *start_allocation)
4414 switch (content->type)
4417 *start_allocation = content->u.tool_item.start_allocation;
4421 /* Only relevant for new API */
4422 g_assert_not_reached ();
4428 toolbar_content_size_allocate (ToolbarContent *content,
4429 GtkAllocation *allocation)
4431 switch (content->type)
4434 gtk_widget_size_allocate (GTK_WIDGET (content->u.tool_item.item),
4439 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
4441 gtk_widget_size_allocate (content->u.compatibility.child.widget,
4446 content->u.compatibility.space_allocation = *allocation;
4453 toolbar_content_set_state (ToolbarContent *content,
4456 content->state = state;
4460 toolbar_content_get_widget (ToolbarContent *content)
4462 GtkToolbarChild *child;
4464 switch (content->type)
4467 return GTK_WIDGET (content->u.tool_item.item);
4471 child = &(content->u.compatibility.child);
4472 if (child->type != GTK_TOOLBAR_CHILD_SPACE)
4473 return child->widget;
4483 toolbar_content_set_disappearing (ToolbarContent *content,
4484 gboolean disappearing)
4486 switch (content->type)
4489 content->u.tool_item.disappearing = disappearing;
4493 /* Only relevant for new API */
4494 g_assert_not_reached ();
4500 toolbar_content_set_size_request (ToolbarContent *content,
4504 switch (content->type)
4507 gtk_widget_set_size_request (GTK_WIDGET (content->u.tool_item.item),
4512 /* Setting size requests only happens with sliding,
4513 * so not relevant here
4515 g_assert_not_reached ();
4521 toolbar_child_reconfigure (GtkToolbar *toolbar,
4522 GtkToolbarChild *child)
4526 GtkToolbarStyle style;
4527 GtkIconSize icon_size;
4528 GtkReliefStyle relief;
4531 style = gtk_toolbar_get_style (toolbar);
4532 icon_size = gtk_toolbar_get_icon_size (toolbar);
4533 relief = gtk_toolbar_get_relief_style (toolbar);
4536 if (child->type == GTK_TOOLBAR_CHILD_BUTTON ||
4537 child->type == GTK_TOOLBAR_CHILD_RADIOBUTTON ||
4538 child->type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
4540 box = gtk_bin_get_child (GTK_BIN (child->widget));
4542 if (style == GTK_TOOLBAR_BOTH && GTK_IS_HBOX (box))
4546 vbox = gtk_vbox_new (FALSE, 0);
4549 gtk_widget_reparent (child->label, vbox);
4551 gtk_widget_reparent (child->icon, vbox);
4553 gtk_widget_destroy (box);
4554 gtk_container_add (GTK_CONTAINER (child->widget), vbox);
4556 gtk_widget_show (vbox);
4558 else if (style == GTK_TOOLBAR_BOTH_HORIZ && GTK_IS_VBOX (box))
4562 hbox = gtk_hbox_new (FALSE, 0);
4565 gtk_widget_reparent (child->label, hbox);
4567 gtk_widget_reparent (child->icon, hbox);
4569 gtk_widget_destroy (box);
4570 gtk_container_add (GTK_CONTAINER (child->widget), hbox);
4572 gtk_widget_show (hbox);
4575 set_child_packing_and_visibility (toolbar, child);
4580 if ((child->type == GTK_TOOLBAR_CHILD_BUTTON ||
4581 child->type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON ||
4582 child->type == GTK_TOOLBAR_CHILD_RADIOBUTTON) &&
4583 GTK_IS_IMAGE (child->icon))
4585 image = GTK_IMAGE (child->icon);
4586 if (gtk_image_get_storage_type (image) == GTK_IMAGE_STOCK)
4588 gtk_image_get_stock (image, &stock_id, NULL);
4589 stock_id = g_strdup (stock_id);
4590 gtk_image_set_from_stock (image,
4598 if (child->type == GTK_TOOLBAR_CHILD_BUTTON ||
4599 child->type == GTK_TOOLBAR_CHILD_RADIOBUTTON ||
4600 child->type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
4602 gtk_button_set_relief (GTK_BUTTON (child->widget), relief);
4607 toolbar_content_toolbar_reconfigured (ToolbarContent *content,
4608 GtkToolbar *toolbar)
4610 switch (content->type)
4613 gtk_tool_item_toolbar_reconfigured (content->u.tool_item.item);
4617 toolbar_child_reconfigure (toolbar, &(content->u.compatibility.child));
4623 toolbar_content_retrieve_menu_item (ToolbarContent *content)
4625 if (content->type == TOOL_ITEM)
4626 return gtk_tool_item_retrieve_proxy_menu_item (content->u.tool_item.item);
4628 /* FIXME - we might actually be able to do something meaningful here */
4633 toolbar_content_has_proxy_menu_item (ToolbarContent *content)
4635 if (content->type == TOOL_ITEM)
4637 GtkWidget *menu_item;
4639 if (content->u.tool_item.has_menu == YES)
4641 else if (content->u.tool_item.has_menu == NO)
4644 menu_item = toolbar_content_retrieve_menu_item (content);
4646 content->u.tool_item.has_menu = menu_item? YES : NO;
4648 return menu_item != NULL;
4657 toolbar_content_set_unknown_menu_status (ToolbarContent *content)
4659 if (content->type == TOOL_ITEM)
4660 content->u.tool_item.has_menu = UNKNOWN;
4664 toolbar_content_is_separator (ToolbarContent *content)
4666 GtkToolbarChild *child;
4668 switch (content->type)
4671 return GTK_IS_SEPARATOR_TOOL_ITEM (content->u.tool_item.item);
4675 child = &(content->u.compatibility.child);
4676 return (child->type == GTK_TOOLBAR_CHILD_SPACE);
4684 toolbar_content_set_expand (ToolbarContent *content,
4687 if (content->type == TOOL_ITEM)
4688 gtk_tool_item_set_expand (content->u.tool_item.item, expand);
4692 ignore_show_and_hide_all (ToolbarContent *content)
4694 if (content->type == COMPATIBILITY)
4696 GtkToolbarChildType type = content->u.compatibility.child.type;
4698 if (type == GTK_TOOLBAR_CHILD_BUTTON ||
4699 type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON ||
4700 type == GTK_TOOLBAR_CHILD_RADIOBUTTON)
4710 toolbar_content_show_all (ToolbarContent *content)
4714 if (ignore_show_and_hide_all (content))
4717 widget = toolbar_content_get_widget (content);
4719 gtk_widget_show_all (widget);
4723 toolbar_content_hide_all (ToolbarContent *content)
4727 if (ignore_show_and_hide_all (content))
4730 widget = toolbar_content_get_widget (content);
4732 gtk_widget_hide_all (widget);
4739 get_space_size (GtkToolbar *toolbar)
4741 gint space_size = DEFAULT_SPACE_SIZE;
4745 gtk_widget_style_get (GTK_WIDGET (toolbar),
4746 "space-size", &space_size,
4753 static GtkToolbarSpaceStyle
4754 get_space_style (GtkToolbar *toolbar)
4756 GtkToolbarSpaceStyle space_style = DEFAULT_SPACE_STYLE;
4760 gtk_widget_style_get (GTK_WIDGET (toolbar),
4761 "space-style", &space_style,
4768 static GtkReliefStyle
4769 get_button_relief (GtkToolbar *toolbar)
4771 GtkReliefStyle button_relief = GTK_RELIEF_NORMAL;
4773 gtk_widget_ensure_style (GTK_WIDGET (toolbar));
4775 gtk_widget_style_get (GTK_WIDGET (toolbar),
4776 "button-relief", &button_relief,
4779 return button_relief;
4783 get_internal_padding (GtkToolbar *toolbar)
4787 gtk_widget_style_get (GTK_WIDGET (toolbar),
4788 "internal-padding", &ipadding,
4795 get_max_child_expand (GtkToolbar *toolbar)
4797 gint mexpand = G_MAXINT;
4799 gtk_widget_style_get (GTK_WIDGET (toolbar),
4800 "max-child-expand", &mexpand,
4805 static GtkShadowType
4806 get_shadow_type (GtkToolbar *toolbar)
4808 GtkShadowType shadow_type;
4810 gtk_widget_style_get (GTK_WIDGET (toolbar),
4811 "shadow-type", &shadow_type,
4821 gtk_toolbar_check_old_api (GtkToolbar *toolbar)
4823 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
4825 if (priv->api_mode == NEW_API)
4827 g_warning (MIXED_API_WARNING);
4831 priv->api_mode = OLD_API;
4836 gtk_toolbar_check_new_api (GtkToolbar *toolbar)
4838 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
4840 if (priv->api_mode == OLD_API)
4842 g_warning (MIXED_API_WARNING);
4846 priv->api_mode = NEW_API;
4850 /* GTK+ internal methods */
4853 _gtk_toolbar_get_default_space_size (void)
4855 return DEFAULT_SPACE_SIZE;
4859 _gtk_toolbar_paint_space_line (GtkWidget *widget,
4860 GtkToolbar *toolbar,
4861 const GdkRectangle *area,
4862 const GtkAllocation *allocation)
4864 const double start_fraction = (SPACE_LINE_START / SPACE_LINE_DIVISION);
4865 const double end_fraction = (SPACE_LINE_END / SPACE_LINE_DIVISION);
4867 GtkOrientation orientation;
4869 g_return_if_fail (GTK_IS_WIDGET (widget));
4871 orientation = toolbar? toolbar->orientation : GTK_ORIENTATION_HORIZONTAL;
4873 if (orientation == GTK_ORIENTATION_HORIZONTAL)
4875 gboolean wide_separators;
4876 gint separator_width;
4878 gtk_widget_style_get (widget,
4879 "wide-separators", &wide_separators,
4880 "separator-width", &separator_width,
4883 if (wide_separators)
4884 gtk_paint_box (widget->style, widget->window,
4885 GTK_WIDGET_STATE (widget), GTK_SHADOW_ETCHED_OUT,
4886 area, widget, "vseparator",
4887 allocation->x + (allocation->width - separator_width) / 2,
4888 allocation->y + allocation->height * start_fraction,
4890 allocation->height * (end_fraction - start_fraction));
4892 gtk_paint_vline (widget->style, widget->window,
4893 GTK_WIDGET_STATE (widget), area, widget,
4895 allocation->y + allocation->height * start_fraction,
4896 allocation->y + allocation->height * end_fraction,
4897 allocation->x + (allocation->width - widget->style->xthickness) / 2);
4901 gboolean wide_separators;
4902 gint separator_height;
4904 gtk_widget_style_get (widget,
4905 "wide-separators", &wide_separators,
4906 "separator-height", &separator_height,
4909 if (wide_separators)
4910 gtk_paint_box (widget->style, widget->window,
4911 GTK_WIDGET_STATE (widget), GTK_SHADOW_ETCHED_OUT,
4912 area, widget, "hseparator",
4913 allocation->x + allocation->width * start_fraction,
4914 allocation->y + (allocation->height - separator_height) / 2,
4915 allocation->width * (end_fraction - start_fraction),
4918 gtk_paint_hline (widget->style, widget->window,
4919 GTK_WIDGET_STATE (widget), area, widget,
4921 allocation->x + allocation->width * start_fraction,
4922 allocation->x + allocation->width * end_fraction,
4923 allocation->y + (allocation->height - widget->style->ythickness) / 2);
4928 _gtk_toolbar_elide_underscores (const gchar *original)
4931 const gchar *p, *end;
4933 gboolean last_underscore;
4938 len = strlen (original);
4939 q = result = g_malloc (len + 1);
4940 last_underscore = FALSE;
4942 end = original + len;
4943 for (p = original; p < end; p++)
4945 if (!last_underscore && *p == '_')
4946 last_underscore = TRUE;
4949 last_underscore = FALSE;
4950 if (original + 2 <= p && p + 1 <= end &&
4951 p[-2] == '(' && p[-1] == '_' && p[0] != '_' && p[1] == ')')
4962 if (last_underscore)
4971 toolbar_get_icon_size (GtkToolShell *shell)
4973 return GTK_TOOLBAR (shell)->icon_size;
4976 static GtkOrientation
4977 toolbar_get_orientation (GtkToolShell *shell)
4979 return GTK_TOOLBAR (shell)->orientation;
4982 static GtkToolbarStyle
4983 toolbar_get_style (GtkToolShell *shell)
4985 return GTK_TOOLBAR (shell)->style;
4988 static GtkReliefStyle
4989 toolbar_get_relief_style (GtkToolShell *shell)
4991 return get_button_relief (GTK_TOOLBAR (shell));
4995 toolbar_rebuild_menu (GtkToolShell *shell)
4997 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (shell);
5000 priv->need_rebuild = TRUE;
5002 for (list = priv->content; list != NULL; list = list->next)
5004 ToolbarContent *content = list->data;
5006 toolbar_content_set_unknown_menu_status (content);
5009 gtk_widget_queue_resize (GTK_WIDGET (shell));
5012 #define __GTK_TOOLBAR_C__
5013 #include "gtkaliasdef.c"