Blame modules/other/gail/gailradiobutton.c

Packit 98cdb6
/* GAIL - The GNOME Accessibility Implementation Library
Packit 98cdb6
 * Copyright 2001 Sun Microsystems Inc.
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 Lesser 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
 * Lesser General Public License for more details.
Packit 98cdb6
 *
Packit 98cdb6
 * You should have received a copy of the GNU Lesser 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
#include "config.h"
Packit 98cdb6
Packit 98cdb6
#include <gtk/gtk.h>
Packit 98cdb6
#include "gailradiobutton.h"
Packit 98cdb6
Packit 98cdb6
static void      gail_radio_button_class_init        (GailRadioButtonClass *klass);
Packit 98cdb6
static void      gail_radio_button_init              (GailRadioButton      *radio_button);
Packit 98cdb6
static void      gail_radio_button_initialize        (AtkObject            *accessible,
Packit 98cdb6
                                                      gpointer              data);
Packit 98cdb6
Packit 98cdb6
static AtkRelationSet* gail_radio_button_ref_relation_set (AtkObject       *obj);
Packit 98cdb6
Packit 98cdb6
G_DEFINE_TYPE (GailRadioButton, gail_radio_button, GAIL_TYPE_TOGGLE_BUTTON)
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gail_radio_button_class_init (GailRadioButtonClass *klass)
Packit 98cdb6
{
Packit 98cdb6
  AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
Packit 98cdb6
Packit 98cdb6
  class->initialize = gail_radio_button_initialize;
Packit 98cdb6
  class->ref_relation_set = gail_radio_button_ref_relation_set;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gail_radio_button_init (GailRadioButton *radio_button)
Packit 98cdb6
{
Packit 98cdb6
  radio_button->old_group = NULL;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gail_radio_button_initialize (AtkObject *accessible,
Packit 98cdb6
                              gpointer  data)
Packit 98cdb6
{
Packit 98cdb6
  ATK_OBJECT_CLASS (gail_radio_button_parent_class)->initialize (accessible, data);
Packit 98cdb6
Packit 98cdb6
  accessible->role = ATK_ROLE_RADIO_BUTTON;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
AtkRelationSet*
Packit 98cdb6
gail_radio_button_ref_relation_set (AtkObject *obj)
Packit 98cdb6
{
Packit 98cdb6
  GtkWidget *widget;
Packit 98cdb6
  AtkRelationSet *relation_set;
Packit 98cdb6
  GSList *list;
Packit 98cdb6
  GailRadioButton *radio_button;
Packit 98cdb6
Packit 98cdb6
  g_return_val_if_fail (GAIL_IS_RADIO_BUTTON (obj), NULL);
Packit 98cdb6
Packit 98cdb6
  widget = GTK_ACCESSIBLE (obj)->widget;
Packit 98cdb6
  if (widget == NULL)
Packit 98cdb6
  {
Packit 98cdb6
    /*
Packit 98cdb6
     * State is defunct
Packit 98cdb6
     */
Packit 98cdb6
    return NULL;
Packit 98cdb6
  }
Packit 98cdb6
  radio_button = GAIL_RADIO_BUTTON (obj);
Packit 98cdb6
Packit 98cdb6
  relation_set = ATK_OBJECT_CLASS (gail_radio_button_parent_class)->ref_relation_set (obj);
Packit 98cdb6
Packit 98cdb6
  /*
Packit 98cdb6
   * If the radio button'group has changed remove the relation
Packit 98cdb6
   */
Packit 98cdb6
  list = gtk_radio_button_get_group (GTK_RADIO_BUTTON (widget));
Packit 98cdb6
  
Packit 98cdb6
  if (radio_button->old_group != list)
Packit 98cdb6
    {
Packit 98cdb6
      AtkRelation *relation;
Packit 98cdb6
Packit 98cdb6
      relation = atk_relation_set_get_relation_by_type (relation_set, ATK_RELATION_MEMBER_OF);
Packit 98cdb6
      atk_relation_set_remove (relation_set, relation);
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  if (!atk_relation_set_contains (relation_set, ATK_RELATION_MEMBER_OF))
Packit 98cdb6
  {
Packit 98cdb6
    /*
Packit 98cdb6
     * Get the members of the button group
Packit 98cdb6
     */
Packit 98cdb6
Packit 98cdb6
    radio_button->old_group = list;
Packit 98cdb6
    if (list)
Packit 98cdb6
    {
Packit 98cdb6
      AtkObject **accessible_array;
Packit 98cdb6
      guint list_length;
Packit 98cdb6
      AtkRelation* relation;
Packit 98cdb6
      gint i = 0;
Packit 98cdb6
Packit 98cdb6
      list_length = g_slist_length (list);
Packit 98cdb6
      accessible_array = (AtkObject**) g_malloc (sizeof (AtkObject *) * 
Packit 98cdb6
                          list_length);
Packit 98cdb6
      while (list != NULL)
Packit 98cdb6
      {
Packit 98cdb6
        GtkWidget* list_item = list->data;
Packit 98cdb6
Packit 98cdb6
        accessible_array[i++] = gtk_widget_get_accessible (list_item);
Packit 98cdb6
Packit 98cdb6
        list = list->next;
Packit 98cdb6
      }
Packit 98cdb6
      relation = atk_relation_new (accessible_array, list_length,
Packit 98cdb6
                                   ATK_RELATION_MEMBER_OF);
Packit 98cdb6
      g_free (accessible_array);
Packit 98cdb6
Packit 98cdb6
      atk_relation_set_add (relation_set, relation);
Packit 98cdb6
      /*
Packit 98cdb6
       * Unref the relation so that it is not leaked.
Packit 98cdb6
       */
Packit 98cdb6
      g_object_unref (relation);
Packit 98cdb6
    }
Packit 98cdb6
  }
Packit 98cdb6
  return relation_set;
Packit 98cdb6
}