gtktoolbar.c 97 KB
Newer Older
1 2 3 4
/* GTK - The GIMP Toolkit
 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
 * GtkToolbar copyright (C) Federico Mena
 *
5 6 7 8
 * Copyright (C) 2002 Anders Carlsson <andersca@codefactory.se>
 * Copyright (C) 2002 James Henstridge <james@daa.com.au>
 * Copyright (C) 2003 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 12 13 14 15 16
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
 * Lesser General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Lesser General Public
20 21 22
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
23 24
 */

25
/*
26
 * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
27 28 29 30 31
 * file for a list of people on the GTK+ Team.  See the ChangeLog
 * files for a list of changes.  These files are distributed with
 * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
 */

32
#undef GTK_DISABLE_DEPRECATED
33

34 35 36 37 38
#include "gtkarrow.h"
#include "gtktoolbar.h"
#include "gtkradiotoolbutton.h"
#include "gtkseparatortoolitem.h"
#include "gtkmenu.h"
39
#include "gtkradiobutton.h"
40
#include "gtktoolbar.h"
41 42 43 44
#include "gtkbindings.h"
#include <gdk/gdkkeysyms.h>
#include "gtkmarshalers.h"
#include "gtkmain.h"
45
#include "gtkstock.h"
46 47
#include "gtklabel.h"
#include "gtkprivate.h"
Havoc Pennington's avatar
Havoc Pennington committed
48
#include "gtkintl.h"
49
#include <string.h>
50

51
#define DEFAULT_IPADDING 0
52 53

/* note: keep in sync with DEFAULT_SPACE_SIZE and DEFAULT_SPACE_STYLE in gtkseparatortoolitem.c */
54
#define DEFAULT_SPACE_SIZE  4
55
#define DEFAULT_SPACE_STYLE GTK_TOOLBAR_SPACE_LINE
56

57
#define DEFAULT_ICON_SIZE GTK_ICON_SIZE_LARGE_TOOLBAR
58
#define DEFAULT_TOOLBAR_STYLE GTK_TOOLBAR_BOTH
59

60 61
#define MAX_HOMOGENEOUS_N_CHARS 13 /* Items that are wider than this do not participate
				    * in the homogeneous game. In units of
62 63 64
				    * pango_font_get_estimated_char_width().
				    */

65
enum {
66 67
  PROP_0,
  PROP_ORIENTATION,
68 69 70 71 72 73 74
  PROP_TOOLBAR_STYLE,
  PROP_SHOW_ARROW
};

enum {
  CHILD_PROP_0,
  CHILD_PROP_EXPAND,
75
  CHILD_PROP_HOMOGENEOUS
76 77
};

78
enum {
79 80
  ORIENTATION_CHANGED,
  STYLE_CHANGED,
81 82
  POPUP_CONTEXT_MENU,
  MOVE_FOCUS,
Soeren Sandmann's avatar
Soeren Sandmann committed
83
  FOCUS_HOME_OR_END,
84
  LAST_SIGNAL
85 86
};

87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
static void gtk_toolbar_init       (GtkToolbar      *toolbar);
static void gtk_toolbar_class_init (GtkToolbarClass *klass);

static void gtk_toolbar_set_property (GObject      *object,
				      guint         prop_id,
				      const GValue *value,
				      GParamSpec   *pspec);
static void gtk_toolbar_get_property (GObject      *object,
				      guint         prop_id,
				      GValue       *value,
				      GParamSpec   *pspec);

static gint     gtk_toolbar_expose         (GtkWidget        *widget,
					    GdkEventExpose   *event);
static void     gtk_toolbar_realize        (GtkWidget        *widget);
static void     gtk_toolbar_unrealize      (GtkWidget        *widget);
static void     gtk_toolbar_size_request   (GtkWidget        *widget,
					    GtkRequisition   *requisition);
static void     gtk_toolbar_size_allocate  (GtkWidget        *widget,
					    GtkAllocation    *allocation);
static void     gtk_toolbar_style_set      (GtkWidget        *widget,
					    GtkStyle         *prev_style);
static void     gtk_toolbar_direction_changed (GtkWidget        *widget,
                                               GtkTextDirection  previous_direction);
static gboolean gtk_toolbar_focus          (GtkWidget        *widget,
					    GtkDirectionType  dir);
static void     gtk_toolbar_screen_changed (GtkWidget        *widget,
					    GdkScreen        *previous_screen);
static void     gtk_toolbar_map            (GtkWidget        *widget);
static void     gtk_toolbar_unmap          (GtkWidget        *widget);

static void     gtk_toolbar_set_child_property (GtkContainer    *container,
						GtkWidget       *child,
						guint            property_id,
						const GValue    *value,
						GParamSpec      *pspec);
static void    gtk_toolbar_get_child_property (GtkContainer    *container,
					       GtkWidget       *child,
					       guint            property_id,
					       GValue          *value,
					       GParamSpec      *pspec);
128 129
static void gtk_toolbar_finalize (GObject *object);

130 131 132 133 134 135 136 137 138 139 140 141

static void  gtk_toolbar_add        (GtkContainer *container,
				     GtkWidget    *widget);
static void  gtk_toolbar_remove     (GtkContainer *container,
				     GtkWidget    *widget);
static void  gtk_toolbar_forall     (GtkContainer *container,
				     gboolean      include_internals,
				     GtkCallback   callback,
				     gpointer      callback_data);
static GType gtk_toolbar_child_type (GtkContainer *container);

static void gtk_toolbar_real_orientation_changed (GtkToolbar      *toolbar,
142
						  GtkOrientation   orientation);
143
static void gtk_toolbar_real_style_changed       (GtkToolbar      *toolbar,
144 145
						  GtkToolbarStyle  style);

Soeren Sandmann's avatar
Soeren Sandmann committed
146 147 148 149
static gboolean gtk_toolbar_move_focus        (GtkToolbar       *toolbar,
					       GtkDirectionType  dir);
static gboolean gtk_toolbar_focus_home_or_end (GtkToolbar       *toolbar,
					       gboolean          focus_home);
150 151 152 153 154 155 156 157 158 159 160

static gboolean             gtk_toolbar_button_press         (GtkWidget      *toolbar,
							      GdkEventButton *event);
static gboolean             gtk_toolbar_arrow_button_press (GtkWidget      *button,
							      GdkEventButton *event,
							      GtkToolbar     *toolbar);
static void                 gtk_toolbar_arrow_button_clicked (GtkWidget      *button,
							       GtkToolbar     *toolbar);
static void                 gtk_toolbar_update_button_relief (GtkToolbar     *toolbar);
static GtkReliefStyle       get_button_relief                (GtkToolbar     *toolbar);
static gint                 get_internal_padding             (GtkToolbar     *toolbar);
161
static GtkShadowType        get_shadow_type                  (GtkToolbar     *toolbar);
162 163
static void                 gtk_toolbar_remove_tool_item     (GtkToolbar     *toolbar,
							      GtkToolItem    *item);
164
static gboolean		    gtk_toolbar_popup_menu	     (GtkWidget      *toolbar);
165 166 167 168 169 170 171 172 173 174 175 176

static GtkWidget *gtk_toolbar_internal_insert_element (GtkToolbar          *toolbar,
						       GtkToolbarChildType  type,
						       GtkWidget           *widget,
						       const char          *text,
						       const char          *tooltip_text,
						       const char          *tooltip_private_text,
						       GtkWidget           *icon,
						       GtkSignalFunc        callback,
						       gpointer             user_data,
						       gint                 position,
						       gboolean             use_stock);
177 178 179 180
static void gtk_toolbar_insert_tool_item (GtkToolbar  *toolbar,
					  GtkToolItem *item,
					  gint         pos,
					  gboolean     is_placeholder);
181 182 183 184 185 186 187 188


typedef enum {
  DONT_KNOW,
  OLD_API,
  NEW_API
} ApiMode;

Matthias Clasen's avatar
Matthias Clasen committed
189
#define GTK_TOOLBAR_GET_PRIVATE(o)  (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_TOOLBAR, GtkToolbarPrivate))
190 191 192 193 194 195 196 197 198 199 200
typedef struct _ToolbarContent ToolbarContent;
struct _ToolbarContent
{
  GtkToolItem *item;
  guint        is_overflow : 1;
  guint        is_placeholder : 1;
  gint	       start_width;
  gint	       goal_width;
  gint	       start_height;
  gint         goal_height;
};
Matthias Clasen's avatar
Matthias Clasen committed
201

202 203
struct _GtkToolbarPrivate
{
204
  GList     *content;
205 206 207 208 209
  
  GtkWidget *arrow;
  GtkWidget *arrow_button;
  
  gboolean   show_arrow;
Havoc Pennington's avatar
Havoc Pennington committed
210

211
  GtkMenu   *menu;
212

213 214 215
  GdkWindow *event_window;
  ApiMode    api_mode;
  GtkSettings *settings;
216 217 218 219 220 221
  int        idle_id;
  GTimer   *timer;
  gboolean   need_sync;
  gboolean   leaving_dnd;
  gboolean   in_dnd;
  gint	     n_overflow_items_when_dnd_started;
222
  GtkToolItem *highlight_tool_item;
223
};
224

225 226
static GtkContainerClass *parent_class = NULL;
static guint toolbar_signals [LAST_SIGNAL] = { 0 };
227

Manish Singh's avatar
Manish Singh committed
228
GType
229
gtk_toolbar_get_type (void)
230
{
231
  static GtkType type = 0;
232

233
  if (!type)
234
    {
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
      static const GTypeInfo type_info =
	{
	  sizeof (GtkToolbarClass),
	  (GBaseInitFunc) NULL,
	  (GBaseFinalizeFunc) NULL,
	  (GClassInitFunc) gtk_toolbar_class_init,
	  (GClassFinalizeFunc) NULL,
	  NULL,
	  sizeof (GtkToolbar),
	  0, /* n_preallocs */
	  (GInstanceInitFunc) gtk_toolbar_init,
	};

      type = g_type_register_static (GTK_TYPE_CONTAINER,
				     "GtkToolbar",
				     &type_info, 0);
251
    }
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
  
  return type;
}

static void
add_arrow_bindings (GtkBindingSet   *binding_set,
		    guint            keysym,
		    GtkDirectionType dir)
{
  guint keypad_keysym = keysym - GDK_Left + GDK_KP_Left;
  
  gtk_binding_entry_add_signal (binding_set, keysym, 0,
                                "move_focus", 1,
                                GTK_TYPE_DIRECTION_TYPE, dir);
  gtk_binding_entry_add_signal (binding_set, keypad_keysym, 0,
                                "move_focus", 1,
                                GTK_TYPE_DIRECTION_TYPE, dir);
}
270

271 272 273 274 275 276 277 278 279 280 281 282 283
static void
add_ctrl_tab_bindings (GtkBindingSet    *binding_set,
		       GdkModifierType   modifiers,
		       GtkDirectionType  direction)
{
  gtk_binding_entry_add_signal (binding_set,
				GDK_Tab, GDK_CONTROL_MASK | modifiers,
				"move_focus", 1,
				GTK_TYPE_DIRECTION_TYPE, direction);
  gtk_binding_entry_add_signal (binding_set,
				GDK_KP_Tab, GDK_CONTROL_MASK | modifiers,
				"move_focus", 1,
				GTK_TYPE_DIRECTION_TYPE, direction);
284 285 286
}

static void
287
gtk_toolbar_class_init (GtkToolbarClass *klass)
288
{
289
  GObjectClass *gobject_class;
290 291
  GtkWidgetClass *widget_class;
  GtkContainerClass *container_class;
292
  GtkBindingSet *binding_set;
293

294 295 296 297 298 299
  parent_class = g_type_class_peek_parent (klass);
  
  gobject_class = (GObjectClass *)klass;
  widget_class = (GtkWidgetClass *)klass;
  container_class = (GtkContainerClass *)klass;
  
300 301
  gobject_class->set_property = gtk_toolbar_set_property;
  gobject_class->get_property = gtk_toolbar_get_property;
302
  gobject_class->finalize = gtk_toolbar_finalize;
303

304
  widget_class->button_press_event = gtk_toolbar_button_press;
305 306 307
  widget_class->expose_event = gtk_toolbar_expose;
  widget_class->size_request = gtk_toolbar_size_request;
  widget_class->size_allocate = gtk_toolbar_size_allocate;
Havoc Pennington's avatar
Havoc Pennington committed
308
  widget_class->style_set = gtk_toolbar_style_set;
309
  widget_class->direction_changed = gtk_toolbar_direction_changed;
310
  widget_class->focus = gtk_toolbar_focus;
Owen Taylor's avatar
Owen Taylor committed
311
  widget_class->screen_changed = gtk_toolbar_screen_changed;
312 313 314 315
  widget_class->realize = gtk_toolbar_realize;
  widget_class->unrealize = gtk_toolbar_unrealize;
  widget_class->map = gtk_toolbar_map;
  widget_class->unmap = gtk_toolbar_unmap;
316
  widget_class->popup_menu = gtk_toolbar_popup_menu;
Havoc Pennington's avatar
Havoc Pennington committed
317
  
318
  container_class->add    = gtk_toolbar_add;
319
  container_class->remove = gtk_toolbar_remove;
320
  container_class->forall = gtk_toolbar_forall;
321 322 323 324 325 326
  container_class->child_type = gtk_toolbar_child_type;
  container_class->get_child_property = gtk_toolbar_get_child_property;
  container_class->set_child_property = gtk_toolbar_set_child_property;
  
  klass->orientation_changed = gtk_toolbar_real_orientation_changed;
  klass->style_changed = gtk_toolbar_real_style_changed;
327
  
328 329 330 331 332 333 334
/**
 * GtkToolbar::orientation-changed:
 * @toolbar: the object which emitted the signal
 * @orientation: the new #GtkOrientation of the toolbar
 *
 * Emitted when the orientation of the toolbar changes.
 */
335
  toolbar_signals[ORIENTATION_CHANGED] =
336
    g_signal_new ("orientation-changed",
337
		  G_OBJECT_CLASS_TYPE (klass),
Manish Singh's avatar
Manish Singh committed
338 339 340
		  G_SIGNAL_RUN_FIRST,
		  G_STRUCT_OFFSET (GtkToolbarClass, orientation_changed),
		  NULL, NULL,
341
		  g_cclosure_marshal_VOID__ENUM,
Manish Singh's avatar
Manish Singh committed
342 343
		  G_TYPE_NONE, 1,
		  GTK_TYPE_ORIENTATION);
344 345 346 347 348 349 350
/**
 * GtkToolbar::style-changed:
 * @toolbar: The #GtkToolbar which emitted the signal
 * @style: the new #GtkToolbarStyle of the toolbar
 *
 * Emitted when the style of the toolbar changes. 
 */
351
  toolbar_signals[STYLE_CHANGED] =
352
    g_signal_new ("style-changed",
353
		  G_OBJECT_CLASS_TYPE (klass),
Manish Singh's avatar
Manish Singh committed
354 355 356
		  G_SIGNAL_RUN_FIRST,
		  G_STRUCT_OFFSET (GtkToolbarClass, style_changed),
		  NULL, NULL,
357
		  g_cclosure_marshal_VOID__ENUM,
Manish Singh's avatar
Manish Singh committed
358 359
		  G_TYPE_NONE, 1,
		  GTK_TYPE_TOOLBAR_STYLE);
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377
/**
 * GtkToolbar::popup-context-menu:
 * @toolbar: the #GtkToolbar which emitted the signal
 * @x: the x coordinate of the point where the menu should appear
 * @y: the y coordinate of the point where the menu should appear
 * @button: the mouse button the user pressed, or -1
 *
 * Emitted when the user right-clicks the toolbar or uses the
 * keybinding to display a popup menu.
 *
 * Application developers should handle this signal if they want
 * to display a context menu on the toolbar. The context-menu should
 * appear at the coordinates given by @x and @y. The mouse button
 * number is given by the @button parameter. If the menu was popped
 * up using the keybaord, @button is -1.
 *
 * Return value: return %TRUE if the signal was handled, %FALSE if not
 */
378 379 380
  toolbar_signals[POPUP_CONTEXT_MENU] =
    g_signal_new ("popup_context_menu",
		  G_OBJECT_CLASS_TYPE (klass),
381
		  G_SIGNAL_RUN_LAST,
382
		  G_STRUCT_OFFSET (GtkToolbarClass, popup_context_menu),
383 384 385 386 387
		  _gtk_boolean_handled_accumulator, NULL,
		  _gtk_marshal_BOOLEAN__INT_INT_INT,
		  G_TYPE_BOOLEAN, 3,
		  G_TYPE_INT, G_TYPE_INT,
		  G_TYPE_INT);
388 389 390 391 392 393 394 395 396 397
/**
 * GtkToolbar::move-focus:
 * @toolbar: the #GtkToolbar which emitted the signal
 * @dir: a #GtkDirection
 *
 * A keybinding signal used internally by GTK+. This signal can't
 * be used in application code.
 *
 * Return value: %TRUE if the signal was handled, %FALSE if not
 */
398 399 400 401 402 403 404 405 406
  toolbar_signals[MOVE_FOCUS] =
    _gtk_binding_signal_new ("move_focus",
			     G_TYPE_FROM_CLASS (klass),
			     G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
			     G_CALLBACK (gtk_toolbar_move_focus),
			     NULL, NULL,
			     _gtk_marshal_BOOLEAN__ENUM,
			     G_TYPE_BOOLEAN, 1,
			     GTK_TYPE_DIRECTION_TYPE);
407 408 409 410 411 412 413 414 415 416
/**
 * GtkToolbar::focus-home-or-end:
 * @toolbar: the #GtkToolbar which emitted the signal
 * @focus_home: %TRUE if the first item should be focused
 *
 * A keybinding signal used internally by GTK+. This signal can't
 * be used in application code
 *
 * Return value: %TRUE if the signal was handled, %FALSE if not
 */
Soeren Sandmann's avatar
Soeren Sandmann committed
417 418
  toolbar_signals[FOCUS_HOME_OR_END] =
    _gtk_binding_signal_new ("focus_home_or_end",
419 420
			     G_OBJECT_CLASS_TYPE (klass),
			     G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
Soeren Sandmann's avatar
Soeren Sandmann committed
421
			     G_CALLBACK (gtk_toolbar_focus_home_or_end),
422 423 424 425 426 427
			     NULL, NULL,
			     _gtk_marshal_BOOLEAN__BOOLEAN,
			     G_TYPE_BOOLEAN, 1,
			     G_TYPE_BOOLEAN);

  /* properties */
428 429 430 431 432 433 434 435
  g_object_class_install_property (gobject_class,
				   PROP_ORIENTATION,
				   g_param_spec_enum ("orientation",
 						      _("Orientation"),
 						      _("The orientation of the toolbar"),
 						      GTK_TYPE_ORIENTATION,
 						      GTK_ORIENTATION_HORIZONTAL,
 						      G_PARAM_READWRITE));
436 437 438 439

  g_object_class_install_property (gobject_class,
				   PROP_TOOLBAR_STYLE,
				   g_param_spec_enum ("toolbar_style",
440 441 442 443 444
 						      _("Toolbar Style"),
 						      _("How to draw the toolbar"),
 						      GTK_TYPE_TOOLBAR_STYLE,
 						      GTK_TOOLBAR_ICONS,
 						      G_PARAM_READWRITE));
445 446 447 448 449
  g_object_class_install_property (gobject_class,
				   PROP_SHOW_ARROW,
				   g_param_spec_boolean ("show_arrow",
							 _("Show Arrow"),
							 _("If an arrow should be shown if the toolbar doesn't fit"),
450
							 TRUE,
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470
							 G_PARAM_READWRITE));

  /* child properties */
  gtk_container_class_install_child_property (container_class,
					      CHILD_PROP_EXPAND,
					      g_param_spec_boolean ("expand", 
								    _("Expand"), 
								    _("Whether the item should receive extra space when the toolbar grows"),
								    TRUE,
								    G_PARAM_READWRITE));

  gtk_container_class_install_child_property (container_class,
					      CHILD_PROP_HOMOGENEOUS,
					      g_param_spec_boolean ("homogeneous", 
								    _("Homogeneous"), 
								    _("Whether the item should be the same size as other homogeneous items"),
								    TRUE,
								    G_PARAM_READWRITE));

  /* style properties */
Havoc Pennington's avatar
Havoc Pennington committed
471 472 473 474 475 476 477 478
  gtk_widget_class_install_style_property (widget_class,
					   g_param_spec_int ("space_size",
							     _("Spacer size"),
							     _("Size of spacers"),
							     0,
							     G_MAXINT,
                                                             DEFAULT_SPACE_SIZE,
							     G_PARAM_READABLE));
479
  
480 481 482 483 484 485 486 487
  gtk_widget_class_install_style_property (widget_class,
					   g_param_spec_int ("internal_padding",
							     _("Internal padding"),
							     _("Amount of border space between the toolbar shadow and the buttons"),
							     0,
							     G_MAXINT,
                                                             DEFAULT_IPADDING,
                                                             G_PARAM_READABLE));
488

Havoc Pennington's avatar
Havoc Pennington committed
489 490 491 492 493 494 495
  gtk_widget_class_install_style_property (widget_class,
					   g_param_spec_enum ("space_style",
							     _("Space style"),
							     _("Whether spacers are vertical lines or just blank"),
                                                              GTK_TYPE_TOOLBAR_SPACE_STYLE,
                                                              DEFAULT_SPACE_STYLE,
                                                              G_PARAM_READABLE));
496
  
Havoc Pennington's avatar
Havoc Pennington committed
497 498
  gtk_widget_class_install_style_property (widget_class,
					   g_param_spec_enum ("button_relief",
499 500
							      _("Button relief"),
							      _("Type of bevel around toolbar buttons"),
Havoc Pennington's avatar
Havoc Pennington committed
501
                                                              GTK_TYPE_RELIEF_STYLE,
502
                                                              GTK_RELIEF_NONE,
Havoc Pennington's avatar
Havoc Pennington committed
503
                                                              G_PARAM_READABLE));
504 505 506 507 508 509 510 511
  gtk_widget_class_install_style_property (widget_class,
                                           g_param_spec_enum ("shadow_type",
                                                              _("Shadow type"),
                                                              _("Style of bevel around the toolbar"),
                                                              GTK_TYPE_SHADOW_TYPE,
                                                              GTK_SHADOW_OUT,
                                                              G_PARAM_READABLE));

512
  gtk_settings_install_property (g_param_spec_enum ("gtk-toolbar-style",
513 514 515
                                                    _("Toolbar style"),
                                                    _("Whether default toolbars have text only, text and icons, icons only, etc."),
                                                    GTK_TYPE_TOOLBAR_STYLE,
516
                                                    DEFAULT_TOOLBAR_STYLE,
517 518
                                                    G_PARAM_READWRITE));

519
  gtk_settings_install_property (g_param_spec_enum ("gtk-toolbar-icon-size",
520 521 522
                                                    _("Toolbar icon size"),
                                                    _("Size of icons in default toolbars"),
                                                    GTK_TYPE_ICON_SIZE,
523
                                                    DEFAULT_ICON_SIZE,
524
                                                    G_PARAM_READWRITE));  
525

526 527 528 529 530 531 532 533
  binding_set = gtk_binding_set_by_class (klass);

  add_arrow_bindings (binding_set, GDK_Left, GTK_DIR_LEFT);
  add_arrow_bindings (binding_set, GDK_Right, GTK_DIR_RIGHT);
  add_arrow_bindings (binding_set, GDK_Up, GTK_DIR_UP);
  add_arrow_bindings (binding_set, GDK_Down, GTK_DIR_DOWN);

  gtk_binding_entry_add_signal (binding_set, GDK_KP_Home, 0,
Soeren Sandmann's avatar
Soeren Sandmann committed
534
                                "focus_home_or_end", 1,
535 536
				G_TYPE_BOOLEAN, TRUE);
  gtk_binding_entry_add_signal (binding_set, GDK_Home, 0,
Soeren Sandmann's avatar
Soeren Sandmann committed
537
                                "focus_home_or_end", 1,
538 539
				G_TYPE_BOOLEAN, TRUE);
  gtk_binding_entry_add_signal (binding_set, GDK_KP_End, 0,
Soeren Sandmann's avatar
Soeren Sandmann committed
540
                                "focus_home_or_end", 1,
541 542
				G_TYPE_BOOLEAN, FALSE);
  gtk_binding_entry_add_signal (binding_set, GDK_End, 0,
Soeren Sandmann's avatar
Soeren Sandmann committed
543
                                "focus_home_or_end", 1,
544 545
				G_TYPE_BOOLEAN, FALSE);

Soeren Sandmann's avatar
Soeren Sandmann committed
546 547
  add_ctrl_tab_bindings (binding_set, 0, GTK_DIR_TAB_FORWARD);
  add_ctrl_tab_bindings (binding_set, GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
548 549

  g_type_class_add_private (gobject_class, sizeof (GtkToolbarPrivate));  
550 551
}

552
static void
553
gtk_toolbar_init (GtkToolbar *toolbar)
554
{
555 556 557 558
  GtkToolbarPrivate *priv;
  
  GTK_WIDGET_UNSET_FLAGS (toolbar, GTK_CAN_FOCUS);
  GTK_WIDGET_SET_FLAGS (toolbar, GTK_NO_WINDOW);
559

560
  priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
561
  
562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581
  toolbar->orientation = GTK_ORIENTATION_HORIZONTAL;
  toolbar->style = DEFAULT_TOOLBAR_STYLE;
  toolbar->icon_size = DEFAULT_ICON_SIZE;
  toolbar->tooltips = gtk_tooltips_new ();
  g_object_ref (toolbar->tooltips);
  gtk_object_sink (GTK_OBJECT (toolbar->tooltips));
  
  priv->arrow_button = gtk_toggle_button_new ();
  g_signal_connect (priv->arrow_button, "button_press_event",
		    G_CALLBACK (gtk_toolbar_arrow_button_press), toolbar);
  g_signal_connect (priv->arrow_button, "clicked",
		    G_CALLBACK (gtk_toolbar_arrow_button_clicked), toolbar);
  gtk_button_set_relief (GTK_BUTTON (priv->arrow_button),
			 get_button_relief (toolbar));

  priv->api_mode = DONT_KNOW;
  
  gtk_button_set_focus_on_click (GTK_BUTTON (priv->arrow_button), FALSE);
  
  priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
582
  gtk_widget_set_name (priv->arrow, "gtk-toolbar-arrow");
583 584 585 586
  gtk_widget_show (priv->arrow);
  gtk_container_add (GTK_CONTAINER (priv->arrow_button), priv->arrow);
  
  gtk_widget_set_parent (priv->arrow_button, GTK_WIDGET (toolbar));
587

588 589
  /* which child position a drop will occur at */
  priv->menu = NULL;
590
  priv->show_arrow = TRUE;
591
  priv->settings = NULL;
592 593

  priv->timer = g_timer_new ();
594 595
}

596 597 598
static gboolean
toolbar_item_visible (GtkToolbar  *toolbar,
		      GtkToolItem *item)
599
{
600
  if (GTK_WIDGET_VISIBLE (item) &&
601 602 603 604
      ((toolbar->orientation == GTK_ORIENTATION_HORIZONTAL &&
	gtk_tool_item_get_visible_horizontal (item)) ||
       (toolbar->orientation == GTK_ORIENTATION_VERTICAL &&
	gtk_tool_item_get_visible_vertical (item))))
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621
    {
      GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
      
      /* With the old toolbar you could hide a button by calling gtk_widget_hide()
       * on it. This doesn't work with the new API because the GtkToolItem will not be
       * hidden.
       */
      if (priv->api_mode == OLD_API)
	{
	  GtkWidget *bin_child = GTK_BIN (item)->child;
	  
	  if (bin_child && !GTK_WIDGET_VISIBLE (bin_child))
	    return FALSE;
	}
      
      return TRUE;
    }
622
  
623
  return FALSE;
624 625
}

626
static gboolean
627 628
toolbar_item_is_homogeneous (GtkToolbar  *toolbar,
			     GtkToolItem *item)
629
{
630 631 632 633 634 635 636 637 638 639 640 641 642
  gboolean result;
  GtkWidget *widget = GTK_WIDGET (item);
  GtkRequisition requisition;
  PangoContext *context;
  PangoFontMetrics *metrics;
  int char_width;
  gint max_homogeneous_pixels;

  context = gtk_widget_get_pango_context (widget);
  metrics = pango_context_get_metrics (context,
				       widget->style->font_desc,
				       pango_context_get_language (context));
  char_width = pango_font_metrics_get_approximate_char_width (metrics);
643 644
  pango_font_metrics_unref (metrics);
      
645 646 647
  max_homogeneous_pixels = PANGO_PIXELS (MAX_HOMOGENEOUS_N_CHARS * char_width);
  
  result = gtk_tool_item_get_homogeneous (item) && !GTK_IS_SEPARATOR_TOOL_ITEM (item);
648

649
  gtk_widget_size_request (GTK_WIDGET (item), &requisition);
650

651 652 653 654
  if ((gtk_tool_item_get_is_important (item) &&
       toolbar->style == GTK_TOOLBAR_BOTH_HORIZ &&
       toolbar->orientation == GTK_ORIENTATION_HORIZONTAL) ||
      requisition.width > max_homogeneous_pixels)
655 656 657 658 659
    {
      result = FALSE;
    }

  return result;
660 661
}

662
static void
663 664
gtk_toolbar_set_property (GObject     *object,
			  guint        prop_id,
665 666
			  const GValue *value,
			  GParamSpec   *pspec)
667 668
{
  GtkToolbar *toolbar = GTK_TOOLBAR (object);
669

670
  switch (prop_id)
671
    {
672 673
    case PROP_ORIENTATION:
      gtk_toolbar_set_orientation (toolbar, g_value_get_enum (value));
674
      break;
675 676
    case PROP_TOOLBAR_STYLE:
      gtk_toolbar_set_style (toolbar, g_value_get_enum (value));
677
      break;
678 679 680 681 682 683
    case PROP_SHOW_ARROW:
      gtk_toolbar_set_show_arrow (toolbar, g_value_get_boolean (value));
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
684 685 686 687
    }
}

static void
688 689 690 691
gtk_toolbar_get_property (GObject    *object,
			  guint       prop_id,
			  GValue     *value,
			  GParamSpec *pspec)
692 693
{
  GtkToolbar *toolbar = GTK_TOOLBAR (object);
694 695
  GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
  
696
  switch (prop_id)
697
    {
698 699
    case PROP_ORIENTATION:
      g_value_set_enum (value, toolbar->orientation);
700
      break;
701 702
    case PROP_TOOLBAR_STYLE:
      g_value_set_enum (value, toolbar->style);
703
      break;
704 705 706
    case PROP_SHOW_ARROW:
      g_value_set_boolean (value, priv->show_arrow);
      break;
707
    default:
708
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
709 710 711 712
      break;
    }
}

713 714
static void
gtk_toolbar_map (GtkWidget *widget)
715
{
716
  GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
717

718
  GTK_WIDGET_CLASS (parent_class)->map (widget);
719

720 721
  if (priv->event_window)
    gdk_window_show_unraised (priv->event_window);
722 723 724
}

static void
725
gtk_toolbar_unmap (GtkWidget *widget)
726
{
727
  GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
728

729 730
  if (priv->event_window)
    gdk_window_hide (priv->event_window);
731

732
  GTK_WIDGET_CLASS (parent_class)->unmap (widget);
733 734
}

735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755
static void
gtk_toolbar_realize (GtkWidget *widget)
{
  GtkToolbar *toolbar = GTK_TOOLBAR (widget);
  GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);

  GdkWindowAttr attributes;
  gint attributes_mask;
  gint border_width;

  GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);

  border_width = GTK_CONTAINER (widget)->border_width;

  attributes.wclass = GDK_INPUT_ONLY;
  attributes.window_type = GDK_WINDOW_CHILD;
  attributes.x = widget->allocation.x + border_width;
  attributes.y = widget->allocation.y + border_width;
  attributes.width = widget->allocation.width - border_width * 2;
  attributes.height = widget->allocation.height - border_width * 2;
  attributes.event_mask = gtk_widget_get_events (widget);
756
  attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
757 758 759 760 761 762 763 764
			    GDK_BUTTON_RELEASE_MASK |
			    GDK_ENTER_NOTIFY_MASK |
			    GDK_LEAVE_NOTIFY_MASK);

  attributes_mask = GDK_WA_X | GDK_WA_Y;

  widget->window = gtk_widget_get_parent_window (widget);
  g_object_ref (widget->window);
765
  widget->style = gtk_style_attach (widget->style, widget->window);
766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785
  
  priv->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
				       &attributes, attributes_mask);
  gdk_window_set_user_data (priv->event_window, toolbar);
}

static void
gtk_toolbar_unrealize (GtkWidget *widget)
{
  GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);

  if (priv->event_window)
    {
      gdk_window_set_user_data (priv->event_window, NULL);
      gdk_window_destroy (priv->event_window);
      priv->event_window = NULL;
    }

  if (GTK_WIDGET_CLASS (parent_class)->unrealize)
    (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
786 787
}

788
static gint
789 790
gtk_toolbar_expose (GtkWidget      *widget,
		    GdkEventExpose *event)
791
{
792 793 794
  GtkToolbar *toolbar = GTK_TOOLBAR (widget);
  GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
  
795
  GList *list;
796
  gint border_width;
797
  
798 799
  border_width = GTK_CONTAINER (widget)->border_width;
  
800 801
  if (GTK_WIDGET_DRAWABLE (widget))
    {
802 803 804
      gtk_paint_box (widget->style,
		     widget->window,
                     GTK_WIDGET_STATE (widget),
805
                     get_shadow_type (toolbar),
806
		     &event->area, widget, "toolbar",
807 808
		     border_width + widget->allocation.x,
                     border_width + widget->allocation.y,
809 810
		     widget->allocation.width - 2 * border_width,
                     widget->allocation.height - 2 * border_width);
811
    }
812

813
  for (list = priv->content; list != NULL; list = list->next)
814
    {
815 816
      ToolbarContent *content = list->data;
      GtkToolItem *item = content->item;
817

818 819 820 821
      if (!content->is_placeholder)
	gtk_container_propagate_expose (GTK_CONTAINER (widget),
					GTK_WIDGET (item),
					event);
822
    }
823

824 825 826 827
  gtk_container_propagate_expose (GTK_CONTAINER (widget),
				  priv->arrow_button,
				  event);

828
  return FALSE;
829 830 831
}

static void
832 833 834
gtk_toolbar_size_request (GtkWidget      *widget,
			  GtkRequisition *requisition)
{
835 836 837 838 839 840 841 842 843 844
  GtkToolbar *toolbar = GTK_TOOLBAR (widget);
  GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
  GList *list;
  gint max_child_height;
  gint max_child_width;
  gint max_homogeneous_child_width;
  gint max_homogeneous_child_height;
  gint homogeneous_size;
  gint long_req;
  gint pack_front_size;
845
  gint ipadding;
846
  GtkRequisition arrow_requisition;
847

848 849 850 851
  max_homogeneous_child_width = 0;
  max_homogeneous_child_height = 0;
  max_child_width = 0;
  max_child_height = 0;
852
  for (list = priv->content; list != NULL; list = list->next)
853
    {
854
      GtkRequisition requisition;
855 856
      ToolbarContent *content = list->data;
      GtkToolItem *item = content->item;
857 858 859
      
      if (!toolbar_item_visible (toolbar, item))
	continue;
860

861 862 863 864
      gtk_widget_size_request (GTK_WIDGET (item), &requisition);
      
      max_child_width = MAX (max_child_width, requisition.width);
      max_child_height = MAX (max_child_height, requisition.height);
865

866
      if (toolbar_item_is_homogeneous (toolbar, item))
867 868 869
	{
	  max_homogeneous_child_width = MAX (max_homogeneous_child_width, requisition.width);
	  max_homogeneous_child_height = MAX (max_homogeneous_child_height, requisition.height);
870
	}
871
    }
872
  
873
  if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
874
    homogeneous_size = max_homogeneous_child_width;
875
  else
876 877 878
    homogeneous_size = max_homogeneous_child_height;
  
  pack_front_size = 0;
879
  for (list = priv->content; list != NULL; list = list->next)
880
    {
881 882
      ToolbarContent *content = list->data;
      GtkToolItem *item = content->item;
883 884 885 886 887
      guint size;
      
      if (!toolbar_item_visible (toolbar, item))
	continue;
      
888
      if (toolbar_item_is_homogeneous (toolbar, item))
889 890 891 892 893 894 895 896 897 898 899 900 901 902 903
	{
	  size = homogeneous_size;
	}
      else
	{
	  GtkRequisition requisition;
	  
	  gtk_widget_size_request (GTK_WIDGET (item), &requisition);

	  if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
	    size = requisition.width;
	  else
	    size = requisition.height;
	}
      
904
      pack_front_size += size;
905
    }
906
  
907
  if (priv->show_arrow && priv->api_mode == NEW_API)
908 909 910 911 912 913 914
    {
      gtk_widget_size_request (priv->arrow_button, &arrow_requisition);
      
      if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
	long_req = arrow_requisition.width;
      else
	long_req = arrow_requisition.height;
915

916 917 918
      /* There is no point requesting space for the arrow if that would take
       * up more space than all the items combined
       */
919
      long_req = MIN (long_req, pack_front_size);
920 921 922 923 924 925
    }
  else
    {
      arrow_requisition.height = 0;
      arrow_requisition.width = 0;
      
926
      long_req = pack_front_size;
927 928 929 930 931 932 933 934 935 936 937 938 939
    }
  
  if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
    {
      requisition->width = long_req;
      requisition->height = MAX (max_child_height, arrow_requisition.height);
    }
  else
    {
      requisition->height = long_req;
      requisition->width = MAX (max_child_width, arrow_requisition.width);
    }
  
940
  /* Extra spacing */
941 942 943 944
  ipadding = get_internal_padding (toolbar);

  requisition->width += 2 * (ipadding + GTK_CONTAINER (toolbar)->border_width);
  requisition->height += 2 * (ipadding + GTK_CONTAINER (toolbar)->border_width);
945 946 947 948 949 950

  if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
    {
      requisition->width += 2 * widget->style->xthickness;
      requisition->height += 2 * widget->style->ythickness;
    }
951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966
  
  toolbar->button_maxw = max_homogeneous_child_width;
  toolbar->button_maxh = max_homogeneous_child_height;
}

static void
fixup_allocation_for_rtl (gint           total_size,
			  GtkAllocation *allocation)
{
  allocation->x += (total_size - (2 * allocation->x + allocation->width));
}

static void
fixup_allocation_for_vertical (GtkAllocation *allocation)
{
  gint tmp;
967
  
968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984
  tmp = allocation->x;
  allocation->x = allocation->y;
  allocation->y = tmp;
  
  tmp = allocation->width;
  allocation->width = allocation->height;
  allocation->height = tmp;
}

static gint
get_item_size (GtkToolbar *toolbar,
	       GtkWidget  *child)
{
  GtkRequisition requisition;
  GtkToolItem *item = GTK_TOOL_ITEM (child);

  gtk_widget_get_child_requisition (child, &requisition);
985
  
986 987
  if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
    {
988
      if (toolbar_item_is_homogeneous (toolbar, item))
989 990 991 992 993 994
	return toolbar->button_maxw;
      else
	return requisition.width;
    }
  else
    {
995
      if (toolbar_item_is_homogeneous (toolbar, item))
996 997 998 999
	return toolbar->button_maxh;
      else
	return requisition.height;
    }
1000 1001 1002
}

static void
1003 1004 1005
gtk_toolbar_size_allocate (GtkWidget     *widget,
			   GtkAllocation *allocation)
{
1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020
  GtkToolbar *toolbar = GTK_TOOLBAR (widget);
  GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
  GtkAllocation *allocations;
  GtkAllocation arrow_allocation;
  gint arrow_size;
  gint size, pos, short_size;
  GList *list;
  gint i;
  gboolean need_arrow;
  gint n_expand_items;
  gint border_width;
  gint available_size;
  gint n_items;
  gint needed_size;
  GtkRequisition arrow_requisition;
1021
  gint n_overflowed;
1022
  gboolean overflowing;
1023 1024

  widget->allocation = *allocation;
1025

1026
  border_width = GTK_CONTAINER (toolbar)->border_width;
1027

1028 1029 1030 1031 1032 1033 1034 1035 1036 1037
  if (GTK_WIDGET_REALIZED (widget))
    {
      gdk_window_move_resize (priv->event_window,
                              allocation->x + border_width,
                              allocation->y + border_width,
                              allocation->width - border_width * 2,
                              allocation->height - border_width * 2);
    }
  
  border_width += get_internal_padding (toolbar);
1038
  
1039 1040
  gtk_widget_get_child_requisition (GTK_WIDGET (priv->arrow_button),
				    &arrow_requisition);
1041
  
1042
  if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
1043 1044 1045 1046
    {
      available_size = size = allocation->width - 2 * border_width;
      short_size = allocation->height - 2 * border_width;
      arrow_size = arrow_requisition.width;
1047 1048 1049 1050 1051 1052

      if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
	{
	  available_size -= 2 * widget->style->xthickness;
	  short_size -= 2 * widget->style->ythickness;
	}
1053
    }
1054
  else
1055 1056 1057 1058
    {
      available_size = size = allocation->height - 2 * border_width;
      short_size = allocation->width - 2 * border_width;
      arrow_size = arrow_requisition.height;
1059 1060 1061 1062 1063 1064

      if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
	{
	  available_size -= 2 * widget->style->ythickness;
	  short_size -= 2 * widget->style->xthickness;
	}
1065
    }
1066

1067
  n_items = g_list_length (priv->content);
1068 1069 1070
  allocations = g_new0 (GtkAllocation, n_items);

  needed_size = 0;
1071
  for (list = priv->content; list != NULL; list = list->next)
1072
    {
1073 1074
      ToolbarContent *content = list->data;
      GtkToolItem *item = content->item;
1075 1076 1077 1078
      
      if (toolbar_item_visible (toolbar, item))
	needed_size += get_item_size (toolbar, GTK_WIDGET (item));
    }
1079

1080
  need_arrow = (needed_size > available_size) && priv->show_arrow && priv->api_mode == NEW_API;
1081

1082 1083 1084 1085
  if (need_arrow)
    size = available_size - arrow_size;
  else
    size = available_size;
1086

1087
  n_overflowed = 0;
1088

1089
  /* calculate widths of pack front items */
1090 1091
  overflowing = FALSE;
  for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1092
    {
1093 1094
      ToolbarContent *content = list->data;
      GtkToolItem *item = content->item;
1095
      gint item_size;
1096

1097
      if (!toolbar_item_visible (toolbar, item))
1098
	continue;
1099

1100
      item_size = get_item_size (toolbar, GTK_WIDGET (item));
1101
      if (item_size <= size && !overflowing)
1102 1103 1104
	{
	  size -= item_size;
	  allocations[i].width = item_size;
1105
	  content->is_overflow = FALSE;
1106 1107 1108
	}
      else
	{
1109 1110 1111
	  ++n_overflowed;
	  content->is_overflow = TRUE;
	  overflowing = TRUE;
1112 1113
	}
    }
1114

1115 1116 1117 1118 1119 1120 1121
  if (need_arrow)
    {
      arrow_allocation.width = arrow_size;
      arrow_allocation.height = short_size;
    }
  
  /* expand expandable items */
1122 1123 1124 1125 1126 1127 1128

  /* We don't expand when dnd causes items to overflow. Doing so would result in
   * weird jumps as items are overflowed and expandable items suddenly get lots of
   * extra space. On the other hand we can't disable expanding completely, because
   * that would cause a weird jump when dnd begins
   */
  if (!(priv->in_dnd && n_overflowed > priv->n_overflow_items_when_dnd_started))
1129
    {
1130 1131
      n_expand_items = 0;
      for (list = priv->content; list != NULL; list = list->next)
1132
	{
1133 1134 1135 1136 1137
	  ToolbarContent *content = list->data;
	  GtkToolItem *item = content->item;
	  
	  if (toolbar_item_visible (toolbar, item) &&
	      gtk_tool_item_get_expand (item) &&
1138
	      !content->is_overflow)
1139 1140 1141
	    {
	      n_expand_items++;
	    }
1142 1143
	}
      
1144
      for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1145
	{
1146 1147 1148
	  ToolbarContent *content = list->data;
	  GtkToolItem *item = content->item;
	  
1149 1150 1151
	  if (toolbar_item_visible (toolbar, item) &&
	      gtk_tool_item_get_expand (item) &&
	      !content->is_overflow)
1152 1153 1154 1155 1156 1157 1158 1159 1160
	    {
	      gint extra = size / n_expand_items;
	      if (size % n_expand_items != 0)
		extra++;
	      
	      allocations[i].width += extra;
	      size -= extra;
	      n_expand_items--;
	    }
1161
	}
1162 1163
      
      g_assert (n_expand_items == 0);
1164 1165
    }
  
1166
  /* position regular items */
1167
  pos = border_width;
1168
  for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1169
    {
1170 1171
      ToolbarContent *content = list->data;
      GtkToolItem *item = content->item;
1172
      
1173
      if (toolbar_item_visible (toolbar, item) && !content->is_overflow)
1174 1175 1176 1177
	{
	  allocations[i].x = pos;
	  allocations[i].y = border_width;
	  allocations[i].height = short_size;
1178

1179 1180 1181
	  pos += allocations[i].width;
	}
    }
1182

1183 1184 1185
  /* position arrow */
  if (need_arrow)
    {
1186
      arrow_allocation.x = available_size - border_width - arrow_allocation.width;
1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202
      arrow_allocation.y = border_width;
    }
  
  /* fix up allocations in the vertical or RTL cases */
  if (toolbar->orientation == GTK_ORIENTATION_VERTICAL)
    {
      for (i = 0; i < n_items; ++i)
	fixup_allocation_for_vertical (&(allocations[i]));
      
      if (need_arrow)
	fixup_allocation_for_vertical (&arrow_allocation);
    }
  else if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL)
    {
      for (i = 0; i < n_items; ++i)
	fixup_allocation_for_rtl (available_size, &(allocations[i]));
1203

1204 1205 1206 1207 1208 1209 1210 1211 1212
      if (need_arrow)
	fixup_allocation_for_rtl (available_size, &arrow_allocation);
    }
  
  /* translate the items by allocation->(x,y) */
  for (i = 0; i < n_items; ++i)
    {
      allocations[i].x += allocation->x;
      allocations[i].y += allocation->y;
1213 1214 1215 1216 1217 1218

      if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
	{
	  allocations[i].