2 * GTK - The GIMP Toolkit
3 * Copyright (C) 1998, 1999 Red Hat, Inc.
6 * This Library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This Library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with the Gnome Library; see the file COPYING.LIB. If not,
18 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
23 * Author: James Henstridge <james@daa.com.au>
25 * Modified by the GTK+ Team and others 2003. See the AUTHORS
26 * file for a list of people on the GTK+ Team. See the ChangeLog
27 * files for a list of changes. These files are distributed with
28 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
33 #include "gtkaction.h"
34 #include "gtkactiongroup.h"
35 #include "gtkaccellabel.h"
36 #include "gtkbutton.h"
37 #include "gtkiconfactory.h"
39 #include "gtkimagemenuitem.h"
42 #include "gtkmarshalers.h"
43 #include "gtkmenuitem.h"
45 #include "gtktearoffmenuitem.h"
46 #include "gtktoolbutton.h"
47 #include "gtktoolbar.h"
48 #include "gtkprivate.h"
49 #include "gtkbuildable.h"
50 #include "gtkactivatable.h"
54 #define GTK_ACTION_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ACTION, GtkActionPrivate))
56 struct _GtkActionPrivate
58 const gchar *name; /* interned */
62 gchar *stock_id; /* stock icon */
63 gchar *icon_name; /* themed icon */
68 guint label_set : 1; /* these two used so we can set label */
69 guint short_label_set : 1; /* based on stock id */
70 guint visible_horizontal : 1;
71 guint visible_vertical : 1;
72 guint is_important : 1;
73 guint hide_if_empty : 1;
74 guint visible_overflown : 1;
75 guint always_show_image : 1;
76 guint recursion_guard : 1;
77 guint activate_blocked : 1;
81 GtkAccelGroup *accel_group;
82 GClosure *accel_closure;
85 GtkActionGroup *action_group;
87 /* list of proxy widgets */
107 PROP_VISIBLE_HORIZONTAL,
108 PROP_VISIBLE_VERTICAL,
109 PROP_VISIBLE_OVERFLOWN,
115 PROP_ALWAYS_SHOW_IMAGE
119 static void gtk_action_buildable_init (GtkBuildableIface *iface);
120 static void gtk_action_buildable_set_name (GtkBuildable *buildable,
122 static const gchar* gtk_action_buildable_get_name (GtkBuildable *buildable);
124 G_DEFINE_TYPE_WITH_CODE (GtkAction, gtk_action, G_TYPE_OBJECT,
125 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
126 gtk_action_buildable_init))
128 static void gtk_action_finalize (GObject *object);
129 static void gtk_action_set_property (GObject *object,
133 static void gtk_action_get_property (GObject *object,
137 static void gtk_action_set_action_group (GtkAction *action,
138 GtkActionGroup *action_group);
140 static GtkWidget *create_menu_item (GtkAction *action);
141 static GtkWidget *create_tool_item (GtkAction *action);
142 static void connect_proxy (GtkAction *action,
144 static void disconnect_proxy (GtkAction *action,
147 static void closure_accel_activate (GClosure *closure,
148 GValue *return_value,
149 guint n_param_values,
150 const GValue *param_values,
151 gpointer invocation_hint,
152 gpointer marshal_data);
154 static guint action_signals[LAST_SIGNAL] = { 0 };
158 gtk_action_class_init (GtkActionClass *klass)
160 GObjectClass *gobject_class;
162 gobject_class = G_OBJECT_CLASS (klass);
164 gobject_class->finalize = gtk_action_finalize;
165 gobject_class->set_property = gtk_action_set_property;
166 gobject_class->get_property = gtk_action_get_property;
168 klass->activate = NULL;
170 klass->create_menu_item = create_menu_item;
171 klass->create_tool_item = create_tool_item;
172 klass->create_menu = NULL;
173 klass->menu_item_type = GTK_TYPE_IMAGE_MENU_ITEM;
174 klass->toolbar_item_type = GTK_TYPE_TOOL_BUTTON;
175 klass->connect_proxy = connect_proxy;
176 klass->disconnect_proxy = disconnect_proxy;
178 g_object_class_install_property (gobject_class,
180 g_param_spec_string ("name",
182 P_("A unique name for the action."),
184 GTK_PARAM_READWRITE |
185 G_PARAM_CONSTRUCT_ONLY));
190 * The label used for menu items and buttons that activate
191 * this action. If the label is %NULL, GTK+ uses the stock
192 * label specified via the stock-id property.
194 * This is an appearance property and thus only applies if
195 * #GtkActivatable:use-action-appearance is %TRUE.
197 g_object_class_install_property (gobject_class,
199 g_param_spec_string ("label",
201 P_("The label used for menu items and buttons "
202 "that activate this action."),
204 GTK_PARAM_READWRITE));
207 * GtkAction:short-label:
209 * A shorter label that may be used on toolbar buttons.
211 * This is an appearance property and thus only applies if
212 * #GtkActivatable:use-action-appearance is %TRUE.
214 g_object_class_install_property (gobject_class,
216 g_param_spec_string ("short-label",
218 P_("A shorter label that may be used on toolbar buttons."),
220 GTK_PARAM_READWRITE));
223 g_object_class_install_property (gobject_class,
225 g_param_spec_string ("tooltip",
227 P_("A tooltip for this action."),
229 GTK_PARAM_READWRITE));
232 * GtkAction:stock-id:
234 * The stock icon displayed in widgets representing this action.
236 * This is an appearance property and thus only applies if
237 * #GtkActivatable:use-action-appearance is %TRUE.
239 g_object_class_install_property (gobject_class,
241 g_param_spec_string ("stock-id",
243 P_("The stock icon displayed in widgets representing "
246 GTK_PARAM_READWRITE));
250 * The #GIcon displayed in the #GtkAction.
252 * Note that the stock icon is preferred, if the #GtkAction:stock-id
253 * property holds the id of an existing stock icon.
255 * This is an appearance property and thus only applies if
256 * #GtkActivatable:use-action-appearance is %TRUE.
260 g_object_class_install_property (gobject_class,
262 g_param_spec_object ("gicon",
264 P_("The GIcon being displayed"),
266 GTK_PARAM_READWRITE));
268 * GtkAction:icon-name:
270 * The name of the icon from the icon theme.
272 * Note that the stock icon is preferred, if the #GtkAction:stock-id
273 * property holds the id of an existing stock icon, and the #GIcon is
274 * preferred if the #GtkAction:gicon property is set.
276 * This is an appearance property and thus only applies if
277 * #GtkActivatable:use-action-appearance is %TRUE.
281 g_object_class_install_property (gobject_class,
283 g_param_spec_string ("icon-name",
285 P_("The name of the icon from the icon theme"),
287 GTK_PARAM_READWRITE));
289 g_object_class_install_property (gobject_class,
290 PROP_VISIBLE_HORIZONTAL,
291 g_param_spec_boolean ("visible-horizontal",
292 P_("Visible when horizontal"),
293 P_("Whether the toolbar item is visible when the toolbar "
294 "is in a horizontal orientation."),
296 GTK_PARAM_READWRITE));
298 * GtkAction:visible-overflown:
300 * When %TRUE, toolitem proxies for this action are represented in the
301 * toolbar overflow menu.
305 g_object_class_install_property (gobject_class,
306 PROP_VISIBLE_OVERFLOWN,
307 g_param_spec_boolean ("visible-overflown",
308 P_("Visible when overflown"),
309 P_("When TRUE, toolitem proxies for this action "
310 "are represented in the toolbar overflow menu."),
312 GTK_PARAM_READWRITE));
313 g_object_class_install_property (gobject_class,
314 PROP_VISIBLE_VERTICAL,
315 g_param_spec_boolean ("visible-vertical",
316 P_("Visible when vertical"),
317 P_("Whether the toolbar item is visible when the toolbar "
318 "is in a vertical orientation."),
320 GTK_PARAM_READWRITE));
321 g_object_class_install_property (gobject_class,
323 g_param_spec_boolean ("is-important",
325 P_("Whether the action is considered important. "
326 "When TRUE, toolitem proxies for this action "
327 "show text in GTK_TOOLBAR_BOTH_HORIZ mode."),
329 GTK_PARAM_READWRITE));
330 g_object_class_install_property (gobject_class,
332 g_param_spec_boolean ("hide-if-empty",
334 P_("When TRUE, empty menu proxies for this action are hidden."),
336 GTK_PARAM_READWRITE));
337 g_object_class_install_property (gobject_class,
339 g_param_spec_boolean ("sensitive",
341 P_("Whether the action is enabled."),
343 GTK_PARAM_READWRITE));
344 g_object_class_install_property (gobject_class,
346 g_param_spec_boolean ("visible",
348 P_("Whether the action is visible."),
350 GTK_PARAM_READWRITE));
351 g_object_class_install_property (gobject_class,
353 g_param_spec_object ("action-group",
355 P_("The GtkActionGroup this GtkAction is associated with, or NULL (for internal use)."),
356 GTK_TYPE_ACTION_GROUP,
357 GTK_PARAM_READWRITE));
360 * GtkAction:always-show-image:
362 * If %TRUE, the action's menu item proxies will ignore the #GtkSettings:gtk-menu-images
363 * setting and always show their image, if available.
365 * Use this property if the menu item would be useless or hard to use
366 * without their image.
370 g_object_class_install_property (gobject_class,
371 PROP_ALWAYS_SHOW_IMAGE,
372 g_param_spec_boolean ("always-show-image",
373 P_("Always show image"),
374 P_("Whether the image will always be shown"),
376 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
379 * GtkAction::activate:
380 * @action: the #GtkAction
382 * The "activate" signal is emitted when the action is activated.
386 action_signals[ACTIVATE] =
387 g_signal_new (I_("activate"),
388 G_OBJECT_CLASS_TYPE (klass),
389 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
390 G_STRUCT_OFFSET (GtkActionClass, activate), NULL, NULL,
391 g_cclosure_marshal_VOID__VOID,
394 g_type_class_add_private (gobject_class, sizeof (GtkActionPrivate));
399 gtk_action_init (GtkAction *action)
401 action->private_data = GTK_ACTION_GET_PRIVATE (action);
403 action->private_data->name = NULL;
404 action->private_data->label = NULL;
405 action->private_data->short_label = NULL;
406 action->private_data->tooltip = NULL;
407 action->private_data->stock_id = NULL;
408 action->private_data->icon_name = NULL;
409 action->private_data->visible_horizontal = TRUE;
410 action->private_data->visible_vertical = TRUE;
411 action->private_data->visible_overflown = TRUE;
412 action->private_data->is_important = FALSE;
413 action->private_data->hide_if_empty = TRUE;
414 action->private_data->always_show_image = FALSE;
415 action->private_data->activate_blocked = FALSE;
417 action->private_data->sensitive = TRUE;
418 action->private_data->visible = TRUE;
420 action->private_data->label_set = FALSE;
421 action->private_data->short_label_set = FALSE;
423 action->private_data->accel_count = 0;
424 action->private_data->accel_group = NULL;
425 action->private_data->accel_quark = 0;
426 action->private_data->accel_closure =
427 g_closure_new_object (sizeof (GClosure), G_OBJECT (action));
428 g_closure_set_marshal (action->private_data->accel_closure,
429 closure_accel_activate);
430 g_closure_ref (action->private_data->accel_closure);
431 g_closure_sink (action->private_data->accel_closure);
433 action->private_data->action_group = NULL;
435 action->private_data->proxies = NULL;
436 action->private_data->gicon = NULL;
440 gtk_action_buildable_init (GtkBuildableIface *iface)
442 iface->set_name = gtk_action_buildable_set_name;
443 iface->get_name = gtk_action_buildable_get_name;
447 gtk_action_buildable_set_name (GtkBuildable *buildable,
450 GtkAction *action = GTK_ACTION (buildable);
452 action->private_data->name = g_intern_string (name);
456 gtk_action_buildable_get_name (GtkBuildable *buildable)
458 GtkAction *action = GTK_ACTION (buildable);
460 return action->private_data->name;
465 * @name: A unique name for the action
466 * @label: the label displayed in menu items and on buttons, or %NULL
467 * @tooltip: a tooltip for the action, or %NULL
468 * @stock_id: the stock icon to display in widgets representing the
471 * Creates a new #GtkAction object. To add the action to a
472 * #GtkActionGroup and set the accelerator for the action,
473 * call gtk_action_group_add_action_with_accel().
474 * See <xref linkend="XML-UI"/> for information on allowed action
477 * Return value: a new #GtkAction
482 gtk_action_new (const gchar *name,
484 const gchar *tooltip,
485 const gchar *stock_id)
487 g_return_val_if_fail (name != NULL, NULL);
489 return g_object_new (GTK_TYPE_ACTION,
493 "stock-id", stock_id,
498 gtk_action_finalize (GObject *object)
501 action = GTK_ACTION (object);
503 g_free (action->private_data->label);
504 g_free (action->private_data->short_label);
505 g_free (action->private_data->tooltip);
506 g_free (action->private_data->stock_id);
507 g_free (action->private_data->icon_name);
509 if (action->private_data->gicon)
510 g_object_unref (action->private_data->gicon);
512 g_closure_unref (action->private_data->accel_closure);
513 if (action->private_data->accel_group)
514 g_object_unref (action->private_data->accel_group);
516 G_OBJECT_CLASS (gtk_action_parent_class)->finalize (object);
520 gtk_action_set_property (GObject *object,
527 action = GTK_ACTION (object);
532 action->private_data->name = g_intern_string (g_value_get_string (value));
535 gtk_action_set_label (action, g_value_get_string (value));
537 case PROP_SHORT_LABEL:
538 gtk_action_set_short_label (action, g_value_get_string (value));
541 gtk_action_set_tooltip (action, g_value_get_string (value));
544 gtk_action_set_stock_id (action, g_value_get_string (value));
547 gtk_action_set_gicon (action, g_value_get_object (value));
550 gtk_action_set_icon_name (action, g_value_get_string (value));
552 case PROP_VISIBLE_HORIZONTAL:
553 gtk_action_set_visible_horizontal (action, g_value_get_boolean (value));
555 case PROP_VISIBLE_VERTICAL:
556 gtk_action_set_visible_vertical (action, g_value_get_boolean (value));
558 case PROP_VISIBLE_OVERFLOWN:
559 action->private_data->visible_overflown = g_value_get_boolean (value);
561 case PROP_IS_IMPORTANT:
562 gtk_action_set_is_important (action, g_value_get_boolean (value));
564 case PROP_HIDE_IF_EMPTY:
565 action->private_data->hide_if_empty = g_value_get_boolean (value);
568 gtk_action_set_sensitive (action, g_value_get_boolean (value));
571 gtk_action_set_visible (action, g_value_get_boolean (value));
573 case PROP_ACTION_GROUP:
574 gtk_action_set_action_group (action, g_value_get_object (value));
576 case PROP_ALWAYS_SHOW_IMAGE:
577 gtk_action_set_always_show_image (action, g_value_get_boolean (value));
580 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
586 gtk_action_get_property (GObject *object,
593 action = GTK_ACTION (object);
598 g_value_set_static_string (value, action->private_data->name);
601 g_value_set_string (value, action->private_data->label);
603 case PROP_SHORT_LABEL:
604 g_value_set_string (value, action->private_data->short_label);
607 g_value_set_string (value, action->private_data->tooltip);
610 g_value_set_string (value, action->private_data->stock_id);
613 g_value_set_string (value, action->private_data->icon_name);
616 g_value_set_object (value, action->private_data->gicon);
618 case PROP_VISIBLE_HORIZONTAL:
619 g_value_set_boolean (value, action->private_data->visible_horizontal);
621 case PROP_VISIBLE_VERTICAL:
622 g_value_set_boolean (value, action->private_data->visible_vertical);
624 case PROP_VISIBLE_OVERFLOWN:
625 g_value_set_boolean (value, action->private_data->visible_overflown);
627 case PROP_IS_IMPORTANT:
628 g_value_set_boolean (value, action->private_data->is_important);
630 case PROP_HIDE_IF_EMPTY:
631 g_value_set_boolean (value, action->private_data->hide_if_empty);
634 g_value_set_boolean (value, action->private_data->sensitive);
637 g_value_set_boolean (value, action->private_data->visible);
639 case PROP_ACTION_GROUP:
640 g_value_set_object (value, action->private_data->action_group);
642 case PROP_ALWAYS_SHOW_IMAGE:
643 g_value_set_boolean (value, action->private_data->always_show_image);
646 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
652 create_menu_item (GtkAction *action)
654 GType menu_item_type;
656 menu_item_type = GTK_ACTION_GET_CLASS (action)->menu_item_type;
658 return g_object_new (menu_item_type, NULL);
662 create_tool_item (GtkAction *action)
664 GType toolbar_item_type;
666 toolbar_item_type = GTK_ACTION_GET_CLASS (action)->toolbar_item_type;
668 return g_object_new (toolbar_item_type, NULL);
672 remove_proxy (GtkAction *action,
675 action->private_data->proxies = g_slist_remove (action->private_data->proxies, proxy);
679 connect_proxy (GtkAction *action,
682 action->private_data->proxies = g_slist_prepend (action->private_data->proxies, proxy);
684 if (action->private_data->action_group)
685 _gtk_action_group_emit_connect_proxy (action->private_data->action_group, action, proxy);
690 disconnect_proxy (GtkAction *action,
693 remove_proxy (action, proxy);
695 if (action->private_data->action_group)
696 _gtk_action_group_emit_disconnect_proxy (action->private_data->action_group, action, proxy);
700 * _gtk_action_sync_menu_visible:
701 * @action: a #GtkAction, or %NULL to determine the action from @proxy
702 * @proxy: a proxy menu item
703 * @empty: whether the submenu attached to @proxy is empty
705 * Updates the visibility of @proxy from the visibility of @action
706 * according to the following rules:
708 * <listitem><para>if @action is invisible, @proxy is too
710 * <listitem><para>if @empty is %TRUE, hide @proxy unless the "hide-if-empty"
711 * property of @action indicates otherwise
715 * This function is used in the implementation of #GtkUIManager.
718 _gtk_action_sync_menu_visible (GtkAction *action,
722 gboolean visible = TRUE;
723 gboolean hide_if_empty = TRUE;
725 g_return_if_fail (GTK_IS_MENU_ITEM (proxy));
726 g_return_if_fail (action == NULL || GTK_IS_ACTION (action));
729 action = gtk_activatable_get_related_action (GTK_ACTIVATABLE (proxy));
733 /* a GtkMenu for a <popup/> doesn't have to have an action */
734 visible = gtk_action_is_visible (action);
735 hide_if_empty = action->private_data->hide_if_empty;
738 if (visible && !(empty && hide_if_empty))
739 gtk_widget_show (proxy);
741 gtk_widget_hide (proxy);
745 _gtk_action_emit_activate (GtkAction *action)
747 GtkActionGroup *group = action->private_data->action_group;
751 g_object_ref (group);
752 _gtk_action_group_emit_pre_activate (group, action);
755 g_signal_emit (action, action_signals[ACTIVATE], 0);
759 _gtk_action_group_emit_post_activate (group, action);
760 g_object_unref (group);
765 * gtk_action_activate:
766 * @action: the action object
768 * Emits the "activate" signal on the specified action, if it isn't
769 * insensitive. This gets called by the proxy widgets when they get
772 * It can also be used to manually activate an action.
777 gtk_action_activate (GtkAction *action)
779 g_return_if_fail (GTK_IS_ACTION (action));
781 if (action->private_data->activate_blocked)
784 if (gtk_action_is_sensitive (action))
785 _gtk_action_emit_activate (action);
789 * gtk_action_block_activate:
790 * @action: a #GtkAction
792 * Disable activation signals from the action
794 * This is needed when updating the state of your proxy
795 * #GtkActivatable widget could result in calling gtk_action_activate(),
796 * this is a convenience function to avoid recursing in those
797 * cases (updating toggle state for instance).
802 gtk_action_block_activate (GtkAction *action)
804 g_return_if_fail (GTK_IS_ACTION (action));
806 action->private_data->activate_blocked = TRUE;
810 * gtk_action_unblock_activate:
811 * @action: a #GtkAction
813 * Reenable activation signals from the action
818 gtk_action_unblock_activate (GtkAction *action)
820 g_return_if_fail (GTK_IS_ACTION (action));
822 action->private_data->activate_blocked = FALSE;
826 * gtk_action_create_icon:
827 * @action: the action object
828 * @icon_size: the size of the icon that should be created.
830 * This function is intended for use by action implementations to
831 * create icons displayed in the proxy widgets.
833 * Returns: a widget that displays the icon for this action.
838 gtk_action_create_icon (GtkAction *action, GtkIconSize icon_size)
840 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
842 if (action->private_data->stock_id &&
843 gtk_icon_factory_lookup_default (action->private_data->stock_id))
844 return gtk_image_new_from_stock (action->private_data->stock_id, icon_size);
845 else if (action->private_data->gicon)
846 return gtk_image_new_from_gicon (action->private_data->gicon, icon_size);
847 else if (action->private_data->icon_name)
848 return gtk_image_new_from_icon_name (action->private_data->icon_name, icon_size);
854 * gtk_action_create_menu_item:
855 * @action: the action object
857 * Creates a menu item widget that proxies for the given action.
859 * Returns: a menu item connected to the action.
864 gtk_action_create_menu_item (GtkAction *action)
866 GtkWidget *menu_item;
868 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
870 menu_item = GTK_ACTION_GET_CLASS (action)->create_menu_item (action);
872 gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (menu_item), TRUE);
873 gtk_activatable_set_related_action (GTK_ACTIVATABLE (menu_item), action);
879 * gtk_action_create_tool_item:
880 * @action: the action object
882 * Creates a toolbar item widget that proxies for the given action.
884 * Returns: a toolbar item connected to the action.
889 gtk_action_create_tool_item (GtkAction *action)
893 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
895 button = GTK_ACTION_GET_CLASS (action)->create_tool_item (action);
897 gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (button), TRUE);
898 gtk_activatable_set_related_action (GTK_ACTIVATABLE (button), action);
904 _gtk_action_add_to_proxy_list (GtkAction *action,
907 g_return_if_fail (GTK_IS_ACTION (action));
908 g_return_if_fail (GTK_IS_WIDGET (proxy));
910 GTK_ACTION_GET_CLASS (action)->connect_proxy (action, proxy);
914 _gtk_action_remove_from_proxy_list (GtkAction *action,
917 g_return_if_fail (GTK_IS_ACTION (action));
918 g_return_if_fail (GTK_IS_WIDGET (proxy));
920 GTK_ACTION_GET_CLASS (action)->disconnect_proxy (action, proxy);
924 * gtk_action_connect_proxy:
925 * @action: the action object
926 * @proxy: the proxy widget
928 * Connects a widget to an action object as a proxy. Synchronises
929 * various properties of the action with the widget (such as label
930 * text, icon, tooltip, etc), and attaches a callback so that the
931 * action gets activated when the proxy widget does.
933 * If the widget is already connected to an action, it is disconnected
938 * Deprecated: 2.16: Use gtk_activatable_set_related_action() instead.
941 gtk_action_connect_proxy (GtkAction *action,
944 g_return_if_fail (GTK_IS_ACTION (action));
945 g_return_if_fail (GTK_IS_WIDGET (proxy));
946 g_return_if_fail (GTK_IS_ACTIVATABLE (proxy));
948 gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (proxy), TRUE);
950 gtk_activatable_set_related_action (GTK_ACTIVATABLE (proxy), action);
954 * gtk_action_disconnect_proxy:
955 * @action: the action object
956 * @proxy: the proxy widget
958 * Disconnects a proxy widget from an action.
959 * Does <emphasis>not</emphasis> destroy the widget, however.
963 * Deprecated: 2.16: Use gtk_activatable_set_related_action() instead.
966 gtk_action_disconnect_proxy (GtkAction *action,
969 g_return_if_fail (GTK_IS_ACTION (action));
970 g_return_if_fail (GTK_IS_WIDGET (proxy));
972 gtk_activatable_set_related_action (GTK_ACTIVATABLE (proxy), NULL);
976 * gtk_action_get_proxies:
977 * @action: the action object
979 * Returns the proxy widgets for an action.
980 * See also gtk_widget_get_action().
982 * Return value: a #GSList of proxy widgets. The list is owned by GTK+
983 * and must not be modified.
988 gtk_action_get_proxies (GtkAction *action)
990 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
992 return action->private_data->proxies;
997 * gtk_widget_get_action:
998 * @widget: a #GtkWidget
1000 * Returns the #GtkAction that @widget is a proxy for.
1001 * See also gtk_action_get_proxies().
1003 * Returns: the action that a widget is a proxy for, or
1004 * %NULL, if it is not attached to an action.
1008 * Deprecated: 2.16: Use gtk_activatable_get_related_action() instead.
1011 gtk_widget_get_action (GtkWidget *widget)
1013 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1015 if (GTK_IS_ACTIVATABLE (widget))
1016 return gtk_activatable_get_related_action (GTK_ACTIVATABLE (widget));
1022 * gtk_action_get_name:
1023 * @action: the action object
1025 * Returns the name of the action.
1027 * Return value: the name of the action. The string belongs to GTK+ and should not
1032 G_CONST_RETURN gchar *
1033 gtk_action_get_name (GtkAction *action)
1035 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1037 return action->private_data->name;
1041 * gtk_action_is_sensitive:
1042 * @action: the action object
1044 * Returns whether the action is effectively sensitive.
1046 * Return value: %TRUE if the action and its associated action group
1047 * are both sensitive.
1052 gtk_action_is_sensitive (GtkAction *action)
1054 GtkActionPrivate *priv;
1055 g_return_val_if_fail (GTK_IS_ACTION (action), FALSE);
1057 priv = action->private_data;
1058 return priv->sensitive &&
1059 (priv->action_group == NULL ||
1060 gtk_action_group_get_sensitive (priv->action_group));
1064 * gtk_action_get_sensitive:
1065 * @action: the action object
1067 * Returns whether the action itself is sensitive. Note that this doesn't
1068 * necessarily mean effective sensitivity. See gtk_action_is_sensitive()
1071 * Return value: %TRUE if the action itself is sensitive.
1076 gtk_action_get_sensitive (GtkAction *action)
1078 g_return_val_if_fail (GTK_IS_ACTION (action), FALSE);
1080 return action->private_data->sensitive;
1084 * gtk_action_set_sensitive:
1085 * @action: the action object
1086 * @sensitive: %TRUE to make the action sensitive
1088 * Sets the ::sensitive property of the action to @sensitive. Note that
1089 * this doesn't necessarily mean effective sensitivity. See
1090 * gtk_action_is_sensitive()
1096 gtk_action_set_sensitive (GtkAction *action,
1099 g_return_if_fail (GTK_IS_ACTION (action));
1101 sensitive = sensitive != FALSE;
1103 if (action->private_data->sensitive != sensitive)
1105 action->private_data->sensitive = sensitive;
1107 g_object_notify (G_OBJECT (action), "sensitive");
1112 * gtk_action_is_visible:
1113 * @action: the action object
1115 * Returns whether the action is effectively visible.
1117 * Return value: %TRUE if the action and its associated action group
1123 gtk_action_is_visible (GtkAction *action)
1125 GtkActionPrivate *priv;
1126 g_return_val_if_fail (GTK_IS_ACTION (action), FALSE);
1128 priv = action->private_data;
1129 return priv->visible &&
1130 (priv->action_group == NULL ||
1131 gtk_action_group_get_visible (priv->action_group));
1135 * gtk_action_get_visible:
1136 * @action: the action object
1138 * Returns whether the action itself is visible. Note that this doesn't
1139 * necessarily mean effective visibility. See gtk_action_is_sensitive()
1142 * Return value: %TRUE if the action itself is visible.
1147 gtk_action_get_visible (GtkAction *action)
1149 g_return_val_if_fail (GTK_IS_ACTION (action), FALSE);
1151 return action->private_data->visible;
1155 * gtk_action_set_visible:
1156 * @action: the action object
1157 * @visible: %TRUE to make the action visible
1159 * Sets the ::visible property of the action to @visible. Note that
1160 * this doesn't necessarily mean effective visibility. See
1161 * gtk_action_is_visible()
1167 gtk_action_set_visible (GtkAction *action,
1170 g_return_if_fail (GTK_IS_ACTION (action));
1172 visible = visible != FALSE;
1174 if (action->private_data->visible != visible)
1176 action->private_data->visible = visible;
1178 g_object_notify (G_OBJECT (action), "visible");
1182 * gtk_action_set_is_important:
1183 * @action: the action object
1184 * @is_important: %TRUE to make the action important
1186 * Sets whether the action is important, this attribute is used
1187 * primarily by toolbar items to decide whether to show a label
1193 gtk_action_set_is_important (GtkAction *action,
1194 gboolean is_important)
1196 g_return_if_fail (GTK_IS_ACTION (action));
1198 is_important = is_important != FALSE;
1200 if (action->private_data->is_important != is_important)
1202 action->private_data->is_important = is_important;
1204 g_object_notify (G_OBJECT (action), "is-important");
1209 * gtk_action_get_is_important:
1210 * @action: a #GtkAction
1212 * Checks whether @action is important or not
1214 * Returns: whether @action is important
1219 gtk_action_get_is_important (GtkAction *action)
1221 g_return_val_if_fail (GTK_IS_ACTION (action), FALSE);
1223 return action->private_data->is_important;
1227 * gtk_action_set_always_show_image:
1228 * @action: the action object
1229 * @always_show: %TRUE if menuitem proxies should always show their image
1231 * Sets whether @action<!-- -->'s menu item proxies will ignore the
1232 * #GtkSettings:gtk-menu-images setting and always show their image, if available.
1234 * Use this if the menu item would be useless or hard to use
1235 * without their image.
1240 gtk_action_set_always_show_image (GtkAction *action,
1241 gboolean always_show)
1243 GtkActionPrivate *priv;
1245 g_return_if_fail (GTK_IS_ACTION (action));
1247 priv = action->private_data;
1249 always_show = always_show != FALSE;
1251 if (priv->always_show_image != always_show)
1253 priv->always_show_image = always_show;
1255 g_object_notify (G_OBJECT (action), "always-show-image");
1260 * gtk_action_get_always_show_image:
1263 * Returns whether @action<!-- -->'s menu item proxies will ignore the
1264 * #GtkSettings:gtk-menu-images setting and always show their image, if available.
1266 * Returns: %TRUE if the menu item proxies will always show their image
1271 gtk_action_get_always_show_image (GtkAction *action)
1273 g_return_val_if_fail (GTK_IS_ACTION (action), FALSE);
1275 return action->private_data->always_show_image;
1279 * gtk_action_set_label:
1280 * @action: a #GtkAction
1281 * @label: the label text to set
1283 * Sets the label of @action.
1288 gtk_action_set_label (GtkAction *action,
1293 g_return_if_fail (GTK_IS_ACTION (action));
1295 tmp = action->private_data->label;
1296 action->private_data->label = g_strdup (label);
1298 action->private_data->label_set = (action->private_data->label != NULL);
1299 /* if label is unset, then use the label from the stock item */
1300 if (!action->private_data->label_set && action->private_data->stock_id)
1302 GtkStockItem stock_item;
1304 if (gtk_stock_lookup (action->private_data->stock_id, &stock_item))
1305 action->private_data->label = g_strdup (stock_item.label);
1308 g_object_notify (G_OBJECT (action), "label");
1310 /* if short_label is unset, set short_label=label */
1311 if (!action->private_data->short_label_set)
1313 gtk_action_set_short_label (action, action->private_data->label);
1314 action->private_data->short_label_set = FALSE;
1319 * gtk_action_get_label:
1320 * @action: a #GtkAction
1322 * Gets the label text of @action.
1324 * Returns: the label text
1328 G_CONST_RETURN gchar *
1329 gtk_action_get_label (GtkAction *action)
1331 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1333 return action->private_data->label;
1337 * gtk_action_set_short_label:
1338 * @action: a #GtkAction
1339 * @short_label: the label text to set
1341 * Sets a shorter label text on @action.
1346 gtk_action_set_short_label (GtkAction *action,
1347 const gchar *short_label)
1351 g_return_if_fail (GTK_IS_ACTION (action));
1353 tmp = action->private_data->short_label;
1354 action->private_data->short_label = g_strdup (short_label);
1356 action->private_data->short_label_set = (action->private_data->short_label != NULL);
1357 /* if short_label is unset, then use the value of label */
1358 if (!action->private_data->short_label_set)
1359 action->private_data->short_label = g_strdup (action->private_data->label);
1361 g_object_notify (G_OBJECT (action), "short-label");
1365 * gtk_action_get_short_label:
1366 * @action: a #GtkAction
1368 * Gets the short label text of @action.
1370 * Returns: the short label text.
1374 G_CONST_RETURN gchar *
1375 gtk_action_get_short_label (GtkAction *action)
1377 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1379 return action->private_data->short_label;
1383 * gtk_action_set_visible_horizontal:
1384 * @action: a #GtkAction
1385 * @visible_horizontal: whether the action is visible horizontally
1387 * Sets whether @action is visible when horizontal
1392 gtk_action_set_visible_horizontal (GtkAction *action,
1393 gboolean visible_horizontal)
1395 g_return_if_fail (GTK_IS_ACTION (action));
1397 g_return_if_fail (GTK_IS_ACTION (action));
1399 visible_horizontal = visible_horizontal != FALSE;
1401 if (action->private_data->visible_horizontal != visible_horizontal)
1403 action->private_data->visible_horizontal = visible_horizontal;
1405 g_object_notify (G_OBJECT (action), "visible-horizontal");
1410 * gtk_action_get_visible_horizontal:
1411 * @action: a #GtkAction
1413 * Checks whether @action is visible when horizontal
1415 * Returns: whether @action is visible when horizontal
1420 gtk_action_get_visible_horizontal (GtkAction *action)
1422 g_return_val_if_fail (GTK_IS_ACTION (action), FALSE);
1424 return action->private_data->visible_horizontal;
1428 * gtk_action_set_visible_vertical:
1429 * @action: a #GtkAction
1430 * @visible_vertical: whether the action is visible vertically
1432 * Sets whether @action is visible when vertical
1437 gtk_action_set_visible_vertical (GtkAction *action,
1438 gboolean visible_vertical)
1440 g_return_if_fail (GTK_IS_ACTION (action));
1442 g_return_if_fail (GTK_IS_ACTION (action));
1444 visible_vertical = visible_vertical != FALSE;
1446 if (action->private_data->visible_vertical != visible_vertical)
1448 action->private_data->visible_vertical = visible_vertical;
1450 g_object_notify (G_OBJECT (action), "visible-vertical");
1455 * gtk_action_get_visible_vertical:
1456 * @action: a #GtkAction
1458 * Checks whether @action is visible when horizontal
1460 * Returns: whether @action is visible when horizontal
1465 gtk_action_get_visible_vertical (GtkAction *action)
1467 g_return_val_if_fail (GTK_IS_ACTION (action), FALSE);
1469 return action->private_data->visible_vertical;
1473 * gtk_action_set_tooltip:
1474 * @action: a #GtkAction
1475 * @tooltip: the tooltip text
1477 * Sets the tooltip text on @action
1482 gtk_action_set_tooltip (GtkAction *action,
1483 const gchar *tooltip)
1487 g_return_if_fail (GTK_IS_ACTION (action));
1489 tmp = action->private_data->tooltip;
1490 action->private_data->tooltip = g_strdup (tooltip);
1493 g_object_notify (G_OBJECT (action), "tooltip");
1497 * gtk_action_get_tooltip:
1498 * @action: a #GtkAction
1500 * Gets the tooltip text of @action.
1502 * Returns: the tooltip text
1506 G_CONST_RETURN gchar *
1507 gtk_action_get_tooltip (GtkAction *action)
1509 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1511 return action->private_data->tooltip;
1515 * gtk_action_set_stock_id:
1516 * @action: a #GtkAction
1517 * @stock_id: the stock id
1519 * Sets the stock id on @action
1524 gtk_action_set_stock_id (GtkAction *action,
1525 const gchar *stock_id)
1529 g_return_if_fail (GTK_IS_ACTION (action));
1531 g_return_if_fail (GTK_IS_ACTION (action));
1533 tmp = action->private_data->stock_id;
1534 action->private_data->stock_id = g_strdup (stock_id);
1537 g_object_notify (G_OBJECT (action), "stock-id");
1539 /* update label and short_label if appropriate */
1540 if (!action->private_data->label_set)
1542 GtkStockItem stock_item;
1544 if (action->private_data->stock_id &&
1545 gtk_stock_lookup (action->private_data->stock_id, &stock_item))
1546 gtk_action_set_label (action, stock_item.label);
1548 gtk_action_set_label (action, NULL);
1550 action->private_data->label_set = FALSE;
1555 * gtk_action_get_stock_id:
1556 * @action: a #GtkAction
1558 * Gets the stock id of @action.
1560 * Returns: the stock id
1564 G_CONST_RETURN gchar *
1565 gtk_action_get_stock_id (GtkAction *action)
1567 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1569 return action->private_data->stock_id;
1573 * gtk_action_set_icon_name:
1574 * @action: a #GtkAction
1575 * @icon_name: the icon name to set
1577 * Sets the icon name on @action
1582 gtk_action_set_icon_name (GtkAction *action,
1583 const gchar *icon_name)
1587 g_return_if_fail (GTK_IS_ACTION (action));
1589 tmp = action->private_data->icon_name;
1590 action->private_data->icon_name = g_strdup (icon_name);
1593 g_object_notify (G_OBJECT (action), "icon-name");
1597 * gtk_action_get_icon_name:
1598 * @action: a #GtkAction
1600 * Gets the icon name of @action.
1602 * Returns: the icon name
1606 G_CONST_RETURN gchar *
1607 gtk_action_get_icon_name (GtkAction *action)
1609 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1611 return action->private_data->icon_name;
1615 * gtk_action_set_gicon:
1616 * @action: a #GtkAction
1617 * @icon: the #GIcon to set
1619 * Sets the icon of @action.
1624 gtk_action_set_gicon (GtkAction *action,
1627 g_return_if_fail (GTK_IS_ACTION (action));
1629 if (action->private_data->gicon)
1630 g_object_unref (action->private_data->gicon);
1632 action->private_data->gicon = icon;
1634 if (action->private_data->gicon)
1635 g_object_ref (action->private_data->gicon);
1637 g_object_notify (G_OBJECT (action), "gicon");
1641 * gtk_action_get_gicon:
1642 * @action: a #GtkAction
1644 * Gets the gicon of @action.
1646 * Returns: The action's #GIcon if one is set.
1651 gtk_action_get_gicon (GtkAction *action)
1653 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1655 return action->private_data->gicon;
1659 * gtk_action_block_activate_from:
1660 * @action: the action object
1661 * @proxy: a proxy widget
1663 * Disables calls to the gtk_action_activate()
1664 * function by signals on the given proxy widget. This is used to
1665 * break notification loops for things like check or radio actions.
1667 * This function is intended for use by action implementations.
1671 * Deprecated: 2.16: activatables are now responsible for activating the
1672 * action directly so this doesnt apply anymore.
1675 gtk_action_block_activate_from (GtkAction *action,
1678 g_return_if_fail (GTK_IS_ACTION (action));
1680 g_signal_handlers_block_by_func (proxy, G_CALLBACK (gtk_action_activate),
1683 gtk_action_block_activate (action);
1687 * gtk_action_unblock_activate_from:
1688 * @action: the action object
1689 * @proxy: a proxy widget
1691 * Re-enables calls to the gtk_action_activate()
1692 * function by signals on the given proxy widget. This undoes the
1693 * blocking done by gtk_action_block_activate_from().
1695 * This function is intended for use by action implementations.
1699 * Deprecated: 2.16: activatables are now responsible for activating the
1700 * action directly so this doesnt apply anymore.
1703 gtk_action_unblock_activate_from (GtkAction *action,
1706 g_return_if_fail (GTK_IS_ACTION (action));
1708 g_signal_handlers_unblock_by_func (proxy, G_CALLBACK (gtk_action_activate),
1711 gtk_action_unblock_activate (action);
1715 closure_accel_activate (GClosure *closure,
1716 GValue *return_value,
1717 guint n_param_values,
1718 const GValue *param_values,
1719 gpointer invocation_hint,
1720 gpointer marshal_data)
1722 if (gtk_action_is_sensitive (GTK_ACTION (closure->data)))
1724 _gtk_action_emit_activate (GTK_ACTION (closure->data));
1726 /* we handled the accelerator */
1727 g_value_set_boolean (return_value, TRUE);
1732 gtk_action_set_action_group (GtkAction *action,
1733 GtkActionGroup *action_group)
1735 if (action->private_data->action_group == NULL)
1736 g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
1738 g_return_if_fail (action_group == NULL);
1740 action->private_data->action_group = action_group;
1744 * gtk_action_set_accel_path:
1745 * @action: the action object
1746 * @accel_path: the accelerator path
1748 * Sets the accel path for this action. All proxy widgets associated
1749 * with the action will have this accel path, so that their
1750 * accelerators are consistent.
1752 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
1753 * pass a static string, you can save some memory by interning it first with
1754 * g_intern_static_string().
1759 gtk_action_set_accel_path (GtkAction *action,
1760 const gchar *accel_path)
1762 g_return_if_fail (GTK_IS_ACTION (action));
1764 action->private_data->accel_quark = g_quark_from_string (accel_path);
1768 * gtk_action_get_accel_path:
1769 * @action: the action object
1771 * Returns the accel path for this action.
1775 * Returns: the accel path for this action, or %NULL
1776 * if none is set. The returned string is owned by GTK+
1777 * and must not be freed or modified.
1779 G_CONST_RETURN gchar *
1780 gtk_action_get_accel_path (GtkAction *action)
1782 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1784 if (action->private_data->accel_quark)
1785 return g_quark_to_string (action->private_data->accel_quark);
1791 * gtk_action_get_accel_closure:
1792 * @action: the action object
1794 * Returns the accel closure for this action.
1798 * Returns: the accel closure for this action. The returned closure is
1799 * owned by GTK+ and must not be unreffed or modified.
1802 gtk_action_get_accel_closure (GtkAction *action)
1804 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1806 return action->private_data->accel_closure;
1811 * gtk_action_set_accel_group:
1812 * @action: the action object
1813 * @accel_group: a #GtkAccelGroup or %NULL
1815 * Sets the #GtkAccelGroup in which the accelerator for this action
1816 * will be installed.
1821 gtk_action_set_accel_group (GtkAction *action,
1822 GtkAccelGroup *accel_group)
1824 g_return_if_fail (GTK_IS_ACTION (action));
1825 g_return_if_fail (accel_group == NULL || GTK_IS_ACCEL_GROUP (accel_group));
1828 g_object_ref (accel_group);
1829 if (action->private_data->accel_group)
1830 g_object_unref (action->private_data->accel_group);
1832 action->private_data->accel_group = accel_group;
1836 * gtk_action_connect_accelerator:
1837 * @action: a #GtkAction
1839 * Installs the accelerator for @action if @action has an
1840 * accel path and group. See gtk_action_set_accel_path() and
1841 * gtk_action_set_accel_group()
1843 * Since multiple proxies may independently trigger the installation
1844 * of the accelerator, the @action counts the number of times this
1845 * function has been called and doesn't remove the accelerator until
1846 * gtk_action_disconnect_accelerator() has been called as many times.
1851 gtk_action_connect_accelerator (GtkAction *action)
1853 g_return_if_fail (GTK_IS_ACTION (action));
1855 if (!action->private_data->accel_quark ||
1856 !action->private_data->accel_group)
1859 if (action->private_data->accel_count == 0)
1861 const gchar *accel_path =
1862 g_quark_to_string (action->private_data->accel_quark);
1864 gtk_accel_group_connect_by_path (action->private_data->accel_group,
1866 action->private_data->accel_closure);
1869 action->private_data->accel_count++;
1873 * gtk_action_disconnect_accelerator:
1874 * @action: a #GtkAction
1876 * Undoes the effect of one call to gtk_action_connect_accelerator().
1881 gtk_action_disconnect_accelerator (GtkAction *action)
1883 g_return_if_fail (GTK_IS_ACTION (action));
1885 if (!action->private_data->accel_quark ||
1886 !action->private_data->accel_group)
1889 action->private_data->accel_count--;
1891 if (action->private_data->accel_count == 0)
1892 gtk_accel_group_disconnect (action->private_data->accel_group,
1893 action->private_data->accel_closure);
1897 * gtk_action_create_menu:
1898 * @action: a #GtkAction
1900 * If @action provides a #GtkMenu widget as a submenu for the menu
1901 * item or the toolbar item it creates, this function returns an
1902 * instance of that menu.
1904 * Return value: the menu item provided by the action, or %NULL.
1909 gtk_action_create_menu (GtkAction *action)
1911 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1913 if (GTK_ACTION_GET_CLASS (action)->create_menu)
1914 return GTK_ACTION_GET_CLASS (action)->create_menu (action);
1919 #define __GTK_ACTION_C__
1920 #include "gtkaliasdef.c"