1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3 * GtkToolbar copyright (C) Federico Mena
5 * Copyright (C) 2002 Anders Carlsson <andersca@gnome.org>
6 * Copyright (C) 2002 James Henstridge <james@daa.com.au>
7 * Copyright (C) 2003, 2004 Soeren Sandmann <sandmann@daimi.au.dk>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the
21 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 * Boston, MA 02111-1307, USA.
26 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
27 * file for a list of people on the GTK+ Team. See the ChangeLog
28 * files for a list of changes. These files are distributed with
29 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
32 #undef GTK_DISABLE_DEPRECATED
36 #include "gtktoolbar.h"
37 #include "gtkradiotoolbutton.h"
38 #include "gtkseparatortoolitem.h"
40 #include "gtkradiobutton.h"
41 #include "gtktoolbar.h"
42 #include "gtkbindings.h"
43 #include <gdk/gdkkeysyms.h>
44 #include "gtkmarshalers.h"
48 #include "gtkprivate.h"
55 typedef struct _ToolbarContent ToolbarContent;
57 #define DEFAULT_IPADDING 0
59 #define DEFAULT_SPACE_SIZE 12
60 #define DEFAULT_SPACE_STYLE GTK_TOOLBAR_SPACE_LINE
61 #define SPACE_LINE_DIVISION 10.0
62 #define SPACE_LINE_START 2.0
63 #define SPACE_LINE_END 8.0
65 #define DEFAULT_ICON_SIZE GTK_ICON_SIZE_LARGE_TOOLBAR
66 #define DEFAULT_TOOLBAR_STYLE GTK_TOOLBAR_BOTH
68 #define MAX_HOMOGENEOUS_N_CHARS 13 /* Items that are wider than this do not participate
69 * in the homogeneous game. In units of
70 * pango_font_get_estimated_char_width().
72 #define SLIDE_SPEED 600 /* How fast the items slide, in pixels per second */
82 /* Child properties */
86 CHILD_PROP_HOMOGENEOUS
118 struct _GtkToolbarPrivate
123 GtkWidget * arrow_button;
127 GdkWindow * event_window;
129 GtkSettings * settings;
131 GtkToolItem * highlight_tool_item;
132 gint max_homogeneous_pixels;
136 guint show_arrow : 1;
138 guint is_sliding : 1;
141 static void gtk_toolbar_init (GtkToolbar *toolbar);
142 static void gtk_toolbar_class_init (GtkToolbarClass *klass);
143 static void gtk_toolbar_set_property (GObject *object,
147 static void gtk_toolbar_get_property (GObject *object,
151 static gint gtk_toolbar_expose (GtkWidget *widget,
152 GdkEventExpose *event);
153 static void gtk_toolbar_realize (GtkWidget *widget);
154 static void gtk_toolbar_unrealize (GtkWidget *widget);
155 static void gtk_toolbar_size_request (GtkWidget *widget,
156 GtkRequisition *requisition);
157 static void gtk_toolbar_size_allocate (GtkWidget *widget,
158 GtkAllocation *allocation);
159 static void gtk_toolbar_style_set (GtkWidget *widget,
160 GtkStyle *prev_style);
161 static gboolean gtk_toolbar_focus (GtkWidget *widget,
162 GtkDirectionType dir);
163 static void gtk_toolbar_screen_changed (GtkWidget *widget,
164 GdkScreen *previous_screen);
165 static void gtk_toolbar_map (GtkWidget *widget);
166 static void gtk_toolbar_unmap (GtkWidget *widget);
167 static void gtk_toolbar_set_child_property (GtkContainer *container,
172 static void gtk_toolbar_get_child_property (GtkContainer *container,
177 static void gtk_toolbar_finalize (GObject *object);
178 static void gtk_toolbar_show_all (GtkWidget *widget);
179 static void gtk_toolbar_hide_all (GtkWidget *widget);
180 static void gtk_toolbar_add (GtkContainer *container,
182 static void gtk_toolbar_remove (GtkContainer *container,
184 static void gtk_toolbar_forall (GtkContainer *container,
185 gboolean include_internals,
186 GtkCallback callback,
187 gpointer callback_data);
188 static GType gtk_toolbar_child_type (GtkContainer *container);
189 static void gtk_toolbar_orientation_changed (GtkToolbar *toolbar,
190 GtkOrientation orientation);
191 static void gtk_toolbar_real_style_changed (GtkToolbar *toolbar,
192 GtkToolbarStyle style);
193 static gboolean gtk_toolbar_move_focus (GtkToolbar *toolbar,
194 GtkDirectionType dir);
195 static gboolean gtk_toolbar_focus_home_or_end (GtkToolbar *toolbar,
196 gboolean focus_home);
197 static gboolean gtk_toolbar_button_press (GtkWidget *toolbar,
198 GdkEventButton *event);
199 static gboolean gtk_toolbar_arrow_button_press (GtkWidget *button,
200 GdkEventButton *event,
201 GtkToolbar *toolbar);
202 static void gtk_toolbar_arrow_button_clicked (GtkWidget *button,
203 GtkToolbar *toolbar);
204 static void gtk_toolbar_update_button_relief (GtkToolbar *toolbar);
205 static gboolean gtk_toolbar_popup_menu (GtkWidget *toolbar);
206 static GtkWidget *internal_insert_element (GtkToolbar *toolbar,
207 GtkToolbarChildType type,
210 const char *tooltip_text,
211 const char *tooltip_private_text,
213 GtkSignalFunc callback,
217 static void gtk_toolbar_reconfigured (GtkToolbar *toolbar);
218 static gboolean gtk_toolbar_check_new_api (GtkToolbar *toolbar);
219 static gboolean gtk_toolbar_check_old_api (GtkToolbar *toolbar);
221 static GtkReliefStyle get_button_relief (GtkToolbar *toolbar);
222 static gint get_internal_padding (GtkToolbar *toolbar);
223 static GtkShadowType get_shadow_type (GtkToolbar *toolbar);
224 static gint get_space_size (GtkToolbar *toolbar);
225 static GtkToolbarSpaceStyle get_space_style (GtkToolbar *toolbar);
227 /* methods on ToolbarContent 'class' */
228 static ToolbarContent *toolbar_content_new_tool_item (GtkToolbar *toolbar,
230 gboolean is_placeholder,
232 static ToolbarContent *toolbar_content_new_compatibility (GtkToolbar *toolbar,
233 GtkToolbarChildType type,
238 static void toolbar_content_remove (ToolbarContent *content,
239 GtkToolbar *toolbar);
240 static void toolbar_content_free (ToolbarContent *content);
241 static void toolbar_content_expose (ToolbarContent *content,
242 GtkContainer *container,
243 GdkEventExpose *expose);
244 static gboolean toolbar_content_visible (ToolbarContent *content,
245 GtkToolbar *toolbar);
246 static void toolbar_content_size_request (ToolbarContent *content,
248 GtkRequisition *requisition);
249 static gboolean toolbar_content_is_homogeneous (ToolbarContent *content,
250 GtkToolbar *toolbar);
251 static gboolean toolbar_content_is_placeholder (ToolbarContent *content);
252 static gboolean toolbar_content_disappearing (ToolbarContent *content);
253 static ItemState toolbar_content_get_state (ToolbarContent *content);
254 static gboolean toolbar_content_child_visible (ToolbarContent *content);
255 static void toolbar_content_get_goal_allocation (ToolbarContent *content,
256 GtkAllocation *allocation);
257 static void toolbar_content_get_allocation (ToolbarContent *content,
258 GtkAllocation *allocation);
259 static void toolbar_content_set_start_allocation (ToolbarContent *content,
260 GtkAllocation *new_start_allocation);
261 static void toolbar_content_get_start_allocation (ToolbarContent *content,
262 GtkAllocation *start_allocation);
263 static gboolean toolbar_content_get_expand (ToolbarContent *content);
264 static void toolbar_content_set_goal_allocation (ToolbarContent *content,
265 GtkAllocation *allocation);
266 static void toolbar_content_set_child_visible (ToolbarContent *content,
269 static void toolbar_content_size_allocate (ToolbarContent *content,
270 GtkAllocation *allocation);
271 static void toolbar_content_set_state (ToolbarContent *content,
272 ItemState new_state);
273 static GtkWidget * toolbar_content_get_widget (ToolbarContent *content);
274 static void toolbar_content_set_disappearing (ToolbarContent *content,
275 gboolean disappearing);
276 static void toolbar_content_set_size_request (ToolbarContent *content,
279 static void toolbar_content_toolbar_reconfigured (ToolbarContent *content,
280 GtkToolbar *toolbar);
281 static GtkWidget * toolbar_content_retrieve_menu_item (ToolbarContent *content);
282 static gboolean toolbar_content_is_separator (ToolbarContent *content);
283 static void toolbar_content_show_all (ToolbarContent *content);
284 static void toolbar_content_hide_all (ToolbarContent *content);
287 #define GTK_TOOLBAR_GET_PRIVATE(o) \
288 (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_TOOLBAR, GtkToolbarPrivate))
290 static GtkContainerClass * parent_class = NULL;
291 static guint toolbar_signals [LAST_SIGNAL] = { 0 };
294 gtk_toolbar_get_type (void)
296 static GtkType type = 0;
300 static const GTypeInfo type_info =
302 sizeof (GtkToolbarClass),
303 (GBaseInitFunc) NULL,
304 (GBaseFinalizeFunc) NULL,
305 (GClassInitFunc) gtk_toolbar_class_init,
306 (GClassFinalizeFunc) NULL,
310 (GInstanceInitFunc) gtk_toolbar_init,
313 type = g_type_register_static (GTK_TYPE_CONTAINER,
322 add_arrow_bindings (GtkBindingSet *binding_set,
324 GtkDirectionType dir)
326 guint keypad_keysym = keysym - GDK_Left + GDK_KP_Left;
328 gtk_binding_entry_add_signal (binding_set, keysym, 0,
330 GTK_TYPE_DIRECTION_TYPE, dir);
331 gtk_binding_entry_add_signal (binding_set, keypad_keysym, 0,
333 GTK_TYPE_DIRECTION_TYPE, dir);
337 add_ctrl_tab_bindings (GtkBindingSet *binding_set,
338 GdkModifierType modifiers,
339 GtkDirectionType direction)
341 gtk_binding_entry_add_signal (binding_set,
342 GDK_Tab, GDK_CONTROL_MASK | modifiers,
344 GTK_TYPE_DIRECTION_TYPE, direction);
345 gtk_binding_entry_add_signal (binding_set,
346 GDK_KP_Tab, GDK_CONTROL_MASK | modifiers,
348 GTK_TYPE_DIRECTION_TYPE, direction);
352 gtk_toolbar_class_init (GtkToolbarClass *klass)
354 GObjectClass *gobject_class;
355 GtkWidgetClass *widget_class;
356 GtkContainerClass *container_class;
357 GtkBindingSet *binding_set;
359 parent_class = g_type_class_peek_parent (klass);
361 gobject_class = (GObjectClass *)klass;
362 widget_class = (GtkWidgetClass *)klass;
363 container_class = (GtkContainerClass *)klass;
365 gobject_class->set_property = gtk_toolbar_set_property;
366 gobject_class->get_property = gtk_toolbar_get_property;
367 gobject_class->finalize = gtk_toolbar_finalize;
369 widget_class->button_press_event = gtk_toolbar_button_press;
370 widget_class->expose_event = gtk_toolbar_expose;
371 widget_class->size_request = gtk_toolbar_size_request;
372 widget_class->size_allocate = gtk_toolbar_size_allocate;
373 widget_class->style_set = gtk_toolbar_style_set;
374 widget_class->focus = gtk_toolbar_focus;
375 widget_class->screen_changed = gtk_toolbar_screen_changed;
376 widget_class->realize = gtk_toolbar_realize;
377 widget_class->unrealize = gtk_toolbar_unrealize;
378 widget_class->map = gtk_toolbar_map;
379 widget_class->unmap = gtk_toolbar_unmap;
380 widget_class->popup_menu = gtk_toolbar_popup_menu;
381 widget_class->show_all = gtk_toolbar_show_all;
382 widget_class->hide_all = gtk_toolbar_hide_all;
384 container_class->add = gtk_toolbar_add;
385 container_class->remove = gtk_toolbar_remove;
386 container_class->forall = gtk_toolbar_forall;
387 container_class->child_type = gtk_toolbar_child_type;
388 container_class->get_child_property = gtk_toolbar_get_child_property;
389 container_class->set_child_property = gtk_toolbar_set_child_property;
391 klass->orientation_changed = gtk_toolbar_orientation_changed;
392 klass->style_changed = gtk_toolbar_real_style_changed;
395 * GtkToolbar::orientation-changed:
396 * @toolbar: the object which emitted the signal
397 * @orientation: the new #GtkOrientation of the toolbar
399 * Emitted when the orientation of the toolbar changes.
401 toolbar_signals[ORIENTATION_CHANGED] =
402 g_signal_new ("orientation-changed",
403 G_OBJECT_CLASS_TYPE (klass),
405 G_STRUCT_OFFSET (GtkToolbarClass, orientation_changed),
407 g_cclosure_marshal_VOID__ENUM,
409 GTK_TYPE_ORIENTATION);
411 * GtkToolbar::style-changed:
412 * @toolbar: The #GtkToolbar which emitted the signal
413 * @style: the new #GtkToolbarStyle of the toolbar
415 * Emitted when the style of the toolbar changes.
417 toolbar_signals[STYLE_CHANGED] =
418 g_signal_new ("style-changed",
419 G_OBJECT_CLASS_TYPE (klass),
421 G_STRUCT_OFFSET (GtkToolbarClass, style_changed),
423 g_cclosure_marshal_VOID__ENUM,
425 GTK_TYPE_TOOLBAR_STYLE);
427 * GtkToolbar::popup-context-menu:
428 * @toolbar: the #GtkToolbar which emitted the signal
429 * @x: the x coordinate of the point where the menu should appear
430 * @y: the y coordinate of the point where the menu should appear
431 * @button: the mouse button the user pressed, or -1
433 * Emitted when the user right-clicks the toolbar or uses the
434 * keybinding to display a popup menu.
436 * Application developers should handle this signal if they want
437 * to display a context menu on the toolbar. The context-menu should
438 * appear at the coordinates given by @x and @y. The mouse button
439 * number is given by the @button parameter. If the menu was popped
440 * up using the keybaord, @button is -1.
442 * Return value: return %TRUE if the signal was handled, %FALSE if not
444 toolbar_signals[POPUP_CONTEXT_MENU] =
445 g_signal_new ("popup_context_menu",
446 G_OBJECT_CLASS_TYPE (klass),
448 G_STRUCT_OFFSET (GtkToolbarClass, popup_context_menu),
449 _gtk_boolean_handled_accumulator, NULL,
450 _gtk_marshal_BOOLEAN__INT_INT_INT,
452 G_TYPE_INT, G_TYPE_INT,
455 * GtkToolbar::move-focus:
456 * @toolbar: the #GtkToolbar which emitted the signal
457 * @dir: a #GtkDirection
459 * A keybinding signal used internally by GTK+. This signal can't
460 * be used in application code.
462 * Return value: %TRUE if the signal was handled, %FALSE if not
464 toolbar_signals[MOVE_FOCUS] =
465 _gtk_binding_signal_new ("move_focus",
466 G_TYPE_FROM_CLASS (klass),
467 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
468 G_CALLBACK (gtk_toolbar_move_focus),
470 _gtk_marshal_BOOLEAN__ENUM,
472 GTK_TYPE_DIRECTION_TYPE);
474 * GtkToolbar::focus-home-or-end:
475 * @toolbar: the #GtkToolbar which emitted the signal
476 * @focus_home: %TRUE if the first item should be focused
478 * A keybinding signal used internally by GTK+. This signal can't
479 * be used in application code
481 * Return value: %TRUE if the signal was handled, %FALSE if not
483 toolbar_signals[FOCUS_HOME_OR_END] =
484 _gtk_binding_signal_new ("focus_home_or_end",
485 G_OBJECT_CLASS_TYPE (klass),
486 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
487 G_CALLBACK (gtk_toolbar_focus_home_or_end),
489 _gtk_marshal_BOOLEAN__BOOLEAN,
494 g_object_class_install_property (gobject_class,
496 g_param_spec_enum ("orientation",
498 P_("The orientation of the toolbar"),
499 GTK_TYPE_ORIENTATION,
500 GTK_ORIENTATION_HORIZONTAL,
503 g_object_class_install_property (gobject_class,
505 g_param_spec_enum ("toolbar_style",
507 P_("How to draw the toolbar"),
508 GTK_TYPE_TOOLBAR_STYLE,
511 g_object_class_install_property (gobject_class,
513 g_param_spec_boolean ("show_arrow",
515 P_("If an arrow should be shown if the toolbar doesn't fit"),
519 /* child properties */
520 gtk_container_class_install_child_property (container_class,
522 g_param_spec_boolean ("expand",
524 P_("Whether the item should receive extra space when the toolbar grows"),
528 gtk_container_class_install_child_property (container_class,
529 CHILD_PROP_HOMOGENEOUS,
530 g_param_spec_boolean ("homogeneous",
532 P_("Whether the item should be the same size as other homogeneous items"),
536 /* style properties */
537 gtk_widget_class_install_style_property (widget_class,
538 g_param_spec_int ("space_size",
540 P_("Size of spacers"),
546 gtk_widget_class_install_style_property (widget_class,
547 g_param_spec_int ("internal_padding",
548 P_("Internal padding"),
549 P_("Amount of border space between the toolbar shadow and the buttons"),
555 gtk_widget_class_install_style_property (widget_class,
556 g_param_spec_enum ("space_style",
558 P_("Whether spacers are vertical lines or just blank"),
559 GTK_TYPE_TOOLBAR_SPACE_STYLE,
563 gtk_widget_class_install_style_property (widget_class,
564 g_param_spec_enum ("button_relief",
566 P_("Type of bevel around toolbar buttons"),
567 GTK_TYPE_RELIEF_STYLE,
570 gtk_widget_class_install_style_property (widget_class,
571 g_param_spec_enum ("shadow_type",
573 P_("Style of bevel around the toolbar"),
574 GTK_TYPE_SHADOW_TYPE,
578 gtk_settings_install_property (g_param_spec_enum ("gtk-toolbar-style",
580 P_("Whether default toolbars have text only, text and icons, icons only, etc."),
581 GTK_TYPE_TOOLBAR_STYLE,
582 DEFAULT_TOOLBAR_STYLE,
585 gtk_settings_install_property (g_param_spec_enum ("gtk-toolbar-icon-size",
586 P_("Toolbar icon size"),
587 P_("Size of icons in default toolbars"),
592 binding_set = gtk_binding_set_by_class (klass);
594 add_arrow_bindings (binding_set, GDK_Left, GTK_DIR_LEFT);
595 add_arrow_bindings (binding_set, GDK_Right, GTK_DIR_RIGHT);
596 add_arrow_bindings (binding_set, GDK_Up, GTK_DIR_UP);
597 add_arrow_bindings (binding_set, GDK_Down, GTK_DIR_DOWN);
599 gtk_binding_entry_add_signal (binding_set, GDK_KP_Home, 0,
600 "focus_home_or_end", 1,
601 G_TYPE_BOOLEAN, TRUE);
602 gtk_binding_entry_add_signal (binding_set, GDK_Home, 0,
603 "focus_home_or_end", 1,
604 G_TYPE_BOOLEAN, TRUE);
605 gtk_binding_entry_add_signal (binding_set, GDK_KP_End, 0,
606 "focus_home_or_end", 1,
607 G_TYPE_BOOLEAN, FALSE);
608 gtk_binding_entry_add_signal (binding_set, GDK_End, 0,
609 "focus_home_or_end", 1,
610 G_TYPE_BOOLEAN, FALSE);
612 add_ctrl_tab_bindings (binding_set, 0, GTK_DIR_TAB_FORWARD);
613 add_ctrl_tab_bindings (binding_set, GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
615 g_type_class_add_private (gobject_class, sizeof (GtkToolbarPrivate));
619 gtk_toolbar_init (GtkToolbar *toolbar)
621 GtkToolbarPrivate *priv;
623 GTK_WIDGET_UNSET_FLAGS (toolbar, GTK_CAN_FOCUS);
624 GTK_WIDGET_SET_FLAGS (toolbar, GTK_NO_WINDOW);
626 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
628 toolbar->orientation = GTK_ORIENTATION_HORIZONTAL;
629 toolbar->style = DEFAULT_TOOLBAR_STYLE;
630 toolbar->icon_size = DEFAULT_ICON_SIZE;
631 toolbar->tooltips = gtk_tooltips_new ();
632 g_object_ref (toolbar->tooltips);
633 gtk_object_sink (GTK_OBJECT (toolbar->tooltips));
635 priv->arrow_button = gtk_toggle_button_new ();
636 g_signal_connect (priv->arrow_button, "button_press_event",
637 G_CALLBACK (gtk_toolbar_arrow_button_press), toolbar);
638 g_signal_connect (priv->arrow_button, "clicked",
639 G_CALLBACK (gtk_toolbar_arrow_button_clicked), toolbar);
640 gtk_button_set_relief (GTK_BUTTON (priv->arrow_button),
641 get_button_relief (toolbar));
643 priv->api_mode = DONT_KNOW;
645 gtk_button_set_focus_on_click (GTK_BUTTON (priv->arrow_button), FALSE);
647 priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
648 gtk_widget_set_name (priv->arrow, "gtk-toolbar-arrow");
649 gtk_widget_show (priv->arrow);
650 gtk_container_add (GTK_CONTAINER (priv->arrow_button), priv->arrow);
652 gtk_widget_set_parent (priv->arrow_button, GTK_WIDGET (toolbar));
654 /* which child position a drop will occur at */
656 priv->show_arrow = TRUE;
657 priv->settings = NULL;
659 priv->max_homogeneous_pixels = -1;
661 priv->timer = g_timer_new ();
665 gtk_toolbar_set_property (GObject *object,
670 GtkToolbar *toolbar = GTK_TOOLBAR (object);
674 case PROP_ORIENTATION:
675 gtk_toolbar_set_orientation (toolbar, g_value_get_enum (value));
677 case PROP_TOOLBAR_STYLE:
678 gtk_toolbar_set_style (toolbar, g_value_get_enum (value));
680 case PROP_SHOW_ARROW:
681 gtk_toolbar_set_show_arrow (toolbar, g_value_get_boolean (value));
684 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
690 gtk_toolbar_get_property (GObject *object,
695 GtkToolbar *toolbar = GTK_TOOLBAR (object);
696 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
700 case PROP_ORIENTATION:
701 g_value_set_enum (value, toolbar->orientation);
703 case PROP_TOOLBAR_STYLE:
704 g_value_set_enum (value, toolbar->style);
706 case PROP_SHOW_ARROW:
707 g_value_set_boolean (value, priv->show_arrow);
710 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
716 gtk_toolbar_map (GtkWidget *widget)
718 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
720 GTK_WIDGET_CLASS (parent_class)->map (widget);
722 if (priv->event_window)
723 gdk_window_show_unraised (priv->event_window);
727 gtk_toolbar_unmap (GtkWidget *widget)
729 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
731 if (priv->event_window)
732 gdk_window_hide (priv->event_window);
734 GTK_WIDGET_CLASS (parent_class)->unmap (widget);
738 gtk_toolbar_realize (GtkWidget *widget)
740 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
741 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
743 GdkWindowAttr attributes;
744 gint attributes_mask;
747 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
749 border_width = GTK_CONTAINER (widget)->border_width;
751 attributes.wclass = GDK_INPUT_ONLY;
752 attributes.window_type = GDK_WINDOW_CHILD;
753 attributes.x = widget->allocation.x + border_width;
754 attributes.y = widget->allocation.y + border_width;
755 attributes.width = widget->allocation.width - border_width * 2;
756 attributes.height = widget->allocation.height - border_width * 2;
757 attributes.event_mask = gtk_widget_get_events (widget);
758 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
759 GDK_BUTTON_RELEASE_MASK |
760 GDK_ENTER_NOTIFY_MASK |
761 GDK_LEAVE_NOTIFY_MASK);
763 attributes_mask = GDK_WA_X | GDK_WA_Y;
765 widget->window = gtk_widget_get_parent_window (widget);
766 g_object_ref (widget->window);
767 widget->style = gtk_style_attach (widget->style, widget->window);
769 priv->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
770 &attributes, attributes_mask);
771 gdk_window_set_user_data (priv->event_window, toolbar);
775 gtk_toolbar_unrealize (GtkWidget *widget)
777 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
779 if (priv->event_window)
781 gdk_window_set_user_data (priv->event_window, NULL);
782 gdk_window_destroy (priv->event_window);
783 priv->event_window = NULL;
786 if (GTK_WIDGET_CLASS (parent_class)->unrealize)
787 (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
791 gtk_toolbar_expose (GtkWidget *widget,
792 GdkEventExpose *event)
794 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
795 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
800 border_width = GTK_CONTAINER (widget)->border_width;
802 if (GTK_WIDGET_DRAWABLE (widget))
804 gtk_paint_box (widget->style,
806 GTK_WIDGET_STATE (widget),
807 get_shadow_type (toolbar),
808 &event->area, widget, "toolbar",
809 border_width + widget->allocation.x,
810 border_width + widget->allocation.y,
811 widget->allocation.width - 2 * border_width,
812 widget->allocation.height - 2 * border_width);
815 for (list = priv->content; list != NULL; list = list->next)
817 ToolbarContent *content = list->data;
819 toolbar_content_expose (content, GTK_CONTAINER (widget), event);
822 gtk_container_propagate_expose (GTK_CONTAINER (widget),
830 gtk_toolbar_size_request (GtkWidget *widget,
831 GtkRequisition *requisition)
833 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
834 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
836 gint max_child_height;
837 gint max_child_width;
838 gint max_homogeneous_child_width;
839 gint max_homogeneous_child_height;
840 gint homogeneous_size;
842 gint pack_front_size;
844 GtkRequisition arrow_requisition;
846 max_homogeneous_child_width = 0;
847 max_homogeneous_child_height = 0;
849 max_child_height = 0;
850 for (list = priv->content; list != NULL; list = list->next)
852 GtkRequisition requisition;
853 ToolbarContent *content = list->data;
855 if (!toolbar_content_visible (content, toolbar))
858 toolbar_content_size_request (content, toolbar, &requisition);
860 max_child_width = MAX (max_child_width, requisition.width);
861 max_child_height = MAX (max_child_height, requisition.height);
863 if (toolbar_content_is_homogeneous (content, toolbar))
865 max_homogeneous_child_width = MAX (max_homogeneous_child_width, requisition.width);
866 max_homogeneous_child_height = MAX (max_homogeneous_child_height, requisition.height);
870 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
871 homogeneous_size = max_homogeneous_child_width;
873 homogeneous_size = max_homogeneous_child_height;
876 for (list = priv->content; list != NULL; list = list->next)
878 ToolbarContent *content = list->data;
881 if (!toolbar_content_visible (content, toolbar))
884 if (toolbar_content_is_homogeneous (content, toolbar))
886 size = homogeneous_size;
890 GtkRequisition requisition;
892 toolbar_content_size_request (content, toolbar, &requisition);
894 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
895 size = requisition.width;
897 size = requisition.height;
900 pack_front_size += size;
903 if (priv->show_arrow && priv->api_mode == NEW_API)
905 gtk_widget_size_request (priv->arrow_button, &arrow_requisition);
907 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
908 long_req = arrow_requisition.width;
910 long_req = arrow_requisition.height;
912 /* There is no point requesting space for the arrow if that would take
913 * up more space than all the items combined
915 long_req = MIN (long_req, pack_front_size);
919 arrow_requisition.height = 0;
920 arrow_requisition.width = 0;
922 long_req = pack_front_size;
925 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
927 requisition->width = long_req;
928 requisition->height = MAX (max_child_height, arrow_requisition.height);
932 requisition->height = long_req;
933 requisition->width = MAX (max_child_width, arrow_requisition.width);
937 ipadding = get_internal_padding (toolbar);
939 requisition->width += 2 * (ipadding + GTK_CONTAINER (toolbar)->border_width);
940 requisition->height += 2 * (ipadding + GTK_CONTAINER (toolbar)->border_width);
942 if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
944 requisition->width += 2 * widget->style->xthickness;
945 requisition->height += 2 * widget->style->ythickness;
948 toolbar->button_maxw = max_homogeneous_child_width;
949 toolbar->button_maxh = max_homogeneous_child_height;
953 position (gint from, gint to, gdouble elapsed)
956 return MIN (from + SLIDE_SPEED * elapsed, to);
958 return MAX (from - SLIDE_SPEED * elapsed, to);
962 compute_intermediate_allocation (GtkToolbar *toolbar,
963 const GtkAllocation *start,
964 const GtkAllocation *goal,
965 GtkAllocation *intermediate)
967 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
968 gdouble elapsed = g_timer_elapsed (priv->timer, NULL);
970 intermediate->x = position (start->x, goal->x, elapsed);
971 intermediate->y = position (start->y, goal->y, elapsed);
972 intermediate->width =
973 position (start->x + start->width, goal->x + goal->width, elapsed) - intermediate->x;
974 intermediate->height =
975 position (start->y + start->height, goal->y + goal->height, elapsed) - intermediate->y;
979 fixup_allocation_for_rtl (gint total_size,
980 GtkAllocation *allocation)
982 allocation->x += (total_size - (2 * allocation->x + allocation->width));
986 fixup_allocation_for_vertical (GtkAllocation *allocation)
991 allocation->x = allocation->y;
994 tmp = allocation->width;
995 allocation->width = allocation->height;
996 allocation->height = tmp;
1000 get_item_size (GtkToolbar *toolbar,
1001 ToolbarContent *content)
1003 GtkRequisition requisition;
1005 toolbar_content_size_request (content, toolbar, &requisition);
1007 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
1009 if (toolbar_content_is_homogeneous (content, toolbar))
1010 return toolbar->button_maxw;
1012 return requisition.width;
1016 if (toolbar_content_is_homogeneous (content, toolbar))
1017 return toolbar->button_maxh;
1019 return requisition.height;
1024 slide_idle_handler (gpointer data)
1026 GtkToolbar *toolbar = data;
1027 GtkToolbarPrivate *priv;
1030 GDK_THREADS_ENTER ();
1032 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1034 if (priv->need_sync)
1037 priv->need_sync = FALSE;
1040 for (list = priv->content; list != NULL; list = list->next)
1042 ToolbarContent *content = list->data;
1044 GtkAllocation goal_allocation;
1045 GtkAllocation allocation;
1048 state = toolbar_content_get_state (content);
1049 toolbar_content_get_goal_allocation (content, &goal_allocation);
1050 toolbar_content_get_allocation (content, &allocation);
1054 if (state == NOT_ALLOCATED)
1056 /* an unallocated item means that size allocate has to
1057 * called at least once more
1062 /* An invisible item with a goal allocation of
1063 * 0 is already at its goal.
1065 if ((state == NORMAL || state == OVERFLOWN) &&
1066 ((goal_allocation.width != 0 &&
1067 goal_allocation.height != 0) ||
1068 toolbar_content_child_visible (content)))
1070 if ((goal_allocation.x != allocation.x ||
1071 goal_allocation.y != allocation.y ||
1072 goal_allocation.width != allocation.width ||
1073 goal_allocation.height != allocation.height))
1075 /* An item is not in its right position yet. Note
1076 * that OVERFLOWN items do get an allocation in
1077 * gtk_toolbar_size_allocate(). This way you can see
1078 * them slide back in when you drag an item off the
1085 if (toolbar_content_is_placeholder (content) &&
1086 toolbar_content_disappearing (content) &&
1087 toolbar_content_child_visible (content))
1089 /* A disappearing placeholder is still visible.
1097 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1099 GDK_THREADS_LEAVE ();
1104 priv->is_sliding = FALSE;
1107 GDK_THREADS_LEAVE();
1112 rect_within (GtkAllocation *a1,
1115 return (a1->x >= a2->x &&
1116 a1->x + a1->width <= a2->x + a2->width &&
1118 a1->y + a1->height <= a2->y + a2->height);
1122 gtk_toolbar_begin_sliding (GtkToolbar *toolbar)
1124 GtkWidget *widget = GTK_WIDGET (toolbar);
1125 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1133 /* Start the sliding. This function copies the allocation of every
1134 * item into content->start_allocation. For items that haven't
1135 * been allocated yet, we calculate their position and save that
1136 * in start_allocatino along with zero width and zero height.
1138 priv->is_sliding = TRUE;
1141 priv->idle_id = g_idle_add (slide_idle_handler, toolbar);
1143 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1144 vertical = (toolbar->orientation == GTK_ORIENTATION_VERTICAL);
1145 border_width = get_internal_padding (toolbar) + GTK_CONTAINER (toolbar)->border_width;
1149 cur_x = widget->allocation.width - border_width - widget->style->xthickness;
1150 cur_y = widget->allocation.height - border_width - widget->style->ythickness;
1154 cur_x = border_width + widget->style->xthickness;
1155 cur_y = border_width + widget->style->ythickness;
1158 cur_x += widget->allocation.x;
1159 cur_y += widget->allocation.y;
1161 for (list = priv->content; list != NULL; list = list->next)
1163 ToolbarContent *content = list->data;
1164 GtkAllocation new_start_allocation;
1165 GtkAllocation item_allocation;
1168 state = toolbar_content_get_state (content);
1169 toolbar_content_get_allocation (content, &item_allocation);
1171 if ((state == NORMAL &&
1172 rect_within (&item_allocation, &(widget->allocation))) ||
1175 new_start_allocation = item_allocation;
1179 new_start_allocation.x = cur_x;
1180 new_start_allocation.y = cur_y;
1184 new_start_allocation.width = widget->allocation.width -
1185 2 * border_width - 2 * widget->style->xthickness;
1186 new_start_allocation.height = 0;
1190 new_start_allocation.width = 0;
1191 new_start_allocation.height = widget->allocation.height -
1192 2 * border_width - 2 * widget->style->ythickness;
1197 cur_y = new_start_allocation.y + new_start_allocation.height;
1199 cur_x = new_start_allocation.x;
1201 cur_x = new_start_allocation.x + new_start_allocation.width;
1203 toolbar_content_set_start_allocation (content, &new_start_allocation);
1206 /* This resize will run before the first idle handler. This
1207 * will make sure that items get the right goal allocatiuon
1208 * so that the idle handler will not immediately return
1211 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1212 g_timer_reset (priv->timer);
1216 gtk_toolbar_stop_sliding (GtkToolbar *toolbar)
1218 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1220 if (priv->is_sliding)
1224 priv->is_sliding = FALSE;
1228 g_source_remove (priv->idle_id);
1232 list = priv->content;
1235 ToolbarContent *content = list->data;
1238 if (toolbar_content_is_placeholder (content))
1240 toolbar_content_remove (content, toolbar);
1241 toolbar_content_free (content);
1245 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1250 gtk_toolbar_size_allocate (GtkWidget *widget,
1251 GtkAllocation *allocation)
1253 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1254 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1255 GtkAllocation *allocations;
1256 ItemState *new_states;
1257 GtkAllocation arrow_allocation;
1259 gint size, pos, short_size;
1262 gboolean need_arrow;
1263 gint n_expand_items;
1265 gint available_size;
1268 GtkRequisition arrow_requisition;
1269 gboolean overflowing;
1270 gboolean size_changed;
1272 GtkAllocation item_area;
1274 size_changed = FALSE;
1275 if (widget->allocation.x != allocation->x ||
1276 widget->allocation.y != allocation->y ||
1277 widget->allocation.width != allocation->width ||
1278 widget->allocation.height != allocation->height)
1280 size_changed = TRUE;
1284 gtk_toolbar_stop_sliding (toolbar);
1286 widget->allocation = *allocation;
1288 border_width = GTK_CONTAINER (toolbar)->border_width;
1290 if (GTK_WIDGET_REALIZED (widget))
1292 gdk_window_move_resize (priv->event_window,
1293 allocation->x + border_width,
1294 allocation->y + border_width,
1295 allocation->width - border_width * 2,
1296 allocation->height - border_width * 2);
1299 border_width += get_internal_padding (toolbar);
1301 gtk_widget_get_child_requisition (GTK_WIDGET (priv->arrow_button),
1302 &arrow_requisition);
1304 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
1306 available_size = size = allocation->width - 2 * border_width;
1307 short_size = allocation->height - 2 * border_width;
1308 arrow_size = arrow_requisition.width;
1310 if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
1312 available_size -= 2 * widget->style->xthickness;
1313 short_size -= 2 * widget->style->ythickness;
1318 available_size = size = allocation->height - 2 * border_width;
1319 short_size = allocation->width - 2 * border_width;
1320 arrow_size = arrow_requisition.height;
1322 if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
1324 available_size -= 2 * widget->style->ythickness;
1325 short_size -= 2 * widget->style->xthickness;
1329 n_items = g_list_length (priv->content);
1330 allocations = g_new0 (GtkAllocation, n_items);
1331 new_states = g_new0 (ItemState, n_items);
1334 for (list = priv->content; list != NULL; list = list->next)
1336 ToolbarContent *content = list->data;
1338 if (toolbar_content_visible (content, toolbar))
1339 needed_size += get_item_size (toolbar, content);
1342 need_arrow = (needed_size > available_size) && priv->show_arrow && priv->api_mode == NEW_API;
1345 size = available_size - arrow_size;
1347 size = available_size;
1349 /* calculate widths of items */
1350 overflowing = FALSE;
1351 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1353 ToolbarContent *content = list->data;
1356 if (!toolbar_content_visible (content, toolbar))
1358 new_states[i] = HIDDEN;
1362 item_size = get_item_size (toolbar, content);
1363 if (item_size <= size && !overflowing)
1366 allocations[i].width = item_size;
1367 new_states[i] = NORMAL;
1372 new_states[i] = OVERFLOWN;
1373 allocations[i].width = item_size;
1377 /* calculate width of arrow */
1380 arrow_allocation.width = arrow_size;
1381 arrow_allocation.height = short_size;
1384 /* expand expandable items */
1386 /* We don't expand when there is an overflow menu, because that leads to
1387 * weird jumps when items get moved to the overflow menu and the expanding
1388 * items suddenly get a lot of extra space
1393 for (i = 0, list = priv->content; list != NULL; list = list->next, ++i)
1395 ToolbarContent *content = list->data;
1397 if (toolbar_content_get_expand (content) && new_states[i] == NORMAL)
1401 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1403 ToolbarContent *content = list->data;
1405 if (toolbar_content_get_expand (content) && new_states[i] == NORMAL)
1407 gint extra = size / n_expand_items;
1408 if (size % n_expand_items != 0)
1411 allocations[i].width += extra;
1417 g_assert (n_expand_items == 0);
1420 /* position items */
1422 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1424 /* both NORMAL and OVERFLOWN items get a position. This ensures
1425 * that sliding will work for OVERFLOWN items too
1427 if (new_states[i] == NORMAL ||
1428 new_states[i] == OVERFLOWN)
1430 allocations[i].x = pos;
1431 allocations[i].y = border_width;
1432 allocations[i].height = short_size;
1434 pos += allocations[i].width;
1438 /* position arrow */
1441 arrow_allocation.x = available_size - border_width - arrow_allocation.width;
1442 arrow_allocation.y = border_width;
1445 item_area.x = border_width;
1446 item_area.y = border_width;
1447 item_area.width = available_size - (need_arrow? arrow_size : 0);
1448 item_area.height = short_size;
1450 /* fix up allocations in the vertical or RTL cases */
1451 if (toolbar->orientation == GTK_ORIENTATION_VERTICAL)
1453 for (i = 0; i < n_items; ++i)
1454 fixup_allocation_for_vertical (&(allocations[i]));
1457 fixup_allocation_for_vertical (&arrow_allocation);
1459 fixup_allocation_for_vertical (&item_area);
1461 else if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL)
1463 for (i = 0; i < n_items; ++i)
1464 fixup_allocation_for_rtl (available_size, &(allocations[i]));
1467 fixup_allocation_for_rtl (available_size, &arrow_allocation);
1469 fixup_allocation_for_rtl (available_size, &item_area);
1472 /* translate the items by allocation->(x,y) */
1473 for (i = 0; i < n_items; ++i)
1475 allocations[i].x += allocation->x;
1476 allocations[i].y += allocation->y;
1478 if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
1480 allocations[i].x += widget->style->xthickness;
1481 allocations[i].y += widget->style->ythickness;
1487 arrow_allocation.x += allocation->x;
1488 arrow_allocation.y += allocation->y;
1490 if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
1492 arrow_allocation.x += widget->style->xthickness;
1493 arrow_allocation.y += widget->style->ythickness;
1497 item_area.x += allocation->x;
1498 item_area.y += allocation->y;
1499 if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
1501 item_area.x += widget->style->xthickness;
1502 item_area.y += widget->style->ythickness;
1505 /* did anything change? */
1506 for (list = priv->content, i = 0; list != NULL; list = list->next, i++)
1508 ToolbarContent *content = list->data;
1510 if (toolbar_content_get_state (content) == NORMAL &&
1511 new_states[i] != NORMAL)
1513 /* an item disappeared, begin sliding */
1514 if (!size_changed && priv->api_mode == NEW_API)
1515 gtk_toolbar_begin_sliding (toolbar);
1519 /* finally allocate the items */
1520 if (priv->is_sliding)
1522 for (list = priv->content, i = 0; list != NULL; list = list->next, i++)
1524 ToolbarContent *content = list->data;
1526 toolbar_content_set_goal_allocation (content, &(allocations[i]));
1530 elapsed = g_timer_elapsed (priv->timer, NULL);
1531 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1533 ToolbarContent *content = list->data;
1535 if (new_states[i] == OVERFLOWN ||
1536 new_states[i] == NORMAL)
1538 GtkAllocation alloc;
1539 GtkAllocation start_allocation;
1540 GtkAllocation goal_allocation;
1542 if (priv->is_sliding)
1544 toolbar_content_get_start_allocation (content, &start_allocation);
1545 toolbar_content_get_goal_allocation (content, &goal_allocation);
1547 compute_intermediate_allocation (toolbar,
1552 priv->need_sync = TRUE;
1556 alloc = allocations[i];
1559 if (alloc.width == 0 || alloc.height == 0)
1561 toolbar_content_set_child_visible (content, toolbar, FALSE);
1565 if (!rect_within (&alloc, &item_area))
1567 toolbar_content_set_child_visible (content, toolbar, FALSE);
1568 toolbar_content_size_allocate (content, &alloc);
1572 toolbar_content_set_child_visible (content, toolbar, TRUE);
1573 toolbar_content_size_allocate (content, &alloc);
1579 toolbar_content_set_child_visible (content, toolbar, FALSE);
1582 toolbar_content_set_state (content, new_states[i]);
1587 gtk_widget_size_allocate (GTK_WIDGET (priv->arrow_button),
1589 gtk_widget_show (GTK_WIDGET (priv->arrow_button));
1593 gtk_widget_hide (GTK_WIDGET (priv->arrow_button));
1596 g_free (allocations);
1597 g_free (new_states);
1601 gtk_toolbar_update_button_relief (GtkToolbar *toolbar)
1603 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1605 gtk_toolbar_reconfigured (toolbar);
1607 gtk_button_set_relief (GTK_BUTTON (priv->arrow_button), get_button_relief (toolbar));
1611 gtk_toolbar_style_set (GtkWidget *widget,
1612 GtkStyle *prev_style)
1614 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
1616 priv->max_homogeneous_pixels = -1;
1618 if (GTK_WIDGET_REALIZED (widget))
1619 gtk_style_set_background (widget->style, widget->window, widget->state);
1622 gtk_toolbar_update_button_relief (GTK_TOOLBAR (widget));
1626 gtk_toolbar_list_children_in_focus_order (GtkToolbar *toolbar,
1627 GtkDirectionType dir)
1629 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1630 GList *result = NULL;
1634 /* generate list of children in reverse logical order */
1636 for (list = priv->content; list != NULL; list = list->next)
1638 ToolbarContent *content = list->data;
1641 widget = toolbar_content_get_widget (content);
1644 result = g_list_prepend (result, widget);
1647 result = g_list_prepend (result, priv->arrow_button);
1649 rtl = (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL);
1651 /* move in logical order when
1653 * - dir is TAB_FORWARD
1655 * - in RTL mode and moving left or up
1657 * - in LTR mode and moving right or down
1659 if (dir == GTK_DIR_TAB_FORWARD ||
1660 (rtl && (dir == GTK_DIR_UP || dir == GTK_DIR_LEFT)) ||
1661 (!rtl && (dir == GTK_DIR_DOWN || dir == GTK_DIR_RIGHT)))
1663 result = g_list_reverse (result);
1670 gtk_toolbar_focus_home_or_end (GtkToolbar *toolbar,
1671 gboolean focus_home)
1673 GList *children, *list;
1674 GtkDirectionType dir = focus_home? GTK_DIR_RIGHT : GTK_DIR_LEFT;
1676 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1678 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL)
1680 children = g_list_reverse (children);
1682 dir = (dir == GTK_DIR_RIGHT)? GTK_DIR_LEFT : GTK_DIR_RIGHT;
1685 for (list = children; list != NULL; list = list->next)
1687 GtkWidget *child = list->data;
1689 if (GTK_CONTAINER (toolbar)->focus_child == child)
1692 if (GTK_WIDGET_MAPPED (child) && gtk_widget_child_focus (child, dir))
1696 g_list_free (children);
1701 /* Keybinding handler. This function is called when the user presses
1702 * Ctrl TAB or an arrow key.
1705 gtk_toolbar_move_focus (GtkToolbar *toolbar,
1706 GtkDirectionType dir)
1709 gboolean try_focus = FALSE;
1711 GtkContainer *container = GTK_CONTAINER (toolbar);
1713 if (container->focus_child &&
1714 gtk_widget_child_focus (container->focus_child, dir))
1719 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1721 for (list = children; list != NULL; list = list->next)
1723 GtkWidget *child = list->data;
1725 if (try_focus && GTK_WIDGET_MAPPED (child) && gtk_widget_child_focus (child, dir))
1728 if (child == GTK_CONTAINER (toolbar)->focus_child)
1732 g_list_free (children);
1737 /* The focus handler for the toolbar. It called when the user presses
1738 * TAB or otherwise tries to focus the toolbar.
1741 gtk_toolbar_focus (GtkWidget *widget,
1742 GtkDirectionType dir)
1744 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1745 GList *children, *list;
1747 /* if focus is already somewhere inside the toolbar then return FALSE.
1748 * The only way focus can stay inside the toolbar is when the user presses
1749 * arrow keys or Ctrl TAB (both of which are handled by the
1750 * gtk_toolbar_move_focus() keybinding function.
1752 if (GTK_CONTAINER (widget)->focus_child)
1755 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1757 for (list = children; list != NULL; list = list->next)
1759 GtkWidget *child = list->data;
1761 if (GTK_WIDGET_MAPPED (child) && gtk_widget_child_focus (child, dir))
1765 g_list_free (children);
1771 style_change_notify (GtkToolbar *toolbar)
1773 if (!toolbar->style_set)
1775 /* pretend it was set, then unset, thus reverting to new default */
1776 toolbar->style_set = TRUE;
1777 gtk_toolbar_unset_style (toolbar);
1782 icon_size_change_notify (GtkToolbar *toolbar)
1784 if (!toolbar->icon_size_set)
1786 /* pretend it was set, then unset, thus reverting to new default */
1787 toolbar->icon_size_set = TRUE;
1788 gtk_toolbar_unset_icon_size (toolbar);
1792 static GtkSettings *
1793 toolbar_get_settings (GtkToolbar *toolbar)
1795 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1796 return priv->settings;
1800 gtk_toolbar_screen_changed (GtkWidget *widget,
1801 GdkScreen *previous_screen)
1803 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
1804 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1805 GtkSettings *old_settings = toolbar_get_settings (toolbar);
1806 GtkSettings *settings;
1808 if (gtk_widget_has_screen (GTK_WIDGET (toolbar)))
1809 settings = gtk_widget_get_settings (GTK_WIDGET (toolbar));
1813 if (settings == old_settings)
1818 g_signal_handler_disconnect (old_settings, toolbar->style_set_connection);
1819 g_signal_handler_disconnect (old_settings, toolbar->icon_size_connection);
1821 g_object_unref (old_settings);
1826 toolbar->style_set_connection =
1827 g_signal_connect_swapped (settings,
1828 "notify::gtk-toolbar-style",
1829 G_CALLBACK (style_change_notify),
1831 toolbar->icon_size_connection =
1832 g_signal_connect_swapped (settings,
1833 "notify::gtk-toolbar-icon-size",
1834 G_CALLBACK (icon_size_change_notify),
1837 g_object_ref (settings);
1838 priv->settings = settings;
1841 priv->settings = NULL;
1843 style_change_notify (toolbar);
1844 icon_size_change_notify (toolbar);
1848 find_drop_index (GtkToolbar *toolbar,
1852 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1853 GList *interesting_content;
1855 GtkOrientation orientation;
1856 GtkTextDirection direction;
1857 gint best_distance = G_MAXINT;
1861 ToolbarContent *best_content;
1862 GtkAllocation allocation;
1864 /* list items we care about wrt. drag and drop */
1865 interesting_content = NULL;
1866 for (list = priv->content; list != NULL; list = list->next)
1868 ToolbarContent *content = list->data;
1870 if (toolbar_content_get_state (content) == NORMAL)
1871 interesting_content = g_list_prepend (interesting_content, content);
1873 interesting_content = g_list_reverse (interesting_content);
1875 if (!interesting_content)
1878 orientation = toolbar->orientation;
1879 direction = gtk_widget_get_direction (GTK_WIDGET (toolbar));
1881 /* distance to first interesting item */
1882 best_content = interesting_content->data;
1883 toolbar_content_get_allocation (best_content, &allocation);
1885 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1889 if (direction == GTK_TEXT_DIR_LTR)
1892 pos = allocation.x + allocation.width;
1900 best_content = NULL;
1901 best_distance = ABS (pos - cursor);
1903 /* distance to far end of each item */
1904 for (list = interesting_content; list != NULL; list = list->next)
1906 ToolbarContent *content = list->data;
1908 toolbar_content_get_allocation (content, &allocation);
1910 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1912 if (direction == GTK_TEXT_DIR_LTR)
1913 pos = allocation.x + allocation.width;
1919 pos = allocation.y + allocation.height;
1922 distance = ABS (pos - cursor);
1924 if (distance < best_distance)
1926 best_distance = distance;
1927 best_content = content;
1931 g_list_free (interesting_content);
1936 return g_list_index (priv->content, best_content) + 1;
1940 reset_all_placeholders (GtkToolbar *toolbar)
1942 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1945 for (list = priv->content; list != NULL; list = list->next)
1947 ToolbarContent *content = list->data;
1948 if (toolbar_content_is_placeholder (content))
1949 toolbar_content_set_disappearing (content, TRUE);
1954 physical_to_logical (GtkToolbar *toolbar,
1957 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1961 g_assert (physical >= 0);
1964 for (list = priv->content; list && physical > 0; list = list->next)
1966 ToolbarContent *content = list->data;
1968 if (!toolbar_content_is_placeholder (content))
1973 g_assert (physical == 0);
1979 logical_to_physical (GtkToolbar *toolbar,
1982 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1986 g_assert (logical >= 0);
1989 for (list = priv->content; list; list = list->next)
1991 ToolbarContent *content = list->data;
1993 if (!toolbar_content_is_placeholder (content))
2003 g_assert (logical == 0);
2009 * gtk_toolbar_set_drop_highlight_item:
2010 * @toolbar: a #GtkToolbar
2011 * @tool_item: a #GtkToolItem, or %NULL to turn of highlighting
2012 * @index: a position on @toolbar
2014 * Highlights @toolbar to give an idea of what it would look like
2015 * if @item was added to @toolbar at position indicated by @index. If @item
2016 * is %NULL, highlighting is turned off. In that case @index is ignored.
2018 * The @tool_item passed to this function must not be part of any widget
2019 * hierarchy. When an item is set as drop highlight item it can not
2020 * added to any widget hierarchy or used as highlight item for another
2026 gtk_toolbar_set_drop_highlight_item (GtkToolbar *toolbar,
2027 GtkToolItem *tool_item,
2030 ToolbarContent *content;
2031 GtkToolbarPrivate *priv;
2033 GtkRequisition requisition;
2034 GtkRequisition old_requisition;
2035 gboolean restart_sliding;
2037 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2038 g_return_if_fail (tool_item == NULL || GTK_IS_TOOL_ITEM (tool_item));
2040 gtk_toolbar_check_new_api (toolbar);
2042 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2046 if (priv->highlight_tool_item)
2048 gtk_widget_unparent (GTK_WIDGET (priv->highlight_tool_item));
2049 g_object_unref (priv->highlight_tool_item);
2050 priv->highlight_tool_item = NULL;
2053 reset_all_placeholders (toolbar);
2054 gtk_toolbar_begin_sliding (toolbar);
2058 n_items = gtk_toolbar_get_n_items (toolbar);
2059 if (index < 0 || index > n_items)
2062 if (tool_item != priv->highlight_tool_item)
2064 if (priv->highlight_tool_item)
2065 g_object_unref (priv->highlight_tool_item);
2067 g_object_ref (tool_item);
2068 gtk_object_sink (GTK_OBJECT (tool_item));
2070 priv->highlight_tool_item = tool_item;
2072 gtk_widget_set_parent (GTK_WIDGET (priv->highlight_tool_item),
2073 GTK_WIDGET (toolbar));
2076 index = logical_to_physical (toolbar, index);
2078 content = g_list_nth_data (priv->content, index);
2082 ToolbarContent *prev_content;
2084 prev_content = g_list_nth_data (priv->content, index - 1);
2086 if (prev_content && toolbar_content_is_placeholder (prev_content))
2087 content = prev_content;
2090 if (!content || !toolbar_content_is_placeholder (content))
2092 GtkWidget *placeholder;
2094 placeholder = GTK_WIDGET (gtk_separator_tool_item_new ());
2096 content = toolbar_content_new_tool_item (toolbar,
2097 GTK_TOOL_ITEM (placeholder),
2099 gtk_widget_show (placeholder);
2103 g_assert (toolbar_content_is_placeholder (content));
2105 gtk_widget_size_request (GTK_WIDGET (priv->highlight_tool_item),
2109 restart_sliding = FALSE;
2110 toolbar_content_size_request (content, toolbar, &old_requisition);
2111 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
2113 requisition.height = -1;
2114 if (requisition.width != old_requisition.width)
2115 restart_sliding = TRUE;
2119 requisition.width = -1;
2120 if (requisition.height != old_requisition.height)
2121 restart_sliding = TRUE;
2124 if (toolbar_content_disappearing (content))
2125 restart_sliding = TRUE;
2127 reset_all_placeholders (toolbar);
2128 toolbar_content_set_disappearing (content, FALSE);
2130 toolbar_content_set_size_request (content,
2131 requisition.width, requisition.height);
2133 if (restart_sliding)
2134 gtk_toolbar_begin_sliding (toolbar);
2138 gtk_toolbar_get_child_property (GtkContainer *container,
2144 GtkToolItem *item = GTK_TOOL_ITEM (child);
2146 switch (property_id)
2148 case CHILD_PROP_HOMOGENEOUS:
2149 g_value_set_boolean (value, gtk_tool_item_get_homogeneous (item));
2152 case CHILD_PROP_EXPAND:
2153 g_value_set_boolean (value, gtk_tool_item_get_expand (item));
2157 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
2163 gtk_toolbar_set_child_property (GtkContainer *container,
2166 const GValue *value,
2169 switch (property_id)
2171 case CHILD_PROP_HOMOGENEOUS:
2172 gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (child), g_value_get_boolean (value));
2175 case CHILD_PROP_EXPAND:
2176 gtk_tool_item_set_expand (GTK_TOOL_ITEM (child), g_value_get_boolean (value));
2180 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
2186 gtk_toolbar_show_all (GtkWidget *widget)
2188 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
2191 for (list = priv->content; list != NULL; list = list->next)
2193 ToolbarContent *content = list->data;
2195 toolbar_content_show_all (content);
2198 gtk_widget_show (widget);
2202 gtk_toolbar_hide_all (GtkWidget *widget)
2204 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
2207 for (list = priv->content; list != NULL; list = list->next)
2209 ToolbarContent *content = list->data;
2211 toolbar_content_hide_all (content);
2214 gtk_widget_hide (widget);
2218 gtk_toolbar_add (GtkContainer *container,
2221 GtkToolbar *toolbar;
2223 g_return_if_fail (GTK_IS_TOOLBAR (container));
2224 g_return_if_fail (widget != NULL);
2226 toolbar = GTK_TOOLBAR (container);
2228 if (GTK_IS_TOOL_ITEM (widget))
2229 gtk_toolbar_insert (toolbar, GTK_TOOL_ITEM (widget), -1);
2231 gtk_toolbar_append_widget (toolbar, widget, NULL, NULL);
2235 gtk_toolbar_remove (GtkContainer *container,
2238 GtkToolbar *toolbar;
2239 GtkToolbarPrivate *priv;
2240 ToolbarContent *content_to_remove;
2243 g_return_if_fail (GTK_IS_TOOLBAR (container));
2244 g_return_if_fail (GTK_IS_WIDGET (widget));
2246 toolbar = GTK_TOOLBAR (container);
2247 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2249 content_to_remove = NULL;
2250 for (list = priv->content; list != NULL; list = list->next)
2252 ToolbarContent *content = list->data;
2255 child = toolbar_content_get_widget (content);
2256 if (child && child == widget)
2258 content_to_remove = content;
2263 g_return_if_fail (content_to_remove != NULL);
2265 toolbar_content_remove (content_to_remove, toolbar);
2266 toolbar_content_free (content_to_remove);
2270 gtk_toolbar_forall (GtkContainer *container,
2271 gboolean include_internals,
2272 GtkCallback callback,
2273 gpointer callback_data)
2275 GtkToolbar *toolbar = GTK_TOOLBAR (container);
2276 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2279 g_return_if_fail (callback != NULL);
2281 list = priv->content;
2284 ToolbarContent *content = list->data;
2285 GList *next = list->next;
2287 if (include_internals || !toolbar_content_is_placeholder (content))
2289 GtkWidget *child = toolbar_content_get_widget (content);
2292 (*callback) (child, callback_data);
2298 if (include_internals)
2299 (* callback) (priv->arrow_button, callback_data);
2303 gtk_toolbar_child_type (GtkContainer *container)
2305 return GTK_TYPE_TOOL_ITEM;
2309 gtk_toolbar_reconfigured (GtkToolbar *toolbar)
2311 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2314 list = priv->content;
2317 ToolbarContent *content = list->data;
2318 GList *next = list->next;
2320 toolbar_content_toolbar_reconfigured (content, toolbar);
2327 gtk_toolbar_orientation_changed (GtkToolbar *toolbar,
2328 GtkOrientation orientation)
2330 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2331 if (toolbar->orientation != orientation)
2333 toolbar->orientation = orientation;
2335 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2336 gtk_arrow_set (GTK_ARROW (priv->arrow), GTK_ARROW_DOWN, GTK_SHADOW_NONE);
2338 gtk_arrow_set (GTK_ARROW (priv->arrow), GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
2340 gtk_toolbar_reconfigured (toolbar);
2342 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
2343 g_object_notify (G_OBJECT (toolbar), "orientation");
2348 gtk_toolbar_real_style_changed (GtkToolbar *toolbar,
2349 GtkToolbarStyle style)
2351 if (toolbar->style != style)
2353 toolbar->style = style;
2355 gtk_toolbar_reconfigured (toolbar);
2357 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
2358 g_object_notify (G_OBJECT (toolbar), "toolbar_style");
2363 menu_position_func (GtkMenu *menu,
2369 GtkToolbar *toolbar = GTK_TOOLBAR (user_data);
2370 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2372 GtkRequisition menu_req;
2374 gdk_window_get_origin (GTK_BUTTON (priv->arrow_button)->event_window, x, y);
2375 gtk_widget_size_request (priv->arrow_button, &req);
2376 gtk_widget_size_request (GTK_WIDGET (menu), &menu_req);
2378 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
2380 *y += priv->arrow_button->allocation.height;
2381 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
2382 *x += priv->arrow_button->allocation.width - req.width;
2384 *x += req.width - menu_req.width;
2388 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
2389 *x += priv->arrow_button->allocation.width;
2391 *x -= menu_req.width;
2392 *y += priv->arrow_button->allocation.height - req.height;
2399 menu_deactivated (GtkWidget *menu,
2400 GtkToolbar *toolbar)
2402 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2403 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->arrow_button), FALSE);
2407 menu_detached (GtkWidget *toolbar,
2410 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2415 remove_item (GtkWidget *menu_item,
2418 gtk_container_remove (GTK_CONTAINER (menu_item->parent), menu_item);
2422 show_menu (GtkToolbar *toolbar,
2423 GdkEventButton *event)
2425 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2430 gtk_container_foreach (GTK_CONTAINER (priv->menu), remove_item, NULL);
2431 gtk_widget_destroy (GTK_WIDGET (priv->menu));
2434 priv->menu = GTK_MENU (gtk_menu_new ());
2435 gtk_menu_attach_to_widget (priv->menu,
2436 GTK_WIDGET (toolbar),
2438 g_signal_connect (priv->menu, "deactivate", G_CALLBACK (menu_deactivated), toolbar);
2440 for (list = priv->content; list != NULL; list = list->next)
2442 ToolbarContent *content = list->data;
2444 if (toolbar_content_get_state (content) == OVERFLOWN &&
2445 !toolbar_content_is_placeholder (content))
2447 GtkWidget *menu_item = toolbar_content_retrieve_menu_item (content);
2451 g_assert (GTK_IS_MENU_ITEM (menu_item));
2452 gtk_menu_shell_append (GTK_MENU_SHELL (priv->menu), menu_item);
2457 gtk_widget_show_all (GTK_WIDGET (priv->menu));
2459 gtk_menu_popup (priv->menu, NULL, NULL,
2460 menu_position_func, toolbar,
2461 event? event->button : 0,
2462 event? event->time : gtk_get_current_event_time());
2466 gtk_toolbar_arrow_button_clicked (GtkWidget *button,
2467 GtkToolbar *toolbar)
2469 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2471 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->arrow_button)) &&
2472 (!priv->menu || !GTK_WIDGET_VISIBLE (GTK_WIDGET (priv->menu))))
2474 /* We only get here when the button is clicked with the keybaord,
2475 * because mouse button presses result in the menu being shown so
2476 * that priv->menu would be non-NULL and visible.
2478 show_menu (toolbar, NULL);
2479 gtk_menu_shell_select_first (GTK_MENU_SHELL (priv->menu), FALSE);
2484 gtk_toolbar_arrow_button_press (GtkWidget *button,
2485 GdkEventButton *event,
2486 GtkToolbar *toolbar)
2488 show_menu (toolbar, event);
2489 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
2495 gtk_toolbar_button_press (GtkWidget *toolbar,
2496 GdkEventButton *event)
2498 if (event->button == 3)
2500 gboolean return_value;
2502 g_signal_emit (toolbar, toolbar_signals[POPUP_CONTEXT_MENU], 0,
2503 (int)event->x_root, (int)event->y_root, event->button,
2506 return return_value;
2513 gtk_toolbar_popup_menu (GtkWidget *toolbar)
2515 gboolean return_value;
2516 /* This function is the handler for the "popup menu" keybinding,
2517 * ie., it is called when the user presses Shift F10
2519 g_signal_emit (toolbar, toolbar_signals[POPUP_CONTEXT_MENU], 0,
2520 -1, -1, -1, &return_value);
2522 return return_value;
2528 * Creates a new toolbar.
2530 * Return Value: the newly-created toolbar.
2533 gtk_toolbar_new (void)
2535 GtkToolbar *toolbar;
2537 toolbar = g_object_new (GTK_TYPE_TOOLBAR, NULL);
2539 return GTK_WIDGET (toolbar);
2543 * gtk_toolbar_insert:
2544 * @toolbar: a #GtkToolbar
2545 * @item: a #GtkToolItem
2546 * @pos: the position of the new item
2548 * Insert a #GtkToolItem into the toolbar at position @pos. If @pos is
2549 * 0 the item is prepended to the start of the toolbar. If @pos is
2550 * negative, the item is appended to the end of the toolbar.
2555 gtk_toolbar_insert (GtkToolbar *toolbar,
2559 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2560 g_return_if_fail (GTK_IS_TOOL_ITEM (item));
2562 if (!gtk_toolbar_check_new_api (toolbar))
2566 pos = logical_to_physical (toolbar, pos);
2568 toolbar_content_new_tool_item (toolbar, item, FALSE, pos);
2572 * gtk_toolbar_get_item_index:
2573 * @toolbar: a #GtkToolbar
2574 * @item: a #GtkToolItem that is a child of @toolbar
2576 * Returns the position of @item on the toolbar, starting from 0.
2577 * It is an error if @item is not a child of the toolbar.
2579 * Return value: the position of item on the toolbar.
2584 gtk_toolbar_get_item_index (GtkToolbar *toolbar,
2587 GtkToolbarPrivate *priv;
2591 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
2592 g_return_val_if_fail (GTK_IS_TOOL_ITEM (item), -1);
2593 g_return_val_if_fail (GTK_WIDGET (item)->parent == GTK_WIDGET (toolbar), -1);
2595 if (!gtk_toolbar_check_new_api (toolbar))
2598 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2601 for (list = priv->content; list != NULL; list = list->next)
2603 ToolbarContent *content = list->data;
2606 widget = toolbar_content_get_widget (content);
2608 if (item == GTK_TOOL_ITEM (widget))
2614 return physical_to_logical (toolbar, n);
2618 * gtk_toolbar_set_orientation:
2619 * @toolbar: a #GtkToolbar.
2620 * @orientation: a new #GtkOrientation.
2622 * Sets whether a toolbar should appear horizontally or vertically.
2625 gtk_toolbar_set_orientation (GtkToolbar *toolbar,
2626 GtkOrientation orientation)
2628 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2630 g_signal_emit (toolbar, toolbar_signals[ORIENTATION_CHANGED], 0, orientation);
2634 * gtk_toolbar_get_orientation:
2635 * @toolbar: a #GtkToolbar
2637 * Retrieves the current orientation of the toolbar. See
2638 * gtk_toolbar_set_orientation().
2640 * Return value: the orientation
2643 gtk_toolbar_get_orientation (GtkToolbar *toolbar)
2645 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), GTK_ORIENTATION_HORIZONTAL);
2647 return toolbar->orientation;
2651 * gtk_toolbar_set_style:
2652 * @toolbar: a #GtkToolbar.
2653 * @style: the new style for @toolbar.
2655 * Alters the view of @toolbar to display either icons only, text only, or both.
2658 gtk_toolbar_set_style (GtkToolbar *toolbar,
2659 GtkToolbarStyle style)
2661 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2663 toolbar->style_set = TRUE;
2664 g_signal_emit (toolbar, toolbar_signals[STYLE_CHANGED], 0, style);
2668 * gtk_toolbar_get_style:
2669 * @toolbar: a #GtkToolbar
2671 * Retrieves whether the toolbar has text, icons, or both . See
2672 * gtk_toolbar_set_style().
2674 * Return value: the current style of @toolbar
2677 gtk_toolbar_get_style (GtkToolbar *toolbar)
2679 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), DEFAULT_TOOLBAR_STYLE);
2681 return toolbar->style;
2685 * gtk_toolbar_unset_style:
2686 * @toolbar: a #GtkToolbar
2688 * Unsets a toolbar style set with gtk_toolbar_set_style(), so that
2689 * user preferences will be used to determine the toolbar style.
2692 gtk_toolbar_unset_style (GtkToolbar *toolbar)
2694 GtkToolbarStyle style;
2696 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2698 if (toolbar->style_set)
2700 GtkSettings *settings = toolbar_get_settings (toolbar);
2703 g_object_get (settings,
2704 "gtk-toolbar-style", &style,
2707 style = DEFAULT_TOOLBAR_STYLE;
2709 if (style != toolbar->style)
2710 g_signal_emit (toolbar, toolbar_signals[STYLE_CHANGED], 0, style);
2712 toolbar->style_set = FALSE;
2717 * gtk_toolbar_set_tooltips:
2718 * @toolbar: a #GtkToolbar.
2719 * @enable: set to %FALSE to disable the tooltips, or %TRUE to enable them.
2721 * Sets if the tooltips of a toolbar should be active or not.
2724 gtk_toolbar_set_tooltips (GtkToolbar *toolbar,
2727 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2730 gtk_tooltips_enable (toolbar->tooltips);
2732 gtk_tooltips_disable (toolbar->tooltips);
2736 * gtk_toolbar_get_tooltips:
2737 * @toolbar: a #GtkToolbar
2739 * Retrieves whether tooltips are enabled. See
2740 * gtk_toolbar_set_tooltips().
2742 * Return value: %TRUE if tooltips are enabled
2745 gtk_toolbar_get_tooltips (GtkToolbar *toolbar)
2747 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), FALSE);
2749 return toolbar->tooltips->enabled;
2753 * gtk_toolbar_get_n_items:
2754 * @toolbar: a #GtkToolbar
2756 * Returns the number of items on the toolbar.
2758 * Return value: the number of items on the toolbar
2763 gtk_toolbar_get_n_items (GtkToolbar *toolbar)
2765 GtkToolbarPrivate *priv;
2767 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
2769 if (!gtk_toolbar_check_new_api (toolbar))
2772 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2774 return physical_to_logical (toolbar, g_list_length (priv->content));
2778 * gtk_toolbar_get_nth_item:
2779 * @toolbar: a #GtkToolbar
2780 * @n: A position on the toolbar
2782 * Returns the @n<!-- -->'s item on @toolbar, or %NULL if the
2783 * toolbar does not contain an @n<!-- -->'th item.
2785 * Return value: The @n<!-- -->'th #GtkToolItem on @toolbar, or %NULL if there
2786 * isn't an @n<!-- -->th item.
2791 gtk_toolbar_get_nth_item (GtkToolbar *toolbar,
2794 GtkToolbarPrivate *priv;
2795 ToolbarContent *content;
2798 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), NULL);
2800 if (!gtk_toolbar_check_new_api (toolbar))
2803 n_items = gtk_toolbar_get_n_items (toolbar);
2805 if (n < 0 || n >= n_items)
2808 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2810 content = g_list_nth_data (priv->content, logical_to_physical (toolbar, n));
2813 g_assert (!toolbar_content_is_placeholder (content));
2815 return GTK_TOOL_ITEM (toolbar_content_get_widget (content));
2819 * gtk_toolbar_get_icon_size:
2820 * @toolbar: a #GtkToolbar
2822 * Retrieves the icon size fo the toolbar. See gtk_toolbar_set_icon_size().
2824 * Return value: the current icon size for the icons on the toolbar.
2827 gtk_toolbar_get_icon_size (GtkToolbar *toolbar)
2829 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), DEFAULT_ICON_SIZE);
2831 return toolbar->icon_size;
2835 * gtk_toolbar_get_relief_style:
2836 * @toolbar: a #GtkToolbar
2838 * Returns the relief style of buttons on @toolbar. See
2839 * gtk_button_set_relief().
2841 * Return value: The relief style of buttons on @toolbar.
2846 gtk_toolbar_get_relief_style (GtkToolbar *toolbar)
2848 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), GTK_RELIEF_NONE);
2850 return get_button_relief (toolbar);
2854 * gtk_toolbar_set_show_arrow:
2855 * @toolbar: a #GtkToolbar
2856 * @show_arrow: Whether to show an overflow menu
2858 * Sets whether to show an overflow menu when
2859 * @toolbar doesn't have room for all items on it. If %TRUE,
2860 * items that there are not room are available through an
2866 gtk_toolbar_set_show_arrow (GtkToolbar *toolbar,
2867 gboolean show_arrow)
2869 GtkToolbarPrivate *priv;
2871 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2873 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2874 show_arrow = show_arrow != FALSE;
2876 if (priv->show_arrow != show_arrow)
2878 priv->show_arrow = show_arrow;
2880 if (!priv->show_arrow)
2881 gtk_widget_hide (priv->arrow_button);
2883 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
2884 g_object_notify (G_OBJECT (toolbar), "show_arrow");
2889 * gtk_toolbar_get_show_arrow:
2890 * @toolbar: a #GtkToolbar
2892 * Returns whether the toolbar has an overflow menu.
2893 * See gtk_toolbar_set_show_arrow()
2900 gtk_toolbar_get_show_arrow (GtkToolbar *toolbar)
2902 GtkToolbarPrivate *priv;
2904 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), FALSE);
2906 if (!gtk_toolbar_check_new_api (toolbar))
2909 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2911 return priv->show_arrow;
2915 * gtk_toolbar_get_drop_index:
2916 * @toolbar: a #GtkToolbar
2917 * @x: x coordinate of a point on the toolbar
2918 * @y: y coordinate of a point on the toolbar
2920 * Returns the position corresponding to the indicated point on
2921 * @toolbar. This is useful when dragging items to the toolbar:
2922 * this function returns the position a new item should be
2925 * @x and @y are in @toolbar coordinates.
2927 * Return value: The position corresponding to the point (@x, @y) on the toolbar.
2932 gtk_toolbar_get_drop_index (GtkToolbar *toolbar,
2936 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
2938 if (!gtk_toolbar_check_new_api (toolbar))
2941 return physical_to_logical (toolbar, find_drop_index (toolbar, x, y));
2945 gtk_toolbar_finalize (GObject *object)
2948 GtkToolbar *toolbar = GTK_TOOLBAR (object);
2949 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2951 if (toolbar->tooltips)
2952 g_object_unref (toolbar->tooltips);
2954 for (list = priv->content; list != NULL; list = list->next)
2956 ToolbarContent *content = list->data;
2958 toolbar_content_free (content);
2961 g_list_free (priv->content);
2962 g_list_free (toolbar->children);
2964 g_timer_destroy (priv->timer);
2967 gtk_widget_destroy (GTK_WIDGET (priv->menu));
2970 g_source_remove (priv->idle_id);
2972 G_OBJECT_CLASS (parent_class)->finalize (object);
2980 * gtk_toolbar_set_icon_size:
2981 * @toolbar: A #GtkToolbar
2982 * @icon_size: The #GtkIconSize that stock icons in the toolbar shall have.
2984 * This function sets the size of stock icons in the toolbar. You
2985 * can call it both before you add the icons and after they've been
2986 * added. The size you set will override user preferences for the default
2990 gtk_toolbar_set_icon_size (GtkToolbar *toolbar,
2991 GtkIconSize icon_size)
2993 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2995 toolbar->icon_size_set = TRUE;
2997 if (toolbar->icon_size == icon_size)
3000 toolbar->icon_size = icon_size;
3002 gtk_toolbar_reconfigured (toolbar);
3004 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3008 * gtk_toolbar_unset_icon_size:
3009 * @toolbar: a #GtkToolbar
3011 * Unsets toolbar icon size set with gtk_toolbar_set_icon_size(), so that
3012 * user preferences will be used to determine the icon size.
3015 gtk_toolbar_unset_icon_size (GtkToolbar *toolbar)
3019 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3021 if (toolbar->icon_size_set)
3023 GtkSettings *settings = toolbar_get_settings (toolbar);
3027 g_object_get (settings,
3028 "gtk-toolbar-icon-size", &size,
3032 size = DEFAULT_ICON_SIZE;
3034 if (size != toolbar->icon_size)
3035 gtk_toolbar_set_icon_size (toolbar, size);
3037 toolbar->icon_size_set = FALSE;
3042 * gtk_toolbar_append_item:
3043 * @toolbar: a #GtkToolbar.
3044 * @text: give your toolbar button a label.
3045 * @tooltip_text: a string that appears when the user holds the mouse over this item.
3046 * @tooltip_private_text: use with #GtkTipsQuery.
3047 * @icon: a #GtkWidget that should be used as the button's icon.
3048 * @callback: the function to be executed when the button is pressed.
3049 * @user_data: a pointer to any data you wish to be passed to the callback.
3051 * Inserts a new item into the toolbar. You must specify the position
3052 * in the toolbar where it will be inserted.
3054 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3055 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3057 * Return value: the new toolbar item as a #GtkWidget.
3060 gtk_toolbar_append_item (GtkToolbar *toolbar,
3062 const char *tooltip_text,
3063 const char *tooltip_private_text,
3065 GtkSignalFunc callback,
3068 return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
3070 tooltip_text, tooltip_private_text,
3071 icon, callback, user_data,
3072 toolbar->num_children);
3076 * gtk_toolbar_prepend_item:
3077 * @toolbar: a #GtkToolbar.
3078 * @text: give your toolbar button a label.
3079 * @tooltip_text: a string that appears when the user holds the mouse over this item.
3080 * @tooltip_private_text: use with #GtkTipsQuery.
3081 * @icon: a #GtkWidget that should be used as the button's icon.
3082 * @callback: the function to be executed when the button is pressed.
3083 * @user_data: a pointer to any data you wish to be passed to the callback.
3085 * Adds a new button to the beginning (top or left edges) of the given toolbar.
3087 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3088 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3090 * Return value: the new toolbar item as a #GtkWidget.
3093 gtk_toolbar_prepend_item (GtkToolbar *toolbar,
3095 const char *tooltip_text,
3096 const char *tooltip_private_text,
3098 GtkSignalFunc callback,
3101 return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
3103 tooltip_text, tooltip_private_text,
3104 icon, callback, user_data,
3109 * gtk_toolbar_insert_item:
3110 * @toolbar: a #GtkToolbar.
3111 * @text: give your toolbar button a label.
3112 * @tooltip_text: a string that appears when the user holds the mouse over this item.
3113 * @tooltip_private_text: use with #GtkTipsQuery.
3114 * @icon: a #GtkWidget that should be used as the button's icon.
3115 * @callback: the function to be executed when the button is pressed.
3116 * @user_data: a pointer to any data you wish to be passed to the callback.
3117 * @position: the number of widgets to insert this item after.
3119 * Inserts a new item into the toolbar. You must specify the position in the
3120 * toolbar where it will be inserted.
3122 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3123 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3125 * Return value: the new toolbar item as a #GtkWidget.
3128 gtk_toolbar_insert_item (GtkToolbar *toolbar,
3130 const char *tooltip_text,
3131 const char *tooltip_private_text,
3133 GtkSignalFunc callback,
3137 return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
3139 tooltip_text, tooltip_private_text,
3140 icon, callback, user_data,
3145 * gtk_toolbar_insert_stock:
3146 * @toolbar: A #GtkToolbar
3147 * @stock_id: The id of the stock item you want to insert
3148 * @tooltip_text: The text in the tooltip of the toolbar button
3149 * @tooltip_private_text: The private text of the tooltip
3150 * @callback: The callback called when the toolbar button is clicked.
3151 * @user_data: user data passed to callback
3152 * @position: The position the button shall be inserted at.
3153 * -1 means at the end.
3155 * Inserts a stock item at the specified position of the toolbar. If
3156 * @stock_id is not a known stock item ID, it's inserted verbatim,
3157 * except that underscores used to mark mnemonics are removed.
3159 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3160 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3162 * Returns: the inserted widget
3165 gtk_toolbar_insert_stock (GtkToolbar *toolbar,
3166 const gchar *stock_id,
3167 const char *tooltip_text,
3168 const char *tooltip_private_text,
3169 GtkSignalFunc callback,
3173 return internal_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
3175 tooltip_text, tooltip_private_text,
3176 NULL, callback, user_data,
3181 * gtk_toolbar_append_space:
3182 * @toolbar: a #GtkToolbar.
3184 * Adds a new space to the end of the toolbar.
3187 gtk_toolbar_append_space (GtkToolbar *toolbar)
3189 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_SPACE,
3193 toolbar->num_children);
3197 * gtk_toolbar_prepend_space:
3198 * @toolbar: a #GtkToolbar.
3200 * Adds a new space to the beginning of the toolbar.
3203 gtk_toolbar_prepend_space (GtkToolbar *toolbar)
3205 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_SPACE,
3213 * gtk_toolbar_insert_space:
3214 * @toolbar: a #GtkToolbar
3215 * @position: the number of widgets after which a space should be inserted.
3217 * Inserts a new space in the toolbar at the specified position.
3220 gtk_toolbar_insert_space (GtkToolbar *toolbar,
3223 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_SPACE,
3231 * gtk_toolbar_remove_space:
3232 * @toolbar: a #GtkToolbar.
3233 * @position: the index of the space to remove.
3235 * Removes a space from the specified position.
3238 gtk_toolbar_remove_space (GtkToolbar *toolbar,
3241 GtkToolbarPrivate *priv;
3242 ToolbarContent *content;
3244 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3246 if (!gtk_toolbar_check_old_api (toolbar))
3249 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3251 content = g_list_nth_data (priv->content, position);
3255 g_warning ("Toolbar position %d doesn't exist", position);
3259 if (!toolbar_content_is_separator (content))
3261 g_warning ("Toolbar position %d is not a space", position);
3265 toolbar_content_remove (content, toolbar);
3266 toolbar_content_free (content);
3270 * gtk_toolbar_append_widget:
3271 * @toolbar: a #GtkToolbar.
3272 * @widget: a #GtkWidget to add to the toolbar.
3273 * @tooltip_text: the element's tooltip.
3274 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3276 * Adds a widget to the end of the given toolbar.
3279 gtk_toolbar_append_widget (GtkToolbar *toolbar,
3281 const gchar *tooltip_text,
3282 const gchar *tooltip_private_text)
3284 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_WIDGET,
3286 tooltip_text, tooltip_private_text,
3288 toolbar->num_children);
3292 * gtk_toolbar_prepend_widget:
3293 * @toolbar: a #GtkToolbar.
3294 * @widget: a #GtkWidget to add to the toolbar.
3295 * @tooltip_text: the element's tooltip.
3296 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3298 * Adds a widget to the beginning of the given toolbar.
3301 gtk_toolbar_prepend_widget (GtkToolbar *toolbar,
3303 const gchar *tooltip_text,
3304 const gchar *tooltip_private_text)
3306 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_WIDGET,
3308 tooltip_text, tooltip_private_text,
3314 * gtk_toolbar_insert_widget:
3315 * @toolbar: a #GtkToolbar.
3316 * @widget: a #GtkWidget to add to the toolbar.
3317 * @tooltip_text: the element's tooltip.
3318 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3319 * @position: the number of widgets to insert this widget after.
3321 * Inserts a widget in the toolbar at the given position.
3324 gtk_toolbar_insert_widget (GtkToolbar *toolbar,
3326 const char *tooltip_text,
3327 const char *tooltip_private_text,
3330 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_WIDGET,
3332 tooltip_text, tooltip_private_text,
3338 * gtk_toolbar_append_element:
3339 * @toolbar: a #GtkToolbar.
3340 * @type: a value of type #GtkToolbarChildType that determines what @widget will be.
3341 * @widget: a #GtkWidget, or %NULL.
3342 * @text: the element's label.
3343 * @tooltip_text: the element's tooltip.
3344 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3345 * @icon: a #GtkWidget that provides pictorial representation of the element's function.
3346 * @callback: the function to be executed when the button is pressed.
3347 * @user_data: any data you wish to pass to the callback.
3349 * Adds a new element to the end of a toolbar.
3351 * If @type == %GTK_TOOLBAR_CHILD_WIDGET, @widget is used as the new element.
3352 * If @type == %GTK_TOOLBAR_CHILD_RADIOBUTTON, @widget is used to determine
3353 * the radio group for the new element. In all other cases, @widget must
3356 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3357 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3359 * Return value: the new toolbar element as a #GtkWidget.
3362 gtk_toolbar_append_element (GtkToolbar *toolbar,
3363 GtkToolbarChildType type,
3366 const char *tooltip_text,
3367 const char *tooltip_private_text,
3369 GtkSignalFunc callback,
3372 return gtk_toolbar_insert_element (toolbar, type, widget, text,
3373 tooltip_text, tooltip_private_text,
3374 icon, callback, user_data,
3375 toolbar->num_children);
3379 * gtk_toolbar_prepend_element:
3380 * @toolbar: a #GtkToolbar.
3381 * @type: a value of type #GtkToolbarChildType that determines what @widget will be.
3382 * @widget: a #GtkWidget, or %NULL
3383 * @text: the element's label.
3384 * @tooltip_text: the element's tooltip.
3385 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3386 * @icon: a #GtkWidget that provides pictorial representation of the element's function.
3387 * @callback: the function to be executed when the button is pressed.
3388 * @user_data: any data you wish to pass to the callback.
3390 * Adds a new element to the beginning of a toolbar.
3392 * If @type == %GTK_TOOLBAR_CHILD_WIDGET, @widget is used as the new element.
3393 * If @type == %GTK_TOOLBAR_CHILD_RADIOBUTTON, @widget is used to determine
3394 * the radio group for the new element. In all other cases, @widget must
3397 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3398 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3400 * Return value: the new toolbar element as a #GtkWidget.
3403 gtk_toolbar_prepend_element (GtkToolbar *toolbar,
3404 GtkToolbarChildType type,
3407 const char *tooltip_text,
3408 const char *tooltip_private_text,
3410 GtkSignalFunc callback,
3413 return gtk_toolbar_insert_element (toolbar, type, widget, text,
3414 tooltip_text, tooltip_private_text,
3415 icon, callback, user_data, 0);
3419 * gtk_toolbar_insert_element:
3420 * @toolbar: a #GtkToolbar.
3421 * @type: a value of type #GtkToolbarChildType that determines what @widget
3423 * @widget: a #GtkWidget, or %NULL.
3424 * @text: the element's label.
3425 * @tooltip_text: the element's tooltip.
3426 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3427 * @icon: a #GtkWidget that provides pictorial representation of the element's function.
3428 * @callback: the function to be executed when the button is pressed.
3429 * @user_data: any data you wish to pass to the callback.
3430 * @position: the number of widgets to insert this element after.
3432 * Inserts a new element in the toolbar at the given position.
3434 * If @type == %GTK_TOOLBAR_CHILD_WIDGET, @widget is used as the new element.
3435 * If @type == %GTK_TOOLBAR_CHILD_RADIOBUTTON, @widget is used to determine
3436 * the radio group for the new element. In all other cases, @widget must
3439 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3440 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3442 * Return value: the new toolbar element as a #GtkWidget.
3445 gtk_toolbar_insert_element (GtkToolbar *toolbar,
3446 GtkToolbarChildType type,
3449 const char *tooltip_text,
3450 const char *tooltip_private_text,
3452 GtkSignalFunc callback,
3456 return internal_insert_element (toolbar, type, widget, text,
3457 tooltip_text, tooltip_private_text,
3458 icon, callback, user_data, position, FALSE);
3462 set_child_packing_and_visibility(GtkToolbar *toolbar,
3463 GtkToolbarChild *child)
3468 box = gtk_bin_get_child (GTK_BIN (child->widget));
3470 g_return_if_fail (GTK_IS_BOX (box));
3474 expand = (toolbar->style != GTK_TOOLBAR_BOTH);
3476 gtk_box_set_child_packing (GTK_BOX (box), child->label,
3477 expand, expand, 0, GTK_PACK_END);
3479 if (toolbar->style != GTK_TOOLBAR_ICONS)
3480 gtk_widget_show (child->label);
3482 gtk_widget_hide (child->label);
3487 expand = (toolbar->style != GTK_TOOLBAR_BOTH_HORIZ);
3489 gtk_box_set_child_packing (GTK_BOX (box), child->icon,
3490 expand, expand, 0, GTK_PACK_END);
3492 if (toolbar->style != GTK_TOOLBAR_TEXT)
3493 gtk_widget_show (child->icon);
3495 gtk_widget_hide (child->icon);
3500 internal_insert_element (GtkToolbar *toolbar,
3501 GtkToolbarChildType type,
3504 const char *tooltip_text,
3505 const char *tooltip_private_text,
3507 GtkSignalFunc callback,
3513 ToolbarContent *content;
3514 GtkToolbarPrivate *priv;
3515 char *free_me = NULL;
3516 gboolean is_button = FALSE;
3518 GtkWidget *child_widget;
3519 GtkWidget *child_label;
3520 GtkWidget *child_icon;
3522 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), NULL);
3523 if (type == GTK_TOOLBAR_CHILD_WIDGET)
3524 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3525 else if (type != GTK_TOOLBAR_CHILD_RADIOBUTTON)
3526 g_return_val_if_fail (widget == NULL, NULL);
3528 if (!gtk_toolbar_check_old_api (toolbar))
3531 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3533 child_widget = NULL;
3539 case GTK_TOOLBAR_CHILD_SPACE:
3542 case GTK_TOOLBAR_CHILD_WIDGET:
3543 child_widget = widget;
3546 case GTK_TOOLBAR_CHILD_BUTTON:
3547 case GTK_TOOLBAR_CHILD_TOGGLEBUTTON:
3548 case GTK_TOOLBAR_CHILD_RADIOBUTTON:
3550 if (type == GTK_TOOLBAR_CHILD_BUTTON)
3552 child_widget = gtk_button_new ();
3554 else if (type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
3556 child_widget = gtk_toggle_button_new ();
3557 gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (child_widget), FALSE);
3559 else /* type == GTK_TOOLBAR_CHILD_RADIOBUTTON */
3561 GSList *group = NULL;
3564 group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (widget));
3566 child_widget = gtk_radio_button_new (group);
3567 gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (child_widget), FALSE);
3570 gtk_button_set_relief (GTK_BUTTON (child_widget), get_button_relief (toolbar));
3571 gtk_button_set_focus_on_click (GTK_BUTTON (child_widget), FALSE);
3575 g_signal_connect (child_widget, "clicked",
3576 callback, user_data);
3579 if (toolbar->style == GTK_TOOLBAR_BOTH_HORIZ)
3580 box = gtk_hbox_new (FALSE, 0);
3582 box = gtk_vbox_new (FALSE, 0);
3584 gtk_container_add (GTK_CONTAINER (child_widget), box);
3585 gtk_widget_show (box);
3587 if (text && use_stock)
3589 GtkStockItem stock_item;
3590 if (gtk_stock_lookup (text, &stock_item))
3593 icon = gtk_image_new_from_stock (text, toolbar->icon_size);
3595 text = free_me = _gtk_toolbar_elide_underscores (stock_item.label);
3601 child_label = gtk_label_new (text);
3603 gtk_container_add (GTK_CONTAINER (box), child_label);
3608 child_icon = GTK_WIDGET (icon);
3609 gtk_container_add (GTK_CONTAINER (box), child_icon);
3612 gtk_widget_show (child_widget);
3616 g_assert_not_reached ();
3620 if ((type != GTK_TOOLBAR_CHILD_SPACE) && tooltip_text)
3622 gtk_tooltips_set_tip (toolbar->tooltips, child_widget,
3623 tooltip_text, tooltip_private_text);
3626 content = toolbar_content_new_compatibility (toolbar, type, child_widget,
3627 child_icon, child_label, position);
3632 return child_widget;
3636 * ToolbarContent methods
3638 struct _ToolbarContent
3648 GtkAllocation start_allocation;
3649 GtkAllocation goal_allocation;
3650 guint is_placeholder : 1;
3651 guint disappearing : 1;
3656 GtkToolbarChild child;
3657 GtkAllocation space_allocation;
3658 guint space_visible : 1;
3663 static ToolbarContent *
3664 toolbar_content_new_tool_item (GtkToolbar *toolbar,
3666 gboolean is_placeholder,
3669 ToolbarContent *content;
3670 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3672 content = g_new0 (ToolbarContent, 1);
3674 content->type = TOOL_ITEM;
3675 content->state = NOT_ALLOCATED;
3676 content->u.tool_item.item = item;
3677 content->u.tool_item.is_placeholder = is_placeholder;
3679 gtk_widget_set_parent (GTK_WIDGET (item), GTK_WIDGET (toolbar));
3681 priv->content = g_list_insert (priv->content, content, pos);
3683 if (!is_placeholder)
3685 toolbar->num_children++;
3687 gtk_toolbar_stop_sliding (toolbar);
3690 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3695 static ToolbarContent *
3696 toolbar_content_new_compatibility (GtkToolbar *toolbar,
3697 GtkToolbarChildType type,
3703 ToolbarContent *content;
3704 GtkToolbarChild *child;
3705 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3707 content = g_new0 (ToolbarContent, 1);
3709 child = &(content->u.compatibility.child);
3711 content->type = COMPATIBILITY;
3713 child->widget = widget;
3715 child->label = label;
3717 if (type != GTK_TOOLBAR_CHILD_SPACE)
3719 gtk_widget_set_parent (child->widget, GTK_WIDGET (toolbar));
3723 content->u.compatibility.space_visible = TRUE;
3724 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3727 if (type == GTK_TOOLBAR_CHILD_BUTTON ||
3728 type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON ||
3729 type == GTK_TOOLBAR_CHILD_RADIOBUTTON)
3731 set_child_packing_and_visibility (toolbar, child);
3734 priv->content = g_list_insert (priv->content, content, pos);
3735 toolbar->children = g_list_insert (toolbar->children, child, pos);
3737 toolbar->num_children++;
3743 toolbar_content_remove (ToolbarContent *content,
3744 GtkToolbar *toolbar)
3746 GtkToolbarChild *child;
3747 GtkToolbarPrivate *priv;
3749 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3751 switch (content->type)
3754 gtk_widget_unparent (GTK_WIDGET (content->u.tool_item.item));
3758 child = &(content->u.compatibility.child);
3760 if (child->type != GTK_TOOLBAR_CHILD_SPACE)
3762 g_object_ref (child->widget);
3763 gtk_widget_unparent (child->widget);
3764 gtk_widget_destroy (child->widget);
3765 g_object_unref (child->widget);
3768 toolbar->children = g_list_remove (toolbar->children, child);
3772 priv->content = g_list_remove (priv->content, content);
3774 if (!toolbar_content_is_placeholder (content))
3775 toolbar->num_children--;
3777 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3781 toolbar_content_free (ToolbarContent *content)
3787 calculate_max_homogeneous_pixels (GtkWidget *widget)
3789 PangoContext *context;
3790 PangoFontMetrics *metrics;
3793 context = gtk_widget_get_pango_context (widget);
3794 metrics = pango_context_get_metrics (context,
3795 widget->style->font_desc,
3796 pango_context_get_language (context));
3797 char_width = pango_font_metrics_get_approximate_char_width (metrics);
3798 pango_font_metrics_unref (metrics);
3800 return PANGO_PIXELS (MAX_HOMOGENEOUS_N_CHARS * char_width);
3804 toolbar_content_expose (ToolbarContent *content,
3805 GtkContainer *container,
3806 GdkEventExpose *expose)
3808 GtkToolbar *toolbar = GTK_TOOLBAR (container);
3809 GtkToolbarChild *child;
3810 GtkWidget *widget = NULL; /* quiet gcc */
3812 switch (content->type)
3815 if (!content->u.tool_item.is_placeholder)
3816 widget = GTK_WIDGET (content->u.tool_item.item);
3820 child = &(content->u.compatibility.child);
3822 if (child->type == GTK_TOOLBAR_CHILD_SPACE)
3824 if (get_space_style (toolbar) == GTK_TOOLBAR_SPACE_LINE &&
3825 content->u.compatibility.space_visible)
3827 _gtk_toolbar_paint_space_line (GTK_WIDGET (toolbar), toolbar,
3829 &content->u.compatibility.space_allocation);
3834 widget = child->widget;
3839 gtk_container_propagate_expose (container, widget, expose);
3843 toolbar_content_visible (ToolbarContent *content,
3844 GtkToolbar *toolbar)
3848 switch (content->type)
3851 item = content->u.tool_item.item;
3853 if (!GTK_WIDGET_VISIBLE (item))
3856 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL &&
3857 gtk_tool_item_get_visible_horizontal (item))
3862 if ((toolbar->orientation == GTK_ORIENTATION_VERTICAL &&
3863 gtk_tool_item_get_visible_vertical (item)))
3872 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
3873 return GTK_WIDGET_VISIBLE (content->u.compatibility.child.widget);
3879 g_assert_not_reached ();
3884 toolbar_content_size_request (ToolbarContent *content,
3885 GtkToolbar *toolbar,
3886 GtkRequisition *requisition)
3890 switch (content->type)
3893 gtk_widget_size_request (GTK_WIDGET (content->u.tool_item.item),
3895 if (content->u.tool_item.is_placeholder &&
3896 content->u.tool_item.disappearing)
3898 requisition->width = 0;
3899 requisition->height = 0;
3904 space_size = get_space_size (toolbar);
3906 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
3908 gtk_widget_size_request (content->u.compatibility.child.widget,
3913 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
3915 requisition->width = space_size;
3916 requisition->height = 0;
3920 requisition->height = space_size;
3921 requisition->width = 0;
3930 toolbar_content_is_homogeneous (ToolbarContent *content,
3931 GtkToolbar *toolbar)
3933 gboolean result = FALSE; /* quiet gcc */
3934 GtkRequisition requisition;
3935 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3937 if (priv->max_homogeneous_pixels < 0)
3939 priv->max_homogeneous_pixels =
3940 calculate_max_homogeneous_pixels (GTK_WIDGET (toolbar));
3943 toolbar_content_size_request (content, toolbar, &requisition);
3945 if (requisition.width > priv->max_homogeneous_pixels)
3948 switch (content->type)
3951 result = gtk_tool_item_get_homogeneous (content->u.tool_item.item) &&
3952 !GTK_IS_SEPARATOR_TOOL_ITEM (content->u.tool_item.item);
3954 if (gtk_tool_item_get_is_important (content->u.tool_item.item) &&
3955 toolbar->style == GTK_TOOLBAR_BOTH_HORIZ &&
3956 toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
3963 if (content->u.compatibility.child.type == GTK_TOOLBAR_CHILD_BUTTON ||
3964 content->u.compatibility.child.type == GTK_TOOLBAR_CHILD_RADIOBUTTON ||
3965 content->u.compatibility.child.type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
3980 toolbar_content_is_placeholder (ToolbarContent *content)
3982 if (content->type == TOOL_ITEM && content->u.tool_item.is_placeholder)
3989 toolbar_content_disappearing (ToolbarContent *content)
3991 if (content->type == TOOL_ITEM && content->u.tool_item.disappearing)
3998 toolbar_content_get_state (ToolbarContent *content)
4000 return content->state;
4004 toolbar_content_child_visible (ToolbarContent *content)
4006 switch (content->type)
4009 return GTK_WIDGET_CHILD_VISIBLE (content->u.tool_item.item);
4013 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
4015 return GTK_WIDGET_CHILD_VISIBLE (content->u.compatibility.child.widget);
4019 return content->u.compatibility.space_visible;
4024 return FALSE; /* quiet gcc */
4028 toolbar_content_get_goal_allocation (ToolbarContent *content,
4029 GtkAllocation *allocation)
4031 switch (content->type)
4034 *allocation = content->u.tool_item.goal_allocation;
4038 /* Goal allocations are only relevant when we are
4039 * using the new API, so we should never get here
4041 g_assert_not_reached ();
4047 toolbar_content_get_allocation (ToolbarContent *content,
4048 GtkAllocation *allocation)
4050 GtkToolbarChild *child;
4052 switch (content->type)
4055 *allocation = GTK_WIDGET (content->u.tool_item.item)->allocation;
4059 child = &(content->u.compatibility.child);
4061 if (child->type == GTK_TOOLBAR_CHILD_SPACE)
4062 *allocation = content->u.compatibility.space_allocation;
4064 *allocation = child->widget->allocation;
4070 toolbar_content_set_start_allocation (ToolbarContent *content,
4071 GtkAllocation *allocation)
4073 switch (content->type)
4076 content->u.tool_item.start_allocation = *allocation;
4080 /* start_allocation is only relevant when using the new API */
4081 g_assert_not_reached ();
4087 toolbar_content_get_expand (ToolbarContent *content)
4089 if (content->type == TOOL_ITEM &&
4090 gtk_tool_item_get_expand (content->u.tool_item.item))
4099 toolbar_content_set_goal_allocation (ToolbarContent *content,
4100 GtkAllocation *allocation)
4102 switch (content->type)
4105 content->u.tool_item.goal_allocation = *allocation;
4109 /* Only relevant when using new API */
4110 g_assert_not_reached ();
4116 toolbar_content_set_child_visible (ToolbarContent *content,
4117 GtkToolbar *toolbar,
4120 GtkToolbarChild *child;
4122 switch (content->type)
4125 gtk_widget_set_child_visible (GTK_WIDGET (content->u.tool_item.item),
4130 child = &(content->u.compatibility.child);
4132 if (child->type != GTK_TOOLBAR_CHILD_SPACE)
4134 gtk_widget_set_child_visible (child->widget, visible);
4138 content->u.compatibility.space_visible = visible;
4139 gtk_widget_queue_draw (GTK_WIDGET (toolbar));
4146 toolbar_content_get_start_allocation (ToolbarContent *content,
4147 GtkAllocation *start_allocation)
4149 switch (content->type)
4152 *start_allocation = content->u.tool_item.start_allocation;
4156 /* Only relevant for new API */
4157 g_assert_not_reached ();
4163 toolbar_content_size_allocate (ToolbarContent *content,
4164 GtkAllocation *allocation)
4166 switch (content->type)
4169 gtk_widget_size_allocate (GTK_WIDGET (content->u.tool_item.item),
4174 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
4176 gtk_widget_size_allocate (content->u.compatibility.child.widget,
4181 content->u.compatibility.space_allocation = *allocation;
4188 toolbar_content_set_state (ToolbarContent *content,
4191 content->state = state;
4195 toolbar_content_get_widget (ToolbarContent *content)
4197 GtkToolbarChild *child;
4199 switch (content->type)
4202 return GTK_WIDGET (content->u.tool_item.item);
4206 child = &(content->u.compatibility.child);
4207 if (child->type != GTK_TOOLBAR_CHILD_SPACE)
4208 return child->widget;
4218 toolbar_content_set_disappearing (ToolbarContent *content,
4219 gboolean disappearing)
4221 switch (content->type)
4224 content->u.tool_item.disappearing = disappearing;
4228 /* Only relevant for new API */
4229 g_assert_not_reached ();
4235 toolbar_content_set_size_request (ToolbarContent *content,
4239 switch (content->type)
4242 gtk_widget_set_size_request (GTK_WIDGET (content->u.tool_item.item),
4247 /* Setting size requests only happens with sliding,
4248 * so not relevant here
4250 g_assert_not_reached ();
4256 toolbar_child_reconfigure (GtkToolbar *toolbar,
4257 GtkToolbarChild *child)
4261 GtkToolbarStyle style;
4262 GtkIconSize icon_size;
4263 GtkReliefStyle relief;
4266 style = gtk_toolbar_get_style (toolbar);
4267 icon_size = gtk_toolbar_get_icon_size (toolbar);
4268 relief = gtk_toolbar_get_relief_style (toolbar);
4271 if (child->type == GTK_TOOLBAR_CHILD_BUTTON ||
4272 child->type == GTK_TOOLBAR_CHILD_RADIOBUTTON ||
4273 child->type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
4275 box = gtk_bin_get_child (GTK_BIN (child->widget));
4277 if (style == GTK_TOOLBAR_BOTH && GTK_IS_HBOX (box))
4281 vbox = gtk_vbox_new (FALSE, 0);
4284 gtk_widget_reparent (child->label, vbox);
4286 gtk_widget_reparent (child->icon, vbox);
4288 gtk_widget_destroy (box);
4289 gtk_container_add (GTK_CONTAINER (child->widget), vbox);
4291 gtk_widget_show (vbox);
4293 else if (style == GTK_TOOLBAR_BOTH_HORIZ && GTK_IS_VBOX (box))
4297 hbox = gtk_hbox_new (FALSE, 0);
4300 gtk_widget_reparent (child->label, hbox);
4302 gtk_widget_reparent (child->icon, hbox);
4304 gtk_widget_destroy (box);
4305 gtk_container_add (GTK_CONTAINER (child->widget), hbox);
4307 gtk_widget_show (hbox);
4310 set_child_packing_and_visibility (toolbar, child);
4315 if ((child->type == GTK_TOOLBAR_CHILD_BUTTON ||
4316 child->type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON ||
4317 child->type == GTK_TOOLBAR_CHILD_RADIOBUTTON) &&
4318 GTK_IS_IMAGE (child->icon))
4320 image = GTK_IMAGE (child->icon);
4321 if (gtk_image_get_storage_type (image) == GTK_IMAGE_STOCK)
4323 gtk_image_get_stock (image, &stock_id, NULL);
4324 stock_id = g_strdup (stock_id);
4325 gtk_image_set_from_stock (image,
4333 if (child->type == GTK_TOOLBAR_CHILD_BUTTON ||
4334 child->type == GTK_TOOLBAR_CHILD_RADIOBUTTON ||
4335 child->type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
4337 gtk_button_set_relief (GTK_BUTTON (child->widget), relief);
4342 toolbar_content_toolbar_reconfigured (ToolbarContent *content,
4343 GtkToolbar *toolbar)
4345 switch (content->type)
4348 _gtk_tool_item_toolbar_reconfigured (content->u.tool_item.item);
4352 toolbar_child_reconfigure (toolbar, &(content->u.compatibility.child));
4358 toolbar_content_retrieve_menu_item (ToolbarContent *content)
4360 if (content->type == TOOL_ITEM)
4361 return gtk_tool_item_retrieve_proxy_menu_item (content->u.tool_item.item);
4363 /* FIXME - we might actually be able to do something meaningful here */
4368 toolbar_content_is_separator (ToolbarContent *content)
4370 GtkToolbarChild *child;
4372 switch (content->type)
4375 return GTK_IS_SEPARATOR_TOOL_ITEM (content->u.tool_item.item);
4379 child = &(content->u.compatibility.child);
4380 return (child->type == GTK_TOOLBAR_CHILD_SPACE);
4388 ignore_show_and_hide_all (ToolbarContent *content)
4390 if (content->type == COMPATIBILITY)
4392 GtkToolbarChildType type = content->u.compatibility.child.type;
4394 if (type == GTK_TOOLBAR_CHILD_BUTTON ||
4395 type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON ||
4396 type == GTK_TOOLBAR_CHILD_RADIOBUTTON)
4406 toolbar_content_show_all (ToolbarContent *content)
4410 if (ignore_show_and_hide_all (content))
4413 widget = toolbar_content_get_widget (content);
4415 gtk_widget_show_all (widget);
4419 toolbar_content_hide_all (ToolbarContent *content)
4423 if (ignore_show_and_hide_all (content))
4426 widget = toolbar_content_get_widget (content);
4428 gtk_widget_hide_all (widget);
4435 get_space_size (GtkToolbar *toolbar)
4437 gint space_size = DEFAULT_SPACE_SIZE;
4441 gtk_widget_style_get (GTK_WIDGET (toolbar),
4442 "space_size", &space_size,
4449 static GtkToolbarSpaceStyle
4450 get_space_style (GtkToolbar *toolbar)
4452 GtkToolbarSpaceStyle space_style = DEFAULT_SPACE_STYLE;
4456 gtk_widget_style_get (GTK_WIDGET (toolbar),
4457 "space_style", &space_style,
4464 static GtkReliefStyle
4465 get_button_relief (GtkToolbar *toolbar)
4467 GtkReliefStyle button_relief = GTK_RELIEF_NORMAL;
4469 gtk_widget_ensure_style (GTK_WIDGET (toolbar));
4471 gtk_widget_style_get (GTK_WIDGET (toolbar),
4472 "button_relief", &button_relief,
4475 return button_relief;
4479 get_internal_padding (GtkToolbar *toolbar)
4483 gtk_widget_style_get (GTK_WIDGET (toolbar),
4484 "internal_padding", &ipadding,
4490 static GtkShadowType
4491 get_shadow_type (GtkToolbar *toolbar)
4493 GtkShadowType shadow_type;
4495 gtk_widget_style_get (GTK_WIDGET (toolbar),
4496 "shadow_type", &shadow_type,
4505 #define mixed_api_warning \
4506 "mixing deprecated and non-deprecated GtkToolbar API is not allowed"
4509 gtk_toolbar_check_old_api (GtkToolbar *toolbar)
4511 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
4513 if (priv->api_mode == NEW_API)
4515 g_warning (mixed_api_warning);
4519 priv->api_mode = OLD_API;
4524 gtk_toolbar_check_new_api (GtkToolbar *toolbar)
4526 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
4528 if (priv->api_mode == OLD_API)
4530 g_warning (mixed_api_warning);
4534 priv->api_mode = NEW_API;
4538 /* GTK+ internal methods */
4541 _gtk_toolbar_get_default_space_size (void)
4543 return DEFAULT_SPACE_SIZE;
4547 _gtk_toolbar_paint_space_line (GtkWidget *widget,
4548 GtkToolbar *toolbar,
4550 GtkAllocation *allocation)
4552 const double start_fraction = (SPACE_LINE_START / SPACE_LINE_DIVISION);
4553 const double end_fraction = (SPACE_LINE_END / SPACE_LINE_DIVISION);
4556 GtkToolbarSpaceStyle space_style;
4557 GtkOrientation orientation;
4559 g_return_if_fail (GTK_IS_WIDGET (widget));
4561 space_size = get_space_size (toolbar);
4562 space_style = get_space_style (toolbar);
4563 orientation = toolbar? toolbar->orientation : GTK_ORIENTATION_HORIZONTAL;
4565 if (orientation == GTK_ORIENTATION_HORIZONTAL)
4567 gtk_paint_vline (widget->style, widget->window,
4568 GTK_WIDGET_STATE (widget), area, widget,
4570 allocation->y + allocation->height * start_fraction,
4571 allocation->y + allocation->height * end_fraction,
4572 allocation->x + (space_size - widget->style->xthickness) / 2);
4576 gtk_paint_hline (widget->style, widget->window,
4577 GTK_WIDGET_STATE (widget), area, widget,
4579 allocation->x + allocation->width * start_fraction,
4580 allocation->x + allocation->width * end_fraction,
4581 allocation->y + (space_size - widget->style->ythickness) / 2);
4586 _gtk_toolbar_elide_underscores (const gchar *original)
4590 gboolean last_underscore;
4592 q = result = g_malloc (strlen (original) + 1);
4593 last_underscore = FALSE;
4595 for (p = original; *p; p++)
4597 if (!last_underscore && *p == '_')
4598 last_underscore = TRUE;
4601 last_underscore = FALSE;