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 * @Short_description: An action which can be triggered by a menu or toolbar item
35 * @See_also: #GtkActionGroup, #GtkUIManager
37 * Actions represent operations that the user can be perform, along with
38 * some information how it should be presented in the interface. Each action
39 * provides methods to create icons, menu items and toolbar items
40 * representing itself.
42 * As well as the callback that is called when the action gets activated,
43 * the following also gets associated with the action:
45 * <listitem><para>a name (not translated, for path lookup)</para></listitem>
46 * <listitem><para>a label (translated, for display)</para></listitem>
47 * <listitem><para>an accelerator</para></listitem>
48 * <listitem><para>whether label indicates a stock id</para></listitem>
49 * <listitem><para>a tooltip (optional, translated)</para></listitem>
50 * <listitem><para>a toolbar label (optional, shorter than label)</para></listitem>
52 * The action will also have some state information:
54 * <listitem><para>visible (shown/hidden)</para></listitem>
55 * <listitem><para>sensitive (enabled/disabled)</para></listitem>
57 * Apart from regular actions, there are <link linkend="GtkToggleAction">toggle
58 * actions</link>, which can be toggled between two states and <link
59 * linkend="GtkRadioAction">radio actions</link>, of which only one in a group
60 * can be in the "active" state. Other actions can be implemented as #GtkAction
63 * Each action can have one or more proxy menu item, toolbar button or
64 * other proxy widgets. Proxies mirror the state of the action (text
65 * label, tooltip, icon, visible, sensitive, etc), and should change when
66 * the action's state changes. When the proxy is activated, it should
67 * activate its action.
72 #include "gtkaction.h"
73 #include "gtkactiongroup.h"
74 #include "gtkaccellabel.h"
75 #include "gtkbutton.h"
76 #include "gtkiconfactory.h"
78 #include "gtkimagemenuitem.h"
81 #include "gtkmarshalers.h"
82 #include "gtkmenuitem.h"
84 #include "gtktearoffmenuitem.h"
85 #include "gtktoolbutton.h"
86 #include "gtktoolbar.h"
87 #include "gtkprivate.h"
88 #include "gtkbuildable.h"
89 #include "gtkactivatable.h"
93 #define GTK_ACTION_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ACTION, GtkActionPrivate))
95 struct _GtkActionPrivate
97 const gchar *name; /* interned */
101 gchar *stock_id; /* stock icon */
102 gchar *icon_name; /* themed icon */
107 guint label_set : 1; /* these two used so we can set label */
108 guint short_label_set : 1; /* based on stock id */
109 guint visible_horizontal : 1;
110 guint visible_vertical : 1;
111 guint is_important : 1;
112 guint hide_if_empty : 1;
113 guint visible_overflown : 1;
114 guint always_show_image : 1;
115 guint recursion_guard : 1;
116 guint activate_blocked : 1;
120 GtkAccelGroup *accel_group;
121 GClosure *accel_closure;
124 GtkActionGroup *action_group;
126 /* list of proxy widgets */
146 PROP_VISIBLE_HORIZONTAL,
147 PROP_VISIBLE_VERTICAL,
148 PROP_VISIBLE_OVERFLOWN,
154 PROP_ALWAYS_SHOW_IMAGE
158 static void gtk_action_buildable_init (GtkBuildableIface *iface);
159 static void gtk_action_buildable_set_name (GtkBuildable *buildable,
161 static const gchar* gtk_action_buildable_get_name (GtkBuildable *buildable);
163 G_DEFINE_TYPE_WITH_CODE (GtkAction, gtk_action, G_TYPE_OBJECT,
164 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
165 gtk_action_buildable_init))
167 static void gtk_action_finalize (GObject *object);
168 static void gtk_action_set_property (GObject *object,
172 static void gtk_action_get_property (GObject *object,
176 static void gtk_action_set_action_group (GtkAction *action,
177 GtkActionGroup *action_group);
179 static GtkWidget *create_menu_item (GtkAction *action);
180 static GtkWidget *create_tool_item (GtkAction *action);
181 static void connect_proxy (GtkAction *action,
183 static void disconnect_proxy (GtkAction *action,
186 static void closure_accel_activate (GClosure *closure,
187 GValue *return_value,
188 guint n_param_values,
189 const GValue *param_values,
190 gpointer invocation_hint,
191 gpointer marshal_data);
193 static guint action_signals[LAST_SIGNAL] = { 0 };
197 gtk_action_class_init (GtkActionClass *klass)
199 GObjectClass *gobject_class;
201 gobject_class = G_OBJECT_CLASS (klass);
203 gobject_class->finalize = gtk_action_finalize;
204 gobject_class->set_property = gtk_action_set_property;
205 gobject_class->get_property = gtk_action_get_property;
207 klass->activate = NULL;
209 klass->create_menu_item = create_menu_item;
210 klass->create_tool_item = create_tool_item;
211 klass->create_menu = NULL;
212 klass->menu_item_type = GTK_TYPE_IMAGE_MENU_ITEM;
213 klass->toolbar_item_type = GTK_TYPE_TOOL_BUTTON;
214 klass->connect_proxy = connect_proxy;
215 klass->disconnect_proxy = disconnect_proxy;
217 g_object_class_install_property (gobject_class,
219 g_param_spec_string ("name",
221 P_("A unique name for the action."),
223 GTK_PARAM_READWRITE |
224 G_PARAM_CONSTRUCT_ONLY));
229 * The label used for menu items and buttons that activate
230 * this action. If the label is %NULL, GTK+ uses the stock
231 * label specified via the stock-id property.
233 * This is an appearance property and thus only applies if
234 * #GtkActivatable:use-action-appearance is %TRUE.
236 g_object_class_install_property (gobject_class,
238 g_param_spec_string ("label",
240 P_("The label used for menu items and buttons "
241 "that activate this action."),
243 GTK_PARAM_READWRITE));
246 * GtkAction:short-label:
248 * A shorter label that may be used on toolbar buttons.
250 * This is an appearance property and thus only applies if
251 * #GtkActivatable:use-action-appearance is %TRUE.
253 g_object_class_install_property (gobject_class,
255 g_param_spec_string ("short-label",
257 P_("A shorter label that may be used on toolbar buttons."),
259 GTK_PARAM_READWRITE));
262 g_object_class_install_property (gobject_class,
264 g_param_spec_string ("tooltip",
266 P_("A tooltip for this action."),
268 GTK_PARAM_READWRITE));
271 * GtkAction:stock-id:
273 * The stock icon displayed in widgets representing this action.
275 * This is an appearance property and thus only applies if
276 * #GtkActivatable:use-action-appearance is %TRUE.
278 g_object_class_install_property (gobject_class,
280 g_param_spec_string ("stock-id",
282 P_("The stock icon displayed in widgets representing "
285 GTK_PARAM_READWRITE));
289 * The #GIcon displayed in the #GtkAction.
291 * Note that the stock icon is preferred, if the #GtkAction:stock-id
292 * property holds the id of an existing stock icon.
294 * This is an appearance property and thus only applies if
295 * #GtkActivatable:use-action-appearance is %TRUE.
299 g_object_class_install_property (gobject_class,
301 g_param_spec_object ("gicon",
303 P_("The GIcon being displayed"),
305 GTK_PARAM_READWRITE));
307 * GtkAction:icon-name:
309 * The name of the icon from the icon theme.
311 * Note that the stock icon is preferred, if the #GtkAction:stock-id
312 * property holds the id of an existing stock icon, and the #GIcon is
313 * preferred if the #GtkAction:gicon property is set.
315 * This is an appearance property and thus only applies if
316 * #GtkActivatable:use-action-appearance is %TRUE.
320 g_object_class_install_property (gobject_class,
322 g_param_spec_string ("icon-name",
324 P_("The name of the icon from the icon theme"),
326 GTK_PARAM_READWRITE));
328 g_object_class_install_property (gobject_class,
329 PROP_VISIBLE_HORIZONTAL,
330 g_param_spec_boolean ("visible-horizontal",
331 P_("Visible when horizontal"),
332 P_("Whether the toolbar item is visible when the toolbar "
333 "is in a horizontal orientation."),
335 GTK_PARAM_READWRITE));
337 * GtkAction:visible-overflown:
339 * When %TRUE, toolitem proxies for this action are represented in the
340 * toolbar overflow menu.
344 g_object_class_install_property (gobject_class,
345 PROP_VISIBLE_OVERFLOWN,
346 g_param_spec_boolean ("visible-overflown",
347 P_("Visible when overflown"),
348 P_("When TRUE, toolitem proxies for this action "
349 "are represented in the toolbar overflow menu."),
351 GTK_PARAM_READWRITE));
352 g_object_class_install_property (gobject_class,
353 PROP_VISIBLE_VERTICAL,
354 g_param_spec_boolean ("visible-vertical",
355 P_("Visible when vertical"),
356 P_("Whether the toolbar item is visible when the toolbar "
357 "is in a vertical orientation."),
359 GTK_PARAM_READWRITE));
360 g_object_class_install_property (gobject_class,
362 g_param_spec_boolean ("is-important",
364 P_("Whether the action is considered important. "
365 "When TRUE, toolitem proxies for this action "
366 "show text in GTK_TOOLBAR_BOTH_HORIZ mode."),
368 GTK_PARAM_READWRITE));
369 g_object_class_install_property (gobject_class,
371 g_param_spec_boolean ("hide-if-empty",
373 P_("When TRUE, empty menu proxies for this action are hidden."),
375 GTK_PARAM_READWRITE));
376 g_object_class_install_property (gobject_class,
378 g_param_spec_boolean ("sensitive",
380 P_("Whether the action is enabled."),
382 GTK_PARAM_READWRITE));
383 g_object_class_install_property (gobject_class,
385 g_param_spec_boolean ("visible",
387 P_("Whether the action is visible."),
389 GTK_PARAM_READWRITE));
390 g_object_class_install_property (gobject_class,
392 g_param_spec_object ("action-group",
394 P_("The GtkActionGroup this GtkAction is associated with, or NULL (for internal use)."),
395 GTK_TYPE_ACTION_GROUP,
396 GTK_PARAM_READWRITE));
399 * GtkAction:always-show-image:
401 * If %TRUE, the action's menu item proxies will ignore the #GtkSettings:gtk-menu-images
402 * setting and always show their image, if available.
404 * Use this property if the menu item would be useless or hard to use
405 * without their image.
409 g_object_class_install_property (gobject_class,
410 PROP_ALWAYS_SHOW_IMAGE,
411 g_param_spec_boolean ("always-show-image",
412 P_("Always show image"),
413 P_("Whether the image will always be shown"),
415 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
418 * GtkAction::activate:
419 * @action: the #GtkAction
421 * The "activate" signal is emitted when the action is activated.
425 action_signals[ACTIVATE] =
426 g_signal_new (I_("activate"),
427 G_OBJECT_CLASS_TYPE (klass),
428 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
429 G_STRUCT_OFFSET (GtkActionClass, activate), NULL, NULL,
430 g_cclosure_marshal_VOID__VOID,
433 g_type_class_add_private (gobject_class, sizeof (GtkActionPrivate));
438 gtk_action_init (GtkAction *action)
440 action->private_data = GTK_ACTION_GET_PRIVATE (action);
442 action->private_data->name = NULL;
443 action->private_data->label = NULL;
444 action->private_data->short_label = NULL;
445 action->private_data->tooltip = NULL;
446 action->private_data->stock_id = NULL;
447 action->private_data->icon_name = NULL;
448 action->private_data->visible_horizontal = TRUE;
449 action->private_data->visible_vertical = TRUE;
450 action->private_data->visible_overflown = TRUE;
451 action->private_data->is_important = FALSE;
452 action->private_data->hide_if_empty = TRUE;
453 action->private_data->always_show_image = FALSE;
454 action->private_data->activate_blocked = FALSE;
456 action->private_data->sensitive = TRUE;
457 action->private_data->visible = TRUE;
459 action->private_data->label_set = FALSE;
460 action->private_data->short_label_set = FALSE;
462 action->private_data->accel_count = 0;
463 action->private_data->accel_group = NULL;
464 action->private_data->accel_quark = 0;
465 action->private_data->accel_closure =
466 g_closure_new_object (sizeof (GClosure), G_OBJECT (action));
467 g_closure_set_marshal (action->private_data->accel_closure,
468 closure_accel_activate);
469 g_closure_ref (action->private_data->accel_closure);
470 g_closure_sink (action->private_data->accel_closure);
472 action->private_data->action_group = NULL;
474 action->private_data->proxies = NULL;
475 action->private_data->gicon = NULL;
479 gtk_action_buildable_init (GtkBuildableIface *iface)
481 iface->set_name = gtk_action_buildable_set_name;
482 iface->get_name = gtk_action_buildable_get_name;
486 gtk_action_buildable_set_name (GtkBuildable *buildable,
489 GtkAction *action = GTK_ACTION (buildable);
491 action->private_data->name = g_intern_string (name);
495 gtk_action_buildable_get_name (GtkBuildable *buildable)
497 GtkAction *action = GTK_ACTION (buildable);
499 return action->private_data->name;
504 * @name: A unique name for the action
505 * @label: (allow-none): the label displayed in menu items and on buttons, or %NULL
506 * @tooltip: (allow-none): a tooltip for the action, or %NULL
507 * @stock_id: the stock icon to display in widgets representing the
510 * Creates a new #GtkAction object. To add the action to a
511 * #GtkActionGroup and set the accelerator for the action,
512 * call gtk_action_group_add_action_with_accel().
513 * See <xref linkend="XML-UI"/> for information on allowed action
516 * Return value: a new #GtkAction
521 gtk_action_new (const gchar *name,
523 const gchar *tooltip,
524 const gchar *stock_id)
526 g_return_val_if_fail (name != NULL, NULL);
528 return g_object_new (GTK_TYPE_ACTION,
532 "stock-id", stock_id,
537 gtk_action_finalize (GObject *object)
540 action = GTK_ACTION (object);
542 g_free (action->private_data->label);
543 g_free (action->private_data->short_label);
544 g_free (action->private_data->tooltip);
545 g_free (action->private_data->stock_id);
546 g_free (action->private_data->icon_name);
548 if (action->private_data->gicon)
549 g_object_unref (action->private_data->gicon);
551 g_closure_unref (action->private_data->accel_closure);
552 if (action->private_data->accel_group)
553 g_object_unref (action->private_data->accel_group);
555 G_OBJECT_CLASS (gtk_action_parent_class)->finalize (object);
559 gtk_action_set_property (GObject *object,
566 action = GTK_ACTION (object);
571 action->private_data->name = g_intern_string (g_value_get_string (value));
574 gtk_action_set_label (action, g_value_get_string (value));
576 case PROP_SHORT_LABEL:
577 gtk_action_set_short_label (action, g_value_get_string (value));
580 gtk_action_set_tooltip (action, g_value_get_string (value));
583 gtk_action_set_stock_id (action, g_value_get_string (value));
586 gtk_action_set_gicon (action, g_value_get_object (value));
589 gtk_action_set_icon_name (action, g_value_get_string (value));
591 case PROP_VISIBLE_HORIZONTAL:
592 gtk_action_set_visible_horizontal (action, g_value_get_boolean (value));
594 case PROP_VISIBLE_VERTICAL:
595 gtk_action_set_visible_vertical (action, g_value_get_boolean (value));
597 case PROP_VISIBLE_OVERFLOWN:
598 action->private_data->visible_overflown = g_value_get_boolean (value);
600 case PROP_IS_IMPORTANT:
601 gtk_action_set_is_important (action, g_value_get_boolean (value));
603 case PROP_HIDE_IF_EMPTY:
604 action->private_data->hide_if_empty = g_value_get_boolean (value);
607 gtk_action_set_sensitive (action, g_value_get_boolean (value));
610 gtk_action_set_visible (action, g_value_get_boolean (value));
612 case PROP_ACTION_GROUP:
613 gtk_action_set_action_group (action, g_value_get_object (value));
615 case PROP_ALWAYS_SHOW_IMAGE:
616 gtk_action_set_always_show_image (action, g_value_get_boolean (value));
619 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
625 gtk_action_get_property (GObject *object,
632 action = GTK_ACTION (object);
637 g_value_set_static_string (value, action->private_data->name);
640 g_value_set_string (value, action->private_data->label);
642 case PROP_SHORT_LABEL:
643 g_value_set_string (value, action->private_data->short_label);
646 g_value_set_string (value, action->private_data->tooltip);
649 g_value_set_string (value, action->private_data->stock_id);
652 g_value_set_string (value, action->private_data->icon_name);
655 g_value_set_object (value, action->private_data->gicon);
657 case PROP_VISIBLE_HORIZONTAL:
658 g_value_set_boolean (value, action->private_data->visible_horizontal);
660 case PROP_VISIBLE_VERTICAL:
661 g_value_set_boolean (value, action->private_data->visible_vertical);
663 case PROP_VISIBLE_OVERFLOWN:
664 g_value_set_boolean (value, action->private_data->visible_overflown);
666 case PROP_IS_IMPORTANT:
667 g_value_set_boolean (value, action->private_data->is_important);
669 case PROP_HIDE_IF_EMPTY:
670 g_value_set_boolean (value, action->private_data->hide_if_empty);
673 g_value_set_boolean (value, action->private_data->sensitive);
676 g_value_set_boolean (value, action->private_data->visible);
678 case PROP_ACTION_GROUP:
679 g_value_set_object (value, action->private_data->action_group);
681 case PROP_ALWAYS_SHOW_IMAGE:
682 g_value_set_boolean (value, action->private_data->always_show_image);
685 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
691 create_menu_item (GtkAction *action)
693 GType menu_item_type;
695 menu_item_type = GTK_ACTION_GET_CLASS (action)->menu_item_type;
697 return g_object_new (menu_item_type, NULL);
701 create_tool_item (GtkAction *action)
703 GType toolbar_item_type;
705 toolbar_item_type = GTK_ACTION_GET_CLASS (action)->toolbar_item_type;
707 return g_object_new (toolbar_item_type, NULL);
711 remove_proxy (GtkAction *action,
714 action->private_data->proxies = g_slist_remove (action->private_data->proxies, proxy);
718 connect_proxy (GtkAction *action,
721 action->private_data->proxies = g_slist_prepend (action->private_data->proxies, proxy);
723 if (action->private_data->action_group)
724 _gtk_action_group_emit_connect_proxy (action->private_data->action_group, action, proxy);
729 disconnect_proxy (GtkAction *action,
732 remove_proxy (action, proxy);
734 if (action->private_data->action_group)
735 _gtk_action_group_emit_disconnect_proxy (action->private_data->action_group, action, proxy);
739 * _gtk_action_sync_menu_visible:
740 * @action: (allow-none): a #GtkAction, or %NULL to determine the action from @proxy
741 * @proxy: a proxy menu item
742 * @empty: whether the submenu attached to @proxy is empty
744 * Updates the visibility of @proxy from the visibility of @action
745 * according to the following rules:
747 * <listitem><para>if @action is invisible, @proxy is too
749 * <listitem><para>if @empty is %TRUE, hide @proxy unless the "hide-if-empty"
750 * property of @action indicates otherwise
754 * This function is used in the implementation of #GtkUIManager.
757 _gtk_action_sync_menu_visible (GtkAction *action,
761 gboolean visible = TRUE;
762 gboolean hide_if_empty = TRUE;
764 g_return_if_fail (GTK_IS_MENU_ITEM (proxy));
765 g_return_if_fail (action == NULL || GTK_IS_ACTION (action));
768 action = gtk_activatable_get_related_action (GTK_ACTIVATABLE (proxy));
772 /* a GtkMenu for a <popup/> doesn't have to have an action */
773 visible = gtk_action_is_visible (action);
774 hide_if_empty = action->private_data->hide_if_empty;
777 if (visible && !(empty && hide_if_empty))
778 gtk_widget_show (proxy);
780 gtk_widget_hide (proxy);
784 _gtk_action_emit_activate (GtkAction *action)
786 GtkActionGroup *group = action->private_data->action_group;
790 g_object_ref (group);
791 _gtk_action_group_emit_pre_activate (group, action);
794 g_signal_emit (action, action_signals[ACTIVATE], 0);
798 _gtk_action_group_emit_post_activate (group, action);
799 g_object_unref (group);
804 * gtk_action_activate:
805 * @action: the action object
807 * Emits the "activate" signal on the specified action, if it isn't
808 * insensitive. This gets called by the proxy widgets when they get
811 * It can also be used to manually activate an action.
816 gtk_action_activate (GtkAction *action)
818 g_return_if_fail (GTK_IS_ACTION (action));
820 if (action->private_data->activate_blocked)
823 if (gtk_action_is_sensitive (action))
824 _gtk_action_emit_activate (action);
828 * gtk_action_block_activate:
829 * @action: a #GtkAction
831 * Disable activation signals from the action
833 * This is needed when updating the state of your proxy
834 * #GtkActivatable widget could result in calling gtk_action_activate(),
835 * this is a convenience function to avoid recursing in those
836 * cases (updating toggle state for instance).
841 gtk_action_block_activate (GtkAction *action)
843 g_return_if_fail (GTK_IS_ACTION (action));
845 action->private_data->activate_blocked = TRUE;
849 * gtk_action_unblock_activate:
850 * @action: a #GtkAction
852 * Reenable activation signals from the action
857 gtk_action_unblock_activate (GtkAction *action)
859 g_return_if_fail (GTK_IS_ACTION (action));
861 action->private_data->activate_blocked = FALSE;
865 * gtk_action_create_icon:
866 * @action: the action object
867 * @icon_size: (type int): the size of the icon that should be created.
869 * This function is intended for use by action implementations to
870 * create icons displayed in the proxy widgets.
872 * Returns: a widget that displays the icon for this action.
877 gtk_action_create_icon (GtkAction *action, GtkIconSize icon_size)
879 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
881 if (action->private_data->stock_id &&
882 gtk_icon_factory_lookup_default (action->private_data->stock_id))
883 return gtk_image_new_from_stock (action->private_data->stock_id, icon_size);
884 else if (action->private_data->gicon)
885 return gtk_image_new_from_gicon (action->private_data->gicon, icon_size);
886 else if (action->private_data->icon_name)
887 return gtk_image_new_from_icon_name (action->private_data->icon_name, icon_size);
893 * gtk_action_create_menu_item:
894 * @action: the action object
896 * Creates a menu item widget that proxies for the given action.
898 * Returns: a menu item connected to the action.
903 gtk_action_create_menu_item (GtkAction *action)
905 GtkWidget *menu_item;
907 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
909 menu_item = GTK_ACTION_GET_CLASS (action)->create_menu_item (action);
911 gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (menu_item), TRUE);
912 gtk_activatable_set_related_action (GTK_ACTIVATABLE (menu_item), action);
918 * gtk_action_create_tool_item:
919 * @action: the action object
921 * Creates a toolbar item widget that proxies for the given action.
923 * Returns: a toolbar item connected to the action.
928 gtk_action_create_tool_item (GtkAction *action)
932 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
934 button = GTK_ACTION_GET_CLASS (action)->create_tool_item (action);
936 gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (button), TRUE);
937 gtk_activatable_set_related_action (GTK_ACTIVATABLE (button), action);
943 _gtk_action_add_to_proxy_list (GtkAction *action,
946 g_return_if_fail (GTK_IS_ACTION (action));
947 g_return_if_fail (GTK_IS_WIDGET (proxy));
949 GTK_ACTION_GET_CLASS (action)->connect_proxy (action, proxy);
953 _gtk_action_remove_from_proxy_list (GtkAction *action,
956 g_return_if_fail (GTK_IS_ACTION (action));
957 g_return_if_fail (GTK_IS_WIDGET (proxy));
959 GTK_ACTION_GET_CLASS (action)->disconnect_proxy (action, proxy);
963 * gtk_action_connect_proxy:
964 * @action: the action object
965 * @proxy: the proxy widget
967 * Connects a widget to an action object as a proxy. Synchronises
968 * various properties of the action with the widget (such as label
969 * text, icon, tooltip, etc), and attaches a callback so that the
970 * action gets activated when the proxy widget does.
972 * If the widget is already connected to an action, it is disconnected
977 * Deprecated: 2.16: Use gtk_activatable_set_related_action() instead.
980 gtk_action_connect_proxy (GtkAction *action,
983 g_return_if_fail (GTK_IS_ACTION (action));
984 g_return_if_fail (GTK_IS_WIDGET (proxy));
985 g_return_if_fail (GTK_IS_ACTIVATABLE (proxy));
987 gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (proxy), TRUE);
989 gtk_activatable_set_related_action (GTK_ACTIVATABLE (proxy), action);
993 * gtk_action_disconnect_proxy:
994 * @action: the action object
995 * @proxy: the proxy widget
997 * Disconnects a proxy widget from an action.
998 * Does <emphasis>not</emphasis> destroy the widget, however.
1002 * Deprecated: 2.16: Use gtk_activatable_set_related_action() instead.
1005 gtk_action_disconnect_proxy (GtkAction *action,
1008 g_return_if_fail (GTK_IS_ACTION (action));
1009 g_return_if_fail (GTK_IS_WIDGET (proxy));
1011 gtk_activatable_set_related_action (GTK_ACTIVATABLE (proxy), NULL);
1015 * gtk_action_get_proxies:
1016 * @action: the action object
1018 * Returns the proxy widgets for an action.
1019 * See also gtk_widget_get_action().
1021 * Return value: (element-type GtkWidget) (transfer none): a #GSList of proxy widgets. The list is owned by GTK+
1022 * and must not be modified.
1027 gtk_action_get_proxies (GtkAction *action)
1029 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1031 return action->private_data->proxies;
1036 * gtk_widget_get_action:
1037 * @widget: a #GtkWidget
1039 * Returns the #GtkAction that @widget is a proxy for.
1040 * See also gtk_action_get_proxies().
1042 * Returns: the action that a widget is a proxy for, or
1043 * %NULL, if it is not attached to an action.
1047 * Deprecated: 2.16: Use gtk_activatable_get_related_action() instead.
1050 gtk_widget_get_action (GtkWidget *widget)
1052 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1054 if (GTK_IS_ACTIVATABLE (widget))
1055 return gtk_activatable_get_related_action (GTK_ACTIVATABLE (widget));
1061 * gtk_action_get_name:
1062 * @action: the action object
1064 * Returns the name of the action.
1066 * Return value: the name of the action. The string belongs to GTK+ and should not
1071 G_CONST_RETURN gchar *
1072 gtk_action_get_name (GtkAction *action)
1074 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1076 return action->private_data->name;
1080 * gtk_action_is_sensitive:
1081 * @action: the action object
1083 * Returns whether the action is effectively sensitive.
1085 * Return value: %TRUE if the action and its associated action group
1086 * are both sensitive.
1091 gtk_action_is_sensitive (GtkAction *action)
1093 GtkActionPrivate *priv;
1094 g_return_val_if_fail (GTK_IS_ACTION (action), FALSE);
1096 priv = action->private_data;
1097 return priv->sensitive &&
1098 (priv->action_group == NULL ||
1099 gtk_action_group_get_sensitive (priv->action_group));
1103 * gtk_action_get_sensitive:
1104 * @action: the action object
1106 * Returns whether the action itself is sensitive. Note that this doesn't
1107 * necessarily mean effective sensitivity. See gtk_action_is_sensitive()
1110 * Return value: %TRUE if the action itself is sensitive.
1115 gtk_action_get_sensitive (GtkAction *action)
1117 g_return_val_if_fail (GTK_IS_ACTION (action), FALSE);
1119 return action->private_data->sensitive;
1123 * gtk_action_set_sensitive:
1124 * @action: the action object
1125 * @sensitive: %TRUE to make the action sensitive
1127 * Sets the ::sensitive property of the action to @sensitive. Note that
1128 * this doesn't necessarily mean effective sensitivity. See
1129 * gtk_action_is_sensitive()
1135 gtk_action_set_sensitive (GtkAction *action,
1138 g_return_if_fail (GTK_IS_ACTION (action));
1140 sensitive = sensitive != FALSE;
1142 if (action->private_data->sensitive != sensitive)
1144 action->private_data->sensitive = sensitive;
1146 g_object_notify (G_OBJECT (action), "sensitive");
1151 * gtk_action_is_visible:
1152 * @action: the action object
1154 * Returns whether the action is effectively visible.
1156 * Return value: %TRUE if the action and its associated action group
1162 gtk_action_is_visible (GtkAction *action)
1164 GtkActionPrivate *priv;
1165 g_return_val_if_fail (GTK_IS_ACTION (action), FALSE);
1167 priv = action->private_data;
1168 return priv->visible &&
1169 (priv->action_group == NULL ||
1170 gtk_action_group_get_visible (priv->action_group));
1174 * gtk_action_get_visible:
1175 * @action: the action object
1177 * Returns whether the action itself is visible. Note that this doesn't
1178 * necessarily mean effective visibility. See gtk_action_is_sensitive()
1181 * Return value: %TRUE if the action itself is visible.
1186 gtk_action_get_visible (GtkAction *action)
1188 g_return_val_if_fail (GTK_IS_ACTION (action), FALSE);
1190 return action->private_data->visible;
1194 * gtk_action_set_visible:
1195 * @action: the action object
1196 * @visible: %TRUE to make the action visible
1198 * Sets the ::visible property of the action to @visible. Note that
1199 * this doesn't necessarily mean effective visibility. See
1200 * gtk_action_is_visible()
1206 gtk_action_set_visible (GtkAction *action,
1209 g_return_if_fail (GTK_IS_ACTION (action));
1211 visible = visible != FALSE;
1213 if (action->private_data->visible != visible)
1215 action->private_data->visible = visible;
1217 g_object_notify (G_OBJECT (action), "visible");
1221 * gtk_action_set_is_important:
1222 * @action: the action object
1223 * @is_important: %TRUE to make the action important
1225 * Sets whether the action is important, this attribute is used
1226 * primarily by toolbar items to decide whether to show a label
1232 gtk_action_set_is_important (GtkAction *action,
1233 gboolean is_important)
1235 g_return_if_fail (GTK_IS_ACTION (action));
1237 is_important = is_important != FALSE;
1239 if (action->private_data->is_important != is_important)
1241 action->private_data->is_important = is_important;
1243 g_object_notify (G_OBJECT (action), "is-important");
1248 * gtk_action_get_is_important:
1249 * @action: a #GtkAction
1251 * Checks whether @action is important or not
1253 * Returns: whether @action is important
1258 gtk_action_get_is_important (GtkAction *action)
1260 g_return_val_if_fail (GTK_IS_ACTION (action), FALSE);
1262 return action->private_data->is_important;
1266 * gtk_action_set_always_show_image:
1267 * @action: a #GtkAction
1268 * @always_show: %TRUE if menuitem proxies should always show their image
1270 * Sets whether @action<!-- -->'s menu item proxies will ignore the
1271 * #GtkSettings:gtk-menu-images setting and always show their image, if available.
1273 * Use this if the menu item would be useless or hard to use
1274 * without their image.
1279 gtk_action_set_always_show_image (GtkAction *action,
1280 gboolean always_show)
1282 GtkActionPrivate *priv;
1284 g_return_if_fail (GTK_IS_ACTION (action));
1286 priv = action->private_data;
1288 always_show = always_show != FALSE;
1290 if (priv->always_show_image != always_show)
1292 priv->always_show_image = always_show;
1294 g_object_notify (G_OBJECT (action), "always-show-image");
1299 * gtk_action_get_always_show_image:
1300 * @action: a #GtkAction
1302 * Returns whether @action<!-- -->'s menu item proxies will ignore the
1303 * #GtkSettings:gtk-menu-images setting and always show their image,
1306 * Returns: %TRUE if the menu item proxies will always show their image
1311 gtk_action_get_always_show_image (GtkAction *action)
1313 g_return_val_if_fail (GTK_IS_ACTION (action), FALSE);
1315 return action->private_data->always_show_image;
1319 * gtk_action_set_label:
1320 * @action: a #GtkAction
1321 * @label: the label text to set
1323 * Sets the label of @action.
1328 gtk_action_set_label (GtkAction *action,
1333 g_return_if_fail (GTK_IS_ACTION (action));
1335 tmp = action->private_data->label;
1336 action->private_data->label = g_strdup (label);
1338 action->private_data->label_set = (action->private_data->label != NULL);
1339 /* if label is unset, then use the label from the stock item */
1340 if (!action->private_data->label_set && action->private_data->stock_id)
1342 GtkStockItem stock_item;
1344 if (gtk_stock_lookup (action->private_data->stock_id, &stock_item))
1345 action->private_data->label = g_strdup (stock_item.label);
1348 g_object_notify (G_OBJECT (action), "label");
1350 /* if short_label is unset, set short_label=label */
1351 if (!action->private_data->short_label_set)
1353 gtk_action_set_short_label (action, action->private_data->label);
1354 action->private_data->short_label_set = FALSE;
1359 * gtk_action_get_label:
1360 * @action: a #GtkAction
1362 * Gets the label text of @action.
1364 * Returns: the label text
1368 G_CONST_RETURN gchar *
1369 gtk_action_get_label (GtkAction *action)
1371 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1373 return action->private_data->label;
1377 * gtk_action_set_short_label:
1378 * @action: a #GtkAction
1379 * @short_label: the label text to set
1381 * Sets a shorter label text on @action.
1386 gtk_action_set_short_label (GtkAction *action,
1387 const gchar *short_label)
1391 g_return_if_fail (GTK_IS_ACTION (action));
1393 tmp = action->private_data->short_label;
1394 action->private_data->short_label = g_strdup (short_label);
1396 action->private_data->short_label_set = (action->private_data->short_label != NULL);
1397 /* if short_label is unset, then use the value of label */
1398 if (!action->private_data->short_label_set)
1399 action->private_data->short_label = g_strdup (action->private_data->label);
1401 g_object_notify (G_OBJECT (action), "short-label");
1405 * gtk_action_get_short_label:
1406 * @action: a #GtkAction
1408 * Gets the short label text of @action.
1410 * Returns: the short label text.
1414 G_CONST_RETURN gchar *
1415 gtk_action_get_short_label (GtkAction *action)
1417 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1419 return action->private_data->short_label;
1423 * gtk_action_set_visible_horizontal:
1424 * @action: a #GtkAction
1425 * @visible_horizontal: whether the action is visible horizontally
1427 * Sets whether @action is visible when horizontal
1432 gtk_action_set_visible_horizontal (GtkAction *action,
1433 gboolean visible_horizontal)
1435 g_return_if_fail (GTK_IS_ACTION (action));
1437 g_return_if_fail (GTK_IS_ACTION (action));
1439 visible_horizontal = visible_horizontal != FALSE;
1441 if (action->private_data->visible_horizontal != visible_horizontal)
1443 action->private_data->visible_horizontal = visible_horizontal;
1445 g_object_notify (G_OBJECT (action), "visible-horizontal");
1450 * gtk_action_get_visible_horizontal:
1451 * @action: a #GtkAction
1453 * Checks whether @action is visible when horizontal
1455 * Returns: whether @action is visible when horizontal
1460 gtk_action_get_visible_horizontal (GtkAction *action)
1462 g_return_val_if_fail (GTK_IS_ACTION (action), FALSE);
1464 return action->private_data->visible_horizontal;
1468 * gtk_action_set_visible_vertical:
1469 * @action: a #GtkAction
1470 * @visible_vertical: whether the action is visible vertically
1472 * Sets whether @action is visible when vertical
1477 gtk_action_set_visible_vertical (GtkAction *action,
1478 gboolean visible_vertical)
1480 g_return_if_fail (GTK_IS_ACTION (action));
1482 g_return_if_fail (GTK_IS_ACTION (action));
1484 visible_vertical = visible_vertical != FALSE;
1486 if (action->private_data->visible_vertical != visible_vertical)
1488 action->private_data->visible_vertical = visible_vertical;
1490 g_object_notify (G_OBJECT (action), "visible-vertical");
1495 * gtk_action_get_visible_vertical:
1496 * @action: a #GtkAction
1498 * Checks whether @action is visible when horizontal
1500 * Returns: whether @action is visible when horizontal
1505 gtk_action_get_visible_vertical (GtkAction *action)
1507 g_return_val_if_fail (GTK_IS_ACTION (action), FALSE);
1509 return action->private_data->visible_vertical;
1513 * gtk_action_set_tooltip:
1514 * @action: a #GtkAction
1515 * @tooltip: the tooltip text
1517 * Sets the tooltip text on @action
1522 gtk_action_set_tooltip (GtkAction *action,
1523 const gchar *tooltip)
1527 g_return_if_fail (GTK_IS_ACTION (action));
1529 tmp = action->private_data->tooltip;
1530 action->private_data->tooltip = g_strdup (tooltip);
1533 g_object_notify (G_OBJECT (action), "tooltip");
1537 * gtk_action_get_tooltip:
1538 * @action: a #GtkAction
1540 * Gets the tooltip text of @action.
1542 * Returns: the tooltip text
1546 G_CONST_RETURN gchar *
1547 gtk_action_get_tooltip (GtkAction *action)
1549 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1551 return action->private_data->tooltip;
1555 * gtk_action_set_stock_id:
1556 * @action: a #GtkAction
1557 * @stock_id: the stock id
1559 * Sets the stock id on @action
1564 gtk_action_set_stock_id (GtkAction *action,
1565 const gchar *stock_id)
1569 g_return_if_fail (GTK_IS_ACTION (action));
1571 g_return_if_fail (GTK_IS_ACTION (action));
1573 tmp = action->private_data->stock_id;
1574 action->private_data->stock_id = g_strdup (stock_id);
1577 g_object_notify (G_OBJECT (action), "stock-id");
1579 /* update label and short_label if appropriate */
1580 if (!action->private_data->label_set)
1582 GtkStockItem stock_item;
1584 if (action->private_data->stock_id &&
1585 gtk_stock_lookup (action->private_data->stock_id, &stock_item))
1586 gtk_action_set_label (action, stock_item.label);
1588 gtk_action_set_label (action, NULL);
1590 action->private_data->label_set = FALSE;
1595 * gtk_action_get_stock_id:
1596 * @action: a #GtkAction
1598 * Gets the stock id of @action.
1600 * Returns: the stock id
1604 G_CONST_RETURN gchar *
1605 gtk_action_get_stock_id (GtkAction *action)
1607 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1609 return action->private_data->stock_id;
1613 * gtk_action_set_icon_name:
1614 * @action: a #GtkAction
1615 * @icon_name: the icon name to set
1617 * Sets the icon name on @action
1622 gtk_action_set_icon_name (GtkAction *action,
1623 const gchar *icon_name)
1627 g_return_if_fail (GTK_IS_ACTION (action));
1629 tmp = action->private_data->icon_name;
1630 action->private_data->icon_name = g_strdup (icon_name);
1633 g_object_notify (G_OBJECT (action), "icon-name");
1637 * gtk_action_get_icon_name:
1638 * @action: a #GtkAction
1640 * Gets the icon name of @action.
1642 * Returns: the icon name
1646 G_CONST_RETURN gchar *
1647 gtk_action_get_icon_name (GtkAction *action)
1649 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1651 return action->private_data->icon_name;
1655 * gtk_action_set_gicon:
1656 * @action: a #GtkAction
1657 * @icon: the #GIcon to set
1659 * Sets the icon of @action.
1664 gtk_action_set_gicon (GtkAction *action,
1667 g_return_if_fail (GTK_IS_ACTION (action));
1669 if (action->private_data->gicon)
1670 g_object_unref (action->private_data->gicon);
1672 action->private_data->gicon = icon;
1674 if (action->private_data->gicon)
1675 g_object_ref (action->private_data->gicon);
1677 g_object_notify (G_OBJECT (action), "gicon");
1681 * gtk_action_get_gicon:
1682 * @action: a #GtkAction
1684 * Gets the gicon of @action.
1686 * Returns: The action's #GIcon if one is set.
1691 gtk_action_get_gicon (GtkAction *action)
1693 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1695 return action->private_data->gicon;
1699 * gtk_action_block_activate_from:
1700 * @action: the action object
1701 * @proxy: a proxy widget
1703 * Disables calls to the gtk_action_activate()
1704 * function by signals on the given proxy widget. This is used to
1705 * break notification loops for things like check or radio actions.
1707 * This function is intended for use by action implementations.
1711 * Deprecated: 2.16: activatables are now responsible for activating the
1712 * action directly so this doesnt apply anymore.
1715 gtk_action_block_activate_from (GtkAction *action,
1718 g_return_if_fail (GTK_IS_ACTION (action));
1720 g_signal_handlers_block_by_func (proxy, G_CALLBACK (gtk_action_activate),
1723 gtk_action_block_activate (action);
1727 * gtk_action_unblock_activate_from:
1728 * @action: the action object
1729 * @proxy: a proxy widget
1731 * Re-enables calls to the gtk_action_activate()
1732 * function by signals on the given proxy widget. This undoes the
1733 * blocking done by gtk_action_block_activate_from().
1735 * This function is intended for use by action implementations.
1739 * Deprecated: 2.16: activatables are now responsible for activating the
1740 * action directly so this doesnt apply anymore.
1743 gtk_action_unblock_activate_from (GtkAction *action,
1746 g_return_if_fail (GTK_IS_ACTION (action));
1748 g_signal_handlers_unblock_by_func (proxy, G_CALLBACK (gtk_action_activate),
1751 gtk_action_unblock_activate (action);
1755 closure_accel_activate (GClosure *closure,
1756 GValue *return_value,
1757 guint n_param_values,
1758 const GValue *param_values,
1759 gpointer invocation_hint,
1760 gpointer marshal_data)
1762 if (gtk_action_is_sensitive (GTK_ACTION (closure->data)))
1764 _gtk_action_emit_activate (GTK_ACTION (closure->data));
1766 /* we handled the accelerator */
1767 g_value_set_boolean (return_value, TRUE);
1772 gtk_action_set_action_group (GtkAction *action,
1773 GtkActionGroup *action_group)
1775 if (action->private_data->action_group == NULL)
1776 g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
1778 g_return_if_fail (action_group == NULL);
1780 action->private_data->action_group = action_group;
1784 * gtk_action_set_accel_path:
1785 * @action: the action object
1786 * @accel_path: the accelerator path
1788 * Sets the accel path for this action. All proxy widgets associated
1789 * with the action will have this accel path, so that their
1790 * accelerators are consistent.
1792 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
1793 * pass a static string, you can save some memory by interning it first with
1794 * g_intern_static_string().
1799 gtk_action_set_accel_path (GtkAction *action,
1800 const gchar *accel_path)
1802 g_return_if_fail (GTK_IS_ACTION (action));
1804 action->private_data->accel_quark = g_quark_from_string (accel_path);
1808 * gtk_action_get_accel_path:
1809 * @action: the action object
1811 * Returns the accel path for this action.
1815 * Returns: the accel path for this action, or %NULL
1816 * if none is set. The returned string is owned by GTK+
1817 * and must not be freed or modified.
1819 G_CONST_RETURN gchar *
1820 gtk_action_get_accel_path (GtkAction *action)
1822 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1824 if (action->private_data->accel_quark)
1825 return g_quark_to_string (action->private_data->accel_quark);
1831 * gtk_action_get_accel_closure:
1832 * @action: the action object
1834 * Returns the accel closure for this action.
1838 * Returns: the accel closure for this action. The returned closure is
1839 * owned by GTK+ and must not be unreffed or modified.
1842 gtk_action_get_accel_closure (GtkAction *action)
1844 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1846 return action->private_data->accel_closure;
1851 * gtk_action_set_accel_group:
1852 * @action: the action object
1853 * @accel_group: (allow-none): a #GtkAccelGroup or %NULL
1855 * Sets the #GtkAccelGroup in which the accelerator for this action
1856 * will be installed.
1861 gtk_action_set_accel_group (GtkAction *action,
1862 GtkAccelGroup *accel_group)
1864 g_return_if_fail (GTK_IS_ACTION (action));
1865 g_return_if_fail (accel_group == NULL || GTK_IS_ACCEL_GROUP (accel_group));
1868 g_object_ref (accel_group);
1869 if (action->private_data->accel_group)
1870 g_object_unref (action->private_data->accel_group);
1872 action->private_data->accel_group = accel_group;
1876 * gtk_action_connect_accelerator:
1877 * @action: a #GtkAction
1879 * Installs the accelerator for @action if @action has an
1880 * accel path and group. See gtk_action_set_accel_path() and
1881 * gtk_action_set_accel_group()
1883 * Since multiple proxies may independently trigger the installation
1884 * of the accelerator, the @action counts the number of times this
1885 * function has been called and doesn't remove the accelerator until
1886 * gtk_action_disconnect_accelerator() has been called as many times.
1891 gtk_action_connect_accelerator (GtkAction *action)
1893 g_return_if_fail (GTK_IS_ACTION (action));
1895 if (!action->private_data->accel_quark ||
1896 !action->private_data->accel_group)
1899 if (action->private_data->accel_count == 0)
1901 const gchar *accel_path =
1902 g_quark_to_string (action->private_data->accel_quark);
1904 gtk_accel_group_connect_by_path (action->private_data->accel_group,
1906 action->private_data->accel_closure);
1909 action->private_data->accel_count++;
1913 * gtk_action_disconnect_accelerator:
1914 * @action: a #GtkAction
1916 * Undoes the effect of one call to gtk_action_connect_accelerator().
1921 gtk_action_disconnect_accelerator (GtkAction *action)
1923 g_return_if_fail (GTK_IS_ACTION (action));
1925 if (!action->private_data->accel_quark ||
1926 !action->private_data->accel_group)
1929 action->private_data->accel_count--;
1931 if (action->private_data->accel_count == 0)
1932 gtk_accel_group_disconnect (action->private_data->accel_group,
1933 action->private_data->accel_closure);
1937 * gtk_action_create_menu:
1938 * @action: a #GtkAction
1940 * If @action provides a #GtkMenu widget as a submenu for the menu
1941 * item or the toolbar item it creates, this function returns an
1942 * instance of that menu.
1944 * Return value: the menu item provided by the action, or %NULL.
1949 gtk_action_create_menu (GtkAction *action)
1951 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1953 if (GTK_ACTION_GET_CLASS (action)->create_menu)
1954 return GTK_ACTION_GET_CLASS (action)->create_menu (action);
1959 #define __GTK_ACTION_C__
1960 #include "gtkaliasdef.c"