1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3 * GtkToolbar copyright (C) Federico Mena
5 * Copyright (C) 2002 Anders Carlsson <andersca@gnome.org>
6 * Copyright (C) 2002 James Henstridge <james@daa.com.au>
7 * Copyright (C) 2003, 2004 Soeren Sandmann <sandmann@daimi.au.dk>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the
21 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 * Boston, MA 02111-1307, USA.
26 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
27 * file for a list of people on the GTK+ Team. See the ChangeLog
28 * files for a list of changes. These files are distributed with
29 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
32 #undef GTK_DISABLE_DEPRECATED
36 #include "gtktoolbar.h"
37 #include "gtkradiotoolbutton.h"
38 #include "gtkseparatortoolitem.h"
40 #include "gtkradiobutton.h"
41 #include "gtktoolbar.h"
42 #include "gtkbindings.h"
43 #include <gdk/gdkkeysyms.h>
44 #include "gtkmarshalers.h"
48 #include "gtkprivate.h"
54 #include "gtkseparatormenuitem.h"
58 typedef struct _ToolbarContent ToolbarContent;
60 #define DEFAULT_IPADDING 0
62 #define DEFAULT_SPACE_SIZE 12
63 #define DEFAULT_SPACE_STYLE GTK_TOOLBAR_SPACE_LINE
64 #define SPACE_LINE_DIVISION 10.0
65 #define SPACE_LINE_START 2.0
66 #define SPACE_LINE_END 8.0
68 #define DEFAULT_ICON_SIZE GTK_ICON_SIZE_LARGE_TOOLBAR
69 #define DEFAULT_TOOLBAR_STYLE GTK_TOOLBAR_BOTH
70 #define DEFAULT_ANIMATION_STATE TRUE
72 #define MAX_HOMOGENEOUS_N_CHARS 13 /* Items that are wider than this do not participate
73 * in the homogeneous game. In units of
74 * pango_font_get_estimated_char_width().
76 #define SLIDE_SPEED 600.0 /* How fast the items slide, in pixels per second */
77 #define ACCEL_THRESHOLD 0.18 /* After how much time in seconds will items start speeding up */
79 #define MIXED_API_WARNING \
80 "Mixing deprecated and non-deprecated GtkToolbar API is not allowed"
94 /* Child properties */
98 CHILD_PROP_HOMOGENEOUS
130 struct _GtkToolbarPrivate
135 GtkWidget * arrow_button;
138 GdkWindow * event_window;
140 GtkSettings * settings;
142 GtkToolItem * highlight_tool_item;
143 gint max_homogeneous_pixels;
147 gulong settings_connection;
149 guint show_arrow : 1;
151 guint is_sliding : 1;
152 guint need_rebuild : 1; /* whether the overflow menu should be regenerated */
156 static void gtk_toolbar_set_property (GObject *object,
160 static void gtk_toolbar_get_property (GObject *object,
164 static gint gtk_toolbar_expose (GtkWidget *widget,
165 GdkEventExpose *event);
166 static void gtk_toolbar_realize (GtkWidget *widget);
167 static void gtk_toolbar_unrealize (GtkWidget *widget);
168 static void gtk_toolbar_size_request (GtkWidget *widget,
169 GtkRequisition *requisition);
170 static void gtk_toolbar_size_allocate (GtkWidget *widget,
171 GtkAllocation *allocation);
172 static void gtk_toolbar_style_set (GtkWidget *widget,
173 GtkStyle *prev_style);
174 static gboolean gtk_toolbar_focus (GtkWidget *widget,
175 GtkDirectionType dir);
176 static void gtk_toolbar_screen_changed (GtkWidget *widget,
177 GdkScreen *previous_screen);
178 static void gtk_toolbar_map (GtkWidget *widget);
179 static void gtk_toolbar_unmap (GtkWidget *widget);
180 static void gtk_toolbar_set_child_property (GtkContainer *container,
185 static void gtk_toolbar_get_child_property (GtkContainer *container,
190 static void gtk_toolbar_finalize (GObject *object);
191 static void gtk_toolbar_show_all (GtkWidget *widget);
192 static void gtk_toolbar_hide_all (GtkWidget *widget);
193 static void gtk_toolbar_add (GtkContainer *container,
195 static void gtk_toolbar_remove (GtkContainer *container,
197 static void gtk_toolbar_forall (GtkContainer *container,
198 gboolean include_internals,
199 GtkCallback callback,
200 gpointer callback_data);
201 static GType gtk_toolbar_child_type (GtkContainer *container);
202 static void gtk_toolbar_orientation_changed (GtkToolbar *toolbar,
203 GtkOrientation orientation);
204 static void gtk_toolbar_real_style_changed (GtkToolbar *toolbar,
205 GtkToolbarStyle style);
206 static gboolean gtk_toolbar_move_focus (GtkToolbar *toolbar,
207 GtkDirectionType dir);
208 static gboolean gtk_toolbar_focus_home_or_end (GtkToolbar *toolbar,
209 gboolean focus_home);
210 static gboolean gtk_toolbar_button_press (GtkWidget *toolbar,
211 GdkEventButton *event);
212 static gboolean gtk_toolbar_arrow_button_press (GtkWidget *button,
213 GdkEventButton *event,
214 GtkToolbar *toolbar);
215 static void gtk_toolbar_arrow_button_clicked (GtkWidget *button,
216 GtkToolbar *toolbar);
217 static void gtk_toolbar_update_button_relief (GtkToolbar *toolbar);
218 static gboolean gtk_toolbar_popup_menu (GtkWidget *toolbar);
219 static GtkWidget *internal_insert_element (GtkToolbar *toolbar,
220 GtkToolbarChildType type,
223 const char *tooltip_text,
224 const char *tooltip_private_text,
226 GtkSignalFunc callback,
230 static void gtk_toolbar_reconfigured (GtkToolbar *toolbar);
231 static gboolean gtk_toolbar_check_new_api (GtkToolbar *toolbar);
232 static gboolean gtk_toolbar_check_old_api (GtkToolbar *toolbar);
234 static GtkReliefStyle get_button_relief (GtkToolbar *toolbar);
235 static gint get_internal_padding (GtkToolbar *toolbar);
236 static GtkShadowType get_shadow_type (GtkToolbar *toolbar);
237 static gint get_space_size (GtkToolbar *toolbar);
238 static GtkToolbarSpaceStyle get_space_style (GtkToolbar *toolbar);
240 /* methods on ToolbarContent 'class' */
241 static ToolbarContent *toolbar_content_new_tool_item (GtkToolbar *toolbar,
243 gboolean is_placeholder,
245 static ToolbarContent *toolbar_content_new_compatibility (GtkToolbar *toolbar,
246 GtkToolbarChildType type,
251 static void toolbar_content_remove (ToolbarContent *content,
252 GtkToolbar *toolbar);
253 static void toolbar_content_free (ToolbarContent *content);
254 static void toolbar_content_expose (ToolbarContent *content,
255 GtkContainer *container,
256 GdkEventExpose *expose);
257 static gboolean toolbar_content_visible (ToolbarContent *content,
258 GtkToolbar *toolbar);
259 static void toolbar_content_size_request (ToolbarContent *content,
261 GtkRequisition *requisition);
262 static gboolean toolbar_content_is_homogeneous (ToolbarContent *content,
263 GtkToolbar *toolbar);
264 static gboolean toolbar_content_is_placeholder (ToolbarContent *content);
265 static gboolean toolbar_content_disappearing (ToolbarContent *content);
266 static ItemState toolbar_content_get_state (ToolbarContent *content);
267 static gboolean toolbar_content_child_visible (ToolbarContent *content);
268 static void toolbar_content_get_goal_allocation (ToolbarContent *content,
269 GtkAllocation *allocation);
270 static void toolbar_content_get_allocation (ToolbarContent *content,
271 GtkAllocation *allocation);
272 static void toolbar_content_set_start_allocation (ToolbarContent *content,
273 GtkAllocation *new_start_allocation);
274 static void toolbar_content_get_start_allocation (ToolbarContent *content,
275 GtkAllocation *start_allocation);
276 static gboolean toolbar_content_get_expand (ToolbarContent *content);
277 static void toolbar_content_set_goal_allocation (ToolbarContent *content,
278 GtkAllocation *allocation);
279 static void toolbar_content_set_child_visible (ToolbarContent *content,
282 static void toolbar_content_size_allocate (ToolbarContent *content,
283 GtkAllocation *allocation);
284 static void toolbar_content_set_state (ToolbarContent *content,
285 ItemState new_state);
286 static GtkWidget * toolbar_content_get_widget (ToolbarContent *content);
287 static void toolbar_content_set_disappearing (ToolbarContent *content,
288 gboolean disappearing);
289 static void toolbar_content_set_size_request (ToolbarContent *content,
292 static void toolbar_content_toolbar_reconfigured (ToolbarContent *content,
293 GtkToolbar *toolbar);
294 static GtkWidget * toolbar_content_retrieve_menu_item (ToolbarContent *content);
295 static gboolean toolbar_content_has_proxy_menu_item (ToolbarContent *content);
296 static gboolean toolbar_content_is_separator (ToolbarContent *content);
297 static void toolbar_content_show_all (ToolbarContent *content);
298 static void toolbar_content_hide_all (ToolbarContent *content);
299 static void toolbar_content_set_expand (ToolbarContent *content,
302 #define GTK_TOOLBAR_GET_PRIVATE(o) \
303 (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_TOOLBAR, GtkToolbarPrivate))
305 static guint toolbar_signals [LAST_SIGNAL] = { 0 };
307 G_DEFINE_TYPE (GtkToolbar, gtk_toolbar, GTK_TYPE_CONTAINER)
310 add_arrow_bindings (GtkBindingSet *binding_set,
312 GtkDirectionType dir)
314 guint keypad_keysym = keysym - GDK_Left + GDK_KP_Left;
316 gtk_binding_entry_add_signal (binding_set, keysym, 0,
318 GTK_TYPE_DIRECTION_TYPE, dir);
319 gtk_binding_entry_add_signal (binding_set, keypad_keysym, 0,
321 GTK_TYPE_DIRECTION_TYPE, dir);
325 add_ctrl_tab_bindings (GtkBindingSet *binding_set,
326 GdkModifierType modifiers,
327 GtkDirectionType direction)
329 gtk_binding_entry_add_signal (binding_set,
330 GDK_Tab, GDK_CONTROL_MASK | modifiers,
332 GTK_TYPE_DIRECTION_TYPE, direction);
333 gtk_binding_entry_add_signal (binding_set,
334 GDK_KP_Tab, GDK_CONTROL_MASK | modifiers,
336 GTK_TYPE_DIRECTION_TYPE, direction);
340 gtk_toolbar_class_init (GtkToolbarClass *klass)
342 GObjectClass *gobject_class;
343 GtkWidgetClass *widget_class;
344 GtkContainerClass *container_class;
345 GtkBindingSet *binding_set;
347 gobject_class = (GObjectClass *)klass;
348 widget_class = (GtkWidgetClass *)klass;
349 container_class = (GtkContainerClass *)klass;
351 gobject_class->set_property = gtk_toolbar_set_property;
352 gobject_class->get_property = gtk_toolbar_get_property;
353 gobject_class->finalize = gtk_toolbar_finalize;
355 widget_class->button_press_event = gtk_toolbar_button_press;
356 widget_class->expose_event = gtk_toolbar_expose;
357 widget_class->size_request = gtk_toolbar_size_request;
358 widget_class->size_allocate = gtk_toolbar_size_allocate;
359 widget_class->style_set = gtk_toolbar_style_set;
360 widget_class->focus = gtk_toolbar_focus;
361 widget_class->screen_changed = gtk_toolbar_screen_changed;
362 widget_class->realize = gtk_toolbar_realize;
363 widget_class->unrealize = gtk_toolbar_unrealize;
364 widget_class->map = gtk_toolbar_map;
365 widget_class->unmap = gtk_toolbar_unmap;
366 widget_class->popup_menu = gtk_toolbar_popup_menu;
367 widget_class->show_all = gtk_toolbar_show_all;
368 widget_class->hide_all = gtk_toolbar_hide_all;
370 container_class->add = gtk_toolbar_add;
371 container_class->remove = gtk_toolbar_remove;
372 container_class->forall = gtk_toolbar_forall;
373 container_class->child_type = gtk_toolbar_child_type;
374 container_class->get_child_property = gtk_toolbar_get_child_property;
375 container_class->set_child_property = gtk_toolbar_set_child_property;
377 klass->orientation_changed = gtk_toolbar_orientation_changed;
378 klass->style_changed = gtk_toolbar_real_style_changed;
381 * GtkToolbar::orientation-changed:
382 * @toolbar: the object which emitted the signal
383 * @orientation: the new #GtkOrientation of the toolbar
385 * Emitted when the orientation of the toolbar changes.
387 toolbar_signals[ORIENTATION_CHANGED] =
388 g_signal_new (I_("orientation-changed"),
389 G_OBJECT_CLASS_TYPE (klass),
391 G_STRUCT_OFFSET (GtkToolbarClass, orientation_changed),
393 g_cclosure_marshal_VOID__ENUM,
395 GTK_TYPE_ORIENTATION);
397 * GtkToolbar::style-changed:
398 * @toolbar: The #GtkToolbar which emitted the signal
399 * @style: the new #GtkToolbarStyle of the toolbar
401 * Emitted when the style of the toolbar changes.
403 toolbar_signals[STYLE_CHANGED] =
404 g_signal_new (I_("style-changed"),
405 G_OBJECT_CLASS_TYPE (klass),
407 G_STRUCT_OFFSET (GtkToolbarClass, style_changed),
409 g_cclosure_marshal_VOID__ENUM,
411 GTK_TYPE_TOOLBAR_STYLE);
413 * GtkToolbar::popup-context-menu:
414 * @toolbar: the #GtkToolbar which emitted the signal
415 * @x: the x coordinate of the point where the menu should appear
416 * @y: the y coordinate of the point where the menu should appear
417 * @button: the mouse button the user pressed, or -1
419 * Emitted when the user right-clicks the toolbar or uses the
420 * keybinding to display a popup menu.
422 * Application developers should handle this signal if they want
423 * to display a context menu on the toolbar. The context-menu should
424 * appear at the coordinates given by @x and @y. The mouse button
425 * number is given by the @button parameter. If the menu was popped
426 * up using the keybaord, @button is -1.
428 * Return value: return %TRUE if the signal was handled, %FALSE if not
430 toolbar_signals[POPUP_CONTEXT_MENU] =
431 g_signal_new (I_("popup_context_menu"),
432 G_OBJECT_CLASS_TYPE (klass),
434 G_STRUCT_OFFSET (GtkToolbarClass, popup_context_menu),
435 _gtk_boolean_handled_accumulator, NULL,
436 _gtk_marshal_BOOLEAN__INT_INT_INT,
438 G_TYPE_INT, G_TYPE_INT,
441 * GtkToolbar::move-focus:
442 * @toolbar: the #GtkToolbar which emitted the signal
443 * @dir: a #GtkDirection
445 * A keybinding signal used internally by GTK+. This signal can't
446 * be used in application code.
448 * Return value: %TRUE if the signal was handled, %FALSE if not
450 toolbar_signals[MOVE_FOCUS] =
451 _gtk_binding_signal_new (I_("move_focus"),
452 G_TYPE_FROM_CLASS (klass),
453 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
454 G_CALLBACK (gtk_toolbar_move_focus),
456 _gtk_marshal_BOOLEAN__ENUM,
458 GTK_TYPE_DIRECTION_TYPE);
460 * GtkToolbar::focus-home-or-end:
461 * @toolbar: the #GtkToolbar which emitted the signal
462 * @focus_home: %TRUE if the first item should be focused
464 * A keybinding signal used internally by GTK+. This signal can't
465 * be used in application code
467 * Return value: %TRUE if the signal was handled, %FALSE if not
469 toolbar_signals[FOCUS_HOME_OR_END] =
470 _gtk_binding_signal_new (I_("focus_home_or_end"),
471 G_OBJECT_CLASS_TYPE (klass),
472 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
473 G_CALLBACK (gtk_toolbar_focus_home_or_end),
475 _gtk_marshal_BOOLEAN__BOOLEAN,
480 g_object_class_install_property (gobject_class,
482 g_param_spec_enum ("orientation",
484 P_("The orientation of the toolbar"),
485 GTK_TYPE_ORIENTATION,
486 GTK_ORIENTATION_HORIZONTAL,
487 GTK_PARAM_READWRITE));
489 g_object_class_install_property (gobject_class,
491 g_param_spec_enum ("toolbar-style",
493 P_("How to draw the toolbar"),
494 GTK_TYPE_TOOLBAR_STYLE,
496 GTK_PARAM_READWRITE));
497 g_object_class_install_property (gobject_class,
499 g_param_spec_boolean ("show-arrow",
501 P_("If an arrow should be shown if the toolbar doesn't fit"),
503 GTK_PARAM_READWRITE));
507 * GtkToolbar:tooltips:
509 * If the tooltips of the toolbar should be active or not.
513 g_object_class_install_property (gobject_class,
515 g_param_spec_boolean ("tooltips",
517 P_("If the tooltips of the toolbar should be active or not"),
519 GTK_PARAM_READWRITE));
523 * GtkToolbar:icon-size:
525 * The size of the icons in a toolbar is normally determined by
526 * the toolbar-icon-size setting. When this property is set, it
527 * overrides the setting.
529 * This should only be used for special-purpose toolbars, normal
530 * application toolbars should respect the user preferences for the
535 g_object_class_install_property (gobject_class,
537 g_param_spec_enum ("icon-size",
539 P_("Size of icons in this toolbar"),
542 GTK_PARAM_READWRITE));
545 * GtkToolbar:icon-size-set:
547 * Is %TRUE if the icon-size property has been set.
551 g_object_class_install_property (gobject_class,
553 g_param_spec_boolean ("icon-size-set",
555 P_("Whether the icon-size property has been set"),
557 GTK_PARAM_READWRITE));
559 /* child properties */
560 gtk_container_class_install_child_property (container_class,
562 g_param_spec_boolean ("expand",
564 P_("Whether the item should receive extra space when the toolbar grows"),
566 GTK_PARAM_READWRITE));
568 gtk_container_class_install_child_property (container_class,
569 CHILD_PROP_HOMOGENEOUS,
570 g_param_spec_boolean ("homogeneous",
572 P_("Whether the item should be the same size as other homogeneous items"),
574 GTK_PARAM_READWRITE));
576 /* style properties */
577 gtk_widget_class_install_style_property (widget_class,
578 g_param_spec_int ("space-size",
580 P_("Size of spacers"),
584 GTK_PARAM_READABLE));
586 gtk_widget_class_install_style_property (widget_class,
587 g_param_spec_int ("internal-padding",
588 P_("Internal padding"),
589 P_("Amount of border space between the toolbar shadow and the buttons"),
593 GTK_PARAM_READABLE));
595 gtk_widget_class_install_style_property (widget_class,
596 g_param_spec_enum ("space-style",
598 P_("Whether spacers are vertical lines or just blank"),
599 GTK_TYPE_TOOLBAR_SPACE_STYLE,
601 GTK_PARAM_READABLE));
603 gtk_widget_class_install_style_property (widget_class,
604 g_param_spec_enum ("button-relief",
606 P_("Type of bevel around toolbar buttons"),
607 GTK_TYPE_RELIEF_STYLE,
609 GTK_PARAM_READABLE));
610 gtk_widget_class_install_style_property (widget_class,
611 g_param_spec_enum ("shadow-type",
613 P_("Style of bevel around the toolbar"),
614 GTK_TYPE_SHADOW_TYPE,
616 GTK_PARAM_READABLE));
618 gtk_settings_install_property (g_param_spec_enum ("gtk-toolbar-style",
620 P_("Whether default toolbars have text only, text and icons, icons only, etc."),
621 GTK_TYPE_TOOLBAR_STYLE,
622 DEFAULT_TOOLBAR_STYLE,
623 GTK_PARAM_READWRITE));
625 gtk_settings_install_property (g_param_spec_enum ("gtk-toolbar-icon-size",
626 P_("Toolbar icon size"),
627 P_("Size of icons in default toolbars"),
630 GTK_PARAM_READWRITE));
632 binding_set = gtk_binding_set_by_class (klass);
634 add_arrow_bindings (binding_set, GDK_Left, GTK_DIR_LEFT);
635 add_arrow_bindings (binding_set, GDK_Right, GTK_DIR_RIGHT);
636 add_arrow_bindings (binding_set, GDK_Up, GTK_DIR_UP);
637 add_arrow_bindings (binding_set, GDK_Down, GTK_DIR_DOWN);
639 gtk_binding_entry_add_signal (binding_set, GDK_KP_Home, 0,
640 "focus_home_or_end", 1,
641 G_TYPE_BOOLEAN, TRUE);
642 gtk_binding_entry_add_signal (binding_set, GDK_Home, 0,
643 "focus_home_or_end", 1,
644 G_TYPE_BOOLEAN, TRUE);
645 gtk_binding_entry_add_signal (binding_set, GDK_KP_End, 0,
646 "focus_home_or_end", 1,
647 G_TYPE_BOOLEAN, FALSE);
648 gtk_binding_entry_add_signal (binding_set, GDK_End, 0,
649 "focus_home_or_end", 1,
650 G_TYPE_BOOLEAN, FALSE);
652 add_ctrl_tab_bindings (binding_set, 0, GTK_DIR_TAB_FORWARD);
653 add_ctrl_tab_bindings (binding_set, GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
655 g_type_class_add_private (gobject_class, sizeof (GtkToolbarPrivate));
659 gtk_toolbar_init (GtkToolbar *toolbar)
661 GtkToolbarPrivate *priv;
663 GTK_WIDGET_UNSET_FLAGS (toolbar, GTK_CAN_FOCUS);
664 GTK_WIDGET_SET_FLAGS (toolbar, GTK_NO_WINDOW);
666 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
668 toolbar->orientation = GTK_ORIENTATION_HORIZONTAL;
669 toolbar->style = DEFAULT_TOOLBAR_STYLE;
670 toolbar->icon_size = DEFAULT_ICON_SIZE;
671 priv->animation = DEFAULT_ANIMATION_STATE;
672 toolbar->tooltips = gtk_tooltips_new ();
673 g_object_ref_sink (toolbar->tooltips);
675 priv->arrow_button = gtk_toggle_button_new ();
676 g_signal_connect (priv->arrow_button, "button_press_event",
677 G_CALLBACK (gtk_toolbar_arrow_button_press), toolbar);
678 g_signal_connect (priv->arrow_button, "clicked",
679 G_CALLBACK (gtk_toolbar_arrow_button_clicked), toolbar);
680 gtk_button_set_relief (GTK_BUTTON (priv->arrow_button),
681 get_button_relief (toolbar));
683 priv->api_mode = DONT_KNOW;
685 gtk_button_set_focus_on_click (GTK_BUTTON (priv->arrow_button), FALSE);
687 priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
688 gtk_widget_set_name (priv->arrow, "gtk-toolbar-arrow");
689 gtk_widget_show (priv->arrow);
690 gtk_container_add (GTK_CONTAINER (priv->arrow_button), priv->arrow);
692 gtk_widget_set_parent (priv->arrow_button, GTK_WIDGET (toolbar));
694 /* which child position a drop will occur at */
696 priv->show_arrow = TRUE;
697 priv->settings = NULL;
699 priv->max_homogeneous_pixels = -1;
701 priv->timer = g_timer_new ();
705 gtk_toolbar_set_property (GObject *object,
710 GtkToolbar *toolbar = GTK_TOOLBAR (object);
714 case PROP_ORIENTATION:
715 gtk_toolbar_set_orientation (toolbar, g_value_get_enum (value));
717 case PROP_TOOLBAR_STYLE:
718 gtk_toolbar_set_style (toolbar, g_value_get_enum (value));
720 case PROP_SHOW_ARROW:
721 gtk_toolbar_set_show_arrow (toolbar, g_value_get_boolean (value));
724 gtk_toolbar_set_tooltips (toolbar, g_value_get_boolean (value));
727 gtk_toolbar_set_icon_size (toolbar, g_value_get_enum (value));
729 case PROP_ICON_SIZE_SET:
730 if (g_value_get_boolean (value))
731 toolbar->icon_size_set = TRUE;
733 gtk_toolbar_unset_icon_size (toolbar);
736 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
742 gtk_toolbar_get_property (GObject *object,
747 GtkToolbar *toolbar = GTK_TOOLBAR (object);
748 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
752 case PROP_ORIENTATION:
753 g_value_set_enum (value, toolbar->orientation);
755 case PROP_TOOLBAR_STYLE:
756 g_value_set_enum (value, toolbar->style);
758 case PROP_SHOW_ARROW:
759 g_value_set_boolean (value, priv->show_arrow);
762 g_value_set_boolean (value, gtk_toolbar_get_tooltips (toolbar));
765 g_value_set_enum (value, gtk_toolbar_get_icon_size (toolbar));
767 case PROP_ICON_SIZE_SET:
768 g_value_set_boolean (value, toolbar->icon_size_set);
771 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
777 gtk_toolbar_map (GtkWidget *widget)
779 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
781 GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->map (widget);
783 if (priv->event_window)
784 gdk_window_show_unraised (priv->event_window);
788 gtk_toolbar_unmap (GtkWidget *widget)
790 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
792 if (priv->event_window)
793 gdk_window_hide (priv->event_window);
795 GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unmap (widget);
799 gtk_toolbar_realize (GtkWidget *widget)
801 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
802 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
804 GdkWindowAttr attributes;
805 gint attributes_mask;
808 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
810 border_width = GTK_CONTAINER (widget)->border_width;
812 attributes.wclass = GDK_INPUT_ONLY;
813 attributes.window_type = GDK_WINDOW_CHILD;
814 attributes.x = widget->allocation.x + border_width;
815 attributes.y = widget->allocation.y + border_width;
816 attributes.width = widget->allocation.width - border_width * 2;
817 attributes.height = widget->allocation.height - border_width * 2;
818 attributes.event_mask = gtk_widget_get_events (widget);
819 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
820 GDK_BUTTON_RELEASE_MASK |
821 GDK_ENTER_NOTIFY_MASK |
822 GDK_LEAVE_NOTIFY_MASK);
824 attributes_mask = GDK_WA_X | GDK_WA_Y;
826 widget->window = gtk_widget_get_parent_window (widget);
827 g_object_ref (widget->window);
828 widget->style = gtk_style_attach (widget->style, widget->window);
830 priv->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
831 &attributes, attributes_mask);
832 gdk_window_set_user_data (priv->event_window, toolbar);
836 gtk_toolbar_unrealize (GtkWidget *widget)
838 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
840 if (priv->event_window)
842 gdk_window_set_user_data (priv->event_window, NULL);
843 gdk_window_destroy (priv->event_window);
844 priv->event_window = NULL;
847 if (GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unrealize)
848 (* GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unrealize) (widget);
852 gtk_toolbar_expose (GtkWidget *widget,
853 GdkEventExpose *event)
855 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
856 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
861 border_width = GTK_CONTAINER (widget)->border_width;
863 if (GTK_WIDGET_DRAWABLE (widget))
865 gtk_paint_box (widget->style,
867 GTK_WIDGET_STATE (widget),
868 get_shadow_type (toolbar),
869 &event->area, widget, "toolbar",
870 border_width + widget->allocation.x,
871 border_width + widget->allocation.y,
872 widget->allocation.width - 2 * border_width,
873 widget->allocation.height - 2 * border_width);
876 for (list = priv->content; list != NULL; list = list->next)
878 ToolbarContent *content = list->data;
880 toolbar_content_expose (content, GTK_CONTAINER (widget), event);
883 gtk_container_propagate_expose (GTK_CONTAINER (widget),
891 gtk_toolbar_size_request (GtkWidget *widget,
892 GtkRequisition *requisition)
894 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
895 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
897 gint max_child_height;
898 gint max_child_width;
899 gint max_homogeneous_child_width;
900 gint max_homogeneous_child_height;
901 gint homogeneous_size;
903 gint pack_front_size;
905 GtkRequisition arrow_requisition;
907 max_homogeneous_child_width = 0;
908 max_homogeneous_child_height = 0;
910 max_child_height = 0;
911 for (list = priv->content; list != NULL; list = list->next)
913 GtkRequisition requisition;
914 ToolbarContent *content = list->data;
916 if (!toolbar_content_visible (content, toolbar))
919 toolbar_content_size_request (content, toolbar, &requisition);
921 max_child_width = MAX (max_child_width, requisition.width);
922 max_child_height = MAX (max_child_height, requisition.height);
924 if (toolbar_content_is_homogeneous (content, toolbar))
926 max_homogeneous_child_width = MAX (max_homogeneous_child_width, requisition.width);
927 max_homogeneous_child_height = MAX (max_homogeneous_child_height, requisition.height);
931 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
932 homogeneous_size = max_homogeneous_child_width;
934 homogeneous_size = max_homogeneous_child_height;
937 for (list = priv->content; list != NULL; list = list->next)
939 ToolbarContent *content = list->data;
942 if (!toolbar_content_visible (content, toolbar))
945 if (toolbar_content_is_homogeneous (content, toolbar))
947 size = homogeneous_size;
951 GtkRequisition requisition;
953 toolbar_content_size_request (content, toolbar, &requisition);
955 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
956 size = requisition.width;
958 size = requisition.height;
961 pack_front_size += size;
964 if (priv->show_arrow && priv->api_mode == NEW_API)
966 gtk_widget_size_request (priv->arrow_button, &arrow_requisition);
968 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
969 long_req = arrow_requisition.width;
971 long_req = arrow_requisition.height;
973 /* There is no point requesting space for the arrow if that would take
974 * up more space than all the items combined
976 long_req = MIN (long_req, pack_front_size);
980 arrow_requisition.height = 0;
981 arrow_requisition.width = 0;
983 long_req = pack_front_size;
986 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
988 requisition->width = long_req;
989 requisition->height = MAX (max_child_height, arrow_requisition.height);
993 requisition->height = long_req;
994 requisition->width = MAX (max_child_width, arrow_requisition.width);
998 ipadding = get_internal_padding (toolbar);
1000 requisition->width += 2 * (ipadding + GTK_CONTAINER (toolbar)->border_width);
1001 requisition->height += 2 * (ipadding + GTK_CONTAINER (toolbar)->border_width);
1003 if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
1005 requisition->width += 2 * widget->style->xthickness;
1006 requisition->height += 2 * widget->style->ythickness;
1009 toolbar->button_maxw = max_homogeneous_child_width;
1010 toolbar->button_maxh = max_homogeneous_child_height;
1014 position (GtkToolbar *toolbar,
1021 if (! GTK_TOOLBAR_GET_PRIVATE (toolbar)->animation)
1024 if (elapsed <= ACCEL_THRESHOLD)
1026 n_pixels = SLIDE_SPEED * elapsed;
1030 /* The formula is a second degree polynomial in
1031 * @elapsed that has the line SLIDE_SPEED * @elapsed
1032 * as tangent for @elapsed == ACCEL_THRESHOLD.
1033 * This makes @n_pixels a smooth function of elapsed time.
1035 n_pixels = (SLIDE_SPEED / ACCEL_THRESHOLD) * elapsed * elapsed -
1036 SLIDE_SPEED * elapsed + SLIDE_SPEED * ACCEL_THRESHOLD;
1040 return MIN (from + n_pixels, to);
1042 return MAX (from - n_pixels, to);
1046 compute_intermediate_allocation (GtkToolbar *toolbar,
1047 const GtkAllocation *start,
1048 const GtkAllocation *goal,
1049 GtkAllocation *intermediate)
1051 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1052 gdouble elapsed = g_timer_elapsed (priv->timer, NULL);
1054 intermediate->x = position (toolbar, start->x, goal->x, elapsed);
1055 intermediate->y = position (toolbar, start->y, goal->y, elapsed);
1056 intermediate->width = position (toolbar, start->x + start->width,
1057 goal->x + goal->width,
1058 elapsed) - intermediate->x;
1059 intermediate->height = position (toolbar, start->y + start->height,
1060 goal->y + goal->height,
1061 elapsed) - intermediate->y;
1065 fixup_allocation_for_rtl (gint total_size,
1066 GtkAllocation *allocation)
1068 allocation->x += (total_size - (2 * allocation->x + allocation->width));
1072 fixup_allocation_for_vertical (GtkAllocation *allocation)
1076 tmp = allocation->x;
1077 allocation->x = allocation->y;
1078 allocation->y = tmp;
1080 tmp = allocation->width;
1081 allocation->width = allocation->height;
1082 allocation->height = tmp;
1086 get_item_size (GtkToolbar *toolbar,
1087 ToolbarContent *content)
1089 GtkRequisition requisition;
1091 toolbar_content_size_request (content, toolbar, &requisition);
1093 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
1095 if (toolbar_content_is_homogeneous (content, toolbar))
1096 return toolbar->button_maxw;
1098 return requisition.width;
1102 if (toolbar_content_is_homogeneous (content, toolbar))
1103 return toolbar->button_maxh;
1105 return requisition.height;
1110 slide_idle_handler (gpointer data)
1112 GtkToolbar *toolbar = data;
1113 GtkToolbarPrivate *priv;
1116 GDK_THREADS_ENTER ();
1118 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1120 if (priv->need_sync)
1123 priv->need_sync = FALSE;
1126 for (list = priv->content; list != NULL; list = list->next)
1128 ToolbarContent *content = list->data;
1130 GtkAllocation goal_allocation;
1131 GtkAllocation allocation;
1134 state = toolbar_content_get_state (content);
1135 toolbar_content_get_goal_allocation (content, &goal_allocation);
1136 toolbar_content_get_allocation (content, &allocation);
1140 if (state == NOT_ALLOCATED)
1142 /* an unallocated item means that size allocate has to
1143 * called at least once more
1148 /* An invisible item with a goal allocation of
1149 * 0 is already at its goal.
1151 if ((state == NORMAL || state == OVERFLOWN) &&
1152 ((goal_allocation.width != 0 &&
1153 goal_allocation.height != 0) ||
1154 toolbar_content_child_visible (content)))
1156 if ((goal_allocation.x != allocation.x ||
1157 goal_allocation.y != allocation.y ||
1158 goal_allocation.width != allocation.width ||
1159 goal_allocation.height != allocation.height))
1161 /* An item is not in its right position yet. Note
1162 * that OVERFLOWN items do get an allocation in
1163 * gtk_toolbar_size_allocate(). This way you can see
1164 * them slide back in when you drag an item off the
1171 if (toolbar_content_is_placeholder (content) &&
1172 toolbar_content_disappearing (content) &&
1173 toolbar_content_child_visible (content))
1175 /* A disappearing placeholder is still visible.
1183 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1185 GDK_THREADS_LEAVE ();
1190 priv->is_sliding = FALSE;
1193 GDK_THREADS_LEAVE();
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 = g_idle_add (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;
1448 GtkAllocation item_area;
1450 size_changed = FALSE;
1451 if (widget->allocation.x != allocation->x ||
1452 widget->allocation.y != allocation->y ||
1453 widget->allocation.width != allocation->width ||
1454 widget->allocation.height != allocation->height)
1456 size_changed = TRUE;
1460 gtk_toolbar_stop_sliding (toolbar);
1462 widget->allocation = *allocation;
1464 border_width = GTK_CONTAINER (toolbar)->border_width;
1466 if (GTK_WIDGET_REALIZED (widget))
1468 gdk_window_move_resize (priv->event_window,
1469 allocation->x + border_width,
1470 allocation->y + border_width,
1471 allocation->width - border_width * 2,
1472 allocation->height - border_width * 2);
1475 border_width += get_internal_padding (toolbar);
1477 gtk_widget_get_child_requisition (GTK_WIDGET (priv->arrow_button),
1478 &arrow_requisition);
1480 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
1482 available_size = size = allocation->width - 2 * border_width;
1483 short_size = allocation->height - 2 * border_width;
1484 arrow_size = arrow_requisition.width;
1486 if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
1488 available_size -= 2 * widget->style->xthickness;
1489 short_size -= 2 * widget->style->ythickness;
1494 available_size = size = allocation->height - 2 * border_width;
1495 short_size = allocation->width - 2 * border_width;
1496 arrow_size = arrow_requisition.height;
1498 if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
1500 available_size -= 2 * widget->style->ythickness;
1501 short_size -= 2 * widget->style->xthickness;
1505 n_items = g_list_length (priv->content);
1506 allocations = g_new0 (GtkAllocation, n_items);
1507 new_states = g_new0 (ItemState, n_items);
1511 for (list = priv->content; list != NULL; list = list->next)
1513 ToolbarContent *content = list->data;
1515 if (toolbar_content_visible (content, toolbar))
1517 needed_size += get_item_size (toolbar, content);
1519 /* Do we need an arrow?
1521 * Assume we don't, and see if any non-separator item with a
1522 * proxy menu item is then going to overflow.
1524 if (needed_size > available_size &&
1527 priv->api_mode == NEW_API &&
1528 toolbar_content_has_proxy_menu_item (content) &&
1529 !toolbar_content_is_separator (content))
1537 size = available_size - arrow_size;
1539 size = available_size;
1541 /* calculate widths and states of items */
1542 overflowing = FALSE;
1543 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1545 ToolbarContent *content = list->data;
1548 if (!toolbar_content_visible (content, toolbar))
1550 new_states[i] = HIDDEN;
1554 item_size = get_item_size (toolbar, content);
1555 if (item_size <= size && !overflowing)
1558 allocations[i].width = item_size;
1559 new_states[i] = NORMAL;
1564 new_states[i] = OVERFLOWN;
1565 allocations[i].width = item_size;
1569 /* calculate width of arrow */
1572 arrow_allocation.width = arrow_size;
1573 arrow_allocation.height = MAX (short_size, 1);
1576 /* expand expandable items */
1578 /* We don't expand when there is an overflow menu, because that leads to
1579 * weird jumps when items get moved to the overflow menu and the expanding
1580 * items suddenly get a lot of extra space
1585 for (i = 0, list = priv->content; list != NULL; list = list->next, ++i)
1587 ToolbarContent *content = list->data;
1589 if (toolbar_content_get_expand (content) && new_states[i] == NORMAL)
1593 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1595 ToolbarContent *content = list->data;
1597 if (toolbar_content_get_expand (content) && new_states[i] == NORMAL)
1599 gint extra = size / n_expand_items;
1600 if (size % n_expand_items != 0)
1603 allocations[i].width += extra;
1609 g_assert (n_expand_items == 0);
1612 /* position items */
1614 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1616 /* both NORMAL and OVERFLOWN items get a position. This ensures
1617 * that sliding will work for OVERFLOWN items too
1619 if (new_states[i] == NORMAL ||
1620 new_states[i] == OVERFLOWN)
1622 allocations[i].x = pos;
1623 allocations[i].y = border_width;
1624 allocations[i].height = short_size;
1626 pos += allocations[i].width;
1630 /* position arrow */
1633 arrow_allocation.x = available_size - border_width - arrow_allocation.width;
1634 arrow_allocation.y = border_width;
1637 item_area.x = border_width;
1638 item_area.y = border_width;
1639 item_area.width = available_size - (need_arrow? arrow_size : 0);
1640 item_area.height = short_size;
1642 /* fix up allocations in the vertical or RTL cases */
1643 if (toolbar->orientation == GTK_ORIENTATION_VERTICAL)
1645 for (i = 0; i < n_items; ++i)
1646 fixup_allocation_for_vertical (&(allocations[i]));
1649 fixup_allocation_for_vertical (&arrow_allocation);
1651 fixup_allocation_for_vertical (&item_area);
1653 else if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL)
1655 for (i = 0; i < n_items; ++i)
1656 fixup_allocation_for_rtl (available_size, &(allocations[i]));
1659 fixup_allocation_for_rtl (available_size, &arrow_allocation);
1661 fixup_allocation_for_rtl (available_size, &item_area);
1664 /* translate the items by allocation->(x,y) */
1665 for (i = 0; i < n_items; ++i)
1667 allocations[i].x += allocation->x;
1668 allocations[i].y += allocation->y;
1670 if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
1672 allocations[i].x += widget->style->xthickness;
1673 allocations[i].y += widget->style->ythickness;
1679 arrow_allocation.x += allocation->x;
1680 arrow_allocation.y += allocation->y;
1682 if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
1684 arrow_allocation.x += widget->style->xthickness;
1685 arrow_allocation.y += widget->style->ythickness;
1689 item_area.x += allocation->x;
1690 item_area.y += allocation->y;
1691 if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
1693 item_area.x += widget->style->xthickness;
1694 item_area.y += widget->style->ythickness;
1697 /* did anything change? */
1698 for (list = priv->content, i = 0; list != NULL; list = list->next, i++)
1700 ToolbarContent *content = list->data;
1702 if (toolbar_content_get_state (content) == NORMAL &&
1703 new_states[i] != NORMAL)
1705 /* an item disappeared and we didn't change size, so begin sliding */
1706 if (!size_changed && priv->api_mode == NEW_API)
1707 gtk_toolbar_begin_sliding (toolbar);
1711 /* finally allocate the items */
1712 if (priv->is_sliding)
1714 for (list = priv->content, i = 0; list != NULL; list = list->next, i++)
1716 ToolbarContent *content = list->data;
1718 toolbar_content_set_goal_allocation (content, &(allocations[i]));
1722 elapsed = g_timer_elapsed (priv->timer, NULL);
1723 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1725 ToolbarContent *content = list->data;
1727 if (new_states[i] == OVERFLOWN ||
1728 new_states[i] == NORMAL)
1730 GtkAllocation alloc;
1731 GtkAllocation start_allocation = { 0, };
1732 GtkAllocation goal_allocation;
1734 if (priv->is_sliding)
1736 toolbar_content_get_start_allocation (content, &start_allocation);
1737 toolbar_content_get_goal_allocation (content, &goal_allocation);
1739 compute_intermediate_allocation (toolbar,
1744 priv->need_sync = TRUE;
1748 alloc = allocations[i];
1751 if (alloc.width <= 0 || alloc.height <= 0)
1753 toolbar_content_set_child_visible (content, toolbar, FALSE);
1757 if (!rect_within (&alloc, &item_area))
1759 toolbar_content_set_child_visible (content, toolbar, FALSE);
1760 toolbar_content_size_allocate (content, &alloc);
1764 toolbar_content_set_child_visible (content, toolbar, TRUE);
1765 toolbar_content_size_allocate (content, &alloc);
1771 toolbar_content_set_child_visible (content, toolbar, FALSE);
1774 toolbar_content_set_state (content, new_states[i]);
1777 if (priv->menu && priv->need_rebuild)
1778 rebuild_menu (toolbar);
1782 gtk_widget_size_allocate (GTK_WIDGET (priv->arrow_button),
1784 gtk_widget_show (GTK_WIDGET (priv->arrow_button));
1788 gtk_widget_hide (GTK_WIDGET (priv->arrow_button));
1790 if (priv->menu && GTK_WIDGET_VISIBLE (priv->menu))
1791 gtk_menu_shell_deactivate (GTK_MENU_SHELL (priv->menu));
1794 g_free (allocations);
1795 g_free (new_states);
1799 gtk_toolbar_update_button_relief (GtkToolbar *toolbar)
1801 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1803 gtk_toolbar_reconfigured (toolbar);
1805 gtk_button_set_relief (GTK_BUTTON (priv->arrow_button), get_button_relief (toolbar));
1809 gtk_toolbar_style_set (GtkWidget *widget,
1810 GtkStyle *prev_style)
1812 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
1814 priv->max_homogeneous_pixels = -1;
1816 if (GTK_WIDGET_REALIZED (widget))
1817 gtk_style_set_background (widget->style, widget->window, widget->state);
1820 gtk_toolbar_update_button_relief (GTK_TOOLBAR (widget));
1824 gtk_toolbar_list_children_in_focus_order (GtkToolbar *toolbar,
1825 GtkDirectionType dir)
1827 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1828 GList *result = NULL;
1832 /* generate list of children in reverse logical order */
1834 for (list = priv->content; list != NULL; list = list->next)
1836 ToolbarContent *content = list->data;
1839 widget = toolbar_content_get_widget (content);
1842 result = g_list_prepend (result, widget);
1845 result = g_list_prepend (result, priv->arrow_button);
1847 rtl = (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL);
1849 /* move in logical order when
1851 * - dir is TAB_FORWARD
1853 * - in RTL mode and moving left or up
1855 * - in LTR mode and moving right or down
1857 if (dir == GTK_DIR_TAB_FORWARD ||
1858 (rtl && (dir == GTK_DIR_UP || dir == GTK_DIR_LEFT)) ||
1859 (!rtl && (dir == GTK_DIR_DOWN || dir == GTK_DIR_RIGHT)))
1861 result = g_list_reverse (result);
1868 gtk_toolbar_focus_home_or_end (GtkToolbar *toolbar,
1869 gboolean focus_home)
1871 GList *children, *list;
1872 GtkDirectionType dir = focus_home? GTK_DIR_RIGHT : GTK_DIR_LEFT;
1874 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1876 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL)
1878 children = g_list_reverse (children);
1880 dir = (dir == GTK_DIR_RIGHT)? GTK_DIR_LEFT : GTK_DIR_RIGHT;
1883 for (list = children; list != NULL; list = list->next)
1885 GtkWidget *child = list->data;
1887 if (GTK_CONTAINER (toolbar)->focus_child == child)
1890 if (GTK_WIDGET_MAPPED (child) && gtk_widget_child_focus (child, dir))
1894 g_list_free (children);
1899 /* Keybinding handler. This function is called when the user presses
1900 * Ctrl TAB or an arrow key.
1903 gtk_toolbar_move_focus (GtkToolbar *toolbar,
1904 GtkDirectionType dir)
1907 gboolean try_focus = FALSE;
1909 GtkContainer *container = GTK_CONTAINER (toolbar);
1911 if (container->focus_child &&
1912 gtk_widget_child_focus (container->focus_child, dir))
1917 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1919 for (list = children; list != NULL; list = list->next)
1921 GtkWidget *child = list->data;
1923 if (try_focus && GTK_WIDGET_MAPPED (child) && gtk_widget_child_focus (child, dir))
1926 if (child == GTK_CONTAINER (toolbar)->focus_child)
1930 g_list_free (children);
1935 /* The focus handler for the toolbar. It called when the user presses
1936 * TAB or otherwise tries to focus the toolbar.
1939 gtk_toolbar_focus (GtkWidget *widget,
1940 GtkDirectionType dir)
1942 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1943 GList *children, *list;
1944 gboolean result = FALSE;
1946 /* if focus is already somewhere inside the toolbar then return FALSE.
1947 * The only way focus can stay inside the toolbar is when the user presses
1948 * arrow keys or Ctrl TAB (both of which are handled by the
1949 * gtk_toolbar_move_focus() keybinding function.
1951 if (GTK_CONTAINER (widget)->focus_child)
1954 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1956 for (list = children; list != NULL; list = list->next)
1958 GtkWidget *child = list->data;
1960 if (GTK_WIDGET_MAPPED (child) && gtk_widget_child_focus (child, dir))
1967 g_list_free (children);
1972 static GtkSettings *
1973 toolbar_get_settings (GtkToolbar *toolbar)
1975 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1976 return priv->settings;
1980 style_change_notify (GtkToolbar *toolbar)
1982 if (!toolbar->style_set)
1984 /* pretend it was set, then unset, thus reverting to new default */
1985 toolbar->style_set = TRUE;
1986 gtk_toolbar_unset_style (toolbar);
1991 icon_size_change_notify (GtkToolbar *toolbar)
1993 if (!toolbar->icon_size_set)
1995 /* pretend it was set, then unset, thus reverting to new default */
1996 toolbar->icon_size_set = TRUE;
1997 gtk_toolbar_unset_icon_size (toolbar);
2002 animation_change_notify (GtkToolbar *toolbar)
2004 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2005 GtkSettings *settings = toolbar_get_settings (toolbar);
2009 g_object_get (settings,
2010 "gtk-enable-animations", &animation,
2013 animation = DEFAULT_ANIMATION_STATE;
2015 priv->animation = animation;
2019 settings_change_notify (GtkSettings *settings,
2020 const GParamSpec *pspec,
2021 GtkToolbar *toolbar)
2023 if (! strcmp (pspec->name, "gtk-toolbar-style"))
2024 style_change_notify (toolbar);
2025 else if (! strcmp (pspec->name, "gtk-toolbar-icon-size"))
2026 icon_size_change_notify (toolbar);
2027 else if (! strcmp (pspec->name, "gtk-enable-animations"))
2028 animation_change_notify (toolbar);
2032 gtk_toolbar_screen_changed (GtkWidget *widget,
2033 GdkScreen *previous_screen)
2035 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
2036 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
2037 GtkSettings *old_settings = toolbar_get_settings (toolbar);
2038 GtkSettings *settings;
2040 if (gtk_widget_has_screen (GTK_WIDGET (toolbar)))
2041 settings = gtk_widget_get_settings (GTK_WIDGET (toolbar));
2045 if (settings == old_settings)
2050 g_signal_handler_disconnect (old_settings, priv->settings_connection);
2052 g_object_unref (old_settings);
2057 priv->settings_connection =
2058 g_signal_connect (settings, "notify",
2059 G_CALLBACK (settings_change_notify),
2062 priv->settings = g_object_ref (settings);
2065 priv->settings = NULL;
2067 style_change_notify (toolbar);
2068 icon_size_change_notify (toolbar);
2069 animation_change_notify (toolbar);
2073 find_drop_index (GtkToolbar *toolbar,
2077 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2078 GList *interesting_content;
2080 GtkOrientation orientation;
2081 GtkTextDirection direction;
2082 gint best_distance = G_MAXINT;
2086 ToolbarContent *best_content;
2087 GtkAllocation allocation;
2089 /* list items we care about wrt. drag and drop */
2090 interesting_content = NULL;
2091 for (list = priv->content; list != NULL; list = list->next)
2093 ToolbarContent *content = list->data;
2095 if (toolbar_content_get_state (content) == NORMAL)
2096 interesting_content = g_list_prepend (interesting_content, content);
2098 interesting_content = g_list_reverse (interesting_content);
2100 if (!interesting_content)
2103 orientation = toolbar->orientation;
2104 direction = gtk_widget_get_direction (GTK_WIDGET (toolbar));
2106 /* distance to first interesting item */
2107 best_content = interesting_content->data;
2108 toolbar_content_get_allocation (best_content, &allocation);
2110 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2114 if (direction == GTK_TEXT_DIR_LTR)
2117 pos = allocation.x + allocation.width;
2125 best_content = NULL;
2126 best_distance = ABS (pos - cursor);
2128 /* distance to far end of each item */
2129 for (list = interesting_content; list != NULL; list = list->next)
2131 ToolbarContent *content = list->data;
2133 toolbar_content_get_allocation (content, &allocation);
2135 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2137 if (direction == GTK_TEXT_DIR_LTR)
2138 pos = allocation.x + allocation.width;
2144 pos = allocation.y + allocation.height;
2147 distance = ABS (pos - cursor);
2149 if (distance < best_distance)
2151 best_distance = distance;
2152 best_content = content;
2156 g_list_free (interesting_content);
2161 return g_list_index (priv->content, best_content) + 1;
2165 reset_all_placeholders (GtkToolbar *toolbar)
2167 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2170 for (list = priv->content; list != NULL; list = list->next)
2172 ToolbarContent *content = list->data;
2173 if (toolbar_content_is_placeholder (content))
2174 toolbar_content_set_disappearing (content, TRUE);
2179 physical_to_logical (GtkToolbar *toolbar,
2182 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2186 g_assert (physical >= 0);
2189 for (list = priv->content; list && physical > 0; list = list->next)
2191 ToolbarContent *content = list->data;
2193 if (!toolbar_content_is_placeholder (content))
2198 g_assert (physical == 0);
2204 logical_to_physical (GtkToolbar *toolbar,
2207 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2211 g_assert (logical >= 0);
2214 for (list = priv->content; list; list = list->next)
2216 ToolbarContent *content = list->data;
2218 if (!toolbar_content_is_placeholder (content))
2228 g_assert (logical == 0);
2234 * gtk_toolbar_set_drop_highlight_item:
2235 * @toolbar: a #GtkToolbar
2236 * @tool_item: a #GtkToolItem, or %NULL to turn of highlighting
2237 * @index_: a position on @toolbar
2239 * Highlights @toolbar to give an idea of what it would look like
2240 * if @item was added to @toolbar at the position indicated by @index_.
2241 * If @item is %NULL, highlighting is turned off. In that case @index_
2244 * The @tool_item passed to this function must not be part of any widget
2245 * hierarchy. When an item is set as drop highlight item it can not
2246 * added to any widget hierarchy or used as highlight item for another
2252 gtk_toolbar_set_drop_highlight_item (GtkToolbar *toolbar,
2253 GtkToolItem *tool_item,
2256 ToolbarContent *content;
2257 GtkToolbarPrivate *priv;
2259 GtkRequisition requisition;
2260 GtkRequisition old_requisition;
2261 gboolean restart_sliding;
2263 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2264 g_return_if_fail (tool_item == NULL || GTK_IS_TOOL_ITEM (tool_item));
2266 gtk_toolbar_check_new_api (toolbar);
2268 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2272 if (priv->highlight_tool_item)
2274 gtk_widget_unparent (GTK_WIDGET (priv->highlight_tool_item));
2275 g_object_unref (priv->highlight_tool_item);
2276 priv->highlight_tool_item = NULL;
2279 reset_all_placeholders (toolbar);
2280 gtk_toolbar_begin_sliding (toolbar);
2284 n_items = gtk_toolbar_get_n_items (toolbar);
2285 if (index_ < 0 || index_ > n_items)
2288 if (tool_item != priv->highlight_tool_item)
2290 if (priv->highlight_tool_item)
2291 g_object_unref (priv->highlight_tool_item);
2293 g_object_ref_sink (tool_item);
2295 priv->highlight_tool_item = tool_item;
2297 gtk_widget_set_parent (GTK_WIDGET (priv->highlight_tool_item),
2298 GTK_WIDGET (toolbar));
2301 index_ = logical_to_physical (toolbar, index_);
2303 content = g_list_nth_data (priv->content, index_);
2307 ToolbarContent *prev_content;
2309 prev_content = g_list_nth_data (priv->content, index_ - 1);
2311 if (prev_content && toolbar_content_is_placeholder (prev_content))
2312 content = prev_content;
2315 if (!content || !toolbar_content_is_placeholder (content))
2317 GtkWidget *placeholder;
2319 placeholder = GTK_WIDGET (gtk_separator_tool_item_new ());
2321 content = toolbar_content_new_tool_item (toolbar,
2322 GTK_TOOL_ITEM (placeholder),
2324 gtk_widget_show (placeholder);
2328 g_assert (toolbar_content_is_placeholder (content));
2330 gtk_widget_size_request (GTK_WIDGET (priv->highlight_tool_item),
2333 toolbar_content_set_expand (content, gtk_tool_item_get_expand (tool_item));
2335 restart_sliding = FALSE;
2336 toolbar_content_size_request (content, toolbar, &old_requisition);
2337 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
2339 requisition.height = -1;
2340 if (requisition.width != old_requisition.width)
2341 restart_sliding = TRUE;
2345 requisition.width = -1;
2346 if (requisition.height != old_requisition.height)
2347 restart_sliding = TRUE;
2350 if (toolbar_content_disappearing (content))
2351 restart_sliding = TRUE;
2353 reset_all_placeholders (toolbar);
2354 toolbar_content_set_disappearing (content, FALSE);
2356 toolbar_content_set_size_request (content,
2357 requisition.width, requisition.height);
2359 if (restart_sliding)
2360 gtk_toolbar_begin_sliding (toolbar);
2364 gtk_toolbar_get_child_property (GtkContainer *container,
2370 GtkToolItem *item = GTK_TOOL_ITEM (child);
2372 switch (property_id)
2374 case CHILD_PROP_HOMOGENEOUS:
2375 g_value_set_boolean (value, gtk_tool_item_get_homogeneous (item));
2378 case CHILD_PROP_EXPAND:
2379 g_value_set_boolean (value, gtk_tool_item_get_expand (item));
2383 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
2389 gtk_toolbar_set_child_property (GtkContainer *container,
2392 const GValue *value,
2395 switch (property_id)
2397 case CHILD_PROP_HOMOGENEOUS:
2398 gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (child), g_value_get_boolean (value));
2401 case CHILD_PROP_EXPAND:
2402 gtk_tool_item_set_expand (GTK_TOOL_ITEM (child), g_value_get_boolean (value));
2406 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
2412 gtk_toolbar_show_all (GtkWidget *widget)
2414 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
2417 for (list = priv->content; list != NULL; list = list->next)
2419 ToolbarContent *content = list->data;
2421 toolbar_content_show_all (content);
2424 gtk_widget_show (widget);
2428 gtk_toolbar_hide_all (GtkWidget *widget)
2430 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
2433 for (list = priv->content; list != NULL; list = list->next)
2435 ToolbarContent *content = list->data;
2437 toolbar_content_hide_all (content);
2440 gtk_widget_hide (widget);
2444 gtk_toolbar_add (GtkContainer *container,
2447 GtkToolbar *toolbar;
2449 g_return_if_fail (GTK_IS_TOOLBAR (container));
2450 g_return_if_fail (widget != NULL);
2452 toolbar = GTK_TOOLBAR (container);
2454 if (GTK_IS_TOOL_ITEM (widget))
2455 gtk_toolbar_insert (toolbar, GTK_TOOL_ITEM (widget), -1);
2457 gtk_toolbar_append_widget (toolbar, widget, NULL, NULL);
2461 gtk_toolbar_remove (GtkContainer *container,
2464 GtkToolbar *toolbar;
2465 GtkToolbarPrivate *priv;
2466 ToolbarContent *content_to_remove;
2469 g_return_if_fail (GTK_IS_TOOLBAR (container));
2470 g_return_if_fail (GTK_IS_WIDGET (widget));
2472 toolbar = GTK_TOOLBAR (container);
2473 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2475 content_to_remove = NULL;
2476 for (list = priv->content; list != NULL; list = list->next)
2478 ToolbarContent *content = list->data;
2481 child = toolbar_content_get_widget (content);
2482 if (child && child == widget)
2484 content_to_remove = content;
2489 g_return_if_fail (content_to_remove != NULL);
2491 toolbar_content_remove (content_to_remove, toolbar);
2492 toolbar_content_free (content_to_remove);
2496 gtk_toolbar_forall (GtkContainer *container,
2497 gboolean include_internals,
2498 GtkCallback callback,
2499 gpointer callback_data)
2501 GtkToolbar *toolbar = GTK_TOOLBAR (container);
2502 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2505 g_return_if_fail (callback != NULL);
2507 list = priv->content;
2510 ToolbarContent *content = list->data;
2511 GList *next = list->next;
2513 if (include_internals || !toolbar_content_is_placeholder (content))
2515 GtkWidget *child = toolbar_content_get_widget (content);
2518 (*callback) (child, callback_data);
2524 if (include_internals)
2525 (* callback) (priv->arrow_button, callback_data);
2529 gtk_toolbar_child_type (GtkContainer *container)
2531 return GTK_TYPE_TOOL_ITEM;
2535 gtk_toolbar_reconfigured (GtkToolbar *toolbar)
2537 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2540 list = priv->content;
2543 ToolbarContent *content = list->data;
2544 GList *next = list->next;
2546 toolbar_content_toolbar_reconfigured (content, toolbar);
2553 gtk_toolbar_orientation_changed (GtkToolbar *toolbar,
2554 GtkOrientation orientation)
2556 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2557 if (toolbar->orientation != orientation)
2559 toolbar->orientation = orientation;
2561 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2562 gtk_arrow_set (GTK_ARROW (priv->arrow), GTK_ARROW_DOWN, GTK_SHADOW_NONE);
2564 gtk_arrow_set (GTK_ARROW (priv->arrow), GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
2566 gtk_toolbar_reconfigured (toolbar);
2568 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
2569 g_object_notify (G_OBJECT (toolbar), "orientation");
2574 gtk_toolbar_real_style_changed (GtkToolbar *toolbar,
2575 GtkToolbarStyle style)
2577 if (toolbar->style != style)
2579 toolbar->style = style;
2581 gtk_toolbar_reconfigured (toolbar);
2583 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
2584 g_object_notify (G_OBJECT (toolbar), "toolbar-style");
2589 menu_position_func (GtkMenu *menu,
2595 GtkToolbar *toolbar = GTK_TOOLBAR (user_data);
2596 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2598 GtkRequisition menu_req;
2599 GdkRectangle monitor;
2603 gtk_widget_size_request (priv->arrow_button, &req);
2604 gtk_widget_size_request (GTK_WIDGET (menu), &menu_req);
2606 screen = gtk_widget_get_screen (GTK_WIDGET (menu));
2607 monitor_num = gdk_screen_get_monitor_at_window (screen, priv->arrow_button->window);
2608 if (monitor_num < 0)
2610 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
2612 gdk_window_get_origin (GTK_BUTTON (priv->arrow_button)->event_window, x, y);
2613 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
2615 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
2616 *x += priv->arrow_button->allocation.width - req.width;
2618 *x += req.width - menu_req.width;
2620 if ((*y + priv->arrow_button->allocation.height + menu_req.height) <= monitor.y + monitor.height)
2621 *y += priv->arrow_button->allocation.height;
2622 else if ((*y - menu_req.height) >= monitor.y)
2623 *y -= menu_req.height;
2624 else if (monitor.y + monitor.height - (*y + priv->arrow_button->allocation.height) > *y)
2625 *y += priv->arrow_button->allocation.height;
2627 *y -= menu_req.height;
2631 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
2632 *x += priv->arrow_button->allocation.width;
2634 *x -= menu_req.width;
2636 if (*y + menu_req.height > monitor.y + monitor.height &&
2637 *y + priv->arrow_button->allocation.height - monitor.y > monitor.y + monitor.height - *y)
2638 *y += priv->arrow_button->allocation.height - menu_req.height;
2645 show_menu (GtkToolbar *toolbar,
2646 GdkEventButton *event)
2648 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2650 rebuild_menu (toolbar);
2652 gtk_widget_show_all (GTK_WIDGET (priv->menu));
2654 gtk_menu_popup (priv->menu, NULL, NULL,
2655 menu_position_func, toolbar,
2656 event? event->button : 0,
2657 event? event->time : gtk_get_current_event_time());
2661 gtk_toolbar_arrow_button_clicked (GtkWidget *button,
2662 GtkToolbar *toolbar)
2664 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2666 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->arrow_button)) &&
2667 (!priv->menu || !GTK_WIDGET_VISIBLE (priv->menu)))
2669 /* We only get here when the button is clicked with the keyboard,
2670 * because mouse button presses result in the menu being shown so
2671 * that priv->menu would be non-NULL and visible.
2673 show_menu (toolbar, NULL);
2674 gtk_menu_shell_select_first (GTK_MENU_SHELL (priv->menu), FALSE);
2679 gtk_toolbar_arrow_button_press (GtkWidget *button,
2680 GdkEventButton *event,
2681 GtkToolbar *toolbar)
2683 show_menu (toolbar, event);
2684 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
2690 gtk_toolbar_button_press (GtkWidget *toolbar,
2691 GdkEventButton *event)
2693 if (event->button == 3)
2695 gboolean return_value;
2697 g_signal_emit (toolbar, toolbar_signals[POPUP_CONTEXT_MENU], 0,
2698 (int)event->x_root, (int)event->y_root, event->button,
2701 return return_value;
2708 gtk_toolbar_popup_menu (GtkWidget *toolbar)
2710 gboolean return_value;
2711 /* This function is the handler for the "popup menu" keybinding,
2712 * ie., it is called when the user presses Shift F10
2714 g_signal_emit (toolbar, toolbar_signals[POPUP_CONTEXT_MENU], 0,
2715 -1, -1, -1, &return_value);
2717 return return_value;
2723 * Creates a new toolbar.
2725 * Return Value: the newly-created toolbar.
2728 gtk_toolbar_new (void)
2730 GtkToolbar *toolbar;
2732 toolbar = g_object_new (GTK_TYPE_TOOLBAR, NULL);
2734 return GTK_WIDGET (toolbar);
2738 * gtk_toolbar_insert:
2739 * @toolbar: a #GtkToolbar
2740 * @item: a #GtkToolItem
2741 * @pos: the position of the new item
2743 * Insert a #GtkToolItem into the toolbar at position @pos. If @pos is
2744 * 0 the item is prepended to the start of the toolbar. If @pos is
2745 * negative, the item is appended to the end of the toolbar.
2750 gtk_toolbar_insert (GtkToolbar *toolbar,
2754 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2755 g_return_if_fail (GTK_IS_TOOL_ITEM (item));
2757 if (!gtk_toolbar_check_new_api (toolbar))
2761 pos = logical_to_physical (toolbar, pos);
2763 toolbar_content_new_tool_item (toolbar, item, FALSE, pos);
2767 * gtk_toolbar_get_item_index:
2768 * @toolbar: a #GtkToolbar
2769 * @item: a #GtkToolItem that is a child of @toolbar
2771 * Returns the position of @item on the toolbar, starting from 0.
2772 * It is an error if @item is not a child of the toolbar.
2774 * Return value: the position of item on the toolbar.
2779 gtk_toolbar_get_item_index (GtkToolbar *toolbar,
2782 GtkToolbarPrivate *priv;
2786 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
2787 g_return_val_if_fail (GTK_IS_TOOL_ITEM (item), -1);
2788 g_return_val_if_fail (GTK_WIDGET (item)->parent == GTK_WIDGET (toolbar), -1);
2790 if (!gtk_toolbar_check_new_api (toolbar))
2793 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2796 for (list = priv->content; list != NULL; list = list->next)
2798 ToolbarContent *content = list->data;
2801 widget = toolbar_content_get_widget (content);
2803 if (item == GTK_TOOL_ITEM (widget))
2809 return physical_to_logical (toolbar, n);
2813 * gtk_toolbar_set_orientation:
2814 * @toolbar: a #GtkToolbar.
2815 * @orientation: a new #GtkOrientation.
2817 * Sets whether a toolbar should appear horizontally or vertically.
2820 gtk_toolbar_set_orientation (GtkToolbar *toolbar,
2821 GtkOrientation orientation)
2823 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2825 g_signal_emit (toolbar, toolbar_signals[ORIENTATION_CHANGED], 0, orientation);
2829 * gtk_toolbar_get_orientation:
2830 * @toolbar: a #GtkToolbar
2832 * Retrieves the current orientation of the toolbar. See
2833 * gtk_toolbar_set_orientation().
2835 * Return value: the orientation
2838 gtk_toolbar_get_orientation (GtkToolbar *toolbar)
2840 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), GTK_ORIENTATION_HORIZONTAL);
2842 return toolbar->orientation;
2846 * gtk_toolbar_set_style:
2847 * @toolbar: a #GtkToolbar.
2848 * @style: the new style for @toolbar.
2850 * Alters the view of @toolbar to display either icons only, text only, or both.
2853 gtk_toolbar_set_style (GtkToolbar *toolbar,
2854 GtkToolbarStyle style)
2856 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2858 toolbar->style_set = TRUE;
2859 g_signal_emit (toolbar, toolbar_signals[STYLE_CHANGED], 0, style);
2863 * gtk_toolbar_get_style:
2864 * @toolbar: a #GtkToolbar
2866 * Retrieves whether the toolbar has text, icons, or both . See
2867 * gtk_toolbar_set_style().
2869 * Return value: the current style of @toolbar
2872 gtk_toolbar_get_style (GtkToolbar *toolbar)
2874 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), DEFAULT_TOOLBAR_STYLE);
2876 return toolbar->style;
2880 * gtk_toolbar_unset_style:
2881 * @toolbar: a #GtkToolbar
2883 * Unsets a toolbar style set with gtk_toolbar_set_style(), so that
2884 * user preferences will be used to determine the toolbar style.
2887 gtk_toolbar_unset_style (GtkToolbar *toolbar)
2889 GtkToolbarStyle style;
2891 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2893 if (toolbar->style_set)
2895 GtkSettings *settings = toolbar_get_settings (toolbar);
2898 g_object_get (settings,
2899 "gtk-toolbar-style", &style,
2902 style = DEFAULT_TOOLBAR_STYLE;
2904 if (style != toolbar->style)
2905 g_signal_emit (toolbar, toolbar_signals[STYLE_CHANGED], 0, style);
2907 toolbar->style_set = FALSE;
2912 * gtk_toolbar_set_tooltips:
2913 * @toolbar: a #GtkToolbar.
2914 * @enable: set to %FALSE to disable the tooltips, or %TRUE to enable them.
2916 * Sets if the tooltips of a toolbar should be active or not.
2919 gtk_toolbar_set_tooltips (GtkToolbar *toolbar,
2922 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2925 gtk_tooltips_enable (toolbar->tooltips);
2927 gtk_tooltips_disable (toolbar->tooltips);
2929 g_object_notify (G_OBJECT (toolbar), "tooltips");
2933 * gtk_toolbar_get_tooltips:
2934 * @toolbar: a #GtkToolbar
2936 * Retrieves whether tooltips are enabled. See
2937 * gtk_toolbar_set_tooltips().
2939 * Return value: %TRUE if tooltips are enabled
2942 gtk_toolbar_get_tooltips (GtkToolbar *toolbar)
2944 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), FALSE);
2946 return toolbar->tooltips->enabled;
2950 * gtk_toolbar_get_n_items:
2951 * @toolbar: a #GtkToolbar
2953 * Returns the number of items on the toolbar.
2955 * Return value: the number of items on the toolbar
2960 gtk_toolbar_get_n_items (GtkToolbar *toolbar)
2962 GtkToolbarPrivate *priv;
2964 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
2966 if (!gtk_toolbar_check_new_api (toolbar))
2969 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2971 return physical_to_logical (toolbar, g_list_length (priv->content));
2975 * gtk_toolbar_get_nth_item:
2976 * @toolbar: a #GtkToolbar
2977 * @n: A position on the toolbar
2979 * Returns the @n<!-- -->'th item on @toolbar, or %NULL if the
2980 * toolbar does not contain an @n<!-- -->'th item.
2982 * Return value: The @n<!-- -->'th #GtkToolItem on @toolbar, or %NULL if there
2983 * isn't an @n<!-- -->'th item.
2988 gtk_toolbar_get_nth_item (GtkToolbar *toolbar,
2991 GtkToolbarPrivate *priv;
2992 ToolbarContent *content;
2995 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), NULL);
2997 if (!gtk_toolbar_check_new_api (toolbar))
3000 n_items = gtk_toolbar_get_n_items (toolbar);
3002 if (n < 0 || n >= n_items)
3005 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3007 content = g_list_nth_data (priv->content, logical_to_physical (toolbar, n));
3010 g_assert (!toolbar_content_is_placeholder (content));
3012 return GTK_TOOL_ITEM (toolbar_content_get_widget (content));
3016 * gtk_toolbar_get_icon_size:
3017 * @toolbar: a #GtkToolbar
3019 * Retrieves the icon size for the toolbar. See gtk_toolbar_set_icon_size().
3021 * Return value: the current icon size for the icons on the toolbar.
3024 gtk_toolbar_get_icon_size (GtkToolbar *toolbar)
3026 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), DEFAULT_ICON_SIZE);
3028 return toolbar->icon_size;
3032 * gtk_toolbar_get_relief_style:
3033 * @toolbar: a #GtkToolbar
3035 * Returns the relief style of buttons on @toolbar. See
3036 * gtk_button_set_relief().
3038 * Return value: The relief style of buttons on @toolbar.
3043 gtk_toolbar_get_relief_style (GtkToolbar *toolbar)
3045 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), GTK_RELIEF_NONE);
3047 return get_button_relief (toolbar);
3051 * gtk_toolbar_set_show_arrow:
3052 * @toolbar: a #GtkToolbar
3053 * @show_arrow: Whether to show an overflow menu
3055 * Sets whether to show an overflow menu when
3056 * @toolbar doesn't have room for all items on it. If %TRUE,
3057 * items that there are not room are available through an
3063 gtk_toolbar_set_show_arrow (GtkToolbar *toolbar,
3064 gboolean show_arrow)
3066 GtkToolbarPrivate *priv;
3068 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3070 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3071 show_arrow = show_arrow != FALSE;
3073 if (priv->show_arrow != show_arrow)
3075 priv->show_arrow = show_arrow;
3077 if (!priv->show_arrow)
3078 gtk_widget_hide (priv->arrow_button);
3080 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3081 g_object_notify (G_OBJECT (toolbar), "show-arrow");
3086 * gtk_toolbar_get_show_arrow:
3087 * @toolbar: a #GtkToolbar
3089 * Returns whether the toolbar has an overflow menu.
3090 * See gtk_toolbar_set_show_arrow().
3092 * Return value: %TRUE if the toolbar has an overflow menu.
3097 gtk_toolbar_get_show_arrow (GtkToolbar *toolbar)
3099 GtkToolbarPrivate *priv;
3101 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), FALSE);
3103 if (!gtk_toolbar_check_new_api (toolbar))
3106 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3108 return priv->show_arrow;
3112 * gtk_toolbar_get_drop_index:
3113 * @toolbar: a #GtkToolbar
3114 * @x: x coordinate of a point on the toolbar
3115 * @y: y coordinate of a point on the toolbar
3117 * Returns the position corresponding to the indicated point on
3118 * @toolbar. This is useful when dragging items to the toolbar:
3119 * this function returns the position a new item should be
3122 * @x and @y are in @toolbar coordinates.
3124 * Return value: The position corresponding to the point (@x, @y) on the toolbar.
3129 gtk_toolbar_get_drop_index (GtkToolbar *toolbar,
3133 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
3135 if (!gtk_toolbar_check_new_api (toolbar))
3138 return physical_to_logical (toolbar, find_drop_index (toolbar, x, y));
3142 gtk_toolbar_finalize (GObject *object)
3145 GtkToolbar *toolbar = GTK_TOOLBAR (object);
3146 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3148 if (toolbar->tooltips)
3149 g_object_unref (toolbar->tooltips);
3151 if (priv->arrow_button)
3152 gtk_widget_unparent (priv->arrow_button);
3154 for (list = priv->content; list != NULL; list = list->next)
3156 ToolbarContent *content = list->data;
3158 toolbar_content_free (content);
3161 g_list_free (priv->content);
3162 g_list_free (toolbar->children);
3164 g_timer_destroy (priv->timer);
3167 gtk_widget_destroy (GTK_WIDGET (priv->menu));
3170 g_source_remove (priv->idle_id);
3172 G_OBJECT_CLASS (gtk_toolbar_parent_class)->finalize (object);
3176 * gtk_toolbar_set_icon_size:
3177 * @toolbar: A #GtkToolbar
3178 * @icon_size: The #GtkIconSize that stock icons in the toolbar shall have.
3180 * This function sets the size of stock icons in the toolbar. You
3181 * can call it both before you add the icons and after they've been
3182 * added. The size you set will override user preferences for the default
3185 * This should only be used for special-purpose toolbars, normal
3186 * application toolbars should respect the user preferences for the
3190 gtk_toolbar_set_icon_size (GtkToolbar *toolbar,
3191 GtkIconSize icon_size)
3193 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3194 g_return_if_fail (icon_size != GTK_ICON_SIZE_INVALID);
3196 if (!toolbar->icon_size_set)
3198 toolbar->icon_size_set = TRUE;
3199 g_object_notify (G_OBJECT (toolbar), "icon-size-set");
3202 if (toolbar->icon_size == icon_size)
3205 toolbar->icon_size = icon_size;
3206 g_object_notify (G_OBJECT (toolbar), "icon-size");
3208 gtk_toolbar_reconfigured (toolbar);
3210 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3214 * gtk_toolbar_unset_icon_size:
3215 * @toolbar: a #GtkToolbar
3217 * Unsets toolbar icon size set with gtk_toolbar_set_icon_size(), so that
3218 * user preferences will be used to determine the icon size.
3221 gtk_toolbar_unset_icon_size (GtkToolbar *toolbar)
3225 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3227 if (toolbar->icon_size_set)
3229 GtkSettings *settings = toolbar_get_settings (toolbar);
3233 g_object_get (settings,
3234 "gtk-toolbar-icon-size", &size,
3238 size = DEFAULT_ICON_SIZE;
3240 if (size != toolbar->icon_size)
3242 gtk_toolbar_set_icon_size (toolbar, size);
3243 g_object_notify (G_OBJECT (toolbar), "icon-size");
3246 toolbar->icon_size_set = FALSE;
3247 g_object_notify (G_OBJECT (toolbar), "icon-size-set");
3256 * gtk_toolbar_append_item:
3257 * @toolbar: a #GtkToolbar.
3258 * @text: give your toolbar button a label.
3259 * @tooltip_text: a string that appears when the user holds the mouse over this item.
3260 * @tooltip_private_text: use with #GtkTipsQuery.
3261 * @icon: a #GtkWidget that should be used as the button's icon.
3262 * @callback: the function to be executed when the button is pressed.
3263 * @user_data: a pointer to any data you wish to be passed to the callback.
3265 * Inserts a new item into the toolbar. You must specify the position
3266 * in the toolbar where it will be inserted.
3268 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3269 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3271 * Return value: the new toolbar item as a #GtkWidget.
3274 gtk_toolbar_append_item (GtkToolbar *toolbar,
3276 const char *tooltip_text,
3277 const char *tooltip_private_text,
3279 GtkSignalFunc callback,
3282 return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
3284 tooltip_text, tooltip_private_text,
3285 icon, callback, user_data,
3286 toolbar->num_children);
3290 * gtk_toolbar_prepend_item:
3291 * @toolbar: a #GtkToolbar.
3292 * @text: give your toolbar button a label.
3293 * @tooltip_text: a string that appears when the user holds the mouse over this item.
3294 * @tooltip_private_text: use with #GtkTipsQuery.
3295 * @icon: a #GtkWidget that should be used as the button's icon.
3296 * @callback: the function to be executed when the button is pressed.
3297 * @user_data: a pointer to any data you wish to be passed to the callback.
3299 * Adds a new button to the beginning (top or left edges) of the given toolbar.
3301 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3302 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3304 * Return value: the new toolbar item as a #GtkWidget.
3307 gtk_toolbar_prepend_item (GtkToolbar *toolbar,
3309 const char *tooltip_text,
3310 const char *tooltip_private_text,
3312 GtkSignalFunc callback,
3315 return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
3317 tooltip_text, tooltip_private_text,
3318 icon, callback, user_data,
3323 * gtk_toolbar_insert_item:
3324 * @toolbar: a #GtkToolbar.
3325 * @text: give your toolbar button a label.
3326 * @tooltip_text: a string that appears when the user holds the mouse over this item.
3327 * @tooltip_private_text: use with #GtkTipsQuery.
3328 * @icon: a #GtkWidget that should be used as the button's icon.
3329 * @callback: the function to be executed when the button is pressed.
3330 * @user_data: a pointer to any data you wish to be passed to the callback.
3331 * @position: the number of widgets to insert this item after.
3333 * Inserts a new item into the toolbar. You must specify the position in the
3334 * toolbar where it will be inserted.
3336 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3337 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3339 * Return value: the new toolbar item as a #GtkWidget.
3342 gtk_toolbar_insert_item (GtkToolbar *toolbar,
3344 const char *tooltip_text,
3345 const char *tooltip_private_text,
3347 GtkSignalFunc callback,
3351 return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
3353 tooltip_text, tooltip_private_text,
3354 icon, callback, user_data,
3359 * gtk_toolbar_insert_stock:
3360 * @toolbar: A #GtkToolbar
3361 * @stock_id: The id of the stock item you want to insert
3362 * @tooltip_text: The text in the tooltip of the toolbar button
3363 * @tooltip_private_text: The private text of the tooltip
3364 * @callback: The callback called when the toolbar button is clicked.
3365 * @user_data: user data passed to callback
3366 * @position: The position the button shall be inserted at.
3367 * -1 means at the end.
3369 * Inserts a stock item at the specified position of the toolbar. If
3370 * @stock_id is not a known stock item ID, it's inserted verbatim,
3371 * except that underscores used to mark mnemonics are removed.
3373 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3374 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3376 * Returns: the inserted widget
3379 gtk_toolbar_insert_stock (GtkToolbar *toolbar,
3380 const gchar *stock_id,
3381 const char *tooltip_text,
3382 const char *tooltip_private_text,
3383 GtkSignalFunc callback,
3387 return internal_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
3389 tooltip_text, tooltip_private_text,
3390 NULL, callback, user_data,
3395 * gtk_toolbar_append_space:
3396 * @toolbar: a #GtkToolbar.
3398 * Adds a new space to the end of the toolbar.
3401 gtk_toolbar_append_space (GtkToolbar *toolbar)
3403 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_SPACE,
3407 toolbar->num_children);
3411 * gtk_toolbar_prepend_space:
3412 * @toolbar: a #GtkToolbar.
3414 * Adds a new space to the beginning of the toolbar.
3417 gtk_toolbar_prepend_space (GtkToolbar *toolbar)
3419 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_SPACE,
3427 * gtk_toolbar_insert_space:
3428 * @toolbar: a #GtkToolbar
3429 * @position: the number of widgets after which a space should be inserted.
3431 * Inserts a new space in the toolbar at the specified position.
3434 gtk_toolbar_insert_space (GtkToolbar *toolbar,
3437 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_SPACE,
3445 * gtk_toolbar_remove_space:
3446 * @toolbar: a #GtkToolbar.
3447 * @position: the index of the space to remove.
3449 * Removes a space from the specified position.
3452 gtk_toolbar_remove_space (GtkToolbar *toolbar,
3455 GtkToolbarPrivate *priv;
3456 ToolbarContent *content;
3458 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3460 if (!gtk_toolbar_check_old_api (toolbar))
3463 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3465 content = g_list_nth_data (priv->content, position);
3469 g_warning ("Toolbar position %d doesn't exist", position);
3473 if (!toolbar_content_is_separator (content))
3475 g_warning ("Toolbar position %d is not a space", position);
3479 toolbar_content_remove (content, toolbar);
3480 toolbar_content_free (content);
3484 * gtk_toolbar_append_widget:
3485 * @toolbar: a #GtkToolbar.
3486 * @widget: a #GtkWidget to add to the toolbar.
3487 * @tooltip_text: the element's tooltip.
3488 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3490 * Adds a widget to the end of the given toolbar.
3493 gtk_toolbar_append_widget (GtkToolbar *toolbar,
3495 const gchar *tooltip_text,
3496 const gchar *tooltip_private_text)
3498 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_WIDGET,
3500 tooltip_text, tooltip_private_text,
3502 toolbar->num_children);
3506 * gtk_toolbar_prepend_widget:
3507 * @toolbar: a #GtkToolbar.
3508 * @widget: a #GtkWidget to add to the toolbar.
3509 * @tooltip_text: the element's tooltip.
3510 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3512 * Adds a widget to the beginning of the given toolbar.
3515 gtk_toolbar_prepend_widget (GtkToolbar *toolbar,
3517 const gchar *tooltip_text,
3518 const gchar *tooltip_private_text)
3520 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_WIDGET,
3522 tooltip_text, tooltip_private_text,
3528 * gtk_toolbar_insert_widget:
3529 * @toolbar: a #GtkToolbar.
3530 * @widget: a #GtkWidget to add to the toolbar.
3531 * @tooltip_text: the element's tooltip.
3532 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3533 * @position: the number of widgets to insert this widget after.
3535 * Inserts a widget in the toolbar at the given position.
3538 gtk_toolbar_insert_widget (GtkToolbar *toolbar,
3540 const char *tooltip_text,
3541 const char *tooltip_private_text,
3544 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_WIDGET,
3546 tooltip_text, tooltip_private_text,
3552 * gtk_toolbar_append_element:
3553 * @toolbar: a #GtkToolbar.
3554 * @type: a value of type #GtkToolbarChildType that determines what @widget will be.
3555 * @widget: a #GtkWidget, or %NULL.
3556 * @text: the element's label.
3557 * @tooltip_text: the element's tooltip.
3558 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3559 * @icon: a #GtkWidget that provides pictorial representation of the element's function.
3560 * @callback: the function to be executed when the button is pressed.
3561 * @user_data: any data you wish to pass to the callback.
3563 * Adds a new element to the end of a toolbar.
3565 * If @type == %GTK_TOOLBAR_CHILD_WIDGET, @widget is used as the new element.
3566 * If @type == %GTK_TOOLBAR_CHILD_RADIOBUTTON, @widget is used to determine
3567 * the radio group for the new element. In all other cases, @widget must
3570 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3571 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3573 * Return value: the new toolbar element as a #GtkWidget.
3576 gtk_toolbar_append_element (GtkToolbar *toolbar,
3577 GtkToolbarChildType type,
3580 const char *tooltip_text,
3581 const char *tooltip_private_text,
3583 GtkSignalFunc callback,
3586 return gtk_toolbar_insert_element (toolbar, type, widget, text,
3587 tooltip_text, tooltip_private_text,
3588 icon, callback, user_data,
3589 toolbar->num_children);
3593 * gtk_toolbar_prepend_element:
3594 * @toolbar: a #GtkToolbar.
3595 * @type: a value of type #GtkToolbarChildType that determines what @widget will be.
3596 * @widget: a #GtkWidget, or %NULL
3597 * @text: the element's label.
3598 * @tooltip_text: the element's tooltip.
3599 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3600 * @icon: a #GtkWidget that provides pictorial representation of the element's function.
3601 * @callback: the function to be executed when the button is pressed.
3602 * @user_data: any data you wish to pass to the callback.
3604 * Adds a new element to the beginning of a toolbar.
3606 * If @type == %GTK_TOOLBAR_CHILD_WIDGET, @widget is used as the new element.
3607 * If @type == %GTK_TOOLBAR_CHILD_RADIOBUTTON, @widget is used to determine
3608 * the radio group for the new element. In all other cases, @widget must
3611 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3612 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3614 * Return value: the new toolbar element as a #GtkWidget.
3617 gtk_toolbar_prepend_element (GtkToolbar *toolbar,
3618 GtkToolbarChildType type,
3621 const char *tooltip_text,
3622 const char *tooltip_private_text,
3624 GtkSignalFunc callback,
3627 return gtk_toolbar_insert_element (toolbar, type, widget, text,
3628 tooltip_text, tooltip_private_text,
3629 icon, callback, user_data, 0);
3633 * gtk_toolbar_insert_element:
3634 * @toolbar: a #GtkToolbar.
3635 * @type: a value of type #GtkToolbarChildType that determines what @widget
3637 * @widget: a #GtkWidget, or %NULL.
3638 * @text: the element's label.
3639 * @tooltip_text: the element's tooltip.
3640 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3641 * @icon: a #GtkWidget that provides pictorial representation of the element's function.
3642 * @callback: the function to be executed when the button is pressed.
3643 * @user_data: any data you wish to pass to the callback.
3644 * @position: the number of widgets to insert this element after.
3646 * Inserts a new element in the toolbar at the given position.
3648 * If @type == %GTK_TOOLBAR_CHILD_WIDGET, @widget is used as the new element.
3649 * If @type == %GTK_TOOLBAR_CHILD_RADIOBUTTON, @widget is used to determine
3650 * the radio group for the new element. In all other cases, @widget must
3653 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3654 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3656 * Return value: the new toolbar element as a #GtkWidget.
3659 gtk_toolbar_insert_element (GtkToolbar *toolbar,
3660 GtkToolbarChildType type,
3663 const char *tooltip_text,
3664 const char *tooltip_private_text,
3666 GtkSignalFunc callback,
3670 return internal_insert_element (toolbar, type, widget, text,
3671 tooltip_text, tooltip_private_text,
3672 icon, callback, user_data, position, FALSE);
3676 set_child_packing_and_visibility(GtkToolbar *toolbar,
3677 GtkToolbarChild *child)
3682 box = gtk_bin_get_child (GTK_BIN (child->widget));
3684 g_return_if_fail (GTK_IS_BOX (box));
3688 expand = (toolbar->style != GTK_TOOLBAR_BOTH);
3690 gtk_box_set_child_packing (GTK_BOX (box), child->label,
3691 expand, expand, 0, GTK_PACK_END);
3693 if (toolbar->style != GTK_TOOLBAR_ICONS)
3694 gtk_widget_show (child->label);
3696 gtk_widget_hide (child->label);
3701 expand = (toolbar->style != GTK_TOOLBAR_BOTH_HORIZ);
3703 gtk_box_set_child_packing (GTK_BOX (box), child->icon,
3704 expand, expand, 0, GTK_PACK_END);
3706 if (toolbar->style != GTK_TOOLBAR_TEXT)
3707 gtk_widget_show (child->icon);
3709 gtk_widget_hide (child->icon);
3714 internal_insert_element (GtkToolbar *toolbar,
3715 GtkToolbarChildType type,
3718 const char *tooltip_text,
3719 const char *tooltip_private_text,
3721 GtkSignalFunc callback,
3727 ToolbarContent *content;
3728 char *free_me = NULL;
3730 GtkWidget *child_widget;
3731 GtkWidget *child_label;
3732 GtkWidget *child_icon;
3734 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), NULL);
3735 if (type == GTK_TOOLBAR_CHILD_WIDGET)
3736 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3737 else if (type != GTK_TOOLBAR_CHILD_RADIOBUTTON)
3738 g_return_val_if_fail (widget == NULL, NULL);
3739 if (GTK_IS_TOOL_ITEM (widget))
3740 g_warning (MIXED_API_WARNING);
3742 if (!gtk_toolbar_check_old_api (toolbar))
3745 child_widget = NULL;
3751 case GTK_TOOLBAR_CHILD_SPACE:
3754 case GTK_TOOLBAR_CHILD_WIDGET:
3755 child_widget = widget;
3758 case GTK_TOOLBAR_CHILD_BUTTON:
3759 case GTK_TOOLBAR_CHILD_TOGGLEBUTTON:
3760 case GTK_TOOLBAR_CHILD_RADIOBUTTON:
3761 if (type == GTK_TOOLBAR_CHILD_BUTTON)
3763 child_widget = gtk_button_new ();
3765 else if (type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
3767 child_widget = gtk_toggle_button_new ();
3768 gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (child_widget), FALSE);
3770 else /* type == GTK_TOOLBAR_CHILD_RADIOBUTTON */
3772 GSList *group = NULL;
3775 group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (widget));
3777 child_widget = gtk_radio_button_new (group);
3778 gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (child_widget), FALSE);
3781 gtk_button_set_relief (GTK_BUTTON (child_widget), get_button_relief (toolbar));
3782 gtk_button_set_focus_on_click (GTK_BUTTON (child_widget), FALSE);
3786 g_signal_connect (child_widget, "clicked",
3787 callback, user_data);
3790 if (toolbar->style == GTK_TOOLBAR_BOTH_HORIZ)
3791 box = gtk_hbox_new (FALSE, 0);
3793 box = gtk_vbox_new (FALSE, 0);
3795 gtk_container_add (GTK_CONTAINER (child_widget), box);
3796 gtk_widget_show (box);
3798 if (text && use_stock)
3800 GtkStockItem stock_item;
3801 if (gtk_stock_lookup (text, &stock_item))
3804 icon = gtk_image_new_from_stock (text, toolbar->icon_size);
3806 text = free_me = _gtk_toolbar_elide_underscores (stock_item.label);
3812 child_label = gtk_label_new (text);
3814 gtk_container_add (GTK_CONTAINER (box), child_label);
3819 child_icon = GTK_WIDGET (icon);
3820 gtk_container_add (GTK_CONTAINER (box), child_icon);
3823 gtk_widget_show (child_widget);
3827 g_assert_not_reached ();
3831 if ((type != GTK_TOOLBAR_CHILD_SPACE) && tooltip_text)
3833 gtk_tooltips_set_tip (toolbar->tooltips, child_widget,
3834 tooltip_text, tooltip_private_text);
3837 content = toolbar_content_new_compatibility (toolbar, type, child_widget,
3838 child_icon, child_label, position);
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;
3914 static ToolbarContent *
3915 toolbar_content_new_compatibility (GtkToolbar *toolbar,
3916 GtkToolbarChildType type,
3922 ToolbarContent *content;
3923 GtkToolbarChild *child;
3924 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3926 content = g_new0 (ToolbarContent, 1);
3928 child = &(content->u.compatibility.child);
3930 content->type = COMPATIBILITY;
3932 child->widget = widget;
3934 child->label = label;
3936 if (type != GTK_TOOLBAR_CHILD_SPACE)
3938 gtk_widget_set_parent (child->widget, GTK_WIDGET (toolbar));
3942 content->u.compatibility.space_visible = TRUE;
3943 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3946 if (type == GTK_TOOLBAR_CHILD_BUTTON ||
3947 type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON ||
3948 type == GTK_TOOLBAR_CHILD_RADIOBUTTON)
3950 set_child_packing_and_visibility (toolbar, child);
3953 priv->content = g_list_insert (priv->content, content, pos);
3954 toolbar->children = g_list_insert (toolbar->children, child, pos);
3955 priv->need_rebuild = TRUE;
3957 toolbar->num_children++;
3963 toolbar_content_remove (ToolbarContent *content,
3964 GtkToolbar *toolbar)
3966 GtkToolbarChild *child;
3967 GtkToolbarPrivate *priv;
3969 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3971 switch (content->type)
3974 gtk_widget_unparent (GTK_WIDGET (content->u.tool_item.item));
3978 child = &(content->u.compatibility.child);
3980 if (child->type != GTK_TOOLBAR_CHILD_SPACE)
3982 g_object_ref (child->widget);
3983 gtk_widget_unparent (child->widget);
3984 gtk_widget_destroy (child->widget);
3985 g_object_unref (child->widget);
3988 toolbar->children = g_list_remove (toolbar->children, child);
3992 priv->content = g_list_remove (priv->content, content);
3994 if (!toolbar_content_is_placeholder (content))
3995 toolbar->num_children--;
3997 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3998 priv->need_rebuild = TRUE;
4002 toolbar_content_free (ToolbarContent *content)
4008 calculate_max_homogeneous_pixels (GtkWidget *widget)
4010 PangoContext *context;
4011 PangoFontMetrics *metrics;
4014 context = gtk_widget_get_pango_context (widget);
4015 metrics = pango_context_get_metrics (context,
4016 widget->style->font_desc,
4017 pango_context_get_language (context));
4018 char_width = pango_font_metrics_get_approximate_char_width (metrics);
4019 pango_font_metrics_unref (metrics);
4021 return PANGO_PIXELS (MAX_HOMOGENEOUS_N_CHARS * char_width);
4025 toolbar_content_expose (ToolbarContent *content,
4026 GtkContainer *container,
4027 GdkEventExpose *expose)
4029 GtkToolbar *toolbar = GTK_TOOLBAR (container);
4030 GtkToolbarChild *child;
4031 GtkWidget *widget = NULL; /* quiet gcc */
4033 switch (content->type)
4036 if (!content->u.tool_item.is_placeholder)
4037 widget = GTK_WIDGET (content->u.tool_item.item);
4041 child = &(content->u.compatibility.child);
4043 if (child->type == GTK_TOOLBAR_CHILD_SPACE)
4045 if (get_space_style (toolbar) == GTK_TOOLBAR_SPACE_LINE &&
4046 content->u.compatibility.space_visible)
4048 _gtk_toolbar_paint_space_line (GTK_WIDGET (toolbar), toolbar,
4050 &content->u.compatibility.space_allocation);
4055 widget = child->widget;
4060 gtk_container_propagate_expose (container, widget, expose);
4064 toolbar_content_visible (ToolbarContent *content,
4065 GtkToolbar *toolbar)
4069 switch (content->type)
4072 item = content->u.tool_item.item;
4074 if (!GTK_WIDGET_VISIBLE (item))
4077 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL &&
4078 gtk_tool_item_get_visible_horizontal (item))
4083 if ((toolbar->orientation == GTK_ORIENTATION_VERTICAL &&
4084 gtk_tool_item_get_visible_vertical (item)))
4093 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
4094 return GTK_WIDGET_VISIBLE (content->u.compatibility.child.widget);
4100 g_assert_not_reached ();
4105 toolbar_content_size_request (ToolbarContent *content,
4106 GtkToolbar *toolbar,
4107 GtkRequisition *requisition)
4111 switch (content->type)
4114 gtk_widget_size_request (GTK_WIDGET (content->u.tool_item.item),
4116 if (content->u.tool_item.is_placeholder &&
4117 content->u.tool_item.disappearing)
4119 requisition->width = 0;
4120 requisition->height = 0;
4125 space_size = get_space_size (toolbar);
4127 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
4129 gtk_widget_size_request (content->u.compatibility.child.widget,
4134 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
4136 requisition->width = space_size;
4137 requisition->height = 0;
4141 requisition->height = space_size;
4142 requisition->width = 0;
4151 toolbar_content_is_homogeneous (ToolbarContent *content,
4152 GtkToolbar *toolbar)
4154 gboolean result = FALSE; /* quiet gcc */
4155 GtkRequisition requisition;
4156 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
4158 if (priv->max_homogeneous_pixels < 0)
4160 priv->max_homogeneous_pixels =
4161 calculate_max_homogeneous_pixels (GTK_WIDGET (toolbar));
4164 toolbar_content_size_request (content, toolbar, &requisition);
4166 if (requisition.width > priv->max_homogeneous_pixels)
4169 switch (content->type)
4172 result = gtk_tool_item_get_homogeneous (content->u.tool_item.item) &&
4173 !GTK_IS_SEPARATOR_TOOL_ITEM (content->u.tool_item.item);
4175 if (gtk_tool_item_get_is_important (content->u.tool_item.item) &&
4176 toolbar->style == GTK_TOOLBAR_BOTH_HORIZ &&
4177 toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
4184 if (content->u.compatibility.child.type == GTK_TOOLBAR_CHILD_BUTTON ||
4185 content->u.compatibility.child.type == GTK_TOOLBAR_CHILD_RADIOBUTTON ||
4186 content->u.compatibility.child.type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
4201 toolbar_content_is_placeholder (ToolbarContent *content)
4203 if (content->type == TOOL_ITEM && content->u.tool_item.is_placeholder)
4210 toolbar_content_disappearing (ToolbarContent *content)
4212 if (content->type == TOOL_ITEM && content->u.tool_item.disappearing)
4219 toolbar_content_get_state (ToolbarContent *content)
4221 return content->state;
4225 toolbar_content_child_visible (ToolbarContent *content)
4227 switch (content->type)
4230 return GTK_WIDGET_CHILD_VISIBLE (content->u.tool_item.item);
4234 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
4236 return GTK_WIDGET_CHILD_VISIBLE (content->u.compatibility.child.widget);
4240 return content->u.compatibility.space_visible;
4245 return FALSE; /* quiet gcc */
4249 toolbar_content_get_goal_allocation (ToolbarContent *content,
4250 GtkAllocation *allocation)
4252 switch (content->type)
4255 *allocation = content->u.tool_item.goal_allocation;
4259 /* Goal allocations are only relevant when we are
4260 * using the new API, so we should never get here
4262 g_assert_not_reached ();
4268 toolbar_content_get_allocation (ToolbarContent *content,
4269 GtkAllocation *allocation)
4271 GtkToolbarChild *child;
4273 switch (content->type)
4276 *allocation = GTK_WIDGET (content->u.tool_item.item)->allocation;
4280 child = &(content->u.compatibility.child);
4282 if (child->type == GTK_TOOLBAR_CHILD_SPACE)
4283 *allocation = content->u.compatibility.space_allocation;
4285 *allocation = child->widget->allocation;
4291 toolbar_content_set_start_allocation (ToolbarContent *content,
4292 GtkAllocation *allocation)
4294 switch (content->type)
4297 content->u.tool_item.start_allocation = *allocation;
4301 /* start_allocation is only relevant when using the new API */
4302 g_assert_not_reached ();
4308 toolbar_content_get_expand (ToolbarContent *content)
4310 if (content->type == TOOL_ITEM &&
4311 gtk_tool_item_get_expand (content->u.tool_item.item) &&
4312 !content->u.tool_item.disappearing)
4321 toolbar_content_set_goal_allocation (ToolbarContent *content,
4322 GtkAllocation *allocation)
4324 switch (content->type)
4327 content->u.tool_item.goal_allocation = *allocation;
4331 /* Only relevant when using new API */
4332 g_assert_not_reached ();
4338 toolbar_content_set_child_visible (ToolbarContent *content,
4339 GtkToolbar *toolbar,
4342 GtkToolbarChild *child;
4344 switch (content->type)
4347 gtk_widget_set_child_visible (GTK_WIDGET (content->u.tool_item.item),
4352 child = &(content->u.compatibility.child);
4354 if (child->type != GTK_TOOLBAR_CHILD_SPACE)
4356 gtk_widget_set_child_visible (child->widget, visible);
4360 if (content->u.compatibility.space_visible != visible)
4362 content->u.compatibility.space_visible = visible;
4363 gtk_widget_queue_draw (GTK_WIDGET (toolbar));
4371 toolbar_content_get_start_allocation (ToolbarContent *content,
4372 GtkAllocation *start_allocation)
4374 switch (content->type)
4377 *start_allocation = content->u.tool_item.start_allocation;
4381 /* Only relevant for new API */
4382 g_assert_not_reached ();
4388 toolbar_content_size_allocate (ToolbarContent *content,
4389 GtkAllocation *allocation)
4391 switch (content->type)
4394 gtk_widget_size_allocate (GTK_WIDGET (content->u.tool_item.item),
4399 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
4401 gtk_widget_size_allocate (content->u.compatibility.child.widget,
4406 content->u.compatibility.space_allocation = *allocation;
4413 toolbar_content_set_state (ToolbarContent *content,
4416 content->state = state;
4420 toolbar_content_get_widget (ToolbarContent *content)
4422 GtkToolbarChild *child;
4424 switch (content->type)
4427 return GTK_WIDGET (content->u.tool_item.item);
4431 child = &(content->u.compatibility.child);
4432 if (child->type != GTK_TOOLBAR_CHILD_SPACE)
4433 return child->widget;
4443 toolbar_content_set_disappearing (ToolbarContent *content,
4444 gboolean disappearing)
4446 switch (content->type)
4449 content->u.tool_item.disappearing = disappearing;
4453 /* Only relevant for new API */
4454 g_assert_not_reached ();
4460 toolbar_content_set_size_request (ToolbarContent *content,
4464 switch (content->type)
4467 gtk_widget_set_size_request (GTK_WIDGET (content->u.tool_item.item),
4472 /* Setting size requests only happens with sliding,
4473 * so not relevant here
4475 g_assert_not_reached ();
4481 toolbar_child_reconfigure (GtkToolbar *toolbar,
4482 GtkToolbarChild *child)
4486 GtkToolbarStyle style;
4487 GtkIconSize icon_size;
4488 GtkReliefStyle relief;
4491 style = gtk_toolbar_get_style (toolbar);
4492 icon_size = gtk_toolbar_get_icon_size (toolbar);
4493 relief = gtk_toolbar_get_relief_style (toolbar);
4496 if (child->type == GTK_TOOLBAR_CHILD_BUTTON ||
4497 child->type == GTK_TOOLBAR_CHILD_RADIOBUTTON ||
4498 child->type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
4500 box = gtk_bin_get_child (GTK_BIN (child->widget));
4502 if (style == GTK_TOOLBAR_BOTH && GTK_IS_HBOX (box))
4506 vbox = gtk_vbox_new (FALSE, 0);
4509 gtk_widget_reparent (child->label, vbox);
4511 gtk_widget_reparent (child->icon, vbox);
4513 gtk_widget_destroy (box);
4514 gtk_container_add (GTK_CONTAINER (child->widget), vbox);
4516 gtk_widget_show (vbox);
4518 else if (style == GTK_TOOLBAR_BOTH_HORIZ && GTK_IS_VBOX (box))
4522 hbox = gtk_hbox_new (FALSE, 0);
4525 gtk_widget_reparent (child->label, hbox);
4527 gtk_widget_reparent (child->icon, hbox);
4529 gtk_widget_destroy (box);
4530 gtk_container_add (GTK_CONTAINER (child->widget), hbox);
4532 gtk_widget_show (hbox);
4535 set_child_packing_and_visibility (toolbar, child);
4540 if ((child->type == GTK_TOOLBAR_CHILD_BUTTON ||
4541 child->type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON ||
4542 child->type == GTK_TOOLBAR_CHILD_RADIOBUTTON) &&
4543 GTK_IS_IMAGE (child->icon))
4545 image = GTK_IMAGE (child->icon);
4546 if (gtk_image_get_storage_type (image) == GTK_IMAGE_STOCK)
4548 gtk_image_get_stock (image, &stock_id, NULL);
4549 stock_id = g_strdup (stock_id);
4550 gtk_image_set_from_stock (image,
4558 if (child->type == GTK_TOOLBAR_CHILD_BUTTON ||
4559 child->type == GTK_TOOLBAR_CHILD_RADIOBUTTON ||
4560 child->type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
4562 gtk_button_set_relief (GTK_BUTTON (child->widget), relief);
4567 toolbar_content_toolbar_reconfigured (ToolbarContent *content,
4568 GtkToolbar *toolbar)
4570 switch (content->type)
4573 _gtk_tool_item_toolbar_reconfigured (content->u.tool_item.item);
4577 toolbar_child_reconfigure (toolbar, &(content->u.compatibility.child));
4583 toolbar_content_retrieve_menu_item (ToolbarContent *content)
4585 if (content->type == TOOL_ITEM)
4586 return gtk_tool_item_retrieve_proxy_menu_item (content->u.tool_item.item);
4588 /* FIXME - we might actually be able to do something meaningful here */
4593 toolbar_content_has_proxy_menu_item (ToolbarContent *content)
4595 if (content->type == TOOL_ITEM)
4597 GtkWidget *menu_item;
4599 if (content->u.tool_item.has_menu == YES)
4601 else if (content->u.tool_item.has_menu == NO)
4604 menu_item = toolbar_content_retrieve_menu_item (content);
4606 content->u.tool_item.has_menu = menu_item? YES : NO;
4608 return menu_item != NULL;
4617 toolbar_content_set_unknown_menu_status (ToolbarContent *content)
4619 if (content->type == TOOL_ITEM)
4620 content->u.tool_item.has_menu = UNKNOWN;
4624 toolbar_content_is_separator (ToolbarContent *content)
4626 GtkToolbarChild *child;
4628 switch (content->type)
4631 return GTK_IS_SEPARATOR_TOOL_ITEM (content->u.tool_item.item);
4635 child = &(content->u.compatibility.child);
4636 return (child->type == GTK_TOOLBAR_CHILD_SPACE);
4644 toolbar_content_set_expand (ToolbarContent *content,
4647 if (content->type == TOOL_ITEM)
4648 gtk_tool_item_set_expand (content->u.tool_item.item, expand);
4652 ignore_show_and_hide_all (ToolbarContent *content)
4654 if (content->type == COMPATIBILITY)
4656 GtkToolbarChildType type = content->u.compatibility.child.type;
4658 if (type == GTK_TOOLBAR_CHILD_BUTTON ||
4659 type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON ||
4660 type == GTK_TOOLBAR_CHILD_RADIOBUTTON)
4670 toolbar_content_show_all (ToolbarContent *content)
4674 if (ignore_show_and_hide_all (content))
4677 widget = toolbar_content_get_widget (content);
4679 gtk_widget_show_all (widget);
4683 toolbar_content_hide_all (ToolbarContent *content)
4687 if (ignore_show_and_hide_all (content))
4690 widget = toolbar_content_get_widget (content);
4692 gtk_widget_hide_all (widget);
4699 get_space_size (GtkToolbar *toolbar)
4701 gint space_size = DEFAULT_SPACE_SIZE;
4705 gtk_widget_style_get (GTK_WIDGET (toolbar),
4706 "space-size", &space_size,
4713 static GtkToolbarSpaceStyle
4714 get_space_style (GtkToolbar *toolbar)
4716 GtkToolbarSpaceStyle space_style = DEFAULT_SPACE_STYLE;
4720 gtk_widget_style_get (GTK_WIDGET (toolbar),
4721 "space-style", &space_style,
4728 static GtkReliefStyle
4729 get_button_relief (GtkToolbar *toolbar)
4731 GtkReliefStyle button_relief = GTK_RELIEF_NORMAL;
4733 gtk_widget_ensure_style (GTK_WIDGET (toolbar));
4735 gtk_widget_style_get (GTK_WIDGET (toolbar),
4736 "button-relief", &button_relief,
4739 return button_relief;
4743 get_internal_padding (GtkToolbar *toolbar)
4747 gtk_widget_style_get (GTK_WIDGET (toolbar),
4748 "internal-padding", &ipadding,
4754 static GtkShadowType
4755 get_shadow_type (GtkToolbar *toolbar)
4757 GtkShadowType shadow_type;
4759 gtk_widget_style_get (GTK_WIDGET (toolbar),
4760 "shadow-type", &shadow_type,
4770 gtk_toolbar_check_old_api (GtkToolbar *toolbar)
4772 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
4774 if (priv->api_mode == NEW_API)
4776 g_warning (MIXED_API_WARNING);
4780 priv->api_mode = OLD_API;
4785 gtk_toolbar_check_new_api (GtkToolbar *toolbar)
4787 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
4789 if (priv->api_mode == OLD_API)
4791 g_warning (MIXED_API_WARNING);
4795 priv->api_mode = NEW_API;
4799 /* GTK+ internal methods */
4802 _gtk_toolbar_get_default_space_size (void)
4804 return DEFAULT_SPACE_SIZE;
4808 _gtk_toolbar_paint_space_line (GtkWidget *widget,
4809 GtkToolbar *toolbar,
4811 GtkAllocation *allocation)
4813 const double start_fraction = (SPACE_LINE_START / SPACE_LINE_DIVISION);
4814 const double end_fraction = (SPACE_LINE_END / SPACE_LINE_DIVISION);
4816 GtkOrientation orientation;
4818 g_return_if_fail (GTK_IS_WIDGET (widget));
4820 orientation = toolbar? toolbar->orientation : GTK_ORIENTATION_HORIZONTAL;
4822 if (orientation == GTK_ORIENTATION_HORIZONTAL)
4824 gboolean wide_separators;
4825 gint separator_width;
4827 gtk_widget_style_get (widget,
4828 "wide-separators", &wide_separators,
4829 "separator-width", &separator_width,
4832 if (wide_separators)
4833 gtk_paint_box (widget->style, widget->window,
4834 GTK_WIDGET_STATE (widget), GTK_SHADOW_ETCHED_OUT,
4835 area, widget, "vseparator",
4836 allocation->x + (allocation->width - separator_width) / 2,
4837 allocation->y + allocation->height * start_fraction,
4839 allocation->height * (end_fraction - start_fraction));
4841 gtk_paint_vline (widget->style, widget->window,
4842 GTK_WIDGET_STATE (widget), area, widget,
4844 allocation->y + allocation->height * start_fraction,
4845 allocation->y + allocation->height * end_fraction,
4846 allocation->x + (allocation->width - widget->style->xthickness) / 2);
4850 gboolean wide_separators;
4851 gint separator_height;
4853 gtk_widget_style_get (widget,
4854 "wide-separators", &wide_separators,
4855 "separator-height", &separator_height,
4858 if (wide_separators)
4859 gtk_paint_box (widget->style, widget->window,
4860 GTK_WIDGET_STATE (widget), GTK_SHADOW_ETCHED_OUT,
4861 area, widget, "hseparator",
4862 allocation->x + allocation->width * start_fraction,
4863 allocation->y + (allocation->height - separator_height) / 2,
4864 allocation->width * (end_fraction - start_fraction),
4867 gtk_paint_hline (widget->style, widget->window,
4868 GTK_WIDGET_STATE (widget), area, widget,
4870 allocation->x + allocation->width * start_fraction,
4871 allocation->x + allocation->width * end_fraction,
4872 allocation->y + (allocation->height - widget->style->ythickness) / 2);
4877 _gtk_toolbar_elide_underscores (const gchar *original)
4880 const gchar *p, *end;
4882 gboolean last_underscore;
4887 len = strlen (original);
4888 q = result = g_malloc (len + 1);
4889 last_underscore = FALSE;
4891 end = original + len;
4892 for (p = original; p < end; p++)
4894 if (!last_underscore && *p == '_')
4895 last_underscore = TRUE;
4898 last_underscore = FALSE;
4899 if (*p != '_' && original + 2 <= p && p + 1 <= end && p[-2] == '(' && p[1] == ')')
4910 if (last_underscore)
4919 _gtk_toolbar_rebuild_menu (GtkToolbar *toolbar)
4921 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
4924 priv->need_rebuild = TRUE;
4926 for (list = priv->content; list != NULL; list = list->next)
4928 ToolbarContent *content = list->data;
4930 toolbar_content_set_unknown_menu_status (content);
4933 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
4936 #define __GTK_TOOLBAR_C__
4937 #include "gtkaliasdef.c"