/* gtkactivatable.c
 * Copyright (C) 2006-2007 Async Open Source,
 *                         Johan Dahlin <jdahlin@async.com.br>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */


#include "config.h"
#include "gtkactivatable.h"
#include "gtktypeutils.h"
#include "gtkintl.h"
#include "gtkalias.h"


static void gtk_activatable_class_init (gpointer g_iface);

GType
gtk_activatable_get_type (void)
{
  static GType activatable_type = 0;

  if (!activatable_type)
    activatable_type =
      g_type_register_static_simple (G_TYPE_INTERFACE, I_("GtkActivatable"),
				     sizeof (GtkActivatableIface),
				     (GClassInitFunc) gtk_activatable_class_init,
				     0, NULL, 0);

  return activatable_type;
}

static void
gtk_activatable_class_init (gpointer g_iface)
{
  /**
   * GtkActivatable:related-action:
   * 
   * The action that this activatable will activate and recieve
   * updates from for various states and possibly appearance.
   *
   * Since: 2.16
   */
  g_object_interface_install_property (g_iface,
				       g_param_spec_object ("related-action",
							    P_("Related Action"),
							    P_("The action this activatable will activate and receive updates from"),
							    GTK_TYPE_ACTION,
							    GTK_PARAM_READWRITE));

  /**
   * GtkActivatable:use-action-appearance:
   * 
   * Whether this activatable should reset its layout
   * and appearance when setting the related action or when
   * the action changes appearance 
   *
   * Since: 2.16
   */
  g_object_interface_install_property (g_iface,
				       g_param_spec_boolean ("use-action-appearance",
							     P_("Use Action Appearance"),
							     P_("Whether to use the related actions appearance properties"),
							     FALSE,
							     GTK_PARAM_READWRITE));


}


/**
 * gtk_activatable_update:
 * @activatable: a #GtkActivatable
 * @property_name: the name of the action property to update from, or %NULL
 *
 * This is called when @activatable needs to be updated for a property
 * change on its related action. When called with %NULL, as when setting
 * the action initially, all relavent properties should be updated.
 *
 * Since: 2.16
 **/
void
gtk_activatable_update (GtkActivatable *activatable,
			const gchar    *property_name)
{
  GtkActivatableIface *iface;

  g_return_if_fail (GTK_IS_ACTIVATABLE (activatable));

  iface = GTK_ACTIVATABLE_GET_IFACE (activatable);
  if (iface->update)
    iface->update (activatable);
  else
    g_critical ("GtkActivatable->update() unimplemented for type %s", 
		g_type_name (G_OBJECT_TYPE (activatable)));
}


/**
 * gtk_activatable_set_related_action:
 * @activatable: a #GtkActivatable
 * @action: the #GtkAction to set
 *
 * Sets the related action on the @activatable object.
 *
 * Since: 2.16
 **/
void
gtk_activatable_set_related_action (GtkActivatable *activatable,
				    GtkAction      *action)
{
  g_return_if_fail (GTK_IS_ACTIVATABLE (activatable));
  g_return_if_fail (action == NULL || GTK_IS_ACTION (action));

  g_object_set (activatable, "related-action", action, NULL);
}

/**
 * gtk_activatable_get_related_action:
 * @activatable: a #GtkActivatable
 *
 * Gets the related #GtkAction for @activatable.
 *
 * Returns: the related #GtkAction if one is set.
 *
 * Since: 2.16
 **/
GtkAction *
gtk_activatable_get_related_action (GtkActivatable *activatable);
{
  GtkAction *action;

  g_return_if_fail (GTK_IS_ACTIVATABLE (activatable));

  g_object_get (activatable, "related-action", &action, NULL);

  /* g_object_get() gives us a ref... */
  if (action)
    g_object_unref (action);

  return action;
}

/**
 * gtk_activatable_set_use_action_appearance:
 * @activatable: a #GtkActivatable
 * @use_appearance: whether to use the actions appearance
 *
 * Sets whether this activatable should reset its layout
 * and appearance when setting the related action or when
 * the action changes appearance 
 *
 * <para><note>If set to %TRUE with a related action set, 
 * this will also update the appearance.</note></para>
 *
 * Since: 2.16
 **/
void
gtk_activatable_set_use_action_appearance  (GtkActivatable *activatable,
					    gboolean        use_appearance)
{
  g_object_set (activatable, "use-action-appearance", use_appearance, NULL);
}

/**
 * gtk_activatable_get_use_action_appearance:
 * @activatable: a #GtkActivatable
 *
 * Gets whether this activatable should reset its layout
 * and appearance when setting the related action or when
 * the action changes appearance.
 *
 * Returns: whether @activatable uses its actions appearance.
 *
 * Since: 2.16
 **/
gboolean
gtk_activatable_get_use_action_appearance  (GtkActivatable *activatable)
{
  gboolean use_appearance;

  g_object_get (activatable, "use-action-appearance", &use_appearance, NULL);  

  return use_appearance;
}

#define __GTK_ACTIVATABLE_C__
#include "gtkaliasdef.c"
