gtktoolitem.c 40.6 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

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));
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));
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));
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 534 535
      
      gtk_widget_size_allocate (child, &child_allocation);
    }
}

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

  G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558

  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);
559

560
      ret = TRUE;
561 562
    }

563 564 565
  G_GNUC_END_IGNORE_DEPRECATIONS;

  return ret;
566 567
}

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

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

582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602
  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));
603 604

  G_GNUC_END_IGNORE_DEPRECATIONS;
605 606
}

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

614 615
  G_GNUC_BEGIN_IGNORE_DEPRECATIONS;

616 617 618 619 620 621 622 623 624 625 626 627 628 629 630
  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));
631 632

  G_GNUC_END_IGNORE_DEPRECATIONS;
633 634 635 636 637 638 639 640 641
}

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

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

  item->priv->action = action;

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

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

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


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

  item = g_object_new (GTK_TYPE_TOOL_ITEM, NULL);

  return item;
}

688 689
/**
 * gtk_tool_item_get_ellipsize_mode:
690 691
 * @tool_item: a #GtkToolItem
 *
692 693 694
 * Returns the ellipsize mode used for @tool_item. Custom subclasses of
 * #GtkToolItem should call this function to find out how text should
 * be ellipsized.
695
 *
696
 * Returns: a #PangoEllipsizeMode indicating how text in @tool_item
697
 * should be ellipsized.
698 699
 *
 * Since: 2.20
700 701 702 703 704 705 706 707
 **/
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);

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

  return gtk_tool_shell_get_ellipsize_mode (GTK_TOOL_SHELL (parent));
}

715 716
/**
 * gtk_tool_item_get_icon_size:
717
 * @tool_item: a #GtkToolItem
718 719 720 721 722
 * 
 * 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.
 * 
723
 * Returns: (type int): a #GtkIconSize indicating the icon size
724
 * used for @tool_item
725 726 727
 * 
 * Since: 2.4
 **/
728 729 730 731 732 733 734
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);

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

739
  return gtk_tool_shell_get_icon_size (GTK_TOOL_SHELL (parent));
740 741
}

742 743
/**
 * gtk_tool_item_get_orientation:
744
 * @tool_item: a #GtkToolItem 
745 746 747 748 749
 * 
 * Returns the orientation used for @tool_item. Custom subclasses of
 * #GtkToolItem should call this function to find out what size icons
 * they should use.
 * 
750
 * Returns: a #GtkOrientation indicating the orientation
751 752 753 754
 * used for @tool_item
 * 
 * Since: 2.4
 **/
755 756 757 758 759 760 761
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);

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

766
  return gtk_tool_shell_get_orientation (GTK_TOOL_SHELL (parent));
767 768
}

769 770
/**
 * gtk_tool_item_get_toolbar_style:
771
 * @tool_item: a #GtkToolItem 
772 773 774 775 776 777 778
 * 
 * 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:
779 780 781 782 783 784
 * - %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
785
 * 
786
 * Returns: A #GtkToolbarStyle indicating the toolbar style used
787 788 789 790
 * for @tool_item.
 * 
 * Since: 2.4
 **/
791 792 793 794 795 796 797
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);

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

802
  return gtk_tool_shell_get_style (GTK_TOOL_SHELL (parent));
803 804
}

805 806
/**
 * gtk_tool_item_get_relief_style:
807
 * @tool_item: a #GtkToolItem 
808
 * 
809
 * Returns the relief style of @tool_item. See gtk_button_set_relief().
810 811 812 813
 * 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.
 * 
814
 * Returns: a #GtkReliefStyle indicating the relief style used
815 816 817 818
 * for @tool_item.
 * 
 * Since: 2.4
 **/
819 820 821 822 823 824 825
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);

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

830
  return gtk_tool_shell_get_relief_style (GTK_TOOL_SHELL (parent));
831 832
}

833 834 835 836 837 838 839 840
/**
 * 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.
 * 
841
 * Returns: a #gfloat indicating the horizontal text alignment
842 843
 * used for @tool_item
 * 
844
 * Since: 2.20
845 846 847 848 849 850 851 852
 **/
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);

853
  parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
854 855 856 857 858 859 860 861
  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:
862 863
 * @tool_item: a #GtkToolItem
 *
864 865 866
 * Returns the text orientation used for @tool_item. Custom subclasses of
 * #GtkToolItem should call this function to find out how text should
 * be orientated.
867
 *
868
 * Returns: a #GtkOrientation indicating the text orientation
869
 * used for @tool_item
870 871 872
 *
 * Since: 2.20
 */
873 874 875 876 877 878 879
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);

880
  parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
881 882 883 884 885 886 887 888
  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:
889 890
 * @tool_item: a #GtkToolItem
 *
891 892 893
 * 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.
894
 *
895
 * Returns: (transfer none): a #GtkSizeGroup
896 897 898
 *
 * Since: 2.20
 */
899 900 901 902 903
GtkSizeGroup *
gtk_tool_item_get_text_size_group (GtkToolItem *tool_item)
{
  GtkWidget *parent;
  
904
  g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
905

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

  return gtk_tool_shell_get_text_size_group (GTK_TOOL_SHELL (parent));
}

913 914
/**
 * gtk_tool_item_set_expand:
915
 * @tool_item: a #GtkToolItem
916
 * @expand: Whether @tool_item is allocated extra space
917
 *
918 919 920 921
 * 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.
922
 *
923
 * Since: 2.4
924
 */
925 926 927 928 929 930 931 932
void
gtk_tool_item_set_expand (GtkToolItem *tool_item,
			  gboolean     expand)
{
  g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
    
  expand = expand != FALSE;

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

941 942
/**
 * gtk_tool_item_get_expand:
943
 * @tool_item: a #GtkToolItem 
944 945 946 947
 * 
 * Returns whether @tool_item is allocated extra space.
 * See gtk_tool_item_set_expand().
 * 
948
 * Returns: %TRUE if @tool_item is allocated extra space.
949 950 951
 * 
 * Since: 2.4
 **/
952 953 954 955 956 957 958 959
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;
}

960 961
/**
 * gtk_tool_item_set_homogeneous:
962
 * @tool_item: a #GtkToolItem 
963 964 965 966 967 968 969 970
 * @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
 **/
971 972 973 974 975 976 977 978
void
gtk_tool_item_set_homogeneous (GtkToolItem *tool_item,
			       gboolean     homogeneous)
{
  g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
    
  homogeneous = homogeneous != FALSE;

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

987 988
/**
 * gtk_tool_item_get_homogeneous:
989
 * @tool_item: a #GtkToolItem 
990 991 992 993
 * 
 * Returns whether @tool_item is the same size as other homogeneous
 * items. See gtk_tool_item_set_homogeneous().
 * 
994
 * Returns: %TRUE if the item is the same size as other homogeneous
995
 * items.
996 997 998
 * 
 * Since: 2.4
 **/
999 1000 1001 1002 1003 1004 1005 1006
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;
}

1007 1008 1009 1010 1011
/**
 * gtk_tool_item_get_is_important:
 * @tool_item: a #GtkToolItem
 * 
 * Returns whether @tool_item is considered important. See
1012
 * gtk_tool_item_set_is_important()
1013
 * 
1014
 * Returns: %TRUE if @tool_item is considered important.
1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028
 * 
 * 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
1029
 * @is_important: whether the tool item should be considered important
1030 1031 1032 1033
 * 
 * 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
1034 1035
 * only tool buttons with the “is_important” property set have labels, an
 * effect known as “priority text”
1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051
 * 
 * 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));

1052
      g_object_notify (G_OBJECT (tool_item), "is-important");
1053 1054 1055
    }
}

1056 1057
/**
 * gtk_tool_item_set_tooltip_text:
1058
 * @tool_item: a #GtkToolItem 
1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073
 * @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
1074
  child = gtk_bin_get_child (GTK_BIN (tool_item));
1075 1076 1077 1078 1079 1080
  if (child)
    gtk_widget_set_tooltip_text (child, text);
}

/**
 * gtk_tool_item_set_tooltip_markup:
1081
 * @tool_item: a #GtkToolItem 
1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096
 * @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
1097
  child = gtk_bin_get_child (GTK_BIN (tool_item));
1098 1099 1100 1101
  if (child)
    gtk_widget_set_tooltip_markup (child, markup);
}

1102 1103
/**
 * gtk_tool_item_set_use_drag_window:
1104 1105
 * @tool_item: a #GtkToolItem 
 * @use_drag_window: Whether @tool_item has a drag window.
1106
 * 
1107
 * Sets whether @tool_item has a drag window. When %TRUE the
1108
 * toolitem can be used as a drag source through gtk_drag_source_set().
1109 1110
 * 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.
1111 1112 1113
 * 
 * Since: 2.4
 **/
1114 1115 1116 1117 1118 1119 1120 1121
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;

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

1143 1144
/**
 * gtk_tool_item_get_use_drag_window:
1145
 * @tool_item: a #GtkToolItem 
1146
 * 
1147
 * Returns whether @tool_item has a drag window. See
1148 1149
 * gtk_tool_item_set_use_drag_window().
 * 
1150
 * Returns: %TRUE if @tool_item uses a drag window.
1151 1152 1153
 * 
 * Since: 2.4
 **/
1154 1155 1156 1157 1158 1159 1160 1161
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;
}

1162 1163
/**
 * gtk_tool_item_set_visible_horizontal:
1164 1165
 * @tool_item: a #GtkToolItem
 * @visible_horizontal: Whether @tool_item is visible when in horizontal mode
1166
 * 
1167
 * Sets whether @tool_item is visible when the toolbar is docked horizontally.
1168 1169 1170
 * 
 * Since: 2.4
 **/
1171 1172 1173 1174 1175 1176 1177 1178
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;

1179
  if (toolitem->priv->visible_horizontal != visible_horizontal)
1180
    {
1181
      toolitem->priv->visible_horizontal = visible_horizontal;
1182

1183
      g_object_notify (G_OBJECT (toolitem), "visible-horizontal");
1184 1185 1186 1187 1188

      gtk_widget_queue_resize (GTK_WIDGET (toolitem));
    }
}

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

1206
  return toolitem->priv->visible_horizontal;
1207 1208
}

1209 1210
/**
 * gtk_tool_item_set_visible_vertical:
1211 1212
 * @tool_item: a #GtkToolItem 
 * @visible_vertical: whether @tool_item is visible when the toolbar
1213 1214
 * is in vertical mode
 *
1215
 * Sets whether @tool_item is visible when the toolbar is docked
1216 1217
 * vertically. Some tool items, such as text entries, are too wide to be
 * useful on a vertically docked toolbar. If @visible_vertical is %FALSE
1218
 * @tool_item will not appear on toolbars that are docked vertically.
1219 1220 1221
 * 
 * Since: 2.4
 **/
1222 1223 1224 1225 1226 1227 1228 1229
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;

1230
  if (toolitem->priv->visible_vertical != visible_vertical)
1231
    {
1232
      toolitem->priv->visible_vertical = visible_vertical;
1233

1234
      g_object_notify (G_OBJECT (toolitem), "visible-vertical");
1235 1236 1237 1238 1239

      gtk_widget_queue_resize (GTK_WIDGET (toolitem));
    }
}

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

1256
  return toolitem->priv->visible_vertical;
1257 1258
}

1259 1260
/**
 * gtk_tool_item_retrieve_proxy_menu_item:
1261
 * @tool_item: a #GtkToolItem 
1262 1263 1264 1265
 * 
 * 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.
1266
 *
1267
 * Returns: (transfer none): The #GtkMenuItem that is going to appear in the
1268
 * overflow menu for @tool_item.
1269
 *
1270 1271
 * Since: 2.4
 **/
1272 1273 1274 1275 1276 1277 1278
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);

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

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

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

  return NULL;
}

1317
/**
Matthias Clasen's avatar
Matthias Clasen committed
1318
 * gtk_tool_item_rebuild_menu:
1319
 * @tool_item: a #GtkToolItem
Matthias Clasen's avatar
Matthias Clasen committed
1320
 *
1321 1322 1323 1324 1325
 * 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
1326 1327 1328
 * The function must be called when the tool item changes what it
 * will do in response to the #GtkToolItem::create-menu-proxy signal.
 *
1329
 * Since: 2.6
Matthias Clasen's avatar
Matthias Clasen committed
1330
 */
1331 1332 1333
void
gtk_tool_item_rebuild_menu (GtkToolItem *tool_item)
{
1334
  GtkWidget *parent;
1335
  GtkWidget *widget;
1336

1337 1338 1339
  g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));

  widget = GTK_WIDGET (tool_item);
1340

1341 1342 1343
  parent = gtk_widget_get_parent (widget);
  if (GTK_IS_TOOL_SHELL (parent))
    gtk_tool_shell_rebuild_menu (GTK_TOOL_SHELL (parent));
1344 1345
}

1346 1347
/**
 * gtk_tool_item_set_proxy_menu_item:
1348
 * @tool_item: a #GtkToolItem
1349 1350 1351 1352 1353 1354 1355 1356 1357
 * @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
 **/
1358 1359 1360 1361 1362 1363 1364 1365 1366
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);

1367
  g_free (tool_item->priv->menu_item_id);
1368
      
1369
  tool_item->priv->menu_item_id = g_strdup (menu_item_id);
1370

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

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

1388
/**
1389 1390 1391 1392 1393 1394 1395
 * 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.
 *
1396
 * Since: 2.14
1397
 **/
1398
void
1399
gtk_tool_item_toolbar_reconfigured (GtkToolItem *tool_item)
1400
{
1401 1402 1403
  /* 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".
1404
   * It's not possible to rename the signal, and emitting another name than
1405 1406 1407
   * indicated by the function name would be quite confusing. That's the
   * price of providing stable APIs.
   */
1408 1409 1410 1411
  g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));

  g_signal_emit (tool_item, toolitem_signals[TOOLBAR_RECONFIGURED], 0);
  
1412 1413
  if (tool_item->priv->drag_window)
    gdk_window_raise (tool_item->priv->drag_window);