Blame gtk/gtkradioaction.c

Packit 98cdb6
/*
Packit 98cdb6
 * GTK - The GIMP Toolkit
Packit 98cdb6
 * Copyright (C) 1998, 1999 Red Hat, Inc.
Packit 98cdb6
 * All rights reserved.
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 License as
Packit 98cdb6
 * published by the Free Software Foundation; either version 2 of the
Packit 98cdb6
 * 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 the Gnome Library; see the file COPYING.LIB.  If not,
Packit 98cdb6
 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Packit 98cdb6
 * Boston, MA 02111-1307, USA.
Packit 98cdb6
 */
Packit 98cdb6
Packit 98cdb6
/*
Packit 98cdb6
 * Author: James Henstridge <james@daa.com.au>
Packit 98cdb6
 *
Packit 98cdb6
 * Modified by the GTK+ Team and others 2003.  See the AUTHORS
Packit 98cdb6
 * file for a list of people on the GTK+ Team.  See the ChangeLog
Packit 98cdb6
 * files for a list of changes.  These files are distributed with
Packit 98cdb6
 * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
Packit 98cdb6
 */
Packit 98cdb6
Packit 98cdb6
#include "config.h"
Packit 98cdb6
Packit 98cdb6
#include "gtkradioaction.h"
Packit 98cdb6
#include "gtkradiomenuitem.h"
Packit 98cdb6
#include "gtktoggleactionprivate.h"
Packit 98cdb6
#include "gtktoggletoolbutton.h"
Packit 98cdb6
#include "gtkintl.h"
Packit 98cdb6
#include "gtkprivate.h"
Packit 98cdb6
#include "gtkalias.h"
Packit 98cdb6
Packit 98cdb6
#define GTK_RADIO_ACTION_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_RADIO_ACTION, GtkRadioActionPrivate))
Packit 98cdb6
Packit 98cdb6
struct _GtkRadioActionPrivate 
Packit 98cdb6
{
Packit 98cdb6
  GSList *group;
Packit 98cdb6
  gint    value;
Packit 98cdb6
};
Packit 98cdb6
Packit 98cdb6
enum 
Packit 98cdb6
{
Packit 98cdb6
  CHANGED,
Packit 98cdb6
  LAST_SIGNAL
Packit 98cdb6
};
Packit 98cdb6
Packit 98cdb6
enum 
Packit 98cdb6
{
Packit 98cdb6
  PROP_0,
Packit 98cdb6
  PROP_VALUE,
Packit 98cdb6
  PROP_GROUP,
Packit 98cdb6
  PROP_CURRENT_VALUE
Packit 98cdb6
};
Packit 98cdb6
Packit 98cdb6
static void gtk_radio_action_finalize     (GObject *object);
Packit 98cdb6
static void gtk_radio_action_set_property (GObject         *object,
Packit 98cdb6
				           guint            prop_id,
Packit 98cdb6
				           const GValue    *value,
Packit 98cdb6
				           GParamSpec      *pspec);
Packit 98cdb6
static void gtk_radio_action_get_property (GObject         *object,
Packit 98cdb6
				           guint            prop_id,
Packit 98cdb6
				           GValue          *value,
Packit 98cdb6
				           GParamSpec      *pspec);
Packit 98cdb6
static void gtk_radio_action_activate     (GtkAction *action);
Packit 98cdb6
static GtkWidget *create_menu_item        (GtkAction *action);
Packit 98cdb6
Packit 98cdb6
Packit 98cdb6
G_DEFINE_TYPE (GtkRadioAction, gtk_radio_action, GTK_TYPE_TOGGLE_ACTION)
Packit 98cdb6
Packit 98cdb6
static guint         radio_action_signals[LAST_SIGNAL] = { 0 };
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_radio_action_class_init (GtkRadioActionClass *klass)
Packit 98cdb6
{
Packit 98cdb6
  GObjectClass *gobject_class;
Packit 98cdb6
  GtkActionClass *action_class;
Packit 98cdb6
Packit 98cdb6
  gobject_class = G_OBJECT_CLASS (klass);
Packit 98cdb6
  action_class = GTK_ACTION_CLASS (klass);
Packit 98cdb6
Packit 98cdb6
  gobject_class->finalize = gtk_radio_action_finalize;
Packit 98cdb6
  gobject_class->set_property = gtk_radio_action_set_property;
Packit 98cdb6
  gobject_class->get_property = gtk_radio_action_get_property;
Packit 98cdb6
Packit 98cdb6
  action_class->activate = gtk_radio_action_activate;
Packit 98cdb6
Packit 98cdb6
  action_class->create_menu_item = create_menu_item;
Packit 98cdb6
Packit 98cdb6
  /**
Packit 98cdb6
   * GtkRadioAction:value:
Packit 98cdb6
   *
Packit 98cdb6
   * The value is an arbitrary integer which can be used as a
Packit 98cdb6
   * convenient way to determine which action in the group is 
Packit 98cdb6
   * currently active in an ::activate or ::changed signal handler.
Packit 98cdb6
   * See gtk_radio_action_get_current_value() and #GtkRadioActionEntry
Packit 98cdb6
   * for convenient ways to get and set this property.
Packit 98cdb6
   *
Packit 98cdb6
   * Since: 2.4
Packit 98cdb6
   */
Packit 98cdb6
  g_object_class_install_property (gobject_class,
Packit 98cdb6
				   PROP_VALUE,
Packit 98cdb6
				   g_param_spec_int ("value",
Packit 98cdb6
						     P_("The value"),
Packit 98cdb6
						     P_("The value returned by gtk_radio_action_get_current_value() when this action is the current action of its group."),
Packit 98cdb6
						     G_MININT,
Packit 98cdb6
						     G_MAXINT,
Packit 98cdb6
						     0,
Packit 98cdb6
						     GTK_PARAM_READWRITE));
Packit 98cdb6
Packit 98cdb6
  /**
Packit 98cdb6
   * GtkRadioAction:group:
Packit 98cdb6
   *
Packit 98cdb6
   * Sets a new group for a radio action.
Packit 98cdb6
   *
Packit 98cdb6
   * Since: 2.4
Packit 98cdb6
   */
Packit 98cdb6
  g_object_class_install_property (gobject_class,
Packit 98cdb6
				   PROP_GROUP,
Packit 98cdb6
				   g_param_spec_object ("group",
Packit 98cdb6
							P_("Group"),
Packit 98cdb6
							P_("The radio action whose group this action belongs to."),
Packit 98cdb6
							GTK_TYPE_RADIO_ACTION,
Packit 98cdb6
							GTK_PARAM_WRITABLE));
Packit 98cdb6
Packit 98cdb6
  /**
Packit 98cdb6
   * GtkRadioAction:current-value:
Packit 98cdb6
   *
Packit 98cdb6
   * The value property of the currently active member of the group to which
Packit 98cdb6
   * this action belongs. 
Packit 98cdb6
   *
Packit 98cdb6
   * Since: 2.10
Packit 98cdb6
   */
Packit 98cdb6
  g_object_class_install_property (gobject_class,
Packit 98cdb6
				   PROP_CURRENT_VALUE,
Packit 98cdb6
                                   g_param_spec_int ("current-value",
Packit 98cdb6
						     P_("The current value"),
Packit 98cdb6
						     P_("The value property of the currently active member of the group to which this action belongs."),
Packit 98cdb6
						     G_MININT,
Packit 98cdb6
						     G_MAXINT,
Packit 98cdb6
						     0,
Packit 98cdb6
						     GTK_PARAM_READWRITE));
Packit 98cdb6
Packit 98cdb6
  /**
Packit 98cdb6
   * GtkRadioAction::changed:
Packit 98cdb6
   * @action: the action on which the signal is emitted
Packit 98cdb6
   * @current: the member of @actions group which has just been activated
Packit 98cdb6
   *
Packit 98cdb6
   * The ::changed signal is emitted on every member of a radio group when the
Packit 98cdb6
   * active member is changed. The signal gets emitted after the ::activate signals
Packit 98cdb6
   * for the previous and current active members.
Packit 98cdb6
   *
Packit 98cdb6
   * Since: 2.4
Packit 98cdb6
   */
Packit 98cdb6
  radio_action_signals[CHANGED] =
Packit 98cdb6
    g_signal_new (I_("changed"),
Packit 98cdb6
		  G_OBJECT_CLASS_TYPE (klass),
Packit 98cdb6
		  G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
Packit 98cdb6
		  G_STRUCT_OFFSET (GtkRadioActionClass, changed),  NULL, NULL,
Packit 98cdb6
		  g_cclosure_marshal_VOID__OBJECT,
Packit 98cdb6
		  G_TYPE_NONE, 1, GTK_TYPE_RADIO_ACTION);
Packit 98cdb6
Packit 98cdb6
  g_type_class_add_private (gobject_class, sizeof (GtkRadioActionPrivate));
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_radio_action_init (GtkRadioAction *action)
Packit 98cdb6
{
Packit 98cdb6
  action->private_data = GTK_RADIO_ACTION_GET_PRIVATE (action);
Packit 98cdb6
  action->private_data->group = g_slist_prepend (NULL, action);
Packit 98cdb6
  action->private_data->value = 0;
Packit 98cdb6
Packit 98cdb6
  gtk_toggle_action_set_draw_as_radio (GTK_TOGGLE_ACTION (action), TRUE);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gtk_radio_action_new:
Packit 98cdb6
 * @name: A unique name for the action
Packit 98cdb6
 * @label: (allow-none): The label displayed in menu items and on buttons, or %NULL
Packit 98cdb6
 * @tooltip: (allow-none): A tooltip for this action, or %NULL
Packit 98cdb6
 * @stock_id: The stock icon to display in widgets representing this
Packit 98cdb6
 *   action, or %NULL
Packit 98cdb6
 * @value: The value which gtk_radio_action_get_current_value() should
Packit 98cdb6
 *   return if this action is selected.
Packit 98cdb6
 *
Packit 98cdb6
 * Creates a new #GtkRadioAction object. To add the action to
Packit 98cdb6
 * a #GtkActionGroup and set the accelerator for the action,
Packit 98cdb6
 * call gtk_action_group_add_action_with_accel().
Packit 98cdb6
 *
Packit 98cdb6
 * Return value: a new #GtkRadioAction
Packit 98cdb6
 *
Packit 98cdb6
 * Since: 2.4
Packit 98cdb6
 */
Packit 98cdb6
GtkRadioAction *
Packit 98cdb6
gtk_radio_action_new (const gchar *name,
Packit 98cdb6
		      const gchar *label,
Packit 98cdb6
		      const gchar *tooltip,
Packit 98cdb6
		      const gchar *stock_id,
Packit 98cdb6
		      gint value)
Packit 98cdb6
{
Packit 98cdb6
  g_return_val_if_fail (name != NULL, NULL);
Packit 98cdb6
Packit 98cdb6
  return g_object_new (GTK_TYPE_RADIO_ACTION,
Packit 98cdb6
                       "name", name,
Packit 98cdb6
                       "label", label,
Packit 98cdb6
                       "tooltip", tooltip,
Packit 98cdb6
                       "stock-id", stock_id,
Packit 98cdb6
                       "value", value,
Packit 98cdb6
                       NULL);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_radio_action_finalize (GObject *object)
Packit 98cdb6
{
Packit 98cdb6
  GtkRadioAction *action;
Packit 98cdb6
  GSList *tmp_list;
Packit 98cdb6
Packit 98cdb6
  action = GTK_RADIO_ACTION (object);
Packit 98cdb6
Packit 98cdb6
  action->private_data->group = g_slist_remove (action->private_data->group, action);
Packit 98cdb6
Packit 98cdb6
  tmp_list = action->private_data->group;
Packit 98cdb6
Packit 98cdb6
  while (tmp_list)
Packit 98cdb6
    {
Packit 98cdb6
      GtkRadioAction *tmp_action = tmp_list->data;
Packit 98cdb6
Packit 98cdb6
      tmp_list = tmp_list->next;
Packit 98cdb6
      tmp_action->private_data->group = action->private_data->group;
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  G_OBJECT_CLASS (gtk_radio_action_parent_class)->finalize (object);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_radio_action_set_property (GObject         *object,
Packit 98cdb6
			       guint            prop_id,
Packit 98cdb6
			       const GValue    *value,
Packit 98cdb6
			       GParamSpec      *pspec)
Packit 98cdb6
{
Packit 98cdb6
  GtkRadioAction *radio_action;
Packit 98cdb6
  
Packit 98cdb6
  radio_action = GTK_RADIO_ACTION (object);
Packit 98cdb6
Packit 98cdb6
  switch (prop_id)
Packit 98cdb6
    {
Packit 98cdb6
    case PROP_VALUE:
Packit 98cdb6
      radio_action->private_data->value = g_value_get_int (value);
Packit 98cdb6
      break;
Packit 98cdb6
    case PROP_GROUP: 
Packit 98cdb6
      {
Packit 98cdb6
	GtkRadioAction *arg;
Packit 98cdb6
	GSList *slist = NULL;
Packit 98cdb6
	
Packit 98cdb6
	if (G_VALUE_HOLDS_OBJECT (value)) 
Packit 98cdb6
	  {
Packit 98cdb6
	    arg = GTK_RADIO_ACTION (g_value_get_object (value));
Packit 98cdb6
	    if (arg)
Packit 98cdb6
	      slist = gtk_radio_action_get_group (arg);
Packit 98cdb6
	    gtk_radio_action_set_group (radio_action, slist);
Packit 98cdb6
	  }
Packit 98cdb6
      }
Packit 98cdb6
      break;
Packit 98cdb6
    case PROP_CURRENT_VALUE:
Packit 98cdb6
      gtk_radio_action_set_current_value (radio_action,
Packit 98cdb6
                                          g_value_get_int (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
gtk_radio_action_get_property (GObject    *object,
Packit 98cdb6
			       guint       prop_id,
Packit 98cdb6
			       GValue     *value,
Packit 98cdb6
			       GParamSpec *pspec)
Packit 98cdb6
{
Packit 98cdb6
  GtkRadioAction *radio_action;
Packit 98cdb6
Packit 98cdb6
  radio_action = GTK_RADIO_ACTION (object);
Packit 98cdb6
Packit 98cdb6
  switch (prop_id)
Packit 98cdb6
    {
Packit 98cdb6
    case PROP_VALUE:
Packit 98cdb6
      g_value_set_int (value, radio_action->private_data->value);
Packit 98cdb6
      break;
Packit 98cdb6
    case PROP_CURRENT_VALUE:
Packit 98cdb6
      g_value_set_int (value,
Packit 98cdb6
                       gtk_radio_action_get_current_value (radio_action));
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
gtk_radio_action_activate (GtkAction *action)
Packit 98cdb6
{
Packit 98cdb6
  GtkRadioAction *radio_action;
Packit 98cdb6
  GtkToggleAction *toggle_action;
Packit 98cdb6
  GtkToggleAction *tmp_action;
Packit 98cdb6
  GSList *tmp_list;
Packit 98cdb6
Packit 98cdb6
  radio_action = GTK_RADIO_ACTION (action);
Packit 98cdb6
  toggle_action = GTK_TOGGLE_ACTION (action);
Packit 98cdb6
Packit 98cdb6
  if (toggle_action->private_data->active)
Packit 98cdb6
    {
Packit 98cdb6
      tmp_list = radio_action->private_data->group;
Packit 98cdb6
Packit 98cdb6
      while (tmp_list)
Packit 98cdb6
	{
Packit 98cdb6
	  tmp_action = tmp_list->data;
Packit 98cdb6
	  tmp_list = tmp_list->next;
Packit 98cdb6
Packit 98cdb6
	  if (tmp_action->private_data->active && (tmp_action != toggle_action)) 
Packit 98cdb6
	    {
Packit 98cdb6
	      toggle_action->private_data->active = !toggle_action->private_data->active;
Packit 98cdb6
Packit 98cdb6
	      break;
Packit 98cdb6
	    }
Packit 98cdb6
	}
Packit 98cdb6
      g_object_notify (G_OBJECT (action), "active");
Packit 98cdb6
    }
Packit 98cdb6
  else
Packit 98cdb6
    {
Packit 98cdb6
      toggle_action->private_data->active = !toggle_action->private_data->active;
Packit 98cdb6
      g_object_notify (G_OBJECT (action), "active");
Packit 98cdb6
Packit 98cdb6
      tmp_list = radio_action->private_data->group;
Packit 98cdb6
      while (tmp_list)
Packit 98cdb6
	{
Packit 98cdb6
	  tmp_action = tmp_list->data;
Packit 98cdb6
	  tmp_list = tmp_list->next;
Packit 98cdb6
Packit 98cdb6
	  if (tmp_action->private_data->active && (tmp_action != toggle_action))
Packit 98cdb6
	    {
Packit 98cdb6
	      _gtk_action_emit_activate (GTK_ACTION (tmp_action));
Packit 98cdb6
	      break;
Packit 98cdb6
	    }
Packit 98cdb6
	}
Packit 98cdb6
Packit 98cdb6
      tmp_list = radio_action->private_data->group;
Packit 98cdb6
      while (tmp_list)
Packit 98cdb6
	{
Packit 98cdb6
	  tmp_action = tmp_list->data;
Packit 98cdb6
	  tmp_list = tmp_list->next;
Packit 98cdb6
	  
Packit 98cdb6
          g_object_notify (G_OBJECT (tmp_action), "current-value");
Packit 98cdb6
Packit 98cdb6
	  g_signal_emit (tmp_action, radio_action_signals[CHANGED], 0, radio_action);
Packit 98cdb6
	}
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  gtk_toggle_action_toggled (toggle_action);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static GtkWidget *
Packit 98cdb6
create_menu_item (GtkAction *action)
Packit 98cdb6
{
Packit 98cdb6
  return g_object_new (GTK_TYPE_CHECK_MENU_ITEM, 
Packit 98cdb6
		       "draw-as-radio", TRUE,
Packit 98cdb6
		       NULL);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gtk_radio_action_get_group:
Packit 98cdb6
 * @action: the action object
Packit 98cdb6
 *
Packit 98cdb6
 * Returns the list representing the radio group for this object.
Packit 98cdb6
 * Note that the returned list is only valid until the next change
Packit 98cdb6
 * to the group. 
Packit 98cdb6
 *
Packit 98cdb6
 * A common way to set up a group of radio group is the following:
Packit 98cdb6
 * |[
Packit 98cdb6
 *   GSList *group = NULL;
Packit 98cdb6
 *   GtkRadioAction *action;
Packit 98cdb6
 *  
Packit 98cdb6
 *   while (/* more actions to add */)
Packit 98cdb6
 *     {
Packit 98cdb6
 *        action = gtk_radio_action_new (...);
Packit 98cdb6
 *        
Packit 98cdb6
 *        gtk_radio_action_set_group (action, group);
Packit 98cdb6
 *        group = gtk_radio_action_get_group (action);
Packit 98cdb6
 *     }
Packit 98cdb6
 * ]|
Packit 98cdb6
 *
Packit 98cdb6
 * Returns:  (element-type GtkAction) (transfer none): the list representing the radio group for this object
Packit 98cdb6
 *
Packit 98cdb6
 * Since: 2.4
Packit 98cdb6
 */
Packit 98cdb6
GSList *
Packit 98cdb6
gtk_radio_action_get_group (GtkRadioAction *action)
Packit 98cdb6
{
Packit 98cdb6
  g_return_val_if_fail (GTK_IS_RADIO_ACTION (action), NULL);
Packit 98cdb6
Packit 98cdb6
  return action->private_data->group;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gtk_radio_action_set_group:
Packit 98cdb6
 * @action: the action object
Packit 98cdb6
 * @group: a list representing a radio group
Packit 98cdb6
 *
Packit 98cdb6
 * Sets the radio group for the radio action object.
Packit 98cdb6
 *
Packit 98cdb6
 * Since: 2.4
Packit 98cdb6
 */
Packit 98cdb6
void
Packit 98cdb6
gtk_radio_action_set_group (GtkRadioAction *action, 
Packit 98cdb6
			    GSList         *group)
Packit 98cdb6
{
Packit 98cdb6
  g_return_if_fail (GTK_IS_RADIO_ACTION (action));
Packit 98cdb6
  g_return_if_fail (!g_slist_find (group, action));
Packit 98cdb6
Packit 98cdb6
  if (action->private_data->group)
Packit 98cdb6
    {
Packit 98cdb6
      GSList *slist;
Packit 98cdb6
Packit 98cdb6
      action->private_data->group = g_slist_remove (action->private_data->group, action);
Packit 98cdb6
Packit 98cdb6
      for (slist = action->private_data->group; slist; slist = slist->next)
Packit 98cdb6
	{
Packit 98cdb6
	  GtkRadioAction *tmp_action = slist->data;
Packit 98cdb6
Packit 98cdb6
	  tmp_action->private_data->group = action->private_data->group;
Packit 98cdb6
	}
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  action->private_data->group = g_slist_prepend (group, action);
Packit 98cdb6
Packit 98cdb6
  if (group)
Packit 98cdb6
    {
Packit 98cdb6
      GSList *slist;
Packit 98cdb6
Packit 98cdb6
      for (slist = action->private_data->group; slist; slist = slist->next)
Packit 98cdb6
	{
Packit 98cdb6
	  GtkRadioAction *tmp_action = slist->data;
Packit 98cdb6
Packit 98cdb6
	  tmp_action->private_data->group = action->private_data->group;
Packit 98cdb6
	}
Packit 98cdb6
    }
Packit 98cdb6
  else
Packit 98cdb6
    {
Packit 98cdb6
      gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE);
Packit 98cdb6
    }
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gtk_radio_action_get_current_value:
Packit 98cdb6
 * @action: a #GtkRadioAction
Packit 98cdb6
 * 
Packit 98cdb6
 * Obtains the value property of the currently active member of 
Packit 98cdb6
 * the group to which @action belongs.
Packit 98cdb6
 * 
Packit 98cdb6
 * Return value: The value of the currently active group member
Packit 98cdb6
 *
Packit 98cdb6
 * Since: 2.4
Packit 98cdb6
 **/
Packit 98cdb6
gint
Packit 98cdb6
gtk_radio_action_get_current_value (GtkRadioAction *action)
Packit 98cdb6
{
Packit 98cdb6
  GSList *slist;
Packit 98cdb6
Packit 98cdb6
  g_return_val_if_fail (GTK_IS_RADIO_ACTION (action), 0);
Packit 98cdb6
Packit 98cdb6
  if (action->private_data->group)
Packit 98cdb6
    {
Packit 98cdb6
      for (slist = action->private_data->group; slist; slist = slist->next)
Packit 98cdb6
	{
Packit 98cdb6
	  GtkToggleAction *toggle_action = slist->data;
Packit 98cdb6
Packit 98cdb6
	  if (toggle_action->private_data->active)
Packit 98cdb6
	    return GTK_RADIO_ACTION (toggle_action)->private_data->value;
Packit 98cdb6
	}
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  return action->private_data->value;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gtk_radio_action_set_current_value:
Packit 98cdb6
 * @action: a #GtkRadioAction
Packit 98cdb6
 * @current_value: the new value
Packit 98cdb6
 * 
Packit 98cdb6
 * Sets the currently active group member to the member with value
Packit 98cdb6
 * property @current_value.
Packit 98cdb6
 *
Packit 98cdb6
 * Since: 2.10
Packit 98cdb6
 **/
Packit 98cdb6
void
Packit 98cdb6
gtk_radio_action_set_current_value (GtkRadioAction *action,
Packit 98cdb6
                                    gint            current_value)
Packit 98cdb6
{
Packit 98cdb6
  GSList *slist;
Packit 98cdb6
Packit 98cdb6
  g_return_if_fail (GTK_IS_RADIO_ACTION (action));
Packit 98cdb6
Packit 98cdb6
  if (action->private_data->group)
Packit 98cdb6
    {
Packit 98cdb6
      for (slist = action->private_data->group; slist; slist = slist->next)
Packit 98cdb6
	{
Packit 98cdb6
	  GtkRadioAction *radio_action = slist->data;
Packit 98cdb6
Packit 98cdb6
	  if (radio_action->private_data->value == current_value)
Packit 98cdb6
            {
Packit 98cdb6
              gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (radio_action),
Packit 98cdb6
                                            TRUE);
Packit 98cdb6
              return;
Packit 98cdb6
            }
Packit 98cdb6
	}
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  if (action->private_data->value == current_value)
Packit 98cdb6
    gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE);
Packit 98cdb6
  else
Packit 98cdb6
    g_warning ("Radio group does not contain an action with value '%d'",
Packit 98cdb6
	       current_value);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
#define __GTK_RADIO_ACTION_C__
Packit 98cdb6
#include "gtkaliasdef.c"