1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3 * GtkToolbar copyright (C) Federico Mena
5 * Copyright (C) 2002 Anders Carlsson <andersca@gnome.org>
6 * Copyright (C) 2002 James Henstridge <james@daa.com.au>
7 * Copyright (C) 2003, 2004 Soeren Sandmann <sandmann@daimi.au.dk>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the
21 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 * Boston, MA 02111-1307, USA.
26 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
27 * file for a list of people on the GTK+ Team. See the ChangeLog
28 * files for a list of changes. These files are distributed with
29 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
32 #undef GTK_DISABLE_DEPRECATED
36 #include "gtktoolbar.h"
37 #include "gtkradiotoolbutton.h"
38 #include "gtkseparatortoolitem.h"
40 #include "gtkradiobutton.h"
41 #include "gtkbindings.h"
42 #include <gdk/gdkkeysyms.h>
43 #include "gtkmarshalers.h"
47 #include "gtkprivate.h"
53 #include "gtkseparatormenuitem.h"
57 typedef struct _ToolbarContent ToolbarContent;
59 #define DEFAULT_IPADDING 0
61 #define DEFAULT_SPACE_SIZE 12
62 #define DEFAULT_SPACE_STYLE GTK_TOOLBAR_SPACE_LINE
63 #define SPACE_LINE_DIVISION 10.0
64 #define SPACE_LINE_START 2.0
65 #define SPACE_LINE_END 8.0
67 #define DEFAULT_ICON_SIZE GTK_ICON_SIZE_LARGE_TOOLBAR
68 #define DEFAULT_TOOLBAR_STYLE GTK_TOOLBAR_BOTH
69 #define DEFAULT_ANIMATION_STATE TRUE
71 #define MAX_HOMOGENEOUS_N_CHARS 13 /* Items that are wider than this do not participate
72 * in the homogeneous game. In units of
73 * pango_font_get_estimated_char_width().
75 #define SLIDE_SPEED 600.0 /* How fast the items slide, in pixels per second */
76 #define ACCEL_THRESHOLD 0.18 /* After how much time in seconds will items start speeding up */
78 #define MIXED_API_WARNING \
79 "Mixing deprecated and non-deprecated GtkToolbar API is not allowed"
93 /* Child properties */
97 CHILD_PROP_HOMOGENEOUS
129 struct _GtkToolbarPrivate
134 GtkWidget * arrow_button;
137 GdkWindow * event_window;
139 GtkSettings * settings;
141 GtkToolItem * highlight_tool_item;
142 gint max_homogeneous_pixels;
146 gulong settings_connection;
148 guint show_arrow : 1;
150 guint is_sliding : 1;
151 guint need_rebuild : 1; /* whether the overflow menu should be regenerated */
155 static void gtk_toolbar_set_property (GObject *object,
159 static void gtk_toolbar_get_property (GObject *object,
163 static gint gtk_toolbar_expose (GtkWidget *widget,
164 GdkEventExpose *event);
165 static void gtk_toolbar_realize (GtkWidget *widget);
166 static void gtk_toolbar_unrealize (GtkWidget *widget);
167 static void gtk_toolbar_size_request (GtkWidget *widget,
168 GtkRequisition *requisition);
169 static void gtk_toolbar_size_allocate (GtkWidget *widget,
170 GtkAllocation *allocation);
171 static void gtk_toolbar_style_set (GtkWidget *widget,
172 GtkStyle *prev_style);
173 static gboolean gtk_toolbar_focus (GtkWidget *widget,
174 GtkDirectionType dir);
175 static void gtk_toolbar_screen_changed (GtkWidget *widget,
176 GdkScreen *previous_screen);
177 static void gtk_toolbar_map (GtkWidget *widget);
178 static void gtk_toolbar_unmap (GtkWidget *widget);
179 static void gtk_toolbar_set_child_property (GtkContainer *container,
184 static void gtk_toolbar_get_child_property (GtkContainer *container,
189 static void gtk_toolbar_finalize (GObject *object);
190 static void gtk_toolbar_show_all (GtkWidget *widget);
191 static void gtk_toolbar_hide_all (GtkWidget *widget);
192 static void gtk_toolbar_add (GtkContainer *container,
194 static void gtk_toolbar_remove (GtkContainer *container,
196 static void gtk_toolbar_forall (GtkContainer *container,
197 gboolean include_internals,
198 GtkCallback callback,
199 gpointer callback_data);
200 static GType gtk_toolbar_child_type (GtkContainer *container);
201 static void gtk_toolbar_orientation_changed (GtkToolbar *toolbar,
202 GtkOrientation orientation);
203 static void gtk_toolbar_real_style_changed (GtkToolbar *toolbar,
204 GtkToolbarStyle style);
205 static gboolean gtk_toolbar_move_focus (GtkToolbar *toolbar,
206 GtkDirectionType dir);
207 static gboolean gtk_toolbar_focus_home_or_end (GtkToolbar *toolbar,
208 gboolean focus_home);
209 static gboolean gtk_toolbar_button_press (GtkWidget *toolbar,
210 GdkEventButton *event);
211 static gboolean gtk_toolbar_arrow_button_press (GtkWidget *button,
212 GdkEventButton *event,
213 GtkToolbar *toolbar);
214 static void gtk_toolbar_arrow_button_clicked (GtkWidget *button,
215 GtkToolbar *toolbar);
216 static void gtk_toolbar_update_button_relief (GtkToolbar *toolbar);
217 static gboolean gtk_toolbar_popup_menu (GtkWidget *toolbar);
218 static GtkWidget *internal_insert_element (GtkToolbar *toolbar,
219 GtkToolbarChildType type,
222 const char *tooltip_text,
223 const char *tooltip_private_text,
225 GtkSignalFunc callback,
229 static void gtk_toolbar_reconfigured (GtkToolbar *toolbar);
230 static gboolean gtk_toolbar_check_new_api (GtkToolbar *toolbar);
231 static gboolean gtk_toolbar_check_old_api (GtkToolbar *toolbar);
233 static GtkReliefStyle get_button_relief (GtkToolbar *toolbar);
234 static gint get_internal_padding (GtkToolbar *toolbar);
235 static gint get_max_child_expand (GtkToolbar *toolbar);
236 static GtkShadowType get_shadow_type (GtkToolbar *toolbar);
237 static gint get_space_size (GtkToolbar *toolbar);
238 static GtkToolbarSpaceStyle get_space_style (GtkToolbar *toolbar);
240 /* methods on ToolbarContent 'class' */
241 static ToolbarContent *toolbar_content_new_tool_item (GtkToolbar *toolbar,
243 gboolean is_placeholder,
245 static void toolbar_content_remove (ToolbarContent *content,
246 GtkToolbar *toolbar);
247 static void toolbar_content_free (ToolbarContent *content);
248 static void toolbar_content_expose (ToolbarContent *content,
249 GtkContainer *container,
250 GdkEventExpose *expose);
251 static gboolean toolbar_content_visible (ToolbarContent *content,
252 GtkToolbar *toolbar);
253 static void toolbar_content_size_request (ToolbarContent *content,
255 GtkRequisition *requisition);
256 static gboolean toolbar_content_is_homogeneous (ToolbarContent *content,
257 GtkToolbar *toolbar);
258 static gboolean toolbar_content_is_placeholder (ToolbarContent *content);
259 static gboolean toolbar_content_disappearing (ToolbarContent *content);
260 static ItemState toolbar_content_get_state (ToolbarContent *content);
261 static gboolean toolbar_content_child_visible (ToolbarContent *content);
262 static void toolbar_content_get_goal_allocation (ToolbarContent *content,
263 GtkAllocation *allocation);
264 static void toolbar_content_get_allocation (ToolbarContent *content,
265 GtkAllocation *allocation);
266 static void toolbar_content_set_start_allocation (ToolbarContent *content,
267 GtkAllocation *new_start_allocation);
268 static void toolbar_content_get_start_allocation (ToolbarContent *content,
269 GtkAllocation *start_allocation);
270 static gboolean toolbar_content_get_expand (ToolbarContent *content);
271 static void toolbar_content_set_goal_allocation (ToolbarContent *content,
272 GtkAllocation *allocation);
273 static void toolbar_content_set_child_visible (ToolbarContent *content,
276 static void toolbar_content_size_allocate (ToolbarContent *content,
277 GtkAllocation *allocation);
278 static void toolbar_content_set_state (ToolbarContent *content,
279 ItemState new_state);
280 static GtkWidget * toolbar_content_get_widget (ToolbarContent *content);
281 static void toolbar_content_set_disappearing (ToolbarContent *content,
282 gboolean disappearing);
283 static void toolbar_content_set_size_request (ToolbarContent *content,
286 static void toolbar_content_toolbar_reconfigured (ToolbarContent *content,
287 GtkToolbar *toolbar);
288 static GtkWidget * toolbar_content_retrieve_menu_item (ToolbarContent *content);
289 static gboolean toolbar_content_has_proxy_menu_item (ToolbarContent *content);
290 static gboolean toolbar_content_is_separator (ToolbarContent *content);
291 static void toolbar_content_show_all (ToolbarContent *content);
292 static void toolbar_content_hide_all (ToolbarContent *content);
293 static void toolbar_content_set_expand (ToolbarContent *content,
296 #define GTK_TOOLBAR_GET_PRIVATE(o) \
297 (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_TOOLBAR, GtkToolbarPrivate))
299 static guint toolbar_signals [LAST_SIGNAL] = { 0 };
301 G_DEFINE_TYPE (GtkToolbar, gtk_toolbar, GTK_TYPE_CONTAINER)
304 add_arrow_bindings (GtkBindingSet *binding_set,
306 GtkDirectionType dir)
308 guint keypad_keysym = keysym - GDK_Left + GDK_KP_Left;
310 gtk_binding_entry_add_signal (binding_set, keysym, 0,
312 GTK_TYPE_DIRECTION_TYPE, dir);
313 gtk_binding_entry_add_signal (binding_set, keypad_keysym, 0,
315 GTK_TYPE_DIRECTION_TYPE, dir);
319 add_ctrl_tab_bindings (GtkBindingSet *binding_set,
320 GdkModifierType modifiers,
321 GtkDirectionType direction)
323 gtk_binding_entry_add_signal (binding_set,
324 GDK_Tab, GDK_CONTROL_MASK | modifiers,
326 GTK_TYPE_DIRECTION_TYPE, direction);
327 gtk_binding_entry_add_signal (binding_set,
328 GDK_KP_Tab, GDK_CONTROL_MASK | modifiers,
330 GTK_TYPE_DIRECTION_TYPE, direction);
334 gtk_toolbar_class_init (GtkToolbarClass *klass)
336 GObjectClass *gobject_class;
337 GtkWidgetClass *widget_class;
338 GtkContainerClass *container_class;
339 GtkBindingSet *binding_set;
341 gobject_class = (GObjectClass *)klass;
342 widget_class = (GtkWidgetClass *)klass;
343 container_class = (GtkContainerClass *)klass;
345 gobject_class->set_property = gtk_toolbar_set_property;
346 gobject_class->get_property = gtk_toolbar_get_property;
347 gobject_class->finalize = gtk_toolbar_finalize;
349 widget_class->button_press_event = gtk_toolbar_button_press;
350 widget_class->expose_event = gtk_toolbar_expose;
351 widget_class->size_request = gtk_toolbar_size_request;
352 widget_class->size_allocate = gtk_toolbar_size_allocate;
353 widget_class->style_set = gtk_toolbar_style_set;
354 widget_class->focus = gtk_toolbar_focus;
355 widget_class->screen_changed = gtk_toolbar_screen_changed;
356 widget_class->realize = gtk_toolbar_realize;
357 widget_class->unrealize = gtk_toolbar_unrealize;
358 widget_class->map = gtk_toolbar_map;
359 widget_class->unmap = gtk_toolbar_unmap;
360 widget_class->popup_menu = gtk_toolbar_popup_menu;
361 widget_class->show_all = gtk_toolbar_show_all;
362 widget_class->hide_all = gtk_toolbar_hide_all;
364 container_class->add = gtk_toolbar_add;
365 container_class->remove = gtk_toolbar_remove;
366 container_class->forall = gtk_toolbar_forall;
367 container_class->child_type = gtk_toolbar_child_type;
368 container_class->get_child_property = gtk_toolbar_get_child_property;
369 container_class->set_child_property = gtk_toolbar_set_child_property;
371 klass->orientation_changed = gtk_toolbar_orientation_changed;
372 klass->style_changed = gtk_toolbar_real_style_changed;
375 * GtkToolbar::orientation-changed:
376 * @toolbar: the object which emitted the signal
377 * @orientation: the new #GtkOrientation of the toolbar
379 * Emitted when the orientation of the toolbar changes.
381 toolbar_signals[ORIENTATION_CHANGED] =
382 g_signal_new (I_("orientation-changed"),
383 G_OBJECT_CLASS_TYPE (klass),
385 G_STRUCT_OFFSET (GtkToolbarClass, orientation_changed),
387 g_cclosure_marshal_VOID__ENUM,
389 GTK_TYPE_ORIENTATION);
391 * GtkToolbar::style-changed:
392 * @toolbar: The #GtkToolbar which emitted the signal
393 * @style: the new #GtkToolbarStyle of the toolbar
395 * Emitted when the style of the toolbar changes.
397 toolbar_signals[STYLE_CHANGED] =
398 g_signal_new (I_("style-changed"),
399 G_OBJECT_CLASS_TYPE (klass),
401 G_STRUCT_OFFSET (GtkToolbarClass, style_changed),
403 g_cclosure_marshal_VOID__ENUM,
405 GTK_TYPE_TOOLBAR_STYLE);
407 * GtkToolbar::popup-context-menu:
408 * @toolbar: the #GtkToolbar which emitted the signal
409 * @x: the x coordinate of the point where the menu should appear
410 * @y: the y coordinate of the point where the menu should appear
411 * @button: the mouse button the user pressed, or -1
413 * Emitted when the user right-clicks the toolbar or uses the
414 * keybinding to display a popup menu.
416 * Application developers should handle this signal if they want
417 * to display a context menu on the toolbar. The context-menu should
418 * appear at the coordinates given by @x and @y. The mouse button
419 * number is given by the @button parameter. If the menu was popped
420 * up using the keybaord, @button is -1.
422 * Return value: return %TRUE if the signal was handled, %FALSE if not
424 toolbar_signals[POPUP_CONTEXT_MENU] =
425 g_signal_new (I_("popup_context_menu"),
426 G_OBJECT_CLASS_TYPE (klass),
428 G_STRUCT_OFFSET (GtkToolbarClass, popup_context_menu),
429 _gtk_boolean_handled_accumulator, NULL,
430 _gtk_marshal_BOOLEAN__INT_INT_INT,
432 G_TYPE_INT, G_TYPE_INT,
435 * GtkToolbar::move-focus:
436 * @toolbar: the #GtkToolbar which emitted the signal
437 * @dir: a #GtkDirection
439 * A keybinding signal used internally by GTK+. This signal can't
440 * be used in application code.
442 * Return value: %TRUE if the signal was handled, %FALSE if not
444 toolbar_signals[MOVE_FOCUS] =
445 _gtk_binding_signal_new (I_("move_focus"),
446 G_TYPE_FROM_CLASS (klass),
447 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
448 G_CALLBACK (gtk_toolbar_move_focus),
450 _gtk_marshal_BOOLEAN__ENUM,
452 GTK_TYPE_DIRECTION_TYPE);
454 * GtkToolbar::focus-home-or-end:
455 * @toolbar: the #GtkToolbar which emitted the signal
456 * @focus_home: %TRUE if the first item should be focused
458 * A keybinding signal used internally by GTK+. This signal can't
459 * be used in application code
461 * Return value: %TRUE if the signal was handled, %FALSE if not
463 toolbar_signals[FOCUS_HOME_OR_END] =
464 _gtk_binding_signal_new (I_("focus_home_or_end"),
465 G_OBJECT_CLASS_TYPE (klass),
466 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
467 G_CALLBACK (gtk_toolbar_focus_home_or_end),
469 _gtk_marshal_BOOLEAN__BOOLEAN,
474 g_object_class_install_property (gobject_class,
476 g_param_spec_enum ("orientation",
478 P_("The orientation of the toolbar"),
479 GTK_TYPE_ORIENTATION,
480 GTK_ORIENTATION_HORIZONTAL,
481 GTK_PARAM_READWRITE));
483 g_object_class_install_property (gobject_class,
485 g_param_spec_enum ("toolbar-style",
487 P_("How to draw the toolbar"),
488 GTK_TYPE_TOOLBAR_STYLE,
490 GTK_PARAM_READWRITE));
491 g_object_class_install_property (gobject_class,
493 g_param_spec_boolean ("show-arrow",
495 P_("If an arrow should be shown if the toolbar doesn't fit"),
497 GTK_PARAM_READWRITE));
501 * GtkToolbar:tooltips:
503 * If the tooltips of the toolbar should be active or not.
507 g_object_class_install_property (gobject_class,
509 g_param_spec_boolean ("tooltips",
511 P_("If the tooltips of the toolbar should be active or not"),
513 GTK_PARAM_READWRITE));
517 * GtkToolbar:icon-size:
519 * The size of the icons in a toolbar is normally determined by
520 * the toolbar-icon-size setting. When this property is set, it
521 * overrides the setting.
523 * This should only be used for special-purpose toolbars, normal
524 * application toolbars should respect the user preferences for the
529 g_object_class_install_property (gobject_class,
531 g_param_spec_enum ("icon-size",
533 P_("Size of icons in this toolbar"),
536 GTK_PARAM_READWRITE));
539 * GtkToolbar:icon-size-set:
541 * Is %TRUE if the icon-size property has been set.
545 g_object_class_install_property (gobject_class,
547 g_param_spec_boolean ("icon-size-set",
549 P_("Whether the icon-size property has been set"),
551 GTK_PARAM_READWRITE));
553 /* child properties */
554 gtk_container_class_install_child_property (container_class,
556 g_param_spec_boolean ("expand",
558 P_("Whether the item should receive extra space when the toolbar grows"),
560 GTK_PARAM_READWRITE));
562 gtk_container_class_install_child_property (container_class,
563 CHILD_PROP_HOMOGENEOUS,
564 g_param_spec_boolean ("homogeneous",
566 P_("Whether the item should be the same size as other homogeneous items"),
568 GTK_PARAM_READWRITE));
570 /* style properties */
571 gtk_widget_class_install_style_property (widget_class,
572 g_param_spec_int ("space-size",
574 P_("Size of spacers"),
578 GTK_PARAM_READABLE));
580 gtk_widget_class_install_style_property (widget_class,
581 g_param_spec_int ("internal-padding",
582 P_("Internal padding"),
583 P_("Amount of border space between the toolbar shadow and the buttons"),
587 GTK_PARAM_READABLE));
589 gtk_widget_class_install_style_property (widget_class,
590 g_param_spec_int ("max-child-expand",
591 P_("Maximum child expand"),
592 P_("Maximum amount of space an expandable item will be given"),
596 GTK_PARAM_READABLE));
598 gtk_widget_class_install_style_property (widget_class,
599 g_param_spec_enum ("space-style",
601 P_("Whether spacers are vertical lines or just blank"),
602 GTK_TYPE_TOOLBAR_SPACE_STYLE,
604 GTK_PARAM_READABLE));
606 gtk_widget_class_install_style_property (widget_class,
607 g_param_spec_enum ("button-relief",
609 P_("Type of bevel around toolbar buttons"),
610 GTK_TYPE_RELIEF_STYLE,
612 GTK_PARAM_READABLE));
613 gtk_widget_class_install_style_property (widget_class,
614 g_param_spec_enum ("shadow-type",
616 P_("Style of bevel around the toolbar"),
617 GTK_TYPE_SHADOW_TYPE,
619 GTK_PARAM_READABLE));
621 gtk_settings_install_property (g_param_spec_enum ("gtk-toolbar-style",
623 P_("Whether default toolbars have text only, text and icons, icons only, etc."),
624 GTK_TYPE_TOOLBAR_STYLE,
625 DEFAULT_TOOLBAR_STYLE,
626 GTK_PARAM_READWRITE));
628 gtk_settings_install_property (g_param_spec_enum ("gtk-toolbar-icon-size",
629 P_("Toolbar icon size"),
630 P_("Size of icons in default toolbars"),
633 GTK_PARAM_READWRITE));
635 binding_set = gtk_binding_set_by_class (klass);
637 add_arrow_bindings (binding_set, GDK_Left, GTK_DIR_LEFT);
638 add_arrow_bindings (binding_set, GDK_Right, GTK_DIR_RIGHT);
639 add_arrow_bindings (binding_set, GDK_Up, GTK_DIR_UP);
640 add_arrow_bindings (binding_set, GDK_Down, GTK_DIR_DOWN);
642 gtk_binding_entry_add_signal (binding_set, GDK_KP_Home, 0,
643 "focus_home_or_end", 1,
644 G_TYPE_BOOLEAN, TRUE);
645 gtk_binding_entry_add_signal (binding_set, GDK_Home, 0,
646 "focus_home_or_end", 1,
647 G_TYPE_BOOLEAN, TRUE);
648 gtk_binding_entry_add_signal (binding_set, GDK_KP_End, 0,
649 "focus_home_or_end", 1,
650 G_TYPE_BOOLEAN, FALSE);
651 gtk_binding_entry_add_signal (binding_set, GDK_End, 0,
652 "focus_home_or_end", 1,
653 G_TYPE_BOOLEAN, FALSE);
655 add_ctrl_tab_bindings (binding_set, 0, GTK_DIR_TAB_FORWARD);
656 add_ctrl_tab_bindings (binding_set, GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
658 g_type_class_add_private (gobject_class, sizeof (GtkToolbarPrivate));
662 gtk_toolbar_init (GtkToolbar *toolbar)
664 GtkToolbarPrivate *priv;
666 GTK_WIDGET_UNSET_FLAGS (toolbar, GTK_CAN_FOCUS);
667 GTK_WIDGET_SET_FLAGS (toolbar, GTK_NO_WINDOW);
669 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
671 toolbar->orientation = GTK_ORIENTATION_HORIZONTAL;
672 toolbar->style = DEFAULT_TOOLBAR_STYLE;
673 toolbar->icon_size = DEFAULT_ICON_SIZE;
674 priv->animation = DEFAULT_ANIMATION_STATE;
675 toolbar->tooltips = gtk_tooltips_new ();
676 g_object_ref_sink (toolbar->tooltips);
678 priv->arrow_button = gtk_toggle_button_new ();
679 g_signal_connect (priv->arrow_button, "button_press_event",
680 G_CALLBACK (gtk_toolbar_arrow_button_press), toolbar);
681 g_signal_connect (priv->arrow_button, "clicked",
682 G_CALLBACK (gtk_toolbar_arrow_button_clicked), toolbar);
683 gtk_button_set_relief (GTK_BUTTON (priv->arrow_button),
684 get_button_relief (toolbar));
686 priv->api_mode = DONT_KNOW;
688 gtk_button_set_focus_on_click (GTK_BUTTON (priv->arrow_button), FALSE);
690 priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
691 gtk_widget_set_name (priv->arrow, "gtk-toolbar-arrow");
692 gtk_widget_show (priv->arrow);
693 gtk_container_add (GTK_CONTAINER (priv->arrow_button), priv->arrow);
695 gtk_widget_set_parent (priv->arrow_button, GTK_WIDGET (toolbar));
697 /* which child position a drop will occur at */
699 priv->show_arrow = TRUE;
700 priv->settings = NULL;
702 priv->max_homogeneous_pixels = -1;
704 priv->timer = g_timer_new ();
708 gtk_toolbar_set_property (GObject *object,
713 GtkToolbar *toolbar = GTK_TOOLBAR (object);
717 case PROP_ORIENTATION:
718 gtk_toolbar_set_orientation (toolbar, g_value_get_enum (value));
720 case PROP_TOOLBAR_STYLE:
721 gtk_toolbar_set_style (toolbar, g_value_get_enum (value));
723 case PROP_SHOW_ARROW:
724 gtk_toolbar_set_show_arrow (toolbar, g_value_get_boolean (value));
727 gtk_toolbar_set_tooltips (toolbar, g_value_get_boolean (value));
730 gtk_toolbar_set_icon_size (toolbar, g_value_get_enum (value));
732 case PROP_ICON_SIZE_SET:
733 if (g_value_get_boolean (value))
734 toolbar->icon_size_set = TRUE;
736 gtk_toolbar_unset_icon_size (toolbar);
739 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
745 gtk_toolbar_get_property (GObject *object,
750 GtkToolbar *toolbar = GTK_TOOLBAR (object);
751 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
755 case PROP_ORIENTATION:
756 g_value_set_enum (value, toolbar->orientation);
758 case PROP_TOOLBAR_STYLE:
759 g_value_set_enum (value, toolbar->style);
761 case PROP_SHOW_ARROW:
762 g_value_set_boolean (value, priv->show_arrow);
765 g_value_set_boolean (value, gtk_toolbar_get_tooltips (toolbar));
768 g_value_set_enum (value, gtk_toolbar_get_icon_size (toolbar));
770 case PROP_ICON_SIZE_SET:
771 g_value_set_boolean (value, toolbar->icon_size_set);
774 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
780 gtk_toolbar_map (GtkWidget *widget)
782 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
784 GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->map (widget);
786 if (priv->event_window)
787 gdk_window_show_unraised (priv->event_window);
791 gtk_toolbar_unmap (GtkWidget *widget)
793 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
795 if (priv->event_window)
796 gdk_window_hide (priv->event_window);
798 GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unmap (widget);
802 gtk_toolbar_realize (GtkWidget *widget)
804 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
805 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
807 GdkWindowAttr attributes;
808 gint attributes_mask;
811 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
813 border_width = GTK_CONTAINER (widget)->border_width;
815 attributes.wclass = GDK_INPUT_ONLY;
816 attributes.window_type = GDK_WINDOW_CHILD;
817 attributes.x = widget->allocation.x + border_width;
818 attributes.y = widget->allocation.y + border_width;
819 attributes.width = widget->allocation.width - border_width * 2;
820 attributes.height = widget->allocation.height - border_width * 2;
821 attributes.event_mask = gtk_widget_get_events (widget);
822 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
823 GDK_BUTTON_RELEASE_MASK |
824 GDK_ENTER_NOTIFY_MASK |
825 GDK_LEAVE_NOTIFY_MASK);
827 attributes_mask = GDK_WA_X | GDK_WA_Y;
829 widget->window = gtk_widget_get_parent_window (widget);
830 g_object_ref (widget->window);
831 widget->style = gtk_style_attach (widget->style, widget->window);
833 priv->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
834 &attributes, attributes_mask);
835 gdk_window_set_user_data (priv->event_window, toolbar);
839 gtk_toolbar_unrealize (GtkWidget *widget)
841 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
843 if (priv->event_window)
845 gdk_window_set_user_data (priv->event_window, NULL);
846 gdk_window_destroy (priv->event_window);
847 priv->event_window = NULL;
850 if (GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unrealize)
851 (* GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unrealize) (widget);
855 gtk_toolbar_expose (GtkWidget *widget,
856 GdkEventExpose *event)
858 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
859 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
864 border_width = GTK_CONTAINER (widget)->border_width;
866 if (GTK_WIDGET_DRAWABLE (widget))
868 gtk_paint_box (widget->style,
870 GTK_WIDGET_STATE (widget),
871 get_shadow_type (toolbar),
872 &event->area, widget, "toolbar",
873 border_width + widget->allocation.x,
874 border_width + widget->allocation.y,
875 widget->allocation.width - 2 * border_width,
876 widget->allocation.height - 2 * border_width);
879 for (list = priv->content; list != NULL; list = list->next)
881 ToolbarContent *content = list->data;
883 toolbar_content_expose (content, GTK_CONTAINER (widget), event);
886 gtk_container_propagate_expose (GTK_CONTAINER (widget),
894 gtk_toolbar_size_request (GtkWidget *widget,
895 GtkRequisition *requisition)
897 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
898 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
900 gint max_child_height;
901 gint max_child_width;
902 gint max_homogeneous_child_width;
903 gint max_homogeneous_child_height;
904 gint homogeneous_size;
906 gint pack_front_size;
908 GtkRequisition arrow_requisition;
910 max_homogeneous_child_width = 0;
911 max_homogeneous_child_height = 0;
913 max_child_height = 0;
914 for (list = priv->content; list != NULL; list = list->next)
916 GtkRequisition requisition;
917 ToolbarContent *content = list->data;
919 if (!toolbar_content_visible (content, toolbar))
922 toolbar_content_size_request (content, toolbar, &requisition);
924 max_child_width = MAX (max_child_width, requisition.width);
925 max_child_height = MAX (max_child_height, requisition.height);
927 if (toolbar_content_is_homogeneous (content, toolbar))
929 max_homogeneous_child_width = MAX (max_homogeneous_child_width, requisition.width);
930 max_homogeneous_child_height = MAX (max_homogeneous_child_height, requisition.height);
934 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
935 homogeneous_size = max_homogeneous_child_width;
937 homogeneous_size = max_homogeneous_child_height;
940 for (list = priv->content; list != NULL; list = list->next)
942 ToolbarContent *content = list->data;
945 if (!toolbar_content_visible (content, toolbar))
948 if (toolbar_content_is_homogeneous (content, toolbar))
950 size = homogeneous_size;
954 GtkRequisition requisition;
956 toolbar_content_size_request (content, toolbar, &requisition);
958 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
959 size = requisition.width;
961 size = requisition.height;
964 pack_front_size += size;
967 if (priv->show_arrow && priv->api_mode == NEW_API)
969 gtk_widget_size_request (priv->arrow_button, &arrow_requisition);
971 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
972 long_req = arrow_requisition.width;
974 long_req = arrow_requisition.height;
976 /* There is no point requesting space for the arrow if that would take
977 * up more space than all the items combined
979 long_req = MIN (long_req, pack_front_size);
983 arrow_requisition.height = 0;
984 arrow_requisition.width = 0;
986 long_req = pack_front_size;
989 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
991 requisition->width = long_req;
992 requisition->height = MAX (max_child_height, arrow_requisition.height);
996 requisition->height = long_req;
997 requisition->width = MAX (max_child_width, arrow_requisition.width);
1001 ipadding = get_internal_padding (toolbar);
1003 requisition->width += 2 * (ipadding + GTK_CONTAINER (toolbar)->border_width);
1004 requisition->height += 2 * (ipadding + GTK_CONTAINER (toolbar)->border_width);
1006 if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
1008 requisition->width += 2 * widget->style->xthickness;
1009 requisition->height += 2 * widget->style->ythickness;
1012 toolbar->button_maxw = max_homogeneous_child_width;
1013 toolbar->button_maxh = max_homogeneous_child_height;
1017 position (GtkToolbar *toolbar,
1024 if (! GTK_TOOLBAR_GET_PRIVATE (toolbar)->animation)
1027 if (elapsed <= ACCEL_THRESHOLD)
1029 n_pixels = SLIDE_SPEED * elapsed;
1033 /* The formula is a second degree polynomial in
1034 * @elapsed that has the line SLIDE_SPEED * @elapsed
1035 * as tangent for @elapsed == ACCEL_THRESHOLD.
1036 * This makes @n_pixels a smooth function of elapsed time.
1038 n_pixels = (SLIDE_SPEED / ACCEL_THRESHOLD) * elapsed * elapsed -
1039 SLIDE_SPEED * elapsed + SLIDE_SPEED * ACCEL_THRESHOLD;
1043 return MIN (from + n_pixels, to);
1045 return MAX (from - n_pixels, to);
1049 compute_intermediate_allocation (GtkToolbar *toolbar,
1050 const GtkAllocation *start,
1051 const GtkAllocation *goal,
1052 GtkAllocation *intermediate)
1054 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1055 gdouble elapsed = g_timer_elapsed (priv->timer, NULL);
1057 intermediate->x = position (toolbar, start->x, goal->x, elapsed);
1058 intermediate->y = position (toolbar, start->y, goal->y, elapsed);
1059 intermediate->width = position (toolbar, start->x + start->width,
1060 goal->x + goal->width,
1061 elapsed) - intermediate->x;
1062 intermediate->height = position (toolbar, start->y + start->height,
1063 goal->y + goal->height,
1064 elapsed) - intermediate->y;
1068 fixup_allocation_for_rtl (gint total_size,
1069 GtkAllocation *allocation)
1071 allocation->x += (total_size - (2 * allocation->x + allocation->width));
1075 fixup_allocation_for_vertical (GtkAllocation *allocation)
1079 tmp = allocation->x;
1080 allocation->x = allocation->y;
1081 allocation->y = tmp;
1083 tmp = allocation->width;
1084 allocation->width = allocation->height;
1085 allocation->height = tmp;
1089 get_item_size (GtkToolbar *toolbar,
1090 ToolbarContent *content)
1092 GtkRequisition requisition;
1094 toolbar_content_size_request (content, toolbar, &requisition);
1096 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
1098 if (toolbar_content_is_homogeneous (content, toolbar))
1099 return toolbar->button_maxw;
1101 return requisition.width;
1105 if (toolbar_content_is_homogeneous (content, toolbar))
1106 return toolbar->button_maxh;
1108 return requisition.height;
1113 slide_idle_handler (gpointer data)
1115 GtkToolbar *toolbar = data;
1116 GtkToolbarPrivate *priv;
1119 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1121 if (priv->need_sync)
1124 priv->need_sync = FALSE;
1127 for (list = priv->content; list != NULL; list = list->next)
1129 ToolbarContent *content = list->data;
1131 GtkAllocation goal_allocation;
1132 GtkAllocation allocation;
1135 state = toolbar_content_get_state (content);
1136 toolbar_content_get_goal_allocation (content, &goal_allocation);
1137 toolbar_content_get_allocation (content, &allocation);
1141 if (state == NOT_ALLOCATED)
1143 /* an unallocated item means that size allocate has to
1144 * called at least once more
1149 /* An invisible item with a goal allocation of
1150 * 0 is already at its goal.
1152 if ((state == NORMAL || state == OVERFLOWN) &&
1153 ((goal_allocation.width != 0 &&
1154 goal_allocation.height != 0) ||
1155 toolbar_content_child_visible (content)))
1157 if ((goal_allocation.x != allocation.x ||
1158 goal_allocation.y != allocation.y ||
1159 goal_allocation.width != allocation.width ||
1160 goal_allocation.height != allocation.height))
1162 /* An item is not in its right position yet. Note
1163 * that OVERFLOWN items do get an allocation in
1164 * gtk_toolbar_size_allocate(). This way you can see
1165 * them slide back in when you drag an item off the
1172 if (toolbar_content_is_placeholder (content) &&
1173 toolbar_content_disappearing (content) &&
1174 toolbar_content_child_visible (content))
1176 /* A disappearing placeholder is still visible.
1184 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1186 GDK_THREADS_LEAVE ();
1191 priv->is_sliding = FALSE;
1198 rect_within (GtkAllocation *a1,
1201 return (a1->x >= a2->x &&
1202 a1->x + a1->width <= a2->x + a2->width &&
1204 a1->y + a1->height <= a2->y + a2->height);
1208 gtk_toolbar_begin_sliding (GtkToolbar *toolbar)
1210 GtkWidget *widget = GTK_WIDGET (toolbar);
1211 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1219 /* Start the sliding. This function copies the allocation of every
1220 * item into content->start_allocation. For items that haven't
1221 * been allocated yet, we calculate their position and save that
1222 * in start_allocatino along with zero width and zero height.
1224 * FIXME: It would be nice if we could share this code with
1225 * the equivalent in gtk_widget_size_allocate().
1227 priv->is_sliding = TRUE;
1230 priv->idle_id = gdk_threads_add_idle (slide_idle_handler, toolbar);
1232 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1233 vertical = (toolbar->orientation == GTK_ORIENTATION_VERTICAL);
1234 border_width = get_internal_padding (toolbar) + GTK_CONTAINER (toolbar)->border_width;
1238 cur_x = widget->allocation.width - border_width - widget->style->xthickness;
1239 cur_y = widget->allocation.height - border_width - widget->style->ythickness;
1243 cur_x = border_width + widget->style->xthickness;
1244 cur_y = border_width + widget->style->ythickness;
1247 cur_x += widget->allocation.x;
1248 cur_y += widget->allocation.y;
1250 for (list = priv->content; list != NULL; list = list->next)
1252 ToolbarContent *content = list->data;
1253 GtkAllocation new_start_allocation;
1254 GtkAllocation item_allocation;
1257 state = toolbar_content_get_state (content);
1258 toolbar_content_get_allocation (content, &item_allocation);
1260 if ((state == NORMAL &&
1261 rect_within (&item_allocation, &(widget->allocation))) ||
1264 new_start_allocation = item_allocation;
1268 new_start_allocation.x = cur_x;
1269 new_start_allocation.y = cur_y;
1273 new_start_allocation.width = widget->allocation.width -
1274 2 * border_width - 2 * widget->style->xthickness;
1275 new_start_allocation.height = 0;
1279 new_start_allocation.width = 0;
1280 new_start_allocation.height = widget->allocation.height -
1281 2 * border_width - 2 * widget->style->ythickness;
1286 cur_y = new_start_allocation.y + new_start_allocation.height;
1288 cur_x = new_start_allocation.x;
1290 cur_x = new_start_allocation.x + new_start_allocation.width;
1292 toolbar_content_set_start_allocation (content, &new_start_allocation);
1295 /* This resize will run before the first idle handler. This
1296 * will make sure that items get the right goal allocation
1297 * so that the idle handler will not immediately return
1300 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1301 g_timer_reset (priv->timer);
1305 gtk_toolbar_stop_sliding (GtkToolbar *toolbar)
1307 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1309 if (priv->is_sliding)
1313 priv->is_sliding = FALSE;
1317 g_source_remove (priv->idle_id);
1321 list = priv->content;
1324 ToolbarContent *content = list->data;
1327 if (toolbar_content_is_placeholder (content))
1329 toolbar_content_remove (content, toolbar);
1330 toolbar_content_free (content);
1334 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1339 remove_item (GtkWidget *menu_item,
1342 gtk_container_remove (GTK_CONTAINER (menu_item->parent), menu_item);
1346 menu_deactivated (GtkWidget *menu,
1347 GtkToolbar *toolbar)
1349 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1350 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->arrow_button), FALSE);
1354 menu_detached (GtkWidget *toolbar,
1357 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1362 rebuild_menu (GtkToolbar *toolbar)
1364 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1365 GList *list, *children;
1369 priv->menu = GTK_MENU (gtk_menu_new());
1370 gtk_menu_attach_to_widget (priv->menu,
1371 GTK_WIDGET (toolbar),
1374 g_signal_connect (priv->menu, "deactivate", G_CALLBACK (menu_deactivated), toolbar);
1377 gtk_container_foreach (GTK_CONTAINER (priv->menu), remove_item, NULL);
1379 for (list = priv->content; list != NULL; list = list->next)
1381 ToolbarContent *content = list->data;
1383 if (toolbar_content_get_state (content) == OVERFLOWN &&
1384 !toolbar_content_is_placeholder (content))
1386 GtkWidget *menu_item = toolbar_content_retrieve_menu_item (content);
1390 g_assert (GTK_IS_MENU_ITEM (menu_item));
1391 gtk_menu_shell_append (GTK_MENU_SHELL (priv->menu), menu_item);
1396 /* Remove leading and trailing separator items */
1397 children = gtk_container_get_children (GTK_CONTAINER (priv->menu));
1400 while (list && GTK_IS_SEPARATOR_MENU_ITEM (list->data))
1402 GtkWidget *child = list->data;
1404 gtk_container_remove (GTK_CONTAINER (priv->menu), child);
1407 g_list_free (children);
1409 /* Regenerate the list of children so we don't try to remove items twice */
1410 children = gtk_container_get_children (GTK_CONTAINER (priv->menu));
1412 list = g_list_last (children);
1413 while (list && GTK_IS_SEPARATOR_MENU_ITEM (list->data))
1415 GtkWidget *child = list->data;
1417 gtk_container_remove (GTK_CONTAINER (priv->menu), child);
1420 g_list_free (children);
1422 priv->need_rebuild = FALSE;
1426 gtk_toolbar_size_allocate (GtkWidget *widget,
1427 GtkAllocation *allocation)
1429 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1430 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1431 GtkAllocation *allocations;
1432 ItemState *new_states;
1433 GtkAllocation arrow_allocation;
1435 gint size, pos, short_size;
1438 gboolean need_arrow;
1439 gint n_expand_items;
1441 gint available_size;
1444 GtkRequisition arrow_requisition;
1445 gboolean overflowing;
1446 gboolean size_changed;
1447 GtkAllocation item_area;
1448 GtkShadowType shadow_type;
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 shadow_type = get_shadow_type (toolbar);
1482 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
1484 available_size = size = allocation->width - 2 * border_width;
1485 short_size = allocation->height - 2 * border_width;
1486 arrow_size = arrow_requisition.width;
1488 if (shadow_type != GTK_SHADOW_NONE)
1490 available_size -= 2 * widget->style->xthickness;
1491 short_size -= 2 * widget->style->ythickness;
1496 available_size = size = allocation->height - 2 * border_width;
1497 short_size = allocation->width - 2 * border_width;
1498 arrow_size = arrow_requisition.height;
1500 if (shadow_type != GTK_SHADOW_NONE)
1502 available_size -= 2 * widget->style->ythickness;
1503 short_size -= 2 * widget->style->xthickness;
1507 n_items = g_list_length (priv->content);
1508 allocations = g_new0 (GtkAllocation, n_items);
1509 new_states = g_new0 (ItemState, n_items);
1513 for (list = priv->content; list != NULL; list = list->next)
1515 ToolbarContent *content = list->data;
1517 if (toolbar_content_visible (content, toolbar))
1519 needed_size += get_item_size (toolbar, content);
1521 /* Do we need an arrow?
1523 * Assume we don't, and see if any non-separator item with a
1524 * proxy menu item is then going to overflow.
1526 if (needed_size > available_size &&
1529 priv->api_mode == NEW_API &&
1530 toolbar_content_has_proxy_menu_item (content) &&
1531 !toolbar_content_is_separator (content))
1539 size = available_size - arrow_size;
1541 size = available_size;
1543 /* calculate widths and states of items */
1544 overflowing = FALSE;
1545 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1547 ToolbarContent *content = list->data;
1550 if (!toolbar_content_visible (content, toolbar))
1552 new_states[i] = HIDDEN;
1556 item_size = get_item_size (toolbar, content);
1557 if (item_size <= size && !overflowing)
1560 allocations[i].width = item_size;
1561 new_states[i] = NORMAL;
1566 new_states[i] = OVERFLOWN;
1567 allocations[i].width = item_size;
1571 /* calculate width of arrow */
1574 arrow_allocation.width = arrow_size;
1575 arrow_allocation.height = MAX (short_size, 1);
1578 /* expand expandable items */
1580 /* We don't expand when there is an overflow menu, because that leads to
1581 * weird jumps when items get moved to the overflow menu and the expanding
1582 * items suddenly get a lot of extra space
1586 gint max_child_expand;
1589 for (i = 0, list = priv->content; list != NULL; list = list->next, ++i)
1591 ToolbarContent *content = list->data;
1593 if (toolbar_content_get_expand (content) && new_states[i] == NORMAL)
1597 max_child_expand = get_max_child_expand (toolbar);
1598 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1600 ToolbarContent *content = list->data;
1602 if (toolbar_content_get_expand (content) && new_states[i] == NORMAL)
1604 gint extra = size / n_expand_items;
1605 if (size % n_expand_items != 0)
1608 if (extra > max_child_expand)
1609 extra = max_child_expand;
1611 allocations[i].width += extra;
1617 g_assert (n_expand_items == 0);
1620 /* position items */
1622 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1624 /* both NORMAL and OVERFLOWN items get a position. This ensures
1625 * that sliding will work for OVERFLOWN items too
1627 if (new_states[i] == NORMAL ||
1628 new_states[i] == OVERFLOWN)
1630 allocations[i].x = pos;
1631 allocations[i].y = border_width;
1632 allocations[i].height = short_size;
1634 pos += allocations[i].width;
1638 /* position arrow */
1641 arrow_allocation.x = available_size - border_width - arrow_allocation.width;
1642 arrow_allocation.y = border_width;
1645 item_area.x = border_width;
1646 item_area.y = border_width;
1647 item_area.width = available_size - (need_arrow? arrow_size : 0);
1648 item_area.height = short_size;
1650 /* fix up allocations in the vertical or RTL cases */
1651 if (toolbar->orientation == GTK_ORIENTATION_VERTICAL)
1653 for (i = 0; i < n_items; ++i)
1654 fixup_allocation_for_vertical (&(allocations[i]));
1657 fixup_allocation_for_vertical (&arrow_allocation);
1659 fixup_allocation_for_vertical (&item_area);
1661 else if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL)
1663 for (i = 0; i < n_items; ++i)
1664 fixup_allocation_for_rtl (available_size, &(allocations[i]));
1667 fixup_allocation_for_rtl (available_size, &arrow_allocation);
1669 fixup_allocation_for_rtl (available_size, &item_area);
1672 /* translate the items by allocation->(x,y) */
1673 for (i = 0; i < n_items; ++i)
1675 allocations[i].x += allocation->x;
1676 allocations[i].y += allocation->y;
1678 if (shadow_type != GTK_SHADOW_NONE)
1680 allocations[i].x += widget->style->xthickness;
1681 allocations[i].y += widget->style->ythickness;
1687 arrow_allocation.x += allocation->x;
1688 arrow_allocation.y += allocation->y;
1690 if (shadow_type != GTK_SHADOW_NONE)
1692 arrow_allocation.x += widget->style->xthickness;
1693 arrow_allocation.y += widget->style->ythickness;
1697 item_area.x += allocation->x;
1698 item_area.y += allocation->y;
1699 if (shadow_type != GTK_SHADOW_NONE)
1701 item_area.x += widget->style->xthickness;
1702 item_area.y += widget->style->ythickness;
1705 /* did anything change? */
1706 for (list = priv->content, i = 0; list != NULL; list = list->next, i++)
1708 ToolbarContent *content = list->data;
1710 if (toolbar_content_get_state (content) == NORMAL &&
1711 new_states[i] != NORMAL)
1713 /* an item disappeared and we didn't change size, so begin sliding */
1714 if (!size_changed && priv->api_mode == NEW_API)
1715 gtk_toolbar_begin_sliding (toolbar);
1719 /* finally allocate the items */
1720 if (priv->is_sliding)
1722 for (list = priv->content, i = 0; list != NULL; list = list->next, i++)
1724 ToolbarContent *content = list->data;
1726 toolbar_content_set_goal_allocation (content, &(allocations[i]));
1730 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1732 ToolbarContent *content = list->data;
1734 if (new_states[i] == OVERFLOWN ||
1735 new_states[i] == NORMAL)
1737 GtkAllocation alloc;
1738 GtkAllocation start_allocation = { 0, };
1739 GtkAllocation goal_allocation;
1741 if (priv->is_sliding)
1743 toolbar_content_get_start_allocation (content, &start_allocation);
1744 toolbar_content_get_goal_allocation (content, &goal_allocation);
1746 compute_intermediate_allocation (toolbar,
1751 priv->need_sync = TRUE;
1755 alloc = allocations[i];
1758 if (alloc.width <= 0 || alloc.height <= 0)
1760 toolbar_content_set_child_visible (content, toolbar, FALSE);
1764 if (!rect_within (&alloc, &item_area))
1766 toolbar_content_set_child_visible (content, toolbar, FALSE);
1767 toolbar_content_size_allocate (content, &alloc);
1771 toolbar_content_set_child_visible (content, toolbar, TRUE);
1772 toolbar_content_size_allocate (content, &alloc);
1778 toolbar_content_set_child_visible (content, toolbar, FALSE);
1781 toolbar_content_set_state (content, new_states[i]);
1784 if (priv->menu && priv->need_rebuild)
1785 rebuild_menu (toolbar);
1789 gtk_widget_size_allocate (GTK_WIDGET (priv->arrow_button),
1791 gtk_widget_show (GTK_WIDGET (priv->arrow_button));
1795 gtk_widget_hide (GTK_WIDGET (priv->arrow_button));
1797 if (priv->menu && GTK_WIDGET_VISIBLE (priv->menu))
1798 gtk_menu_shell_deactivate (GTK_MENU_SHELL (priv->menu));
1801 g_free (allocations);
1802 g_free (new_states);
1806 gtk_toolbar_update_button_relief (GtkToolbar *toolbar)
1808 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1809 GtkReliefStyle relief;
1811 relief = get_button_relief (toolbar);
1813 if (relief != gtk_button_get_relief (GTK_BUTTON (priv->arrow_button)))
1815 gtk_toolbar_reconfigured (toolbar);
1817 gtk_button_set_relief (GTK_BUTTON (priv->arrow_button), relief);
1822 gtk_toolbar_style_set (GtkWidget *widget,
1823 GtkStyle *prev_style)
1825 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
1827 priv->max_homogeneous_pixels = -1;
1829 if (GTK_WIDGET_REALIZED (widget))
1830 gtk_style_set_background (widget->style, widget->window, widget->state);
1833 gtk_toolbar_update_button_relief (GTK_TOOLBAR (widget));
1837 gtk_toolbar_list_children_in_focus_order (GtkToolbar *toolbar,
1838 GtkDirectionType dir)
1840 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1841 GList *result = NULL;
1845 /* generate list of children in reverse logical order */
1847 for (list = priv->content; list != NULL; list = list->next)
1849 ToolbarContent *content = list->data;
1852 widget = toolbar_content_get_widget (content);
1855 result = g_list_prepend (result, widget);
1858 result = g_list_prepend (result, priv->arrow_button);
1860 rtl = (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL);
1862 /* move in logical order when
1864 * - dir is TAB_FORWARD
1866 * - in RTL mode and moving left or up
1868 * - in LTR mode and moving right or down
1870 if (dir == GTK_DIR_TAB_FORWARD ||
1871 (rtl && (dir == GTK_DIR_UP || dir == GTK_DIR_LEFT)) ||
1872 (!rtl && (dir == GTK_DIR_DOWN || dir == GTK_DIR_RIGHT)))
1874 result = g_list_reverse (result);
1881 gtk_toolbar_focus_home_or_end (GtkToolbar *toolbar,
1882 gboolean focus_home)
1884 GList *children, *list;
1885 GtkDirectionType dir = focus_home? GTK_DIR_RIGHT : GTK_DIR_LEFT;
1887 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1889 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL)
1891 children = g_list_reverse (children);
1893 dir = (dir == GTK_DIR_RIGHT)? GTK_DIR_LEFT : GTK_DIR_RIGHT;
1896 for (list = children; list != NULL; list = list->next)
1898 GtkWidget *child = list->data;
1900 if (GTK_CONTAINER (toolbar)->focus_child == child)
1903 if (GTK_WIDGET_MAPPED (child) && gtk_widget_child_focus (child, dir))
1907 g_list_free (children);
1912 /* Keybinding handler. This function is called when the user presses
1913 * Ctrl TAB or an arrow key.
1916 gtk_toolbar_move_focus (GtkToolbar *toolbar,
1917 GtkDirectionType dir)
1920 gboolean try_focus = FALSE;
1922 GtkContainer *container = GTK_CONTAINER (toolbar);
1924 if (container->focus_child &&
1925 gtk_widget_child_focus (container->focus_child, dir))
1930 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1932 for (list = children; list != NULL; list = list->next)
1934 GtkWidget *child = list->data;
1936 if (try_focus && GTK_WIDGET_MAPPED (child) && gtk_widget_child_focus (child, dir))
1939 if (child == GTK_CONTAINER (toolbar)->focus_child)
1943 g_list_free (children);
1948 /* The focus handler for the toolbar. It called when the user presses
1949 * TAB or otherwise tries to focus the toolbar.
1952 gtk_toolbar_focus (GtkWidget *widget,
1953 GtkDirectionType dir)
1955 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1956 GList *children, *list;
1957 gboolean result = FALSE;
1959 /* if focus is already somewhere inside the toolbar then return FALSE.
1960 * The only way focus can stay inside the toolbar is when the user presses
1961 * arrow keys or Ctrl TAB (both of which are handled by the
1962 * gtk_toolbar_move_focus() keybinding function.
1964 if (GTK_CONTAINER (widget)->focus_child)
1967 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1969 for (list = children; list != NULL; list = list->next)
1971 GtkWidget *child = list->data;
1973 if (GTK_WIDGET_MAPPED (child) && gtk_widget_child_focus (child, dir))
1980 g_list_free (children);
1985 static GtkSettings *
1986 toolbar_get_settings (GtkToolbar *toolbar)
1988 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1989 return priv->settings;
1993 style_change_notify (GtkToolbar *toolbar)
1995 if (!toolbar->style_set)
1997 /* pretend it was set, then unset, thus reverting to new default */
1998 toolbar->style_set = TRUE;
1999 gtk_toolbar_unset_style (toolbar);
2004 icon_size_change_notify (GtkToolbar *toolbar)
2006 if (!toolbar->icon_size_set)
2008 /* pretend it was set, then unset, thus reverting to new default */
2009 toolbar->icon_size_set = TRUE;
2010 gtk_toolbar_unset_icon_size (toolbar);
2015 animation_change_notify (GtkToolbar *toolbar)
2017 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2018 GtkSettings *settings = toolbar_get_settings (toolbar);
2022 g_object_get (settings,
2023 "gtk-enable-animations", &animation,
2026 animation = DEFAULT_ANIMATION_STATE;
2028 priv->animation = animation;
2032 settings_change_notify (GtkSettings *settings,
2033 const GParamSpec *pspec,
2034 GtkToolbar *toolbar)
2036 if (! strcmp (pspec->name, "gtk-toolbar-style"))
2037 style_change_notify (toolbar);
2038 else if (! strcmp (pspec->name, "gtk-toolbar-icon-size"))
2039 icon_size_change_notify (toolbar);
2040 else if (! strcmp (pspec->name, "gtk-enable-animations"))
2041 animation_change_notify (toolbar);
2045 gtk_toolbar_screen_changed (GtkWidget *widget,
2046 GdkScreen *previous_screen)
2048 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
2049 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
2050 GtkSettings *old_settings = toolbar_get_settings (toolbar);
2051 GtkSettings *settings;
2053 if (gtk_widget_has_screen (GTK_WIDGET (toolbar)))
2054 settings = gtk_widget_get_settings (GTK_WIDGET (toolbar));
2058 if (settings == old_settings)
2063 g_signal_handler_disconnect (old_settings, priv->settings_connection);
2065 g_object_unref (old_settings);
2070 priv->settings_connection =
2071 g_signal_connect (settings, "notify",
2072 G_CALLBACK (settings_change_notify),
2075 priv->settings = g_object_ref (settings);
2077 style_change_notify (toolbar);
2078 icon_size_change_notify (toolbar);
2079 animation_change_notify (toolbar);
2082 priv->settings = NULL;
2086 find_drop_index (GtkToolbar *toolbar,
2090 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2091 GList *interesting_content;
2093 GtkOrientation orientation;
2094 GtkTextDirection direction;
2095 gint best_distance = G_MAXINT;
2099 ToolbarContent *best_content;
2100 GtkAllocation allocation;
2102 /* list items we care about wrt. drag and drop */
2103 interesting_content = NULL;
2104 for (list = priv->content; list != NULL; list = list->next)
2106 ToolbarContent *content = list->data;
2108 if (toolbar_content_get_state (content) == NORMAL)
2109 interesting_content = g_list_prepend (interesting_content, content);
2111 interesting_content = g_list_reverse (interesting_content);
2113 if (!interesting_content)
2116 orientation = toolbar->orientation;
2117 direction = gtk_widget_get_direction (GTK_WIDGET (toolbar));
2119 /* distance to first interesting item */
2120 best_content = interesting_content->data;
2121 toolbar_content_get_allocation (best_content, &allocation);
2123 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2127 if (direction == GTK_TEXT_DIR_LTR)
2130 pos = allocation.x + allocation.width;
2138 best_content = NULL;
2139 best_distance = ABS (pos - cursor);
2141 /* distance to far end of each item */
2142 for (list = interesting_content; list != NULL; list = list->next)
2144 ToolbarContent *content = list->data;
2146 toolbar_content_get_allocation (content, &allocation);
2148 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2150 if (direction == GTK_TEXT_DIR_LTR)
2151 pos = allocation.x + allocation.width;
2157 pos = allocation.y + allocation.height;
2160 distance = ABS (pos - cursor);
2162 if (distance < best_distance)
2164 best_distance = distance;
2165 best_content = content;
2169 g_list_free (interesting_content);
2174 return g_list_index (priv->content, best_content) + 1;
2178 reset_all_placeholders (GtkToolbar *toolbar)
2180 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2183 for (list = priv->content; list != NULL; list = list->next)
2185 ToolbarContent *content = list->data;
2186 if (toolbar_content_is_placeholder (content))
2187 toolbar_content_set_disappearing (content, TRUE);
2192 physical_to_logical (GtkToolbar *toolbar,
2195 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2199 g_assert (physical >= 0);
2202 for (list = priv->content; list && physical > 0; list = list->next)
2204 ToolbarContent *content = list->data;
2206 if (!toolbar_content_is_placeholder (content))
2211 g_assert (physical == 0);
2217 logical_to_physical (GtkToolbar *toolbar,
2220 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2224 g_assert (logical >= 0);
2227 for (list = priv->content; list; list = list->next)
2229 ToolbarContent *content = list->data;
2231 if (!toolbar_content_is_placeholder (content))
2241 g_assert (logical == 0);
2247 * gtk_toolbar_set_drop_highlight_item:
2248 * @toolbar: a #GtkToolbar
2249 * @tool_item: a #GtkToolItem, or %NULL to turn of highlighting
2250 * @index_: a position on @toolbar
2252 * Highlights @toolbar to give an idea of what it would look like
2253 * if @item was added to @toolbar at the position indicated by @index_.
2254 * If @item is %NULL, highlighting is turned off. In that case @index_
2257 * The @tool_item passed to this function must not be part of any widget
2258 * hierarchy. When an item is set as drop highlight item it can not
2259 * added to any widget hierarchy or used as highlight item for another
2265 gtk_toolbar_set_drop_highlight_item (GtkToolbar *toolbar,
2266 GtkToolItem *tool_item,
2269 ToolbarContent *content;
2270 GtkToolbarPrivate *priv;
2272 GtkRequisition requisition;
2273 GtkRequisition old_requisition;
2274 gboolean restart_sliding;
2276 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2277 g_return_if_fail (tool_item == NULL || GTK_IS_TOOL_ITEM (tool_item));
2279 gtk_toolbar_check_new_api (toolbar);
2281 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2285 if (priv->highlight_tool_item)
2287 gtk_widget_unparent (GTK_WIDGET (priv->highlight_tool_item));
2288 g_object_unref (priv->highlight_tool_item);
2289 priv->highlight_tool_item = NULL;
2292 reset_all_placeholders (toolbar);
2293 gtk_toolbar_begin_sliding (toolbar);
2297 n_items = gtk_toolbar_get_n_items (toolbar);
2298 if (index_ < 0 || index_ > n_items)
2301 if (tool_item != priv->highlight_tool_item)
2303 if (priv->highlight_tool_item)
2304 g_object_unref (priv->highlight_tool_item);
2306 g_object_ref_sink (tool_item);
2308 priv->highlight_tool_item = tool_item;
2310 gtk_widget_set_parent (GTK_WIDGET (priv->highlight_tool_item),
2311 GTK_WIDGET (toolbar));
2314 index_ = logical_to_physical (toolbar, index_);
2316 content = g_list_nth_data (priv->content, index_);
2320 ToolbarContent *prev_content;
2322 prev_content = g_list_nth_data (priv->content, index_ - 1);
2324 if (prev_content && toolbar_content_is_placeholder (prev_content))
2325 content = prev_content;
2328 if (!content || !toolbar_content_is_placeholder (content))
2330 GtkWidget *placeholder;
2332 placeholder = GTK_WIDGET (gtk_separator_tool_item_new ());
2334 content = toolbar_content_new_tool_item (toolbar,
2335 GTK_TOOL_ITEM (placeholder),
2337 gtk_widget_show (placeholder);
2341 g_assert (toolbar_content_is_placeholder (content));
2343 gtk_widget_size_request (GTK_WIDGET (priv->highlight_tool_item),
2346 toolbar_content_set_expand (content, gtk_tool_item_get_expand (tool_item));
2348 restart_sliding = FALSE;
2349 toolbar_content_size_request (content, toolbar, &old_requisition);
2350 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
2352 requisition.height = -1;
2353 if (requisition.width != old_requisition.width)
2354 restart_sliding = TRUE;
2358 requisition.width = -1;
2359 if (requisition.height != old_requisition.height)
2360 restart_sliding = TRUE;
2363 if (toolbar_content_disappearing (content))
2364 restart_sliding = TRUE;
2366 reset_all_placeholders (toolbar);
2367 toolbar_content_set_disappearing (content, FALSE);
2369 toolbar_content_set_size_request (content,
2370 requisition.width, requisition.height);
2372 if (restart_sliding)
2373 gtk_toolbar_begin_sliding (toolbar);
2377 gtk_toolbar_get_child_property (GtkContainer *container,
2383 GtkToolItem *item = GTK_TOOL_ITEM (child);
2385 switch (property_id)
2387 case CHILD_PROP_HOMOGENEOUS:
2388 g_value_set_boolean (value, gtk_tool_item_get_homogeneous (item));
2391 case CHILD_PROP_EXPAND:
2392 g_value_set_boolean (value, gtk_tool_item_get_expand (item));
2396 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
2402 gtk_toolbar_set_child_property (GtkContainer *container,
2405 const GValue *value,
2408 switch (property_id)
2410 case CHILD_PROP_HOMOGENEOUS:
2411 gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (child), g_value_get_boolean (value));
2414 case CHILD_PROP_EXPAND:
2415 gtk_tool_item_set_expand (GTK_TOOL_ITEM (child), g_value_get_boolean (value));
2419 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
2425 gtk_toolbar_show_all (GtkWidget *widget)
2427 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
2430 for (list = priv->content; list != NULL; list = list->next)
2432 ToolbarContent *content = list->data;
2434 toolbar_content_show_all (content);
2437 gtk_widget_show (widget);
2441 gtk_toolbar_hide_all (GtkWidget *widget)
2443 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
2446 for (list = priv->content; list != NULL; list = list->next)
2448 ToolbarContent *content = list->data;
2450 toolbar_content_hide_all (content);
2453 gtk_widget_hide (widget);
2457 gtk_toolbar_add (GtkContainer *container,
2460 GtkToolbar *toolbar;
2462 g_return_if_fail (GTK_IS_TOOLBAR (container));
2463 g_return_if_fail (widget != NULL);
2465 toolbar = GTK_TOOLBAR (container);
2467 if (GTK_IS_TOOL_ITEM (widget))
2468 gtk_toolbar_insert (toolbar, GTK_TOOL_ITEM (widget), -1);
2470 gtk_toolbar_append_widget (toolbar, widget, NULL, NULL);
2474 gtk_toolbar_remove (GtkContainer *container,
2477 GtkToolbar *toolbar;
2478 GtkToolbarPrivate *priv;
2479 ToolbarContent *content_to_remove;
2482 g_return_if_fail (GTK_IS_TOOLBAR (container));
2483 g_return_if_fail (GTK_IS_WIDGET (widget));
2485 toolbar = GTK_TOOLBAR (container);
2486 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2488 content_to_remove = NULL;
2489 for (list = priv->content; list != NULL; list = list->next)
2491 ToolbarContent *content = list->data;
2494 child = toolbar_content_get_widget (content);
2495 if (child && child == widget)
2497 content_to_remove = content;
2502 g_return_if_fail (content_to_remove != NULL);
2504 toolbar_content_remove (content_to_remove, toolbar);
2505 toolbar_content_free (content_to_remove);
2509 gtk_toolbar_forall (GtkContainer *container,
2510 gboolean include_internals,
2511 GtkCallback callback,
2512 gpointer callback_data)
2514 GtkToolbar *toolbar = GTK_TOOLBAR (container);
2515 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2518 g_return_if_fail (callback != NULL);
2520 list = priv->content;
2523 ToolbarContent *content = list->data;
2524 GList *next = list->next;
2526 if (include_internals || !toolbar_content_is_placeholder (content))
2528 GtkWidget *child = toolbar_content_get_widget (content);
2531 (*callback) (child, callback_data);
2537 if (include_internals)
2538 (* callback) (priv->arrow_button, callback_data);
2542 gtk_toolbar_child_type (GtkContainer *container)
2544 return GTK_TYPE_TOOL_ITEM;
2548 gtk_toolbar_reconfigured (GtkToolbar *toolbar)
2550 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2553 list = priv->content;
2556 ToolbarContent *content = list->data;
2557 GList *next = list->next;
2559 toolbar_content_toolbar_reconfigured (content, toolbar);
2566 gtk_toolbar_orientation_changed (GtkToolbar *toolbar,
2567 GtkOrientation orientation)
2569 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2570 if (toolbar->orientation != orientation)
2572 toolbar->orientation = orientation;
2574 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2575 gtk_arrow_set (GTK_ARROW (priv->arrow), GTK_ARROW_DOWN, GTK_SHADOW_NONE);
2577 gtk_arrow_set (GTK_ARROW (priv->arrow), GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
2579 gtk_toolbar_reconfigured (toolbar);
2581 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
2582 g_object_notify (G_OBJECT (toolbar), "orientation");
2587 gtk_toolbar_real_style_changed (GtkToolbar *toolbar,
2588 GtkToolbarStyle style)
2590 if (toolbar->style != style)
2592 toolbar->style = style;
2594 gtk_toolbar_reconfigured (toolbar);
2596 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
2597 g_object_notify (G_OBJECT (toolbar), "toolbar-style");
2602 menu_position_func (GtkMenu *menu,
2608 GtkToolbar *toolbar = GTK_TOOLBAR (user_data);
2609 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2611 GtkRequisition menu_req;
2612 GdkRectangle monitor;
2616 gtk_widget_size_request (priv->arrow_button, &req);
2617 gtk_widget_size_request (GTK_WIDGET (menu), &menu_req);
2619 screen = gtk_widget_get_screen (GTK_WIDGET (menu));
2620 monitor_num = gdk_screen_get_monitor_at_window (screen, priv->arrow_button->window);
2621 if (monitor_num < 0)
2623 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
2625 gdk_window_get_origin (GTK_BUTTON (priv->arrow_button)->event_window, x, y);
2626 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
2628 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
2629 *x += priv->arrow_button->allocation.width - req.width;
2631 *x += req.width - menu_req.width;
2633 if ((*y + priv->arrow_button->allocation.height + menu_req.height) <= monitor.y + monitor.height)
2634 *y += priv->arrow_button->allocation.height;
2635 else if ((*y - menu_req.height) >= monitor.y)
2636 *y -= menu_req.height;
2637 else if (monitor.y + monitor.height - (*y + priv->arrow_button->allocation.height) > *y)
2638 *y += priv->arrow_button->allocation.height;
2640 *y -= menu_req.height;
2644 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
2645 *x += priv->arrow_button->allocation.width;
2647 *x -= menu_req.width;
2649 if (*y + menu_req.height > monitor.y + monitor.height &&
2650 *y + priv->arrow_button->allocation.height - monitor.y > monitor.y + monitor.height - *y)
2651 *y += priv->arrow_button->allocation.height - menu_req.height;
2658 show_menu (GtkToolbar *toolbar,
2659 GdkEventButton *event)
2661 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2663 rebuild_menu (toolbar);
2665 gtk_widget_show_all (GTK_WIDGET (priv->menu));
2667 gtk_menu_popup (priv->menu, NULL, NULL,
2668 menu_position_func, toolbar,
2669 event? event->button : 0,
2670 event? event->time : gtk_get_current_event_time());
2674 gtk_toolbar_arrow_button_clicked (GtkWidget *button,
2675 GtkToolbar *toolbar)
2677 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2679 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->arrow_button)) &&
2680 (!priv->menu || !GTK_WIDGET_VISIBLE (priv->menu)))
2682 /* We only get here when the button is clicked with the keyboard,
2683 * because mouse button presses result in the menu being shown so
2684 * that priv->menu would be non-NULL and visible.
2686 show_menu (toolbar, NULL);
2687 gtk_menu_shell_select_first (GTK_MENU_SHELL (priv->menu), FALSE);
2692 gtk_toolbar_arrow_button_press (GtkWidget *button,
2693 GdkEventButton *event,
2694 GtkToolbar *toolbar)
2696 show_menu (toolbar, event);
2697 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
2703 gtk_toolbar_button_press (GtkWidget *toolbar,
2704 GdkEventButton *event)
2706 if (event->button == 3)
2708 gboolean return_value;
2710 g_signal_emit (toolbar, toolbar_signals[POPUP_CONTEXT_MENU], 0,
2711 (int)event->x_root, (int)event->y_root, event->button,
2714 return return_value;
2721 gtk_toolbar_popup_menu (GtkWidget *toolbar)
2723 gboolean return_value;
2724 /* This function is the handler for the "popup menu" keybinding,
2725 * ie., it is called when the user presses Shift F10
2727 g_signal_emit (toolbar, toolbar_signals[POPUP_CONTEXT_MENU], 0,
2728 -1, -1, -1, &return_value);
2730 return return_value;
2736 * Creates a new toolbar.
2738 * Return Value: the newly-created toolbar.
2741 gtk_toolbar_new (void)
2743 GtkToolbar *toolbar;
2745 toolbar = g_object_new (GTK_TYPE_TOOLBAR, NULL);
2747 return GTK_WIDGET (toolbar);
2751 * gtk_toolbar_insert:
2752 * @toolbar: a #GtkToolbar
2753 * @item: a #GtkToolItem
2754 * @pos: the position of the new item
2756 * Insert a #GtkToolItem into the toolbar at position @pos. If @pos is
2757 * 0 the item is prepended to the start of the toolbar. If @pos is
2758 * negative, the item is appended to the end of the toolbar.
2763 gtk_toolbar_insert (GtkToolbar *toolbar,
2767 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2768 g_return_if_fail (GTK_IS_TOOL_ITEM (item));
2770 if (!gtk_toolbar_check_new_api (toolbar))
2774 pos = logical_to_physical (toolbar, pos);
2776 toolbar_content_new_tool_item (toolbar, item, FALSE, pos);
2780 * gtk_toolbar_get_item_index:
2781 * @toolbar: a #GtkToolbar
2782 * @item: a #GtkToolItem that is a child of @toolbar
2784 * Returns the position of @item on the toolbar, starting from 0.
2785 * It is an error if @item is not a child of the toolbar.
2787 * Return value: the position of item on the toolbar.
2792 gtk_toolbar_get_item_index (GtkToolbar *toolbar,
2795 GtkToolbarPrivate *priv;
2799 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
2800 g_return_val_if_fail (GTK_IS_TOOL_ITEM (item), -1);
2801 g_return_val_if_fail (GTK_WIDGET (item)->parent == GTK_WIDGET (toolbar), -1);
2803 if (!gtk_toolbar_check_new_api (toolbar))
2806 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2809 for (list = priv->content; list != NULL; list = list->next)
2811 ToolbarContent *content = list->data;
2814 widget = toolbar_content_get_widget (content);
2816 if (item == GTK_TOOL_ITEM (widget))
2822 return physical_to_logical (toolbar, n);
2826 * gtk_toolbar_set_orientation:
2827 * @toolbar: a #GtkToolbar.
2828 * @orientation: a new #GtkOrientation.
2830 * Sets whether a toolbar should appear horizontally or vertically.
2833 gtk_toolbar_set_orientation (GtkToolbar *toolbar,
2834 GtkOrientation orientation)
2836 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2838 g_signal_emit (toolbar, toolbar_signals[ORIENTATION_CHANGED], 0, orientation);
2842 * gtk_toolbar_get_orientation:
2843 * @toolbar: a #GtkToolbar
2845 * Retrieves the current orientation of the toolbar. See
2846 * gtk_toolbar_set_orientation().
2848 * Return value: the orientation
2851 gtk_toolbar_get_orientation (GtkToolbar *toolbar)
2853 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), GTK_ORIENTATION_HORIZONTAL);
2855 return toolbar->orientation;
2859 * gtk_toolbar_set_style:
2860 * @toolbar: a #GtkToolbar.
2861 * @style: the new style for @toolbar.
2863 * Alters the view of @toolbar to display either icons only, text only, or both.
2866 gtk_toolbar_set_style (GtkToolbar *toolbar,
2867 GtkToolbarStyle style)
2869 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2871 toolbar->style_set = TRUE;
2872 g_signal_emit (toolbar, toolbar_signals[STYLE_CHANGED], 0, style);
2876 * gtk_toolbar_get_style:
2877 * @toolbar: a #GtkToolbar
2879 * Retrieves whether the toolbar has text, icons, or both . See
2880 * gtk_toolbar_set_style().
2882 * Return value: the current style of @toolbar
2885 gtk_toolbar_get_style (GtkToolbar *toolbar)
2887 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), DEFAULT_TOOLBAR_STYLE);
2889 return toolbar->style;
2893 * gtk_toolbar_unset_style:
2894 * @toolbar: a #GtkToolbar
2896 * Unsets a toolbar style set with gtk_toolbar_set_style(), so that
2897 * user preferences will be used to determine the toolbar style.
2900 gtk_toolbar_unset_style (GtkToolbar *toolbar)
2902 GtkToolbarStyle style;
2904 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2906 if (toolbar->style_set)
2908 GtkSettings *settings = toolbar_get_settings (toolbar);
2911 g_object_get (settings,
2912 "gtk-toolbar-style", &style,
2915 style = DEFAULT_TOOLBAR_STYLE;
2917 if (style != toolbar->style)
2918 g_signal_emit (toolbar, toolbar_signals[STYLE_CHANGED], 0, style);
2920 toolbar->style_set = FALSE;
2925 * gtk_toolbar_set_tooltips:
2926 * @toolbar: a #GtkToolbar.
2927 * @enable: set to %FALSE to disable the tooltips, or %TRUE to enable them.
2929 * Sets if the tooltips of a toolbar should be active or not.
2932 gtk_toolbar_set_tooltips (GtkToolbar *toolbar,
2935 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2938 gtk_tooltips_enable (toolbar->tooltips);
2940 gtk_tooltips_disable (toolbar->tooltips);
2942 g_object_notify (G_OBJECT (toolbar), "tooltips");
2946 * gtk_toolbar_get_tooltips:
2947 * @toolbar: a #GtkToolbar
2949 * Retrieves whether tooltips are enabled. See
2950 * gtk_toolbar_set_tooltips().
2952 * Return value: %TRUE if tooltips are enabled
2955 gtk_toolbar_get_tooltips (GtkToolbar *toolbar)
2957 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), FALSE);
2959 return toolbar->tooltips->enabled;
2963 * gtk_toolbar_get_n_items:
2964 * @toolbar: a #GtkToolbar
2966 * Returns the number of items on the toolbar.
2968 * Return value: the number of items on the toolbar
2973 gtk_toolbar_get_n_items (GtkToolbar *toolbar)
2975 GtkToolbarPrivate *priv;
2977 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
2979 if (!gtk_toolbar_check_new_api (toolbar))
2982 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2984 return physical_to_logical (toolbar, g_list_length (priv->content));
2988 * gtk_toolbar_get_nth_item:
2989 * @toolbar: a #GtkToolbar
2990 * @n: A position on the toolbar
2992 * Returns the @n<!-- -->'th item on @toolbar, or %NULL if the
2993 * toolbar does not contain an @n<!-- -->'th item.
2995 * Return value: The @n<!-- -->'th #GtkToolItem on @toolbar, or %NULL if there
2996 * isn't an @n<!-- -->'th item.
3001 gtk_toolbar_get_nth_item (GtkToolbar *toolbar,
3004 GtkToolbarPrivate *priv;
3005 ToolbarContent *content;
3008 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), NULL);
3010 if (!gtk_toolbar_check_new_api (toolbar))
3013 n_items = gtk_toolbar_get_n_items (toolbar);
3015 if (n < 0 || n >= n_items)
3018 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3020 content = g_list_nth_data (priv->content, logical_to_physical (toolbar, n));
3023 g_assert (!toolbar_content_is_placeholder (content));
3025 return GTK_TOOL_ITEM (toolbar_content_get_widget (content));
3029 * gtk_toolbar_get_icon_size:
3030 * @toolbar: a #GtkToolbar
3032 * Retrieves the icon size for the toolbar. See gtk_toolbar_set_icon_size().
3034 * Return value: the current icon size for the icons on the toolbar.
3037 gtk_toolbar_get_icon_size (GtkToolbar *toolbar)
3039 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), DEFAULT_ICON_SIZE);
3041 return toolbar->icon_size;
3045 * gtk_toolbar_get_relief_style:
3046 * @toolbar: a #GtkToolbar
3048 * Returns the relief style of buttons on @toolbar. See
3049 * gtk_button_set_relief().
3051 * Return value: The relief style of buttons on @toolbar.
3056 gtk_toolbar_get_relief_style (GtkToolbar *toolbar)
3058 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), GTK_RELIEF_NONE);
3060 return get_button_relief (toolbar);
3064 * gtk_toolbar_set_show_arrow:
3065 * @toolbar: a #GtkToolbar
3066 * @show_arrow: Whether to show an overflow menu
3068 * Sets whether to show an overflow menu when
3069 * @toolbar doesn't have room for all items on it. If %TRUE,
3070 * items that there are not room are available through an
3076 gtk_toolbar_set_show_arrow (GtkToolbar *toolbar,
3077 gboolean show_arrow)
3079 GtkToolbarPrivate *priv;
3081 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3083 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3084 show_arrow = show_arrow != FALSE;
3086 if (priv->show_arrow != show_arrow)
3088 priv->show_arrow = show_arrow;
3090 if (!priv->show_arrow)
3091 gtk_widget_hide (priv->arrow_button);
3093 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3094 g_object_notify (G_OBJECT (toolbar), "show-arrow");
3099 * gtk_toolbar_get_show_arrow:
3100 * @toolbar: a #GtkToolbar
3102 * Returns whether the toolbar has an overflow menu.
3103 * See gtk_toolbar_set_show_arrow().
3105 * Return value: %TRUE if the toolbar has an overflow menu.
3110 gtk_toolbar_get_show_arrow (GtkToolbar *toolbar)
3112 GtkToolbarPrivate *priv;
3114 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), FALSE);
3116 if (!gtk_toolbar_check_new_api (toolbar))
3119 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3121 return priv->show_arrow;
3125 * gtk_toolbar_get_drop_index:
3126 * @toolbar: a #GtkToolbar
3127 * @x: x coordinate of a point on the toolbar
3128 * @y: y coordinate of a point on the toolbar
3130 * Returns the position corresponding to the indicated point on
3131 * @toolbar. This is useful when dragging items to the toolbar:
3132 * this function returns the position a new item should be
3135 * @x and @y are in @toolbar coordinates.
3137 * Return value: The position corresponding to the point (@x, @y) on the toolbar.
3142 gtk_toolbar_get_drop_index (GtkToolbar *toolbar,
3146 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
3148 if (!gtk_toolbar_check_new_api (toolbar))
3151 return physical_to_logical (toolbar, find_drop_index (toolbar, x, y));
3155 gtk_toolbar_finalize (GObject *object)
3158 GtkToolbar *toolbar = GTK_TOOLBAR (object);
3159 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3161 if (toolbar->tooltips)
3162 g_object_unref (toolbar->tooltips);
3164 if (priv->arrow_button)
3165 gtk_widget_unparent (priv->arrow_button);
3167 for (list = priv->content; list != NULL; list = list->next)
3169 ToolbarContent *content = list->data;
3171 toolbar_content_free (content);
3174 g_list_free (priv->content);
3175 g_list_free (toolbar->children);
3177 g_timer_destroy (priv->timer);
3180 gtk_widget_destroy (GTK_WIDGET (priv->menu));
3183 g_source_remove (priv->idle_id);
3185 G_OBJECT_CLASS (gtk_toolbar_parent_class)->finalize (object);
3189 * gtk_toolbar_set_icon_size:
3190 * @toolbar: A #GtkToolbar
3191 * @icon_size: The #GtkIconSize that stock icons in the toolbar shall have.
3193 * This function sets the size of stock icons in the toolbar. You
3194 * can call it both before you add the icons and after they've been
3195 * added. The size you set will override user preferences for the default
3198 * This should only be used for special-purpose toolbars, normal
3199 * application toolbars should respect the user preferences for the
3203 gtk_toolbar_set_icon_size (GtkToolbar *toolbar,
3204 GtkIconSize icon_size)
3206 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3207 g_return_if_fail (icon_size != GTK_ICON_SIZE_INVALID);
3209 if (!toolbar->icon_size_set)
3211 toolbar->icon_size_set = TRUE;
3212 g_object_notify (G_OBJECT (toolbar), "icon-size-set");
3215 if (toolbar->icon_size == icon_size)
3218 toolbar->icon_size = icon_size;
3219 g_object_notify (G_OBJECT (toolbar), "icon-size");
3221 gtk_toolbar_reconfigured (toolbar);
3223 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3227 * gtk_toolbar_unset_icon_size:
3228 * @toolbar: a #GtkToolbar
3230 * Unsets toolbar icon size set with gtk_toolbar_set_icon_size(), so that
3231 * user preferences will be used to determine the icon size.
3234 gtk_toolbar_unset_icon_size (GtkToolbar *toolbar)
3238 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3240 if (toolbar->icon_size_set)
3242 GtkSettings *settings = toolbar_get_settings (toolbar);
3246 g_object_get (settings,
3247 "gtk-toolbar-icon-size", &size,
3251 size = DEFAULT_ICON_SIZE;
3253 if (size != toolbar->icon_size)
3255 gtk_toolbar_set_icon_size (toolbar, size);
3256 g_object_notify (G_OBJECT (toolbar), "icon-size");
3259 toolbar->icon_size_set = FALSE;
3260 g_object_notify (G_OBJECT (toolbar), "icon-size-set");
3269 * gtk_toolbar_append_item:
3270 * @toolbar: a #GtkToolbar.
3271 * @text: give your toolbar button a label.
3272 * @tooltip_text: a string that appears when the user holds the mouse over this item.
3273 * @tooltip_private_text: use with #GtkTipsQuery.
3274 * @icon: a #GtkWidget that should be used as the button's icon.
3275 * @callback: the function to be executed when the button is pressed.
3276 * @user_data: a pointer to any data you wish to be passed to the callback.
3278 * Inserts a new item into the toolbar. You must specify the position
3279 * in the toolbar where it will be inserted.
3281 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3282 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3284 * Return value: the new toolbar item as a #GtkWidget.
3287 gtk_toolbar_append_item (GtkToolbar *toolbar,
3289 const char *tooltip_text,
3290 const char *tooltip_private_text,
3292 GtkSignalFunc callback,
3295 return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
3297 tooltip_text, tooltip_private_text,
3298 icon, callback, user_data,
3299 toolbar->num_children);
3303 * gtk_toolbar_prepend_item:
3304 * @toolbar: a #GtkToolbar.
3305 * @text: give your toolbar button a label.
3306 * @tooltip_text: a string that appears when the user holds the mouse over this item.
3307 * @tooltip_private_text: use with #GtkTipsQuery.
3308 * @icon: a #GtkWidget that should be used as the button's icon.
3309 * @callback: the function to be executed when the button is pressed.
3310 * @user_data: a pointer to any data you wish to be passed to the callback.
3312 * Adds a new button to the beginning (top or left edges) of the given toolbar.
3314 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3315 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3317 * Return value: the new toolbar item as a #GtkWidget.
3320 gtk_toolbar_prepend_item (GtkToolbar *toolbar,
3322 const char *tooltip_text,
3323 const char *tooltip_private_text,
3325 GtkSignalFunc callback,
3328 return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
3330 tooltip_text, tooltip_private_text,
3331 icon, callback, user_data,
3336 * gtk_toolbar_insert_item:
3337 * @toolbar: a #GtkToolbar.
3338 * @text: give your toolbar button a label.
3339 * @tooltip_text: a string that appears when the user holds the mouse over this item.
3340 * @tooltip_private_text: use with #GtkTipsQuery.
3341 * @icon: a #GtkWidget that should be used as the button's icon.
3342 * @callback: the function to be executed when the button is pressed.
3343 * @user_data: a pointer to any data you wish to be passed to the callback.
3344 * @position: the number of widgets to insert this item after.
3346 * Inserts a new item into the toolbar. You must specify the position in the
3347 * toolbar where it will be inserted.
3349 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3350 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3352 * Return value: the new toolbar item as a #GtkWidget.
3355 gtk_toolbar_insert_item (GtkToolbar *toolbar,
3357 const char *tooltip_text,
3358 const char *tooltip_private_text,
3360 GtkSignalFunc callback,
3364 return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
3366 tooltip_text, tooltip_private_text,
3367 icon, callback, user_data,
3372 * gtk_toolbar_insert_stock:
3373 * @toolbar: A #GtkToolbar
3374 * @stock_id: The id of the stock item you want to insert
3375 * @tooltip_text: The text in the tooltip of the toolbar button
3376 * @tooltip_private_text: The private text of the tooltip
3377 * @callback: The callback called when the toolbar button is clicked.
3378 * @user_data: user data passed to callback
3379 * @position: The position the button shall be inserted at.
3380 * -1 means at the end.
3382 * Inserts a stock item at the specified position of the toolbar. If
3383 * @stock_id is not a known stock item ID, it's inserted verbatim,
3384 * except that underscores used to mark mnemonics are removed.
3386 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3387 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3389 * Returns: the inserted widget
3392 gtk_toolbar_insert_stock (GtkToolbar *toolbar,
3393 const gchar *stock_id,
3394 const char *tooltip_text,
3395 const char *tooltip_private_text,
3396 GtkSignalFunc callback,
3400 return internal_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
3402 tooltip_text, tooltip_private_text,
3403 NULL, callback, user_data,
3408 * gtk_toolbar_append_space:
3409 * @toolbar: a #GtkToolbar.
3411 * Adds a new space to the end of the toolbar.
3414 gtk_toolbar_append_space (GtkToolbar *toolbar)
3416 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_SPACE,
3420 toolbar->num_children);
3424 * gtk_toolbar_prepend_space:
3425 * @toolbar: a #GtkToolbar.
3427 * Adds a new space to the beginning of the toolbar.
3430 gtk_toolbar_prepend_space (GtkToolbar *toolbar)
3432 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_SPACE,
3440 * gtk_toolbar_insert_space:
3441 * @toolbar: a #GtkToolbar
3442 * @position: the number of widgets after which a space should be inserted.
3444 * Inserts a new space in the toolbar at the specified position.
3447 gtk_toolbar_insert_space (GtkToolbar *toolbar,
3450 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_SPACE,
3458 * gtk_toolbar_remove_space:
3459 * @toolbar: a #GtkToolbar.
3460 * @position: the index of the space to remove.
3462 * Removes a space from the specified position.
3465 gtk_toolbar_remove_space (GtkToolbar *toolbar,
3468 GtkToolbarPrivate *priv;
3469 ToolbarContent *content;
3471 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3473 if (!gtk_toolbar_check_old_api (toolbar))
3476 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3478 content = g_list_nth_data (priv->content, position);
3482 g_warning ("Toolbar position %d doesn't exist", position);
3486 if (!toolbar_content_is_separator (content))
3488 g_warning ("Toolbar position %d is not a space", position);
3492 toolbar_content_remove (content, toolbar);
3493 toolbar_content_free (content);
3497 * gtk_toolbar_append_widget:
3498 * @toolbar: a #GtkToolbar.
3499 * @widget: a #GtkWidget to add to the toolbar.
3500 * @tooltip_text: the element's tooltip.
3501 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3503 * Adds a widget to the end of the given toolbar.
3506 gtk_toolbar_append_widget (GtkToolbar *toolbar,
3508 const gchar *tooltip_text,
3509 const gchar *tooltip_private_text)
3511 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_WIDGET,
3513 tooltip_text, tooltip_private_text,
3515 toolbar->num_children);
3519 * gtk_toolbar_prepend_widget:
3520 * @toolbar: a #GtkToolbar.
3521 * @widget: a #GtkWidget to add to the toolbar.
3522 * @tooltip_text: the element's tooltip.
3523 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3525 * Adds a widget to the beginning of the given toolbar.
3528 gtk_toolbar_prepend_widget (GtkToolbar *toolbar,
3530 const gchar *tooltip_text,
3531 const gchar *tooltip_private_text)
3533 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_WIDGET,
3535 tooltip_text, tooltip_private_text,
3541 * gtk_toolbar_insert_widget:
3542 * @toolbar: a #GtkToolbar.
3543 * @widget: a #GtkWidget to add to the toolbar.
3544 * @tooltip_text: the element's tooltip.
3545 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3546 * @position: the number of widgets to insert this widget after.
3548 * Inserts a widget in the toolbar at the given position.
3551 gtk_toolbar_insert_widget (GtkToolbar *toolbar,
3553 const char *tooltip_text,
3554 const char *tooltip_private_text,
3557 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_WIDGET,
3559 tooltip_text, tooltip_private_text,
3565 * gtk_toolbar_append_element:
3566 * @toolbar: a #GtkToolbar.
3567 * @type: a value of type #GtkToolbarChildType that determines what @widget will be.
3568 * @widget: a #GtkWidget, or %NULL.
3569 * @text: the element's label.
3570 * @tooltip_text: the element's tooltip.
3571 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3572 * @icon: a #GtkWidget that provides pictorial representation of the element's function.
3573 * @callback: the function to be executed when the button is pressed.
3574 * @user_data: any data you wish to pass to the callback.
3576 * Adds a new element to the end of a toolbar.
3578 * If @type == %GTK_TOOLBAR_CHILD_WIDGET, @widget is used as the new element.
3579 * If @type == %GTK_TOOLBAR_CHILD_RADIOBUTTON, @widget is used to determine
3580 * the radio group for the new element. In all other cases, @widget must
3583 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3584 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3586 * Return value: the new toolbar element as a #GtkWidget.
3589 gtk_toolbar_append_element (GtkToolbar *toolbar,
3590 GtkToolbarChildType type,
3593 const char *tooltip_text,
3594 const char *tooltip_private_text,
3596 GtkSignalFunc callback,
3599 return gtk_toolbar_insert_element (toolbar, type, widget, text,
3600 tooltip_text, tooltip_private_text,
3601 icon, callback, user_data,
3602 toolbar->num_children);
3606 * gtk_toolbar_prepend_element:
3607 * @toolbar: a #GtkToolbar.
3608 * @type: a value of type #GtkToolbarChildType that determines what @widget will be.
3609 * @widget: a #GtkWidget, or %NULL
3610 * @text: the element's label.
3611 * @tooltip_text: the element's tooltip.
3612 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3613 * @icon: a #GtkWidget that provides pictorial representation of the element's function.
3614 * @callback: the function to be executed when the button is pressed.
3615 * @user_data: any data you wish to pass to the callback.
3617 * Adds a new element to the beginning of a toolbar.
3619 * If @type == %GTK_TOOLBAR_CHILD_WIDGET, @widget is used as the new element.
3620 * If @type == %GTK_TOOLBAR_CHILD_RADIOBUTTON, @widget is used to determine
3621 * the radio group for the new element. In all other cases, @widget must
3624 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3625 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3627 * Return value: the new toolbar element as a #GtkWidget.
3630 gtk_toolbar_prepend_element (GtkToolbar *toolbar,
3631 GtkToolbarChildType type,
3634 const char *tooltip_text,
3635 const char *tooltip_private_text,
3637 GtkSignalFunc callback,
3640 return gtk_toolbar_insert_element (toolbar, type, widget, text,
3641 tooltip_text, tooltip_private_text,
3642 icon, callback, user_data, 0);
3646 * gtk_toolbar_insert_element:
3647 * @toolbar: a #GtkToolbar.
3648 * @type: a value of type #GtkToolbarChildType that determines what @widget
3650 * @widget: a #GtkWidget, or %NULL.
3651 * @text: the element's label.
3652 * @tooltip_text: the element's tooltip.
3653 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3654 * @icon: a #GtkWidget that provides pictorial representation of the element's function.
3655 * @callback: the function to be executed when the button is pressed.
3656 * @user_data: any data you wish to pass to the callback.
3657 * @position: the number of widgets to insert this element after.
3659 * Inserts a new element in the toolbar at the given position.
3661 * If @type == %GTK_TOOLBAR_CHILD_WIDGET, @widget is used as the new element.
3662 * If @type == %GTK_TOOLBAR_CHILD_RADIOBUTTON, @widget is used to determine
3663 * the radio group for the new element. In all other cases, @widget must
3666 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3667 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3669 * Return value: the new toolbar element as a #GtkWidget.
3672 gtk_toolbar_insert_element (GtkToolbar *toolbar,
3673 GtkToolbarChildType type,
3676 const char *tooltip_text,
3677 const char *tooltip_private_text,
3679 GtkSignalFunc callback,
3683 return internal_insert_element (toolbar, type, widget, text,
3684 tooltip_text, tooltip_private_text,
3685 icon, callback, user_data, position, FALSE);
3689 set_child_packing_and_visibility(GtkToolbar *toolbar,
3690 GtkToolbarChild *child)
3695 box = gtk_bin_get_child (GTK_BIN (child->widget));
3697 g_return_if_fail (GTK_IS_BOX (box));
3701 expand = (toolbar->style != GTK_TOOLBAR_BOTH);
3703 gtk_box_set_child_packing (GTK_BOX (box), child->label,
3704 expand, expand, 0, GTK_PACK_END);
3706 if (toolbar->style != GTK_TOOLBAR_ICONS)
3707 gtk_widget_show (child->label);
3709 gtk_widget_hide (child->label);
3714 expand = (toolbar->style != GTK_TOOLBAR_BOTH_HORIZ);
3716 gtk_box_set_child_packing (GTK_BOX (box), child->icon,
3717 expand, expand, 0, GTK_PACK_END);
3719 if (toolbar->style != GTK_TOOLBAR_TEXT)
3720 gtk_widget_show (child->icon);
3722 gtk_widget_hide (child->icon);
3727 internal_insert_element (GtkToolbar *toolbar,
3728 GtkToolbarChildType type,
3731 const char *tooltip_text,
3732 const char *tooltip_private_text,
3734 GtkSignalFunc callback,
3740 char *free_me = NULL;
3742 GtkWidget *child_widget;
3743 GtkWidget *child_label;
3744 GtkWidget *child_icon;
3746 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), NULL);
3747 if (type == GTK_TOOLBAR_CHILD_WIDGET)
3748 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3749 else if (type != GTK_TOOLBAR_CHILD_RADIOBUTTON)
3750 g_return_val_if_fail (widget == NULL, NULL);
3751 if (GTK_IS_TOOL_ITEM (widget))
3752 g_warning (MIXED_API_WARNING);
3754 if (!gtk_toolbar_check_old_api (toolbar))
3757 child_widget = NULL;
3763 case GTK_TOOLBAR_CHILD_SPACE:
3766 case GTK_TOOLBAR_CHILD_WIDGET:
3767 child_widget = widget;
3770 case GTK_TOOLBAR_CHILD_BUTTON:
3771 case GTK_TOOLBAR_CHILD_TOGGLEBUTTON:
3772 case GTK_TOOLBAR_CHILD_RADIOBUTTON:
3773 if (type == GTK_TOOLBAR_CHILD_BUTTON)
3775 child_widget = gtk_button_new ();
3777 else if (type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
3779 child_widget = gtk_toggle_button_new ();
3780 gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (child_widget), FALSE);
3782 else /* type == GTK_TOOLBAR_CHILD_RADIOBUTTON */
3784 GSList *group = NULL;
3787 group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (widget));
3789 child_widget = gtk_radio_button_new (group);
3790 gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (child_widget), FALSE);
3793 gtk_button_set_relief (GTK_BUTTON (child_widget), get_button_relief (toolbar));
3794 gtk_button_set_focus_on_click (GTK_BUTTON (child_widget), FALSE);
3798 g_signal_connect (child_widget, "clicked",
3799 callback, user_data);
3802 if (toolbar->style == GTK_TOOLBAR_BOTH_HORIZ)
3803 box = gtk_hbox_new (FALSE, 0);
3805 box = gtk_vbox_new (FALSE, 0);
3807 gtk_container_add (GTK_CONTAINER (child_widget), box);
3808 gtk_widget_show (box);
3810 if (text && use_stock)
3812 GtkStockItem stock_item;
3813 if (gtk_stock_lookup (text, &stock_item))
3816 icon = gtk_image_new_from_stock (text, toolbar->icon_size);
3818 text = free_me = _gtk_toolbar_elide_underscores (stock_item.label);
3824 child_label = gtk_label_new (text);
3826 gtk_container_add (GTK_CONTAINER (box), child_label);
3831 child_icon = GTK_WIDGET (icon);
3832 gtk_container_add (GTK_CONTAINER (box), child_icon);
3835 gtk_widget_show (child_widget);
3839 g_assert_not_reached ();
3843 if ((type != GTK_TOOLBAR_CHILD_SPACE) && tooltip_text)
3845 gtk_tooltips_set_tip (toolbar->tooltips, child_widget,
3846 tooltip_text, tooltip_private_text);
3852 return child_widget;
3856 * ToolbarContent methods
3864 struct _ToolbarContent
3874 GtkAllocation start_allocation;
3875 GtkAllocation goal_allocation;
3876 guint is_placeholder : 1;
3877 guint disappearing : 1;
3878 TriState has_menu : 2;
3883 GtkToolbarChild child;
3884 GtkAllocation space_allocation;
3885 guint space_visible : 1;
3890 static ToolbarContent *
3891 toolbar_content_new_tool_item (GtkToolbar *toolbar,
3893 gboolean is_placeholder,
3896 ToolbarContent *content;
3897 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3899 content = g_new0 (ToolbarContent, 1);
3901 content->type = TOOL_ITEM;
3902 content->state = NOT_ALLOCATED;
3903 content->u.tool_item.item = item;
3904 content->u.tool_item.is_placeholder = is_placeholder;
3906 gtk_widget_set_parent (GTK_WIDGET (item), GTK_WIDGET (toolbar));
3908 priv->content = g_list_insert (priv->content, content, pos);
3910 if (!is_placeholder)
3912 toolbar->num_children++;
3914 gtk_toolbar_stop_sliding (toolbar);
3917 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3918 priv->need_rebuild = TRUE;
3924 toolbar_content_remove (ToolbarContent *content,
3925 GtkToolbar *toolbar)
3927 GtkToolbarChild *child;
3928 GtkToolbarPrivate *priv;
3930 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3932 switch (content->type)
3935 gtk_widget_unparent (GTK_WIDGET (content->u.tool_item.item));
3939 child = &(content->u.compatibility.child);
3941 if (child->type != GTK_TOOLBAR_CHILD_SPACE)
3943 g_object_ref (child->widget);
3944 gtk_widget_unparent (child->widget);
3945 gtk_widget_destroy (child->widget);
3946 g_object_unref (child->widget);
3949 toolbar->children = g_list_remove (toolbar->children, child);
3953 priv->content = g_list_remove (priv->content, content);
3955 if (!toolbar_content_is_placeholder (content))
3956 toolbar->num_children--;
3958 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3959 priv->need_rebuild = TRUE;
3963 toolbar_content_free (ToolbarContent *content)
3969 calculate_max_homogeneous_pixels (GtkWidget *widget)
3971 PangoContext *context;
3972 PangoFontMetrics *metrics;
3975 context = gtk_widget_get_pango_context (widget);
3976 metrics = pango_context_get_metrics (context,
3977 widget->style->font_desc,
3978 pango_context_get_language (context));
3979 char_width = pango_font_metrics_get_approximate_char_width (metrics);
3980 pango_font_metrics_unref (metrics);
3982 return PANGO_PIXELS (MAX_HOMOGENEOUS_N_CHARS * char_width);
3986 toolbar_content_expose (ToolbarContent *content,
3987 GtkContainer *container,
3988 GdkEventExpose *expose)
3990 GtkToolbar *toolbar = GTK_TOOLBAR (container);
3991 GtkToolbarChild *child;
3992 GtkWidget *widget = NULL; /* quiet gcc */
3994 switch (content->type)
3997 if (!content->u.tool_item.is_placeholder)
3998 widget = GTK_WIDGET (content->u.tool_item.item);
4002 child = &(content->u.compatibility.child);
4004 if (child->type == GTK_TOOLBAR_CHILD_SPACE)
4006 if (content->u.compatibility.space_visible &&
4007 get_space_style (toolbar) == GTK_TOOLBAR_SPACE_LINE)
4008 _gtk_toolbar_paint_space_line (GTK_WIDGET (toolbar), toolbar,
4010 &content->u.compatibility.space_allocation);
4014 widget = child->widget;
4019 gtk_container_propagate_expose (container, widget, expose);
4023 toolbar_content_visible (ToolbarContent *content,
4024 GtkToolbar *toolbar)
4028 switch (content->type)
4031 item = content->u.tool_item.item;
4033 if (!GTK_WIDGET_VISIBLE (item))
4036 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL &&
4037 gtk_tool_item_get_visible_horizontal (item))
4040 if ((toolbar->orientation == GTK_ORIENTATION_VERTICAL &&
4041 gtk_tool_item_get_visible_vertical (item)))
4048 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
4049 return GTK_WIDGET_VISIBLE (content->u.compatibility.child.widget);
4055 g_assert_not_reached ();
4060 toolbar_content_size_request (ToolbarContent *content,
4061 GtkToolbar *toolbar,
4062 GtkRequisition *requisition)
4066 switch (content->type)
4069 gtk_widget_size_request (GTK_WIDGET (content->u.tool_item.item),
4071 if (content->u.tool_item.is_placeholder &&
4072 content->u.tool_item.disappearing)
4074 requisition->width = 0;
4075 requisition->height = 0;
4080 space_size = get_space_size (toolbar);
4082 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
4084 gtk_widget_size_request (content->u.compatibility.child.widget,
4089 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
4091 requisition->width = space_size;
4092 requisition->height = 0;
4096 requisition->height = space_size;
4097 requisition->width = 0;
4106 toolbar_content_is_homogeneous (ToolbarContent *content,
4107 GtkToolbar *toolbar)
4109 gboolean result = FALSE; /* quiet gcc */
4110 GtkRequisition requisition;
4111 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
4113 if (priv->max_homogeneous_pixels < 0)
4115 priv->max_homogeneous_pixels =
4116 calculate_max_homogeneous_pixels (GTK_WIDGET (toolbar));
4119 toolbar_content_size_request (content, toolbar, &requisition);
4121 if (requisition.width > priv->max_homogeneous_pixels)
4124 switch (content->type)
4127 result = gtk_tool_item_get_homogeneous (content->u.tool_item.item) &&
4128 !GTK_IS_SEPARATOR_TOOL_ITEM (content->u.tool_item.item);
4130 if (gtk_tool_item_get_is_important (content->u.tool_item.item) &&
4131 toolbar->style == GTK_TOOLBAR_BOTH_HORIZ &&
4132 toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
4139 if (content->u.compatibility.child.type == GTK_TOOLBAR_CHILD_BUTTON ||
4140 content->u.compatibility.child.type == GTK_TOOLBAR_CHILD_RADIOBUTTON ||
4141 content->u.compatibility.child.type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
4156 toolbar_content_is_placeholder (ToolbarContent *content)
4158 if (content->type == TOOL_ITEM && content->u.tool_item.is_placeholder)
4165 toolbar_content_disappearing (ToolbarContent *content)
4167 if (content->type == TOOL_ITEM && content->u.tool_item.disappearing)
4174 toolbar_content_get_state (ToolbarContent *content)
4176 return content->state;
4180 toolbar_content_child_visible (ToolbarContent *content)
4182 switch (content->type)
4185 return GTK_WIDGET_CHILD_VISIBLE (content->u.tool_item.item);
4189 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
4191 return GTK_WIDGET_CHILD_VISIBLE (content->u.compatibility.child.widget);
4195 return content->u.compatibility.space_visible;
4200 return FALSE; /* quiet gcc */
4204 toolbar_content_get_goal_allocation (ToolbarContent *content,
4205 GtkAllocation *allocation)
4207 switch (content->type)
4210 *allocation = content->u.tool_item.goal_allocation;
4214 /* Goal allocations are only relevant when we are
4215 * using the new API, so we should never get here
4217 g_assert_not_reached ();
4223 toolbar_content_get_allocation (ToolbarContent *content,
4224 GtkAllocation *allocation)
4226 GtkToolbarChild *child;
4228 switch (content->type)
4231 *allocation = GTK_WIDGET (content->u.tool_item.item)->allocation;
4235 child = &(content->u.compatibility.child);
4237 if (child->type == GTK_TOOLBAR_CHILD_SPACE)
4238 *allocation = content->u.compatibility.space_allocation;
4240 *allocation = child->widget->allocation;
4246 toolbar_content_set_start_allocation (ToolbarContent *content,
4247 GtkAllocation *allocation)
4249 switch (content->type)
4252 content->u.tool_item.start_allocation = *allocation;
4256 /* start_allocation is only relevant when using the new API */
4257 g_assert_not_reached ();
4263 toolbar_content_get_expand (ToolbarContent *content)
4265 if (content->type == TOOL_ITEM &&
4266 gtk_tool_item_get_expand (content->u.tool_item.item) &&
4267 !content->u.tool_item.disappearing)
4276 toolbar_content_set_goal_allocation (ToolbarContent *content,
4277 GtkAllocation *allocation)
4279 switch (content->type)
4282 content->u.tool_item.goal_allocation = *allocation;
4286 /* Only relevant when using new API */
4287 g_assert_not_reached ();
4293 toolbar_content_set_child_visible (ToolbarContent *content,
4294 GtkToolbar *toolbar,
4297 GtkToolbarChild *child;
4299 switch (content->type)
4302 gtk_widget_set_child_visible (GTK_WIDGET (content->u.tool_item.item),
4307 child = &(content->u.compatibility.child);
4309 if (child->type != GTK_TOOLBAR_CHILD_SPACE)
4311 gtk_widget_set_child_visible (child->widget, visible);
4315 if (content->u.compatibility.space_visible != visible)
4317 content->u.compatibility.space_visible = visible;
4318 gtk_widget_queue_draw (GTK_WIDGET (toolbar));
4326 toolbar_content_get_start_allocation (ToolbarContent *content,
4327 GtkAllocation *start_allocation)
4329 switch (content->type)
4332 *start_allocation = content->u.tool_item.start_allocation;
4336 /* Only relevant for new API */
4337 g_assert_not_reached ();
4343 toolbar_content_size_allocate (ToolbarContent *content,
4344 GtkAllocation *allocation)
4346 switch (content->type)
4349 gtk_widget_size_allocate (GTK_WIDGET (content->u.tool_item.item),
4354 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
4356 gtk_widget_size_allocate (content->u.compatibility.child.widget,
4361 content->u.compatibility.space_allocation = *allocation;
4368 toolbar_content_set_state (ToolbarContent *content,
4371 content->state = state;
4375 toolbar_content_get_widget (ToolbarContent *content)
4377 GtkToolbarChild *child;
4379 switch (content->type)
4382 return GTK_WIDGET (content->u.tool_item.item);
4386 child = &(content->u.compatibility.child);
4387 if (child->type != GTK_TOOLBAR_CHILD_SPACE)
4388 return child->widget;
4398 toolbar_content_set_disappearing (ToolbarContent *content,
4399 gboolean disappearing)
4401 switch (content->type)
4404 content->u.tool_item.disappearing = disappearing;
4408 /* Only relevant for new API */
4409 g_assert_not_reached ();
4415 toolbar_content_set_size_request (ToolbarContent *content,
4419 switch (content->type)
4422 gtk_widget_set_size_request (GTK_WIDGET (content->u.tool_item.item),
4427 /* Setting size requests only happens with sliding,
4428 * so not relevant here
4430 g_assert_not_reached ();
4436 toolbar_child_reconfigure (GtkToolbar *toolbar,
4437 GtkToolbarChild *child)
4441 GtkToolbarStyle style;
4442 GtkIconSize icon_size;
4443 GtkReliefStyle relief;
4446 style = gtk_toolbar_get_style (toolbar);
4447 icon_size = gtk_toolbar_get_icon_size (toolbar);
4448 relief = gtk_toolbar_get_relief_style (toolbar);
4451 if (child->type == GTK_TOOLBAR_CHILD_BUTTON ||
4452 child->type == GTK_TOOLBAR_CHILD_RADIOBUTTON ||
4453 child->type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
4455 box = gtk_bin_get_child (GTK_BIN (child->widget));
4457 if (style == GTK_TOOLBAR_BOTH && GTK_IS_HBOX (box))
4461 vbox = gtk_vbox_new (FALSE, 0);
4464 gtk_widget_reparent (child->label, vbox);
4466 gtk_widget_reparent (child->icon, vbox);
4468 gtk_widget_destroy (box);
4469 gtk_container_add (GTK_CONTAINER (child->widget), vbox);
4471 gtk_widget_show (vbox);
4473 else if (style == GTK_TOOLBAR_BOTH_HORIZ && GTK_IS_VBOX (box))
4477 hbox = gtk_hbox_new (FALSE, 0);
4480 gtk_widget_reparent (child->label, hbox);
4482 gtk_widget_reparent (child->icon, hbox);
4484 gtk_widget_destroy (box);
4485 gtk_container_add (GTK_CONTAINER (child->widget), hbox);
4487 gtk_widget_show (hbox);
4490 set_child_packing_and_visibility (toolbar, child);
4495 if ((child->type == GTK_TOOLBAR_CHILD_BUTTON ||
4496 child->type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON ||
4497 child->type == GTK_TOOLBAR_CHILD_RADIOBUTTON) &&
4498 GTK_IS_IMAGE (child->icon))
4500 image = GTK_IMAGE (child->icon);
4501 if (gtk_image_get_storage_type (image) == GTK_IMAGE_STOCK)
4503 gtk_image_get_stock (image, &stock_id, NULL);
4504 stock_id = g_strdup (stock_id);
4505 gtk_image_set_from_stock (image,
4513 if (child->type == GTK_TOOLBAR_CHILD_BUTTON ||
4514 child->type == GTK_TOOLBAR_CHILD_RADIOBUTTON ||
4515 child->type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
4517 gtk_button_set_relief (GTK_BUTTON (child->widget), relief);
4522 toolbar_content_toolbar_reconfigured (ToolbarContent *content,
4523 GtkToolbar *toolbar)
4525 switch (content->type)
4528 _gtk_tool_item_toolbar_reconfigured (content->u.tool_item.item);
4532 toolbar_child_reconfigure (toolbar, &(content->u.compatibility.child));
4538 toolbar_content_retrieve_menu_item (ToolbarContent *content)
4540 if (content->type == TOOL_ITEM)
4541 return gtk_tool_item_retrieve_proxy_menu_item (content->u.tool_item.item);
4543 /* FIXME - we might actually be able to do something meaningful here */
4548 toolbar_content_has_proxy_menu_item (ToolbarContent *content)
4550 if (content->type == TOOL_ITEM)
4552 GtkWidget *menu_item;
4554 if (content->u.tool_item.has_menu == YES)
4556 else if (content->u.tool_item.has_menu == NO)
4559 menu_item = toolbar_content_retrieve_menu_item (content);
4561 content->u.tool_item.has_menu = menu_item? YES : NO;
4563 return menu_item != NULL;
4572 toolbar_content_set_unknown_menu_status (ToolbarContent *content)
4574 if (content->type == TOOL_ITEM)
4575 content->u.tool_item.has_menu = UNKNOWN;
4579 toolbar_content_is_separator (ToolbarContent *content)
4581 GtkToolbarChild *child;
4583 switch (content->type)
4586 return GTK_IS_SEPARATOR_TOOL_ITEM (content->u.tool_item.item);
4590 child = &(content->u.compatibility.child);
4591 return (child->type == GTK_TOOLBAR_CHILD_SPACE);
4599 toolbar_content_set_expand (ToolbarContent *content,
4602 if (content->type == TOOL_ITEM)
4603 gtk_tool_item_set_expand (content->u.tool_item.item, expand);
4607 ignore_show_and_hide_all (ToolbarContent *content)
4609 if (content->type == COMPATIBILITY)
4611 GtkToolbarChildType type = content->u.compatibility.child.type;
4613 if (type == GTK_TOOLBAR_CHILD_BUTTON ||
4614 type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON ||
4615 type == GTK_TOOLBAR_CHILD_RADIOBUTTON)
4625 toolbar_content_show_all (ToolbarContent *content)
4629 if (ignore_show_and_hide_all (content))
4632 widget = toolbar_content_get_widget (content);
4634 gtk_widget_show_all (widget);
4638 toolbar_content_hide_all (ToolbarContent *content)
4642 if (ignore_show_and_hide_all (content))
4645 widget = toolbar_content_get_widget (content);
4647 gtk_widget_hide_all (widget);
4654 get_space_size (GtkToolbar *toolbar)
4656 gint space_size = DEFAULT_SPACE_SIZE;
4660 gtk_widget_style_get (GTK_WIDGET (toolbar),
4661 "space-size", &space_size,
4668 static GtkToolbarSpaceStyle
4669 get_space_style (GtkToolbar *toolbar)
4671 GtkToolbarSpaceStyle space_style = DEFAULT_SPACE_STYLE;
4675 gtk_widget_style_get (GTK_WIDGET (toolbar),
4676 "space-style", &space_style,
4683 static GtkReliefStyle
4684 get_button_relief (GtkToolbar *toolbar)
4686 GtkReliefStyle button_relief = GTK_RELIEF_NORMAL;
4688 gtk_widget_ensure_style (GTK_WIDGET (toolbar));
4690 gtk_widget_style_get (GTK_WIDGET (toolbar),
4691 "button-relief", &button_relief,
4694 return button_relief;
4698 get_internal_padding (GtkToolbar *toolbar)
4702 gtk_widget_style_get (GTK_WIDGET (toolbar),
4703 "internal-padding", &ipadding,
4710 get_max_child_expand (GtkToolbar *toolbar)
4712 gint mexpand = G_MAXINT;
4714 gtk_widget_style_get (GTK_WIDGET (toolbar),
4715 "max-child-expand", &mexpand,
4720 static GtkShadowType
4721 get_shadow_type (GtkToolbar *toolbar)
4723 GtkShadowType shadow_type;
4725 gtk_widget_style_get (GTK_WIDGET (toolbar),
4726 "shadow-type", &shadow_type,
4736 gtk_toolbar_check_old_api (GtkToolbar *toolbar)
4738 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
4740 if (priv->api_mode == NEW_API)
4742 g_warning (MIXED_API_WARNING);
4746 priv->api_mode = OLD_API;
4751 gtk_toolbar_check_new_api (GtkToolbar *toolbar)
4753 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
4755 if (priv->api_mode == OLD_API)
4757 g_warning (MIXED_API_WARNING);
4761 priv->api_mode = NEW_API;
4765 /* GTK+ internal methods */
4768 _gtk_toolbar_get_default_space_size (void)
4770 return DEFAULT_SPACE_SIZE;
4774 _gtk_toolbar_paint_space_line (GtkWidget *widget,
4775 GtkToolbar *toolbar,
4777 GtkAllocation *allocation)
4779 const double start_fraction = (SPACE_LINE_START / SPACE_LINE_DIVISION);
4780 const double end_fraction = (SPACE_LINE_END / SPACE_LINE_DIVISION);
4782 GtkOrientation orientation;
4784 g_return_if_fail (GTK_IS_WIDGET (widget));
4786 orientation = toolbar? toolbar->orientation : GTK_ORIENTATION_HORIZONTAL;
4788 if (orientation == GTK_ORIENTATION_HORIZONTAL)
4790 gboolean wide_separators;
4791 gint separator_width;
4793 gtk_widget_style_get (widget,
4794 "wide-separators", &wide_separators,
4795 "separator-width", &separator_width,
4798 if (wide_separators)
4799 gtk_paint_box (widget->style, widget->window,
4800 GTK_WIDGET_STATE (widget), GTK_SHADOW_ETCHED_OUT,
4801 area, widget, "vseparator",
4802 allocation->x + (allocation->width - separator_width) / 2,
4803 allocation->y + allocation->height * start_fraction,
4805 allocation->height * (end_fraction - start_fraction));
4807 gtk_paint_vline (widget->style, widget->window,
4808 GTK_WIDGET_STATE (widget), area, widget,
4810 allocation->y + allocation->height * start_fraction,
4811 allocation->y + allocation->height * end_fraction,
4812 allocation->x + (allocation->width - widget->style->xthickness) / 2);
4816 gboolean wide_separators;
4817 gint separator_height;
4819 gtk_widget_style_get (widget,
4820 "wide-separators", &wide_separators,
4821 "separator-height", &separator_height,
4824 if (wide_separators)
4825 gtk_paint_box (widget->style, widget->window,
4826 GTK_WIDGET_STATE (widget), GTK_SHADOW_ETCHED_OUT,
4827 area, widget, "hseparator",
4828 allocation->x + allocation->width * start_fraction,
4829 allocation->y + (allocation->height - separator_height) / 2,
4830 allocation->width * (end_fraction - start_fraction),
4833 gtk_paint_hline (widget->style, widget->window,
4834 GTK_WIDGET_STATE (widget), area, widget,
4836 allocation->x + allocation->width * start_fraction,
4837 allocation->x + allocation->width * end_fraction,
4838 allocation->y + (allocation->height - widget->style->ythickness) / 2);
4843 _gtk_toolbar_elide_underscores (const gchar *original)
4846 const gchar *p, *end;
4848 gboolean last_underscore;
4853 len = strlen (original);
4854 q = result = g_malloc (len + 1);
4855 last_underscore = FALSE;
4857 end = original + len;
4858 for (p = original; p < end; p++)
4860 if (!last_underscore && *p == '_')
4861 last_underscore = TRUE;
4864 last_underscore = FALSE;
4865 if (*p != '_' && original + 2 <= p && p + 1 <= end && p[-2] == '(' && p[1] == ')')
4876 if (last_underscore)
4885 _gtk_toolbar_rebuild_menu (GtkToolbar *toolbar)
4887 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
4890 priv->need_rebuild = TRUE;
4892 for (list = priv->content; list != NULL; list = list->next)
4894 ToolbarContent *content = list->data;
4896 toolbar_content_set_unknown_menu_status (content);
4899 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
4902 #define __GTK_TOOLBAR_C__
4903 #include "gtkaliasdef.c"