1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3 * GtkToolbar copyright (C) Federico Mena
5 * Copyright (C) 2002 Anders Carlsson <andersca@gnome.org>
6 * Copyright (C) 2002 James Henstridge <james@daa.com.au>
7 * Copyright (C) 2003, 2004 Soeren Sandmann <sandmann@daimi.au.dk>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the
21 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 * Boston, MA 02111-1307, USA.
26 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
27 * file for a list of people on the GTK+ Team. See the ChangeLog
28 * files for a list of changes. These files are distributed with
29 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
32 #undef GTK_DISABLE_DEPRECATED
36 #include "gtktoolbar.h"
37 #include "gtkradiotoolbutton.h"
38 #include "gtkseparatortoolitem.h"
40 #include "gtkradiobutton.h"
41 #include "gtktoolbar.h"
42 #include "gtkbindings.h"
43 #include <gdk/gdkkeysyms.h>
44 #include "gtkmarshalers.h"
48 #include "gtkprivate.h"
54 #include "gtkseparatormenuitem.h"
58 typedef struct _ToolbarContent ToolbarContent;
60 #define DEFAULT_IPADDING 0
62 #define DEFAULT_SPACE_SIZE 12
63 #define DEFAULT_SPACE_STYLE GTK_TOOLBAR_SPACE_LINE
64 #define SPACE_LINE_DIVISION 10.0
65 #define SPACE_LINE_START 2.0
66 #define SPACE_LINE_END 8.0
68 #define DEFAULT_ICON_SIZE GTK_ICON_SIZE_LARGE_TOOLBAR
69 #define DEFAULT_TOOLBAR_STYLE GTK_TOOLBAR_BOTH
70 #define DEFAULT_ANIMATION_STATE TRUE
72 #define MAX_HOMOGENEOUS_N_CHARS 13 /* Items that are wider than this do not participate
73 * in the homogeneous game. In units of
74 * pango_font_get_estimated_char_width().
76 #define SLIDE_SPEED 600.0 /* How fast the items slide, in pixels per second */
77 #define ACCEL_THRESHOLD 0.18 /* After how much time in seconds will items start speeding up */
79 #define MIXED_API_WARNING \
80 "Mixing deprecated and non-deprecated GtkToolbar API is not allowed"
94 /* Child properties */
98 CHILD_PROP_HOMOGENEOUS
129 struct _GtkToolbarPrivate
134 GtkWidget * arrow_button;
137 GdkWindow * event_window;
139 GtkSettings * settings;
141 GtkToolItem * highlight_tool_item;
142 gint max_homogeneous_pixels;
146 gulong settings_connection;
148 guint show_arrow : 1;
150 guint is_sliding : 1;
151 guint need_rebuild : 1; /* whether the overflow menu should be regenerated */
155 static void gtk_toolbar_set_property (GObject *object,
159 static void gtk_toolbar_get_property (GObject *object,
163 static gint gtk_toolbar_expose (GtkWidget *widget,
164 GdkEventExpose *event);
165 static void gtk_toolbar_realize (GtkWidget *widget);
166 static void gtk_toolbar_unrealize (GtkWidget *widget);
167 static void gtk_toolbar_size_request (GtkWidget *widget,
168 GtkRequisition *requisition);
169 static void gtk_toolbar_size_allocate (GtkWidget *widget,
170 GtkAllocation *allocation);
171 static void gtk_toolbar_style_set (GtkWidget *widget,
172 GtkStyle *prev_style);
173 static gboolean gtk_toolbar_focus (GtkWidget *widget,
174 GtkDirectionType dir);
175 static void gtk_toolbar_move_focus (GtkWidget *widget,
176 GtkDirectionType dir);
177 static void gtk_toolbar_screen_changed (GtkWidget *widget,
178 GdkScreen *previous_screen);
179 static void gtk_toolbar_map (GtkWidget *widget);
180 static void gtk_toolbar_unmap (GtkWidget *widget);
181 static void gtk_toolbar_set_child_property (GtkContainer *container,
186 static void gtk_toolbar_get_child_property (GtkContainer *container,
191 static void gtk_toolbar_finalize (GObject *object);
192 static void gtk_toolbar_show_all (GtkWidget *widget);
193 static void gtk_toolbar_hide_all (GtkWidget *widget);
194 static void gtk_toolbar_add (GtkContainer *container,
196 static void gtk_toolbar_remove (GtkContainer *container,
198 static void gtk_toolbar_forall (GtkContainer *container,
199 gboolean include_internals,
200 GtkCallback callback,
201 gpointer callback_data);
202 static GType gtk_toolbar_child_type (GtkContainer *container);
203 static void gtk_toolbar_orientation_changed (GtkToolbar *toolbar,
204 GtkOrientation orientation);
205 static void gtk_toolbar_real_style_changed (GtkToolbar *toolbar,
206 GtkToolbarStyle style);
207 static gboolean gtk_toolbar_focus_home_or_end (GtkToolbar *toolbar,
208 gboolean focus_home);
209 static gboolean gtk_toolbar_button_press (GtkWidget *toolbar,
210 GdkEventButton *event);
211 static gboolean gtk_toolbar_arrow_button_press (GtkWidget *button,
212 GdkEventButton *event,
213 GtkToolbar *toolbar);
214 static void gtk_toolbar_arrow_button_clicked (GtkWidget *button,
215 GtkToolbar *toolbar);
216 static void gtk_toolbar_update_button_relief (GtkToolbar *toolbar);
217 static gboolean gtk_toolbar_popup_menu (GtkWidget *toolbar);
218 static GtkWidget *internal_insert_element (GtkToolbar *toolbar,
219 GtkToolbarChildType type,
222 const char *tooltip_text,
223 const char *tooltip_private_text,
225 GtkSignalFunc callback,
229 static void gtk_toolbar_reconfigured (GtkToolbar *toolbar);
230 static gboolean gtk_toolbar_check_new_api (GtkToolbar *toolbar);
231 static gboolean gtk_toolbar_check_old_api (GtkToolbar *toolbar);
233 static GtkReliefStyle get_button_relief (GtkToolbar *toolbar);
234 static gint get_internal_padding (GtkToolbar *toolbar);
235 static gint get_max_child_expand (GtkToolbar *toolbar);
236 static GtkShadowType get_shadow_type (GtkToolbar *toolbar);
237 static gint get_space_size (GtkToolbar *toolbar);
238 static GtkToolbarSpaceStyle get_space_style (GtkToolbar *toolbar);
240 /* methods on ToolbarContent 'class' */
241 static ToolbarContent *toolbar_content_new_tool_item (GtkToolbar *toolbar,
243 gboolean is_placeholder,
245 static ToolbarContent *toolbar_content_new_compatibility (GtkToolbar *toolbar,
246 GtkToolbarChildType type,
251 static void toolbar_content_remove (ToolbarContent *content,
252 GtkToolbar *toolbar);
253 static void toolbar_content_free (ToolbarContent *content);
254 static void toolbar_content_expose (ToolbarContent *content,
255 GtkContainer *container,
256 GdkEventExpose *expose);
257 static gboolean toolbar_content_visible (ToolbarContent *content,
258 GtkToolbar *toolbar);
259 static void toolbar_content_size_request (ToolbarContent *content,
261 GtkRequisition *requisition);
262 static gboolean toolbar_content_is_homogeneous (ToolbarContent *content,
263 GtkToolbar *toolbar);
264 static gboolean toolbar_content_is_placeholder (ToolbarContent *content);
265 static gboolean toolbar_content_disappearing (ToolbarContent *content);
266 static ItemState toolbar_content_get_state (ToolbarContent *content);
267 static gboolean toolbar_content_child_visible (ToolbarContent *content);
268 static void toolbar_content_get_goal_allocation (ToolbarContent *content,
269 GtkAllocation *allocation);
270 static void toolbar_content_get_allocation (ToolbarContent *content,
271 GtkAllocation *allocation);
272 static void toolbar_content_set_start_allocation (ToolbarContent *content,
273 GtkAllocation *new_start_allocation);
274 static void toolbar_content_get_start_allocation (ToolbarContent *content,
275 GtkAllocation *start_allocation);
276 static gboolean toolbar_content_get_expand (ToolbarContent *content);
277 static void toolbar_content_set_goal_allocation (ToolbarContent *content,
278 GtkAllocation *allocation);
279 static void toolbar_content_set_child_visible (ToolbarContent *content,
282 static void toolbar_content_size_allocate (ToolbarContent *content,
283 GtkAllocation *allocation);
284 static void toolbar_content_set_state (ToolbarContent *content,
285 ItemState new_state);
286 static GtkWidget * toolbar_content_get_widget (ToolbarContent *content);
287 static void toolbar_content_set_disappearing (ToolbarContent *content,
288 gboolean disappearing);
289 static void toolbar_content_set_size_request (ToolbarContent *content,
292 static void toolbar_content_toolbar_reconfigured (ToolbarContent *content,
293 GtkToolbar *toolbar);
294 static GtkWidget * toolbar_content_retrieve_menu_item (ToolbarContent *content);
295 static gboolean toolbar_content_has_proxy_menu_item (ToolbarContent *content);
296 static gboolean toolbar_content_is_separator (ToolbarContent *content);
297 static void toolbar_content_show_all (ToolbarContent *content);
298 static void toolbar_content_hide_all (ToolbarContent *content);
299 static void toolbar_content_set_expand (ToolbarContent *content,
302 #define GTK_TOOLBAR_GET_PRIVATE(o) \
303 (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_TOOLBAR, GtkToolbarPrivate))
305 static guint toolbar_signals [LAST_SIGNAL] = { 0 };
307 G_DEFINE_TYPE (GtkToolbar, gtk_toolbar, GTK_TYPE_CONTAINER)
310 add_arrow_bindings (GtkBindingSet *binding_set,
312 GtkDirectionType dir)
314 guint keypad_keysym = keysym - GDK_Left + GDK_KP_Left;
316 gtk_binding_entry_add_signal (binding_set, keysym, 0,
318 GTK_TYPE_DIRECTION_TYPE, dir);
319 gtk_binding_entry_add_signal (binding_set, keypad_keysym, 0,
321 GTK_TYPE_DIRECTION_TYPE, dir);
325 add_ctrl_tab_bindings (GtkBindingSet *binding_set,
326 GdkModifierType modifiers,
327 GtkDirectionType direction)
329 gtk_binding_entry_add_signal (binding_set,
330 GDK_Tab, GDK_CONTROL_MASK | modifiers,
332 GTK_TYPE_DIRECTION_TYPE, direction);
333 gtk_binding_entry_add_signal (binding_set,
334 GDK_KP_Tab, GDK_CONTROL_MASK | modifiers,
336 GTK_TYPE_DIRECTION_TYPE, direction);
340 gtk_toolbar_class_init (GtkToolbarClass *klass)
342 GObjectClass *gobject_class;
343 GtkWidgetClass *widget_class;
344 GtkContainerClass *container_class;
345 GtkBindingSet *binding_set;
347 gobject_class = (GObjectClass *)klass;
348 widget_class = (GtkWidgetClass *)klass;
349 container_class = (GtkContainerClass *)klass;
351 gobject_class->set_property = gtk_toolbar_set_property;
352 gobject_class->get_property = gtk_toolbar_get_property;
353 gobject_class->finalize = gtk_toolbar_finalize;
355 widget_class->button_press_event = gtk_toolbar_button_press;
356 widget_class->expose_event = gtk_toolbar_expose;
357 widget_class->size_request = gtk_toolbar_size_request;
358 widget_class->size_allocate = gtk_toolbar_size_allocate;
359 widget_class->style_set = gtk_toolbar_style_set;
360 widget_class->focus = gtk_toolbar_focus;
362 /* need to override the base class function via override_class_closure,
363 * because the signal slot is not available in GtkWidgetClass
365 g_signal_override_class_closure (g_signal_lookup ("move_focus",
368 g_cclosure_new (G_CALLBACK (gtk_toolbar_move_focus),
371 widget_class->screen_changed = gtk_toolbar_screen_changed;
372 widget_class->realize = gtk_toolbar_realize;
373 widget_class->unrealize = gtk_toolbar_unrealize;
374 widget_class->map = gtk_toolbar_map;
375 widget_class->unmap = gtk_toolbar_unmap;
376 widget_class->popup_menu = gtk_toolbar_popup_menu;
377 widget_class->show_all = gtk_toolbar_show_all;
378 widget_class->hide_all = gtk_toolbar_hide_all;
380 container_class->add = gtk_toolbar_add;
381 container_class->remove = gtk_toolbar_remove;
382 container_class->forall = gtk_toolbar_forall;
383 container_class->child_type = gtk_toolbar_child_type;
384 container_class->get_child_property = gtk_toolbar_get_child_property;
385 container_class->set_child_property = gtk_toolbar_set_child_property;
387 klass->orientation_changed = gtk_toolbar_orientation_changed;
388 klass->style_changed = gtk_toolbar_real_style_changed;
391 * GtkToolbar::orientation-changed:
392 * @toolbar: the object which emitted the signal
393 * @orientation: the new #GtkOrientation of the toolbar
395 * Emitted when the orientation of the toolbar changes.
397 toolbar_signals[ORIENTATION_CHANGED] =
398 g_signal_new (I_("orientation-changed"),
399 G_OBJECT_CLASS_TYPE (klass),
401 G_STRUCT_OFFSET (GtkToolbarClass, orientation_changed),
403 g_cclosure_marshal_VOID__ENUM,
405 GTK_TYPE_ORIENTATION);
407 * GtkToolbar::style-changed:
408 * @toolbar: The #GtkToolbar which emitted the signal
409 * @style: the new #GtkToolbarStyle of the toolbar
411 * Emitted when the style of the toolbar changes.
413 toolbar_signals[STYLE_CHANGED] =
414 g_signal_new (I_("style-changed"),
415 G_OBJECT_CLASS_TYPE (klass),
417 G_STRUCT_OFFSET (GtkToolbarClass, style_changed),
419 g_cclosure_marshal_VOID__ENUM,
421 GTK_TYPE_TOOLBAR_STYLE);
423 * GtkToolbar::popup-context-menu:
424 * @toolbar: the #GtkToolbar which emitted the signal
425 * @x: the x coordinate of the point where the menu should appear
426 * @y: the y coordinate of the point where the menu should appear
427 * @button: the mouse button the user pressed, or -1
429 * Emitted when the user right-clicks the toolbar or uses the
430 * keybinding to display a popup menu.
432 * Application developers should handle this signal if they want
433 * to display a context menu on the toolbar. The context-menu should
434 * appear at the coordinates given by @x and @y. The mouse button
435 * number is given by the @button parameter. If the menu was popped
436 * up using the keybaord, @button is -1.
438 * Return value: return %TRUE if the signal was handled, %FALSE if not
440 toolbar_signals[POPUP_CONTEXT_MENU] =
441 g_signal_new (I_("popup_context_menu"),
442 G_OBJECT_CLASS_TYPE (klass),
444 G_STRUCT_OFFSET (GtkToolbarClass, popup_context_menu),
445 _gtk_boolean_handled_accumulator, NULL,
446 _gtk_marshal_BOOLEAN__INT_INT_INT,
448 G_TYPE_INT, G_TYPE_INT,
452 * GtkToolbar::focus-home-or-end:
453 * @toolbar: the #GtkToolbar which emitted the signal
454 * @focus_home: %TRUE if the first item should be focused
456 * A keybinding signal used internally by GTK+. This signal can't
457 * be used in application code
459 * Return value: %TRUE if the signal was handled, %FALSE if not
461 toolbar_signals[FOCUS_HOME_OR_END] =
462 _gtk_binding_signal_new (I_("focus_home_or_end"),
463 G_OBJECT_CLASS_TYPE (klass),
464 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
465 G_CALLBACK (gtk_toolbar_focus_home_or_end),
467 _gtk_marshal_BOOLEAN__BOOLEAN,
472 g_object_class_install_property (gobject_class,
474 g_param_spec_enum ("orientation",
476 P_("The orientation of the toolbar"),
477 GTK_TYPE_ORIENTATION,
478 GTK_ORIENTATION_HORIZONTAL,
479 GTK_PARAM_READWRITE));
481 g_object_class_install_property (gobject_class,
483 g_param_spec_enum ("toolbar-style",
485 P_("How to draw the toolbar"),
486 GTK_TYPE_TOOLBAR_STYLE,
488 GTK_PARAM_READWRITE));
489 g_object_class_install_property (gobject_class,
491 g_param_spec_boolean ("show-arrow",
493 P_("If an arrow should be shown if the toolbar doesn't fit"),
495 GTK_PARAM_READWRITE));
499 * GtkToolbar:tooltips:
501 * If the tooltips of the toolbar should be active or not.
505 g_object_class_install_property (gobject_class,
507 g_param_spec_boolean ("tooltips",
509 P_("If the tooltips of the toolbar should be active or not"),
511 GTK_PARAM_READWRITE));
515 * GtkToolbar:icon-size:
517 * The size of the icons in a toolbar is normally determined by
518 * the toolbar-icon-size setting. When this property is set, it
519 * overrides the setting.
521 * This should only be used for special-purpose toolbars, normal
522 * application toolbars should respect the user preferences for the
527 g_object_class_install_property (gobject_class,
529 g_param_spec_enum ("icon-size",
531 P_("Size of icons in this toolbar"),
534 GTK_PARAM_READWRITE));
537 * GtkToolbar:icon-size-set:
539 * Is %TRUE if the icon-size property has been set.
543 g_object_class_install_property (gobject_class,
545 g_param_spec_boolean ("icon-size-set",
547 P_("Whether the icon-size property has been set"),
549 GTK_PARAM_READWRITE));
551 /* child properties */
552 gtk_container_class_install_child_property (container_class,
554 g_param_spec_boolean ("expand",
556 P_("Whether the item should receive extra space when the toolbar grows"),
558 GTK_PARAM_READWRITE));
560 gtk_container_class_install_child_property (container_class,
561 CHILD_PROP_HOMOGENEOUS,
562 g_param_spec_boolean ("homogeneous",
564 P_("Whether the item should be the same size as other homogeneous items"),
566 GTK_PARAM_READWRITE));
568 /* style properties */
569 gtk_widget_class_install_style_property (widget_class,
570 g_param_spec_int ("space-size",
572 P_("Size of spacers"),
576 GTK_PARAM_READABLE));
578 gtk_widget_class_install_style_property (widget_class,
579 g_param_spec_int ("internal-padding",
580 P_("Internal padding"),
581 P_("Amount of border space between the toolbar shadow and the buttons"),
585 GTK_PARAM_READABLE));
587 gtk_widget_class_install_style_property (widget_class,
588 g_param_spec_int ("max-child-expand",
589 P_("Maximum child expand"),
590 P_("Maximum amount of space an expandable item will be given"),
594 GTK_PARAM_READABLE));
596 gtk_widget_class_install_style_property (widget_class,
597 g_param_spec_enum ("space-style",
599 P_("Whether spacers are vertical lines or just blank"),
600 GTK_TYPE_TOOLBAR_SPACE_STYLE,
602 GTK_PARAM_READABLE));
604 gtk_widget_class_install_style_property (widget_class,
605 g_param_spec_enum ("button-relief",
607 P_("Type of bevel around toolbar buttons"),
608 GTK_TYPE_RELIEF_STYLE,
610 GTK_PARAM_READABLE));
611 gtk_widget_class_install_style_property (widget_class,
612 g_param_spec_enum ("shadow-type",
614 P_("Style of bevel around the toolbar"),
615 GTK_TYPE_SHADOW_TYPE,
617 GTK_PARAM_READABLE));
619 gtk_settings_install_property (g_param_spec_enum ("gtk-toolbar-style",
621 P_("Whether default toolbars have text only, text and icons, icons only, etc."),
622 GTK_TYPE_TOOLBAR_STYLE,
623 DEFAULT_TOOLBAR_STYLE,
624 GTK_PARAM_READWRITE));
626 gtk_settings_install_property (g_param_spec_enum ("gtk-toolbar-icon-size",
627 P_("Toolbar icon size"),
628 P_("Size of icons in default toolbars"),
631 GTK_PARAM_READWRITE));
633 binding_set = gtk_binding_set_by_class (klass);
635 add_arrow_bindings (binding_set, GDK_Left, GTK_DIR_LEFT);
636 add_arrow_bindings (binding_set, GDK_Right, GTK_DIR_RIGHT);
637 add_arrow_bindings (binding_set, GDK_Up, GTK_DIR_UP);
638 add_arrow_bindings (binding_set, GDK_Down, GTK_DIR_DOWN);
640 gtk_binding_entry_add_signal (binding_set, GDK_KP_Home, 0,
641 "focus_home_or_end", 1,
642 G_TYPE_BOOLEAN, TRUE);
643 gtk_binding_entry_add_signal (binding_set, GDK_Home, 0,
644 "focus_home_or_end", 1,
645 G_TYPE_BOOLEAN, TRUE);
646 gtk_binding_entry_add_signal (binding_set, GDK_KP_End, 0,
647 "focus_home_or_end", 1,
648 G_TYPE_BOOLEAN, FALSE);
649 gtk_binding_entry_add_signal (binding_set, GDK_End, 0,
650 "focus_home_or_end", 1,
651 G_TYPE_BOOLEAN, FALSE);
653 add_ctrl_tab_bindings (binding_set, 0, GTK_DIR_TAB_FORWARD);
654 add_ctrl_tab_bindings (binding_set, GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
656 g_type_class_add_private (gobject_class, sizeof (GtkToolbarPrivate));
660 gtk_toolbar_init (GtkToolbar *toolbar)
662 GtkToolbarPrivate *priv;
664 GTK_WIDGET_UNSET_FLAGS (toolbar, GTK_CAN_FOCUS);
665 GTK_WIDGET_SET_FLAGS (toolbar, GTK_NO_WINDOW);
667 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
669 toolbar->orientation = GTK_ORIENTATION_HORIZONTAL;
670 toolbar->style = DEFAULT_TOOLBAR_STYLE;
671 toolbar->icon_size = DEFAULT_ICON_SIZE;
672 priv->animation = DEFAULT_ANIMATION_STATE;
673 toolbar->tooltips = gtk_tooltips_new ();
674 g_object_ref_sink (toolbar->tooltips);
676 priv->arrow_button = gtk_toggle_button_new ();
677 g_signal_connect (priv->arrow_button, "button_press_event",
678 G_CALLBACK (gtk_toolbar_arrow_button_press), toolbar);
679 g_signal_connect (priv->arrow_button, "clicked",
680 G_CALLBACK (gtk_toolbar_arrow_button_clicked), toolbar);
681 gtk_button_set_relief (GTK_BUTTON (priv->arrow_button),
682 get_button_relief (toolbar));
684 priv->api_mode = DONT_KNOW;
686 gtk_button_set_focus_on_click (GTK_BUTTON (priv->arrow_button), FALSE);
688 priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
689 gtk_widget_set_name (priv->arrow, "gtk-toolbar-arrow");
690 gtk_widget_show (priv->arrow);
691 gtk_container_add (GTK_CONTAINER (priv->arrow_button), priv->arrow);
693 gtk_widget_set_parent (priv->arrow_button, GTK_WIDGET (toolbar));
695 /* which child position a drop will occur at */
697 priv->show_arrow = TRUE;
698 priv->settings = NULL;
700 priv->max_homogeneous_pixels = -1;
702 priv->timer = g_timer_new ();
706 gtk_toolbar_set_property (GObject *object,
711 GtkToolbar *toolbar = GTK_TOOLBAR (object);
715 case PROP_ORIENTATION:
716 gtk_toolbar_set_orientation (toolbar, g_value_get_enum (value));
718 case PROP_TOOLBAR_STYLE:
719 gtk_toolbar_set_style (toolbar, g_value_get_enum (value));
721 case PROP_SHOW_ARROW:
722 gtk_toolbar_set_show_arrow (toolbar, g_value_get_boolean (value));
725 gtk_toolbar_set_tooltips (toolbar, g_value_get_boolean (value));
728 gtk_toolbar_set_icon_size (toolbar, g_value_get_enum (value));
730 case PROP_ICON_SIZE_SET:
731 if (g_value_get_boolean (value))
732 toolbar->icon_size_set = TRUE;
734 gtk_toolbar_unset_icon_size (toolbar);
737 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
743 gtk_toolbar_get_property (GObject *object,
748 GtkToolbar *toolbar = GTK_TOOLBAR (object);
749 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
753 case PROP_ORIENTATION:
754 g_value_set_enum (value, toolbar->orientation);
756 case PROP_TOOLBAR_STYLE:
757 g_value_set_enum (value, toolbar->style);
759 case PROP_SHOW_ARROW:
760 g_value_set_boolean (value, priv->show_arrow);
763 g_value_set_boolean (value, gtk_toolbar_get_tooltips (toolbar));
766 g_value_set_enum (value, gtk_toolbar_get_icon_size (toolbar));
768 case PROP_ICON_SIZE_SET:
769 g_value_set_boolean (value, toolbar->icon_size_set);
772 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
778 gtk_toolbar_map (GtkWidget *widget)
780 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
782 GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->map (widget);
784 if (priv->event_window)
785 gdk_window_show_unraised (priv->event_window);
789 gtk_toolbar_unmap (GtkWidget *widget)
791 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
793 if (priv->event_window)
794 gdk_window_hide (priv->event_window);
796 GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unmap (widget);
800 gtk_toolbar_realize (GtkWidget *widget)
802 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
803 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
805 GdkWindowAttr attributes;
806 gint attributes_mask;
809 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
811 border_width = GTK_CONTAINER (widget)->border_width;
813 attributes.wclass = GDK_INPUT_ONLY;
814 attributes.window_type = GDK_WINDOW_CHILD;
815 attributes.x = widget->allocation.x + border_width;
816 attributes.y = widget->allocation.y + border_width;
817 attributes.width = widget->allocation.width - border_width * 2;
818 attributes.height = widget->allocation.height - border_width * 2;
819 attributes.event_mask = gtk_widget_get_events (widget);
820 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
821 GDK_BUTTON_RELEASE_MASK |
822 GDK_ENTER_NOTIFY_MASK |
823 GDK_LEAVE_NOTIFY_MASK);
825 attributes_mask = GDK_WA_X | GDK_WA_Y;
827 widget->window = gtk_widget_get_parent_window (widget);
828 g_object_ref (widget->window);
829 widget->style = gtk_style_attach (widget->style, widget->window);
831 priv->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
832 &attributes, attributes_mask);
833 gdk_window_set_user_data (priv->event_window, toolbar);
837 gtk_toolbar_unrealize (GtkWidget *widget)
839 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
841 if (priv->event_window)
843 gdk_window_set_user_data (priv->event_window, NULL);
844 gdk_window_destroy (priv->event_window);
845 priv->event_window = NULL;
848 if (GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unrealize)
849 (* GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unrealize) (widget);
853 gtk_toolbar_expose (GtkWidget *widget,
854 GdkEventExpose *event)
856 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
857 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
862 border_width = GTK_CONTAINER (widget)->border_width;
864 if (GTK_WIDGET_DRAWABLE (widget))
866 gtk_paint_box (widget->style,
868 GTK_WIDGET_STATE (widget),
869 get_shadow_type (toolbar),
870 &event->area, widget, "toolbar",
871 border_width + widget->allocation.x,
872 border_width + widget->allocation.y,
873 widget->allocation.width - 2 * border_width,
874 widget->allocation.height - 2 * border_width);
877 for (list = priv->content; list != NULL; list = list->next)
879 ToolbarContent *content = list->data;
881 toolbar_content_expose (content, GTK_CONTAINER (widget), event);
884 gtk_container_propagate_expose (GTK_CONTAINER (widget),
892 gtk_toolbar_size_request (GtkWidget *widget,
893 GtkRequisition *requisition)
895 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
896 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
898 gint max_child_height;
899 gint max_child_width;
900 gint max_homogeneous_child_width;
901 gint max_homogeneous_child_height;
902 gint homogeneous_size;
904 gint pack_front_size;
906 GtkRequisition arrow_requisition;
908 max_homogeneous_child_width = 0;
909 max_homogeneous_child_height = 0;
911 max_child_height = 0;
912 for (list = priv->content; list != NULL; list = list->next)
914 GtkRequisition requisition;
915 ToolbarContent *content = list->data;
917 if (!toolbar_content_visible (content, toolbar))
920 toolbar_content_size_request (content, toolbar, &requisition);
922 max_child_width = MAX (max_child_width, requisition.width);
923 max_child_height = MAX (max_child_height, requisition.height);
925 if (toolbar_content_is_homogeneous (content, toolbar))
927 max_homogeneous_child_width = MAX (max_homogeneous_child_width, requisition.width);
928 max_homogeneous_child_height = MAX (max_homogeneous_child_height, requisition.height);
932 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
933 homogeneous_size = max_homogeneous_child_width;
935 homogeneous_size = max_homogeneous_child_height;
938 for (list = priv->content; list != NULL; list = list->next)
940 ToolbarContent *content = list->data;
943 if (!toolbar_content_visible (content, toolbar))
946 if (toolbar_content_is_homogeneous (content, toolbar))
948 size = homogeneous_size;
952 GtkRequisition requisition;
954 toolbar_content_size_request (content, toolbar, &requisition);
956 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
957 size = requisition.width;
959 size = requisition.height;
962 pack_front_size += size;
965 if (priv->show_arrow && priv->api_mode == NEW_API)
967 gtk_widget_size_request (priv->arrow_button, &arrow_requisition);
969 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
970 long_req = arrow_requisition.width;
972 long_req = arrow_requisition.height;
974 /* There is no point requesting space for the arrow if that would take
975 * up more space than all the items combined
977 long_req = MIN (long_req, pack_front_size);
981 arrow_requisition.height = 0;
982 arrow_requisition.width = 0;
984 long_req = pack_front_size;
987 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
989 requisition->width = long_req;
990 requisition->height = MAX (max_child_height, arrow_requisition.height);
994 requisition->height = long_req;
995 requisition->width = MAX (max_child_width, arrow_requisition.width);
999 ipadding = get_internal_padding (toolbar);
1001 requisition->width += 2 * (ipadding + GTK_CONTAINER (toolbar)->border_width);
1002 requisition->height += 2 * (ipadding + GTK_CONTAINER (toolbar)->border_width);
1004 if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
1006 requisition->width += 2 * widget->style->xthickness;
1007 requisition->height += 2 * widget->style->ythickness;
1010 toolbar->button_maxw = max_homogeneous_child_width;
1011 toolbar->button_maxh = max_homogeneous_child_height;
1015 position (GtkToolbar *toolbar,
1022 if (! GTK_TOOLBAR_GET_PRIVATE (toolbar)->animation)
1025 if (elapsed <= ACCEL_THRESHOLD)
1027 n_pixels = SLIDE_SPEED * elapsed;
1031 /* The formula is a second degree polynomial in
1032 * @elapsed that has the line SLIDE_SPEED * @elapsed
1033 * as tangent for @elapsed == ACCEL_THRESHOLD.
1034 * This makes @n_pixels a smooth function of elapsed time.
1036 n_pixels = (SLIDE_SPEED / ACCEL_THRESHOLD) * elapsed * elapsed -
1037 SLIDE_SPEED * elapsed + SLIDE_SPEED * ACCEL_THRESHOLD;
1041 return MIN (from + n_pixels, to);
1043 return MAX (from - n_pixels, to);
1047 compute_intermediate_allocation (GtkToolbar *toolbar,
1048 const GtkAllocation *start,
1049 const GtkAllocation *goal,
1050 GtkAllocation *intermediate)
1052 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1053 gdouble elapsed = g_timer_elapsed (priv->timer, NULL);
1055 intermediate->x = position (toolbar, start->x, goal->x, elapsed);
1056 intermediate->y = position (toolbar, start->y, goal->y, elapsed);
1057 intermediate->width = position (toolbar, start->x + start->width,
1058 goal->x + goal->width,
1059 elapsed) - intermediate->x;
1060 intermediate->height = position (toolbar, start->y + start->height,
1061 goal->y + goal->height,
1062 elapsed) - intermediate->y;
1066 fixup_allocation_for_rtl (gint total_size,
1067 GtkAllocation *allocation)
1069 allocation->x += (total_size - (2 * allocation->x + allocation->width));
1073 fixup_allocation_for_vertical (GtkAllocation *allocation)
1077 tmp = allocation->x;
1078 allocation->x = allocation->y;
1079 allocation->y = tmp;
1081 tmp = allocation->width;
1082 allocation->width = allocation->height;
1083 allocation->height = tmp;
1087 get_item_size (GtkToolbar *toolbar,
1088 ToolbarContent *content)
1090 GtkRequisition requisition;
1092 toolbar_content_size_request (content, toolbar, &requisition);
1094 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
1096 if (toolbar_content_is_homogeneous (content, toolbar))
1097 return toolbar->button_maxw;
1099 return requisition.width;
1103 if (toolbar_content_is_homogeneous (content, toolbar))
1104 return toolbar->button_maxh;
1106 return requisition.height;
1111 slide_idle_handler (gpointer data)
1113 GtkToolbar *toolbar = data;
1114 GtkToolbarPrivate *priv;
1117 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1119 if (priv->need_sync)
1122 priv->need_sync = FALSE;
1125 for (list = priv->content; list != NULL; list = list->next)
1127 ToolbarContent *content = list->data;
1129 GtkAllocation goal_allocation;
1130 GtkAllocation allocation;
1133 state = toolbar_content_get_state (content);
1134 toolbar_content_get_goal_allocation (content, &goal_allocation);
1135 toolbar_content_get_allocation (content, &allocation);
1139 if (state == NOT_ALLOCATED)
1141 /* an unallocated item means that size allocate has to
1142 * called at least once more
1147 /* An invisible item with a goal allocation of
1148 * 0 is already at its goal.
1150 if ((state == NORMAL || state == OVERFLOWN) &&
1151 ((goal_allocation.width != 0 &&
1152 goal_allocation.height != 0) ||
1153 toolbar_content_child_visible (content)))
1155 if ((goal_allocation.x != allocation.x ||
1156 goal_allocation.y != allocation.y ||
1157 goal_allocation.width != allocation.width ||
1158 goal_allocation.height != allocation.height))
1160 /* An item is not in its right position yet. Note
1161 * that OVERFLOWN items do get an allocation in
1162 * gtk_toolbar_size_allocate(). This way you can see
1163 * them slide back in when you drag an item off the
1170 if (toolbar_content_is_placeholder (content) &&
1171 toolbar_content_disappearing (content) &&
1172 toolbar_content_child_visible (content))
1174 /* A disappearing placeholder is still visible.
1182 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1184 GDK_THREADS_LEAVE ();
1189 priv->is_sliding = FALSE;
1196 rect_within (GtkAllocation *a1,
1199 return (a1->x >= a2->x &&
1200 a1->x + a1->width <= a2->x + a2->width &&
1202 a1->y + a1->height <= a2->y + a2->height);
1206 gtk_toolbar_begin_sliding (GtkToolbar *toolbar)
1208 GtkWidget *widget = GTK_WIDGET (toolbar);
1209 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1217 /* Start the sliding. This function copies the allocation of every
1218 * item into content->start_allocation. For items that haven't
1219 * been allocated yet, we calculate their position and save that
1220 * in start_allocatino along with zero width and zero height.
1222 * FIXME: It would be nice if we could share this code with
1223 * the equivalent in gtk_widget_size_allocate().
1225 priv->is_sliding = TRUE;
1228 priv->idle_id = gdk_threads_add_idle (slide_idle_handler, toolbar);
1230 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1231 vertical = (toolbar->orientation == GTK_ORIENTATION_VERTICAL);
1232 border_width = get_internal_padding (toolbar) + GTK_CONTAINER (toolbar)->border_width;
1236 cur_x = widget->allocation.width - border_width - widget->style->xthickness;
1237 cur_y = widget->allocation.height - border_width - widget->style->ythickness;
1241 cur_x = border_width + widget->style->xthickness;
1242 cur_y = border_width + widget->style->ythickness;
1245 cur_x += widget->allocation.x;
1246 cur_y += widget->allocation.y;
1248 for (list = priv->content; list != NULL; list = list->next)
1250 ToolbarContent *content = list->data;
1251 GtkAllocation new_start_allocation;
1252 GtkAllocation item_allocation;
1255 state = toolbar_content_get_state (content);
1256 toolbar_content_get_allocation (content, &item_allocation);
1258 if ((state == NORMAL &&
1259 rect_within (&item_allocation, &(widget->allocation))) ||
1262 new_start_allocation = item_allocation;
1266 new_start_allocation.x = cur_x;
1267 new_start_allocation.y = cur_y;
1271 new_start_allocation.width = widget->allocation.width -
1272 2 * border_width - 2 * widget->style->xthickness;
1273 new_start_allocation.height = 0;
1277 new_start_allocation.width = 0;
1278 new_start_allocation.height = widget->allocation.height -
1279 2 * border_width - 2 * widget->style->ythickness;
1284 cur_y = new_start_allocation.y + new_start_allocation.height;
1286 cur_x = new_start_allocation.x;
1288 cur_x = new_start_allocation.x + new_start_allocation.width;
1290 toolbar_content_set_start_allocation (content, &new_start_allocation);
1293 /* This resize will run before the first idle handler. This
1294 * will make sure that items get the right goal allocation
1295 * so that the idle handler will not immediately return
1298 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1299 g_timer_reset (priv->timer);
1303 gtk_toolbar_stop_sliding (GtkToolbar *toolbar)
1305 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1307 if (priv->is_sliding)
1311 priv->is_sliding = FALSE;
1315 g_source_remove (priv->idle_id);
1319 list = priv->content;
1322 ToolbarContent *content = list->data;
1325 if (toolbar_content_is_placeholder (content))
1327 toolbar_content_remove (content, toolbar);
1328 toolbar_content_free (content);
1332 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1337 remove_item (GtkWidget *menu_item,
1340 gtk_container_remove (GTK_CONTAINER (menu_item->parent), menu_item);
1344 menu_deactivated (GtkWidget *menu,
1345 GtkToolbar *toolbar)
1347 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1348 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->arrow_button), FALSE);
1352 menu_detached (GtkWidget *toolbar,
1355 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1360 rebuild_menu (GtkToolbar *toolbar)
1362 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1363 GList *list, *children;
1367 priv->menu = GTK_MENU (gtk_menu_new());
1368 gtk_menu_attach_to_widget (priv->menu,
1369 GTK_WIDGET (toolbar),
1372 g_signal_connect (priv->menu, "deactivate", G_CALLBACK (menu_deactivated), toolbar);
1375 gtk_container_foreach (GTK_CONTAINER (priv->menu), remove_item, NULL);
1377 for (list = priv->content; list != NULL; list = list->next)
1379 ToolbarContent *content = list->data;
1381 if (toolbar_content_get_state (content) == OVERFLOWN &&
1382 !toolbar_content_is_placeholder (content))
1384 GtkWidget *menu_item = toolbar_content_retrieve_menu_item (content);
1388 g_assert (GTK_IS_MENU_ITEM (menu_item));
1389 gtk_menu_shell_append (GTK_MENU_SHELL (priv->menu), menu_item);
1394 /* Remove leading and trailing separator items */
1395 children = gtk_container_get_children (GTK_CONTAINER (priv->menu));
1398 while (list && GTK_IS_SEPARATOR_MENU_ITEM (list->data))
1400 GtkWidget *child = list->data;
1402 gtk_container_remove (GTK_CONTAINER (priv->menu), child);
1405 g_list_free (children);
1407 /* Regenerate the list of children so we don't try to remove items twice */
1408 children = gtk_container_get_children (GTK_CONTAINER (priv->menu));
1410 list = g_list_last (children);
1411 while (list && GTK_IS_SEPARATOR_MENU_ITEM (list->data))
1413 GtkWidget *child = list->data;
1415 gtk_container_remove (GTK_CONTAINER (priv->menu), child);
1418 g_list_free (children);
1420 priv->need_rebuild = FALSE;
1424 gtk_toolbar_size_allocate (GtkWidget *widget,
1425 GtkAllocation *allocation)
1427 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1428 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1429 GtkAllocation *allocations;
1430 ItemState *new_states;
1431 GtkAllocation arrow_allocation;
1433 gint size, pos, short_size;
1436 gboolean need_arrow;
1437 gint n_expand_items;
1439 gint available_size;
1442 GtkRequisition arrow_requisition;
1443 gboolean overflowing;
1444 gboolean size_changed;
1446 GtkAllocation item_area;
1447 GtkShadowType shadow_type;
1449 size_changed = FALSE;
1450 if (widget->allocation.x != allocation->x ||
1451 widget->allocation.y != allocation->y ||
1452 widget->allocation.width != allocation->width ||
1453 widget->allocation.height != allocation->height)
1455 size_changed = TRUE;
1459 gtk_toolbar_stop_sliding (toolbar);
1461 widget->allocation = *allocation;
1463 border_width = GTK_CONTAINER (toolbar)->border_width;
1465 if (GTK_WIDGET_REALIZED (widget))
1467 gdk_window_move_resize (priv->event_window,
1468 allocation->x + border_width,
1469 allocation->y + border_width,
1470 allocation->width - border_width * 2,
1471 allocation->height - border_width * 2);
1474 border_width += get_internal_padding (toolbar);
1476 gtk_widget_get_child_requisition (GTK_WIDGET (priv->arrow_button),
1477 &arrow_requisition);
1479 shadow_type = get_shadow_type (toolbar);
1481 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
1483 available_size = size = allocation->width - 2 * border_width;
1484 short_size = allocation->height - 2 * border_width;
1485 arrow_size = arrow_requisition.width;
1487 if (shadow_type != GTK_SHADOW_NONE)
1489 available_size -= 2 * widget->style->xthickness;
1490 short_size -= 2 * widget->style->ythickness;
1495 available_size = size = allocation->height - 2 * border_width;
1496 short_size = allocation->width - 2 * border_width;
1497 arrow_size = arrow_requisition.height;
1499 if (shadow_type != GTK_SHADOW_NONE)
1501 available_size -= 2 * widget->style->ythickness;
1502 short_size -= 2 * widget->style->xthickness;
1506 n_items = g_list_length (priv->content);
1507 allocations = g_new0 (GtkAllocation, n_items);
1508 new_states = g_new0 (ItemState, n_items);
1512 for (list = priv->content; list != NULL; list = list->next)
1514 ToolbarContent *content = list->data;
1516 if (toolbar_content_visible (content, toolbar))
1518 needed_size += get_item_size (toolbar, content);
1520 /* Do we need an arrow?
1522 * Assume we don't, and see if any non-separator item with a
1523 * proxy menu item is then going to overflow.
1525 if (needed_size > available_size &&
1528 priv->api_mode == NEW_API &&
1529 toolbar_content_has_proxy_menu_item (content) &&
1530 !toolbar_content_is_separator (content))
1538 size = available_size - arrow_size;
1540 size = available_size;
1542 /* calculate widths and states of items */
1543 overflowing = FALSE;
1544 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1546 ToolbarContent *content = list->data;
1549 if (!toolbar_content_visible (content, toolbar))
1551 new_states[i] = HIDDEN;
1555 item_size = get_item_size (toolbar, content);
1556 if (item_size <= size && !overflowing)
1559 allocations[i].width = item_size;
1560 new_states[i] = NORMAL;
1565 new_states[i] = OVERFLOWN;
1566 allocations[i].width = item_size;
1570 /* calculate width of arrow */
1573 arrow_allocation.width = arrow_size;
1574 arrow_allocation.height = MAX (short_size, 1);
1577 /* expand expandable items */
1579 /* We don't expand when there is an overflow menu, because that leads to
1580 * weird jumps when items get moved to the overflow menu and the expanding
1581 * items suddenly get a lot of extra space
1585 gint max_child_expand;
1588 for (i = 0, list = priv->content; list != NULL; list = list->next, ++i)
1590 ToolbarContent *content = list->data;
1592 if (toolbar_content_get_expand (content) && new_states[i] == NORMAL)
1596 max_child_expand = get_max_child_expand (toolbar);
1597 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1599 ToolbarContent *content = list->data;
1601 if (toolbar_content_get_expand (content) && new_states[i] == NORMAL)
1603 gint extra = size / n_expand_items;
1604 if (size % n_expand_items != 0)
1607 if (extra > max_child_expand)
1608 extra = max_child_expand;
1610 allocations[i].width += extra;
1616 g_assert (n_expand_items == 0);
1619 /* position items */
1621 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1623 /* both NORMAL and OVERFLOWN items get a position. This ensures
1624 * that sliding will work for OVERFLOWN items too
1626 if (new_states[i] == NORMAL ||
1627 new_states[i] == OVERFLOWN)
1629 allocations[i].x = pos;
1630 allocations[i].y = border_width;
1631 allocations[i].height = short_size;
1633 pos += allocations[i].width;
1637 /* position arrow */
1640 arrow_allocation.x = available_size - border_width - arrow_allocation.width;
1641 arrow_allocation.y = border_width;
1644 item_area.x = border_width;
1645 item_area.y = border_width;
1646 item_area.width = available_size - (need_arrow? arrow_size : 0);
1647 item_area.height = short_size;
1649 /* fix up allocations in the vertical or RTL cases */
1650 if (toolbar->orientation == GTK_ORIENTATION_VERTICAL)
1652 for (i = 0; i < n_items; ++i)
1653 fixup_allocation_for_vertical (&(allocations[i]));
1656 fixup_allocation_for_vertical (&arrow_allocation);
1658 fixup_allocation_for_vertical (&item_area);
1660 else if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL)
1662 for (i = 0; i < n_items; ++i)
1663 fixup_allocation_for_rtl (available_size, &(allocations[i]));
1666 fixup_allocation_for_rtl (available_size, &arrow_allocation);
1668 fixup_allocation_for_rtl (available_size, &item_area);
1671 /* translate the items by allocation->(x,y) */
1672 for (i = 0; i < n_items; ++i)
1674 allocations[i].x += allocation->x;
1675 allocations[i].y += allocation->y;
1677 if (shadow_type != GTK_SHADOW_NONE)
1679 allocations[i].x += widget->style->xthickness;
1680 allocations[i].y += widget->style->ythickness;
1686 arrow_allocation.x += allocation->x;
1687 arrow_allocation.y += allocation->y;
1689 if (shadow_type != GTK_SHADOW_NONE)
1691 arrow_allocation.x += widget->style->xthickness;
1692 arrow_allocation.y += widget->style->ythickness;
1696 item_area.x += allocation->x;
1697 item_area.y += allocation->y;
1698 if (shadow_type != GTK_SHADOW_NONE)
1700 item_area.x += widget->style->xthickness;
1701 item_area.y += widget->style->ythickness;
1704 /* did anything change? */
1705 for (list = priv->content, i = 0; list != NULL; list = list->next, i++)
1707 ToolbarContent *content = list->data;
1709 if (toolbar_content_get_state (content) == NORMAL &&
1710 new_states[i] != NORMAL)
1712 /* an item disappeared and we didn't change size, so begin sliding */
1713 if (!size_changed && priv->api_mode == NEW_API)
1714 gtk_toolbar_begin_sliding (toolbar);
1718 /* finally allocate the items */
1719 if (priv->is_sliding)
1721 for (list = priv->content, i = 0; list != NULL; list = list->next, i++)
1723 ToolbarContent *content = list->data;
1725 toolbar_content_set_goal_allocation (content, &(allocations[i]));
1729 elapsed = g_timer_elapsed (priv->timer, NULL);
1730 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1732 ToolbarContent *content = list->data;
1734 if (new_states[i] == OVERFLOWN ||
1735 new_states[i] == NORMAL)
1737 GtkAllocation alloc;
1738 GtkAllocation start_allocation = { 0, };
1739 GtkAllocation goal_allocation;
1741 if (priv->is_sliding)
1743 toolbar_content_get_start_allocation (content, &start_allocation);
1744 toolbar_content_get_goal_allocation (content, &goal_allocation);
1746 compute_intermediate_allocation (toolbar,
1751 priv->need_sync = TRUE;
1755 alloc = allocations[i];
1758 if (alloc.width <= 0 || alloc.height <= 0)
1760 toolbar_content_set_child_visible (content, toolbar, FALSE);
1764 if (!rect_within (&alloc, &item_area))
1766 toolbar_content_set_child_visible (content, toolbar, FALSE);
1767 toolbar_content_size_allocate (content, &alloc);
1771 toolbar_content_set_child_visible (content, toolbar, TRUE);
1772 toolbar_content_size_allocate (content, &alloc);
1778 toolbar_content_set_child_visible (content, toolbar, FALSE);
1781 toolbar_content_set_state (content, new_states[i]);
1784 if (priv->menu && priv->need_rebuild)
1785 rebuild_menu (toolbar);
1789 gtk_widget_size_allocate (GTK_WIDGET (priv->arrow_button),
1791 gtk_widget_show (GTK_WIDGET (priv->arrow_button));
1795 gtk_widget_hide (GTK_WIDGET (priv->arrow_button));
1797 if (priv->menu && GTK_WIDGET_VISIBLE (priv->menu))
1798 gtk_menu_shell_deactivate (GTK_MENU_SHELL (priv->menu));
1801 g_free (allocations);
1802 g_free (new_states);
1806 gtk_toolbar_update_button_relief (GtkToolbar *toolbar)
1808 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1809 GtkReliefStyle relief;
1811 relief = get_button_relief (toolbar);
1813 if (relief != gtk_button_get_relief (GTK_BUTTON (priv->arrow_button)))
1815 gtk_toolbar_reconfigured (toolbar);
1817 gtk_button_set_relief (GTK_BUTTON (priv->arrow_button), relief);
1822 gtk_toolbar_style_set (GtkWidget *widget,
1823 GtkStyle *prev_style)
1825 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
1827 priv->max_homogeneous_pixels = -1;
1829 if (GTK_WIDGET_REALIZED (widget))
1830 gtk_style_set_background (widget->style, widget->window, widget->state);
1833 gtk_toolbar_update_button_relief (GTK_TOOLBAR (widget));
1837 gtk_toolbar_list_children_in_focus_order (GtkToolbar *toolbar,
1838 GtkDirectionType dir)
1840 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1841 GList *result = NULL;
1845 /* generate list of children in reverse logical order */
1847 for (list = priv->content; list != NULL; list = list->next)
1849 ToolbarContent *content = list->data;
1852 widget = toolbar_content_get_widget (content);
1855 result = g_list_prepend (result, widget);
1858 result = g_list_prepend (result, priv->arrow_button);
1860 rtl = (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL);
1862 /* move in logical order when
1864 * - dir is TAB_FORWARD
1866 * - in RTL mode and moving left or up
1868 * - in LTR mode and moving right or down
1870 if (dir == GTK_DIR_TAB_FORWARD ||
1871 (rtl && (dir == GTK_DIR_UP || dir == GTK_DIR_LEFT)) ||
1872 (!rtl && (dir == GTK_DIR_DOWN || dir == GTK_DIR_RIGHT)))
1874 result = g_list_reverse (result);
1881 gtk_toolbar_focus_home_or_end (GtkToolbar *toolbar,
1882 gboolean focus_home)
1884 GList *children, *list;
1885 GtkDirectionType dir = focus_home? GTK_DIR_RIGHT : GTK_DIR_LEFT;
1887 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1889 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL)
1891 children = g_list_reverse (children);
1893 dir = (dir == GTK_DIR_RIGHT)? GTK_DIR_LEFT : GTK_DIR_RIGHT;
1896 for (list = children; list != NULL; list = list->next)
1898 GtkWidget *child = list->data;
1900 if (GTK_CONTAINER (toolbar)->focus_child == child)
1903 if (GTK_WIDGET_MAPPED (child) && gtk_widget_child_focus (child, dir))
1907 g_list_free (children);
1912 /* Keybinding handler. This function is called when the user presses
1913 * Ctrl TAB or an arrow key.
1916 gtk_toolbar_move_focus (GtkWidget *widget,
1917 GtkDirectionType dir)
1919 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1920 GtkContainer *container = GTK_CONTAINER (toolbar);
1922 gboolean try_focus = FALSE;
1925 if (container->focus_child &&
1926 gtk_widget_child_focus (container->focus_child, dir))
1931 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1933 for (list = children; list != NULL; list = list->next)
1935 GtkWidget *child = list->data;
1937 if (try_focus && GTK_WIDGET_MAPPED (child) && gtk_widget_child_focus (child, dir))
1940 if (child == GTK_CONTAINER (toolbar)->focus_child)
1944 g_list_free (children);
1947 /* The focus handler for the toolbar. It called when the user presses
1948 * TAB or otherwise tries to focus the toolbar.
1951 gtk_toolbar_focus (GtkWidget *widget,
1952 GtkDirectionType dir)
1954 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1955 GList *children, *list;
1956 gboolean result = FALSE;
1958 /* if focus is already somewhere inside the toolbar then return FALSE.
1959 * The only way focus can stay inside the toolbar is when the user presses
1960 * arrow keys or Ctrl TAB (both of which are handled by the
1961 * gtk_toolbar_move_focus() keybinding function.
1963 if (GTK_CONTAINER (widget)->focus_child)
1966 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1968 for (list = children; list != NULL; list = list->next)
1970 GtkWidget *child = list->data;
1972 if (GTK_WIDGET_MAPPED (child) && gtk_widget_child_focus (child, dir))
1979 g_list_free (children);
1984 static GtkSettings *
1985 toolbar_get_settings (GtkToolbar *toolbar)
1987 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1988 return priv->settings;
1992 style_change_notify (GtkToolbar *toolbar)
1994 if (!toolbar->style_set)
1996 /* pretend it was set, then unset, thus reverting to new default */
1997 toolbar->style_set = TRUE;
1998 gtk_toolbar_unset_style (toolbar);
2003 icon_size_change_notify (GtkToolbar *toolbar)
2005 if (!toolbar->icon_size_set)
2007 /* pretend it was set, then unset, thus reverting to new default */
2008 toolbar->icon_size_set = TRUE;
2009 gtk_toolbar_unset_icon_size (toolbar);
2014 animation_change_notify (GtkToolbar *toolbar)
2016 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2017 GtkSettings *settings = toolbar_get_settings (toolbar);
2021 g_object_get (settings,
2022 "gtk-enable-animations", &animation,
2025 animation = DEFAULT_ANIMATION_STATE;
2027 priv->animation = animation;
2031 settings_change_notify (GtkSettings *settings,
2032 const GParamSpec *pspec,
2033 GtkToolbar *toolbar)
2035 if (! strcmp (pspec->name, "gtk-toolbar-style"))
2036 style_change_notify (toolbar);
2037 else if (! strcmp (pspec->name, "gtk-toolbar-icon-size"))
2038 icon_size_change_notify (toolbar);
2039 else if (! strcmp (pspec->name, "gtk-enable-animations"))
2040 animation_change_notify (toolbar);
2044 gtk_toolbar_screen_changed (GtkWidget *widget,
2045 GdkScreen *previous_screen)
2047 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
2048 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
2049 GtkSettings *old_settings = toolbar_get_settings (toolbar);
2050 GtkSettings *settings;
2052 if (gtk_widget_has_screen (GTK_WIDGET (toolbar)))
2053 settings = gtk_widget_get_settings (GTK_WIDGET (toolbar));
2057 if (settings == old_settings)
2062 g_signal_handler_disconnect (old_settings, priv->settings_connection);
2064 g_object_unref (old_settings);
2069 priv->settings_connection =
2070 g_signal_connect (settings, "notify",
2071 G_CALLBACK (settings_change_notify),
2074 priv->settings = g_object_ref (settings);
2077 priv->settings = NULL;
2079 style_change_notify (toolbar);
2080 icon_size_change_notify (toolbar);
2081 animation_change_notify (toolbar);
2085 find_drop_index (GtkToolbar *toolbar,
2089 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2090 GList *interesting_content;
2092 GtkOrientation orientation;
2093 GtkTextDirection direction;
2094 gint best_distance = G_MAXINT;
2098 ToolbarContent *best_content;
2099 GtkAllocation allocation;
2101 /* list items we care about wrt. drag and drop */
2102 interesting_content = NULL;
2103 for (list = priv->content; list != NULL; list = list->next)
2105 ToolbarContent *content = list->data;
2107 if (toolbar_content_get_state (content) == NORMAL)
2108 interesting_content = g_list_prepend (interesting_content, content);
2110 interesting_content = g_list_reverse (interesting_content);
2112 if (!interesting_content)
2115 orientation = toolbar->orientation;
2116 direction = gtk_widget_get_direction (GTK_WIDGET (toolbar));
2118 /* distance to first interesting item */
2119 best_content = interesting_content->data;
2120 toolbar_content_get_allocation (best_content, &allocation);
2122 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2126 if (direction == GTK_TEXT_DIR_LTR)
2129 pos = allocation.x + allocation.width;
2137 best_content = NULL;
2138 best_distance = ABS (pos - cursor);
2140 /* distance to far end of each item */
2141 for (list = interesting_content; list != NULL; list = list->next)
2143 ToolbarContent *content = list->data;
2145 toolbar_content_get_allocation (content, &allocation);
2147 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2149 if (direction == GTK_TEXT_DIR_LTR)
2150 pos = allocation.x + allocation.width;
2156 pos = allocation.y + allocation.height;
2159 distance = ABS (pos - cursor);
2161 if (distance < best_distance)
2163 best_distance = distance;
2164 best_content = content;
2168 g_list_free (interesting_content);
2173 return g_list_index (priv->content, best_content) + 1;
2177 reset_all_placeholders (GtkToolbar *toolbar)
2179 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2182 for (list = priv->content; list != NULL; list = list->next)
2184 ToolbarContent *content = list->data;
2185 if (toolbar_content_is_placeholder (content))
2186 toolbar_content_set_disappearing (content, TRUE);
2191 physical_to_logical (GtkToolbar *toolbar,
2194 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2198 g_assert (physical >= 0);
2201 for (list = priv->content; list && physical > 0; list = list->next)
2203 ToolbarContent *content = list->data;
2205 if (!toolbar_content_is_placeholder (content))
2210 g_assert (physical == 0);
2216 logical_to_physical (GtkToolbar *toolbar,
2219 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2223 g_assert (logical >= 0);
2226 for (list = priv->content; list; list = list->next)
2228 ToolbarContent *content = list->data;
2230 if (!toolbar_content_is_placeholder (content))
2240 g_assert (logical == 0);
2246 * gtk_toolbar_set_drop_highlight_item:
2247 * @toolbar: a #GtkToolbar
2248 * @tool_item: a #GtkToolItem, or %NULL to turn of highlighting
2249 * @index_: a position on @toolbar
2251 * Highlights @toolbar to give an idea of what it would look like
2252 * if @item was added to @toolbar at the position indicated by @index_.
2253 * If @item is %NULL, highlighting is turned off. In that case @index_
2256 * The @tool_item passed to this function must not be part of any widget
2257 * hierarchy. When an item is set as drop highlight item it can not
2258 * added to any widget hierarchy or used as highlight item for another
2264 gtk_toolbar_set_drop_highlight_item (GtkToolbar *toolbar,
2265 GtkToolItem *tool_item,
2268 ToolbarContent *content;
2269 GtkToolbarPrivate *priv;
2271 GtkRequisition requisition;
2272 GtkRequisition old_requisition;
2273 gboolean restart_sliding;
2275 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2276 g_return_if_fail (tool_item == NULL || GTK_IS_TOOL_ITEM (tool_item));
2278 gtk_toolbar_check_new_api (toolbar);
2280 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2284 if (priv->highlight_tool_item)
2286 gtk_widget_unparent (GTK_WIDGET (priv->highlight_tool_item));
2287 g_object_unref (priv->highlight_tool_item);
2288 priv->highlight_tool_item = NULL;
2291 reset_all_placeholders (toolbar);
2292 gtk_toolbar_begin_sliding (toolbar);
2296 n_items = gtk_toolbar_get_n_items (toolbar);
2297 if (index_ < 0 || index_ > n_items)
2300 if (tool_item != priv->highlight_tool_item)
2302 if (priv->highlight_tool_item)
2303 g_object_unref (priv->highlight_tool_item);
2305 g_object_ref_sink (tool_item);
2307 priv->highlight_tool_item = tool_item;
2309 gtk_widget_set_parent (GTK_WIDGET (priv->highlight_tool_item),
2310 GTK_WIDGET (toolbar));
2313 index_ = logical_to_physical (toolbar, index_);
2315 content = g_list_nth_data (priv->content, index_);
2319 ToolbarContent *prev_content;
2321 prev_content = g_list_nth_data (priv->content, index_ - 1);
2323 if (prev_content && toolbar_content_is_placeholder (prev_content))
2324 content = prev_content;
2327 if (!content || !toolbar_content_is_placeholder (content))
2329 GtkWidget *placeholder;
2331 placeholder = GTK_WIDGET (gtk_separator_tool_item_new ());
2333 content = toolbar_content_new_tool_item (toolbar,
2334 GTK_TOOL_ITEM (placeholder),
2336 gtk_widget_show (placeholder);
2340 g_assert (toolbar_content_is_placeholder (content));
2342 gtk_widget_size_request (GTK_WIDGET (priv->highlight_tool_item),
2345 toolbar_content_set_expand (content, gtk_tool_item_get_expand (tool_item));
2347 restart_sliding = FALSE;
2348 toolbar_content_size_request (content, toolbar, &old_requisition);
2349 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
2351 requisition.height = -1;
2352 if (requisition.width != old_requisition.width)
2353 restart_sliding = TRUE;
2357 requisition.width = -1;
2358 if (requisition.height != old_requisition.height)
2359 restart_sliding = TRUE;
2362 if (toolbar_content_disappearing (content))
2363 restart_sliding = TRUE;
2365 reset_all_placeholders (toolbar);
2366 toolbar_content_set_disappearing (content, FALSE);
2368 toolbar_content_set_size_request (content,
2369 requisition.width, requisition.height);
2371 if (restart_sliding)
2372 gtk_toolbar_begin_sliding (toolbar);
2376 gtk_toolbar_get_child_property (GtkContainer *container,
2382 GtkToolItem *item = GTK_TOOL_ITEM (child);
2384 switch (property_id)
2386 case CHILD_PROP_HOMOGENEOUS:
2387 g_value_set_boolean (value, gtk_tool_item_get_homogeneous (item));
2390 case CHILD_PROP_EXPAND:
2391 g_value_set_boolean (value, gtk_tool_item_get_expand (item));
2395 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
2401 gtk_toolbar_set_child_property (GtkContainer *container,
2404 const GValue *value,
2407 switch (property_id)
2409 case CHILD_PROP_HOMOGENEOUS:
2410 gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (child), g_value_get_boolean (value));
2413 case CHILD_PROP_EXPAND:
2414 gtk_tool_item_set_expand (GTK_TOOL_ITEM (child), g_value_get_boolean (value));
2418 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
2424 gtk_toolbar_show_all (GtkWidget *widget)
2426 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
2429 for (list = priv->content; list != NULL; list = list->next)
2431 ToolbarContent *content = list->data;
2433 toolbar_content_show_all (content);
2436 gtk_widget_show (widget);
2440 gtk_toolbar_hide_all (GtkWidget *widget)
2442 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
2445 for (list = priv->content; list != NULL; list = list->next)
2447 ToolbarContent *content = list->data;
2449 toolbar_content_hide_all (content);
2452 gtk_widget_hide (widget);
2456 gtk_toolbar_add (GtkContainer *container,
2459 GtkToolbar *toolbar;
2461 g_return_if_fail (GTK_IS_TOOLBAR (container));
2462 g_return_if_fail (widget != NULL);
2464 toolbar = GTK_TOOLBAR (container);
2466 if (GTK_IS_TOOL_ITEM (widget))
2467 gtk_toolbar_insert (toolbar, GTK_TOOL_ITEM (widget), -1);
2469 gtk_toolbar_append_widget (toolbar, widget, NULL, NULL);
2473 gtk_toolbar_remove (GtkContainer *container,
2476 GtkToolbar *toolbar;
2477 GtkToolbarPrivate *priv;
2478 ToolbarContent *content_to_remove;
2481 g_return_if_fail (GTK_IS_TOOLBAR (container));
2482 g_return_if_fail (GTK_IS_WIDGET (widget));
2484 toolbar = GTK_TOOLBAR (container);
2485 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2487 content_to_remove = NULL;
2488 for (list = priv->content; list != NULL; list = list->next)
2490 ToolbarContent *content = list->data;
2493 child = toolbar_content_get_widget (content);
2494 if (child && child == widget)
2496 content_to_remove = content;
2501 g_return_if_fail (content_to_remove != NULL);
2503 toolbar_content_remove (content_to_remove, toolbar);
2504 toolbar_content_free (content_to_remove);
2508 gtk_toolbar_forall (GtkContainer *container,
2509 gboolean include_internals,
2510 GtkCallback callback,
2511 gpointer callback_data)
2513 GtkToolbar *toolbar = GTK_TOOLBAR (container);
2514 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2517 g_return_if_fail (callback != NULL);
2519 list = priv->content;
2522 ToolbarContent *content = list->data;
2523 GList *next = list->next;
2525 if (include_internals || !toolbar_content_is_placeholder (content))
2527 GtkWidget *child = toolbar_content_get_widget (content);
2530 (*callback) (child, callback_data);
2536 if (include_internals)
2537 (* callback) (priv->arrow_button, callback_data);
2541 gtk_toolbar_child_type (GtkContainer *container)
2543 return GTK_TYPE_TOOL_ITEM;
2547 gtk_toolbar_reconfigured (GtkToolbar *toolbar)
2549 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2552 list = priv->content;
2555 ToolbarContent *content = list->data;
2556 GList *next = list->next;
2558 toolbar_content_toolbar_reconfigured (content, toolbar);
2565 gtk_toolbar_orientation_changed (GtkToolbar *toolbar,
2566 GtkOrientation orientation)
2568 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2569 if (toolbar->orientation != orientation)
2571 toolbar->orientation = orientation;
2573 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2574 gtk_arrow_set (GTK_ARROW (priv->arrow), GTK_ARROW_DOWN, GTK_SHADOW_NONE);
2576 gtk_arrow_set (GTK_ARROW (priv->arrow), GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
2578 gtk_toolbar_reconfigured (toolbar);
2580 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
2581 g_object_notify (G_OBJECT (toolbar), "orientation");
2586 gtk_toolbar_real_style_changed (GtkToolbar *toolbar,
2587 GtkToolbarStyle style)
2589 if (toolbar->style != style)
2591 toolbar->style = style;
2593 gtk_toolbar_reconfigured (toolbar);
2595 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
2596 g_object_notify (G_OBJECT (toolbar), "toolbar-style");
2601 menu_position_func (GtkMenu *menu,
2607 GtkToolbar *toolbar = GTK_TOOLBAR (user_data);
2608 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2610 GtkRequisition menu_req;
2611 GdkRectangle monitor;
2615 gtk_widget_size_request (priv->arrow_button, &req);
2616 gtk_widget_size_request (GTK_WIDGET (menu), &menu_req);
2618 screen = gtk_widget_get_screen (GTK_WIDGET (menu));
2619 monitor_num = gdk_screen_get_monitor_at_window (screen, priv->arrow_button->window);
2620 if (monitor_num < 0)
2622 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
2624 gdk_window_get_origin (GTK_BUTTON (priv->arrow_button)->event_window, x, y);
2625 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
2627 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
2628 *x += priv->arrow_button->allocation.width - req.width;
2630 *x += req.width - menu_req.width;
2632 if ((*y + priv->arrow_button->allocation.height + menu_req.height) <= monitor.y + monitor.height)
2633 *y += priv->arrow_button->allocation.height;
2634 else if ((*y - menu_req.height) >= monitor.y)
2635 *y -= menu_req.height;
2636 else if (monitor.y + monitor.height - (*y + priv->arrow_button->allocation.height) > *y)
2637 *y += priv->arrow_button->allocation.height;
2639 *y -= menu_req.height;
2643 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
2644 *x += priv->arrow_button->allocation.width;
2646 *x -= menu_req.width;
2648 if (*y + menu_req.height > monitor.y + monitor.height &&
2649 *y + priv->arrow_button->allocation.height - monitor.y > monitor.y + monitor.height - *y)
2650 *y += priv->arrow_button->allocation.height - menu_req.height;
2657 show_menu (GtkToolbar *toolbar,
2658 GdkEventButton *event)
2660 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2662 rebuild_menu (toolbar);
2664 gtk_widget_show_all (GTK_WIDGET (priv->menu));
2666 gtk_menu_popup (priv->menu, NULL, NULL,
2667 menu_position_func, toolbar,
2668 event? event->button : 0,
2669 event? event->time : gtk_get_current_event_time());
2673 gtk_toolbar_arrow_button_clicked (GtkWidget *button,
2674 GtkToolbar *toolbar)
2676 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2678 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->arrow_button)) &&
2679 (!priv->menu || !GTK_WIDGET_VISIBLE (priv->menu)))
2681 /* We only get here when the button is clicked with the keyboard,
2682 * because mouse button presses result in the menu being shown so
2683 * that priv->menu would be non-NULL and visible.
2685 show_menu (toolbar, NULL);
2686 gtk_menu_shell_select_first (GTK_MENU_SHELL (priv->menu), FALSE);
2691 gtk_toolbar_arrow_button_press (GtkWidget *button,
2692 GdkEventButton *event,
2693 GtkToolbar *toolbar)
2695 show_menu (toolbar, event);
2696 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
2702 gtk_toolbar_button_press (GtkWidget *toolbar,
2703 GdkEventButton *event)
2705 if (event->button == 3)
2707 gboolean return_value;
2709 g_signal_emit (toolbar, toolbar_signals[POPUP_CONTEXT_MENU], 0,
2710 (int)event->x_root, (int)event->y_root, event->button,
2713 return return_value;
2720 gtk_toolbar_popup_menu (GtkWidget *toolbar)
2722 gboolean return_value;
2723 /* This function is the handler for the "popup menu" keybinding,
2724 * ie., it is called when the user presses Shift F10
2726 g_signal_emit (toolbar, toolbar_signals[POPUP_CONTEXT_MENU], 0,
2727 -1, -1, -1, &return_value);
2729 return return_value;
2735 * Creates a new toolbar.
2737 * Return Value: the newly-created toolbar.
2740 gtk_toolbar_new (void)
2742 GtkToolbar *toolbar;
2744 toolbar = g_object_new (GTK_TYPE_TOOLBAR, NULL);
2746 return GTK_WIDGET (toolbar);
2750 * gtk_toolbar_insert:
2751 * @toolbar: a #GtkToolbar
2752 * @item: a #GtkToolItem
2753 * @pos: the position of the new item
2755 * Insert a #GtkToolItem into the toolbar at position @pos. If @pos is
2756 * 0 the item is prepended to the start of the toolbar. If @pos is
2757 * negative, the item is appended to the end of the toolbar.
2762 gtk_toolbar_insert (GtkToolbar *toolbar,
2766 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2767 g_return_if_fail (GTK_IS_TOOL_ITEM (item));
2769 if (!gtk_toolbar_check_new_api (toolbar))
2773 pos = logical_to_physical (toolbar, pos);
2775 toolbar_content_new_tool_item (toolbar, item, FALSE, pos);
2779 * gtk_toolbar_get_item_index:
2780 * @toolbar: a #GtkToolbar
2781 * @item: a #GtkToolItem that is a child of @toolbar
2783 * Returns the position of @item on the toolbar, starting from 0.
2784 * It is an error if @item is not a child of the toolbar.
2786 * Return value: the position of item on the toolbar.
2791 gtk_toolbar_get_item_index (GtkToolbar *toolbar,
2794 GtkToolbarPrivate *priv;
2798 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
2799 g_return_val_if_fail (GTK_IS_TOOL_ITEM (item), -1);
2800 g_return_val_if_fail (GTK_WIDGET (item)->parent == GTK_WIDGET (toolbar), -1);
2802 if (!gtk_toolbar_check_new_api (toolbar))
2805 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2808 for (list = priv->content; list != NULL; list = list->next)
2810 ToolbarContent *content = list->data;
2813 widget = toolbar_content_get_widget (content);
2815 if (item == GTK_TOOL_ITEM (widget))
2821 return physical_to_logical (toolbar, n);
2825 * gtk_toolbar_set_orientation:
2826 * @toolbar: a #GtkToolbar.
2827 * @orientation: a new #GtkOrientation.
2829 * Sets whether a toolbar should appear horizontally or vertically.
2832 gtk_toolbar_set_orientation (GtkToolbar *toolbar,
2833 GtkOrientation orientation)
2835 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2837 g_signal_emit (toolbar, toolbar_signals[ORIENTATION_CHANGED], 0, orientation);
2841 * gtk_toolbar_get_orientation:
2842 * @toolbar: a #GtkToolbar
2844 * Retrieves the current orientation of the toolbar. See
2845 * gtk_toolbar_set_orientation().
2847 * Return value: the orientation
2850 gtk_toolbar_get_orientation (GtkToolbar *toolbar)
2852 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), GTK_ORIENTATION_HORIZONTAL);
2854 return toolbar->orientation;
2858 * gtk_toolbar_set_style:
2859 * @toolbar: a #GtkToolbar.
2860 * @style: the new style for @toolbar.
2862 * Alters the view of @toolbar to display either icons only, text only, or both.
2865 gtk_toolbar_set_style (GtkToolbar *toolbar,
2866 GtkToolbarStyle style)
2868 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2870 toolbar->style_set = TRUE;
2871 g_signal_emit (toolbar, toolbar_signals[STYLE_CHANGED], 0, style);
2875 * gtk_toolbar_get_style:
2876 * @toolbar: a #GtkToolbar
2878 * Retrieves whether the toolbar has text, icons, or both . See
2879 * gtk_toolbar_set_style().
2881 * Return value: the current style of @toolbar
2884 gtk_toolbar_get_style (GtkToolbar *toolbar)
2886 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), DEFAULT_TOOLBAR_STYLE);
2888 return toolbar->style;
2892 * gtk_toolbar_unset_style:
2893 * @toolbar: a #GtkToolbar
2895 * Unsets a toolbar style set with gtk_toolbar_set_style(), so that
2896 * user preferences will be used to determine the toolbar style.
2899 gtk_toolbar_unset_style (GtkToolbar *toolbar)
2901 GtkToolbarStyle style;
2903 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2905 if (toolbar->style_set)
2907 GtkSettings *settings = toolbar_get_settings (toolbar);
2910 g_object_get (settings,
2911 "gtk-toolbar-style", &style,
2914 style = DEFAULT_TOOLBAR_STYLE;
2916 if (style != toolbar->style)
2917 g_signal_emit (toolbar, toolbar_signals[STYLE_CHANGED], 0, style);
2919 toolbar->style_set = FALSE;
2924 * gtk_toolbar_set_tooltips:
2925 * @toolbar: a #GtkToolbar.
2926 * @enable: set to %FALSE to disable the tooltips, or %TRUE to enable them.
2928 * Sets if the tooltips of a toolbar should be active or not.
2931 gtk_toolbar_set_tooltips (GtkToolbar *toolbar,
2934 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2937 gtk_tooltips_enable (toolbar->tooltips);
2939 gtk_tooltips_disable (toolbar->tooltips);
2941 g_object_notify (G_OBJECT (toolbar), "tooltips");
2945 * gtk_toolbar_get_tooltips:
2946 * @toolbar: a #GtkToolbar
2948 * Retrieves whether tooltips are enabled. See
2949 * gtk_toolbar_set_tooltips().
2951 * Return value: %TRUE if tooltips are enabled
2954 gtk_toolbar_get_tooltips (GtkToolbar *toolbar)
2956 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), FALSE);
2962 * gtk_toolbar_get_n_items:
2963 * @toolbar: a #GtkToolbar
2965 * Returns the number of items on the toolbar.
2967 * Return value: the number of items on the toolbar
2972 gtk_toolbar_get_n_items (GtkToolbar *toolbar)
2974 GtkToolbarPrivate *priv;
2976 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
2978 if (!gtk_toolbar_check_new_api (toolbar))
2981 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2983 return physical_to_logical (toolbar, g_list_length (priv->content));
2987 * gtk_toolbar_get_nth_item:
2988 * @toolbar: a #GtkToolbar
2989 * @n: A position on the toolbar
2991 * Returns the @n<!-- -->'th item on @toolbar, or %NULL if the
2992 * toolbar does not contain an @n<!-- -->'th item.
2994 * Return value: The @n<!-- -->'th #GtkToolItem on @toolbar, or %NULL if there
2995 * isn't an @n<!-- -->'th item.
3000 gtk_toolbar_get_nth_item (GtkToolbar *toolbar,
3003 GtkToolbarPrivate *priv;
3004 ToolbarContent *content;
3007 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), NULL);
3009 if (!gtk_toolbar_check_new_api (toolbar))
3012 n_items = gtk_toolbar_get_n_items (toolbar);
3014 if (n < 0 || n >= n_items)
3017 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3019 content = g_list_nth_data (priv->content, logical_to_physical (toolbar, n));
3022 g_assert (!toolbar_content_is_placeholder (content));
3024 return GTK_TOOL_ITEM (toolbar_content_get_widget (content));
3028 * gtk_toolbar_get_icon_size:
3029 * @toolbar: a #GtkToolbar
3031 * Retrieves the icon size for the toolbar. See gtk_toolbar_set_icon_size().
3033 * Return value: the current icon size for the icons on the toolbar.
3036 gtk_toolbar_get_icon_size (GtkToolbar *toolbar)
3038 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), DEFAULT_ICON_SIZE);
3040 return toolbar->icon_size;
3044 * gtk_toolbar_get_relief_style:
3045 * @toolbar: a #GtkToolbar
3047 * Returns the relief style of buttons on @toolbar. See
3048 * gtk_button_set_relief().
3050 * Return value: The relief style of buttons on @toolbar.
3055 gtk_toolbar_get_relief_style (GtkToolbar *toolbar)
3057 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), GTK_RELIEF_NONE);
3059 return get_button_relief (toolbar);
3063 * gtk_toolbar_set_show_arrow:
3064 * @toolbar: a #GtkToolbar
3065 * @show_arrow: Whether to show an overflow menu
3067 * Sets whether to show an overflow menu when
3068 * @toolbar doesn't have room for all items on it. If %TRUE,
3069 * items that there are not room are available through an
3075 gtk_toolbar_set_show_arrow (GtkToolbar *toolbar,
3076 gboolean show_arrow)
3078 GtkToolbarPrivate *priv;
3080 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3082 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3083 show_arrow = show_arrow != FALSE;
3085 if (priv->show_arrow != show_arrow)
3087 priv->show_arrow = show_arrow;
3089 if (!priv->show_arrow)
3090 gtk_widget_hide (priv->arrow_button);
3092 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3093 g_object_notify (G_OBJECT (toolbar), "show-arrow");
3098 * gtk_toolbar_get_show_arrow:
3099 * @toolbar: a #GtkToolbar
3101 * Returns whether the toolbar has an overflow menu.
3102 * See gtk_toolbar_set_show_arrow().
3104 * Return value: %TRUE if the toolbar has an overflow menu.
3109 gtk_toolbar_get_show_arrow (GtkToolbar *toolbar)
3111 GtkToolbarPrivate *priv;
3113 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), FALSE);
3115 if (!gtk_toolbar_check_new_api (toolbar))
3118 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3120 return priv->show_arrow;
3124 * gtk_toolbar_get_drop_index:
3125 * @toolbar: a #GtkToolbar
3126 * @x: x coordinate of a point on the toolbar
3127 * @y: y coordinate of a point on the toolbar
3129 * Returns the position corresponding to the indicated point on
3130 * @toolbar. This is useful when dragging items to the toolbar:
3131 * this function returns the position a new item should be
3134 * @x and @y are in @toolbar coordinates.
3136 * Return value: The position corresponding to the point (@x, @y) on the toolbar.
3141 gtk_toolbar_get_drop_index (GtkToolbar *toolbar,
3145 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
3147 if (!gtk_toolbar_check_new_api (toolbar))
3150 return physical_to_logical (toolbar, find_drop_index (toolbar, x, y));
3154 gtk_toolbar_finalize (GObject *object)
3157 GtkToolbar *toolbar = GTK_TOOLBAR (object);
3158 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3160 if (toolbar->tooltips)
3161 g_object_unref (toolbar->tooltips);
3163 if (priv->arrow_button)
3164 gtk_widget_unparent (priv->arrow_button);
3166 for (list = priv->content; list != NULL; list = list->next)
3168 ToolbarContent *content = list->data;
3170 toolbar_content_free (content);
3173 g_list_free (priv->content);
3174 g_list_free (toolbar->children);
3176 g_timer_destroy (priv->timer);
3179 gtk_widget_destroy (GTK_WIDGET (priv->menu));
3182 g_source_remove (priv->idle_id);
3184 G_OBJECT_CLASS (gtk_toolbar_parent_class)->finalize (object);
3188 * gtk_toolbar_set_icon_size:
3189 * @toolbar: A #GtkToolbar
3190 * @icon_size: The #GtkIconSize that stock icons in the toolbar shall have.
3192 * This function sets the size of stock icons in the toolbar. You
3193 * can call it both before you add the icons and after they've been
3194 * added. The size you set will override user preferences for the default
3197 * This should only be used for special-purpose toolbars, normal
3198 * application toolbars should respect the user preferences for the
3202 gtk_toolbar_set_icon_size (GtkToolbar *toolbar,
3203 GtkIconSize icon_size)
3205 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3206 g_return_if_fail (icon_size != GTK_ICON_SIZE_INVALID);
3208 if (!toolbar->icon_size_set)
3210 toolbar->icon_size_set = TRUE;
3211 g_object_notify (G_OBJECT (toolbar), "icon-size-set");
3214 if (toolbar->icon_size == icon_size)
3217 toolbar->icon_size = icon_size;
3218 g_object_notify (G_OBJECT (toolbar), "icon-size");
3220 gtk_toolbar_reconfigured (toolbar);
3222 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3226 * gtk_toolbar_unset_icon_size:
3227 * @toolbar: a #GtkToolbar
3229 * Unsets toolbar icon size set with gtk_toolbar_set_icon_size(), so that
3230 * user preferences will be used to determine the icon size.
3233 gtk_toolbar_unset_icon_size (GtkToolbar *toolbar)
3237 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3239 if (toolbar->icon_size_set)
3241 GtkSettings *settings = toolbar_get_settings (toolbar);
3245 g_object_get (settings,
3246 "gtk-toolbar-icon-size", &size,
3250 size = DEFAULT_ICON_SIZE;
3252 if (size != toolbar->icon_size)
3254 gtk_toolbar_set_icon_size (toolbar, size);
3255 g_object_notify (G_OBJECT (toolbar), "icon-size");
3258 toolbar->icon_size_set = FALSE;
3259 g_object_notify (G_OBJECT (toolbar), "icon-size-set");
3268 * gtk_toolbar_append_item:
3269 * @toolbar: a #GtkToolbar.
3270 * @text: give your toolbar button a label.
3271 * @tooltip_text: a string that appears when the user holds the mouse over this item.
3272 * @tooltip_private_text: use with #GtkTipsQuery.
3273 * @icon: a #GtkWidget that should be used as the button's icon.
3274 * @callback: the function to be executed when the button is pressed.
3275 * @user_data: a pointer to any data you wish to be passed to the callback.
3277 * Inserts a new item into the toolbar. You must specify the position
3278 * in the toolbar where it will be inserted.
3280 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3281 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3283 * Return value: the new toolbar item as a #GtkWidget.
3286 gtk_toolbar_append_item (GtkToolbar *toolbar,
3288 const char *tooltip_text,
3289 const char *tooltip_private_text,
3291 GtkSignalFunc callback,
3294 return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
3296 tooltip_text, tooltip_private_text,
3297 icon, callback, user_data,
3298 toolbar->num_children);
3302 * gtk_toolbar_prepend_item:
3303 * @toolbar: a #GtkToolbar.
3304 * @text: give your toolbar button a label.
3305 * @tooltip_text: a string that appears when the user holds the mouse over this item.
3306 * @tooltip_private_text: use with #GtkTipsQuery.
3307 * @icon: a #GtkWidget that should be used as the button's icon.
3308 * @callback: the function to be executed when the button is pressed.
3309 * @user_data: a pointer to any data you wish to be passed to the callback.
3311 * Adds a new button to the beginning (top or left edges) of the given toolbar.
3313 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3314 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3316 * Return value: the new toolbar item as a #GtkWidget.
3319 gtk_toolbar_prepend_item (GtkToolbar *toolbar,
3321 const char *tooltip_text,
3322 const char *tooltip_private_text,
3324 GtkSignalFunc callback,
3327 return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
3329 tooltip_text, tooltip_private_text,
3330 icon, callback, user_data,
3335 * gtk_toolbar_insert_item:
3336 * @toolbar: a #GtkToolbar.
3337 * @text: give your toolbar button a label.
3338 * @tooltip_text: a string that appears when the user holds the mouse over this item.
3339 * @tooltip_private_text: use with #GtkTipsQuery.
3340 * @icon: a #GtkWidget that should be used as the button's icon.
3341 * @callback: the function to be executed when the button is pressed.
3342 * @user_data: a pointer to any data you wish to be passed to the callback.
3343 * @position: the number of widgets to insert this item after.
3345 * Inserts a new item into the toolbar. You must specify the position in the
3346 * toolbar where it will be inserted.
3348 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3349 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3351 * Return value: the new toolbar item as a #GtkWidget.
3354 gtk_toolbar_insert_item (GtkToolbar *toolbar,
3356 const char *tooltip_text,
3357 const char *tooltip_private_text,
3359 GtkSignalFunc callback,
3363 return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
3365 tooltip_text, tooltip_private_text,
3366 icon, callback, user_data,
3371 * gtk_toolbar_insert_stock:
3372 * @toolbar: A #GtkToolbar
3373 * @stock_id: The id of the stock item you want to insert
3374 * @tooltip_text: The text in the tooltip of the toolbar button
3375 * @tooltip_private_text: The private text of the tooltip
3376 * @callback: The callback called when the toolbar button is clicked.
3377 * @user_data: user data passed to callback
3378 * @position: The position the button shall be inserted at.
3379 * -1 means at the end.
3381 * Inserts a stock item at the specified position of the toolbar. If
3382 * @stock_id is not a known stock item ID, it's inserted verbatim,
3383 * except that underscores used to mark mnemonics are removed.
3385 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3386 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3388 * Returns: the inserted widget
3391 gtk_toolbar_insert_stock (GtkToolbar *toolbar,
3392 const gchar *stock_id,
3393 const char *tooltip_text,
3394 const char *tooltip_private_text,
3395 GtkSignalFunc callback,
3399 return internal_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
3401 tooltip_text, tooltip_private_text,
3402 NULL, callback, user_data,
3407 * gtk_toolbar_append_space:
3408 * @toolbar: a #GtkToolbar.
3410 * Adds a new space to the end of the toolbar.
3413 gtk_toolbar_append_space (GtkToolbar *toolbar)
3415 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_SPACE,
3419 toolbar->num_children);
3423 * gtk_toolbar_prepend_space:
3424 * @toolbar: a #GtkToolbar.
3426 * Adds a new space to the beginning of the toolbar.
3429 gtk_toolbar_prepend_space (GtkToolbar *toolbar)
3431 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_SPACE,
3439 * gtk_toolbar_insert_space:
3440 * @toolbar: a #GtkToolbar
3441 * @position: the number of widgets after which a space should be inserted.
3443 * Inserts a new space in the toolbar at the specified position.
3446 gtk_toolbar_insert_space (GtkToolbar *toolbar,
3449 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_SPACE,
3457 * gtk_toolbar_remove_space:
3458 * @toolbar: a #GtkToolbar.
3459 * @position: the index of the space to remove.
3461 * Removes a space from the specified position.
3464 gtk_toolbar_remove_space (GtkToolbar *toolbar,
3467 GtkToolbarPrivate *priv;
3468 ToolbarContent *content;
3470 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3472 if (!gtk_toolbar_check_old_api (toolbar))
3475 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3477 content = g_list_nth_data (priv->content, position);
3481 g_warning ("Toolbar position %d doesn't exist", position);
3485 if (!toolbar_content_is_separator (content))
3487 g_warning ("Toolbar position %d is not a space", position);
3491 toolbar_content_remove (content, toolbar);
3492 toolbar_content_free (content);
3496 * gtk_toolbar_append_widget:
3497 * @toolbar: a #GtkToolbar.
3498 * @widget: a #GtkWidget to add to the toolbar.
3499 * @tooltip_text: the element's tooltip.
3500 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3502 * Adds a widget to the end of the given toolbar.
3505 gtk_toolbar_append_widget (GtkToolbar *toolbar,
3507 const gchar *tooltip_text,
3508 const gchar *tooltip_private_text)
3510 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_WIDGET,
3512 tooltip_text, tooltip_private_text,
3514 toolbar->num_children);
3518 * gtk_toolbar_prepend_widget:
3519 * @toolbar: a #GtkToolbar.
3520 * @widget: a #GtkWidget to add to the toolbar.
3521 * @tooltip_text: the element's tooltip.
3522 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3524 * Adds a widget to the beginning of the given toolbar.
3527 gtk_toolbar_prepend_widget (GtkToolbar *toolbar,
3529 const gchar *tooltip_text,
3530 const gchar *tooltip_private_text)
3532 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_WIDGET,
3534 tooltip_text, tooltip_private_text,
3540 * gtk_toolbar_insert_widget:
3541 * @toolbar: a #GtkToolbar.
3542 * @widget: a #GtkWidget to add to the toolbar.
3543 * @tooltip_text: the element's tooltip.
3544 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3545 * @position: the number of widgets to insert this widget after.
3547 * Inserts a widget in the toolbar at the given position.
3550 gtk_toolbar_insert_widget (GtkToolbar *toolbar,
3552 const char *tooltip_text,
3553 const char *tooltip_private_text,
3556 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_WIDGET,
3558 tooltip_text, tooltip_private_text,
3564 * gtk_toolbar_append_element:
3565 * @toolbar: a #GtkToolbar.
3566 * @type: a value of type #GtkToolbarChildType that determines what @widget will be.
3567 * @widget: a #GtkWidget, or %NULL.
3568 * @text: the element's label.
3569 * @tooltip_text: the element's tooltip.
3570 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3571 * @icon: a #GtkWidget that provides pictorial representation of the element's function.
3572 * @callback: the function to be executed when the button is pressed.
3573 * @user_data: any data you wish to pass to the callback.
3575 * Adds a new element to the end of a toolbar.
3577 * If @type == %GTK_TOOLBAR_CHILD_WIDGET, @widget is used as the new element.
3578 * If @type == %GTK_TOOLBAR_CHILD_RADIOBUTTON, @widget is used to determine
3579 * the radio group for the new element. In all other cases, @widget must
3582 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3583 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3585 * Return value: the new toolbar element as a #GtkWidget.
3588 gtk_toolbar_append_element (GtkToolbar *toolbar,
3589 GtkToolbarChildType type,
3592 const char *tooltip_text,
3593 const char *tooltip_private_text,
3595 GtkSignalFunc callback,
3598 return gtk_toolbar_insert_element (toolbar, type, widget, text,
3599 tooltip_text, tooltip_private_text,
3600 icon, callback, user_data,
3601 toolbar->num_children);
3605 * gtk_toolbar_prepend_element:
3606 * @toolbar: a #GtkToolbar.
3607 * @type: a value of type #GtkToolbarChildType that determines what @widget will be.
3608 * @widget: a #GtkWidget, or %NULL
3609 * @text: the element's label.
3610 * @tooltip_text: the element's tooltip.
3611 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3612 * @icon: a #GtkWidget that provides pictorial representation of the element's function.
3613 * @callback: the function to be executed when the button is pressed.
3614 * @user_data: any data you wish to pass to the callback.
3616 * Adds a new element to the beginning of a toolbar.
3618 * If @type == %GTK_TOOLBAR_CHILD_WIDGET, @widget is used as the new element.
3619 * If @type == %GTK_TOOLBAR_CHILD_RADIOBUTTON, @widget is used to determine
3620 * the radio group for the new element. In all other cases, @widget must
3623 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3624 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3626 * Return value: the new toolbar element as a #GtkWidget.
3629 gtk_toolbar_prepend_element (GtkToolbar *toolbar,
3630 GtkToolbarChildType type,
3633 const char *tooltip_text,
3634 const char *tooltip_private_text,
3636 GtkSignalFunc callback,
3639 return gtk_toolbar_insert_element (toolbar, type, widget, text,
3640 tooltip_text, tooltip_private_text,
3641 icon, callback, user_data, 0);
3645 * gtk_toolbar_insert_element:
3646 * @toolbar: a #GtkToolbar.
3647 * @type: a value of type #GtkToolbarChildType that determines what @widget
3649 * @widget: a #GtkWidget, or %NULL.
3650 * @text: the element's label.
3651 * @tooltip_text: the element's tooltip.
3652 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3653 * @icon: a #GtkWidget that provides pictorial representation of the element's function.
3654 * @callback: the function to be executed when the button is pressed.
3655 * @user_data: any data you wish to pass to the callback.
3656 * @position: the number of widgets to insert this element after.
3658 * Inserts a new element in the toolbar at the given position.
3660 * If @type == %GTK_TOOLBAR_CHILD_WIDGET, @widget is used as the new element.
3661 * If @type == %GTK_TOOLBAR_CHILD_RADIOBUTTON, @widget is used to determine
3662 * the radio group for the new element. In all other cases, @widget must
3665 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3666 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3668 * Return value: the new toolbar element as a #GtkWidget.
3671 gtk_toolbar_insert_element (GtkToolbar *toolbar,
3672 GtkToolbarChildType type,
3675 const char *tooltip_text,
3676 const char *tooltip_private_text,
3678 GtkSignalFunc callback,
3682 return internal_insert_element (toolbar, type, widget, text,
3683 tooltip_text, tooltip_private_text,
3684 icon, callback, user_data, position, FALSE);
3688 set_child_packing_and_visibility(GtkToolbar *toolbar,
3689 GtkToolbarChild *child)
3694 box = gtk_bin_get_child (GTK_BIN (child->widget));
3696 g_return_if_fail (GTK_IS_BOX (box));
3700 expand = (toolbar->style != GTK_TOOLBAR_BOTH);
3702 gtk_box_set_child_packing (GTK_BOX (box), child->label,
3703 expand, expand, 0, GTK_PACK_END);
3705 if (toolbar->style != GTK_TOOLBAR_ICONS)
3706 gtk_widget_show (child->label);
3708 gtk_widget_hide (child->label);
3713 expand = (toolbar->style != GTK_TOOLBAR_BOTH_HORIZ);
3715 gtk_box_set_child_packing (GTK_BOX (box), child->icon,
3716 expand, expand, 0, GTK_PACK_END);
3718 if (toolbar->style != GTK_TOOLBAR_TEXT)
3719 gtk_widget_show (child->icon);
3721 gtk_widget_hide (child->icon);
3726 internal_insert_element (GtkToolbar *toolbar,
3727 GtkToolbarChildType type,
3730 const char *tooltip_text,
3731 const char *tooltip_private_text,
3733 GtkSignalFunc callback,
3739 ToolbarContent *content;
3740 char *free_me = NULL;
3742 GtkWidget *child_widget;
3743 GtkWidget *child_label;
3744 GtkWidget *child_icon;
3746 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), NULL);
3747 if (type == GTK_TOOLBAR_CHILD_WIDGET)
3748 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3749 else if (type != GTK_TOOLBAR_CHILD_RADIOBUTTON)
3750 g_return_val_if_fail (widget == NULL, NULL);
3751 if (GTK_IS_TOOL_ITEM (widget))
3752 g_warning (MIXED_API_WARNING);
3754 if (!gtk_toolbar_check_old_api (toolbar))
3757 child_widget = NULL;
3763 case GTK_TOOLBAR_CHILD_SPACE:
3766 case GTK_TOOLBAR_CHILD_WIDGET:
3767 child_widget = widget;
3770 case GTK_TOOLBAR_CHILD_BUTTON:
3771 case GTK_TOOLBAR_CHILD_TOGGLEBUTTON:
3772 case GTK_TOOLBAR_CHILD_RADIOBUTTON:
3773 if (type == GTK_TOOLBAR_CHILD_BUTTON)
3775 child_widget = gtk_button_new ();
3777 else if (type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
3779 child_widget = gtk_toggle_button_new ();
3780 gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (child_widget), FALSE);
3782 else /* type == GTK_TOOLBAR_CHILD_RADIOBUTTON */
3784 GSList *group = NULL;
3787 group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (widget));
3789 child_widget = gtk_radio_button_new (group);
3790 gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (child_widget), FALSE);
3793 gtk_button_set_relief (GTK_BUTTON (child_widget), get_button_relief (toolbar));
3794 gtk_button_set_focus_on_click (GTK_BUTTON (child_widget), FALSE);
3798 g_signal_connect (child_widget, "clicked",
3799 callback, user_data);
3802 if (toolbar->style == GTK_TOOLBAR_BOTH_HORIZ)
3803 box = gtk_hbox_new (FALSE, 0);
3805 box = gtk_vbox_new (FALSE, 0);
3807 gtk_container_add (GTK_CONTAINER (child_widget), box);
3808 gtk_widget_show (box);
3810 if (text && use_stock)
3812 GtkStockItem stock_item;
3813 if (gtk_stock_lookup (text, &stock_item))
3816 icon = gtk_image_new_from_stock (text, toolbar->icon_size);
3818 text = free_me = _gtk_toolbar_elide_underscores (stock_item.label);
3824 child_label = gtk_label_new (text);
3826 gtk_container_add (GTK_CONTAINER (box), child_label);
3831 child_icon = GTK_WIDGET (icon);
3832 gtk_container_add (GTK_CONTAINER (box), child_icon);
3835 gtk_widget_show (child_widget);
3839 g_assert_not_reached ();
3843 if ((type != GTK_TOOLBAR_CHILD_SPACE) && tooltip_text)
3845 gtk_tooltips_set_tip (toolbar->tooltips, child_widget,
3846 tooltip_text, tooltip_private_text);
3849 content = toolbar_content_new_compatibility (toolbar, type, child_widget,
3850 child_icon, child_label, position);
3854 return child_widget;
3858 * ToolbarContent methods
3866 struct _ToolbarContent
3876 GtkAllocation start_allocation;
3877 GtkAllocation goal_allocation;
3878 guint is_placeholder : 1;
3879 guint disappearing : 1;
3880 TriState has_menu : 2;
3885 GtkToolbarChild child;
3886 GtkAllocation space_allocation;
3887 guint space_visible : 1;
3892 static ToolbarContent *
3893 toolbar_content_new_tool_item (GtkToolbar *toolbar,
3895 gboolean is_placeholder,
3898 ToolbarContent *content;
3899 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3901 content = g_slice_new0 (ToolbarContent);
3903 content->type = TOOL_ITEM;
3904 content->state = NOT_ALLOCATED;
3905 content->u.tool_item.item = item;
3906 content->u.tool_item.is_placeholder = is_placeholder;
3908 gtk_widget_set_parent (GTK_WIDGET (item), GTK_WIDGET (toolbar));
3910 priv->content = g_list_insert (priv->content, content, pos);
3912 if (!is_placeholder)
3914 toolbar->num_children++;
3916 gtk_toolbar_stop_sliding (toolbar);
3919 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3920 priv->need_rebuild = TRUE;
3925 static ToolbarContent *
3926 toolbar_content_new_compatibility (GtkToolbar *toolbar,
3927 GtkToolbarChildType type,
3933 ToolbarContent *content;
3934 GtkToolbarChild *child;
3935 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3937 content = g_slice_new0 (ToolbarContent);
3939 child = &(content->u.compatibility.child);
3941 content->type = COMPATIBILITY;
3943 child->widget = widget;
3945 child->label = label;
3947 if (type != GTK_TOOLBAR_CHILD_SPACE)
3949 gtk_widget_set_parent (child->widget, GTK_WIDGET (toolbar));
3953 content->u.compatibility.space_visible = TRUE;
3954 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3957 if (type == GTK_TOOLBAR_CHILD_BUTTON ||
3958 type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON ||
3959 type == GTK_TOOLBAR_CHILD_RADIOBUTTON)
3961 set_child_packing_and_visibility (toolbar, child);
3964 priv->content = g_list_insert (priv->content, content, pos);
3965 toolbar->children = g_list_insert (toolbar->children, child, pos);
3966 priv->need_rebuild = TRUE;
3968 toolbar->num_children++;
3974 toolbar_content_remove (ToolbarContent *content,
3975 GtkToolbar *toolbar)
3977 GtkToolbarChild *child;
3978 GtkToolbarPrivate *priv;
3980 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3982 switch (content->type)
3985 gtk_widget_unparent (GTK_WIDGET (content->u.tool_item.item));
3989 child = &(content->u.compatibility.child);
3991 if (child->type != GTK_TOOLBAR_CHILD_SPACE)
3993 g_object_ref (child->widget);
3994 gtk_widget_unparent (child->widget);
3995 gtk_widget_destroy (child->widget);
3996 g_object_unref (child->widget);
3999 toolbar->children = g_list_remove (toolbar->children, child);
4003 priv->content = g_list_remove (priv->content, content);
4005 if (!toolbar_content_is_placeholder (content))
4006 toolbar->num_children--;
4008 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
4009 priv->need_rebuild = TRUE;
4013 toolbar_content_free (ToolbarContent *content)
4015 g_slice_free (ToolbarContent, content);
4019 calculate_max_homogeneous_pixels (GtkWidget *widget)
4021 PangoContext *context;
4022 PangoFontMetrics *metrics;
4025 context = gtk_widget_get_pango_context (widget);
4026 metrics = pango_context_get_metrics (context,
4027 widget->style->font_desc,
4028 pango_context_get_language (context));
4029 char_width = pango_font_metrics_get_approximate_char_width (metrics);
4030 pango_font_metrics_unref (metrics);
4032 return PANGO_PIXELS (MAX_HOMOGENEOUS_N_CHARS * char_width);
4036 toolbar_content_expose (ToolbarContent *content,
4037 GtkContainer *container,
4038 GdkEventExpose *expose)
4040 GtkToolbar *toolbar = GTK_TOOLBAR (container);
4041 GtkToolbarChild *child;
4042 GtkWidget *widget = NULL; /* quiet gcc */
4044 switch (content->type)
4047 if (!content->u.tool_item.is_placeholder)
4048 widget = GTK_WIDGET (content->u.tool_item.item);
4052 child = &(content->u.compatibility.child);
4054 if (child->type == GTK_TOOLBAR_CHILD_SPACE)
4056 if (content->u.compatibility.space_visible &&
4057 get_space_style (toolbar) == GTK_TOOLBAR_SPACE_LINE)
4058 _gtk_toolbar_paint_space_line (GTK_WIDGET (toolbar), toolbar,
4060 &content->u.compatibility.space_allocation);
4064 widget = child->widget;
4069 gtk_container_propagate_expose (container, widget, expose);
4073 toolbar_content_visible (ToolbarContent *content,
4074 GtkToolbar *toolbar)
4078 switch (content->type)
4081 item = content->u.tool_item.item;
4083 if (!GTK_WIDGET_VISIBLE (item))
4086 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL &&
4087 gtk_tool_item_get_visible_horizontal (item))
4090 if ((toolbar->orientation == GTK_ORIENTATION_VERTICAL &&
4091 gtk_tool_item_get_visible_vertical (item)))
4098 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
4099 return GTK_WIDGET_VISIBLE (content->u.compatibility.child.widget);
4105 g_assert_not_reached ();
4110 toolbar_content_size_request (ToolbarContent *content,
4111 GtkToolbar *toolbar,
4112 GtkRequisition *requisition)
4116 switch (content->type)
4119 gtk_widget_size_request (GTK_WIDGET (content->u.tool_item.item),
4121 if (content->u.tool_item.is_placeholder &&
4122 content->u.tool_item.disappearing)
4124 requisition->width = 0;
4125 requisition->height = 0;
4130 space_size = get_space_size (toolbar);
4132 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
4134 gtk_widget_size_request (content->u.compatibility.child.widget,
4139 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
4141 requisition->width = space_size;
4142 requisition->height = 0;
4146 requisition->height = space_size;
4147 requisition->width = 0;
4156 toolbar_content_is_homogeneous (ToolbarContent *content,
4157 GtkToolbar *toolbar)
4159 gboolean result = FALSE; /* quiet gcc */
4160 GtkRequisition requisition;
4161 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
4163 if (priv->max_homogeneous_pixels < 0)
4165 priv->max_homogeneous_pixels =
4166 calculate_max_homogeneous_pixels (GTK_WIDGET (toolbar));
4169 toolbar_content_size_request (content, toolbar, &requisition);
4171 if (requisition.width > priv->max_homogeneous_pixels)
4174 switch (content->type)
4177 result = gtk_tool_item_get_homogeneous (content->u.tool_item.item) &&
4178 !GTK_IS_SEPARATOR_TOOL_ITEM (content->u.tool_item.item);
4180 if (gtk_tool_item_get_is_important (content->u.tool_item.item) &&
4181 toolbar->style == GTK_TOOLBAR_BOTH_HORIZ &&
4182 toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
4189 if (content->u.compatibility.child.type == GTK_TOOLBAR_CHILD_BUTTON ||
4190 content->u.compatibility.child.type == GTK_TOOLBAR_CHILD_RADIOBUTTON ||
4191 content->u.compatibility.child.type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
4206 toolbar_content_is_placeholder (ToolbarContent *content)
4208 if (content->type == TOOL_ITEM && content->u.tool_item.is_placeholder)
4215 toolbar_content_disappearing (ToolbarContent *content)
4217 if (content->type == TOOL_ITEM && content->u.tool_item.disappearing)
4224 toolbar_content_get_state (ToolbarContent *content)
4226 return content->state;
4230 toolbar_content_child_visible (ToolbarContent *content)
4232 switch (content->type)
4235 return GTK_WIDGET_CHILD_VISIBLE (content->u.tool_item.item);
4239 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
4241 return GTK_WIDGET_CHILD_VISIBLE (content->u.compatibility.child.widget);
4245 return content->u.compatibility.space_visible;
4250 return FALSE; /* quiet gcc */
4254 toolbar_content_get_goal_allocation (ToolbarContent *content,
4255 GtkAllocation *allocation)
4257 switch (content->type)
4260 *allocation = content->u.tool_item.goal_allocation;
4264 /* Goal allocations are only relevant when we are
4265 * using the new API, so we should never get here
4267 g_assert_not_reached ();
4273 toolbar_content_get_allocation (ToolbarContent *content,
4274 GtkAllocation *allocation)
4276 GtkToolbarChild *child;
4278 switch (content->type)
4281 *allocation = GTK_WIDGET (content->u.tool_item.item)->allocation;
4285 child = &(content->u.compatibility.child);
4287 if (child->type == GTK_TOOLBAR_CHILD_SPACE)
4288 *allocation = content->u.compatibility.space_allocation;
4290 *allocation = child->widget->allocation;
4296 toolbar_content_set_start_allocation (ToolbarContent *content,
4297 GtkAllocation *allocation)
4299 switch (content->type)
4302 content->u.tool_item.start_allocation = *allocation;
4306 /* start_allocation is only relevant when using the new API */
4307 g_assert_not_reached ();
4313 toolbar_content_get_expand (ToolbarContent *content)
4315 if (content->type == TOOL_ITEM &&
4316 gtk_tool_item_get_expand (content->u.tool_item.item) &&
4317 !content->u.tool_item.disappearing)
4326 toolbar_content_set_goal_allocation (ToolbarContent *content,
4327 GtkAllocation *allocation)
4329 switch (content->type)
4332 content->u.tool_item.goal_allocation = *allocation;
4336 /* Only relevant when using new API */
4337 g_assert_not_reached ();
4343 toolbar_content_set_child_visible (ToolbarContent *content,
4344 GtkToolbar *toolbar,
4347 GtkToolbarChild *child;
4349 switch (content->type)
4352 gtk_widget_set_child_visible (GTK_WIDGET (content->u.tool_item.item),
4357 child = &(content->u.compatibility.child);
4359 if (child->type != GTK_TOOLBAR_CHILD_SPACE)
4361 gtk_widget_set_child_visible (child->widget, visible);
4365 if (content->u.compatibility.space_visible != visible)
4367 content->u.compatibility.space_visible = visible;
4368 gtk_widget_queue_draw (GTK_WIDGET (toolbar));
4376 toolbar_content_get_start_allocation (ToolbarContent *content,
4377 GtkAllocation *start_allocation)
4379 switch (content->type)
4382 *start_allocation = content->u.tool_item.start_allocation;
4386 /* Only relevant for new API */
4387 g_assert_not_reached ();
4393 toolbar_content_size_allocate (ToolbarContent *content,
4394 GtkAllocation *allocation)
4396 switch (content->type)
4399 gtk_widget_size_allocate (GTK_WIDGET (content->u.tool_item.item),
4404 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
4406 gtk_widget_size_allocate (content->u.compatibility.child.widget,
4411 content->u.compatibility.space_allocation = *allocation;
4418 toolbar_content_set_state (ToolbarContent *content,
4421 content->state = state;
4425 toolbar_content_get_widget (ToolbarContent *content)
4427 GtkToolbarChild *child;
4429 switch (content->type)
4432 return GTK_WIDGET (content->u.tool_item.item);
4436 child = &(content->u.compatibility.child);
4437 if (child->type != GTK_TOOLBAR_CHILD_SPACE)
4438 return child->widget;
4448 toolbar_content_set_disappearing (ToolbarContent *content,
4449 gboolean disappearing)
4451 switch (content->type)
4454 content->u.tool_item.disappearing = disappearing;
4458 /* Only relevant for new API */
4459 g_assert_not_reached ();
4465 toolbar_content_set_size_request (ToolbarContent *content,
4469 switch (content->type)
4472 gtk_widget_set_size_request (GTK_WIDGET (content->u.tool_item.item),
4477 /* Setting size requests only happens with sliding,
4478 * so not relevant here
4480 g_assert_not_reached ();
4486 toolbar_child_reconfigure (GtkToolbar *toolbar,
4487 GtkToolbarChild *child)
4491 GtkToolbarStyle style;
4492 GtkIconSize icon_size;
4493 GtkReliefStyle relief;
4496 style = gtk_toolbar_get_style (toolbar);
4497 icon_size = gtk_toolbar_get_icon_size (toolbar);
4498 relief = gtk_toolbar_get_relief_style (toolbar);
4501 if (child->type == GTK_TOOLBAR_CHILD_BUTTON ||
4502 child->type == GTK_TOOLBAR_CHILD_RADIOBUTTON ||
4503 child->type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
4505 box = gtk_bin_get_child (GTK_BIN (child->widget));
4507 if (style == GTK_TOOLBAR_BOTH && GTK_IS_HBOX (box))
4511 vbox = gtk_vbox_new (FALSE, 0);
4514 gtk_widget_reparent (child->label, vbox);
4516 gtk_widget_reparent (child->icon, vbox);
4518 gtk_widget_destroy (box);
4519 gtk_container_add (GTK_CONTAINER (child->widget), vbox);
4521 gtk_widget_show (vbox);
4523 else if (style == GTK_TOOLBAR_BOTH_HORIZ && GTK_IS_VBOX (box))
4527 hbox = gtk_hbox_new (FALSE, 0);
4530 gtk_widget_reparent (child->label, hbox);
4532 gtk_widget_reparent (child->icon, hbox);
4534 gtk_widget_destroy (box);
4535 gtk_container_add (GTK_CONTAINER (child->widget), hbox);
4537 gtk_widget_show (hbox);
4540 set_child_packing_and_visibility (toolbar, child);
4545 if ((child->type == GTK_TOOLBAR_CHILD_BUTTON ||
4546 child->type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON ||
4547 child->type == GTK_TOOLBAR_CHILD_RADIOBUTTON) &&
4548 GTK_IS_IMAGE (child->icon))
4550 image = GTK_IMAGE (child->icon);
4551 if (gtk_image_get_storage_type (image) == GTK_IMAGE_STOCK)
4553 gtk_image_get_stock (image, &stock_id, NULL);
4554 stock_id = g_strdup (stock_id);
4555 gtk_image_set_from_stock (image,
4563 if (child->type == GTK_TOOLBAR_CHILD_BUTTON ||
4564 child->type == GTK_TOOLBAR_CHILD_RADIOBUTTON ||
4565 child->type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
4567 gtk_button_set_relief (GTK_BUTTON (child->widget), relief);
4572 toolbar_content_toolbar_reconfigured (ToolbarContent *content,
4573 GtkToolbar *toolbar)
4575 switch (content->type)
4578 _gtk_tool_item_toolbar_reconfigured (content->u.tool_item.item);
4582 toolbar_child_reconfigure (toolbar, &(content->u.compatibility.child));
4588 toolbar_content_retrieve_menu_item (ToolbarContent *content)
4590 if (content->type == TOOL_ITEM)
4591 return gtk_tool_item_retrieve_proxy_menu_item (content->u.tool_item.item);
4593 /* FIXME - we might actually be able to do something meaningful here */
4598 toolbar_content_has_proxy_menu_item (ToolbarContent *content)
4600 if (content->type == TOOL_ITEM)
4602 GtkWidget *menu_item;
4604 if (content->u.tool_item.has_menu == YES)
4606 else if (content->u.tool_item.has_menu == NO)
4609 menu_item = toolbar_content_retrieve_menu_item (content);
4611 content->u.tool_item.has_menu = menu_item? YES : NO;
4613 return menu_item != NULL;
4622 toolbar_content_set_unknown_menu_status (ToolbarContent *content)
4624 if (content->type == TOOL_ITEM)
4625 content->u.tool_item.has_menu = UNKNOWN;
4629 toolbar_content_is_separator (ToolbarContent *content)
4631 GtkToolbarChild *child;
4633 switch (content->type)
4636 return GTK_IS_SEPARATOR_TOOL_ITEM (content->u.tool_item.item);
4640 child = &(content->u.compatibility.child);
4641 return (child->type == GTK_TOOLBAR_CHILD_SPACE);
4649 toolbar_content_set_expand (ToolbarContent *content,
4652 if (content->type == TOOL_ITEM)
4653 gtk_tool_item_set_expand (content->u.tool_item.item, expand);
4657 ignore_show_and_hide_all (ToolbarContent *content)
4659 if (content->type == COMPATIBILITY)
4661 GtkToolbarChildType type = content->u.compatibility.child.type;
4663 if (type == GTK_TOOLBAR_CHILD_BUTTON ||
4664 type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON ||
4665 type == GTK_TOOLBAR_CHILD_RADIOBUTTON)
4675 toolbar_content_show_all (ToolbarContent *content)
4679 if (ignore_show_and_hide_all (content))
4682 widget = toolbar_content_get_widget (content);
4684 gtk_widget_show_all (widget);
4688 toolbar_content_hide_all (ToolbarContent *content)
4692 if (ignore_show_and_hide_all (content))
4695 widget = toolbar_content_get_widget (content);
4697 gtk_widget_hide_all (widget);
4704 get_space_size (GtkToolbar *toolbar)
4706 gint space_size = DEFAULT_SPACE_SIZE;
4710 gtk_widget_style_get (GTK_WIDGET (toolbar),
4711 "space-size", &space_size,
4718 static GtkToolbarSpaceStyle
4719 get_space_style (GtkToolbar *toolbar)
4721 GtkToolbarSpaceStyle space_style = DEFAULT_SPACE_STYLE;
4725 gtk_widget_style_get (GTK_WIDGET (toolbar),
4726 "space-style", &space_style,
4733 static GtkReliefStyle
4734 get_button_relief (GtkToolbar *toolbar)
4736 GtkReliefStyle button_relief = GTK_RELIEF_NORMAL;
4738 gtk_widget_ensure_style (GTK_WIDGET (toolbar));
4740 gtk_widget_style_get (GTK_WIDGET (toolbar),
4741 "button-relief", &button_relief,
4744 return button_relief;
4748 get_internal_padding (GtkToolbar *toolbar)
4752 gtk_widget_style_get (GTK_WIDGET (toolbar),
4753 "internal-padding", &ipadding,
4760 get_max_child_expand (GtkToolbar *toolbar)
4762 gint mexpand = G_MAXINT;
4764 gtk_widget_style_get (GTK_WIDGET (toolbar),
4765 "max-child-expand", &mexpand,
4770 static GtkShadowType
4771 get_shadow_type (GtkToolbar *toolbar)
4773 GtkShadowType shadow_type;
4775 gtk_widget_style_get (GTK_WIDGET (toolbar),
4776 "shadow-type", &shadow_type,
4786 gtk_toolbar_check_old_api (GtkToolbar *toolbar)
4788 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
4790 if (priv->api_mode == NEW_API)
4792 g_warning (MIXED_API_WARNING);
4796 priv->api_mode = OLD_API;
4801 gtk_toolbar_check_new_api (GtkToolbar *toolbar)
4803 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
4805 if (priv->api_mode == OLD_API)
4807 g_warning (MIXED_API_WARNING);
4811 priv->api_mode = NEW_API;
4815 /* GTK+ internal methods */
4818 _gtk_toolbar_get_default_space_size (void)
4820 return DEFAULT_SPACE_SIZE;
4824 _gtk_toolbar_paint_space_line (GtkWidget *widget,
4825 GtkToolbar *toolbar,
4827 GtkAllocation *allocation)
4829 const double start_fraction = (SPACE_LINE_START / SPACE_LINE_DIVISION);
4830 const double end_fraction = (SPACE_LINE_END / SPACE_LINE_DIVISION);
4832 GtkOrientation orientation;
4834 g_return_if_fail (GTK_IS_WIDGET (widget));
4836 orientation = toolbar? toolbar->orientation : GTK_ORIENTATION_HORIZONTAL;
4838 if (orientation == GTK_ORIENTATION_HORIZONTAL)
4840 gboolean wide_separators;
4841 gint separator_width;
4843 gtk_widget_style_get (widget,
4844 "wide-separators", &wide_separators,
4845 "separator-width", &separator_width,
4848 if (wide_separators)
4849 gtk_paint_box (widget->style, widget->window,
4850 GTK_WIDGET_STATE (widget), GTK_SHADOW_ETCHED_OUT,
4851 area, widget, "vseparator",
4852 allocation->x + (allocation->width - separator_width) / 2,
4853 allocation->y + allocation->height * start_fraction,
4855 allocation->height * (end_fraction - start_fraction));
4857 gtk_paint_vline (widget->style, widget->window,
4858 GTK_WIDGET_STATE (widget), area, widget,
4860 allocation->y + allocation->height * start_fraction,
4861 allocation->y + allocation->height * end_fraction,
4862 allocation->x + (allocation->width - widget->style->xthickness) / 2);
4866 gboolean wide_separators;
4867 gint separator_height;
4869 gtk_widget_style_get (widget,
4870 "wide-separators", &wide_separators,
4871 "separator-height", &separator_height,
4874 if (wide_separators)
4875 gtk_paint_box (widget->style, widget->window,
4876 GTK_WIDGET_STATE (widget), GTK_SHADOW_ETCHED_OUT,
4877 area, widget, "hseparator",
4878 allocation->x + allocation->width * start_fraction,
4879 allocation->y + (allocation->height - separator_height) / 2,
4880 allocation->width * (end_fraction - start_fraction),
4883 gtk_paint_hline (widget->style, widget->window,
4884 GTK_WIDGET_STATE (widget), area, widget,
4886 allocation->x + allocation->width * start_fraction,
4887 allocation->x + allocation->width * end_fraction,
4888 allocation->y + (allocation->height - widget->style->ythickness) / 2);
4893 _gtk_toolbar_elide_underscores (const gchar *original)
4896 const gchar *p, *end;
4898 gboolean last_underscore;
4903 len = strlen (original);
4904 q = result = g_malloc (len + 1);
4905 last_underscore = FALSE;
4907 end = original + len;
4908 for (p = original; p < end; p++)
4910 if (!last_underscore && *p == '_')
4911 last_underscore = TRUE;
4914 last_underscore = FALSE;
4915 if (original + 2 <= p && p + 1 <= end &&
4916 p[-2] == '(' && p[-1] == '_' && p[0] != '_' && p[1] == ')')
4927 if (last_underscore)
4936 _gtk_toolbar_rebuild_menu (GtkToolbar *toolbar)
4938 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
4941 priv->need_rebuild = TRUE;
4943 for (list = priv->content; list != NULL; list = list->next)
4945 ToolbarContent *content = list->data;
4947 toolbar_content_set_unknown_menu_status (content);
4950 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
4953 #define __GTK_TOOLBAR_C__
4954 #include "gtkaliasdef.c"