gtktoolitem.c 40.8 KB
Newer Older
1 2
/* gtktoolitem.c
 *
3
 * Copyright (C) 2002 Anders Carlsson <andersca@gnome.org>
4 5 6 7 8 9 10 11 12 13 14 15 16 17
 * Copyright (C) 2002 James Henstridge <james@daa.com.au>
 * Copyright (C) 2003 Soeren Sandmann <sandmann@daimi.au.dk>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
Javier Jardón's avatar
Javier Jardón committed
18
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
19 20
 */

21
#include "config.h"
22

23 24
#include "gtktoolitem.h"

25 26
#include <string.h>

27
#include "gtkmarshalers.h"
28
#include "gtktoolshell.h"
29
#include "gtkseparatormenuitem.h"
30
#include "gtksizerequest.h"
31
#include "deprecated/gtkactivatable.h"
32
#include "gtkintl.h"
33
#include "gtkprivate.h"
34
#include "gtkwidgetprivate.h"
35

36 37
/**
 * SECTION:gtktoolitem
38
 * @short_description: The base class of widgets that can be added to GtkToolShell
39
 * @Title: GtkToolItem
40
 * @see_also: #GtkToolbar, #GtkToolButton, #GtkSeparatorToolItem
41
 *
42
 * #GtkToolItems are widgets that can appear on a toolbar. To
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
 * create a toolbar item that contain something else than a button, use
 * gtk_tool_item_new(). Use gtk_container_add() to add a child
 * widget to the tool item.
 *
 * For toolbar items that contain buttons, see the #GtkToolButton,
 * #GtkToggleToolButton and #GtkRadioToolButton classes.
 *
 * See the #GtkToolbar class for a description of the toolbar widget, and
 * #GtkToolShell for a description of the tool shell interface.
 */

/**
 * GtkToolItem:
 *
 * The GtkToolItem struct contains only private data.
 * It should only be accessed through the functions described below.
 */

61 62 63 64 65 66 67 68 69 70
enum {
  CREATE_MENU_PROXY,
  TOOLBAR_RECONFIGURED,
  LAST_SIGNAL
};

enum {
  PROP_0,
  PROP_VISIBLE_HORIZONTAL,
  PROP_VISIBLE_VERTICAL,
71 72 73 74 75
  PROP_IS_IMPORTANT,

  /* activatable properties */
  PROP_ACTIVATABLE_RELATED_ACTION,
  PROP_ACTIVATABLE_USE_ACTION_APPEARANCE
76 77
};

Matthias Clasen's avatar
Matthias Clasen committed
78

79 80 81 82 83
struct _GtkToolItemPrivate
{
  gchar *tip_text;
  gchar *tip_private;

84 85 86 87 88 89 90
  guint visible_horizontal    : 1;
  guint visible_vertical      : 1;
  guint homogeneous           : 1;
  guint expand                : 1;
  guint use_drag_window       : 1;
  guint is_important          : 1;
  guint use_action_appearance : 1;
91 92 93 94

  GdkWindow *drag_window;
  gchar *menu_item_id;
  GtkWidget *menu_item;
95 96

  GtkAction *action;
97
};
98

99 100 101 102
static void gtk_tool_item_finalize     (GObject         *object);
static void gtk_tool_item_dispose      (GObject         *object);
static void gtk_tool_item_parent_set   (GtkWidget       *toolitem,
				        GtkWidget       *parent);
103 104 105 106 107 108 109 110
static void gtk_tool_item_set_property (GObject         *object,
					guint            prop_id,
					const GValue    *value,
					GParamSpec      *pspec);
static void gtk_tool_item_get_property (GObject         *object,
					guint            prop_id,
					GValue          *value,
					GParamSpec      *pspec);
111 112
static void gtk_tool_item_property_notify (GObject      *object,
					   GParamSpec   *pspec);
113 114 115 116
static void gtk_tool_item_realize       (GtkWidget      *widget);
static void gtk_tool_item_unrealize     (GtkWidget      *widget);
static void gtk_tool_item_map           (GtkWidget      *widget);
static void gtk_tool_item_unmap         (GtkWidget      *widget);
117 118 119 120 121 122 123 124
static void gtk_tool_item_get_preferred_width
                                        (GtkWidget      *widget,
                                         gint           *minimum,
                                         gint           *natural);
static void gtk_tool_item_get_preferred_height
                                        (GtkWidget      *widget,
                                         gint           *minimum,
                                         gint           *natural);
125 126 127
static void gtk_tool_item_size_allocate (GtkWidget      *widget,
					 GtkAllocation  *allocation);

128
static void gtk_tool_item_activatable_interface_init (GtkActivatableIface  *iface);
129
static void gtk_tool_item_update                     (GtkActivatable       *activatable,
130 131
						      GtkAction            *action,
						      const gchar          *property_name);
132
static void gtk_tool_item_sync_action_properties     (GtkActivatable       *activatable,
133 134 135 136 137
						      GtkAction            *action);
static void gtk_tool_item_set_related_action         (GtkToolItem          *item, 
						      GtkAction            *action);
static void gtk_tool_item_set_use_action_appearance  (GtkToolItem          *item, 
						      gboolean              use_appearance);
138

Matthias Clasen's avatar
Matthias Clasen committed
139
static guint toolitem_signals[LAST_SIGNAL] = { 0 };
140

141
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
142
G_DEFINE_TYPE_WITH_CODE (GtkToolItem, gtk_tool_item, GTK_TYPE_BIN,
143
                         G_ADD_PRIVATE (GtkToolItem)
144 145
			 G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIVATABLE,
						gtk_tool_item_activatable_interface_init))
146
G_GNUC_END_IGNORE_DEPRECATIONS;
147 148 149 150 151 152 153 154 155

static void
gtk_tool_item_class_init (GtkToolItemClass *klass)
{
  GObjectClass *object_class;
  GtkWidgetClass *widget_class;
  
  object_class = (GObjectClass *)klass;
  widget_class = (GtkWidgetClass *)klass;
156

157 158
  object_class->set_property = gtk_tool_item_set_property;
  object_class->get_property = gtk_tool_item_get_property;
159 160 161
  object_class->finalize     = gtk_tool_item_finalize;
  object_class->dispose      = gtk_tool_item_dispose;
  object_class->notify       = gtk_tool_item_property_notify;
162 163 164 165 166

  widget_class->realize       = gtk_tool_item_realize;
  widget_class->unrealize     = gtk_tool_item_unrealize;
  widget_class->map           = gtk_tool_item_map;
  widget_class->unmap         = gtk_tool_item_unmap;
167 168
  widget_class->get_preferred_width = gtk_tool_item_get_preferred_width;
  widget_class->get_preferred_height = gtk_tool_item_get_preferred_height;
169 170 171
  widget_class->size_allocate = gtk_tool_item_size_allocate;
  widget_class->parent_set    = gtk_tool_item_parent_set;

172 173
  gtk_container_class_handle_border_width (GTK_CONTAINER_CLASS (klass));

174
  klass->create_menu_proxy = _gtk_tool_item_create_menu_proxy;
175 176 177
  
  g_object_class_install_property (object_class,
				   PROP_VISIBLE_HORIZONTAL,
178
				   g_param_spec_boolean ("visible-horizontal",
179 180
							 P_("Visible when horizontal"),
							 P_("Whether the toolbar item is visible when the toolbar is in a horizontal orientation."),
181
							 TRUE,
182
							 GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
183 184
  g_object_class_install_property (object_class,
				   PROP_VISIBLE_VERTICAL,
185
				   g_param_spec_boolean ("visible-vertical",
186 187
							 P_("Visible when vertical"),
							 P_("Whether the toolbar item is visible when the toolbar is in a vertical orientation."),
188
							 TRUE,
189
							 GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
190 191
  g_object_class_install_property (object_class,
 				   PROP_IS_IMPORTANT,
192
 				   g_param_spec_boolean ("is-important",
193 194
 							 P_("Is important"),
 							 P_("Whether the toolbar item is considered important. When TRUE, toolbar buttons show text in GTK_TOOLBAR_BOTH_HORIZ mode"),
195
 							 FALSE,
196
 							 GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
197

198 199 200 201
  g_object_class_override_property (object_class, PROP_ACTIVATABLE_RELATED_ACTION, "related-action");
  g_object_class_override_property (object_class, PROP_ACTIVATABLE_USE_ACTION_APPEARANCE, "use-action-appearance");


202 203
/**
 * GtkToolItem::create-menu-proxy:
204
 * @tool_item: the object the signal was emitted on
205
 *
206 207 208
 * This signal is emitted when the toolbar needs information from @tool_item
 * about whether the item should appear in the toolbar overflow menu. In
 * response the tool item should either
209 210 211 212 213 214 215 216 217 218 219
 * 
 * - call gtk_tool_item_set_proxy_menu_item() with a %NULL
 *   pointer and return %TRUE to indicate that the item should not appear
 *   in the overflow menu
 * 
 * - call gtk_tool_item_set_proxy_menu_item() with a new menu
 *   item and return %TRUE, or 
 *
 * - return %FALSE to indicate that the signal was not handled by the item.
 *   This means that the item will not appear in the overflow menu unless
 *   a later handler installs a menu item.
220 221 222 223 224 225
 *
 * The toolbar may cache the result of this signal. When the tool item changes
 * how it will respond to this signal it must call gtk_tool_item_rebuild_menu()
 * to invalidate the cache and ensure that the toolbar rebuilds its overflow
 * menu.
 *
226
 * Returns: %TRUE if the signal was handled, %FALSE if not
227
 **/
228
  toolitem_signals[CREATE_MENU_PROXY] =
229
    g_signal_new (I_("create-menu-proxy"),
230 231 232
		  G_OBJECT_CLASS_TYPE (klass),
		  G_SIGNAL_RUN_LAST,
		  G_STRUCT_OFFSET (GtkToolItemClass, create_menu_proxy),
233
		  _gtk_boolean_handled_accumulator, NULL,
234 235
		  _gtk_marshal_BOOLEAN__VOID,
		  G_TYPE_BOOLEAN, 0);
236 237 238

/**
 * GtkToolItem::toolbar-reconfigured:
239
 * @tool_item: the object the signal was emitted on
240 241 242 243
 *
 * This signal is emitted when some property of the toolbar that the
 * item is a child of changes. For custom subclasses of #GtkToolItem,
 * the default handler of this signal use the functions
244 245 246 247
 * - gtk_tool_shell_get_orientation()
 * - gtk_tool_shell_get_style()
 * - gtk_tool_shell_get_icon_size()
 * - gtk_tool_shell_get_relief_style()
248 249 250
 * to find out what the toolbar should look like and change
 * themselves accordingly.
 **/
251
  toolitem_signals[TOOLBAR_RECONFIGURED] =
252
    g_signal_new (I_("toolbar-reconfigured"),
253 254 255 256 257 258 259 260 261 262 263
		  G_OBJECT_CLASS_TYPE (klass),
		  G_SIGNAL_RUN_LAST,
		  G_STRUCT_OFFSET (GtkToolItemClass, toolbar_reconfigured),
		  NULL, NULL,
		  _gtk_marshal_VOID__VOID,
		  G_TYPE_NONE, 0);
}

static void
gtk_tool_item_init (GtkToolItem *toolitem)
{
264
  gtk_widget_set_can_focus (GTK_WIDGET (toolitem), FALSE);
265

266
  toolitem->priv = gtk_tool_item_get_instance_private (toolitem);
267 268 269 270
  toolitem->priv->visible_horizontal = TRUE;
  toolitem->priv->visible_vertical = TRUE;
  toolitem->priv->homogeneous = FALSE;
  toolitem->priv->expand = FALSE;
271
  toolitem->priv->use_action_appearance = TRUE;
272 273 274 275 276 277 278
}

static void
gtk_tool_item_finalize (GObject *object)
{
  GtkToolItem *item = GTK_TOOL_ITEM (object);

279
  g_free (item->priv->menu_item_id);
280

281 282
  if (item->priv->menu_item)
    g_object_unref (item->priv->menu_item);
283 284

  G_OBJECT_CLASS (gtk_tool_item_parent_class)->finalize (object);
285 286
}

287 288 289 290 291 292 293
static void
gtk_tool_item_dispose (GObject *object)
{
  GtkToolItem *item = GTK_TOOL_ITEM (object);

  if (item->priv->action)
    {
294
      G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
295
      gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (item), NULL);      
296
      G_GNUC_END_IGNORE_DEPRECATIONS;
297 298 299 300 301 302
      item->priv->action = NULL;
    }
  G_OBJECT_CLASS (gtk_tool_item_parent_class)->dispose (object);
}


303
static void
304 305
gtk_tool_item_parent_set (GtkWidget   *toolitem,
			  GtkWidget   *prev_parent)
306
{
307
  if (gtk_widget_get_parent (GTK_WIDGET (toolitem)) != NULL)
308
    gtk_tool_item_toolbar_reconfigured (GTK_TOOL_ITEM (toolitem));
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324
}

static void
gtk_tool_item_set_property (GObject      *object,
			    guint         prop_id,
			    const GValue *value,
			    GParamSpec   *pspec)
{
  GtkToolItem *toolitem = GTK_TOOL_ITEM (object);

  switch (prop_id)
    {
    case PROP_VISIBLE_HORIZONTAL:
      gtk_tool_item_set_visible_horizontal (toolitem, g_value_get_boolean (value));
      break;
    case PROP_VISIBLE_VERTICAL:
325
      gtk_tool_item_set_visible_vertical (toolitem, g_value_get_boolean (value));
326
      break;
327 328 329
    case PROP_IS_IMPORTANT:
      gtk_tool_item_set_is_important (toolitem, g_value_get_boolean (value));
      break;
330 331 332 333 334 335
    case PROP_ACTIVATABLE_RELATED_ACTION:
      gtk_tool_item_set_related_action (toolitem, g_value_get_object (value));
      break;
    case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE:
      gtk_tool_item_set_use_action_appearance (toolitem, g_value_get_boolean (value));
      break;
336 337
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
338
      break;
339 340 341 342 343 344 345 346 347 348 349 350 351 352
    }
}

static void
gtk_tool_item_get_property (GObject    *object,
			    guint       prop_id,
			    GValue     *value,
			    GParamSpec *pspec)
{
  GtkToolItem *toolitem = GTK_TOOL_ITEM (object);

  switch (prop_id)
    {
    case PROP_VISIBLE_HORIZONTAL:
353
      g_value_set_boolean (value, toolitem->priv->visible_horizontal);
354 355
      break;
    case PROP_VISIBLE_VERTICAL:
356
      g_value_set_boolean (value, toolitem->priv->visible_vertical);
357
      break;
358 359 360
    case PROP_IS_IMPORTANT:
      g_value_set_boolean (value, toolitem->priv->is_important);
      break;
361 362 363 364 365 366
    case PROP_ACTIVATABLE_RELATED_ACTION:
      g_value_set_object (value, toolitem->priv->action);
      break;
    case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE:
      g_value_set_boolean (value, toolitem->priv->use_action_appearance);
      break;
367 368
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
369
      break;
370 371 372
    }
}

373 374 375 376 377 378 379 380
static void
gtk_tool_item_property_notify (GObject    *object,
			       GParamSpec *pspec)
{
  GtkToolItem *tool_item = GTK_TOOL_ITEM (object);

  if (tool_item->priv->menu_item && strcmp (pspec->name, "sensitive") == 0)
    gtk_widget_set_sensitive (tool_item->priv->menu_item,
381
			      gtk_widget_get_sensitive (GTK_WIDGET (tool_item)));
382 383 384

  if (G_OBJECT_CLASS (gtk_tool_item_parent_class)->notify)
    G_OBJECT_CLASS (gtk_tool_item_parent_class)->notify (object, pspec);
385 386
}

387 388 389
static void
create_drag_window (GtkToolItem *toolitem)
{
390
  GtkAllocation allocation;
391 392
  GtkWidget *widget;
  GdkWindowAttr attributes;
393
  gint attributes_mask;
394

395
  g_return_if_fail (toolitem->priv->use_drag_window == TRUE);
396 397

  widget = GTK_WIDGET (toolitem);
398 399

  gtk_widget_get_allocation (widget, &allocation);
400 401

  attributes.window_type = GDK_WINDOW_CHILD;
402 403 404 405
  attributes.x = allocation.x;
  attributes.y = allocation.y;
  attributes.width = allocation.width;
  attributes.height = allocation.height;
406 407 408 409 410 411
  attributes.wclass = GDK_INPUT_ONLY;
  attributes.event_mask = gtk_widget_get_events (widget);
  attributes.event_mask |= (GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);

  attributes_mask = GDK_WA_X | GDK_WA_Y;

412
  toolitem->priv->drag_window = gdk_window_new (gtk_widget_get_parent_window (widget),
413
					  &attributes, attributes_mask);
414
  gtk_widget_register_window (widget, toolitem->priv->drag_window);
415 416 417 418 419 420
}

static void
gtk_tool_item_realize (GtkWidget *widget)
{
  GtkToolItem *toolitem;
421
  GdkWindow *window;
422 423

  toolitem = GTK_TOOL_ITEM (widget);
424
  gtk_widget_set_realized (widget, TRUE);
425

426 427 428
  window = gtk_widget_get_parent_window (widget);
  gtk_widget_set_window (widget, window);
  g_object_ref (window);
429

430
  if (toolitem->priv->use_drag_window)
431 432 433 434 435 436
    create_drag_window(toolitem);
}

static void
destroy_drag_window (GtkToolItem *toolitem)
{
437
  if (toolitem->priv->drag_window)
438
    {
439
      gtk_widget_unregister_window (GTK_WIDGET (toolitem), toolitem->priv->drag_window);
440 441
      gdk_window_destroy (toolitem->priv->drag_window);
      toolitem->priv->drag_window = NULL;
442 443 444 445 446 447 448 449 450 451 452 453
    }
}

static void
gtk_tool_item_unrealize (GtkWidget *widget)
{
  GtkToolItem *toolitem;

  toolitem = GTK_TOOL_ITEM (widget);

  destroy_drag_window (toolitem);
  
Matthias Clasen's avatar
Matthias Clasen committed
454
  GTK_WIDGET_CLASS (gtk_tool_item_parent_class)->unrealize (widget);
455 456 457 458 459 460 461 462
}

static void
gtk_tool_item_map (GtkWidget *widget)
{
  GtkToolItem *toolitem;

  toolitem = GTK_TOOL_ITEM (widget);
Matthias Clasen's avatar
Matthias Clasen committed
463
  GTK_WIDGET_CLASS (gtk_tool_item_parent_class)->map (widget);
464 465
  if (toolitem->priv->drag_window)
    gdk_window_show (toolitem->priv->drag_window);
466 467 468 469 470 471 472 473
}

static void
gtk_tool_item_unmap (GtkWidget *widget)
{
  GtkToolItem *toolitem;

  toolitem = GTK_TOOL_ITEM (widget);
474 475
  if (toolitem->priv->drag_window)
    gdk_window_hide (toolitem->priv->drag_window);
Matthias Clasen's avatar
Matthias Clasen committed
476
  GTK_WIDGET_CLASS (gtk_tool_item_parent_class)->unmap (widget);
477 478 479
}

static void
480 481 482
gtk_tool_item_get_preferred_width (GtkWidget *widget,
                                   gint      *minimum,
                                   gint      *natural)
483
{
Javier Jardón's avatar
Javier Jardón committed
484
  GtkWidget *child;
485 486

  *minimum = *natural = 0;
487

Javier Jardón's avatar
Javier Jardón committed
488
  child = gtk_bin_get_child (GTK_BIN (widget));
489
  if (child && gtk_widget_get_visible (child))
490 491
    gtk_widget_get_preferred_width (child, minimum, natural);
}
492

493 494 495 496 497 498 499 500 501 502 503 504
static void
gtk_tool_item_get_preferred_height (GtkWidget *widget,
                                    gint      *minimum,
                                    gint      *natural)
{
  GtkWidget *child;

  *minimum = *natural = 0;

  child = gtk_bin_get_child (GTK_BIN (widget));
  if (child && gtk_widget_get_visible (child))
    gtk_widget_get_preferred_height (child, minimum, natural);
505 506 507 508 509 510 511 512
}

static void
gtk_tool_item_size_allocate (GtkWidget     *widget,
			     GtkAllocation *allocation)
{
  GtkToolItem *toolitem = GTK_TOOL_ITEM (widget);
  GtkAllocation child_allocation;
Javier Jardón's avatar
Javier Jardón committed
513
  GtkWidget *child;
514

515 516
  gtk_widget_set_allocation (widget, allocation);

517 518
  if (toolitem->priv->drag_window)
    gdk_window_move_resize (toolitem->priv->drag_window,
519 520 521 522
                            allocation->x,
                            allocation->y,
                            allocation->width,
                            allocation->height);
523 524

  child = gtk_bin_get_child (GTK_BIN (widget));
525
  if (child && gtk_widget_get_visible (child))
526
    {
527 528 529 530
      child_allocation.x = allocation->x;
      child_allocation.y = allocation->y;
      child_allocation.width = allocation->width;
      child_allocation.height = allocation->height;
531 532 533
      
      gtk_widget_size_allocate (child, &child_allocation);
    }
534 535

  _gtk_widget_set_simple_clip (widget, NULL);
536 537
}

538 539
gboolean
_gtk_tool_item_create_menu_proxy (GtkToolItem *item)
540
{
541 542
  GtkWidget *menu_item;
  gboolean visible_overflown;
543 544 545
  gboolean ret = FALSE;

  G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560

  if (item->priv->action)
    {
      g_object_get (item->priv->action, "visible-overflown", &visible_overflown, NULL);
    
      if (visible_overflown)
	{
	  menu_item = gtk_action_create_menu_item (item->priv->action);

	  g_object_ref_sink (menu_item);
      	  gtk_tool_item_set_proxy_menu_item (item, "gtk-action-menu-item", menu_item);
	  g_object_unref (menu_item);
	}
      else
	gtk_tool_item_set_proxy_menu_item (item, "gtk-action-menu-item", NULL);
561

562
      ret = TRUE;
563 564
    }

565 566 567
  G_GNUC_END_IGNORE_DEPRECATIONS;

  return ret;
568 569
}

570 571
static void
gtk_tool_item_activatable_interface_init (GtkActivatableIface *iface)
572
{
573 574
  iface->update = gtk_tool_item_update;
  iface->sync_action_properties = gtk_tool_item_sync_action_properties;
575 576
}

577 578 579 580
static void
gtk_tool_item_update (GtkActivatable *activatable,
		      GtkAction      *action,
	     	      const gchar    *property_name)
581
{
582 583
  G_GNUC_BEGIN_IGNORE_DEPRECATIONS;

584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604
  if (strcmp (property_name, "visible") == 0)
    {
      if (gtk_action_is_visible (action))
	gtk_widget_show (GTK_WIDGET (activatable));
      else
	gtk_widget_hide (GTK_WIDGET (activatable));
    }
  else if (strcmp (property_name, "sensitive") == 0)
    gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action));
  else if (strcmp (property_name, "tooltip") == 0)
    gtk_tool_item_set_tooltip_text (GTK_TOOL_ITEM (activatable),
				    gtk_action_get_tooltip (action));
  else if (strcmp (property_name, "visible-horizontal") == 0)
    gtk_tool_item_set_visible_horizontal (GTK_TOOL_ITEM (activatable),
					  gtk_action_get_visible_horizontal (action));
  else if (strcmp (property_name, "visible-vertical") == 0)
    gtk_tool_item_set_visible_vertical (GTK_TOOL_ITEM (activatable),
					gtk_action_get_visible_vertical (action));
  else if (strcmp (property_name, "is-important") == 0)
    gtk_tool_item_set_is_important (GTK_TOOL_ITEM (activatable),
				    gtk_action_get_is_important (action));
605 606

  G_GNUC_END_IGNORE_DEPRECATIONS;
607 608
}

609 610 611
static void
gtk_tool_item_sync_action_properties (GtkActivatable *activatable,
				      GtkAction      *action)
612 613 614 615
{
  if (!action)
    return;

616 617
  G_GNUC_BEGIN_IGNORE_DEPRECATIONS;

618 619 620 621 622 623 624 625 626 627 628 629 630 631 632
  if (gtk_action_is_visible (action))
    gtk_widget_show (GTK_WIDGET (activatable));
  else
    gtk_widget_hide (GTK_WIDGET (activatable));
  
  gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action));
  
  gtk_tool_item_set_tooltip_text (GTK_TOOL_ITEM (activatable),
				  gtk_action_get_tooltip (action));
  gtk_tool_item_set_visible_horizontal (GTK_TOOL_ITEM (activatable),
					gtk_action_get_visible_horizontal (action));
  gtk_tool_item_set_visible_vertical (GTK_TOOL_ITEM (activatable),
				      gtk_action_get_visible_vertical (action));
  gtk_tool_item_set_is_important (GTK_TOOL_ITEM (activatable),
				  gtk_action_get_is_important (action));
633 634

  G_GNUC_END_IGNORE_DEPRECATIONS;
635 636 637 638 639 640 641 642 643
}

static void
gtk_tool_item_set_related_action (GtkToolItem *item, 
				  GtkAction   *action)
{
  if (item->priv->action == action)
    return;

644
  G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
645
  gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (item), action);
646
  G_GNUC_END_IGNORE_DEPRECATIONS;
647 648 649 650 651 652 653 654 655 656

  item->priv->action = action;

  if (action)
    {
      gtk_tool_item_rebuild_menu (item);
    }
}

static void
657
gtk_tool_item_set_use_action_appearance (GtkToolItem *item,
658 659 660 661 662
					 gboolean     use_appearance)
{
  if (item->priv->use_action_appearance != use_appearance)
    {
      item->priv->use_action_appearance = use_appearance;
663

664
      G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
665
      gtk_activatable_sync_action_properties (GTK_ACTIVATABLE (item), item->priv->action);
666
      G_GNUC_END_IGNORE_DEPRECATIONS;
667 668 669 670
    }
}


671 672 673 674 675
/**
 * gtk_tool_item_new:
 * 
 * Creates a new #GtkToolItem
 * 
676
 * Returns: the new #GtkToolItem
677 678 679
 * 
 * Since: 2.4
 **/
680 681 682 683 684 685 686 687 688 689
GtkToolItem *
gtk_tool_item_new (void)
{
  GtkToolItem *item;

  item = g_object_new (GTK_TYPE_TOOL_ITEM, NULL);

  return item;
}

690 691
/**
 * gtk_tool_item_get_ellipsize_mode:
692 693
 * @tool_item: a #GtkToolItem
 *
694 695 696
 * Returns the ellipsize mode used for @tool_item. Custom subclasses of
 * #GtkToolItem should call this function to find out how text should
 * be ellipsized.
697
 *
698
 * Returns: a #PangoEllipsizeMode indicating how text in @tool_item
699
 * should be ellipsized.
700 701
 *
 * Since: 2.20
702 703 704 705 706 707 708 709
 **/
PangoEllipsizeMode
gtk_tool_item_get_ellipsize_mode (GtkToolItem *tool_item)
{
  GtkWidget *parent;
  
  g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);

710
  parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
711 712 713 714 715 716
  if (!parent || !GTK_IS_TOOL_SHELL (parent))
    return PANGO_ELLIPSIZE_NONE;

  return gtk_tool_shell_get_ellipsize_mode (GTK_TOOL_SHELL (parent));
}

717 718
/**
 * gtk_tool_item_get_icon_size:
719
 * @tool_item: a #GtkToolItem
720 721 722 723 724
 * 
 * Returns the icon size used for @tool_item. Custom subclasses of
 * #GtkToolItem should call this function to find out what size icons
 * they should use.
 * 
725
 * Returns: (type int): a #GtkIconSize indicating the icon size
726
 * used for @tool_item
727 728 729
 * 
 * Since: 2.4
 **/
730 731 732 733 734 735 736
GtkIconSize
gtk_tool_item_get_icon_size (GtkToolItem *tool_item)
{
  GtkWidget *parent;

  g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ICON_SIZE_LARGE_TOOLBAR);

737
  parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
738
  if (!parent || !GTK_IS_TOOL_SHELL (parent))
739 740
    return GTK_ICON_SIZE_LARGE_TOOLBAR;

741
  return gtk_tool_shell_get_icon_size (GTK_TOOL_SHELL (parent));
742 743
}

744 745
/**
 * gtk_tool_item_get_orientation:
746
 * @tool_item: a #GtkToolItem 
747 748 749 750 751
 * 
 * Returns the orientation used for @tool_item. Custom subclasses of
 * #GtkToolItem should call this function to find out what size icons
 * they should use.
 * 
752
 * Returns: a #GtkOrientation indicating the orientation
753 754 755 756
 * used for @tool_item
 * 
 * Since: 2.4
 **/
757 758 759 760 761 762 763
GtkOrientation
gtk_tool_item_get_orientation (GtkToolItem *tool_item)
{
  GtkWidget *parent;
  
  g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);

764
  parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
765
  if (!parent || !GTK_IS_TOOL_SHELL (parent))
766 767
    return GTK_ORIENTATION_HORIZONTAL;

768
  return gtk_tool_shell_get_orientation (GTK_TOOL_SHELL (parent));
769 770
}

771 772
/**
 * gtk_tool_item_get_toolbar_style:
773
 * @tool_item: a #GtkToolItem 
774 775 776 777 778 779 780
 * 
 * Returns the toolbar style used for @tool_item. Custom subclasses of
 * #GtkToolItem should call this function in the handler of the
 * GtkToolItem::toolbar_reconfigured signal to find out in what style
 * the toolbar is displayed and change themselves accordingly 
 *
 * Possibilities are:
781 782 783 784 785 786
 * - %GTK_TOOLBAR_BOTH, meaning the tool item should show
 *   both an icon and a label, stacked vertically
 * - %GTK_TOOLBAR_ICONS, meaning the toolbar shows only icons
 * - %GTK_TOOLBAR_TEXT, meaning the tool item should only show text
 * - %GTK_TOOLBAR_BOTH_HORIZ, meaning the tool item should show
 *   both an icon and a label, arranged horizontally
787
 * 
788
 * Returns: A #GtkToolbarStyle indicating the toolbar style used
789 790 791 792
 * for @tool_item.
 * 
 * Since: 2.4
 **/
793 794 795 796 797 798 799
GtkToolbarStyle
gtk_tool_item_get_toolbar_style (GtkToolItem *tool_item)
{
  GtkWidget *parent;
  
  g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_TOOLBAR_ICONS);

800
  parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
801
  if (!parent || !GTK_IS_TOOL_SHELL (parent))
802 803
    return GTK_TOOLBAR_ICONS;

804
  return gtk_tool_shell_get_style (GTK_TOOL_SHELL (parent));
805 806
}

807 808
/**
 * gtk_tool_item_get_relief_style:
809
 * @tool_item: a #GtkToolItem 
810
 * 
811
 * Returns the relief style of @tool_item. See gtk_button_set_relief().
812 813 814 815
 * Custom subclasses of #GtkToolItem should call this function in the handler
 * of the #GtkToolItem::toolbar_reconfigured signal to find out the
 * relief style of buttons.
 * 
816
 * Returns: a #GtkReliefStyle indicating the relief style used
817 818 819 820
 * for @tool_item.
 * 
 * Since: 2.4
 **/
821 822 823 824 825 826 827
GtkReliefStyle 
gtk_tool_item_get_relief_style (GtkToolItem *tool_item)
{
  GtkWidget *parent;
  
  g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_RELIEF_NONE);

828
  parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
829
  if (!parent || !GTK_IS_TOOL_SHELL (parent))
830 831
    return GTK_RELIEF_NONE;

832
  return gtk_tool_shell_get_relief_style (GTK_TOOL_SHELL (parent));
833 834
}

835 836 837 838 839 840 841 842
/**
 * gtk_tool_item_get_text_alignment:
 * @tool_item: a #GtkToolItem: 
 * 
 * Returns the text alignment used for @tool_item. Custom subclasses of
 * #GtkToolItem should call this function to find out how text should
 * be aligned.
 * 
843
 * Returns: a #gfloat indicating the horizontal text alignment
844 845
 * used for @tool_item
 * 
846
 * Since: 2.20
847 848 849 850 851 852 853 854
 **/
gfloat
gtk_tool_item_get_text_alignment (GtkToolItem *tool_item)
{
  GtkWidget *parent;
  
  g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);

855
  parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
856 857 858 859 860 861 862 863
  if (!parent || !GTK_IS_TOOL_SHELL (parent))
    return 0.5;

  return gtk_tool_shell_get_text_alignment (GTK_TOOL_SHELL (parent));
}

/**
 * gtk_tool_item_get_text_orientation:
864 865
 * @tool_item: a #GtkToolItem
 *
866 867 868
 * Returns the text orientation used for @tool_item. Custom subclasses of
 * #GtkToolItem should call this function to find out how text should
 * be orientated.
869
 *
870
 * Returns: a #GtkOrientation indicating the text orientation
871
 * used for @tool_item
872 873 874
 *
 * Since: 2.20
 */
875 876 877 878 879 880 881
GtkOrientation
gtk_tool_item_get_text_orientation (GtkToolItem *tool_item)
{
  GtkWidget *parent;
  
  g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);

882
  parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
883 884 885 886 887 888 889 890
  if (!parent || !GTK_IS_TOOL_SHELL (parent))
    return GTK_ORIENTATION_HORIZONTAL;

  return gtk_tool_shell_get_text_orientation (GTK_TOOL_SHELL (parent));
}

/**
 * gtk_tool_item_get_text_size_group:
891 892
 * @tool_item: a #GtkToolItem
 *
893 894 895
 * Returns the size group used for labels in @tool_item.
 * Custom subclasses of #GtkToolItem should call this function
 * and use the size group for labels.
896
 *
897
 * Returns: (transfer none): a #GtkSizeGroup
898 899 900
 *
 * Since: 2.20
 */
901 902 903 904 905
GtkSizeGroup *
gtk_tool_item_get_text_size_group (GtkToolItem *tool_item)
{
  GtkWidget *parent;
  
906
  g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
907

908
  parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
909 910 911 912 913 914
  if (!parent || !GTK_IS_TOOL_SHELL (parent))
    return NULL;

  return gtk_tool_shell_get_text_size_group (GTK_TOOL_SHELL (parent));
}

915 916
/**
 * gtk_tool_item_set_expand:
917
 * @tool_item: a #GtkToolItem
918
 * @expand: Whether @tool_item is allocated extra space
919
 *
920 921 922 923
 * Sets whether @tool_item is allocated extra space when there
 * is more room on the toolbar then needed for the items. The
 * effect is that the item gets bigger when the toolbar gets bigger
 * and smaller when the toolbar gets smaller.
924
 *
925
 * Since: 2.4
926
 */
927 928 929 930 931 932 933 934
void
gtk_tool_item_set_expand (GtkToolItem *tool_item,
			  gboolean     expand)
{
  g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
    
  expand = expand != FALSE;

935
  if (tool_item->priv->expand != expand)
936
    {
937
      tool_item->priv->expand = expand;
938 939 940 941 942
      gtk_widget_child_notify (GTK_WIDGET (tool_item), "expand");
      gtk_widget_queue_resize (GTK_WIDGET (tool_item));
    }
}

943 944
/**
 * gtk_tool_item_get_expand:
945
 * @tool_item: a #GtkToolItem 
946 947 948 949
 * 
 * Returns whether @tool_item is allocated extra space.
 * See gtk_tool_item_set_expand().
 * 
950
 * Returns: %TRUE if @tool_item is allocated extra space.
951 952 953
 * 
 * Since: 2.4
 **/
954 955 956 957 958 959 960 961
gboolean
gtk_tool_item_get_expand (GtkToolItem *tool_item)
{
  g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);

  return tool_item->priv->expand;
}

962 963
/**
 * gtk_tool_item_set_homogeneous:
964
 * @tool_item: a #GtkToolItem 
965 966 967 968 969 970 971 972
 * @homogeneous: whether @tool_item is the same size as other homogeneous items
 * 
 * Sets whether @tool_item is to be allocated the same size as other
 * homogeneous items. The effect is that all homogeneous items will have
 * the same width as the widest of the items.
 * 
 * Since: 2.4
 **/
973 974 975 976 977 978 979 980
void
gtk_tool_item_set_homogeneous (GtkToolItem *tool_item,
			       gboolean     homogeneous)
{
  g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
    
  homogeneous = homogeneous != FALSE;

981
  if (tool_item->priv->homogeneous != homogeneous)
982
    {
983
      tool_item->priv->homogeneous = homogeneous;
984 985 986 987 988
      gtk_widget_child_notify (GTK_WIDGET (tool_item), "homogeneous");
      gtk_widget_queue_resize (GTK_WIDGET (tool_item));
    }
}

989 990
/**
 * gtk_tool_item_get_homogeneous:
991
 * @tool_item: a #GtkToolItem 
992 993 994 995
 * 
 * Returns whether @tool_item is the same size as other homogeneous
 * items. See gtk_tool_item_set_homogeneous().
 * 
996
 * Returns: %TRUE if the item is the same size as other homogeneous
997
 * items.
998 999 1000
 * 
 * Since: 2.4
 **/
1001 1002 1003 1004 1005 1006 1007 1008
gboolean
gtk_tool_item_get_homogeneous (GtkToolItem *tool_item)
{
  g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);

  return tool_item->priv->homogeneous;
}

1009 1010 1011 1012 1013
/**
 * gtk_tool_item_get_is_important:
 * @tool_item: a #GtkToolItem
 * 
 * Returns whether @tool_item is considered important. See
1014
 * gtk_tool_item_set_is_important()
1015
 * 
1016
 * Returns: %TRUE if @tool_item is considered important.
1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030
 * 
 * Since: 2.4
 **/
gboolean
gtk_tool_item_get_is_important (GtkToolItem *tool_item)
{
  g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);

  return tool_item->priv->is_important;
}

/**
 * gtk_tool_item_set_is_important:
 * @tool_item: a #GtkToolItem
Matthias Clasen's avatar
Matthias Clasen committed
1031
 * @is_important: whether the tool item should be considered important
1032 1033 1034 1035
 * 
 * Sets whether @tool_item should be considered important. The #GtkToolButton
 * class uses this property to determine whether to show or hide its label
 * when the toolbar style is %GTK_TOOLBAR_BOTH_HORIZ. The result is that
1036 1037
 * only tool buttons with the “is_important” property set have labels, an
 * effect known as “priority text”
1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053
 * 
 * Since: 2.4
 **/
void
gtk_tool_item_set_is_important (GtkToolItem *tool_item, gboolean is_important)
{
  g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));

  is_important = is_important != FALSE;

  if (is_important != tool_item->priv->is_important)
    {
      tool_item->priv->is_important = is_important;

      gtk_widget_queue_resize (GTK_WIDGET (tool_item));

1054
      g_object_notify (G_OBJECT (tool_item), "is-important");
1055 1056 1057
    }
}

1058 1059
/**
 * gtk_tool_item_set_tooltip_text:
1060
 * @tool_item: a #GtkToolItem 
1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075
 * @text: text to be used as tooltip for @tool_item
 *
 * Sets the text to be displayed as tooltip on the item.
 * See gtk_widget_set_tooltip_text().
 *
 * Since: 2.12
 **/
void
gtk_tool_item_set_tooltip_text (GtkToolItem *tool_item,
			        const gchar *text)
{
  GtkWidget *child;

  g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));

Javier Jardón's avatar
Javier Jardón committed
1076
  child = gtk_bin_get_child (GTK_BIN (tool_item));
1077 1078 1079 1080 1081 1082
  if (child)
    gtk_widget_set_tooltip_text (child, text);
}

/**
 * gtk_tool_item_set_tooltip_markup:
1083
 * @tool_item: a #GtkToolItem 
1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098
 * @markup: markup text to be used as tooltip for @tool_item
 *
 * Sets the markup text to be displayed as tooltip on the item.
 * See gtk_widget_set_tooltip_markup().
 *
 * Since: 2.12
 **/
void
gtk_tool_item_set_tooltip_markup (GtkToolItem *tool_item,
				  const gchar *markup)
{
  GtkWidget *child;

  g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));

Javier Jardón's avatar
Javier Jardón committed
1099
  child = gtk_bin_get_child (GTK_BIN (tool_item));
1100 1101 1102 1103
  if (child)
    gtk_widget_set_tooltip_markup (child, markup);
}

1104 1105
/**
 * gtk_tool_item_set_use_drag_window:
1106 1107
 * @tool_item: a #GtkToolItem 
 * @use_drag_window: Whether @tool_item has a drag window.
1108
 * 
1109
 * Sets whether @tool_item has a drag window. When %TRUE the
1110
 * toolitem can be used as a drag source through gtk_drag_source_set().
1111 1112
 * When @tool_item has a drag window it will intercept all events,
 * even those that would otherwise be sent to a child of @tool_item.
1113 1114 1115
 * 
 * Since: 2.4
 **/
1116 1117 1118 1119 1120 1121 1122 1123
void
gtk_tool_item_set_use_drag_window (GtkToolItem *toolitem,
				   gboolean     use_drag_window)
{
  g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));

  use_drag_window = use_drag_window != FALSE;

1124
  if (toolitem->priv->use_drag_window != use_drag_window)
1125
    {
1126
      toolitem->priv->use_drag_window = use_drag_window;
1127 1128 1129
      
      if (use_drag_window)
	{
1130 1131
	  if (!toolitem->priv->drag_window &&
              gtk_widget_get_realized (GTK_WIDGET (toolitem)))
1132 1133
	    {
	      create_drag_window(toolitem);
1134
	      if (gtk_widget_get_mapped (GTK_WIDGET (toolitem)))
1135
		gdk_window_show (toolitem->priv->drag_window);
1136 1137 1138 1139 1140 1141 1142 1143 1144
	    }
	}
      else
	{
	  destroy_drag_window (toolitem);
	}
    }
}

1145 1146
/**
 * gtk_tool_item_get_use_drag_window:
1147
 * @tool_item: a #GtkToolItem 
1148
 * 
1149
 * Returns whether @tool_item has a drag window. See
1150 1151
 * gtk_tool_item_set_use_drag_window().
 * 
1152
 * Returns: %TRUE if @tool_item uses a drag window.
1153 1154 1155
 * 
 * Since: 2.4
 **/
1156 1157 1158 1159 1160 1161 1162 1163
gboolean
gtk_tool_item_get_use_drag_window (GtkToolItem *toolitem)
{
  g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);

  return toolitem->priv->use_drag_window;
}

1164 1165
/**
 * gtk_tool_item_set_visible_horizontal:
1166 1167
 * @tool_item: a #GtkToolItem
 * @visible_horizontal: Whether @tool_item is visible when in horizontal mode
1168
 * 
1169
 * Sets whether @tool_item is visible when the toolbar is docked horizontally.
1170 1171 1172
 * 
 * Since: 2.4
 **/
1173 1174 1175 1176 1177 1178 1179 1180
void
gtk_tool_item_set_visible_horizontal (GtkToolItem *toolitem,
				      gboolean     visible_horizontal)
{
  g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));

  visible_horizontal = visible_horizontal != FALSE;

1181
  if (toolitem->priv->visible_horizontal != visible_horizontal)
1182
    {
1183
      toolitem->priv->visible_horizontal = visible_horizontal;
1184

1185
      g_object_notify (G_OBJECT (toolitem), "visible-horizontal");
1186 1187 1188 1189 1190

      gtk_widget_queue_resize (GTK_WIDGET (toolitem));
    }
}

1191 1192
/**
 * gtk_tool_item_get_visible_horizontal:
1193
 * @tool_item: a #GtkToolItem 
1194
 * 
1195
 * Returns whether the @tool_item is visible on toolbars that are
1196
 * docked horizontally.
1197
 * 
1198
 * Returns: %TRUE if @tool_item is visible on toolbars that are
1199 1200 1201 1202
 * docked horizontally.
 * 
 * Since: 2.4
 **/
1203 1204 1205 1206 1207
gboolean
gtk_tool_item_get_visible_horizontal (GtkToolItem *toolitem)
{
  g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);

1208
  return toolitem->priv->visible_horizontal;
1209 1210
}

1211 1212
/**
 * gtk_tool_item_set_visible_vertical:
1213 1214
 * @tool_item: a #GtkToolItem 
 * @visible_vertical: whether @tool_item is visible when the toolbar
1215 1216
 * is in vertical mode
 *
1217
 * Sets whether @tool_item is visible when the toolbar is docked
1218 1219
 * vertically. Some tool items, such as text entries, are too wide to be
 * useful on a vertically docked toolbar. If @visible_vertical is %FALSE
1220
 * @tool_item will not appear on toolbars that are docked vertically.
1221 1222 1223
 * 
 * Since: 2.4
 **/
1224 1225 1226 1227 1228 1229 1230 1231
void
gtk_tool_item_set_visible_vertical (GtkToolItem *toolitem,
				    gboolean     visible_vertical)
{
  g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));

  visible_vertical = visible_vertical != FALSE;

1232
  if (toolitem->priv->visible_vertical != visible_vertical)
1233
    {
1234
      toolitem->priv->visible_vertical = visible_vertical;
1235

1236
      g_object_notify (G_OBJECT (toolitem), "visible-vertical");
1237 1238 1239 1240 1241

      gtk_widget_queue_resize (GTK_WIDGET (toolitem));
    }
}

1242 1243
/**
 * gtk_tool_item_get_visible_vertical:
1244
 * @tool_item: a #GtkToolItem 
1245
 * 
1246
 * Returns whether @tool_item is visible when the toolbar is docked vertically.
1247 1248
 * See gtk_tool_item_set_visible_vertical().
 * 
1249
 * Returns: Whether @tool_item is visible when the toolbar is docked vertically
1250 1251 1252
 * 
 * Since: 2.4
 **/
1253 1254 1255 1256 1257
gboolean
gtk_tool_item_get_visible_vertical (GtkToolItem *toolitem)
{
  g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);

1258
  return toolitem->priv->visible_vertical;
1259 1260
}

1261 1262
/**
 * gtk_tool_item_retrieve_proxy_menu_item:
1263
 * @tool_item: a #GtkToolItem 
1264 1265 1266 1267
 * 
 * Returns the #GtkMenuItem that was last set by
 * gtk_tool_item_set_proxy_menu_item(), ie. the #GtkMenuItem
 * that is going to appear in the overflow menu.
1268
 *
1269
 * Returns: (transfer none): The #GtkMenuItem that is going to appear in the
1270
 * overflow menu for @tool_item.
1271
 *
1272 1273
 * Since: 2.4
 **/
1274 1275 1276 1277 1278 1279 1280
GtkWidget *
gtk_tool_item_retrieve_proxy_menu_item (GtkToolItem *tool_item)
{
  gboolean retval;
  
  g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);

1281 1282
  g_signal_emit (tool_item, toolitem_signals[CREATE_MENU_PROXY], 0,
		 &retval);
1283
  
1284
  return tool_item->priv->menu_item;
1285 1286
}

1287 1288
/**
 * gtk_tool_item_get_proxy_menu_item:
1289
 * @tool_item: a #GtkToolItem
1290
 * @menu_item_id: a string used to identify the menu item
1291
 *
1292 1293 1294
 * If @menu_item_id matches the string passed to
 * gtk_tool_item_set_proxy_menu_item() return the corresponding #GtkMenuItem.
 *
1295 1296
 * Custom subclasses of #GtkToolItem should use this function to
 * update their menu item when the #GtkToolItem changes. That the
1297
 * @menu_item_ids must match ensures that a #GtkToolItem
1298 1299
 * will not inadvertently change a menu item that they did not create.
 *
1300
 * Returns: (transfer none): The #GtkMenuItem passed to
1301
 *     gtk_tool_item_set_proxy_menu_item(), if the @menu_item_ids
1302 1303
 *     match.
 *
1304 1305
 * Since: 2.4
 **/
1306 1307 1308 1309 1310 1311 1312
GtkWidget *
gtk_tool_item_get_proxy_menu_item (GtkToolItem *tool_item,
				   const gchar *menu_item_id)
{
  g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
  g_return_val_if_fail (menu_item_id != NULL, NULL);

1313 1314
  if (tool_item->priv->menu_item_id && strcmp (tool_item->priv->menu_item_id, menu_item_id) == 0)
    return tool_item->priv->menu_item;
1315 1316 1317 1318

  return NULL;
}

1319
/**
Matthias Clasen's avatar
Matthias Clasen committed
1320
 * gtk_tool_item_rebuild_menu:
1321
 * @tool_item: a #GtkToolItem
Matthias Clasen's avatar
Matthias Clasen committed
1322
 *
1323 1324 1325 1326 1327
 * Calling this function signals to the toolbar that the
 * overflow menu item for @tool_item has changed. If the
 * overflow menu is visible when this function it called,
 * the menu will be rebuilt.
 *
Matthias Clasen's avatar
Matthias Clasen committed
1328 1329 1330
 * The function must be called when the tool item changes what it
 * will do in response to the #GtkToolItem::create-menu-proxy signal.
 *
1331
 * Since: 2.6
Matthias Clasen's avatar
Matthias Clasen committed
1332
 */
1333 1334 1335
void
gtk_tool_item_rebuild_menu (GtkToolItem *tool_item)
{
1336
  GtkWidget *parent;
1337
  GtkWidget *widget;
1338

1339 1340 1341
  g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));

  widget = GTK_WIDGET (tool_item);
1342

1343 1344 1345
  parent = gtk_widget_get_parent (widget);
  if (GTK_IS_TOOL_SHELL (parent))
    gtk_tool_shell_rebuild_menu (GTK_TOOL_SHELL (parent));
1346 1347
}

1348 1349
/**
 * gtk_tool_item_set_proxy_menu_item:
1350
 * @tool_item: a #GtkToolItem
1351 1352 1353 1354 1355 1356 1357 1358 1359
 * @menu_item_id: a string used to identify @menu_item
 * @menu_item: a #GtkMenuItem to be used in the overflow menu
 * 
 * Sets the #GtkMenuItem used in the toolbar overflow menu. The
 * @menu_item_id is used to identify the caller of this function and
 * should also be used with gtk_tool_item_get_proxy_menu_item().
 * 
 * Since: 2.4
 **/
1360 1361 1362 1363 1364 1365 1366 1367 1368
void
gtk_tool_item_set_proxy_menu_item (GtkToolItem *tool_item,
				   const gchar *menu_item_id,
				   GtkWidget   *menu_item)
{
  g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
  g_return_if_fail (menu_item == NULL || GTK_IS_MENU_ITEM (menu_item));
  g_return_if_fail (menu_item_id != NULL);

1369
  g_free (tool_item->priv->menu_item_id);
1370
      
1371
  tool_item->priv->menu_item_id = g_strdup (menu_item_id);
1372

1373
  if (tool_item->priv->menu_item != menu_item)
1374
    {
1375
      if (tool_item->priv->menu_item)
1376
	g_object_unref (tool_item->priv->menu_item);
1377 1378 1379
      
      if (menu_item)
	{
1380
	  g_object_ref_sink (menu_item);
1381 1382

	  gtk_widget_set_sensitive (menu_item,
1383
				    gtk_widget_get_sensitive (GTK_WIDGET (tool_item)));
1384 1385
	}
      
1386
      tool_item->priv->menu_item = menu_item;
1387 1388
    }
}
1389

1390
/**
1391 1392 1393 1394 1395 1396 1397
 * gtk_tool_item_toolbar_reconfigured:
 * @tool_item: a #GtkToolItem
 *
 * Emits the signal #GtkToolItem::toolbar_reconfigured on @tool_item.
 * #GtkToolbar and other #GtkToolShell implementations use this function
 * to notify children, when some aspect of their configuration changes.
 *
1398
 * Since: 2.14
1399
 **/
1400
void
1401
gtk_tool_item_toolbar_reconfigured (GtkToolItem *tool_item)
1402
{
1403 1404 1405
  /* The slightely inaccurate name "gtk_tool_item_toolbar_reconfigured" was
   * choosen over "gtk_tool_item_tool_shell_reconfigured", since the function
   * emits the "toolbar-reconfigured" signal, not "tool-shell-reconfigured".
1406
   * It's not possible to rename the signal, and emitting another name than
1407 1408 1409
   * indicated by the function name would be quite confusing. That's the
   * price of providing stable APIs.
   */
1410 1411 1412