X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=gtk%2Fgtkaction.c;h=6bb0ae9d7b6eb3a07063bf6d4fb70f515aa56e48;hb=HEAD;hp=9ce778eaef00ef431583bb0f4fe26f12b818f334;hpb=95caf23ddd3b7183498340411ef51edf7d365ad8;p=~andy%2Fgtk diff --git a/gtk/gtkaction.c b/gtk/gtkaction.c index 9ce778eae..6bb0ae9d7 100644 --- a/gtk/gtkaction.c +++ b/gtk/gtkaction.c @@ -14,9 +14,7 @@ * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public - * License along with the Gnome Library; see the file COPYING.LIB. If not, - * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * License along with this library. If not, see . */ /* @@ -28,6 +26,50 @@ * GTK+ at ftp://ftp.gtk.org/pub/gtk/. */ +/** + * SECTION:gtkaction + * @Short_description: An action which can be triggered by a menu or toolbar item + * @Title: GtkAction + * @See_also: #GtkActionGroup, #GtkUIManager, #GtkActivatable + * + * Actions represent operations that the user can be perform, along with + * some information how it should be presented in the interface. Each action + * provides methods to create icons, menu items and toolbar items + * representing itself. + * + * As well as the callback that is called when the action gets activated, + * the following also gets associated with the action: + * + * a name (not translated, for path lookup) + * a label (translated, for display) + * an accelerator + * whether label indicates a stock id + * a tooltip (optional, translated) + * a toolbar label (optional, shorter than label) + * + * The action will also have some state information: + * + * visible (shown/hidden) + * sensitive (enabled/disabled) + * + * Apart from regular actions, there are toggle + * actions, which can be toggled between two states and radio actions, of which only one in a group + * can be in the "active" state. Other actions can be implemented as #GtkAction + * subclasses. + * + * Each action can have one or more proxy widgets. To act as an action proxy, + * widget needs to implement #GtkActivatable interface. Proxies mirror the state + * of the action and should change when the action's state changes. Properties + * that are always mirrored by proxies are #GtkAction:sensitive and + * #GtkAction:visible. #GtkAction:gicon, #GtkAction:icon-name, #GtkAction:label, + * #GtkAction:short-label and #GtkAction:stock-id properties are only mirorred + * if proxy widget has #GtkActivatable:use-action-appearance property set to + * %TRUE. + * + * When the proxy is activated, it should activate its action. + */ + #include "config.h" #include "gtkaction.h" @@ -42,17 +84,14 @@ #include "gtkmarshalers.h" #include "gtkmenuitem.h" #include "gtkstock.h" -#include "gtktearoffmenuitem.h" +#include "deprecated/gtktearoffmenuitem.h" #include "gtktoolbutton.h" #include "gtktoolbar.h" #include "gtkprivate.h" #include "gtkbuildable.h" #include "gtkactivatable.h" -#include "gtkalias.h" -#define GTK_ACTION_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ACTION, GtkActionPrivate)) - struct _GtkActionPrivate { const gchar *name; /* interned */ @@ -72,6 +111,7 @@ struct _GtkActionPrivate guint is_important : 1; guint hide_if_empty : 1; guint visible_overflown : 1; + guint always_show_image : 1; guint recursion_guard : 1; guint activate_blocked : 1; @@ -110,7 +150,8 @@ enum PROP_HIDE_IF_EMPTY, PROP_SENSITIVE, PROP_VISIBLE, - PROP_ACTION_GROUP + PROP_ACTION_GROUP, + PROP_ALWAYS_SHOW_IMAGE }; /* GtkBuildable */ @@ -354,6 +395,25 @@ gtk_action_class_init (GtkActionClass *klass) GTK_TYPE_ACTION_GROUP, GTK_PARAM_READWRITE)); + /** + * GtkAction:always-show-image: + * + * If %TRUE, the action's menu item proxies will ignore the #GtkSettings:gtk-menu-images + * setting and always show their image, if available. + * + * Use this property if the menu item would be useless or hard to use + * without their image. + * + * Since: 2.20 + **/ + g_object_class_install_property (gobject_class, + PROP_ALWAYS_SHOW_IMAGE, + g_param_spec_boolean ("always-show-image", + P_("Always show image"), + P_("Whether the image will always be shown"), + FALSE, + GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT)); + /** * GtkAction::activate: * @action: the #GtkAction @@ -377,7 +437,9 @@ gtk_action_class_init (GtkActionClass *klass) static void gtk_action_init (GtkAction *action) { - action->private_data = GTK_ACTION_GET_PRIVATE (action); + action->private_data = G_TYPE_INSTANCE_GET_PRIVATE (action, + GTK_TYPE_ACTION, + GtkActionPrivate); action->private_data->name = NULL; action->private_data->label = NULL; @@ -390,6 +452,7 @@ gtk_action_init (GtkAction *action) action->private_data->visible_overflown = TRUE; action->private_data->is_important = FALSE; action->private_data->hide_if_empty = TRUE; + action->private_data->always_show_image = FALSE; action->private_data->activate_blocked = FALSE; action->private_data->sensitive = TRUE; @@ -441,10 +504,11 @@ gtk_action_buildable_get_name (GtkBuildable *buildable) /** * gtk_action_new: * @name: A unique name for the action - * @label: the label displayed in menu items and on buttons, or %NULL - * @tooltip: a tooltip for the action, or %NULL - * @stock_id: the stock icon to display in widgets representing the - * action, or %NULL + * @label: (allow-none): the label displayed in menu items and on buttons, + * or %NULL + * @tooltip: (allow-none): a tooltip for the action, or %NULL + * @stock_id: (allow-none): the stock icon to display in widgets representing + * the action, or %NULL * * Creates a new #GtkAction object. To add the action to a * #GtkActionGroup and set the accelerator for the action, @@ -551,6 +615,9 @@ gtk_action_set_property (GObject *object, case PROP_ACTION_GROUP: gtk_action_set_action_group (action, g_value_get_object (value)); break; + case PROP_ALWAYS_SHOW_IMAGE: + gtk_action_set_always_show_image (action, g_value_get_boolean (value)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -614,6 +681,9 @@ gtk_action_get_property (GObject *object, case PROP_ACTION_GROUP: g_value_set_object (value, action->private_data->action_group); break; + case PROP_ALWAYS_SHOW_IMAGE: + g_value_set_boolean (value, action->private_data->always_show_image); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -644,6 +714,7 @@ static void remove_proxy (GtkAction *action, GtkWidget *proxy) { + g_object_unref (proxy); action->private_data->proxies = g_slist_remove (action->private_data->proxies, proxy); } @@ -653,6 +724,8 @@ connect_proxy (GtkAction *action, { action->private_data->proxies = g_slist_prepend (action->private_data->proxies, proxy); + g_object_ref_sink (proxy); + if (action->private_data->action_group) _gtk_action_group_emit_connect_proxy (action->private_data->action_group, action, proxy); @@ -670,7 +743,7 @@ disconnect_proxy (GtkAction *action, /** * _gtk_action_sync_menu_visible: - * @action: a #GtkAction, or %NULL to determine the action from @proxy + * @action: (allow-none): a #GtkAction, or %NULL to determine the action from @proxy * @proxy: a proxy menu item * @empty: whether the submenu attached to @proxy is empty * @@ -718,18 +791,20 @@ _gtk_action_emit_activate (GtkAction *action) { GtkActionGroup *group = action->private_data->action_group; - if (group != NULL) + if (group != NULL) { + g_object_ref (action); g_object_ref (group); _gtk_action_group_emit_pre_activate (group, action); } - g_signal_emit (action, action_signals[ACTIVATE], 0); + g_signal_emit (action, action_signals[ACTIVATE], 0); - if (group != NULL) + if (group != NULL) { _gtk_action_group_emit_post_activate (group, action); g_object_unref (group); + g_object_unref (action); } } @@ -759,6 +834,7 @@ gtk_action_activate (GtkAction *action) /** * gtk_action_block_activate: + * @action: a #GtkAction * * Disable activation signals from the action * @@ -766,6 +842,8 @@ gtk_action_activate (GtkAction *action) * #GtkActivatable widget could result in calling gtk_action_activate(), * this is a convenience function to avoid recursing in those * cases (updating toggle state for instance). + * + * Since: 2.16 */ void gtk_action_block_activate (GtkAction *action) @@ -777,8 +855,11 @@ gtk_action_block_activate (GtkAction *action) /** * gtk_action_unblock_activate: + * @action: a #GtkAction * * Reenable activation signals from the action + * + * Since: 2.16 */ void gtk_action_unblock_activate (GtkAction *action) @@ -791,12 +872,12 @@ gtk_action_unblock_activate (GtkAction *action) /** * gtk_action_create_icon: * @action: the action object - * @icon_size: the size of the icon that should be created. + * @icon_size: (type int): the size of the icon that should be created. * * This function is intended for use by action implementations to * create icons displayed in the proxy widgets. * - * Returns: a widget that displays the icon for this action. + * Returns: (transfer none): a widget that displays the icon for this action. * * Since: 2.4 */ @@ -822,7 +903,7 @@ gtk_action_create_icon (GtkAction *action, GtkIconSize icon_size) * * Creates a menu item widget that proxies for the given action. * - * Returns: a menu item connected to the action. + * Returns: (transfer none): a menu item connected to the action. * * Since: 2.4 */ @@ -847,7 +928,7 @@ gtk_action_create_menu_item (GtkAction *action) * * Creates a toolbar item widget that proxies for the given action. * - * Returns: a toolbar item connected to the action. + * Returns: (transfer none): a toolbar item connected to the action. * * Since: 2.4 */ @@ -886,66 +967,14 @@ _gtk_action_remove_from_proxy_list (GtkAction *action, GTK_ACTION_GET_CLASS (action)->disconnect_proxy (action, proxy); } -/** - * gtk_action_connect_proxy: - * @action: the action object - * @proxy: the proxy widget - * - * Connects a widget to an action object as a proxy. Synchronises - * various properties of the action with the widget (such as label - * text, icon, tooltip, etc), and attaches a callback so that the - * action gets activated when the proxy widget does. - * - * If the widget is already connected to an action, it is disconnected - * first. - * - * Since: 2.4 - * - * Deprecated 2.16: Use gtk_activatable_set_related_action() instead. - */ -void -gtk_action_connect_proxy (GtkAction *action, - GtkWidget *proxy) -{ - g_return_if_fail (GTK_IS_ACTION (action)); - g_return_if_fail (GTK_IS_WIDGET (proxy)); - g_return_if_fail (GTK_IS_ACTIVATABLE (proxy)); - - gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (proxy), TRUE); - - gtk_activatable_set_related_action (GTK_ACTIVATABLE (proxy), action); -} - -/** - * gtk_action_disconnect_proxy: - * @action: the action object - * @proxy: the proxy widget - * - * Disconnects a proxy widget from an action. - * Does not destroy the widget, however. - * - * Since: 2.4 - * - * Deprecated 2.16: Use gtk_activatable_set_related_action() instead. - */ -void -gtk_action_disconnect_proxy (GtkAction *action, - GtkWidget *proxy) -{ - g_return_if_fail (GTK_IS_ACTION (action)); - g_return_if_fail (GTK_IS_WIDGET (proxy)); - - gtk_activatable_set_related_action (GTK_ACTIVATABLE (proxy), NULL); -} - /** * gtk_action_get_proxies: * @action: the action object * * Returns the proxy widgets for an action. - * See also gtk_widget_get_action(). - * - * Return value: a #GSList of proxy widgets. The list is owned by GTK+ + * See also gtk_activatable_get_related_action(). + * + * Return value: (element-type GtkWidget) (transfer none): a #GSList of proxy widgets. The list is owned by GTK+ * and must not be modified. * * Since: 2.4 @@ -958,32 +987,6 @@ gtk_action_get_proxies (GtkAction *action) return action->private_data->proxies; } - -/** - * gtk_widget_get_action: - * @widget: a #GtkWidget - * - * Returns the #GtkAction that @widget is a proxy for. - * See also gtk_action_get_proxies(). - * - * Returns: the action that a widget is a proxy for, or - * %NULL, if it is not attached to an action. - * - * Since: 2.10 - * - * Deprecated 2.16: Use gtk_activatable_get_related_action() instead. - */ -GtkAction* -gtk_widget_get_action (GtkWidget *widget) -{ - g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL); - - if (GTK_IS_ACTIVATABLE (widget)) - return gtk_activatable_get_related_action (GTK_ACTIVATABLE (widget)); - - return NULL; -} - /** * gtk_action_get_name: * @action: the action object @@ -995,7 +998,7 @@ gtk_widget_get_action (GtkWidget *widget) * * Since: 2.4 **/ -G_CONST_RETURN gchar * +const gchar * gtk_action_get_name (GtkAction *action) { g_return_val_if_fail (GTK_IS_ACTION (action), NULL); @@ -1161,8 +1164,6 @@ gtk_action_set_is_important (GtkAction *action, { g_return_if_fail (GTK_IS_ACTION (action)); - g_return_if_fail (GTK_IS_ACTION (action)); - is_important = is_important != FALSE; if (action->private_data->is_important != is_important) @@ -1191,6 +1192,59 @@ gtk_action_get_is_important (GtkAction *action) return action->private_data->is_important; } +/** + * gtk_action_set_always_show_image: + * @action: a #GtkAction + * @always_show: %TRUE if menuitem proxies should always show their image + * + * Sets whether @action's menu item proxies will ignore the + * #GtkSettings:gtk-menu-images setting and always show their image, if available. + * + * Use this if the menu item would be useless or hard to use + * without their image. + * + * Since: 2.20 + */ +void +gtk_action_set_always_show_image (GtkAction *action, + gboolean always_show) +{ + GtkActionPrivate *priv; + + g_return_if_fail (GTK_IS_ACTION (action)); + + priv = action->private_data; + + always_show = always_show != FALSE; + + if (priv->always_show_image != always_show) + { + priv->always_show_image = always_show; + + g_object_notify (G_OBJECT (action), "always-show-image"); + } +} + +/** + * gtk_action_get_always_show_image: + * @action: a #GtkAction + * + * Returns whether @action's menu item proxies will ignore the + * #GtkSettings:gtk-menu-images setting and always show their image, + * if available. + * + * Returns: %TRUE if the menu item proxies will always show their image + * + * Since: 2.20 + */ +gboolean +gtk_action_get_always_show_image (GtkAction *action) +{ + g_return_val_if_fail (GTK_IS_ACTION (action), FALSE); + + return action->private_data->always_show_image; +} + /** * gtk_action_set_label: * @action: a #GtkAction @@ -1241,7 +1295,7 @@ gtk_action_set_label (GtkAction *action, * * Since: 2.16 */ -G_CONST_RETURN gchar * +const gchar * gtk_action_get_label (GtkAction *action) { g_return_val_if_fail (GTK_IS_ACTION (action), NULL); @@ -1252,7 +1306,7 @@ gtk_action_get_label (GtkAction *action) /** * gtk_action_set_short_label: * @action: a #GtkAction - * @label: the label text to set + * @short_label: the label text to set * * Sets a shorter label text on @action. * @@ -1260,14 +1314,14 @@ gtk_action_get_label (GtkAction *action) */ void gtk_action_set_short_label (GtkAction *action, - const gchar *label) + const gchar *short_label) { gchar *tmp; g_return_if_fail (GTK_IS_ACTION (action)); tmp = action->private_data->short_label; - action->private_data->short_label = g_strdup (label); + action->private_data->short_label = g_strdup (short_label); g_free (tmp); action->private_data->short_label_set = (action->private_data->short_label != NULL); /* if short_label is unset, then use the value of label */ @@ -1280,7 +1334,6 @@ gtk_action_set_short_label (GtkAction *action, /** * gtk_action_get_short_label: * @action: a #GtkAction - * @label: the label text to set * * Gets the short label text of @action. * @@ -1288,7 +1341,7 @@ gtk_action_set_short_label (GtkAction *action, * * Since: 2.16 */ -G_CONST_RETURN gchar * +const gchar * gtk_action_get_short_label (GtkAction *action) { g_return_val_if_fail (GTK_IS_ACTION (action), NULL); @@ -1420,7 +1473,7 @@ gtk_action_set_tooltip (GtkAction *action, * * Since: 2.16 */ -G_CONST_RETURN gchar * +const gchar * gtk_action_get_tooltip (GtkAction *action) { g_return_val_if_fail (GTK_IS_ACTION (action), NULL); @@ -1431,7 +1484,7 @@ gtk_action_get_tooltip (GtkAction *action) /** * gtk_action_set_stock_id: * @action: a #GtkAction - * @tooltip: the tooltip text + * @stock_id: the stock id * * Sets the stock id on @action * @@ -1478,7 +1531,7 @@ gtk_action_set_stock_id (GtkAction *action, * * Since: 2.16 */ -G_CONST_RETURN gchar * +const gchar * gtk_action_get_stock_id (GtkAction *action) { g_return_val_if_fail (GTK_IS_ACTION (action), NULL); @@ -1489,7 +1542,7 @@ gtk_action_get_stock_id (GtkAction *action) /** * gtk_action_set_icon_name: * @action: a #GtkAction - * @tooltip: the icon name to set + * @icon_name: the icon name to set * * Sets the icon name on @action * @@ -1503,8 +1556,6 @@ gtk_action_set_icon_name (GtkAction *action, g_return_if_fail (GTK_IS_ACTION (action)); - g_return_if_fail (GTK_IS_ACTION (action)); - tmp = action->private_data->icon_name; action->private_data->icon_name = g_strdup (icon_name); g_free (tmp); @@ -1522,7 +1573,7 @@ gtk_action_set_icon_name (GtkAction *action, * * Since: 2.16 */ -G_CONST_RETURN gchar * +const gchar * gtk_action_get_icon_name (GtkAction *action) { g_return_val_if_fail (GTK_IS_ACTION (action), NULL); @@ -1562,7 +1613,7 @@ gtk_action_set_gicon (GtkAction *action, * * Gets the gicon of @action. * - * Returns: The action's #GIcon if one is set. + * Returns: (transfer none): The action's #GIcon if one is set. * * Since: 2.16 */ @@ -1574,58 +1625,6 @@ gtk_action_get_gicon (GtkAction *action) return action->private_data->gicon; } -/** - * gtk_action_block_activate_from: - * @action: the action object - * @proxy: a proxy widget - * - * Disables calls to the gtk_action_activate() - * function by signals on the given proxy widget. This is used to - * break notification loops for things like check or radio actions. - * - * This function is intended for use by action implementations. - * - * Since: 2.4 - * - * Deprecated 2.16: activatables are now responsible for activating the - * action directly so this doesnt apply anymore. - */ -void -gtk_action_block_activate_from (GtkAction *action, - GtkWidget *proxy) -{ - g_return_if_fail (GTK_IS_ACTION (action)); - - g_signal_handlers_block_by_func (proxy, G_CALLBACK (gtk_action_activate), - action); -} - -/** - * gtk_action_unblock_activate_from: - * @action: the action object - * @proxy: a proxy widget - * - * Re-enables calls to the gtk_action_activate() - * function by signals on the given proxy widget. This undoes the - * blocking done by gtk_action_block_activate_from(). - * - * This function is intended for use by action implementations. - * - * Since: 2.4 - * - * Deprecated 2.16: activatables are now responsible for activating the - * action directly so this doesnt apply anymore. - */ -void -gtk_action_unblock_activate_from (GtkAction *action, - GtkWidget *proxy) -{ - g_return_if_fail (GTK_IS_ACTION (action)); - - g_signal_handlers_unblock_by_func (proxy, G_CALLBACK (gtk_action_activate), - action); -} - static void closure_accel_activate (GClosure *closure, GValue *return_value, @@ -1691,7 +1690,7 @@ gtk_action_set_accel_path (GtkAction *action, * if none is set. The returned string is owned by GTK+ * and must not be freed or modified. */ -G_CONST_RETURN gchar * +const gchar * gtk_action_get_accel_path (GtkAction *action) { g_return_val_if_fail (GTK_IS_ACTION (action), NULL); @@ -1710,8 +1709,9 @@ gtk_action_get_accel_path (GtkAction *action) * * Since: 2.8 * - * Returns: the accel closure for this action. The returned closure is - * owned by GTK+ and must not be unreffed or modified. + * Returns: (transfer none): the accel closure for this action. The + * returned closure is owned by GTK+ and must not be unreffed + * or modified. */ GClosure * gtk_action_get_accel_closure (GtkAction *action) @@ -1725,8 +1725,8 @@ gtk_action_get_accel_closure (GtkAction *action) /** * gtk_action_set_accel_group: * @action: the action object - * @accel_group: a #GtkAccelGroup or %NULL - * + * @accel_group: (allow-none): a #GtkAccelGroup or %NULL + * * Sets the #GtkAccelGroup in which the accelerator for this action * will be installed. * @@ -1816,7 +1816,8 @@ gtk_action_disconnect_accelerator (GtkAction *action) * item or the toolbar item it creates, this function returns an * instance of that menu. * - * Return value: the menu item provided by the action, or %NULL. + * Return value: (transfer none): the menu item provided by the + * action, or %NULL. * * Since: 2.12 */ @@ -1830,6 +1831,3 @@ gtk_action_create_menu (GtkAction *action) return NULL; } - -#define __GTK_ACTION_C__ -#include "gtkaliasdef.c"