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:
763 * Disable activation signals from the action
765 * This is needed when updating the state of your proxy
766 * #GtkActivatable widget could result in calling gtk_action_activate(),
767 * this is a convenience function to avoid recursing in those
768 * cases (updating toggle state for instance).
771 gtk_action_block_activate (GtkAction *action)
773 g_return_if_fail (GTK_IS_ACTION (action));
775 action->private_data->activate_blocked = TRUE;
779 * gtk_action_unblock_activate:
781 * Reenable activation signals from the action
784 gtk_action_unblock_activate (GtkAction *action)
786 g_return_if_fail (GTK_IS_ACTION (action));
788 action->private_data->activate_blocked = FALSE;
792 * gtk_action_create_icon:
793 * @action: the action object
794 * @icon_size: the size of the icon that should be created.
796 * This function is intended for use by action implementations to
797 * create icons displayed in the proxy widgets.
799 * Returns: a widget that displays the icon for this action.
804 gtk_action_create_icon (GtkAction *action, GtkIconSize icon_size)
806 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
808 if (action->private_data->stock_id &&
809 gtk_icon_factory_lookup_default (action->private_data->stock_id))
810 return gtk_image_new_from_stock (action->private_data->stock_id, icon_size);
811 else if (action->private_data->gicon)
812 return gtk_image_new_from_gicon (action->private_data->gicon, icon_size);
813 else if (action->private_data->icon_name)
814 return gtk_image_new_from_icon_name (action->private_data->icon_name, icon_size);
820 * gtk_action_create_menu_item:
821 * @action: the action object
823 * Creates a menu item widget that proxies for the given action.
825 * Returns: a menu item connected to the action.
830 gtk_action_create_menu_item (GtkAction *action)
832 GtkWidget *menu_item;
834 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
836 menu_item = GTK_ACTION_GET_CLASS (action)->create_menu_item (action);
838 gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (menu_item), TRUE);
839 gtk_activatable_set_related_action (GTK_ACTIVATABLE (menu_item), action);
845 * gtk_action_create_tool_item:
846 * @action: the action object
848 * Creates a toolbar item widget that proxies for the given action.
850 * Returns: a toolbar item connected to the action.
855 gtk_action_create_tool_item (GtkAction *action)
859 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
861 button = GTK_ACTION_GET_CLASS (action)->create_tool_item (action);
863 gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (button), TRUE);
864 gtk_activatable_set_related_action (GTK_ACTIVATABLE (button), action);
870 _gtk_action_add_to_proxy_list (GtkAction *action,
873 g_return_if_fail (GTK_IS_ACTION (action));
874 g_return_if_fail (GTK_IS_WIDGET (proxy));
876 GTK_ACTION_GET_CLASS (action)->connect_proxy (action, proxy);
880 _gtk_action_remove_from_proxy_list (GtkAction *action,
883 g_return_if_fail (GTK_IS_ACTION (action));
884 g_return_if_fail (GTK_IS_WIDGET (proxy));
886 GTK_ACTION_GET_CLASS (action)->disconnect_proxy (action, proxy);
890 * gtk_action_connect_proxy:
891 * @action: the action object
892 * @proxy: the proxy widget
894 * Connects a widget to an action object as a proxy. Synchronises
895 * various properties of the action with the widget (such as label
896 * text, icon, tooltip, etc), and attaches a callback so that the
897 * action gets activated when the proxy widget does.
899 * If the widget is already connected to an action, it is disconnected
904 * Deprecated 2.16: Use gtk_activatable_set_related_action() instead.
907 gtk_action_connect_proxy (GtkAction *action,
910 g_return_if_fail (GTK_IS_ACTION (action));
911 g_return_if_fail (GTK_IS_WIDGET (proxy));
912 g_return_if_fail (GTK_IS_ACTIVATABLE (proxy));
914 gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (proxy), TRUE);
916 gtk_activatable_set_related_action (GTK_ACTIVATABLE (proxy), action);
920 * gtk_action_disconnect_proxy:
921 * @action: the action object
922 * @proxy: the proxy widget
924 * Disconnects a proxy widget from an action.
925 * Does <emphasis>not</emphasis> destroy the widget, however.
929 * Deprecated 2.16: Use gtk_activatable_set_related_action() instead.
932 gtk_action_disconnect_proxy (GtkAction *action,
935 g_return_if_fail (GTK_IS_ACTION (action));
936 g_return_if_fail (GTK_IS_WIDGET (proxy));
938 gtk_activatable_set_related_action (GTK_ACTIVATABLE (proxy), NULL);
942 * gtk_action_get_proxies:
943 * @action: the action object
945 * Returns the proxy widgets for an action.
946 * See also gtk_widget_get_action().
948 * Return value: a #GSList of proxy widgets. The list is owned by GTK+
949 * and must not be modified.
954 gtk_action_get_proxies (GtkAction *action)
956 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
958 return action->private_data->proxies;
963 * gtk_widget_get_action:
964 * @widget: a #GtkWidget
966 * Returns the #GtkAction that @widget is a proxy for.
967 * See also gtk_action_get_proxies().
969 * Returns: the action that a widget is a proxy for, or
970 * %NULL, if it is not attached to an action.
974 * Deprecated 2.16: Use gtk_activatable_get_related_action() instead.
977 gtk_widget_get_action (GtkWidget *widget)
979 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
981 if (GTK_IS_ACTIVATABLE (widget))
982 return gtk_activatable_get_related_action (GTK_ACTIVATABLE (widget));
988 * gtk_action_get_name:
989 * @action: the action object
991 * Returns the name of the action.
993 * Return value: the name of the action. The string belongs to GTK+ and should not
998 G_CONST_RETURN gchar *
999 gtk_action_get_name (GtkAction *action)
1001 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1003 return action->private_data->name;
1007 * gtk_action_is_sensitive:
1008 * @action: the action object
1010 * Returns whether the action is effectively sensitive.
1012 * Return value: %TRUE if the action and its associated action group
1013 * are both sensitive.
1018 gtk_action_is_sensitive (GtkAction *action)
1020 GtkActionPrivate *priv;
1021 g_return_val_if_fail (GTK_IS_ACTION (action), FALSE);
1023 priv = action->private_data;
1024 return priv->sensitive &&
1025 (priv->action_group == NULL ||
1026 gtk_action_group_get_sensitive (priv->action_group));
1030 * gtk_action_get_sensitive:
1031 * @action: the action object
1033 * Returns whether the action itself is sensitive. Note that this doesn't
1034 * necessarily mean effective sensitivity. See gtk_action_is_sensitive()
1037 * Return value: %TRUE if the action itself is sensitive.
1042 gtk_action_get_sensitive (GtkAction *action)
1044 g_return_val_if_fail (GTK_IS_ACTION (action), FALSE);
1046 return action->private_data->sensitive;
1050 * gtk_action_set_sensitive:
1051 * @action: the action object
1052 * @sensitive: %TRUE to make the action sensitive
1054 * Sets the ::sensitive property of the action to @sensitive. Note that
1055 * this doesn't necessarily mean effective sensitivity. See
1056 * gtk_action_is_sensitive()
1062 gtk_action_set_sensitive (GtkAction *action,
1065 g_return_if_fail (GTK_IS_ACTION (action));
1067 sensitive = sensitive != FALSE;
1069 if (action->private_data->sensitive != sensitive)
1071 action->private_data->sensitive = sensitive;
1073 g_object_notify (G_OBJECT (action), "sensitive");
1078 * gtk_action_is_visible:
1079 * @action: the action object
1081 * Returns whether the action is effectively visible.
1083 * Return value: %TRUE if the action and its associated action group
1089 gtk_action_is_visible (GtkAction *action)
1091 GtkActionPrivate *priv;
1092 g_return_val_if_fail (GTK_IS_ACTION (action), FALSE);
1094 priv = action->private_data;
1095 return priv->visible &&
1096 (priv->action_group == NULL ||
1097 gtk_action_group_get_visible (priv->action_group));
1101 * gtk_action_get_visible:
1102 * @action: the action object
1104 * Returns whether the action itself is visible. Note that this doesn't
1105 * necessarily mean effective visibility. See gtk_action_is_sensitive()
1108 * Return value: %TRUE if the action itself is visible.
1113 gtk_action_get_visible (GtkAction *action)
1115 g_return_val_if_fail (GTK_IS_ACTION (action), FALSE);
1117 return action->private_data->visible;
1121 * gtk_action_set_visible:
1122 * @action: the action object
1123 * @visible: %TRUE to make the action visible
1125 * Sets the ::visible property of the action to @visible. Note that
1126 * this doesn't necessarily mean effective visibility. See
1127 * gtk_action_is_visible()
1133 gtk_action_set_visible (GtkAction *action,
1136 g_return_if_fail (GTK_IS_ACTION (action));
1138 visible = visible != FALSE;
1140 if (action->private_data->visible != visible)
1142 action->private_data->visible = visible;
1144 g_object_notify (G_OBJECT (action), "visible");
1148 * gtk_action_set_is_important:
1149 * @action: the action object
1150 * @is_important: %TRUE to make the action important
1152 * Sets whether the action is important, this attribute is used
1153 * primarily by toolbar items to decide whether to show a label
1159 gtk_action_set_is_important (GtkAction *action,
1160 gboolean is_important)
1162 g_return_if_fail (GTK_IS_ACTION (action));
1164 g_return_if_fail (GTK_IS_ACTION (action));
1166 is_important = is_important != FALSE;
1168 if (action->private_data->is_important != is_important)
1170 action->private_data->is_important = is_important;
1172 g_object_notify (G_OBJECT (action), "is-important");
1177 * gtk_action_get_is_important:
1178 * @action: a #GtkAction
1180 * Checks whether @action is important or not
1182 * Returns: whether @action is important
1187 gtk_action_get_is_important (GtkAction *action)
1189 g_return_val_if_fail (GTK_IS_ACTION (action), FALSE);
1191 return action->private_data->is_important;
1195 * gtk_action_set_label:
1196 * @action: a #GtkAction
1197 * @label: the label text to set
1199 * Sets the label of @action.
1204 gtk_action_set_label (GtkAction *action,
1209 g_return_if_fail (GTK_IS_ACTION (action));
1211 tmp = action->private_data->label;
1212 action->private_data->label = g_strdup (label);
1214 action->private_data->label_set = (action->private_data->label != NULL);
1215 /* if label is unset, then use the label from the stock item */
1216 if (!action->private_data->label_set && action->private_data->stock_id)
1218 GtkStockItem stock_item;
1220 if (gtk_stock_lookup (action->private_data->stock_id, &stock_item))
1221 action->private_data->label = g_strdup (stock_item.label);
1224 g_object_notify (G_OBJECT (action), "label");
1226 /* if short_label is unset, set short_label=label */
1227 if (!action->private_data->short_label_set)
1229 gtk_action_set_short_label (action, action->private_data->label);
1230 action->private_data->short_label_set = FALSE;
1235 * gtk_action_get_label:
1236 * @action: a #GtkAction
1238 * Gets the label text of @action.
1240 * Returns: the label text
1244 G_CONST_RETURN gchar *
1245 gtk_action_get_label (GtkAction *action)
1247 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1249 return action->private_data->label;
1253 * gtk_action_set_short_label:
1254 * @action: a #GtkAction
1255 * @label: the label text to set
1257 * Sets a shorter label text on @action.
1262 gtk_action_set_short_label (GtkAction *action,
1267 g_return_if_fail (GTK_IS_ACTION (action));
1269 tmp = action->private_data->short_label;
1270 action->private_data->short_label = g_strdup (label);
1272 action->private_data->short_label_set = (action->private_data->short_label != NULL);
1273 /* if short_label is unset, then use the value of label */
1274 if (!action->private_data->short_label_set)
1275 action->private_data->short_label = g_strdup (action->private_data->label);
1277 g_object_notify (G_OBJECT (action), "short-label");
1281 * gtk_action_get_short_label:
1282 * @action: a #GtkAction
1283 * @label: the label text to set
1285 * Gets the short label text of @action.
1287 * Returns: the short label text.
1291 G_CONST_RETURN gchar *
1292 gtk_action_get_short_label (GtkAction *action)
1294 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1296 return action->private_data->short_label;
1300 * gtk_action_set_visible_horizontal:
1301 * @action: a #GtkAction
1302 * @visible_horizontal: whether the action is visible horizontally
1304 * Sets whether @action is visible when horizontal
1309 gtk_action_set_visible_horizontal (GtkAction *action,
1310 gboolean visible_horizontal)
1312 g_return_if_fail (GTK_IS_ACTION (action));
1314 g_return_if_fail (GTK_IS_ACTION (action));
1316 visible_horizontal = visible_horizontal != FALSE;
1318 if (action->private_data->visible_horizontal != visible_horizontal)
1320 action->private_data->visible_horizontal = visible_horizontal;
1322 g_object_notify (G_OBJECT (action), "visible-horizontal");
1327 * gtk_action_get_visible_horizontal:
1328 * @action: a #GtkAction
1330 * Checks whether @action is visible when horizontal
1332 * Returns: whether @action is visible when horizontal
1337 gtk_action_get_visible_horizontal (GtkAction *action)
1339 g_return_val_if_fail (GTK_IS_ACTION (action), FALSE);
1341 return action->private_data->visible_horizontal;
1345 * gtk_action_set_visible_vertical:
1346 * @action: a #GtkAction
1347 * @visible_vertical: whether the action is visible vertically
1349 * Sets whether @action is visible when vertical
1354 gtk_action_set_visible_vertical (GtkAction *action,
1355 gboolean visible_vertical)
1357 g_return_if_fail (GTK_IS_ACTION (action));
1359 g_return_if_fail (GTK_IS_ACTION (action));
1361 visible_vertical = visible_vertical != FALSE;
1363 if (action->private_data->visible_vertical != visible_vertical)
1365 action->private_data->visible_vertical = visible_vertical;
1367 g_object_notify (G_OBJECT (action), "visible-vertical");
1372 * gtk_action_get_visible_vertical:
1373 * @action: a #GtkAction
1375 * Checks whether @action is visible when horizontal
1377 * Returns: whether @action is visible when horizontal
1382 gtk_action_get_visible_vertical (GtkAction *action)
1384 g_return_val_if_fail (GTK_IS_ACTION (action), FALSE);
1386 return action->private_data->visible_vertical;
1390 * gtk_action_set_tooltip:
1391 * @action: a #GtkAction
1392 * @tooltip: the tooltip text
1394 * Sets the tooltip text on @action
1399 gtk_action_set_tooltip (GtkAction *action,
1400 const gchar *tooltip)
1404 g_return_if_fail (GTK_IS_ACTION (action));
1406 tmp = action->private_data->tooltip;
1407 action->private_data->tooltip = g_strdup (tooltip);
1410 g_object_notify (G_OBJECT (action), "tooltip");
1414 * gtk_action_get_tooltip:
1415 * @action: a #GtkAction
1417 * Gets the tooltip text of @action.
1419 * Returns: the tooltip text
1423 G_CONST_RETURN gchar *
1424 gtk_action_get_tooltip (GtkAction *action)
1426 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1428 return action->private_data->tooltip;
1432 * gtk_action_set_stock_id:
1433 * @action: a #GtkAction
1434 * @tooltip: the tooltip text
1436 * Sets the stock id on @action
1441 gtk_action_set_stock_id (GtkAction *action,
1442 const gchar *stock_id)
1446 g_return_if_fail (GTK_IS_ACTION (action));
1448 g_return_if_fail (GTK_IS_ACTION (action));
1450 tmp = action->private_data->stock_id;
1451 action->private_data->stock_id = g_strdup (stock_id);
1454 g_object_notify (G_OBJECT (action), "stock-id");
1456 /* update label and short_label if appropriate */
1457 if (!action->private_data->label_set)
1459 GtkStockItem stock_item;
1461 if (action->private_data->stock_id &&
1462 gtk_stock_lookup (action->private_data->stock_id, &stock_item))
1463 gtk_action_set_label (action, stock_item.label);
1465 gtk_action_set_label (action, NULL);
1467 action->private_data->label_set = FALSE;
1472 * gtk_action_get_stock_id:
1473 * @action: a #GtkAction
1475 * Gets the stock id of @action.
1477 * Returns: the stock id
1481 G_CONST_RETURN gchar *
1482 gtk_action_get_stock_id (GtkAction *action)
1484 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1486 return action->private_data->stock_id;
1490 * gtk_action_set_icon_name:
1491 * @action: a #GtkAction
1492 * @tooltip: the icon name to set
1494 * Sets the icon name on @action
1499 gtk_action_set_icon_name (GtkAction *action,
1500 const gchar *icon_name)
1504 g_return_if_fail (GTK_IS_ACTION (action));
1506 g_return_if_fail (GTK_IS_ACTION (action));
1508 tmp = action->private_data->icon_name;
1509 action->private_data->icon_name = g_strdup (icon_name);
1512 g_object_notify (G_OBJECT (action), "icon-name");
1516 * gtk_action_get_icon_name:
1517 * @action: a #GtkAction
1519 * Gets the icon name of @action.
1521 * Returns: the icon name
1525 G_CONST_RETURN gchar *
1526 gtk_action_get_icon_name (GtkAction *action)
1528 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1530 return action->private_data->icon_name;
1534 * gtk_action_set_gicon:
1535 * @action: a #GtkAction
1536 * @icon: the #GIcon to set
1538 * Sets the icon of @action.
1543 gtk_action_set_gicon (GtkAction *action,
1546 g_return_if_fail (GTK_IS_ACTION (action));
1548 if (action->private_data->gicon)
1549 g_object_unref (action->private_data->gicon);
1551 action->private_data->gicon = icon;
1553 if (action->private_data->gicon)
1554 g_object_ref (action->private_data->gicon);
1556 g_object_notify (G_OBJECT (action), "gicon");
1560 * gtk_action_get_gicon:
1561 * @action: a #GtkAction
1563 * Gets the gicon of @action.
1565 * Returns: The action's #GIcon if one is set.
1570 gtk_action_get_gicon (GtkAction *action)
1572 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1574 return action->private_data->gicon;
1578 * gtk_action_block_activate_from:
1579 * @action: the action object
1580 * @proxy: a proxy widget
1582 * Disables calls to the gtk_action_activate()
1583 * function by signals on the given proxy widget. This is used to
1584 * break notification loops for things like check or radio actions.
1586 * This function is intended for use by action implementations.
1590 * Deprecated 2.16: activatables are now responsible for activating the
1591 * action directly so this doesnt apply anymore.
1594 gtk_action_block_activate_from (GtkAction *action,
1597 g_return_if_fail (GTK_IS_ACTION (action));
1599 g_signal_handlers_block_by_func (proxy, G_CALLBACK (gtk_action_activate),
1604 * gtk_action_unblock_activate_from:
1605 * @action: the action object
1606 * @proxy: a proxy widget
1608 * Re-enables calls to the gtk_action_activate()
1609 * function by signals on the given proxy widget. This undoes the
1610 * blocking done by gtk_action_block_activate_from().
1612 * This function is intended for use by action implementations.
1616 * Deprecated 2.16: activatables are now responsible for activating the
1617 * action directly so this doesnt apply anymore.
1620 gtk_action_unblock_activate_from (GtkAction *action,
1623 g_return_if_fail (GTK_IS_ACTION (action));
1625 g_signal_handlers_unblock_by_func (proxy, G_CALLBACK (gtk_action_activate),
1630 closure_accel_activate (GClosure *closure,
1631 GValue *return_value,
1632 guint n_param_values,
1633 const GValue *param_values,
1634 gpointer invocation_hint,
1635 gpointer marshal_data)
1637 if (gtk_action_is_sensitive (GTK_ACTION (closure->data)))
1639 _gtk_action_emit_activate (GTK_ACTION (closure->data));
1641 /* we handled the accelerator */
1642 g_value_set_boolean (return_value, TRUE);
1647 gtk_action_set_action_group (GtkAction *action,
1648 GtkActionGroup *action_group)
1650 if (action->private_data->action_group == NULL)
1651 g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
1653 g_return_if_fail (action_group == NULL);
1655 action->private_data->action_group = action_group;
1659 * gtk_action_set_accel_path:
1660 * @action: the action object
1661 * @accel_path: the accelerator path
1663 * Sets the accel path for this action. All proxy widgets associated
1664 * with the action will have this accel path, so that their
1665 * accelerators are consistent.
1667 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
1668 * pass a static string, you can save some memory by interning it first with
1669 * g_intern_static_string().
1674 gtk_action_set_accel_path (GtkAction *action,
1675 const gchar *accel_path)
1677 g_return_if_fail (GTK_IS_ACTION (action));
1679 action->private_data->accel_quark = g_quark_from_string (accel_path);
1683 * gtk_action_get_accel_path:
1684 * @action: the action object
1686 * Returns the accel path for this action.
1690 * Returns: the accel path for this action, or %NULL
1691 * if none is set. The returned string is owned by GTK+
1692 * and must not be freed or modified.
1694 G_CONST_RETURN gchar *
1695 gtk_action_get_accel_path (GtkAction *action)
1697 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1699 if (action->private_data->accel_quark)
1700 return g_quark_to_string (action->private_data->accel_quark);
1706 * gtk_action_get_accel_closure:
1707 * @action: the action object
1709 * Returns the accel closure for this action.
1713 * Returns: the accel closure for this action. The returned closure is
1714 * owned by GTK+ and must not be unreffed or modified.
1717 gtk_action_get_accel_closure (GtkAction *action)
1719 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1721 return action->private_data->accel_closure;
1726 * gtk_action_set_accel_group:
1727 * @action: the action object
1728 * @accel_group: a #GtkAccelGroup or %NULL
1730 * Sets the #GtkAccelGroup in which the accelerator for this action
1731 * will be installed.
1736 gtk_action_set_accel_group (GtkAction *action,
1737 GtkAccelGroup *accel_group)
1739 g_return_if_fail (GTK_IS_ACTION (action));
1740 g_return_if_fail (accel_group == NULL || GTK_IS_ACCEL_GROUP (accel_group));
1743 g_object_ref (accel_group);
1744 if (action->private_data->accel_group)
1745 g_object_unref (action->private_data->accel_group);
1747 action->private_data->accel_group = accel_group;
1751 * gtk_action_connect_accelerator:
1752 * @action: a #GtkAction
1754 * Installs the accelerator for @action if @action has an
1755 * accel path and group. See gtk_action_set_accel_path() and
1756 * gtk_action_set_accel_group()
1758 * Since multiple proxies may independently trigger the installation
1759 * of the accelerator, the @action counts the number of times this
1760 * function has been called and doesn't remove the accelerator until
1761 * gtk_action_disconnect_accelerator() has been called as many times.
1766 gtk_action_connect_accelerator (GtkAction *action)
1768 g_return_if_fail (GTK_IS_ACTION (action));
1770 if (!action->private_data->accel_quark ||
1771 !action->private_data->accel_group)
1774 if (action->private_data->accel_count == 0)
1776 const gchar *accel_path =
1777 g_quark_to_string (action->private_data->accel_quark);
1779 gtk_accel_group_connect_by_path (action->private_data->accel_group,
1781 action->private_data->accel_closure);
1784 action->private_data->accel_count++;
1788 * gtk_action_disconnect_accelerator:
1789 * @action: a #GtkAction
1791 * Undoes the effect of one call to gtk_action_connect_accelerator().
1796 gtk_action_disconnect_accelerator (GtkAction *action)
1798 g_return_if_fail (GTK_IS_ACTION (action));
1800 if (!action->private_data->accel_quark ||
1801 !action->private_data->accel_group)
1804 action->private_data->accel_count--;
1806 if (action->private_data->accel_count == 0)
1807 gtk_accel_group_disconnect (action->private_data->accel_group,
1808 action->private_data->accel_closure);
1812 * gtk_action_create_menu:
1813 * @action: a #GtkAction
1815 * If @action provides a #GtkMenu widget as a submenu for the menu
1816 * item or the toolbar item it creates, this function returns an
1817 * instance of that menu.
1819 * Return value: the menu item provided by the action, or %NULL.
1824 gtk_action_create_menu (GtkAction *action)
1826 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1828 if (GTK_ACTION_GET_CLASS (action)->create_menu)
1829 return GTK_ACTION_GET_CLASS (action)->create_menu (action);
1834 #define __GTK_ACTION_C__
1835 #include "gtkaliasdef.c"