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 "gtkbindings.h"
42 #include <gdk/gdkkeysyms.h>
43 #include "gtkmarshalers.h"
47 #include "gtkprivate.h"
53 #include "gtkseparatormenuitem.h"
57 typedef struct _ToolbarContent ToolbarContent;
59 #define DEFAULT_IPADDING 0
61 #define DEFAULT_SPACE_SIZE 12
62 #define DEFAULT_SPACE_STYLE GTK_TOOLBAR_SPACE_LINE
63 #define SPACE_LINE_DIVISION 10.0
64 #define SPACE_LINE_START 2.0
65 #define SPACE_LINE_END 8.0
67 #define DEFAULT_ICON_SIZE GTK_ICON_SIZE_LARGE_TOOLBAR
68 #define DEFAULT_TOOLBAR_STYLE GTK_TOOLBAR_BOTH
69 #define DEFAULT_ANIMATION_STATE TRUE
71 #define MAX_HOMOGENEOUS_N_CHARS 13 /* Items that are wider than this do not participate
72 * in the homogeneous game. In units of
73 * pango_font_get_estimated_char_width().
75 #define SLIDE_SPEED 600.0 /* How fast the items slide, in pixels per second */
76 #define ACCEL_THRESHOLD 0.18 /* After how much time in seconds will items start speeding up */
78 #define MIXED_API_WARNING \
79 "Mixing deprecated and non-deprecated GtkToolbar API is not allowed"
93 /* Child properties */
97 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_screen_changed (GtkWidget *widget,
176 GdkScreen *previous_screen);
177 static void gtk_toolbar_map (GtkWidget *widget);
178 static void gtk_toolbar_unmap (GtkWidget *widget);
179 static void gtk_toolbar_set_child_property (GtkContainer *container,
184 static void gtk_toolbar_get_child_property (GtkContainer *container,
189 static void gtk_toolbar_finalize (GObject *object);
190 static void gtk_toolbar_show_all (GtkWidget *widget);
191 static void gtk_toolbar_hide_all (GtkWidget *widget);
192 static void gtk_toolbar_add (GtkContainer *container,
194 static void gtk_toolbar_remove (GtkContainer *container,
196 static void gtk_toolbar_forall (GtkContainer *container,
197 gboolean include_internals,
198 GtkCallback callback,
199 gpointer callback_data);
200 static GType gtk_toolbar_child_type (GtkContainer *container);
201 static void gtk_toolbar_orientation_changed (GtkToolbar *toolbar,
202 GtkOrientation orientation);
203 static void gtk_toolbar_real_style_changed (GtkToolbar *toolbar,
204 GtkToolbarStyle style);
205 static gboolean gtk_toolbar_move_focus (GtkToolbar *toolbar,
206 GtkDirectionType dir);
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 void toolbar_content_remove (ToolbarContent *content,
246 GtkToolbar *toolbar);
247 static void toolbar_content_free (ToolbarContent *content);
248 static void toolbar_content_expose (ToolbarContent *content,
249 GtkContainer *container,
250 GdkEventExpose *expose);
251 static gboolean toolbar_content_visible (ToolbarContent *content,
252 GtkToolbar *toolbar);
253 static void toolbar_content_size_request (ToolbarContent *content,
255 GtkRequisition *requisition);
256 static gboolean toolbar_content_is_homogeneous (ToolbarContent *content,
257 GtkToolbar *toolbar);
258 static gboolean toolbar_content_is_placeholder (ToolbarContent *content);
259 static gboolean toolbar_content_disappearing (ToolbarContent *content);
260 static ItemState toolbar_content_get_state (ToolbarContent *content);
261 static gboolean toolbar_content_child_visible (ToolbarContent *content);
262 static void toolbar_content_get_goal_allocation (ToolbarContent *content,
263 GtkAllocation *allocation);
264 static void toolbar_content_get_allocation (ToolbarContent *content,
265 GtkAllocation *allocation);
266 static void toolbar_content_set_start_allocation (ToolbarContent *content,
267 GtkAllocation *new_start_allocation);
268 static void toolbar_content_get_start_allocation (ToolbarContent *content,
269 GtkAllocation *start_allocation);
270 static gboolean toolbar_content_get_expand (ToolbarContent *content);
271 static void toolbar_content_set_goal_allocation (ToolbarContent *content,
272 GtkAllocation *allocation);
273 static void toolbar_content_set_child_visible (ToolbarContent *content,
276 static void toolbar_content_size_allocate (ToolbarContent *content,
277 GtkAllocation *allocation);
278 static void toolbar_content_set_state (ToolbarContent *content,
279 ItemState new_state);
280 static GtkWidget * toolbar_content_get_widget (ToolbarContent *content);
281 static void toolbar_content_set_disappearing (ToolbarContent *content,
282 gboolean disappearing);
283 static void toolbar_content_set_size_request (ToolbarContent *content,
286 static void toolbar_content_toolbar_reconfigured (ToolbarContent *content,
287 GtkToolbar *toolbar);
288 static GtkWidget * toolbar_content_retrieve_menu_item (ToolbarContent *content);
289 static gboolean toolbar_content_has_proxy_menu_item (ToolbarContent *content);
290 static gboolean toolbar_content_is_separator (ToolbarContent *content);
291 static void toolbar_content_show_all (ToolbarContent *content);
292 static void toolbar_content_hide_all (ToolbarContent *content);
293 static void toolbar_content_set_expand (ToolbarContent *content,
296 #define GTK_TOOLBAR_GET_PRIVATE(o) \
297 (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_TOOLBAR, GtkToolbarPrivate))
299 static guint toolbar_signals [LAST_SIGNAL] = { 0 };
301 G_DEFINE_TYPE (GtkToolbar, gtk_toolbar, GTK_TYPE_CONTAINER)
304 add_arrow_bindings (GtkBindingSet *binding_set,
306 GtkDirectionType dir)
308 guint keypad_keysym = keysym - GDK_Left + GDK_KP_Left;
310 gtk_binding_entry_add_signal (binding_set, keysym, 0,
312 GTK_TYPE_DIRECTION_TYPE, dir);
313 gtk_binding_entry_add_signal (binding_set, keypad_keysym, 0,
315 GTK_TYPE_DIRECTION_TYPE, dir);
319 add_ctrl_tab_bindings (GtkBindingSet *binding_set,
320 GdkModifierType modifiers,
321 GtkDirectionType direction)
323 gtk_binding_entry_add_signal (binding_set,
324 GDK_Tab, GDK_CONTROL_MASK | modifiers,
326 GTK_TYPE_DIRECTION_TYPE, direction);
327 gtk_binding_entry_add_signal (binding_set,
328 GDK_KP_Tab, GDK_CONTROL_MASK | modifiers,
330 GTK_TYPE_DIRECTION_TYPE, direction);
334 gtk_toolbar_class_init (GtkToolbarClass *klass)
336 GObjectClass *gobject_class;
337 GtkWidgetClass *widget_class;
338 GtkContainerClass *container_class;
339 GtkBindingSet *binding_set;
341 gobject_class = (GObjectClass *)klass;
342 widget_class = (GtkWidgetClass *)klass;
343 container_class = (GtkContainerClass *)klass;
345 gobject_class->set_property = gtk_toolbar_set_property;
346 gobject_class->get_property = gtk_toolbar_get_property;
347 gobject_class->finalize = gtk_toolbar_finalize;
349 widget_class->button_press_event = gtk_toolbar_button_press;
350 widget_class->expose_event = gtk_toolbar_expose;
351 widget_class->size_request = gtk_toolbar_size_request;
352 widget_class->size_allocate = gtk_toolbar_size_allocate;
353 widget_class->style_set = gtk_toolbar_style_set;
354 widget_class->focus = gtk_toolbar_focus;
355 widget_class->screen_changed = gtk_toolbar_screen_changed;
356 widget_class->realize = gtk_toolbar_realize;
357 widget_class->unrealize = gtk_toolbar_unrealize;
358 widget_class->map = gtk_toolbar_map;
359 widget_class->unmap = gtk_toolbar_unmap;
360 widget_class->popup_menu = gtk_toolbar_popup_menu;
361 widget_class->show_all = gtk_toolbar_show_all;
362 widget_class->hide_all = gtk_toolbar_hide_all;
364 container_class->add = gtk_toolbar_add;
365 container_class->remove = gtk_toolbar_remove;
366 container_class->forall = gtk_toolbar_forall;
367 container_class->child_type = gtk_toolbar_child_type;
368 container_class->get_child_property = gtk_toolbar_get_child_property;
369 container_class->set_child_property = gtk_toolbar_set_child_property;
371 klass->orientation_changed = gtk_toolbar_orientation_changed;
372 klass->style_changed = gtk_toolbar_real_style_changed;
375 * GtkToolbar::orientation-changed:
376 * @toolbar: the object which emitted the signal
377 * @orientation: the new #GtkOrientation of the toolbar
379 * Emitted when the orientation of the toolbar changes.
381 toolbar_signals[ORIENTATION_CHANGED] =
382 g_signal_new (I_("orientation-changed"),
383 G_OBJECT_CLASS_TYPE (klass),
385 G_STRUCT_OFFSET (GtkToolbarClass, orientation_changed),
387 g_cclosure_marshal_VOID__ENUM,
389 GTK_TYPE_ORIENTATION);
391 * GtkToolbar::style-changed:
392 * @toolbar: The #GtkToolbar which emitted the signal
393 * @style: the new #GtkToolbarStyle of the toolbar
395 * Emitted when the style of the toolbar changes.
397 toolbar_signals[STYLE_CHANGED] =
398 g_signal_new (I_("style-changed"),
399 G_OBJECT_CLASS_TYPE (klass),
401 G_STRUCT_OFFSET (GtkToolbarClass, style_changed),
403 g_cclosure_marshal_VOID__ENUM,
405 GTK_TYPE_TOOLBAR_STYLE);
407 * GtkToolbar::popup-context-menu:
408 * @toolbar: the #GtkToolbar which emitted the signal
409 * @x: the x coordinate of the point where the menu should appear
410 * @y: the y coordinate of the point where the menu should appear
411 * @button: the mouse button the user pressed, or -1
413 * Emitted when the user right-clicks the toolbar or uses the
414 * keybinding to display a popup menu.
416 * Application developers should handle this signal if they want
417 * to display a context menu on the toolbar. The context-menu should
418 * appear at the coordinates given by @x and @y. The mouse button
419 * number is given by the @button parameter. If the menu was popped
420 * up using the keybaord, @button is -1.
422 * Return value: return %TRUE if the signal was handled, %FALSE if not
424 toolbar_signals[POPUP_CONTEXT_MENU] =
425 g_signal_new (I_("popup_context_menu"),
426 G_OBJECT_CLASS_TYPE (klass),
428 G_STRUCT_OFFSET (GtkToolbarClass, popup_context_menu),
429 _gtk_boolean_handled_accumulator, NULL,
430 _gtk_marshal_BOOLEAN__INT_INT_INT,
432 G_TYPE_INT, G_TYPE_INT,
435 * GtkToolbar::move-focus:
436 * @toolbar: the #GtkToolbar which emitted the signal
437 * @dir: a #GtkDirection
439 * A keybinding signal used internally by GTK+. This signal can't
440 * be used in application code.
442 * Return value: %TRUE if the signal was handled, %FALSE if not
444 toolbar_signals[MOVE_FOCUS] =
445 _gtk_binding_signal_new (I_("move_focus"),
446 G_TYPE_FROM_CLASS (klass),
447 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
448 G_CALLBACK (gtk_toolbar_move_focus),
450 _gtk_marshal_BOOLEAN__ENUM,
452 GTK_TYPE_DIRECTION_TYPE);
454 * GtkToolbar::focus-home-or-end:
455 * @toolbar: the #GtkToolbar which emitted the signal
456 * @focus_home: %TRUE if the first item should be focused
458 * A keybinding signal used internally by GTK+. This signal can't
459 * be used in application code
461 * Return value: %TRUE if the signal was handled, %FALSE if not
463 toolbar_signals[FOCUS_HOME_OR_END] =
464 _gtk_binding_signal_new (I_("focus_home_or_end"),
465 G_OBJECT_CLASS_TYPE (klass),
466 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
467 G_CALLBACK (gtk_toolbar_focus_home_or_end),
469 _gtk_marshal_BOOLEAN__BOOLEAN,
474 g_object_class_install_property (gobject_class,
476 g_param_spec_enum ("orientation",
478 P_("The orientation of the toolbar"),
479 GTK_TYPE_ORIENTATION,
480 GTK_ORIENTATION_HORIZONTAL,
481 GTK_PARAM_READWRITE));
483 g_object_class_install_property (gobject_class,
485 g_param_spec_enum ("toolbar-style",
487 P_("How to draw the toolbar"),
488 GTK_TYPE_TOOLBAR_STYLE,
490 GTK_PARAM_READWRITE));
491 g_object_class_install_property (gobject_class,
493 g_param_spec_boolean ("show-arrow",
495 P_("If an arrow should be shown if the toolbar doesn't fit"),
497 GTK_PARAM_READWRITE));
501 * GtkToolbar:tooltips:
503 * If the tooltips of the toolbar should be active or not.
507 g_object_class_install_property (gobject_class,
509 g_param_spec_boolean ("tooltips",
511 P_("If the tooltips of the toolbar should be active or not"),
513 GTK_PARAM_READWRITE));
517 * GtkToolbar:icon-size:
519 * The size of the icons in a toolbar is normally determined by
520 * the toolbar-icon-size setting. When this property is set, it
521 * overrides the setting.
523 * This should only be used for special-purpose toolbars, normal
524 * application toolbars should respect the user preferences for the
529 g_object_class_install_property (gobject_class,
531 g_param_spec_enum ("icon-size",
533 P_("Size of icons in this toolbar"),
536 GTK_PARAM_READWRITE));
539 * GtkToolbar:icon-size-set:
541 * Is %TRUE if the icon-size property has been set.
545 g_object_class_install_property (gobject_class,
547 g_param_spec_boolean ("icon-size-set",
549 P_("Whether the icon-size property has been set"),
551 GTK_PARAM_READWRITE));
553 /* child properties */
554 gtk_container_class_install_child_property (container_class,
556 g_param_spec_boolean ("expand",
558 P_("Whether the item should receive extra space when the toolbar grows"),
560 GTK_PARAM_READWRITE));
562 gtk_container_class_install_child_property (container_class,
563 CHILD_PROP_HOMOGENEOUS,
564 g_param_spec_boolean ("homogeneous",
566 P_("Whether the item should be the same size as other homogeneous items"),
568 GTK_PARAM_READWRITE));
570 /* style properties */
571 gtk_widget_class_install_style_property (widget_class,
572 g_param_spec_int ("space-size",
574 P_("Size of spacers"),
578 GTK_PARAM_READABLE));
580 gtk_widget_class_install_style_property (widget_class,
581 g_param_spec_int ("internal-padding",
582 P_("Internal padding"),
583 P_("Amount of border space between the toolbar shadow and the buttons"),
587 GTK_PARAM_READABLE));
589 gtk_widget_class_install_style_property (widget_class,
590 g_param_spec_int ("max-child-expand",
591 P_("Maximum child expand"),
592 P_("Maximum amount of space an expandable item will be given"),
596 GTK_PARAM_READABLE));
598 gtk_widget_class_install_style_property (widget_class,
599 g_param_spec_enum ("space-style",
601 P_("Whether spacers are vertical lines or just blank"),
602 GTK_TYPE_TOOLBAR_SPACE_STYLE,
604 GTK_PARAM_READABLE));
606 gtk_widget_class_install_style_property (widget_class,
607 g_param_spec_enum ("button-relief",
609 P_("Type of bevel around toolbar buttons"),
610 GTK_TYPE_RELIEF_STYLE,
612 GTK_PARAM_READABLE));
613 gtk_widget_class_install_style_property (widget_class,
614 g_param_spec_enum ("shadow-type",
616 P_("Style of bevel around the toolbar"),
617 GTK_TYPE_SHADOW_TYPE,
619 GTK_PARAM_READABLE));
621 gtk_settings_install_property (g_param_spec_enum ("gtk-toolbar-style",
623 P_("Whether default toolbars have text only, text and icons, icons only, etc."),
624 GTK_TYPE_TOOLBAR_STYLE,
625 DEFAULT_TOOLBAR_STYLE,
626 GTK_PARAM_READWRITE));
628 gtk_settings_install_property (g_param_spec_enum ("gtk-toolbar-icon-size",
629 P_("Toolbar icon size"),
630 P_("Size of icons in default toolbars"),
633 GTK_PARAM_READWRITE));
635 binding_set = gtk_binding_set_by_class (klass);
637 add_arrow_bindings (binding_set, GDK_Left, GTK_DIR_LEFT);
638 add_arrow_bindings (binding_set, GDK_Right, GTK_DIR_RIGHT);
639 add_arrow_bindings (binding_set, GDK_Up, GTK_DIR_UP);
640 add_arrow_bindings (binding_set, GDK_Down, GTK_DIR_DOWN);
642 gtk_binding_entry_add_signal (binding_set, GDK_KP_Home, 0,
643 "focus_home_or_end", 1,
644 G_TYPE_BOOLEAN, TRUE);
645 gtk_binding_entry_add_signal (binding_set, GDK_Home, 0,
646 "focus_home_or_end", 1,
647 G_TYPE_BOOLEAN, TRUE);
648 gtk_binding_entry_add_signal (binding_set, GDK_KP_End, 0,
649 "focus_home_or_end", 1,
650 G_TYPE_BOOLEAN, FALSE);
651 gtk_binding_entry_add_signal (binding_set, GDK_End, 0,
652 "focus_home_or_end", 1,
653 G_TYPE_BOOLEAN, FALSE);
655 add_ctrl_tab_bindings (binding_set, 0, GTK_DIR_TAB_FORWARD);
656 add_ctrl_tab_bindings (binding_set, GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
658 g_type_class_add_private (gobject_class, sizeof (GtkToolbarPrivate));
662 gtk_toolbar_init (GtkToolbar *toolbar)
664 GtkToolbarPrivate *priv;
666 GTK_WIDGET_UNSET_FLAGS (toolbar, GTK_CAN_FOCUS);
667 GTK_WIDGET_SET_FLAGS (toolbar, GTK_NO_WINDOW);
669 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
671 toolbar->orientation = GTK_ORIENTATION_HORIZONTAL;
672 toolbar->style = DEFAULT_TOOLBAR_STYLE;
673 toolbar->icon_size = DEFAULT_ICON_SIZE;
674 priv->animation = DEFAULT_ANIMATION_STATE;
675 toolbar->tooltips = gtk_tooltips_new ();
676 g_object_ref_sink (toolbar->tooltips);
678 priv->arrow_button = gtk_toggle_button_new ();
679 g_signal_connect (priv->arrow_button, "button_press_event",
680 G_CALLBACK (gtk_toolbar_arrow_button_press), toolbar);
681 g_signal_connect (priv->arrow_button, "clicked",
682 G_CALLBACK (gtk_toolbar_arrow_button_clicked), toolbar);
683 gtk_button_set_relief (GTK_BUTTON (priv->arrow_button),
684 get_button_relief (toolbar));
686 priv->api_mode = DONT_KNOW;
688 gtk_button_set_focus_on_click (GTK_BUTTON (priv->arrow_button), FALSE);
690 priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
691 gtk_widget_set_name (priv->arrow, "gtk-toolbar-arrow");
692 gtk_widget_show (priv->arrow);
693 gtk_container_add (GTK_CONTAINER (priv->arrow_button), priv->arrow);
695 gtk_widget_set_parent (priv->arrow_button, GTK_WIDGET (toolbar));
697 /* which child position a drop will occur at */
699 priv->show_arrow = TRUE;
700 priv->settings = NULL;
702 priv->max_homogeneous_pixels = -1;
704 priv->timer = g_timer_new ();
708 gtk_toolbar_set_property (GObject *object,
713 GtkToolbar *toolbar = GTK_TOOLBAR (object);
717 case PROP_ORIENTATION:
718 gtk_toolbar_set_orientation (toolbar, g_value_get_enum (value));
720 case PROP_TOOLBAR_STYLE:
721 gtk_toolbar_set_style (toolbar, g_value_get_enum (value));
723 case PROP_SHOW_ARROW:
724 gtk_toolbar_set_show_arrow (toolbar, g_value_get_boolean (value));
727 gtk_toolbar_set_tooltips (toolbar, g_value_get_boolean (value));
730 gtk_toolbar_set_icon_size (toolbar, g_value_get_enum (value));
732 case PROP_ICON_SIZE_SET:
733 if (g_value_get_boolean (value))
734 toolbar->icon_size_set = TRUE;
736 gtk_toolbar_unset_icon_size (toolbar);
739 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
745 gtk_toolbar_get_property (GObject *object,
750 GtkToolbar *toolbar = GTK_TOOLBAR (object);
751 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
755 case PROP_ORIENTATION:
756 g_value_set_enum (value, toolbar->orientation);
758 case PROP_TOOLBAR_STYLE:
759 g_value_set_enum (value, toolbar->style);
761 case PROP_SHOW_ARROW:
762 g_value_set_boolean (value, priv->show_arrow);
765 g_value_set_boolean (value, gtk_toolbar_get_tooltips (toolbar));
768 g_value_set_enum (value, gtk_toolbar_get_icon_size (toolbar));
770 case PROP_ICON_SIZE_SET:
771 g_value_set_boolean (value, toolbar->icon_size_set);
774 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
780 gtk_toolbar_map (GtkWidget *widget)
782 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
784 GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->map (widget);
786 if (priv->event_window)
787 gdk_window_show_unraised (priv->event_window);
791 gtk_toolbar_unmap (GtkWidget *widget)
793 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
795 if (priv->event_window)
796 gdk_window_hide (priv->event_window);
798 GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unmap (widget);
802 gtk_toolbar_realize (GtkWidget *widget)
804 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
805 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
807 GdkWindowAttr attributes;
808 gint attributes_mask;
811 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
813 border_width = GTK_CONTAINER (widget)->border_width;
815 attributes.wclass = GDK_INPUT_ONLY;
816 attributes.window_type = GDK_WINDOW_CHILD;
817 attributes.x = widget->allocation.x + border_width;
818 attributes.y = widget->allocation.y + border_width;
819 attributes.width = widget->allocation.width - border_width * 2;
820 attributes.height = widget->allocation.height - border_width * 2;
821 attributes.event_mask = gtk_widget_get_events (widget);
822 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
823 GDK_BUTTON_RELEASE_MASK |
824 GDK_ENTER_NOTIFY_MASK |
825 GDK_LEAVE_NOTIFY_MASK);
827 attributes_mask = GDK_WA_X | GDK_WA_Y;
829 widget->window = gtk_widget_get_parent_window (widget);
830 g_object_ref (widget->window);
831 widget->style = gtk_style_attach (widget->style, widget->window);
833 priv->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
834 &attributes, attributes_mask);
835 gdk_window_set_user_data (priv->event_window, toolbar);
839 gtk_toolbar_unrealize (GtkWidget *widget)
841 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
843 if (priv->event_window)
845 gdk_window_set_user_data (priv->event_window, NULL);
846 gdk_window_destroy (priv->event_window);
847 priv->event_window = NULL;
850 if (GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unrealize)
851 (* GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unrealize) (widget);
855 gtk_toolbar_expose (GtkWidget *widget,
856 GdkEventExpose *event)
858 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
859 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
864 border_width = GTK_CONTAINER (widget)->border_width;
866 if (GTK_WIDGET_DRAWABLE (widget))
868 gtk_paint_box (widget->style,
870 GTK_WIDGET_STATE (widget),
871 get_shadow_type (toolbar),
872 &event->area, widget, "toolbar",
873 border_width + widget->allocation.x,
874 border_width + widget->allocation.y,
875 widget->allocation.width - 2 * border_width,
876 widget->allocation.height - 2 * border_width);
879 for (list = priv->content; list != NULL; list = list->next)
881 ToolbarContent *content = list->data;
883 toolbar_content_expose (content, GTK_CONTAINER (widget), event);
886 gtk_container_propagate_expose (GTK_CONTAINER (widget),
894 gtk_toolbar_size_request (GtkWidget *widget,
895 GtkRequisition *requisition)
897 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
898 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
900 gint max_child_height;
901 gint max_child_width;
902 gint max_homogeneous_child_width;
903 gint max_homogeneous_child_height;
904 gint homogeneous_size;
906 gint pack_front_size;
908 GtkRequisition arrow_requisition;
910 max_homogeneous_child_width = 0;
911 max_homogeneous_child_height = 0;
913 max_child_height = 0;
914 for (list = priv->content; list != NULL; list = list->next)
916 GtkRequisition requisition;
917 ToolbarContent *content = list->data;
919 if (!toolbar_content_visible (content, toolbar))
922 toolbar_content_size_request (content, toolbar, &requisition);
924 max_child_width = MAX (max_child_width, requisition.width);
925 max_child_height = MAX (max_child_height, requisition.height);
927 if (toolbar_content_is_homogeneous (content, toolbar))
929 max_homogeneous_child_width = MAX (max_homogeneous_child_width, requisition.width);
930 max_homogeneous_child_height = MAX (max_homogeneous_child_height, requisition.height);
934 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
935 homogeneous_size = max_homogeneous_child_width;
937 homogeneous_size = max_homogeneous_child_height;
940 for (list = priv->content; list != NULL; list = list->next)
942 ToolbarContent *content = list->data;
945 if (!toolbar_content_visible (content, toolbar))
948 if (toolbar_content_is_homogeneous (content, toolbar))
950 size = homogeneous_size;
954 GtkRequisition requisition;
956 toolbar_content_size_request (content, toolbar, &requisition);
958 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
959 size = requisition.width;
961 size = requisition.height;
964 pack_front_size += size;
967 if (priv->show_arrow && priv->api_mode == NEW_API)
969 gtk_widget_size_request (priv->arrow_button, &arrow_requisition);
971 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
972 long_req = arrow_requisition.width;
974 long_req = arrow_requisition.height;
976 /* There is no point requesting space for the arrow if that would take
977 * up more space than all the items combined
979 long_req = MIN (long_req, pack_front_size);
983 arrow_requisition.height = 0;
984 arrow_requisition.width = 0;
986 long_req = pack_front_size;
989 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
991 requisition->width = long_req;
992 requisition->height = MAX (max_child_height, arrow_requisition.height);
996 requisition->height = long_req;
997 requisition->width = MAX (max_child_width, arrow_requisition.width);
1001 ipadding = get_internal_padding (toolbar);
1003 requisition->width += 2 * (ipadding + GTK_CONTAINER (toolbar)->border_width);
1004 requisition->height += 2 * (ipadding + GTK_CONTAINER (toolbar)->border_width);
1006 if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
1008 requisition->width += 2 * widget->style->xthickness;
1009 requisition->height += 2 * widget->style->ythickness;
1012 toolbar->button_maxw = max_homogeneous_child_width;
1013 toolbar->button_maxh = max_homogeneous_child_height;
1017 position (GtkToolbar *toolbar,
1024 if (! GTK_TOOLBAR_GET_PRIVATE (toolbar)->animation)
1027 if (elapsed <= ACCEL_THRESHOLD)
1029 n_pixels = SLIDE_SPEED * elapsed;
1033 /* The formula is a second degree polynomial in
1034 * @elapsed that has the line SLIDE_SPEED * @elapsed
1035 * as tangent for @elapsed == ACCEL_THRESHOLD.
1036 * This makes @n_pixels a smooth function of elapsed time.
1038 n_pixels = (SLIDE_SPEED / ACCEL_THRESHOLD) * elapsed * elapsed -
1039 SLIDE_SPEED * elapsed + SLIDE_SPEED * ACCEL_THRESHOLD;
1043 return MIN (from + n_pixels, to);
1045 return MAX (from - n_pixels, to);
1049 compute_intermediate_allocation (GtkToolbar *toolbar,
1050 const GtkAllocation *start,
1051 const GtkAllocation *goal,
1052 GtkAllocation *intermediate)
1054 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1055 gdouble elapsed = g_timer_elapsed (priv->timer, NULL);
1057 intermediate->x = position (toolbar, start->x, goal->x, elapsed);
1058 intermediate->y = position (toolbar, start->y, goal->y, elapsed);
1059 intermediate->width = position (toolbar, start->x + start->width,
1060 goal->x + goal->width,
1061 elapsed) - intermediate->x;
1062 intermediate->height = position (toolbar, start->y + start->height,
1063 goal->y + goal->height,
1064 elapsed) - intermediate->y;
1068 fixup_allocation_for_rtl (gint total_size,
1069 GtkAllocation *allocation)
1071 allocation->x += (total_size - (2 * allocation->x + allocation->width));
1075 fixup_allocation_for_vertical (GtkAllocation *allocation)
1079 tmp = allocation->x;
1080 allocation->x = allocation->y;
1081 allocation->y = tmp;
1083 tmp = allocation->width;
1084 allocation->width = allocation->height;
1085 allocation->height = tmp;
1089 get_item_size (GtkToolbar *toolbar,
1090 ToolbarContent *content)
1092 GtkRequisition requisition;
1094 toolbar_content_size_request (content, toolbar, &requisition);
1096 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
1098 if (toolbar_content_is_homogeneous (content, toolbar))
1099 return toolbar->button_maxw;
1101 return requisition.width;
1105 if (toolbar_content_is_homogeneous (content, toolbar))
1106 return toolbar->button_maxh;
1108 return requisition.height;
1113 slide_idle_handler (gpointer data)
1115 GtkToolbar *toolbar = data;
1116 GtkToolbarPrivate *priv;
1119 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1121 if (priv->need_sync)
1124 priv->need_sync = FALSE;
1127 for (list = priv->content; list != NULL; list = list->next)
1129 ToolbarContent *content = list->data;
1131 GtkAllocation goal_allocation;
1132 GtkAllocation allocation;
1135 state = toolbar_content_get_state (content);
1136 toolbar_content_get_goal_allocation (content, &goal_allocation);
1137 toolbar_content_get_allocation (content, &allocation);
1141 if (state == NOT_ALLOCATED)
1143 /* an unallocated item means that size allocate has to
1144 * called at least once more
1149 /* An invisible item with a goal allocation of
1150 * 0 is already at its goal.
1152 if ((state == NORMAL || state == OVERFLOWN) &&
1153 ((goal_allocation.width != 0 &&
1154 goal_allocation.height != 0) ||
1155 toolbar_content_child_visible (content)))
1157 if ((goal_allocation.x != allocation.x ||
1158 goal_allocation.y != allocation.y ||
1159 goal_allocation.width != allocation.width ||
1160 goal_allocation.height != allocation.height))
1162 /* An item is not in its right position yet. Note
1163 * that OVERFLOWN items do get an allocation in
1164 * gtk_toolbar_size_allocate(). This way you can see
1165 * them slide back in when you drag an item off the
1172 if (toolbar_content_is_placeholder (content) &&
1173 toolbar_content_disappearing (content) &&
1174 toolbar_content_child_visible (content))
1176 /* A disappearing placeholder is still visible.
1184 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1186 GDK_THREADS_LEAVE ();
1191 priv->is_sliding = FALSE;
1198 rect_within (GtkAllocation *a1,
1201 return (a1->x >= a2->x &&
1202 a1->x + a1->width <= a2->x + a2->width &&
1204 a1->y + a1->height <= a2->y + a2->height);
1208 gtk_toolbar_begin_sliding (GtkToolbar *toolbar)
1210 GtkWidget *widget = GTK_WIDGET (toolbar);
1211 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1219 /* Start the sliding. This function copies the allocation of every
1220 * item into content->start_allocation. For items that haven't
1221 * been allocated yet, we calculate their position and save that
1222 * in start_allocatino along with zero width and zero height.
1224 * FIXME: It would be nice if we could share this code with
1225 * the equivalent in gtk_widget_size_allocate().
1227 priv->is_sliding = TRUE;
1230 priv->idle_id = gdk_threads_add_idle (slide_idle_handler, toolbar);
1232 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1233 vertical = (toolbar->orientation == GTK_ORIENTATION_VERTICAL);
1234 border_width = get_internal_padding (toolbar) + GTK_CONTAINER (toolbar)->border_width;
1238 cur_x = widget->allocation.width - border_width - widget->style->xthickness;
1239 cur_y = widget->allocation.height - border_width - widget->style->ythickness;
1243 cur_x = border_width + widget->style->xthickness;
1244 cur_y = border_width + widget->style->ythickness;
1247 cur_x += widget->allocation.x;
1248 cur_y += widget->allocation.y;
1250 for (list = priv->content; list != NULL; list = list->next)
1252 ToolbarContent *content = list->data;
1253 GtkAllocation new_start_allocation;
1254 GtkAllocation item_allocation;
1257 state = toolbar_content_get_state (content);
1258 toolbar_content_get_allocation (content, &item_allocation);
1260 if ((state == NORMAL &&
1261 rect_within (&item_allocation, &(widget->allocation))) ||
1264 new_start_allocation = item_allocation;
1268 new_start_allocation.x = cur_x;
1269 new_start_allocation.y = cur_y;
1273 new_start_allocation.width = widget->allocation.width -
1274 2 * border_width - 2 * widget->style->xthickness;
1275 new_start_allocation.height = 0;
1279 new_start_allocation.width = 0;
1280 new_start_allocation.height = widget->allocation.height -
1281 2 * border_width - 2 * widget->style->ythickness;
1286 cur_y = new_start_allocation.y + new_start_allocation.height;
1288 cur_x = new_start_allocation.x;
1290 cur_x = new_start_allocation.x + new_start_allocation.width;
1292 toolbar_content_set_start_allocation (content, &new_start_allocation);
1295 /* This resize will run before the first idle handler. This
1296 * will make sure that items get the right goal allocation
1297 * so that the idle handler will not immediately return
1300 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1301 g_timer_reset (priv->timer);
1305 gtk_toolbar_stop_sliding (GtkToolbar *toolbar)
1307 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1309 if (priv->is_sliding)
1313 priv->is_sliding = FALSE;
1317 g_source_remove (priv->idle_id);
1321 list = priv->content;
1324 ToolbarContent *content = list->data;
1327 if (toolbar_content_is_placeholder (content))
1329 toolbar_content_remove (content, toolbar);
1330 toolbar_content_free (content);
1334 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1339 remove_item (GtkWidget *menu_item,
1342 gtk_container_remove (GTK_CONTAINER (menu_item->parent), menu_item);
1346 menu_deactivated (GtkWidget *menu,
1347 GtkToolbar *toolbar)
1349 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1350 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->arrow_button), FALSE);
1354 menu_detached (GtkWidget *toolbar,
1357 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1362 rebuild_menu (GtkToolbar *toolbar)
1364 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1365 GList *list, *children;
1369 priv->menu = GTK_MENU (gtk_menu_new());
1370 gtk_menu_attach_to_widget (priv->menu,
1371 GTK_WIDGET (toolbar),
1374 g_signal_connect (priv->menu, "deactivate", G_CALLBACK (menu_deactivated), toolbar);
1377 gtk_container_foreach (GTK_CONTAINER (priv->menu), remove_item, NULL);
1379 for (list = priv->content; list != NULL; list = list->next)
1381 ToolbarContent *content = list->data;
1383 if (toolbar_content_get_state (content) == OVERFLOWN &&
1384 !toolbar_content_is_placeholder (content))
1386 GtkWidget *menu_item = toolbar_content_retrieve_menu_item (content);
1390 g_assert (GTK_IS_MENU_ITEM (menu_item));
1391 gtk_menu_shell_append (GTK_MENU_SHELL (priv->menu), menu_item);
1396 /* Remove leading and trailing separator items */
1397 children = gtk_container_get_children (GTK_CONTAINER (priv->menu));
1400 while (list && GTK_IS_SEPARATOR_MENU_ITEM (list->data))
1402 GtkWidget *child = list->data;
1404 gtk_container_remove (GTK_CONTAINER (priv->menu), child);
1407 g_list_free (children);
1409 /* Regenerate the list of children so we don't try to remove items twice */
1410 children = gtk_container_get_children (GTK_CONTAINER (priv->menu));
1412 list = g_list_last (children);
1413 while (list && GTK_IS_SEPARATOR_MENU_ITEM (list->data))
1415 GtkWidget *child = list->data;
1417 gtk_container_remove (GTK_CONTAINER (priv->menu), child);
1420 g_list_free (children);
1422 priv->need_rebuild = FALSE;
1426 gtk_toolbar_size_allocate (GtkWidget *widget,
1427 GtkAllocation *allocation)
1429 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1430 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1431 GtkAllocation *allocations;
1432 ItemState *new_states;
1433 GtkAllocation arrow_allocation;
1435 gint size, pos, short_size;
1438 gboolean need_arrow;
1439 gint n_expand_items;
1441 gint available_size;
1444 GtkRequisition arrow_requisition;
1445 gboolean overflowing;
1446 gboolean size_changed;
1447 GtkAllocation item_area;
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 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
1481 available_size = size = allocation->width - 2 * border_width;
1482 short_size = allocation->height - 2 * border_width;
1483 arrow_size = arrow_requisition.width;
1485 if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
1487 available_size -= 2 * widget->style->xthickness;
1488 short_size -= 2 * widget->style->ythickness;
1493 available_size = size = allocation->height - 2 * border_width;
1494 short_size = allocation->width - 2 * border_width;
1495 arrow_size = arrow_requisition.height;
1497 if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
1499 available_size -= 2 * widget->style->ythickness;
1500 short_size -= 2 * widget->style->xthickness;
1504 n_items = g_list_length (priv->content);
1505 allocations = g_new0 (GtkAllocation, n_items);
1506 new_states = g_new0 (ItemState, n_items);
1510 for (list = priv->content; list != NULL; list = list->next)
1512 ToolbarContent *content = list->data;
1514 if (toolbar_content_visible (content, toolbar))
1516 needed_size += get_item_size (toolbar, content);
1518 /* Do we need an arrow?
1520 * Assume we don't, and see if any non-separator item with a
1521 * proxy menu item is then going to overflow.
1523 if (needed_size > available_size &&
1526 priv->api_mode == NEW_API &&
1527 toolbar_content_has_proxy_menu_item (content) &&
1528 !toolbar_content_is_separator (content))
1536 size = available_size - arrow_size;
1538 size = available_size;
1540 /* calculate widths and states of items */
1541 overflowing = FALSE;
1542 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1544 ToolbarContent *content = list->data;
1547 if (!toolbar_content_visible (content, toolbar))
1549 new_states[i] = HIDDEN;
1553 item_size = get_item_size (toolbar, content);
1554 if (item_size <= size && !overflowing)
1557 allocations[i].width = item_size;
1558 new_states[i] = NORMAL;
1563 new_states[i] = OVERFLOWN;
1564 allocations[i].width = item_size;
1568 /* calculate width of arrow */
1571 arrow_allocation.width = arrow_size;
1572 arrow_allocation.height = MAX (short_size, 1);
1575 /* expand expandable items */
1577 /* We don't expand when there is an overflow menu, because that leads to
1578 * weird jumps when items get moved to the overflow menu and the expanding
1579 * items suddenly get a lot of extra space
1583 gint max_child_expand;
1586 for (i = 0, list = priv->content; list != NULL; list = list->next, ++i)
1588 ToolbarContent *content = list->data;
1590 if (toolbar_content_get_expand (content) && new_states[i] == NORMAL)
1594 max_child_expand = get_max_child_expand (toolbar);
1595 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1597 ToolbarContent *content = list->data;
1599 if (toolbar_content_get_expand (content) && new_states[i] == NORMAL)
1601 gint extra = size / n_expand_items;
1602 if (size % n_expand_items != 0)
1605 if (extra > max_child_expand)
1606 extra = max_child_expand;
1608 allocations[i].width += extra;
1614 g_assert (n_expand_items == 0);
1617 /* position items */
1619 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1621 /* both NORMAL and OVERFLOWN items get a position. This ensures
1622 * that sliding will work for OVERFLOWN items too
1624 if (new_states[i] == NORMAL ||
1625 new_states[i] == OVERFLOWN)
1627 allocations[i].x = pos;
1628 allocations[i].y = border_width;
1629 allocations[i].height = short_size;
1631 pos += allocations[i].width;
1635 /* position arrow */
1638 arrow_allocation.x = available_size - border_width - arrow_allocation.width;
1639 arrow_allocation.y = border_width;
1642 item_area.x = border_width;
1643 item_area.y = border_width;
1644 item_area.width = available_size - (need_arrow? arrow_size : 0);
1645 item_area.height = short_size;
1647 /* fix up allocations in the vertical or RTL cases */
1648 if (toolbar->orientation == GTK_ORIENTATION_VERTICAL)
1650 for (i = 0; i < n_items; ++i)
1651 fixup_allocation_for_vertical (&(allocations[i]));
1654 fixup_allocation_for_vertical (&arrow_allocation);
1656 fixup_allocation_for_vertical (&item_area);
1658 else if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL)
1660 for (i = 0; i < n_items; ++i)
1661 fixup_allocation_for_rtl (available_size, &(allocations[i]));
1664 fixup_allocation_for_rtl (available_size, &arrow_allocation);
1666 fixup_allocation_for_rtl (available_size, &item_area);
1669 /* translate the items by allocation->(x,y) */
1670 for (i = 0; i < n_items; ++i)
1672 allocations[i].x += allocation->x;
1673 allocations[i].y += allocation->y;
1675 if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
1677 allocations[i].x += widget->style->xthickness;
1678 allocations[i].y += widget->style->ythickness;
1684 arrow_allocation.x += allocation->x;
1685 arrow_allocation.y += allocation->y;
1687 if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
1689 arrow_allocation.x += widget->style->xthickness;
1690 arrow_allocation.y += widget->style->ythickness;
1694 item_area.x += allocation->x;
1695 item_area.y += allocation->y;
1696 if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
1698 item_area.x += widget->style->xthickness;
1699 item_area.y += widget->style->ythickness;
1702 /* did anything change? */
1703 for (list = priv->content, i = 0; list != NULL; list = list->next, i++)
1705 ToolbarContent *content = list->data;
1707 if (toolbar_content_get_state (content) == NORMAL &&
1708 new_states[i] != NORMAL)
1710 /* an item disappeared and we didn't change size, so begin sliding */
1711 if (!size_changed && priv->api_mode == NEW_API)
1712 gtk_toolbar_begin_sliding (toolbar);
1716 /* finally allocate the items */
1717 if (priv->is_sliding)
1719 for (list = priv->content, i = 0; list != NULL; list = list->next, i++)
1721 ToolbarContent *content = list->data;
1723 toolbar_content_set_goal_allocation (content, &(allocations[i]));
1727 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1729 ToolbarContent *content = list->data;
1731 if (new_states[i] == OVERFLOWN ||
1732 new_states[i] == NORMAL)
1734 GtkAllocation alloc;
1735 GtkAllocation start_allocation = { 0, };
1736 GtkAllocation goal_allocation;
1738 if (priv->is_sliding)
1740 toolbar_content_get_start_allocation (content, &start_allocation);
1741 toolbar_content_get_goal_allocation (content, &goal_allocation);
1743 compute_intermediate_allocation (toolbar,
1748 priv->need_sync = TRUE;
1752 alloc = allocations[i];
1755 if (alloc.width <= 0 || alloc.height <= 0)
1757 toolbar_content_set_child_visible (content, toolbar, FALSE);
1761 if (!rect_within (&alloc, &item_area))
1763 toolbar_content_set_child_visible (content, toolbar, FALSE);
1764 toolbar_content_size_allocate (content, &alloc);
1768 toolbar_content_set_child_visible (content, toolbar, TRUE);
1769 toolbar_content_size_allocate (content, &alloc);
1775 toolbar_content_set_child_visible (content, toolbar, FALSE);
1778 toolbar_content_set_state (content, new_states[i]);
1781 if (priv->menu && priv->need_rebuild)
1782 rebuild_menu (toolbar);
1786 gtk_widget_size_allocate (GTK_WIDGET (priv->arrow_button),
1788 gtk_widget_show (GTK_WIDGET (priv->arrow_button));
1792 gtk_widget_hide (GTK_WIDGET (priv->arrow_button));
1794 if (priv->menu && GTK_WIDGET_VISIBLE (priv->menu))
1795 gtk_menu_shell_deactivate (GTK_MENU_SHELL (priv->menu));
1798 g_free (allocations);
1799 g_free (new_states);
1803 gtk_toolbar_update_button_relief (GtkToolbar *toolbar)
1805 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1807 gtk_toolbar_reconfigured (toolbar);
1809 gtk_button_set_relief (GTK_BUTTON (priv->arrow_button), get_button_relief (toolbar));
1813 gtk_toolbar_style_set (GtkWidget *widget,
1814 GtkStyle *prev_style)
1816 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
1818 priv->max_homogeneous_pixels = -1;
1820 if (GTK_WIDGET_REALIZED (widget))
1821 gtk_style_set_background (widget->style, widget->window, widget->state);
1824 gtk_toolbar_update_button_relief (GTK_TOOLBAR (widget));
1828 gtk_toolbar_list_children_in_focus_order (GtkToolbar *toolbar,
1829 GtkDirectionType dir)
1831 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1832 GList *result = NULL;
1836 /* generate list of children in reverse logical order */
1838 for (list = priv->content; list != NULL; list = list->next)
1840 ToolbarContent *content = list->data;
1843 widget = toolbar_content_get_widget (content);
1846 result = g_list_prepend (result, widget);
1849 result = g_list_prepend (result, priv->arrow_button);
1851 rtl = (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL);
1853 /* move in logical order when
1855 * - dir is TAB_FORWARD
1857 * - in RTL mode and moving left or up
1859 * - in LTR mode and moving right or down
1861 if (dir == GTK_DIR_TAB_FORWARD ||
1862 (rtl && (dir == GTK_DIR_UP || dir == GTK_DIR_LEFT)) ||
1863 (!rtl && (dir == GTK_DIR_DOWN || dir == GTK_DIR_RIGHT)))
1865 result = g_list_reverse (result);
1872 gtk_toolbar_focus_home_or_end (GtkToolbar *toolbar,
1873 gboolean focus_home)
1875 GList *children, *list;
1876 GtkDirectionType dir = focus_home? GTK_DIR_RIGHT : GTK_DIR_LEFT;
1878 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1880 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL)
1882 children = g_list_reverse (children);
1884 dir = (dir == GTK_DIR_RIGHT)? GTK_DIR_LEFT : GTK_DIR_RIGHT;
1887 for (list = children; list != NULL; list = list->next)
1889 GtkWidget *child = list->data;
1891 if (GTK_CONTAINER (toolbar)->focus_child == child)
1894 if (GTK_WIDGET_MAPPED (child) && gtk_widget_child_focus (child, dir))
1898 g_list_free (children);
1903 /* Keybinding handler. This function is called when the user presses
1904 * Ctrl TAB or an arrow key.
1907 gtk_toolbar_move_focus (GtkToolbar *toolbar,
1908 GtkDirectionType dir)
1911 gboolean try_focus = FALSE;
1913 GtkContainer *container = GTK_CONTAINER (toolbar);
1915 if (container->focus_child &&
1916 gtk_widget_child_focus (container->focus_child, dir))
1921 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1923 for (list = children; list != NULL; list = list->next)
1925 GtkWidget *child = list->data;
1927 if (try_focus && GTK_WIDGET_MAPPED (child) && gtk_widget_child_focus (child, dir))
1930 if (child == GTK_CONTAINER (toolbar)->focus_child)
1934 g_list_free (children);
1939 /* The focus handler for the toolbar. It called when the user presses
1940 * TAB or otherwise tries to focus the toolbar.
1943 gtk_toolbar_focus (GtkWidget *widget,
1944 GtkDirectionType dir)
1946 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1947 GList *children, *list;
1948 gboolean result = FALSE;
1950 /* if focus is already somewhere inside the toolbar then return FALSE.
1951 * The only way focus can stay inside the toolbar is when the user presses
1952 * arrow keys or Ctrl TAB (both of which are handled by the
1953 * gtk_toolbar_move_focus() keybinding function.
1955 if (GTK_CONTAINER (widget)->focus_child)
1958 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1960 for (list = children; list != NULL; list = list->next)
1962 GtkWidget *child = list->data;
1964 if (GTK_WIDGET_MAPPED (child) && gtk_widget_child_focus (child, dir))
1971 g_list_free (children);
1976 static GtkSettings *
1977 toolbar_get_settings (GtkToolbar *toolbar)
1979 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1980 return priv->settings;
1984 style_change_notify (GtkToolbar *toolbar)
1986 if (!toolbar->style_set)
1988 /* pretend it was set, then unset, thus reverting to new default */
1989 toolbar->style_set = TRUE;
1990 gtk_toolbar_unset_style (toolbar);
1995 icon_size_change_notify (GtkToolbar *toolbar)
1997 if (!toolbar->icon_size_set)
1999 /* pretend it was set, then unset, thus reverting to new default */
2000 toolbar->icon_size_set = TRUE;
2001 gtk_toolbar_unset_icon_size (toolbar);
2006 animation_change_notify (GtkToolbar *toolbar)
2008 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2009 GtkSettings *settings = toolbar_get_settings (toolbar);
2013 g_object_get (settings,
2014 "gtk-enable-animations", &animation,
2017 animation = DEFAULT_ANIMATION_STATE;
2019 priv->animation = animation;
2023 settings_change_notify (GtkSettings *settings,
2024 const GParamSpec *pspec,
2025 GtkToolbar *toolbar)
2027 if (! strcmp (pspec->name, "gtk-toolbar-style"))
2028 style_change_notify (toolbar);
2029 else if (! strcmp (pspec->name, "gtk-toolbar-icon-size"))
2030 icon_size_change_notify (toolbar);
2031 else if (! strcmp (pspec->name, "gtk-enable-animations"))
2032 animation_change_notify (toolbar);
2036 gtk_toolbar_screen_changed (GtkWidget *widget,
2037 GdkScreen *previous_screen)
2039 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
2040 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
2041 GtkSettings *old_settings = toolbar_get_settings (toolbar);
2042 GtkSettings *settings;
2044 if (gtk_widget_has_screen (GTK_WIDGET (toolbar)))
2045 settings = gtk_widget_get_settings (GTK_WIDGET (toolbar));
2049 if (settings == old_settings)
2054 g_signal_handler_disconnect (old_settings, priv->settings_connection);
2056 g_object_unref (old_settings);
2061 priv->settings_connection =
2062 g_signal_connect (settings, "notify",
2063 G_CALLBACK (settings_change_notify),
2066 priv->settings = g_object_ref (settings);
2069 priv->settings = NULL;
2071 style_change_notify (toolbar);
2072 icon_size_change_notify (toolbar);
2073 animation_change_notify (toolbar);
2077 find_drop_index (GtkToolbar *toolbar,
2081 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2082 GList *interesting_content;
2084 GtkOrientation orientation;
2085 GtkTextDirection direction;
2086 gint best_distance = G_MAXINT;
2090 ToolbarContent *best_content;
2091 GtkAllocation allocation;
2093 /* list items we care about wrt. drag and drop */
2094 interesting_content = NULL;
2095 for (list = priv->content; list != NULL; list = list->next)
2097 ToolbarContent *content = list->data;
2099 if (toolbar_content_get_state (content) == NORMAL)
2100 interesting_content = g_list_prepend (interesting_content, content);
2102 interesting_content = g_list_reverse (interesting_content);
2104 if (!interesting_content)
2107 orientation = toolbar->orientation;
2108 direction = gtk_widget_get_direction (GTK_WIDGET (toolbar));
2110 /* distance to first interesting item */
2111 best_content = interesting_content->data;
2112 toolbar_content_get_allocation (best_content, &allocation);
2114 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2118 if (direction == GTK_TEXT_DIR_LTR)
2121 pos = allocation.x + allocation.width;
2129 best_content = NULL;
2130 best_distance = ABS (pos - cursor);
2132 /* distance to far end of each item */
2133 for (list = interesting_content; list != NULL; list = list->next)
2135 ToolbarContent *content = list->data;
2137 toolbar_content_get_allocation (content, &allocation);
2139 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2141 if (direction == GTK_TEXT_DIR_LTR)
2142 pos = allocation.x + allocation.width;
2148 pos = allocation.y + allocation.height;
2151 distance = ABS (pos - cursor);
2153 if (distance < best_distance)
2155 best_distance = distance;
2156 best_content = content;
2160 g_list_free (interesting_content);
2165 return g_list_index (priv->content, best_content) + 1;
2169 reset_all_placeholders (GtkToolbar *toolbar)
2171 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2174 for (list = priv->content; list != NULL; list = list->next)
2176 ToolbarContent *content = list->data;
2177 if (toolbar_content_is_placeholder (content))
2178 toolbar_content_set_disappearing (content, TRUE);
2183 physical_to_logical (GtkToolbar *toolbar,
2186 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2190 g_assert (physical >= 0);
2193 for (list = priv->content; list && physical > 0; list = list->next)
2195 ToolbarContent *content = list->data;
2197 if (!toolbar_content_is_placeholder (content))
2202 g_assert (physical == 0);
2208 logical_to_physical (GtkToolbar *toolbar,
2211 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2215 g_assert (logical >= 0);
2218 for (list = priv->content; list; list = list->next)
2220 ToolbarContent *content = list->data;
2222 if (!toolbar_content_is_placeholder (content))
2232 g_assert (logical == 0);
2238 * gtk_toolbar_set_drop_highlight_item:
2239 * @toolbar: a #GtkToolbar
2240 * @tool_item: a #GtkToolItem, or %NULL to turn of highlighting
2241 * @index_: a position on @toolbar
2243 * Highlights @toolbar to give an idea of what it would look like
2244 * if @item was added to @toolbar at the position indicated by @index_.
2245 * If @item is %NULL, highlighting is turned off. In that case @index_
2248 * The @tool_item passed to this function must not be part of any widget
2249 * hierarchy. When an item is set as drop highlight item it can not
2250 * added to any widget hierarchy or used as highlight item for another
2256 gtk_toolbar_set_drop_highlight_item (GtkToolbar *toolbar,
2257 GtkToolItem *tool_item,
2260 ToolbarContent *content;
2261 GtkToolbarPrivate *priv;
2263 GtkRequisition requisition;
2264 GtkRequisition old_requisition;
2265 gboolean restart_sliding;
2267 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2268 g_return_if_fail (tool_item == NULL || GTK_IS_TOOL_ITEM (tool_item));
2270 gtk_toolbar_check_new_api (toolbar);
2272 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2276 if (priv->highlight_tool_item)
2278 gtk_widget_unparent (GTK_WIDGET (priv->highlight_tool_item));
2279 g_object_unref (priv->highlight_tool_item);
2280 priv->highlight_tool_item = NULL;
2283 reset_all_placeholders (toolbar);
2284 gtk_toolbar_begin_sliding (toolbar);
2288 n_items = gtk_toolbar_get_n_items (toolbar);
2289 if (index_ < 0 || index_ > n_items)
2292 if (tool_item != priv->highlight_tool_item)
2294 if (priv->highlight_tool_item)
2295 g_object_unref (priv->highlight_tool_item);
2297 g_object_ref_sink (tool_item);
2299 priv->highlight_tool_item = tool_item;
2301 gtk_widget_set_parent (GTK_WIDGET (priv->highlight_tool_item),
2302 GTK_WIDGET (toolbar));
2305 index_ = logical_to_physical (toolbar, index_);
2307 content = g_list_nth_data (priv->content, index_);
2311 ToolbarContent *prev_content;
2313 prev_content = g_list_nth_data (priv->content, index_ - 1);
2315 if (prev_content && toolbar_content_is_placeholder (prev_content))
2316 content = prev_content;
2319 if (!content || !toolbar_content_is_placeholder (content))
2321 GtkWidget *placeholder;
2323 placeholder = GTK_WIDGET (gtk_separator_tool_item_new ());
2325 content = toolbar_content_new_tool_item (toolbar,
2326 GTK_TOOL_ITEM (placeholder),
2328 gtk_widget_show (placeholder);
2332 g_assert (toolbar_content_is_placeholder (content));
2334 gtk_widget_size_request (GTK_WIDGET (priv->highlight_tool_item),
2337 toolbar_content_set_expand (content, gtk_tool_item_get_expand (tool_item));
2339 restart_sliding = FALSE;
2340 toolbar_content_size_request (content, toolbar, &old_requisition);
2341 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
2343 requisition.height = -1;
2344 if (requisition.width != old_requisition.width)
2345 restart_sliding = TRUE;
2349 requisition.width = -1;
2350 if (requisition.height != old_requisition.height)
2351 restart_sliding = TRUE;
2354 if (toolbar_content_disappearing (content))
2355 restart_sliding = TRUE;
2357 reset_all_placeholders (toolbar);
2358 toolbar_content_set_disappearing (content, FALSE);
2360 toolbar_content_set_size_request (content,
2361 requisition.width, requisition.height);
2363 if (restart_sliding)
2364 gtk_toolbar_begin_sliding (toolbar);
2368 gtk_toolbar_get_child_property (GtkContainer *container,
2374 GtkToolItem *item = GTK_TOOL_ITEM (child);
2376 switch (property_id)
2378 case CHILD_PROP_HOMOGENEOUS:
2379 g_value_set_boolean (value, gtk_tool_item_get_homogeneous (item));
2382 case CHILD_PROP_EXPAND:
2383 g_value_set_boolean (value, gtk_tool_item_get_expand (item));
2387 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
2393 gtk_toolbar_set_child_property (GtkContainer *container,
2396 const GValue *value,
2399 switch (property_id)
2401 case CHILD_PROP_HOMOGENEOUS:
2402 gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (child), g_value_get_boolean (value));
2405 case CHILD_PROP_EXPAND:
2406 gtk_tool_item_set_expand (GTK_TOOL_ITEM (child), g_value_get_boolean (value));
2410 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
2416 gtk_toolbar_show_all (GtkWidget *widget)
2418 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
2421 for (list = priv->content; list != NULL; list = list->next)
2423 ToolbarContent *content = list->data;
2425 toolbar_content_show_all (content);
2428 gtk_widget_show (widget);
2432 gtk_toolbar_hide_all (GtkWidget *widget)
2434 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
2437 for (list = priv->content; list != NULL; list = list->next)
2439 ToolbarContent *content = list->data;
2441 toolbar_content_hide_all (content);
2444 gtk_widget_hide (widget);
2448 gtk_toolbar_add (GtkContainer *container,
2451 GtkToolbar *toolbar;
2453 g_return_if_fail (GTK_IS_TOOLBAR (container));
2454 g_return_if_fail (widget != NULL);
2456 toolbar = GTK_TOOLBAR (container);
2458 if (GTK_IS_TOOL_ITEM (widget))
2459 gtk_toolbar_insert (toolbar, GTK_TOOL_ITEM (widget), -1);
2461 gtk_toolbar_append_widget (toolbar, widget, NULL, NULL);
2465 gtk_toolbar_remove (GtkContainer *container,
2468 GtkToolbar *toolbar;
2469 GtkToolbarPrivate *priv;
2470 ToolbarContent *content_to_remove;
2473 g_return_if_fail (GTK_IS_TOOLBAR (container));
2474 g_return_if_fail (GTK_IS_WIDGET (widget));
2476 toolbar = GTK_TOOLBAR (container);
2477 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2479 content_to_remove = NULL;
2480 for (list = priv->content; list != NULL; list = list->next)
2482 ToolbarContent *content = list->data;
2485 child = toolbar_content_get_widget (content);
2486 if (child && child == widget)
2488 content_to_remove = content;
2493 g_return_if_fail (content_to_remove != NULL);
2495 toolbar_content_remove (content_to_remove, toolbar);
2496 toolbar_content_free (content_to_remove);
2500 gtk_toolbar_forall (GtkContainer *container,
2501 gboolean include_internals,
2502 GtkCallback callback,
2503 gpointer callback_data)
2505 GtkToolbar *toolbar = GTK_TOOLBAR (container);
2506 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2509 g_return_if_fail (callback != NULL);
2511 list = priv->content;
2514 ToolbarContent *content = list->data;
2515 GList *next = list->next;
2517 if (include_internals || !toolbar_content_is_placeholder (content))
2519 GtkWidget *child = toolbar_content_get_widget (content);
2522 (*callback) (child, callback_data);
2528 if (include_internals)
2529 (* callback) (priv->arrow_button, callback_data);
2533 gtk_toolbar_child_type (GtkContainer *container)
2535 return GTK_TYPE_TOOL_ITEM;
2539 gtk_toolbar_reconfigured (GtkToolbar *toolbar)
2541 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2544 list = priv->content;
2547 ToolbarContent *content = list->data;
2548 GList *next = list->next;
2550 toolbar_content_toolbar_reconfigured (content, toolbar);
2557 gtk_toolbar_orientation_changed (GtkToolbar *toolbar,
2558 GtkOrientation orientation)
2560 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2561 if (toolbar->orientation != orientation)
2563 toolbar->orientation = orientation;
2565 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2566 gtk_arrow_set (GTK_ARROW (priv->arrow), GTK_ARROW_DOWN, GTK_SHADOW_NONE);
2568 gtk_arrow_set (GTK_ARROW (priv->arrow), GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
2570 gtk_toolbar_reconfigured (toolbar);
2572 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
2573 g_object_notify (G_OBJECT (toolbar), "orientation");
2578 gtk_toolbar_real_style_changed (GtkToolbar *toolbar,
2579 GtkToolbarStyle style)
2581 if (toolbar->style != style)
2583 toolbar->style = style;
2585 gtk_toolbar_reconfigured (toolbar);
2587 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
2588 g_object_notify (G_OBJECT (toolbar), "toolbar-style");
2593 menu_position_func (GtkMenu *menu,
2599 GtkToolbar *toolbar = GTK_TOOLBAR (user_data);
2600 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2602 GtkRequisition menu_req;
2603 GdkRectangle monitor;
2607 gtk_widget_size_request (priv->arrow_button, &req);
2608 gtk_widget_size_request (GTK_WIDGET (menu), &menu_req);
2610 screen = gtk_widget_get_screen (GTK_WIDGET (menu));
2611 monitor_num = gdk_screen_get_monitor_at_window (screen, priv->arrow_button->window);
2612 if (monitor_num < 0)
2614 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
2616 gdk_window_get_origin (GTK_BUTTON (priv->arrow_button)->event_window, x, y);
2617 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
2619 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
2620 *x += priv->arrow_button->allocation.width - req.width;
2622 *x += req.width - menu_req.width;
2624 if ((*y + priv->arrow_button->allocation.height + menu_req.height) <= monitor.y + monitor.height)
2625 *y += priv->arrow_button->allocation.height;
2626 else if ((*y - menu_req.height) >= monitor.y)
2627 *y -= menu_req.height;
2628 else if (monitor.y + monitor.height - (*y + priv->arrow_button->allocation.height) > *y)
2629 *y += priv->arrow_button->allocation.height;
2631 *y -= menu_req.height;
2635 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
2636 *x += priv->arrow_button->allocation.width;
2638 *x -= menu_req.width;
2640 if (*y + menu_req.height > monitor.y + monitor.height &&
2641 *y + priv->arrow_button->allocation.height - monitor.y > monitor.y + monitor.height - *y)
2642 *y += priv->arrow_button->allocation.height - menu_req.height;
2649 show_menu (GtkToolbar *toolbar,
2650 GdkEventButton *event)
2652 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2654 rebuild_menu (toolbar);
2656 gtk_widget_show_all (GTK_WIDGET (priv->menu));
2658 gtk_menu_popup (priv->menu, NULL, NULL,
2659 menu_position_func, toolbar,
2660 event? event->button : 0,
2661 event? event->time : gtk_get_current_event_time());
2665 gtk_toolbar_arrow_button_clicked (GtkWidget *button,
2666 GtkToolbar *toolbar)
2668 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2670 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->arrow_button)) &&
2671 (!priv->menu || !GTK_WIDGET_VISIBLE (priv->menu)))
2673 /* We only get here when the button is clicked with the keyboard,
2674 * because mouse button presses result in the menu being shown so
2675 * that priv->menu would be non-NULL and visible.
2677 show_menu (toolbar, NULL);
2678 gtk_menu_shell_select_first (GTK_MENU_SHELL (priv->menu), FALSE);
2683 gtk_toolbar_arrow_button_press (GtkWidget *button,
2684 GdkEventButton *event,
2685 GtkToolbar *toolbar)
2687 show_menu (toolbar, event);
2688 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
2694 gtk_toolbar_button_press (GtkWidget *toolbar,
2695 GdkEventButton *event)
2697 if (event->button == 3)
2699 gboolean return_value;
2701 g_signal_emit (toolbar, toolbar_signals[POPUP_CONTEXT_MENU], 0,
2702 (int)event->x_root, (int)event->y_root, event->button,
2705 return return_value;
2712 gtk_toolbar_popup_menu (GtkWidget *toolbar)
2714 gboolean return_value;
2715 /* This function is the handler for the "popup menu" keybinding,
2716 * ie., it is called when the user presses Shift F10
2718 g_signal_emit (toolbar, toolbar_signals[POPUP_CONTEXT_MENU], 0,
2719 -1, -1, -1, &return_value);
2721 return return_value;
2727 * Creates a new toolbar.
2729 * Return Value: the newly-created toolbar.
2732 gtk_toolbar_new (void)
2734 GtkToolbar *toolbar;
2736 toolbar = g_object_new (GTK_TYPE_TOOLBAR, NULL);
2738 return GTK_WIDGET (toolbar);
2742 * gtk_toolbar_insert:
2743 * @toolbar: a #GtkToolbar
2744 * @item: a #GtkToolItem
2745 * @pos: the position of the new item
2747 * Insert a #GtkToolItem into the toolbar at position @pos. If @pos is
2748 * 0 the item is prepended to the start of the toolbar. If @pos is
2749 * negative, the item is appended to the end of the toolbar.
2754 gtk_toolbar_insert (GtkToolbar *toolbar,
2758 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2759 g_return_if_fail (GTK_IS_TOOL_ITEM (item));
2761 if (!gtk_toolbar_check_new_api (toolbar))
2765 pos = logical_to_physical (toolbar, pos);
2767 toolbar_content_new_tool_item (toolbar, item, FALSE, pos);
2771 * gtk_toolbar_get_item_index:
2772 * @toolbar: a #GtkToolbar
2773 * @item: a #GtkToolItem that is a child of @toolbar
2775 * Returns the position of @item on the toolbar, starting from 0.
2776 * It is an error if @item is not a child of the toolbar.
2778 * Return value: the position of item on the toolbar.
2783 gtk_toolbar_get_item_index (GtkToolbar *toolbar,
2786 GtkToolbarPrivate *priv;
2790 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
2791 g_return_val_if_fail (GTK_IS_TOOL_ITEM (item), -1);
2792 g_return_val_if_fail (GTK_WIDGET (item)->parent == GTK_WIDGET (toolbar), -1);
2794 if (!gtk_toolbar_check_new_api (toolbar))
2797 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2800 for (list = priv->content; list != NULL; list = list->next)
2802 ToolbarContent *content = list->data;
2805 widget = toolbar_content_get_widget (content);
2807 if (item == GTK_TOOL_ITEM (widget))
2813 return physical_to_logical (toolbar, n);
2817 * gtk_toolbar_set_orientation:
2818 * @toolbar: a #GtkToolbar.
2819 * @orientation: a new #GtkOrientation.
2821 * Sets whether a toolbar should appear horizontally or vertically.
2824 gtk_toolbar_set_orientation (GtkToolbar *toolbar,
2825 GtkOrientation orientation)
2827 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2829 g_signal_emit (toolbar, toolbar_signals[ORIENTATION_CHANGED], 0, orientation);
2833 * gtk_toolbar_get_orientation:
2834 * @toolbar: a #GtkToolbar
2836 * Retrieves the current orientation of the toolbar. See
2837 * gtk_toolbar_set_orientation().
2839 * Return value: the orientation
2842 gtk_toolbar_get_orientation (GtkToolbar *toolbar)
2844 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), GTK_ORIENTATION_HORIZONTAL);
2846 return toolbar->orientation;
2850 * gtk_toolbar_set_style:
2851 * @toolbar: a #GtkToolbar.
2852 * @style: the new style for @toolbar.
2854 * Alters the view of @toolbar to display either icons only, text only, or both.
2857 gtk_toolbar_set_style (GtkToolbar *toolbar,
2858 GtkToolbarStyle style)
2860 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2862 toolbar->style_set = TRUE;
2863 g_signal_emit (toolbar, toolbar_signals[STYLE_CHANGED], 0, style);
2867 * gtk_toolbar_get_style:
2868 * @toolbar: a #GtkToolbar
2870 * Retrieves whether the toolbar has text, icons, or both . See
2871 * gtk_toolbar_set_style().
2873 * Return value: the current style of @toolbar
2876 gtk_toolbar_get_style (GtkToolbar *toolbar)
2878 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), DEFAULT_TOOLBAR_STYLE);
2880 return toolbar->style;
2884 * gtk_toolbar_unset_style:
2885 * @toolbar: a #GtkToolbar
2887 * Unsets a toolbar style set with gtk_toolbar_set_style(), so that
2888 * user preferences will be used to determine the toolbar style.
2891 gtk_toolbar_unset_style (GtkToolbar *toolbar)
2893 GtkToolbarStyle style;
2895 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2897 if (toolbar->style_set)
2899 GtkSettings *settings = toolbar_get_settings (toolbar);
2902 g_object_get (settings,
2903 "gtk-toolbar-style", &style,
2906 style = DEFAULT_TOOLBAR_STYLE;
2908 if (style != toolbar->style)
2909 g_signal_emit (toolbar, toolbar_signals[STYLE_CHANGED], 0, style);
2911 toolbar->style_set = FALSE;
2916 * gtk_toolbar_set_tooltips:
2917 * @toolbar: a #GtkToolbar.
2918 * @enable: set to %FALSE to disable the tooltips, or %TRUE to enable them.
2920 * Sets if the tooltips of a toolbar should be active or not.
2923 gtk_toolbar_set_tooltips (GtkToolbar *toolbar,
2926 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2929 gtk_tooltips_enable (toolbar->tooltips);
2931 gtk_tooltips_disable (toolbar->tooltips);
2933 g_object_notify (G_OBJECT (toolbar), "tooltips");
2937 * gtk_toolbar_get_tooltips:
2938 * @toolbar: a #GtkToolbar
2940 * Retrieves whether tooltips are enabled. See
2941 * gtk_toolbar_set_tooltips().
2943 * Return value: %TRUE if tooltips are enabled
2946 gtk_toolbar_get_tooltips (GtkToolbar *toolbar)
2948 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), FALSE);
2950 return toolbar->tooltips->enabled;
2954 * gtk_toolbar_get_n_items:
2955 * @toolbar: a #GtkToolbar
2957 * Returns the number of items on the toolbar.
2959 * Return value: the number of items on the toolbar
2964 gtk_toolbar_get_n_items (GtkToolbar *toolbar)
2966 GtkToolbarPrivate *priv;
2968 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
2970 if (!gtk_toolbar_check_new_api (toolbar))
2973 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2975 return physical_to_logical (toolbar, g_list_length (priv->content));
2979 * gtk_toolbar_get_nth_item:
2980 * @toolbar: a #GtkToolbar
2981 * @n: A position on the toolbar
2983 * Returns the @n<!-- -->'th item on @toolbar, or %NULL if the
2984 * toolbar does not contain an @n<!-- -->'th item.
2986 * Return value: The @n<!-- -->'th #GtkToolItem on @toolbar, or %NULL if there
2987 * isn't an @n<!-- -->'th item.
2992 gtk_toolbar_get_nth_item (GtkToolbar *toolbar,
2995 GtkToolbarPrivate *priv;
2996 ToolbarContent *content;
2999 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), NULL);
3001 if (!gtk_toolbar_check_new_api (toolbar))
3004 n_items = gtk_toolbar_get_n_items (toolbar);
3006 if (n < 0 || n >= n_items)
3009 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3011 content = g_list_nth_data (priv->content, logical_to_physical (toolbar, n));
3014 g_assert (!toolbar_content_is_placeholder (content));
3016 return GTK_TOOL_ITEM (toolbar_content_get_widget (content));
3020 * gtk_toolbar_get_icon_size:
3021 * @toolbar: a #GtkToolbar
3023 * Retrieves the icon size for the toolbar. See gtk_toolbar_set_icon_size().
3025 * Return value: the current icon size for the icons on the toolbar.
3028 gtk_toolbar_get_icon_size (GtkToolbar *toolbar)
3030 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), DEFAULT_ICON_SIZE);
3032 return toolbar->icon_size;
3036 * gtk_toolbar_get_relief_style:
3037 * @toolbar: a #GtkToolbar
3039 * Returns the relief style of buttons on @toolbar. See
3040 * gtk_button_set_relief().
3042 * Return value: The relief style of buttons on @toolbar.
3047 gtk_toolbar_get_relief_style (GtkToolbar *toolbar)
3049 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), GTK_RELIEF_NONE);
3051 return get_button_relief (toolbar);
3055 * gtk_toolbar_set_show_arrow:
3056 * @toolbar: a #GtkToolbar
3057 * @show_arrow: Whether to show an overflow menu
3059 * Sets whether to show an overflow menu when
3060 * @toolbar doesn't have room for all items on it. If %TRUE,
3061 * items that there are not room are available through an
3067 gtk_toolbar_set_show_arrow (GtkToolbar *toolbar,
3068 gboolean show_arrow)
3070 GtkToolbarPrivate *priv;
3072 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3074 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3075 show_arrow = show_arrow != FALSE;
3077 if (priv->show_arrow != show_arrow)
3079 priv->show_arrow = show_arrow;
3081 if (!priv->show_arrow)
3082 gtk_widget_hide (priv->arrow_button);
3084 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3085 g_object_notify (G_OBJECT (toolbar), "show-arrow");
3090 * gtk_toolbar_get_show_arrow:
3091 * @toolbar: a #GtkToolbar
3093 * Returns whether the toolbar has an overflow menu.
3094 * See gtk_toolbar_set_show_arrow().
3096 * Return value: %TRUE if the toolbar has an overflow menu.
3101 gtk_toolbar_get_show_arrow (GtkToolbar *toolbar)
3103 GtkToolbarPrivate *priv;
3105 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), FALSE);
3107 if (!gtk_toolbar_check_new_api (toolbar))
3110 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3112 return priv->show_arrow;
3116 * gtk_toolbar_get_drop_index:
3117 * @toolbar: a #GtkToolbar
3118 * @x: x coordinate of a point on the toolbar
3119 * @y: y coordinate of a point on the toolbar
3121 * Returns the position corresponding to the indicated point on
3122 * @toolbar. This is useful when dragging items to the toolbar:
3123 * this function returns the position a new item should be
3126 * @x and @y are in @toolbar coordinates.
3128 * Return value: The position corresponding to the point (@x, @y) on the toolbar.
3133 gtk_toolbar_get_drop_index (GtkToolbar *toolbar,
3137 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
3139 if (!gtk_toolbar_check_new_api (toolbar))
3142 return physical_to_logical (toolbar, find_drop_index (toolbar, x, y));
3146 gtk_toolbar_finalize (GObject *object)
3149 GtkToolbar *toolbar = GTK_TOOLBAR (object);
3150 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3152 if (toolbar->tooltips)
3153 g_object_unref (toolbar->tooltips);
3155 if (priv->arrow_button)
3156 gtk_widget_unparent (priv->arrow_button);
3158 for (list = priv->content; list != NULL; list = list->next)
3160 ToolbarContent *content = list->data;
3162 toolbar_content_free (content);
3165 g_list_free (priv->content);
3166 g_list_free (toolbar->children);
3168 g_timer_destroy (priv->timer);
3171 gtk_widget_destroy (GTK_WIDGET (priv->menu));
3174 g_source_remove (priv->idle_id);
3176 G_OBJECT_CLASS (gtk_toolbar_parent_class)->finalize (object);
3180 * gtk_toolbar_set_icon_size:
3181 * @toolbar: A #GtkToolbar
3182 * @icon_size: The #GtkIconSize that stock icons in the toolbar shall have.
3184 * This function sets the size of stock icons in the toolbar. You
3185 * can call it both before you add the icons and after they've been
3186 * added. The size you set will override user preferences for the default
3189 * This should only be used for special-purpose toolbars, normal
3190 * application toolbars should respect the user preferences for the
3194 gtk_toolbar_set_icon_size (GtkToolbar *toolbar,
3195 GtkIconSize icon_size)
3197 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3198 g_return_if_fail (icon_size != GTK_ICON_SIZE_INVALID);
3200 if (!toolbar->icon_size_set)
3202 toolbar->icon_size_set = TRUE;
3203 g_object_notify (G_OBJECT (toolbar), "icon-size-set");
3206 if (toolbar->icon_size == icon_size)
3209 toolbar->icon_size = icon_size;
3210 g_object_notify (G_OBJECT (toolbar), "icon-size");
3212 gtk_toolbar_reconfigured (toolbar);
3214 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3218 * gtk_toolbar_unset_icon_size:
3219 * @toolbar: a #GtkToolbar
3221 * Unsets toolbar icon size set with gtk_toolbar_set_icon_size(), so that
3222 * user preferences will be used to determine the icon size.
3225 gtk_toolbar_unset_icon_size (GtkToolbar *toolbar)
3229 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3231 if (toolbar->icon_size_set)
3233 GtkSettings *settings = toolbar_get_settings (toolbar);
3237 g_object_get (settings,
3238 "gtk-toolbar-icon-size", &size,
3242 size = DEFAULT_ICON_SIZE;
3244 if (size != toolbar->icon_size)
3246 gtk_toolbar_set_icon_size (toolbar, size);
3247 g_object_notify (G_OBJECT (toolbar), "icon-size");
3250 toolbar->icon_size_set = FALSE;
3251 g_object_notify (G_OBJECT (toolbar), "icon-size-set");
3260 * gtk_toolbar_append_item:
3261 * @toolbar: a #GtkToolbar.
3262 * @text: give your toolbar button a label.
3263 * @tooltip_text: a string that appears when the user holds the mouse over this item.
3264 * @tooltip_private_text: use with #GtkTipsQuery.
3265 * @icon: a #GtkWidget that should be used as the button's icon.
3266 * @callback: the function to be executed when the button is pressed.
3267 * @user_data: a pointer to any data you wish to be passed to the callback.
3269 * Inserts a new item into the toolbar. You must specify the position
3270 * in the toolbar where it will be inserted.
3272 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3273 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3275 * Return value: the new toolbar item as a #GtkWidget.
3278 gtk_toolbar_append_item (GtkToolbar *toolbar,
3280 const char *tooltip_text,
3281 const char *tooltip_private_text,
3283 GtkSignalFunc callback,
3286 return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
3288 tooltip_text, tooltip_private_text,
3289 icon, callback, user_data,
3290 toolbar->num_children);
3294 * gtk_toolbar_prepend_item:
3295 * @toolbar: a #GtkToolbar.
3296 * @text: give your toolbar button a label.
3297 * @tooltip_text: a string that appears when the user holds the mouse over this item.
3298 * @tooltip_private_text: use with #GtkTipsQuery.
3299 * @icon: a #GtkWidget that should be used as the button's icon.
3300 * @callback: the function to be executed when the button is pressed.
3301 * @user_data: a pointer to any data you wish to be passed to the callback.
3303 * Adds a new button to the beginning (top or left edges) of the given toolbar.
3305 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3306 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3308 * Return value: the new toolbar item as a #GtkWidget.
3311 gtk_toolbar_prepend_item (GtkToolbar *toolbar,
3313 const char *tooltip_text,
3314 const char *tooltip_private_text,
3316 GtkSignalFunc callback,
3319 return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
3321 tooltip_text, tooltip_private_text,
3322 icon, callback, user_data,
3327 * gtk_toolbar_insert_item:
3328 * @toolbar: a #GtkToolbar.
3329 * @text: give your toolbar button a label.
3330 * @tooltip_text: a string that appears when the user holds the mouse over this item.
3331 * @tooltip_private_text: use with #GtkTipsQuery.
3332 * @icon: a #GtkWidget that should be used as the button's icon.
3333 * @callback: the function to be executed when the button is pressed.
3334 * @user_data: a pointer to any data you wish to be passed to the callback.
3335 * @position: the number of widgets to insert this item after.
3337 * Inserts a new item into the toolbar. You must specify the position in the
3338 * toolbar where it will be inserted.
3340 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3341 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3343 * Return value: the new toolbar item as a #GtkWidget.
3346 gtk_toolbar_insert_item (GtkToolbar *toolbar,
3348 const char *tooltip_text,
3349 const char *tooltip_private_text,
3351 GtkSignalFunc callback,
3355 return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
3357 tooltip_text, tooltip_private_text,
3358 icon, callback, user_data,
3363 * gtk_toolbar_insert_stock:
3364 * @toolbar: A #GtkToolbar
3365 * @stock_id: The id of the stock item you want to insert
3366 * @tooltip_text: The text in the tooltip of the toolbar button
3367 * @tooltip_private_text: The private text of the tooltip
3368 * @callback: The callback called when the toolbar button is clicked.
3369 * @user_data: user data passed to callback
3370 * @position: The position the button shall be inserted at.
3371 * -1 means at the end.
3373 * Inserts a stock item at the specified position of the toolbar. If
3374 * @stock_id is not a known stock item ID, it's inserted verbatim,
3375 * except that underscores used to mark mnemonics are removed.
3377 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3378 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3380 * Returns: the inserted widget
3383 gtk_toolbar_insert_stock (GtkToolbar *toolbar,
3384 const gchar *stock_id,
3385 const char *tooltip_text,
3386 const char *tooltip_private_text,
3387 GtkSignalFunc callback,
3391 return internal_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
3393 tooltip_text, tooltip_private_text,
3394 NULL, callback, user_data,
3399 * gtk_toolbar_append_space:
3400 * @toolbar: a #GtkToolbar.
3402 * Adds a new space to the end of the toolbar.
3405 gtk_toolbar_append_space (GtkToolbar *toolbar)
3407 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_SPACE,
3411 toolbar->num_children);
3415 * gtk_toolbar_prepend_space:
3416 * @toolbar: a #GtkToolbar.
3418 * Adds a new space to the beginning of the toolbar.
3421 gtk_toolbar_prepend_space (GtkToolbar *toolbar)
3423 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_SPACE,
3431 * gtk_toolbar_insert_space:
3432 * @toolbar: a #GtkToolbar
3433 * @position: the number of widgets after which a space should be inserted.
3435 * Inserts a new space in the toolbar at the specified position.
3438 gtk_toolbar_insert_space (GtkToolbar *toolbar,
3441 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_SPACE,
3449 * gtk_toolbar_remove_space:
3450 * @toolbar: a #GtkToolbar.
3451 * @position: the index of the space to remove.
3453 * Removes a space from the specified position.
3456 gtk_toolbar_remove_space (GtkToolbar *toolbar,
3459 GtkToolbarPrivate *priv;
3460 ToolbarContent *content;
3462 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3464 if (!gtk_toolbar_check_old_api (toolbar))
3467 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3469 content = g_list_nth_data (priv->content, position);
3473 g_warning ("Toolbar position %d doesn't exist", position);
3477 if (!toolbar_content_is_separator (content))
3479 g_warning ("Toolbar position %d is not a space", position);
3483 toolbar_content_remove (content, toolbar);
3484 toolbar_content_free (content);
3488 * gtk_toolbar_append_widget:
3489 * @toolbar: a #GtkToolbar.
3490 * @widget: a #GtkWidget to add to the toolbar.
3491 * @tooltip_text: the element's tooltip.
3492 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3494 * Adds a widget to the end of the given toolbar.
3497 gtk_toolbar_append_widget (GtkToolbar *toolbar,
3499 const gchar *tooltip_text,
3500 const gchar *tooltip_private_text)
3502 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_WIDGET,
3504 tooltip_text, tooltip_private_text,
3506 toolbar->num_children);
3510 * gtk_toolbar_prepend_widget:
3511 * @toolbar: a #GtkToolbar.
3512 * @widget: a #GtkWidget to add to the toolbar.
3513 * @tooltip_text: the element's tooltip.
3514 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3516 * Adds a widget to the beginning of the given toolbar.
3519 gtk_toolbar_prepend_widget (GtkToolbar *toolbar,
3521 const gchar *tooltip_text,
3522 const gchar *tooltip_private_text)
3524 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_WIDGET,
3526 tooltip_text, tooltip_private_text,
3532 * gtk_toolbar_insert_widget:
3533 * @toolbar: a #GtkToolbar.
3534 * @widget: a #GtkWidget to add to the toolbar.
3535 * @tooltip_text: the element's tooltip.
3536 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3537 * @position: the number of widgets to insert this widget after.
3539 * Inserts a widget in the toolbar at the given position.
3542 gtk_toolbar_insert_widget (GtkToolbar *toolbar,
3544 const char *tooltip_text,
3545 const char *tooltip_private_text,
3548 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_WIDGET,
3550 tooltip_text, tooltip_private_text,
3556 * gtk_toolbar_append_element:
3557 * @toolbar: a #GtkToolbar.
3558 * @type: a value of type #GtkToolbarChildType that determines what @widget will be.
3559 * @widget: a #GtkWidget, or %NULL.
3560 * @text: the element's label.
3561 * @tooltip_text: the element's tooltip.
3562 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3563 * @icon: a #GtkWidget that provides pictorial representation of the element's function.
3564 * @callback: the function to be executed when the button is pressed.
3565 * @user_data: any data you wish to pass to the callback.
3567 * Adds a new element to the end of a toolbar.
3569 * If @type == %GTK_TOOLBAR_CHILD_WIDGET, @widget is used as the new element.
3570 * If @type == %GTK_TOOLBAR_CHILD_RADIOBUTTON, @widget is used to determine
3571 * the radio group for the new element. In all other cases, @widget must
3574 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3575 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3577 * Return value: the new toolbar element as a #GtkWidget.
3580 gtk_toolbar_append_element (GtkToolbar *toolbar,
3581 GtkToolbarChildType type,
3584 const char *tooltip_text,
3585 const char *tooltip_private_text,
3587 GtkSignalFunc callback,
3590 return gtk_toolbar_insert_element (toolbar, type, widget, text,
3591 tooltip_text, tooltip_private_text,
3592 icon, callback, user_data,
3593 toolbar->num_children);
3597 * gtk_toolbar_prepend_element:
3598 * @toolbar: a #GtkToolbar.
3599 * @type: a value of type #GtkToolbarChildType that determines what @widget will be.
3600 * @widget: a #GtkWidget, or %NULL
3601 * @text: the element's label.
3602 * @tooltip_text: the element's tooltip.
3603 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3604 * @icon: a #GtkWidget that provides pictorial representation of the element's function.
3605 * @callback: the function to be executed when the button is pressed.
3606 * @user_data: any data you wish to pass to the callback.
3608 * Adds a new element to the beginning of a toolbar.
3610 * If @type == %GTK_TOOLBAR_CHILD_WIDGET, @widget is used as the new element.
3611 * If @type == %GTK_TOOLBAR_CHILD_RADIOBUTTON, @widget is used to determine
3612 * the radio group for the new element. In all other cases, @widget must
3615 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3616 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3618 * Return value: the new toolbar element as a #GtkWidget.
3621 gtk_toolbar_prepend_element (GtkToolbar *toolbar,
3622 GtkToolbarChildType type,
3625 const char *tooltip_text,
3626 const char *tooltip_private_text,
3628 GtkSignalFunc callback,
3631 return gtk_toolbar_insert_element (toolbar, type, widget, text,
3632 tooltip_text, tooltip_private_text,
3633 icon, callback, user_data, 0);
3637 * gtk_toolbar_insert_element:
3638 * @toolbar: a #GtkToolbar.
3639 * @type: a value of type #GtkToolbarChildType that determines what @widget
3641 * @widget: a #GtkWidget, or %NULL.
3642 * @text: the element's label.
3643 * @tooltip_text: the element's tooltip.
3644 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3645 * @icon: a #GtkWidget that provides pictorial representation of the element's function.
3646 * @callback: the function to be executed when the button is pressed.
3647 * @user_data: any data you wish to pass to the callback.
3648 * @position: the number of widgets to insert this element after.
3650 * Inserts a new element in the toolbar at the given position.
3652 * If @type == %GTK_TOOLBAR_CHILD_WIDGET, @widget is used as the new element.
3653 * If @type == %GTK_TOOLBAR_CHILD_RADIOBUTTON, @widget is used to determine
3654 * the radio group for the new element. In all other cases, @widget must
3657 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3658 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3660 * Return value: the new toolbar element as a #GtkWidget.
3663 gtk_toolbar_insert_element (GtkToolbar *toolbar,
3664 GtkToolbarChildType type,
3667 const char *tooltip_text,
3668 const char *tooltip_private_text,
3670 GtkSignalFunc callback,
3674 return internal_insert_element (toolbar, type, widget, text,
3675 tooltip_text, tooltip_private_text,
3676 icon, callback, user_data, position, FALSE);
3680 set_child_packing_and_visibility(GtkToolbar *toolbar,
3681 GtkToolbarChild *child)
3686 box = gtk_bin_get_child (GTK_BIN (child->widget));
3688 g_return_if_fail (GTK_IS_BOX (box));
3692 expand = (toolbar->style != GTK_TOOLBAR_BOTH);
3694 gtk_box_set_child_packing (GTK_BOX (box), child->label,
3695 expand, expand, 0, GTK_PACK_END);
3697 if (toolbar->style != GTK_TOOLBAR_ICONS)
3698 gtk_widget_show (child->label);
3700 gtk_widget_hide (child->label);
3705 expand = (toolbar->style != GTK_TOOLBAR_BOTH_HORIZ);
3707 gtk_box_set_child_packing (GTK_BOX (box), child->icon,
3708 expand, expand, 0, GTK_PACK_END);
3710 if (toolbar->style != GTK_TOOLBAR_TEXT)
3711 gtk_widget_show (child->icon);
3713 gtk_widget_hide (child->icon);
3718 internal_insert_element (GtkToolbar *toolbar,
3719 GtkToolbarChildType type,
3722 const char *tooltip_text,
3723 const char *tooltip_private_text,
3725 GtkSignalFunc callback,
3731 char *free_me = NULL;
3733 GtkWidget *child_widget;
3734 GtkWidget *child_label;
3735 GtkWidget *child_icon;
3737 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), NULL);
3738 if (type == GTK_TOOLBAR_CHILD_WIDGET)
3739 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3740 else if (type != GTK_TOOLBAR_CHILD_RADIOBUTTON)
3741 g_return_val_if_fail (widget == NULL, NULL);
3742 if (GTK_IS_TOOL_ITEM (widget))
3743 g_warning (MIXED_API_WARNING);
3745 if (!gtk_toolbar_check_old_api (toolbar))
3748 child_widget = NULL;
3754 case GTK_TOOLBAR_CHILD_SPACE:
3757 case GTK_TOOLBAR_CHILD_WIDGET:
3758 child_widget = widget;
3761 case GTK_TOOLBAR_CHILD_BUTTON:
3762 case GTK_TOOLBAR_CHILD_TOGGLEBUTTON:
3763 case GTK_TOOLBAR_CHILD_RADIOBUTTON:
3764 if (type == GTK_TOOLBAR_CHILD_BUTTON)
3766 child_widget = gtk_button_new ();
3768 else if (type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
3770 child_widget = gtk_toggle_button_new ();
3771 gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (child_widget), FALSE);
3773 else /* type == GTK_TOOLBAR_CHILD_RADIOBUTTON */
3775 GSList *group = NULL;
3778 group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (widget));
3780 child_widget = gtk_radio_button_new (group);
3781 gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (child_widget), FALSE);
3784 gtk_button_set_relief (GTK_BUTTON (child_widget), get_button_relief (toolbar));
3785 gtk_button_set_focus_on_click (GTK_BUTTON (child_widget), FALSE);
3789 g_signal_connect (child_widget, "clicked",
3790 callback, user_data);
3793 if (toolbar->style == GTK_TOOLBAR_BOTH_HORIZ)
3794 box = gtk_hbox_new (FALSE, 0);
3796 box = gtk_vbox_new (FALSE, 0);
3798 gtk_container_add (GTK_CONTAINER (child_widget), box);
3799 gtk_widget_show (box);
3801 if (text && use_stock)
3803 GtkStockItem stock_item;
3804 if (gtk_stock_lookup (text, &stock_item))
3807 icon = gtk_image_new_from_stock (text, toolbar->icon_size);
3809 text = free_me = _gtk_toolbar_elide_underscores (stock_item.label);
3815 child_label = gtk_label_new (text);
3817 gtk_container_add (GTK_CONTAINER (box), child_label);
3822 child_icon = GTK_WIDGET (icon);
3823 gtk_container_add (GTK_CONTAINER (box), child_icon);
3826 gtk_widget_show (child_widget);
3830 g_assert_not_reached ();
3834 if ((type != GTK_TOOLBAR_CHILD_SPACE) && tooltip_text)
3836 gtk_tooltips_set_tip (toolbar->tooltips, child_widget,
3837 tooltip_text, tooltip_private_text);
3843 return child_widget;
3847 * ToolbarContent methods
3855 struct _ToolbarContent
3865 GtkAllocation start_allocation;
3866 GtkAllocation goal_allocation;
3867 guint is_placeholder : 1;
3868 guint disappearing : 1;
3869 TriState has_menu : 2;
3874 GtkToolbarChild child;
3875 GtkAllocation space_allocation;
3876 guint space_visible : 1;
3881 static ToolbarContent *
3882 toolbar_content_new_tool_item (GtkToolbar *toolbar,
3884 gboolean is_placeholder,
3887 ToolbarContent *content;
3888 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3890 content = g_new0 (ToolbarContent, 1);
3892 content->type = TOOL_ITEM;
3893 content->state = NOT_ALLOCATED;
3894 content->u.tool_item.item = item;
3895 content->u.tool_item.is_placeholder = is_placeholder;
3897 gtk_widget_set_parent (GTK_WIDGET (item), GTK_WIDGET (toolbar));
3899 priv->content = g_list_insert (priv->content, content, pos);
3901 if (!is_placeholder)
3903 toolbar->num_children++;
3905 gtk_toolbar_stop_sliding (toolbar);
3908 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3909 priv->need_rebuild = TRUE;
3915 toolbar_content_remove (ToolbarContent *content,
3916 GtkToolbar *toolbar)
3918 GtkToolbarChild *child;
3919 GtkToolbarPrivate *priv;
3921 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3923 switch (content->type)
3926 gtk_widget_unparent (GTK_WIDGET (content->u.tool_item.item));
3930 child = &(content->u.compatibility.child);
3932 if (child->type != GTK_TOOLBAR_CHILD_SPACE)
3934 g_object_ref (child->widget);
3935 gtk_widget_unparent (child->widget);
3936 gtk_widget_destroy (child->widget);
3937 g_object_unref (child->widget);
3940 toolbar->children = g_list_remove (toolbar->children, child);
3944 priv->content = g_list_remove (priv->content, content);
3946 if (!toolbar_content_is_placeholder (content))
3947 toolbar->num_children--;
3949 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3950 priv->need_rebuild = TRUE;
3954 toolbar_content_free (ToolbarContent *content)
3960 calculate_max_homogeneous_pixels (GtkWidget *widget)
3962 PangoContext *context;
3963 PangoFontMetrics *metrics;
3966 context = gtk_widget_get_pango_context (widget);
3967 metrics = pango_context_get_metrics (context,
3968 widget->style->font_desc,
3969 pango_context_get_language (context));
3970 char_width = pango_font_metrics_get_approximate_char_width (metrics);
3971 pango_font_metrics_unref (metrics);
3973 return PANGO_PIXELS (MAX_HOMOGENEOUS_N_CHARS * char_width);
3977 toolbar_content_expose (ToolbarContent *content,
3978 GtkContainer *container,
3979 GdkEventExpose *expose)
3981 GtkToolbar *toolbar = GTK_TOOLBAR (container);
3982 GtkToolbarChild *child;
3983 GtkWidget *widget = NULL; /* quiet gcc */
3985 switch (content->type)
3988 if (!content->u.tool_item.is_placeholder)
3989 widget = GTK_WIDGET (content->u.tool_item.item);
3993 child = &(content->u.compatibility.child);
3995 if (child->type == GTK_TOOLBAR_CHILD_SPACE)
3997 if (get_space_style (toolbar) == GTK_TOOLBAR_SPACE_LINE &&
3998 content->u.compatibility.space_visible)
4000 _gtk_toolbar_paint_space_line (GTK_WIDGET (toolbar), toolbar,
4002 &content->u.compatibility.space_allocation);
4007 widget = child->widget;
4012 gtk_container_propagate_expose (container, widget, expose);
4016 toolbar_content_visible (ToolbarContent *content,
4017 GtkToolbar *toolbar)
4021 switch (content->type)
4024 item = content->u.tool_item.item;
4026 if (!GTK_WIDGET_VISIBLE (item))
4029 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL &&
4030 gtk_tool_item_get_visible_horizontal (item))
4035 if ((toolbar->orientation == GTK_ORIENTATION_VERTICAL &&
4036 gtk_tool_item_get_visible_vertical (item)))
4045 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
4046 return GTK_WIDGET_VISIBLE (content->u.compatibility.child.widget);
4052 g_assert_not_reached ();
4057 toolbar_content_size_request (ToolbarContent *content,
4058 GtkToolbar *toolbar,
4059 GtkRequisition *requisition)
4063 switch (content->type)
4066 gtk_widget_size_request (GTK_WIDGET (content->u.tool_item.item),
4068 if (content->u.tool_item.is_placeholder &&
4069 content->u.tool_item.disappearing)
4071 requisition->width = 0;
4072 requisition->height = 0;
4077 space_size = get_space_size (toolbar);
4079 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
4081 gtk_widget_size_request (content->u.compatibility.child.widget,
4086 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
4088 requisition->width = space_size;
4089 requisition->height = 0;
4093 requisition->height = space_size;
4094 requisition->width = 0;
4103 toolbar_content_is_homogeneous (ToolbarContent *content,
4104 GtkToolbar *toolbar)
4106 gboolean result = FALSE; /* quiet gcc */
4107 GtkRequisition requisition;
4108 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
4110 if (priv->max_homogeneous_pixels < 0)
4112 priv->max_homogeneous_pixels =
4113 calculate_max_homogeneous_pixels (GTK_WIDGET (toolbar));
4116 toolbar_content_size_request (content, toolbar, &requisition);
4118 if (requisition.width > priv->max_homogeneous_pixels)
4121 switch (content->type)
4124 result = gtk_tool_item_get_homogeneous (content->u.tool_item.item) &&
4125 !GTK_IS_SEPARATOR_TOOL_ITEM (content->u.tool_item.item);
4127 if (gtk_tool_item_get_is_important (content->u.tool_item.item) &&
4128 toolbar->style == GTK_TOOLBAR_BOTH_HORIZ &&
4129 toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
4136 if (content->u.compatibility.child.type == GTK_TOOLBAR_CHILD_BUTTON ||
4137 content->u.compatibility.child.type == GTK_TOOLBAR_CHILD_RADIOBUTTON ||
4138 content->u.compatibility.child.type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
4153 toolbar_content_is_placeholder (ToolbarContent *content)
4155 if (content->type == TOOL_ITEM && content->u.tool_item.is_placeholder)
4162 toolbar_content_disappearing (ToolbarContent *content)
4164 if (content->type == TOOL_ITEM && content->u.tool_item.disappearing)
4171 toolbar_content_get_state (ToolbarContent *content)
4173 return content->state;
4177 toolbar_content_child_visible (ToolbarContent *content)
4179 switch (content->type)
4182 return GTK_WIDGET_CHILD_VISIBLE (content->u.tool_item.item);
4186 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
4188 return GTK_WIDGET_CHILD_VISIBLE (content->u.compatibility.child.widget);
4192 return content->u.compatibility.space_visible;
4197 return FALSE; /* quiet gcc */
4201 toolbar_content_get_goal_allocation (ToolbarContent *content,
4202 GtkAllocation *allocation)
4204 switch (content->type)
4207 *allocation = content->u.tool_item.goal_allocation;
4211 /* Goal allocations are only relevant when we are
4212 * using the new API, so we should never get here
4214 g_assert_not_reached ();
4220 toolbar_content_get_allocation (ToolbarContent *content,
4221 GtkAllocation *allocation)
4223 GtkToolbarChild *child;
4225 switch (content->type)
4228 *allocation = GTK_WIDGET (content->u.tool_item.item)->allocation;
4232 child = &(content->u.compatibility.child);
4234 if (child->type == GTK_TOOLBAR_CHILD_SPACE)
4235 *allocation = content->u.compatibility.space_allocation;
4237 *allocation = child->widget->allocation;
4243 toolbar_content_set_start_allocation (ToolbarContent *content,
4244 GtkAllocation *allocation)
4246 switch (content->type)
4249 content->u.tool_item.start_allocation = *allocation;
4253 /* start_allocation is only relevant when using the new API */
4254 g_assert_not_reached ();
4260 toolbar_content_get_expand (ToolbarContent *content)
4262 if (content->type == TOOL_ITEM &&
4263 gtk_tool_item_get_expand (content->u.tool_item.item) &&
4264 !content->u.tool_item.disappearing)
4273 toolbar_content_set_goal_allocation (ToolbarContent *content,
4274 GtkAllocation *allocation)
4276 switch (content->type)
4279 content->u.tool_item.goal_allocation = *allocation;
4283 /* Only relevant when using new API */
4284 g_assert_not_reached ();
4290 toolbar_content_set_child_visible (ToolbarContent *content,
4291 GtkToolbar *toolbar,
4294 GtkToolbarChild *child;
4296 switch (content->type)
4299 gtk_widget_set_child_visible (GTK_WIDGET (content->u.tool_item.item),
4304 child = &(content->u.compatibility.child);
4306 if (child->type != GTK_TOOLBAR_CHILD_SPACE)
4308 gtk_widget_set_child_visible (child->widget, visible);
4312 if (content->u.compatibility.space_visible != visible)
4314 content->u.compatibility.space_visible = visible;
4315 gtk_widget_queue_draw (GTK_WIDGET (toolbar));
4323 toolbar_content_get_start_allocation (ToolbarContent *content,
4324 GtkAllocation *start_allocation)
4326 switch (content->type)
4329 *start_allocation = content->u.tool_item.start_allocation;
4333 /* Only relevant for new API */
4334 g_assert_not_reached ();
4340 toolbar_content_size_allocate (ToolbarContent *content,
4341 GtkAllocation *allocation)
4343 switch (content->type)
4346 gtk_widget_size_allocate (GTK_WIDGET (content->u.tool_item.item),
4351 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
4353 gtk_widget_size_allocate (content->u.compatibility.child.widget,
4358 content->u.compatibility.space_allocation = *allocation;
4365 toolbar_content_set_state (ToolbarContent *content,
4368 content->state = state;
4372 toolbar_content_get_widget (ToolbarContent *content)
4374 GtkToolbarChild *child;
4376 switch (content->type)
4379 return GTK_WIDGET (content->u.tool_item.item);
4383 child = &(content->u.compatibility.child);
4384 if (child->type != GTK_TOOLBAR_CHILD_SPACE)
4385 return child->widget;
4395 toolbar_content_set_disappearing (ToolbarContent *content,
4396 gboolean disappearing)
4398 switch (content->type)
4401 content->u.tool_item.disappearing = disappearing;
4405 /* Only relevant for new API */
4406 g_assert_not_reached ();
4412 toolbar_content_set_size_request (ToolbarContent *content,
4416 switch (content->type)
4419 gtk_widget_set_size_request (GTK_WIDGET (content->u.tool_item.item),
4424 /* Setting size requests only happens with sliding,
4425 * so not relevant here
4427 g_assert_not_reached ();
4433 toolbar_child_reconfigure (GtkToolbar *toolbar,
4434 GtkToolbarChild *child)
4438 GtkToolbarStyle style;
4439 GtkIconSize icon_size;
4440 GtkReliefStyle relief;
4443 style = gtk_toolbar_get_style (toolbar);
4444 icon_size = gtk_toolbar_get_icon_size (toolbar);
4445 relief = gtk_toolbar_get_relief_style (toolbar);
4448 if (child->type == GTK_TOOLBAR_CHILD_BUTTON ||
4449 child->type == GTK_TOOLBAR_CHILD_RADIOBUTTON ||
4450 child->type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
4452 box = gtk_bin_get_child (GTK_BIN (child->widget));
4454 if (style == GTK_TOOLBAR_BOTH && GTK_IS_HBOX (box))
4458 vbox = gtk_vbox_new (FALSE, 0);
4461 gtk_widget_reparent (child->label, vbox);
4463 gtk_widget_reparent (child->icon, vbox);
4465 gtk_widget_destroy (box);
4466 gtk_container_add (GTK_CONTAINER (child->widget), vbox);
4468 gtk_widget_show (vbox);
4470 else if (style == GTK_TOOLBAR_BOTH_HORIZ && GTK_IS_VBOX (box))
4474 hbox = gtk_hbox_new (FALSE, 0);
4477 gtk_widget_reparent (child->label, hbox);
4479 gtk_widget_reparent (child->icon, hbox);
4481 gtk_widget_destroy (box);
4482 gtk_container_add (GTK_CONTAINER (child->widget), hbox);
4484 gtk_widget_show (hbox);
4487 set_child_packing_and_visibility (toolbar, child);
4492 if ((child->type == GTK_TOOLBAR_CHILD_BUTTON ||
4493 child->type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON ||
4494 child->type == GTK_TOOLBAR_CHILD_RADIOBUTTON) &&
4495 GTK_IS_IMAGE (child->icon))
4497 image = GTK_IMAGE (child->icon);
4498 if (gtk_image_get_storage_type (image) == GTK_IMAGE_STOCK)
4500 gtk_image_get_stock (image, &stock_id, NULL);
4501 stock_id = g_strdup (stock_id);
4502 gtk_image_set_from_stock (image,
4510 if (child->type == GTK_TOOLBAR_CHILD_BUTTON ||
4511 child->type == GTK_TOOLBAR_CHILD_RADIOBUTTON ||
4512 child->type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
4514 gtk_button_set_relief (GTK_BUTTON (child->widget), relief);
4519 toolbar_content_toolbar_reconfigured (ToolbarContent *content,
4520 GtkToolbar *toolbar)
4522 switch (content->type)
4525 _gtk_tool_item_toolbar_reconfigured (content->u.tool_item.item);
4529 toolbar_child_reconfigure (toolbar, &(content->u.compatibility.child));
4535 toolbar_content_retrieve_menu_item (ToolbarContent *content)
4537 if (content->type == TOOL_ITEM)
4538 return gtk_tool_item_retrieve_proxy_menu_item (content->u.tool_item.item);
4540 /* FIXME - we might actually be able to do something meaningful here */
4545 toolbar_content_has_proxy_menu_item (ToolbarContent *content)
4547 if (content->type == TOOL_ITEM)
4549 GtkWidget *menu_item;
4551 if (content->u.tool_item.has_menu == YES)
4553 else if (content->u.tool_item.has_menu == NO)
4556 menu_item = toolbar_content_retrieve_menu_item (content);
4558 content->u.tool_item.has_menu = menu_item? YES : NO;
4560 return menu_item != NULL;
4569 toolbar_content_set_unknown_menu_status (ToolbarContent *content)
4571 if (content->type == TOOL_ITEM)
4572 content->u.tool_item.has_menu = UNKNOWN;
4576 toolbar_content_is_separator (ToolbarContent *content)
4578 GtkToolbarChild *child;
4580 switch (content->type)
4583 return GTK_IS_SEPARATOR_TOOL_ITEM (content->u.tool_item.item);
4587 child = &(content->u.compatibility.child);
4588 return (child->type == GTK_TOOLBAR_CHILD_SPACE);
4596 toolbar_content_set_expand (ToolbarContent *content,
4599 if (content->type == TOOL_ITEM)
4600 gtk_tool_item_set_expand (content->u.tool_item.item, expand);
4604 ignore_show_and_hide_all (ToolbarContent *content)
4606 if (content->type == COMPATIBILITY)
4608 GtkToolbarChildType type = content->u.compatibility.child.type;
4610 if (type == GTK_TOOLBAR_CHILD_BUTTON ||
4611 type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON ||
4612 type == GTK_TOOLBAR_CHILD_RADIOBUTTON)
4622 toolbar_content_show_all (ToolbarContent *content)
4626 if (ignore_show_and_hide_all (content))
4629 widget = toolbar_content_get_widget (content);
4631 gtk_widget_show_all (widget);
4635 toolbar_content_hide_all (ToolbarContent *content)
4639 if (ignore_show_and_hide_all (content))
4642 widget = toolbar_content_get_widget (content);
4644 gtk_widget_hide_all (widget);
4651 get_space_size (GtkToolbar *toolbar)
4653 gint space_size = DEFAULT_SPACE_SIZE;
4657 gtk_widget_style_get (GTK_WIDGET (toolbar),
4658 "space-size", &space_size,
4665 static GtkToolbarSpaceStyle
4666 get_space_style (GtkToolbar *toolbar)
4668 GtkToolbarSpaceStyle space_style = DEFAULT_SPACE_STYLE;
4672 gtk_widget_style_get (GTK_WIDGET (toolbar),
4673 "space-style", &space_style,
4680 static GtkReliefStyle
4681 get_button_relief (GtkToolbar *toolbar)
4683 GtkReliefStyle button_relief = GTK_RELIEF_NORMAL;
4685 gtk_widget_ensure_style (GTK_WIDGET (toolbar));
4687 gtk_widget_style_get (GTK_WIDGET (toolbar),
4688 "button-relief", &button_relief,
4691 return button_relief;
4695 get_internal_padding (GtkToolbar *toolbar)
4699 gtk_widget_style_get (GTK_WIDGET (toolbar),
4700 "internal-padding", &ipadding,
4707 get_max_child_expand (GtkToolbar *toolbar)
4709 gint mexpand = G_MAXINT;
4711 gtk_widget_style_get (GTK_WIDGET (toolbar),
4712 "max-child-expand", &mexpand,
4717 static GtkShadowType
4718 get_shadow_type (GtkToolbar *toolbar)
4720 GtkShadowType shadow_type;
4722 gtk_widget_style_get (GTK_WIDGET (toolbar),
4723 "shadow-type", &shadow_type,
4733 gtk_toolbar_check_old_api (GtkToolbar *toolbar)
4735 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
4737 if (priv->api_mode == NEW_API)
4739 g_warning (MIXED_API_WARNING);
4743 priv->api_mode = OLD_API;
4748 gtk_toolbar_check_new_api (GtkToolbar *toolbar)
4750 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
4752 if (priv->api_mode == OLD_API)
4754 g_warning (MIXED_API_WARNING);
4758 priv->api_mode = NEW_API;
4762 /* GTK+ internal methods */
4765 _gtk_toolbar_get_default_space_size (void)
4767 return DEFAULT_SPACE_SIZE;
4771 _gtk_toolbar_paint_space_line (GtkWidget *widget,
4772 GtkToolbar *toolbar,
4774 GtkAllocation *allocation)
4776 const double start_fraction = (SPACE_LINE_START / SPACE_LINE_DIVISION);
4777 const double end_fraction = (SPACE_LINE_END / SPACE_LINE_DIVISION);
4779 GtkOrientation orientation;
4781 g_return_if_fail (GTK_IS_WIDGET (widget));
4783 orientation = toolbar? toolbar->orientation : GTK_ORIENTATION_HORIZONTAL;
4785 if (orientation == GTK_ORIENTATION_HORIZONTAL)
4787 gboolean wide_separators;
4788 gint separator_width;
4790 gtk_widget_style_get (widget,
4791 "wide-separators", &wide_separators,
4792 "separator-width", &separator_width,
4795 if (wide_separators)
4796 gtk_paint_box (widget->style, widget->window,
4797 GTK_WIDGET_STATE (widget), GTK_SHADOW_ETCHED_OUT,
4798 area, widget, "vseparator",
4799 allocation->x + (allocation->width - separator_width) / 2,
4800 allocation->y + allocation->height * start_fraction,
4802 allocation->height * (end_fraction - start_fraction));
4804 gtk_paint_vline (widget->style, widget->window,
4805 GTK_WIDGET_STATE (widget), area, widget,
4807 allocation->y + allocation->height * start_fraction,
4808 allocation->y + allocation->height * end_fraction,
4809 allocation->x + (allocation->width - widget->style->xthickness) / 2);
4813 gboolean wide_separators;
4814 gint separator_height;
4816 gtk_widget_style_get (widget,
4817 "wide-separators", &wide_separators,
4818 "separator-height", &separator_height,
4821 if (wide_separators)
4822 gtk_paint_box (widget->style, widget->window,
4823 GTK_WIDGET_STATE (widget), GTK_SHADOW_ETCHED_OUT,
4824 area, widget, "hseparator",
4825 allocation->x + allocation->width * start_fraction,
4826 allocation->y + (allocation->height - separator_height) / 2,
4827 allocation->width * (end_fraction - start_fraction),
4830 gtk_paint_hline (widget->style, widget->window,
4831 GTK_WIDGET_STATE (widget), area, widget,
4833 allocation->x + allocation->width * start_fraction,
4834 allocation->x + allocation->width * end_fraction,
4835 allocation->y + (allocation->height - widget->style->ythickness) / 2);
4840 _gtk_toolbar_elide_underscores (const gchar *original)
4843 const gchar *p, *end;
4845 gboolean last_underscore;
4850 len = strlen (original);
4851 q = result = g_malloc (len + 1);
4852 last_underscore = FALSE;
4854 end = original + len;
4855 for (p = original; p < end; p++)
4857 if (!last_underscore && *p == '_')
4858 last_underscore = TRUE;
4861 last_underscore = FALSE;
4862 if (*p != '_' && original + 2 <= p && p + 1 <= end && p[-2] == '(' && p[1] == ')')
4873 if (last_underscore)
4882 _gtk_toolbar_rebuild_menu (GtkToolbar *toolbar)
4884 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
4887 priv->need_rebuild = TRUE;
4889 for (list = priv->content; list != NULL; list = list->next)
4891 ToolbarContent *content = list->data;
4893 toolbar_content_set_unknown_menu_status (content);
4896 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
4899 #define __GTK_TOOLBAR_C__
4900 #include "gtkaliasdef.c"