Blame gtk/gtkactivatable.c

Packit 98cdb6
/* gtkactivatable.c
Packit 98cdb6
 * Copyright (C) 2008 Tristan Van Berkom <tristan.van.berkom@gmail.com>
Packit 98cdb6
 *
Packit 98cdb6
 * This library is free software; you can redistribute it and/or
Packit 98cdb6
 * modify it under the terms of the GNU Library General Public
Packit 98cdb6
 * License as published by the Free Software Foundation; either
Packit 98cdb6
 * version 2 of the License, or (at your option) any later version.
Packit 98cdb6
 *
Packit 98cdb6
 * This library is distributed in the hope that it will be useful,
Packit 98cdb6
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 98cdb6
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 98cdb6
 * Library General Public License for more details.
Packit 98cdb6
 *
Packit 98cdb6
 * You should have received a copy of the GNU Library General Public
Packit 98cdb6
 * License along with this library; if not, write to the
Packit 98cdb6
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Packit 98cdb6
 * Boston, MA 02111-1307, USA.
Packit 98cdb6
 */
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * SECTION:gtkactivatable
Packit 98cdb6
 * @Short_Description: An interface for activatable widgets
Packit 98cdb6
 * @Title: GtkActivatable
Packit 98cdb6
 *
Packit 98cdb6
 * Activatable widgets can be connected to a #GtkAction and reflects
Packit 98cdb6
 * the state of its action. A #GtkActivatable can also provide feedback
Packit 98cdb6
 * through its action, as they are responsible for activating their
Packit 98cdb6
 * related actions.
Packit 98cdb6
 *
Packit 98cdb6
 * <refsect2>
Packit 98cdb6
 * <title>Implementing GtkActivatable</title>
Packit 98cdb6
 * <para>
Packit 98cdb6
 * When extending a class that is already #GtkActivatable; it is only
Packit 98cdb6
 * necessary to implement the #GtkActivatable->sync_action_properties()
Packit 98cdb6
 * and #GtkActivatable->update() methods and chain up to the parent
Packit 98cdb6
 * implementation, however when introducing
Packit 98cdb6
 * a new #GtkActivatable class; the #GtkActivatable:related-action and
Packit 98cdb6
 * #GtkActivatable:use-action-appearance properties need to be handled by
Packit 98cdb6
 * the implementor. Handling these properties is mostly a matter of installing
Packit 98cdb6
 * the action pointer and boolean flag on your instance, and calling
Packit 98cdb6
 * gtk_activatable_do_set_related_action() and
Packit 98cdb6
 * gtk_activatable_sync_action_properties() at the appropriate times.
Packit 98cdb6
 * </para>
Packit 98cdb6
 * <example>
Packit 98cdb6
 * <title>A class fragment implementing #GtkActivatable</title>
Packit 98cdb6
 * <programlisting>
Packit 98cdb6
 *
Packit 98cdb6
 * enum {
Packit 98cdb6
 * ...
Packit 98cdb6
 *
Packit 98cdb6
 * PROP_ACTIVATABLE_RELATED_ACTION,
Packit 98cdb6
 * PROP_ACTIVATABLE_USE_ACTION_APPEARANCE
Packit 98cdb6
 * }
Packit 98cdb6
 * 
Packit 98cdb6
 * struct _FooBarPrivate
Packit 98cdb6
 * {
Packit 98cdb6
 * 
Packit 98cdb6
 *   ...
Packit 98cdb6
 * 
Packit 98cdb6
 *   GtkAction      *action;
Packit 98cdb6
 *   gboolean        use_action_appearance;
Packit 98cdb6
 * };
Packit 98cdb6
 * 
Packit 98cdb6
 * ...
Packit 98cdb6
 * 
Packit 98cdb6
 * static void foo_bar_activatable_interface_init         (GtkActivatableIface  *iface);
Packit 98cdb6
 * static void foo_bar_activatable_update                 (GtkActivatable       *activatable,
Packit 98cdb6
 * 						           GtkAction            *action,
Packit 98cdb6
 * 						           const gchar          *property_name);
Packit 98cdb6
 * static void foo_bar_activatable_sync_action_properties (GtkActivatable       *activatable,
Packit 98cdb6
 * 						           GtkAction            *action);
Packit 98cdb6
 * ...
Packit 98cdb6
 *
Packit 98cdb6
 *
Packit 98cdb6
 * static void
Packit 98cdb6
 * foo_bar_class_init (FooBarClass *klass)
Packit 98cdb6
 * {
Packit 98cdb6
 *
Packit 98cdb6
 *   ...
Packit 98cdb6
 *
Packit 98cdb6
 *   g_object_class_override_property (gobject_class, PROP_ACTIVATABLE_RELATED_ACTION, "related-action");
Packit 98cdb6
 *   g_object_class_override_property (gobject_class, PROP_ACTIVATABLE_USE_ACTION_APPEARANCE, "use-action-appearance");
Packit 98cdb6
 *
Packit 98cdb6
 *   ...
Packit 98cdb6
 * }
Packit 98cdb6
 *
Packit 98cdb6
 *
Packit 98cdb6
 * static void
Packit 98cdb6
 * foo_bar_activatable_interface_init (GtkActivatableIface  *iface)
Packit 98cdb6
 * {
Packit 98cdb6
 *   iface->update = foo_bar_activatable_update;
Packit 98cdb6
 *   iface->sync_action_properties = foo_bar_activatable_sync_action_properties;
Packit 98cdb6
 * }
Packit 98cdb6
 * 
Packit 98cdb6
 * ... Break the reference using gtk_activatable_do_set_related_action()...
Packit 98cdb6
 *
Packit 98cdb6
 * static void 
Packit 98cdb6
 * foo_bar_dispose (GObject *object)
Packit 98cdb6
 * {
Packit 98cdb6
 *   FooBar *bar = FOO_BAR (object);
Packit 98cdb6
 *   FooBarPrivate *priv = FOO_BAR_GET_PRIVATE (bar);
Packit 98cdb6
 * 
Packit 98cdb6
 *   ...
Packit 98cdb6
 * 
Packit 98cdb6
 *   if (priv->action)
Packit 98cdb6
 *     {
Packit 98cdb6
 *       gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (bar), NULL);
Packit 98cdb6
 *       priv->action = NULL;
Packit 98cdb6
 *     }
Packit 98cdb6
 *   G_OBJECT_CLASS (foo_bar_parent_class)->dispose (object);
Packit 98cdb6
 * }
Packit 98cdb6
 * 
Packit 98cdb6
 * ... Handle the "related-action" and "use-action-appearance" properties ...
Packit 98cdb6
 *
Packit 98cdb6
 * static void
Packit 98cdb6
 * foo_bar_set_property (GObject         *object,
Packit 98cdb6
 *                       guint            prop_id,
Packit 98cdb6
 *                       const GValue    *value,
Packit 98cdb6
 *                       GParamSpec      *pspec)
Packit 98cdb6
 * {
Packit 98cdb6
 *   FooBar *bar = FOO_BAR (object);
Packit 98cdb6
 *   FooBarPrivate *priv = FOO_BAR_GET_PRIVATE (bar);
Packit 98cdb6
 * 
Packit 98cdb6
 *   switch (prop_id)
Packit 98cdb6
 *     {
Packit 98cdb6
 * 
Packit 98cdb6
 *       ...
Packit 98cdb6
 * 
Packit 98cdb6
 *     case PROP_ACTIVATABLE_RELATED_ACTION:
Packit 98cdb6
 *       foo_bar_set_related_action (bar, g_value_get_object (value));
Packit 98cdb6
 *       break;
Packit 98cdb6
 *     case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE:
Packit 98cdb6
 *       foo_bar_set_use_action_appearance (bar, g_value_get_boolean (value));
Packit 98cdb6
 *       break;
Packit 98cdb6
 *     default:
Packit 98cdb6
 *       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
Packit 98cdb6
 *       break;
Packit 98cdb6
 *     }
Packit 98cdb6
 * }
Packit 98cdb6
 * 
Packit 98cdb6
 * static void
Packit 98cdb6
 * foo_bar_get_property (GObject         *object,
Packit 98cdb6
 *                          guint            prop_id,
Packit 98cdb6
 *                          GValue          *value,
Packit 98cdb6
 *                          GParamSpec      *pspec)
Packit 98cdb6
 * {
Packit 98cdb6
 *   FooBar *bar = FOO_BAR (object);
Packit 98cdb6
 *   FooBarPrivate *priv = FOO_BAR_GET_PRIVATE (bar);
Packit 98cdb6
 * 
Packit 98cdb6
 *   switch (prop_id)
Packit 98cdb6
 *     { 
Packit 98cdb6
 * 
Packit 98cdb6
 *       ...
Packit 98cdb6
 * 
Packit 98cdb6
 *     case PROP_ACTIVATABLE_RELATED_ACTION:
Packit 98cdb6
 *       g_value_set_object (value, priv->action);
Packit 98cdb6
 *       break;
Packit 98cdb6
 *     case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE:
Packit 98cdb6
 *       g_value_set_boolean (value, priv->use_action_appearance);
Packit 98cdb6
 *       break;
Packit 98cdb6
 *     default:
Packit 98cdb6
 *       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
Packit 98cdb6
 *       break;
Packit 98cdb6
 *     }
Packit 98cdb6
 * }
Packit 98cdb6
 * 
Packit 98cdb6
 * 
Packit 98cdb6
 * static void
Packit 98cdb6
 * foo_bar_set_use_action_appearance (FooBar   *bar, 
Packit 98cdb6
 * 				   gboolean  use_appearance)
Packit 98cdb6
 * {
Packit 98cdb6
 *   FooBarPrivate *priv = FOO_BAR_GET_PRIVATE (bar);
Packit 98cdb6
 * 
Packit 98cdb6
 *   if (priv->use_action_appearance != use_appearance)
Packit 98cdb6
 *     {
Packit 98cdb6
 *       priv->use_action_appearance = use_appearance;
Packit 98cdb6
 *       
Packit 98cdb6
 *       gtk_activatable_sync_action_properties (GTK_ACTIVATABLE (bar), priv->action);
Packit 98cdb6
 *     }
Packit 98cdb6
 * }
Packit 98cdb6
 * 
Packit 98cdb6
 * ... call gtk_activatable_do_set_related_action() and then assign the action pointer, 
Packit 98cdb6
 * no need to reference the action here since gtk_activatable_do_set_related_action() already 
Packit 98cdb6
 * holds a reference here for you...
Packit 98cdb6
 * static void
Packit 98cdb6
 * foo_bar_set_related_action (FooBar    *bar, 
Packit 98cdb6
 * 			    GtkAction *action)
Packit 98cdb6
 * {
Packit 98cdb6
 *   FooBarPrivate *priv = FOO_BAR_GET_PRIVATE (bar);
Packit 98cdb6
 * 
Packit 98cdb6
 *   if (priv->action == action)
Packit 98cdb6
 *     return;
Packit 98cdb6
 * 
Packit 98cdb6
 *   gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (bar), action);
Packit 98cdb6
 * 
Packit 98cdb6
 *   priv->action = action;
Packit 98cdb6
 * }
Packit 98cdb6
 * 
Packit 98cdb6
 * ... Selectively reset and update activatable depending on the use-action-appearance property ...
Packit 98cdb6
 * static void
Packit 98cdb6
 * gtk_button_activatable_sync_action_properties (GtkActivatable       *activatable,
Packit 98cdb6
 * 		                                  GtkAction            *action)
Packit 98cdb6
 * {
Packit 98cdb6
 *   GtkButtonPrivate *priv = GTK_BUTTON_GET_PRIVATE (activatable);
Packit 98cdb6
 * 
Packit 98cdb6
 *   if (!action)
Packit 98cdb6
 *     return;
Packit 98cdb6
 * 
Packit 98cdb6
 *   if (gtk_action_is_visible (action))
Packit 98cdb6
 *     gtk_widget_show (GTK_WIDGET (activatable));
Packit 98cdb6
 *   else
Packit 98cdb6
 *     gtk_widget_hide (GTK_WIDGET (activatable));
Packit 98cdb6
 *   
Packit 98cdb6
 *   gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action));
Packit 98cdb6
 * 
Packit 98cdb6
 *   ...
Packit 98cdb6
 *   
Packit 98cdb6
 *   if (priv->use_action_appearance)
Packit 98cdb6
 *     {
Packit 98cdb6
 *       if (gtk_action_get_stock_id (action))
Packit 98cdb6
 * 	foo_bar_set_stock (button, gtk_action_get_stock_id (action));
Packit 98cdb6
 *       else if (gtk_action_get_label (action))
Packit 98cdb6
 * 	foo_bar_set_label (button, gtk_action_get_label (action));
Packit 98cdb6
 * 
Packit 98cdb6
 *       ...
Packit 98cdb6
 * 
Packit 98cdb6
 *     }
Packit 98cdb6
 * }
Packit 98cdb6
 * 
Packit 98cdb6
 * static void 
Packit 98cdb6
 * foo_bar_activatable_update (GtkActivatable       *activatable,
Packit 98cdb6
 * 			       GtkAction            *action,
Packit 98cdb6
 * 			       const gchar          *property_name)
Packit 98cdb6
 * {
Packit 98cdb6
 *   FooBarPrivate *priv = FOO_BAR_GET_PRIVATE (activatable);
Packit 98cdb6
 * 
Packit 98cdb6
 *   if (strcmp (property_name, "visible") == 0)
Packit 98cdb6
 *     {
Packit 98cdb6
 *       if (gtk_action_is_visible (action))
Packit 98cdb6
 * 	gtk_widget_show (GTK_WIDGET (activatable));
Packit 98cdb6
 *       else
Packit 98cdb6
 * 	gtk_widget_hide (GTK_WIDGET (activatable));
Packit 98cdb6
 *     }
Packit 98cdb6
 *   else if (strcmp (property_name, "sensitive") == 0)
Packit 98cdb6
 *     gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action));
Packit 98cdb6
 * 
Packit 98cdb6
 *   ...
Packit 98cdb6
 * 
Packit 98cdb6
 *   if (!priv->use_action_appearance)
Packit 98cdb6
 *     return;
Packit 98cdb6
 * 
Packit 98cdb6
 *   if (strcmp (property_name, "stock-id") == 0)
Packit 98cdb6
 *     foo_bar_set_stock (button, gtk_action_get_stock_id (action));
Packit 98cdb6
 *   else if (strcmp (property_name, "label") == 0)
Packit 98cdb6
 *     foo_bar_set_label (button, gtk_action_get_label (action));
Packit 98cdb6
 * 
Packit 98cdb6
 *   ...
Packit 98cdb6
 * }]]></programlisting>
Packit 98cdb6
 * </example>
Packit 98cdb6
 * </refsect2>
Packit 98cdb6
 */
Packit 98cdb6
Packit 98cdb6
#include "config.h"
Packit 98cdb6
#include "gtkactivatable.h"
Packit 98cdb6
#include "gtkactiongroup.h"
Packit 98cdb6
#include "gtktypeutils.h"
Packit 98cdb6
#include "gtkprivate.h"
Packit 98cdb6
#include "gtkintl.h"
Packit 98cdb6
#include "gtkalias.h"
Packit 98cdb6
Packit 98cdb6
Packit 98cdb6
static void gtk_activatable_class_init (gpointer g_iface);
Packit 98cdb6
Packit 98cdb6
GType
Packit 98cdb6
gtk_activatable_get_type (void)
Packit 98cdb6
{
Packit 98cdb6
  static GType activatable_type = 0;
Packit 98cdb6
Packit 98cdb6
  if (!activatable_type) {
Packit 98cdb6
    activatable_type =
Packit 98cdb6
      g_type_register_static_simple (G_TYPE_INTERFACE, I_("GtkActivatable"),
Packit 98cdb6
				     sizeof (GtkActivatableIface),
Packit 98cdb6
				     (GClassInitFunc) gtk_activatable_class_init,
Packit 98cdb6
				     0, NULL, 0);
Packit 98cdb6
Packit 98cdb6
    g_type_interface_add_prerequisite (activatable_type, G_TYPE_OBJECT);
Packit 98cdb6
  }
Packit 98cdb6
Packit 98cdb6
  return activatable_type;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_activatable_class_init (gpointer g_iface)
Packit 98cdb6
{
Packit 98cdb6
  /**
Packit 98cdb6
   * GtkActivatable:related-action:
Packit 98cdb6
   * 
Packit 98cdb6
   * The action that this activatable will activate and receive
Packit 98cdb6
   * updates from for various states and possibly appearance.
Packit 98cdb6
   *
Packit 98cdb6
   * <note><para>#GtkActivatable implementors need to handle the this property and 
Packit 98cdb6
   * call gtk_activatable_do_set_related_action() when it changes.</para></note>
Packit 98cdb6
   *
Packit 98cdb6
   * Since: 2.16
Packit 98cdb6
   */
Packit 98cdb6
  g_object_interface_install_property (g_iface,
Packit 98cdb6
				       g_param_spec_object ("related-action",
Packit 98cdb6
							    P_("Related Action"),
Packit 98cdb6
							    P_("The action this activatable will activate and receive updates from"),
Packit 98cdb6
							    GTK_TYPE_ACTION,
Packit 98cdb6
							    GTK_PARAM_READWRITE));
Packit 98cdb6
Packit 98cdb6
  /**
Packit 98cdb6
   * GtkActivatable:use-action-appearance:
Packit 98cdb6
   * 
Packit 98cdb6
   * Whether this activatable should reset its layout
Packit 98cdb6
   * and appearance when setting the related action or when
Packit 98cdb6
   * the action changes appearance.
Packit 98cdb6
   *
Packit 98cdb6
   * See the #GtkAction documentation directly to find which properties
Packit 98cdb6
   * should be ignored by the #GtkActivatable when this property is %FALSE.
Packit 98cdb6
   *
Packit 98cdb6
   * <note><para>#GtkActivatable implementors need to handle this property
Packit 98cdb6
   * and call gtk_activatable_sync_action_properties() on the activatable
Packit 98cdb6
   * widget when it changes.</para></note>
Packit 98cdb6
   *
Packit 98cdb6
   * Since: 2.16
Packit 98cdb6
   */
Packit 98cdb6
  g_object_interface_install_property (g_iface,
Packit 98cdb6
				       g_param_spec_boolean ("use-action-appearance",
Packit 98cdb6
							     P_("Use Action Appearance"),
Packit 98cdb6
							     P_("Whether to use the related actions appearance properties"),
Packit 98cdb6
							     TRUE,
Packit 98cdb6
							     GTK_PARAM_READWRITE));
Packit 98cdb6
Packit 98cdb6
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_activatable_update (GtkActivatable *activatable,
Packit 98cdb6
			GtkAction      *action,
Packit 98cdb6
			const gchar    *property_name)
Packit 98cdb6
{
Packit 98cdb6
  GtkActivatableIface *iface;
Packit 98cdb6
Packit 98cdb6
  g_return_if_fail (GTK_IS_ACTIVATABLE (activatable));
Packit 98cdb6
Packit 98cdb6
  iface = GTK_ACTIVATABLE_GET_IFACE (activatable);
Packit 98cdb6
  if (iface->update)
Packit 98cdb6
    iface->update (activatable, action, property_name);
Packit 98cdb6
  else
Packit 98cdb6
    g_critical ("GtkActivatable->update() unimplemented for type %s", 
Packit 98cdb6
		g_type_name (G_OBJECT_TYPE (activatable)));
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gtk_activatable_sync_action_properties:
Packit 98cdb6
 * @activatable: a #GtkActivatable
Packit 98cdb6
 * @action: (allow-none): the related #GtkAction or %NULL
Packit 98cdb6
 *
Packit 98cdb6
 * This is called to update the activatable completely, this is called
Packit 98cdb6
 * internally when the #GtkActivatable::related-action property is set
Packit 98cdb6
 * or unset and by the implementing class when
Packit 98cdb6
 * #GtkActivatable::use-action-appearance changes.
Packit 98cdb6
 *
Packit 98cdb6
 * Since: 2.16
Packit 98cdb6
 **/
Packit 98cdb6
void
Packit 98cdb6
gtk_activatable_sync_action_properties (GtkActivatable *activatable,
Packit 98cdb6
		                        GtkAction      *action)
Packit 98cdb6
{
Packit 98cdb6
  GtkActivatableIface *iface;
Packit 98cdb6
Packit 98cdb6
  g_return_if_fail (GTK_IS_ACTIVATABLE (activatable));
Packit 98cdb6
Packit 98cdb6
  iface = GTK_ACTIVATABLE_GET_IFACE (activatable);
Packit 98cdb6
  if (iface->sync_action_properties)
Packit 98cdb6
    iface->sync_action_properties (activatable, action);
Packit 98cdb6
  else
Packit 98cdb6
    g_critical ("GtkActivatable->sync_action_properties() unimplemented for type %s", 
Packit 98cdb6
		g_type_name (G_OBJECT_TYPE (activatable)));
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gtk_activatable_set_related_action:
Packit 98cdb6
 * @activatable: a #GtkActivatable
Packit 98cdb6
 * @action: the #GtkAction to set
Packit 98cdb6
 *
Packit 98cdb6
 * Sets the related action on the @activatable object.
Packit 98cdb6
 *
Packit 98cdb6
 * <note><para>#GtkActivatable implementors need to handle the #GtkActivatable:related-action
Packit 98cdb6
 * property and call gtk_activatable_do_set_related_action() when it changes.</para></note>
Packit 98cdb6
 *
Packit 98cdb6
 * Since: 2.16
Packit 98cdb6
 **/
Packit 98cdb6
void
Packit 98cdb6
gtk_activatable_set_related_action (GtkActivatable *activatable,
Packit 98cdb6
				    GtkAction      *action)
Packit 98cdb6
{
Packit 98cdb6
  g_return_if_fail (GTK_IS_ACTIVATABLE (activatable));
Packit 98cdb6
  g_return_if_fail (action == NULL || GTK_IS_ACTION (action));
Packit 98cdb6
Packit 98cdb6
  g_object_set (activatable, "related-action", action, NULL);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_activatable_action_notify (GtkAction      *action,
Packit 98cdb6
			       GParamSpec     *pspec,
Packit 98cdb6
			       GtkActivatable *activatable)
Packit 98cdb6
{
Packit 98cdb6
  gtk_activatable_update (activatable, action, pspec->name);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gtk_activatable_do_set_related_action:
Packit 98cdb6
 * @activatable: a #GtkActivatable
Packit 98cdb6
 * @action: the #GtkAction to set
Packit 98cdb6
 * 
Packit 98cdb6
 * This is a utility function for #GtkActivatable implementors.
Packit 98cdb6
 * 
Packit 98cdb6
 * When implementing #GtkActivatable you must call this when
Packit 98cdb6
 * handling changes of the #GtkActivatable:related-action, and
Packit 98cdb6
 * you must also use this to break references in #GObject->dispose().
Packit 98cdb6
 *
Packit 98cdb6
 * This function adds a reference to the currently set related
Packit 98cdb6
 * action for you, it also makes sure the #GtkActivatable->update()
Packit 98cdb6
 * method is called when the related #GtkAction properties change
Packit 98cdb6
 * and registers to the action's proxy list.
Packit 98cdb6
 *
Packit 98cdb6
 * <note><para>Be careful to call this before setting the local
Packit 98cdb6
 * copy of the #GtkAction property, since this function uses 
Packit 98cdb6
 * gtk_activatable_get_action() to retrieve the previous action</para></note>
Packit 98cdb6
 *
Packit 98cdb6
 * Since: 2.16
Packit 98cdb6
 */
Packit 98cdb6
void
Packit 98cdb6
gtk_activatable_do_set_related_action (GtkActivatable *activatable,
Packit 98cdb6
				       GtkAction      *action)
Packit 98cdb6
{
Packit 98cdb6
  GtkAction *prev_action;
Packit 98cdb6
Packit 98cdb6
  prev_action = gtk_activatable_get_related_action (activatable);
Packit 98cdb6
  
Packit 98cdb6
  if (prev_action != action)
Packit 98cdb6
    {
Packit 98cdb6
      if (prev_action)
Packit 98cdb6
	{
Packit 98cdb6
	  g_signal_handlers_disconnect_by_func (prev_action, gtk_activatable_action_notify, activatable);
Packit 98cdb6
	  
Packit 98cdb6
          /* Check the type so that actions can be activatable too. */
Packit 98cdb6
          if (GTK_IS_WIDGET (activatable))
Packit 98cdb6
            _gtk_action_remove_from_proxy_list (prev_action, GTK_WIDGET (activatable));
Packit 98cdb6
	  
Packit 98cdb6
          /* Some apps are using the object data directly...
Packit 98cdb6
           * so continue to set it for a bit longer
Packit 98cdb6
           */
Packit 98cdb6
          g_object_set_data (G_OBJECT (activatable), "gtk-action", NULL);
Packit 98cdb6
Packit 98cdb6
          /*
Packit 98cdb6
           * We don't want prev_action to be activated
Packit 98cdb6
           * during the sync_action_properties() call when syncing "active".
Packit 98cdb6
           */ 
Packit 98cdb6
          gtk_action_block_activate (prev_action);
Packit 98cdb6
	}
Packit 98cdb6
      
Packit 98cdb6
      /* Some applications rely on their proxy UI to be set up
Packit 98cdb6
       * before they receive the ::connect-proxy signal, so we
Packit 98cdb6
       * need to call sync_action_properties() before add_to_proxy_list().
Packit 98cdb6
       */
Packit 98cdb6
      gtk_activatable_sync_action_properties (activatable, action);
Packit 98cdb6
Packit 98cdb6
      if (prev_action)
Packit 98cdb6
        {
Packit 98cdb6
          gtk_action_unblock_activate (prev_action);
Packit 98cdb6
	  g_object_unref (prev_action);
Packit 98cdb6
        }
Packit 98cdb6
Packit 98cdb6
      if (action)
Packit 98cdb6
	{
Packit 98cdb6
	  g_object_ref (action);
Packit 98cdb6
Packit 98cdb6
	  g_signal_connect (G_OBJECT (action), "notify", G_CALLBACK (gtk_activatable_action_notify), activatable);
Packit 98cdb6
Packit 98cdb6
          if (GTK_IS_WIDGET (activatable))
Packit 98cdb6
            _gtk_action_add_to_proxy_list (action, GTK_WIDGET (activatable));
Packit 98cdb6
Packit 98cdb6
          g_object_set_data (G_OBJECT (activatable), "gtk-action", action);
Packit 98cdb6
	}
Packit 98cdb6
    }
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gtk_activatable_get_related_action:
Packit 98cdb6
 * @activatable: a #GtkActivatable
Packit 98cdb6
 *
Packit 98cdb6
 * Gets the related #GtkAction for @activatable.
Packit 98cdb6
 *
Packit 98cdb6
 * Returns: (transfer none): the related #GtkAction if one is set.
Packit 98cdb6
 *
Packit 98cdb6
 * Since: 2.16
Packit 98cdb6
 **/
Packit 98cdb6
GtkAction *
Packit 98cdb6
gtk_activatable_get_related_action (GtkActivatable *activatable)
Packit 98cdb6
{
Packit 98cdb6
  GtkAction *action;
Packit 98cdb6
Packit 98cdb6
  g_return_val_if_fail (GTK_IS_ACTIVATABLE (activatable), NULL);
Packit 98cdb6
Packit 98cdb6
  g_object_get (activatable, "related-action", &action, NULL);
Packit 98cdb6
Packit 98cdb6
  /* g_object_get() gives us a ref... */
Packit 98cdb6
  if (action)
Packit 98cdb6
    g_object_unref (action);
Packit 98cdb6
Packit 98cdb6
  return action;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gtk_activatable_set_use_action_appearance:
Packit 98cdb6
 * @activatable: a #GtkActivatable
Packit 98cdb6
 * @use_appearance: whether to use the actions appearance
Packit 98cdb6
 *
Packit 98cdb6
 * Sets whether this activatable should reset its layout and appearance
Packit 98cdb6
 * when setting the related action or when the action changes appearance
Packit 98cdb6
 *
Packit 98cdb6
 * <note><para>#GtkActivatable implementors need to handle the
Packit 98cdb6
 * #GtkActivatable:use-action-appearance property and call
Packit 98cdb6
 * gtk_activatable_sync_action_properties() to update @activatable
Packit 98cdb6
 * if needed.</para></note>
Packit 98cdb6
 *
Packit 98cdb6
 * Since: 2.16
Packit 98cdb6
 **/
Packit 98cdb6
void
Packit 98cdb6
gtk_activatable_set_use_action_appearance (GtkActivatable *activatable,
Packit 98cdb6
					   gboolean        use_appearance)
Packit 98cdb6
{
Packit 98cdb6
  g_object_set (activatable, "use-action-appearance", use_appearance, NULL);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gtk_activatable_get_use_action_appearance:
Packit 98cdb6
 * @activatable: a #GtkActivatable
Packit 98cdb6
 *
Packit 98cdb6
 * Gets whether this activatable should reset its layout
Packit 98cdb6
 * and appearance when setting the related action or when
Packit 98cdb6
 * the action changes appearance.
Packit 98cdb6
 *
Packit 98cdb6
 * Returns: whether @activatable uses its actions appearance.
Packit 98cdb6
 *
Packit 98cdb6
 * Since: 2.16
Packit 98cdb6
 **/
Packit 98cdb6
gboolean
Packit 98cdb6
gtk_activatable_get_use_action_appearance  (GtkActivatable *activatable)
Packit 98cdb6
{
Packit 98cdb6
  gboolean use_appearance;
Packit 98cdb6
Packit 98cdb6
  g_object_get (activatable, "use-action-appearance", &use_appearance, NULL);  
Packit 98cdb6
Packit 98cdb6
  return use_appearance;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
#define __GTK_ACTIVATABLE_C__
Packit 98cdb6
#include "gtkaliasdef.c"