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 recursion_guard : 1;
76 guint activate_blocked : 1;
80 GtkAccelGroup *accel_group;
81 GClosure *accel_closure;
84 GtkActionGroup *action_group;
86 /* list of proxy widgets */
106 PROP_VISIBLE_HORIZONTAL,
107 PROP_VISIBLE_VERTICAL,
108 PROP_VISIBLE_OVERFLOWN,
117 static void gtk_action_buildable_init (GtkBuildableIface *iface);
118 static void gtk_action_buildable_set_name (GtkBuildable *buildable,
120 static const gchar* gtk_action_buildable_get_name (GtkBuildable *buildable);
122 G_DEFINE_TYPE_WITH_CODE (GtkAction, gtk_action, G_TYPE_OBJECT,
123 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
124 gtk_action_buildable_init))
126 static void gtk_action_finalize (GObject *object);
127 static void gtk_action_set_property (GObject *object,
131 static void gtk_action_get_property (GObject *object,
135 static void gtk_action_set_action_group (GtkAction *action,
136 GtkActionGroup *action_group);
138 static GtkWidget *create_menu_item (GtkAction *action);
139 static GtkWidget *create_tool_item (GtkAction *action);
140 static void connect_proxy (GtkAction *action,
142 static void disconnect_proxy (GtkAction *action,
145 static void closure_accel_activate (GClosure *closure,
146 GValue *return_value,
147 guint n_param_values,
148 const GValue *param_values,
149 gpointer invocation_hint,
150 gpointer marshal_data);
152 static guint action_signals[LAST_SIGNAL] = { 0 };
156 gtk_action_class_init (GtkActionClass *klass)
158 GObjectClass *gobject_class;
160 gobject_class = G_OBJECT_CLASS (klass);
162 gobject_class->finalize = gtk_action_finalize;
163 gobject_class->set_property = gtk_action_set_property;
164 gobject_class->get_property = gtk_action_get_property;
166 klass->activate = NULL;
168 klass->create_menu_item = create_menu_item;
169 klass->create_tool_item = create_tool_item;
170 klass->create_menu = NULL;
171 klass->menu_item_type = GTK_TYPE_IMAGE_MENU_ITEM;
172 klass->toolbar_item_type = GTK_TYPE_TOOL_BUTTON;
173 klass->connect_proxy = connect_proxy;
174 klass->disconnect_proxy = disconnect_proxy;
176 g_object_class_install_property (gobject_class,
178 g_param_spec_string ("name",
180 P_("A unique name for the action."),
182 GTK_PARAM_READWRITE |
183 G_PARAM_CONSTRUCT_ONLY));
188 * The label used for menu items and buttons that activate
189 * this action. If the label is %NULL, GTK+ uses the stock
190 * label specified via the stock-id property.
192 * This is an appearance property and thus only applies if
193 * #GtkActivatable:use-action-appearance is %TRUE.
195 g_object_class_install_property (gobject_class,
197 g_param_spec_string ("label",
199 P_("The label used for menu items and buttons "
200 "that activate this action."),
202 GTK_PARAM_READWRITE));
205 * GtkAction:short-label:
207 * A shorter label that may be used on toolbar buttons.
209 * This is an appearance property and thus only applies if
210 * #GtkActivatable:use-action-appearance is %TRUE.
212 g_object_class_install_property (gobject_class,
214 g_param_spec_string ("short-label",
216 P_("A shorter label that may be used on toolbar buttons."),
218 GTK_PARAM_READWRITE));
221 g_object_class_install_property (gobject_class,
223 g_param_spec_string ("tooltip",
225 P_("A tooltip for this action."),
227 GTK_PARAM_READWRITE));
230 * GtkAction:stock-id:
232 * The stock icon displayed in widgets representing this action.
234 * This is an appearance property and thus only applies if
235 * #GtkActivatable:use-action-appearance is %TRUE.
237 g_object_class_install_property (gobject_class,
239 g_param_spec_string ("stock-id",
241 P_("The stock icon displayed in widgets representing "
244 GTK_PARAM_READWRITE));
248 * The #GIcon displayed in the #GtkAction.
250 * Note that the stock icon is preferred, if the #GtkAction:stock-id
251 * property holds the id of an existing stock icon.
253 * This is an appearance property and thus only applies if
254 * #GtkActivatable:use-action-appearance is %TRUE.
258 g_object_class_install_property (gobject_class,
260 g_param_spec_object ("gicon",
262 P_("The GIcon being displayed"),
264 GTK_PARAM_READWRITE));
266 * GtkAction:icon-name:
268 * The name of the icon from the icon theme.
270 * Note that the stock icon is preferred, if the #GtkAction:stock-id
271 * property holds the id of an existing stock icon, and the #GIcon is
272 * preferred if the #GtkAction:gicon property is set.
274 * This is an appearance property and thus only applies if
275 * #GtkActivatable:use-action-appearance is %TRUE.
279 g_object_class_install_property (gobject_class,
281 g_param_spec_string ("icon-name",
283 P_("The name of the icon from the icon theme"),
285 GTK_PARAM_READWRITE));
287 g_object_class_install_property (gobject_class,
288 PROP_VISIBLE_HORIZONTAL,
289 g_param_spec_boolean ("visible-horizontal",
290 P_("Visible when horizontal"),
291 P_("Whether the toolbar item is visible when the toolbar "
292 "is in a horizontal orientation."),
294 GTK_PARAM_READWRITE));
296 * GtkAction:visible-overflown:
298 * When %TRUE, toolitem proxies for this action are represented in the
299 * toolbar overflow menu.
303 g_object_class_install_property (gobject_class,
304 PROP_VISIBLE_OVERFLOWN,
305 g_param_spec_boolean ("visible-overflown",
306 P_("Visible when overflown"),
307 P_("When TRUE, toolitem proxies for this action "
308 "are represented in the toolbar overflow menu."),
310 GTK_PARAM_READWRITE));
311 g_object_class_install_property (gobject_class,
312 PROP_VISIBLE_VERTICAL,
313 g_param_spec_boolean ("visible-vertical",
314 P_("Visible when vertical"),
315 P_("Whether the toolbar item is visible when the toolbar "
316 "is in a vertical orientation."),
318 GTK_PARAM_READWRITE));
319 g_object_class_install_property (gobject_class,
321 g_param_spec_boolean ("is-important",
323 P_("Whether the action is considered important. "
324 "When TRUE, toolitem proxies for this action "
325 "show text in GTK_TOOLBAR_BOTH_HORIZ mode."),
327 GTK_PARAM_READWRITE));
328 g_object_class_install_property (gobject_class,
330 g_param_spec_boolean ("hide-if-empty",
332 P_("When TRUE, empty menu proxies for this action are hidden."),
334 GTK_PARAM_READWRITE));
335 g_object_class_install_property (gobject_class,
337 g_param_spec_boolean ("sensitive",
339 P_("Whether the action is enabled."),
341 GTK_PARAM_READWRITE));
342 g_object_class_install_property (gobject_class,
344 g_param_spec_boolean ("visible",
346 P_("Whether the action is visible."),
348 GTK_PARAM_READWRITE));
349 g_object_class_install_property (gobject_class,
351 g_param_spec_object ("action-group",
353 P_("The GtkActionGroup this GtkAction is associated with, or NULL (for internal use)."),
354 GTK_TYPE_ACTION_GROUP,
355 GTK_PARAM_READWRITE));
358 * GtkAction::activate:
359 * @action: the #GtkAction
361 * The "activate" signal is emitted when the action is activated.
365 action_signals[ACTIVATE] =
366 g_signal_new (I_("activate"),
367 G_OBJECT_CLASS_TYPE (klass),
368 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
369 G_STRUCT_OFFSET (GtkActionClass, activate), NULL, NULL,
370 g_cclosure_marshal_VOID__VOID,
373 g_type_class_add_private (gobject_class, sizeof (GtkActionPrivate));
378 gtk_action_init (GtkAction *action)
380 action->private_data = GTK_ACTION_GET_PRIVATE (action);
382 action->private_data->name = NULL;
383 action->private_data->label = NULL;
384 action->private_data->short_label = NULL;
385 action->private_data->tooltip = NULL;
386 action->private_data->stock_id = NULL;
387 action->private_data->icon_name = NULL;
388 action->private_data->visible_horizontal = TRUE;
389 action->private_data->visible_vertical = TRUE;
390 action->private_data->visible_overflown = TRUE;
391 action->private_data->is_important = FALSE;
392 action->private_data->hide_if_empty = TRUE;
393 action->private_data->activate_blocked = FALSE;
395 action->private_data->sensitive = TRUE;
396 action->private_data->visible = TRUE;
398 action->private_data->label_set = FALSE;
399 action->private_data->short_label_set = FALSE;
401 action->private_data->accel_count = 0;
402 action->private_data->accel_group = NULL;
403 action->private_data->accel_quark = 0;
404 action->private_data->accel_closure =
405 g_closure_new_object (sizeof (GClosure), G_OBJECT (action));
406 g_closure_set_marshal (action->private_data->accel_closure,
407 closure_accel_activate);
408 g_closure_ref (action->private_data->accel_closure);
409 g_closure_sink (action->private_data->accel_closure);
411 action->private_data->action_group = NULL;
413 action->private_data->proxies = NULL;
414 action->private_data->gicon = NULL;
418 gtk_action_buildable_init (GtkBuildableIface *iface)
420 iface->set_name = gtk_action_buildable_set_name;
421 iface->get_name = gtk_action_buildable_get_name;
425 gtk_action_buildable_set_name (GtkBuildable *buildable,
428 GtkAction *action = GTK_ACTION (buildable);
430 action->private_data->name = g_intern_string (name);
434 gtk_action_buildable_get_name (GtkBuildable *buildable)
436 GtkAction *action = GTK_ACTION (buildable);
438 return action->private_data->name;
443 * @name: A unique name for the action
444 * @label: the label displayed in menu items and on buttons, or %NULL
445 * @tooltip: a tooltip for the action, or %NULL
446 * @stock_id: the stock icon to display in widgets representing the
449 * Creates a new #GtkAction object. To add the action to a
450 * #GtkActionGroup and set the accelerator for the action,
451 * call gtk_action_group_add_action_with_accel().
452 * See <xref linkend="XML-UI"/> for information on allowed action
455 * Return value: a new #GtkAction
460 gtk_action_new (const gchar *name,
462 const gchar *tooltip,
463 const gchar *stock_id)
465 g_return_val_if_fail (name != NULL, NULL);
467 return g_object_new (GTK_TYPE_ACTION,
471 "stock-id", stock_id,
476 gtk_action_finalize (GObject *object)
479 action = GTK_ACTION (object);
481 g_free (action->private_data->label);
482 g_free (action->private_data->short_label);
483 g_free (action->private_data->tooltip);
484 g_free (action->private_data->stock_id);
485 g_free (action->private_data->icon_name);
487 if (action->private_data->gicon)
488 g_object_unref (action->private_data->gicon);
490 g_closure_unref (action->private_data->accel_closure);
491 if (action->private_data->accel_group)
492 g_object_unref (action->private_data->accel_group);
494 G_OBJECT_CLASS (gtk_action_parent_class)->finalize (object);
498 gtk_action_set_property (GObject *object,
505 action = GTK_ACTION (object);
510 action->private_data->name = g_intern_string (g_value_get_string (value));
513 gtk_action_set_label (action, g_value_get_string (value));
515 case PROP_SHORT_LABEL:
516 gtk_action_set_short_label (action, g_value_get_string (value));
519 gtk_action_set_tooltip (action, g_value_get_string (value));
522 gtk_action_set_stock_id (action, g_value_get_string (value));
525 gtk_action_set_gicon (action, g_value_get_object (value));
528 gtk_action_set_icon_name (action, g_value_get_string (value));
530 case PROP_VISIBLE_HORIZONTAL:
531 gtk_action_set_visible_horizontal (action, g_value_get_boolean (value));
533 case PROP_VISIBLE_VERTICAL:
534 gtk_action_set_visible_vertical (action, g_value_get_boolean (value));
536 case PROP_VISIBLE_OVERFLOWN:
537 action->private_data->visible_overflown = g_value_get_boolean (value);
539 case PROP_IS_IMPORTANT:
540 gtk_action_set_is_important (action, g_value_get_boolean (value));
542 case PROP_HIDE_IF_EMPTY:
543 action->private_data->hide_if_empty = g_value_get_boolean (value);
546 gtk_action_set_sensitive (action, g_value_get_boolean (value));
549 gtk_action_set_visible (action, g_value_get_boolean (value));
551 case PROP_ACTION_GROUP:
552 gtk_action_set_action_group (action, g_value_get_object (value));
555 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
561 gtk_action_get_property (GObject *object,
568 action = GTK_ACTION (object);
573 g_value_set_static_string (value, action->private_data->name);
576 g_value_set_string (value, action->private_data->label);
578 case PROP_SHORT_LABEL:
579 g_value_set_string (value, action->private_data->short_label);
582 g_value_set_string (value, action->private_data->tooltip);
585 g_value_set_string (value, action->private_data->stock_id);
588 g_value_set_string (value, action->private_data->icon_name);
591 g_value_set_object (value, action->private_data->gicon);
593 case PROP_VISIBLE_HORIZONTAL:
594 g_value_set_boolean (value, action->private_data->visible_horizontal);
596 case PROP_VISIBLE_VERTICAL:
597 g_value_set_boolean (value, action->private_data->visible_vertical);
599 case PROP_VISIBLE_OVERFLOWN:
600 g_value_set_boolean (value, action->private_data->visible_overflown);
602 case PROP_IS_IMPORTANT:
603 g_value_set_boolean (value, action->private_data->is_important);
605 case PROP_HIDE_IF_EMPTY:
606 g_value_set_boolean (value, action->private_data->hide_if_empty);
609 g_value_set_boolean (value, action->private_data->sensitive);
612 g_value_set_boolean (value, action->private_data->visible);
614 case PROP_ACTION_GROUP:
615 g_value_set_object (value, action->private_data->action_group);
618 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
624 create_menu_item (GtkAction *action)
626 GType menu_item_type;
628 menu_item_type = GTK_ACTION_GET_CLASS (action)->menu_item_type;
630 return g_object_new (menu_item_type, NULL);
634 create_tool_item (GtkAction *action)
636 GType toolbar_item_type;
638 toolbar_item_type = GTK_ACTION_GET_CLASS (action)->toolbar_item_type;
640 return g_object_new (toolbar_item_type, NULL);
644 remove_proxy (GtkAction *action,
647 action->private_data->proxies = g_slist_remove (action->private_data->proxies, proxy);
651 connect_proxy (GtkAction *action,
654 action->private_data->proxies = g_slist_prepend (action->private_data->proxies, proxy);
656 if (action->private_data->action_group)
657 _gtk_action_group_emit_connect_proxy (action->private_data->action_group, action, proxy);
662 disconnect_proxy (GtkAction *action,
665 remove_proxy (action, proxy);
667 if (action->private_data->action_group)
668 _gtk_action_group_emit_disconnect_proxy (action->private_data->action_group, action, proxy);
672 * _gtk_action_sync_menu_visible:
673 * @action: a #GtkAction, or %NULL to determine the action from @proxy
674 * @proxy: a proxy menu item
675 * @empty: whether the submenu attached to @proxy is empty
677 * Updates the visibility of @proxy from the visibility of @action
678 * according to the following rules:
680 * <listitem><para>if @action is invisible, @proxy is too
682 * <listitem><para>if @empty is %TRUE, hide @proxy unless the "hide-if-empty"
683 * property of @action indicates otherwise
687 * This function is used in the implementation of #GtkUIManager.
690 _gtk_action_sync_menu_visible (GtkAction *action,
694 gboolean visible = TRUE;
695 gboolean hide_if_empty = TRUE;
697 g_return_if_fail (GTK_IS_MENU_ITEM (proxy));
698 g_return_if_fail (action == NULL || GTK_IS_ACTION (action));
701 action = gtk_activatable_get_related_action (GTK_ACTIVATABLE (proxy));
705 /* a GtkMenu for a <popup/> doesn't have to have an action */
706 visible = gtk_action_is_visible (action);
707 hide_if_empty = action->private_data->hide_if_empty;
710 if (visible && !(empty && hide_if_empty))
711 gtk_widget_show (proxy);
713 gtk_widget_hide (proxy);
717 _gtk_action_emit_activate (GtkAction *action)
719 GtkActionGroup *group = action->private_data->action_group;
723 g_object_ref (group);
724 _gtk_action_group_emit_pre_activate (group, action);
727 g_signal_emit (action, action_signals[ACTIVATE], 0);
731 _gtk_action_group_emit_post_activate (group, action);
732 g_object_unref (group);
737 * gtk_action_activate:
738 * @action: the action object
740 * Emits the "activate" signal on the specified action, if it isn't
741 * insensitive. This gets called by the proxy widgets when they get
744 * It can also be used to manually activate an action.
749 gtk_action_activate (GtkAction *action)
751 g_return_if_fail (GTK_IS_ACTION (action));
753 if (action->private_data->activate_blocked)
756 if (gtk_action_is_sensitive (action))
757 _gtk_action_emit_activate (action);
761 * gtk_action_block_activate:
762 * @action: a #GtkAction
764 * Disable activation signals from the action
766 * This is needed when updating the state of your proxy
767 * #GtkActivatable widget could result in calling gtk_action_activate(),
768 * this is a convenience function to avoid recursing in those
769 * cases (updating toggle state for instance).
774 gtk_action_block_activate (GtkAction *action)
776 g_return_if_fail (GTK_IS_ACTION (action));
778 action->private_data->activate_blocked = TRUE;
782 * gtk_action_unblock_activate:
783 * @action: a #GtkAction
785 * Reenable activation signals from the action
790 gtk_action_unblock_activate (GtkAction *action)
792 g_return_if_fail (GTK_IS_ACTION (action));
794 action->private_data->activate_blocked = FALSE;
798 * gtk_action_create_icon:
799 * @action: the action object
800 * @icon_size: the size of the icon that should be created.
802 * This function is intended for use by action implementations to
803 * create icons displayed in the proxy widgets.
805 * Returns: a widget that displays the icon for this action.
810 gtk_action_create_icon (GtkAction *action, GtkIconSize icon_size)
812 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
814 if (action->private_data->stock_id &&
815 gtk_icon_factory_lookup_default (action->private_data->stock_id))
816 return gtk_image_new_from_stock (action->private_data->stock_id, icon_size);
817 else if (action->private_data->gicon)
818 return gtk_image_new_from_gicon (action->private_data->gicon, icon_size);
819 else if (action->private_data->icon_name)
820 return gtk_image_new_from_icon_name (action->private_data->icon_name, icon_size);
826 * gtk_action_create_menu_item:
827 * @action: the action object
829 * Creates a menu item widget that proxies for the given action.
831 * Returns: a menu item connected to the action.
836 gtk_action_create_menu_item (GtkAction *action)
838 GtkWidget *menu_item;
840 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
842 menu_item = GTK_ACTION_GET_CLASS (action)->create_menu_item (action);
844 gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (menu_item), TRUE);
845 gtk_activatable_set_related_action (GTK_ACTIVATABLE (menu_item), action);
851 * gtk_action_create_tool_item:
852 * @action: the action object
854 * Creates a toolbar item widget that proxies for the given action.
856 * Returns: a toolbar item connected to the action.
861 gtk_action_create_tool_item (GtkAction *action)
865 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
867 button = GTK_ACTION_GET_CLASS (action)->create_tool_item (action);
869 gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (button), TRUE);
870 gtk_activatable_set_related_action (GTK_ACTIVATABLE (button), action);
876 _gtk_action_add_to_proxy_list (GtkAction *action,
879 g_return_if_fail (GTK_IS_ACTION (action));
880 g_return_if_fail (GTK_IS_WIDGET (proxy));
882 GTK_ACTION_GET_CLASS (action)->connect_proxy (action, proxy);
886 _gtk_action_remove_from_proxy_list (GtkAction *action,
889 g_return_if_fail (GTK_IS_ACTION (action));
890 g_return_if_fail (GTK_IS_WIDGET (proxy));
892 GTK_ACTION_GET_CLASS (action)->disconnect_proxy (action, proxy);
896 * gtk_action_connect_proxy:
897 * @action: the action object
898 * @proxy: the proxy widget
900 * Connects a widget to an action object as a proxy. Synchronises
901 * various properties of the action with the widget (such as label
902 * text, icon, tooltip, etc), and attaches a callback so that the
903 * action gets activated when the proxy widget does.
905 * If the widget is already connected to an action, it is disconnected
910 * Deprecated: 2.16: Use gtk_activatable_set_related_action() instead.
913 gtk_action_connect_proxy (GtkAction *action,
916 g_return_if_fail (GTK_IS_ACTION (action));
917 g_return_if_fail (GTK_IS_WIDGET (proxy));
918 g_return_if_fail (GTK_IS_ACTIVATABLE (proxy));
920 gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (proxy), TRUE);
922 gtk_activatable_set_related_action (GTK_ACTIVATABLE (proxy), action);
926 * gtk_action_disconnect_proxy:
927 * @action: the action object
928 * @proxy: the proxy widget
930 * Disconnects a proxy widget from an action.
931 * Does <emphasis>not</emphasis> destroy the widget, however.
935 * Deprecated: 2.16: Use gtk_activatable_set_related_action() instead.
938 gtk_action_disconnect_proxy (GtkAction *action,
941 g_return_if_fail (GTK_IS_ACTION (action));
942 g_return_if_fail (GTK_IS_WIDGET (proxy));
944 gtk_activatable_set_related_action (GTK_ACTIVATABLE (proxy), NULL);
948 * gtk_action_get_proxies:
949 * @action: the action object
951 * Returns the proxy widgets for an action.
952 * See also gtk_widget_get_action().
954 * Return value: a #GSList of proxy widgets. The list is owned by GTK+
955 * and must not be modified.
960 gtk_action_get_proxies (GtkAction *action)
962 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
964 return action->private_data->proxies;
969 * gtk_widget_get_action:
970 * @widget: a #GtkWidget
972 * Returns the #GtkAction that @widget is a proxy for.
973 * See also gtk_action_get_proxies().
975 * Returns: the action that a widget is a proxy for, or
976 * %NULL, if it is not attached to an action.
980 * Deprecated: 2.16: Use gtk_activatable_get_related_action() instead.
983 gtk_widget_get_action (GtkWidget *widget)
985 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
987 if (GTK_IS_ACTIVATABLE (widget))
988 return gtk_activatable_get_related_action (GTK_ACTIVATABLE (widget));
994 * gtk_action_get_name:
995 * @action: the action object
997 * Returns the name of the action.
999 * Return value: the name of the action. The string belongs to GTK+ and should not
1004 G_CONST_RETURN gchar *
1005 gtk_action_get_name (GtkAction *action)
1007 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1009 return action->private_data->name;
1013 * gtk_action_is_sensitive:
1014 * @action: the action object
1016 * Returns whether the action is effectively sensitive.
1018 * Return value: %TRUE if the action and its associated action group
1019 * are both sensitive.
1024 gtk_action_is_sensitive (GtkAction *action)
1026 GtkActionPrivate *priv;
1027 g_return_val_if_fail (GTK_IS_ACTION (action), FALSE);
1029 priv = action->private_data;
1030 return priv->sensitive &&
1031 (priv->action_group == NULL ||
1032 gtk_action_group_get_sensitive (priv->action_group));
1036 * gtk_action_get_sensitive:
1037 * @action: the action object
1039 * Returns whether the action itself is sensitive. Note that this doesn't
1040 * necessarily mean effective sensitivity. See gtk_action_is_sensitive()
1043 * Return value: %TRUE if the action itself is sensitive.
1048 gtk_action_get_sensitive (GtkAction *action)
1050 g_return_val_if_fail (GTK_IS_ACTION (action), FALSE);
1052 return action->private_data->sensitive;
1056 * gtk_action_set_sensitive:
1057 * @action: the action object
1058 * @sensitive: %TRUE to make the action sensitive
1060 * Sets the ::sensitive property of the action to @sensitive. Note that
1061 * this doesn't necessarily mean effective sensitivity. See
1062 * gtk_action_is_sensitive()
1068 gtk_action_set_sensitive (GtkAction *action,
1071 g_return_if_fail (GTK_IS_ACTION (action));
1073 sensitive = sensitive != FALSE;
1075 if (action->private_data->sensitive != sensitive)
1077 action->private_data->sensitive = sensitive;
1079 g_object_notify (G_OBJECT (action), "sensitive");
1084 * gtk_action_is_visible:
1085 * @action: the action object
1087 * Returns whether the action is effectively visible.
1089 * Return value: %TRUE if the action and its associated action group
1095 gtk_action_is_visible (GtkAction *action)
1097 GtkActionPrivate *priv;
1098 g_return_val_if_fail (GTK_IS_ACTION (action), FALSE);
1100 priv = action->private_data;
1101 return priv->visible &&
1102 (priv->action_group == NULL ||
1103 gtk_action_group_get_visible (priv->action_group));
1107 * gtk_action_get_visible:
1108 * @action: the action object
1110 * Returns whether the action itself is visible. Note that this doesn't
1111 * necessarily mean effective visibility. See gtk_action_is_sensitive()
1114 * Return value: %TRUE if the action itself is visible.
1119 gtk_action_get_visible (GtkAction *action)
1121 g_return_val_if_fail (GTK_IS_ACTION (action), FALSE);
1123 return action->private_data->visible;
1127 * gtk_action_set_visible:
1128 * @action: the action object
1129 * @visible: %TRUE to make the action visible
1131 * Sets the ::visible property of the action to @visible. Note that
1132 * this doesn't necessarily mean effective visibility. See
1133 * gtk_action_is_visible()
1139 gtk_action_set_visible (GtkAction *action,
1142 g_return_if_fail (GTK_IS_ACTION (action));
1144 visible = visible != FALSE;
1146 if (action->private_data->visible != visible)
1148 action->private_data->visible = visible;
1150 g_object_notify (G_OBJECT (action), "visible");
1154 * gtk_action_set_is_important:
1155 * @action: the action object
1156 * @is_important: %TRUE to make the action important
1158 * Sets whether the action is important, this attribute is used
1159 * primarily by toolbar items to decide whether to show a label
1165 gtk_action_set_is_important (GtkAction *action,
1166 gboolean is_important)
1168 g_return_if_fail (GTK_IS_ACTION (action));
1170 g_return_if_fail (GTK_IS_ACTION (action));
1172 is_important = is_important != FALSE;
1174 if (action->private_data->is_important != is_important)
1176 action->private_data->is_important = is_important;
1178 g_object_notify (G_OBJECT (action), "is-important");
1183 * gtk_action_get_is_important:
1184 * @action: a #GtkAction
1186 * Checks whether @action is important or not
1188 * Returns: whether @action is important
1193 gtk_action_get_is_important (GtkAction *action)
1195 g_return_val_if_fail (GTK_IS_ACTION (action), FALSE);
1197 return action->private_data->is_important;
1201 * gtk_action_set_label:
1202 * @action: a #GtkAction
1203 * @label: the label text to set
1205 * Sets the label of @action.
1210 gtk_action_set_label (GtkAction *action,
1215 g_return_if_fail (GTK_IS_ACTION (action));
1217 tmp = action->private_data->label;
1218 action->private_data->label = g_strdup (label);
1220 action->private_data->label_set = (action->private_data->label != NULL);
1221 /* if label is unset, then use the label from the stock item */
1222 if (!action->private_data->label_set && action->private_data->stock_id)
1224 GtkStockItem stock_item;
1226 if (gtk_stock_lookup (action->private_data->stock_id, &stock_item))
1227 action->private_data->label = g_strdup (stock_item.label);
1230 g_object_notify (G_OBJECT (action), "label");
1232 /* if short_label is unset, set short_label=label */
1233 if (!action->private_data->short_label_set)
1235 gtk_action_set_short_label (action, action->private_data->label);
1236 action->private_data->short_label_set = FALSE;
1241 * gtk_action_get_label:
1242 * @action: a #GtkAction
1244 * Gets the label text of @action.
1246 * Returns: the label text
1250 G_CONST_RETURN gchar *
1251 gtk_action_get_label (GtkAction *action)
1253 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1255 return action->private_data->label;
1259 * gtk_action_set_short_label:
1260 * @action: a #GtkAction
1261 * @short_label: the label text to set
1263 * Sets a shorter label text on @action.
1268 gtk_action_set_short_label (GtkAction *action,
1269 const gchar *short_label)
1273 g_return_if_fail (GTK_IS_ACTION (action));
1275 tmp = action->private_data->short_label;
1276 action->private_data->short_label = g_strdup (short_label);
1278 action->private_data->short_label_set = (action->private_data->short_label != NULL);
1279 /* if short_label is unset, then use the value of label */
1280 if (!action->private_data->short_label_set)
1281 action->private_data->short_label = g_strdup (action->private_data->label);
1283 g_object_notify (G_OBJECT (action), "short-label");
1287 * gtk_action_get_short_label:
1288 * @action: a #GtkAction
1289 * @label: the label text to set
1291 * Gets the short label text of @action.
1293 * Returns: the short label text.
1297 G_CONST_RETURN gchar *
1298 gtk_action_get_short_label (GtkAction *action)
1300 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1302 return action->private_data->short_label;
1306 * gtk_action_set_visible_horizontal:
1307 * @action: a #GtkAction
1308 * @visible_horizontal: whether the action is visible horizontally
1310 * Sets whether @action is visible when horizontal
1315 gtk_action_set_visible_horizontal (GtkAction *action,
1316 gboolean visible_horizontal)
1318 g_return_if_fail (GTK_IS_ACTION (action));
1320 g_return_if_fail (GTK_IS_ACTION (action));
1322 visible_horizontal = visible_horizontal != FALSE;
1324 if (action->private_data->visible_horizontal != visible_horizontal)
1326 action->private_data->visible_horizontal = visible_horizontal;
1328 g_object_notify (G_OBJECT (action), "visible-horizontal");
1333 * gtk_action_get_visible_horizontal:
1334 * @action: a #GtkAction
1336 * Checks whether @action is visible when horizontal
1338 * Returns: whether @action is visible when horizontal
1343 gtk_action_get_visible_horizontal (GtkAction *action)
1345 g_return_val_if_fail (GTK_IS_ACTION (action), FALSE);
1347 return action->private_data->visible_horizontal;
1351 * gtk_action_set_visible_vertical:
1352 * @action: a #GtkAction
1353 * @visible_vertical: whether the action is visible vertically
1355 * Sets whether @action is visible when vertical
1360 gtk_action_set_visible_vertical (GtkAction *action,
1361 gboolean visible_vertical)
1363 g_return_if_fail (GTK_IS_ACTION (action));
1365 g_return_if_fail (GTK_IS_ACTION (action));
1367 visible_vertical = visible_vertical != FALSE;
1369 if (action->private_data->visible_vertical != visible_vertical)
1371 action->private_data->visible_vertical = visible_vertical;
1373 g_object_notify (G_OBJECT (action), "visible-vertical");
1378 * gtk_action_get_visible_vertical:
1379 * @action: a #GtkAction
1381 * Checks whether @action is visible when horizontal
1383 * Returns: whether @action is visible when horizontal
1388 gtk_action_get_visible_vertical (GtkAction *action)
1390 g_return_val_if_fail (GTK_IS_ACTION (action), FALSE);
1392 return action->private_data->visible_vertical;
1396 * gtk_action_set_tooltip:
1397 * @action: a #GtkAction
1398 * @tooltip: the tooltip text
1400 * Sets the tooltip text on @action
1405 gtk_action_set_tooltip (GtkAction *action,
1406 const gchar *tooltip)
1410 g_return_if_fail (GTK_IS_ACTION (action));
1412 tmp = action->private_data->tooltip;
1413 action->private_data->tooltip = g_strdup (tooltip);
1416 g_object_notify (G_OBJECT (action), "tooltip");
1420 * gtk_action_get_tooltip:
1421 * @action: a #GtkAction
1423 * Gets the tooltip text of @action.
1425 * Returns: the tooltip text
1429 G_CONST_RETURN gchar *
1430 gtk_action_get_tooltip (GtkAction *action)
1432 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1434 return action->private_data->tooltip;
1438 * gtk_action_set_stock_id:
1439 * @action: a #GtkAction
1440 * @stock_id: the stock id
1442 * Sets the stock id on @action
1447 gtk_action_set_stock_id (GtkAction *action,
1448 const gchar *stock_id)
1452 g_return_if_fail (GTK_IS_ACTION (action));
1454 g_return_if_fail (GTK_IS_ACTION (action));
1456 tmp = action->private_data->stock_id;
1457 action->private_data->stock_id = g_strdup (stock_id);
1460 g_object_notify (G_OBJECT (action), "stock-id");
1462 /* update label and short_label if appropriate */
1463 if (!action->private_data->label_set)
1465 GtkStockItem stock_item;
1467 if (action->private_data->stock_id &&
1468 gtk_stock_lookup (action->private_data->stock_id, &stock_item))
1469 gtk_action_set_label (action, stock_item.label);
1471 gtk_action_set_label (action, NULL);
1473 action->private_data->label_set = FALSE;
1478 * gtk_action_get_stock_id:
1479 * @action: a #GtkAction
1481 * Gets the stock id of @action.
1483 * Returns: the stock id
1487 G_CONST_RETURN gchar *
1488 gtk_action_get_stock_id (GtkAction *action)
1490 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1492 return action->private_data->stock_id;
1496 * gtk_action_set_icon_name:
1497 * @action: a #GtkAction
1498 * @icon_name: the icon name to set
1500 * Sets the icon name on @action
1505 gtk_action_set_icon_name (GtkAction *action,
1506 const gchar *icon_name)
1510 g_return_if_fail (GTK_IS_ACTION (action));
1512 tmp = action->private_data->icon_name;
1513 action->private_data->icon_name = g_strdup (icon_name);
1516 g_object_notify (G_OBJECT (action), "icon-name");
1520 * gtk_action_get_icon_name:
1521 * @action: a #GtkAction
1523 * Gets the icon name of @action.
1525 * Returns: the icon name
1529 G_CONST_RETURN gchar *
1530 gtk_action_get_icon_name (GtkAction *action)
1532 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1534 return action->private_data->icon_name;
1538 * gtk_action_set_gicon:
1539 * @action: a #GtkAction
1540 * @icon: the #GIcon to set
1542 * Sets the icon of @action.
1547 gtk_action_set_gicon (GtkAction *action,
1550 g_return_if_fail (GTK_IS_ACTION (action));
1552 if (action->private_data->gicon)
1553 g_object_unref (action->private_data->gicon);
1555 action->private_data->gicon = icon;
1557 if (action->private_data->gicon)
1558 g_object_ref (action->private_data->gicon);
1560 g_object_notify (G_OBJECT (action), "gicon");
1564 * gtk_action_get_gicon:
1565 * @action: a #GtkAction
1567 * Gets the gicon of @action.
1569 * Returns: The action's #GIcon if one is set.
1574 gtk_action_get_gicon (GtkAction *action)
1576 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1578 return action->private_data->gicon;
1582 * gtk_action_block_activate_from:
1583 * @action: the action object
1584 * @proxy: a proxy widget
1586 * Disables calls to the gtk_action_activate()
1587 * function by signals on the given proxy widget. This is used to
1588 * break notification loops for things like check or radio actions.
1590 * This function is intended for use by action implementations.
1594 * Deprecated: 2.16: activatables are now responsible for activating the
1595 * action directly so this doesnt apply anymore.
1598 gtk_action_block_activate_from (GtkAction *action,
1601 g_return_if_fail (GTK_IS_ACTION (action));
1603 g_signal_handlers_block_by_func (proxy, G_CALLBACK (gtk_action_activate),
1606 gtk_action_block_activate (action);
1610 * gtk_action_unblock_activate_from:
1611 * @action: the action object
1612 * @proxy: a proxy widget
1614 * Re-enables calls to the gtk_action_activate()
1615 * function by signals on the given proxy widget. This undoes the
1616 * blocking done by gtk_action_block_activate_from().
1618 * This function is intended for use by action implementations.
1622 * Deprecated: 2.16: activatables are now responsible for activating the
1623 * action directly so this doesnt apply anymore.
1626 gtk_action_unblock_activate_from (GtkAction *action,
1629 g_return_if_fail (GTK_IS_ACTION (action));
1631 g_signal_handlers_unblock_by_func (proxy, G_CALLBACK (gtk_action_activate),
1634 gtk_action_unblock_activate (action);
1638 closure_accel_activate (GClosure *closure,
1639 GValue *return_value,
1640 guint n_param_values,
1641 const GValue *param_values,
1642 gpointer invocation_hint,
1643 gpointer marshal_data)
1645 if (gtk_action_is_sensitive (GTK_ACTION (closure->data)))
1647 _gtk_action_emit_activate (GTK_ACTION (closure->data));
1649 /* we handled the accelerator */
1650 g_value_set_boolean (return_value, TRUE);
1655 gtk_action_set_action_group (GtkAction *action,
1656 GtkActionGroup *action_group)
1658 if (action->private_data->action_group == NULL)
1659 g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
1661 g_return_if_fail (action_group == NULL);
1663 action->private_data->action_group = action_group;
1667 * gtk_action_set_accel_path:
1668 * @action: the action object
1669 * @accel_path: the accelerator path
1671 * Sets the accel path for this action. All proxy widgets associated
1672 * with the action will have this accel path, so that their
1673 * accelerators are consistent.
1675 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
1676 * pass a static string, you can save some memory by interning it first with
1677 * g_intern_static_string().
1682 gtk_action_set_accel_path (GtkAction *action,
1683 const gchar *accel_path)
1685 g_return_if_fail (GTK_IS_ACTION (action));
1687 action->private_data->accel_quark = g_quark_from_string (accel_path);
1691 * gtk_action_get_accel_path:
1692 * @action: the action object
1694 * Returns the accel path for this action.
1698 * Returns: the accel path for this action, or %NULL
1699 * if none is set. The returned string is owned by GTK+
1700 * and must not be freed or modified.
1702 G_CONST_RETURN gchar *
1703 gtk_action_get_accel_path (GtkAction *action)
1705 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1707 if (action->private_data->accel_quark)
1708 return g_quark_to_string (action->private_data->accel_quark);
1714 * gtk_action_get_accel_closure:
1715 * @action: the action object
1717 * Returns the accel closure for this action.
1721 * Returns: the accel closure for this action. The returned closure is
1722 * owned by GTK+ and must not be unreffed or modified.
1725 gtk_action_get_accel_closure (GtkAction *action)
1727 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1729 return action->private_data->accel_closure;
1734 * gtk_action_set_accel_group:
1735 * @action: the action object
1736 * @accel_group: a #GtkAccelGroup or %NULL
1738 * Sets the #GtkAccelGroup in which the accelerator for this action
1739 * will be installed.
1744 gtk_action_set_accel_group (GtkAction *action,
1745 GtkAccelGroup *accel_group)
1747 g_return_if_fail (GTK_IS_ACTION (action));
1748 g_return_if_fail (accel_group == NULL || GTK_IS_ACCEL_GROUP (accel_group));
1751 g_object_ref (accel_group);
1752 if (action->private_data->accel_group)
1753 g_object_unref (action->private_data->accel_group);
1755 action->private_data->accel_group = accel_group;
1759 * gtk_action_connect_accelerator:
1760 * @action: a #GtkAction
1762 * Installs the accelerator for @action if @action has an
1763 * accel path and group. See gtk_action_set_accel_path() and
1764 * gtk_action_set_accel_group()
1766 * Since multiple proxies may independently trigger the installation
1767 * of the accelerator, the @action counts the number of times this
1768 * function has been called and doesn't remove the accelerator until
1769 * gtk_action_disconnect_accelerator() has been called as many times.
1774 gtk_action_connect_accelerator (GtkAction *action)
1776 g_return_if_fail (GTK_IS_ACTION (action));
1778 if (!action->private_data->accel_quark ||
1779 !action->private_data->accel_group)
1782 if (action->private_data->accel_count == 0)
1784 const gchar *accel_path =
1785 g_quark_to_string (action->private_data->accel_quark);
1787 gtk_accel_group_connect_by_path (action->private_data->accel_group,
1789 action->private_data->accel_closure);
1792 action->private_data->accel_count++;
1796 * gtk_action_disconnect_accelerator:
1797 * @action: a #GtkAction
1799 * Undoes the effect of one call to gtk_action_connect_accelerator().
1804 gtk_action_disconnect_accelerator (GtkAction *action)
1806 g_return_if_fail (GTK_IS_ACTION (action));
1808 if (!action->private_data->accel_quark ||
1809 !action->private_data->accel_group)
1812 action->private_data->accel_count--;
1814 if (action->private_data->accel_count == 0)
1815 gtk_accel_group_disconnect (action->private_data->accel_group,
1816 action->private_data->accel_closure);
1820 * gtk_action_create_menu:
1821 * @action: a #GtkAction
1823 * If @action provides a #GtkMenu widget as a submenu for the menu
1824 * item or the toolbar item it creates, this function returns an
1825 * instance of that menu.
1827 * Return value: the menu item provided by the action, or %NULL.
1832 gtk_action_create_menu (GtkAction *action)
1834 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1836 if (GTK_ACTION_GET_CLASS (action)->create_menu)
1837 return GTK_ACTION_GET_CLASS (action)->create_menu (action);
1842 #define __GTK_ACTION_C__
1843 #include "gtkaliasdef.c"