Commit 7f58482d authored by Matthias Clasen's avatar Matthias Clasen

Convert GailRange to GtkRangeAccessible

parent 5f6ed88b
......@@ -34,7 +34,7 @@ gail_c_sources = \
gailradiobutton.c \
gailradiomenuitem.c \
gailradiosubmenuitem.c \
gailrange.c \
gtkrangeaccessible.c \
gailrenderercell.c \
gtkscaleaccessible.c \
gailscalebutton.c \
......@@ -86,7 +86,7 @@ gail_private_h_sources = \
gailradiobutton.h \
gailradiomenuitem.h \
gailradiosubmenuitem.h \
gailrange.h \
gtkrangeaccessible.h \
gailrenderercell.h \
gtkscaleaccessible.h \
gailscalebutton.h \
......
......@@ -22,80 +22,33 @@
#include <string.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include "gailrange.h"
#include "gtkrangeaccessible.h"
#include "gailadjustment.h"
#include "gail-private-macros.h"
static void gail_range_class_init (GailRangeClass *klass);
static void gail_range_init (GailRange *range);
static void gail_range_real_initialize (AtkObject *obj,
gpointer data);
static void gail_range_finalize (GObject *object);
static void gail_range_real_notify_gtk (GObject *obj,
GParamSpec *pspec);
static void atk_value_interface_init (AtkValueIface *iface);
static void gail_range_get_current_value (AtkValue *obj,
GValue *value);
static void gail_range_get_maximum_value (AtkValue *obj,
GValue *value);
static void gail_range_get_minimum_value (AtkValue *obj,
GValue *value);
static void gail_range_get_minimum_increment (AtkValue *obj,
GValue *value);
static gboolean gail_range_set_current_value (AtkValue *obj,
const GValue *value);
static void gail_range_value_changed (GtkAdjustment *adjustment,
gpointer data);
static void atk_action_interface_init (AtkActionIface *iface);
static gboolean gail_range_do_action (AtkAction *action,
gint i);
static gboolean idle_do_action (gpointer data);
static gint gail_range_get_n_actions (AtkAction *action);
static const gchar* gail_range_get_keybinding (AtkAction *action,
gint i);
static const gchar* gail_range_action_get_name (AtkAction *action,
gint i);
G_DEFINE_TYPE_WITH_CODE (GailRange, gail_range, GAIL_TYPE_WIDGET,
G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION, atk_action_interface_init)
G_IMPLEMENT_INTERFACE (ATK_TYPE_VALUE, atk_value_interface_init))
static void
gail_range_class_init (GailRangeClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
GailWidgetClass *widget_class;
widget_class = (GailWidgetClass*)klass;
widget_class->notify_gtk = gail_range_real_notify_gtk;
static void atk_action_interface_init (AtkActionIface *iface);
static void atk_value_interface_init (AtkValueIface *iface);
class->initialize = gail_range_real_initialize;
gobject_class->finalize = gail_range_finalize;
}
G_DEFINE_TYPE_WITH_CODE (GtkRangeAccessible, gtk_range_accessible, GAIL_TYPE_WIDGET,
G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION, atk_action_interface_init)
G_IMPLEMENT_INTERFACE (ATK_TYPE_VALUE, atk_value_interface_init))
static void
gail_range_init (GailRange *range)
gtk_range_accessible_value_changed (GtkAdjustment *adjustment,
gpointer data)
{
g_object_notify (G_OBJECT (data), "accessible-value");
}
static void
gail_range_real_initialize (AtkObject *obj,
gpointer data)
gtk_range_accessible_initialize (AtkObject *obj,
gpointer data)
{
GailRange *range = GAIL_RANGE (obj);
GtkRangeAccessible *range = GTK_RANGE_ACCESSIBLE (obj);
GtkAdjustment *adj;
GtkRange *gtk_range;
ATK_OBJECT_CLASS (gail_range_parent_class)->initialize (obj, data);
ATK_OBJECT_CLASS (gtk_range_accessible_parent_class)->initialize (obj, data);
gtk_range = GTK_RANGE (data);
/*
......@@ -108,68 +61,123 @@ gail_range_real_initialize (AtkObject *obj,
range->adjustment = gail_adjustment_new (adj);
g_signal_connect (adj,
"value-changed",
G_CALLBACK (gail_range_value_changed),
G_CALLBACK (gtk_range_accessible_value_changed),
range);
}
else
range->adjustment = NULL;
range->activate_keybinding=NULL;
/*
* Assumed to GtkScale (either GtkHScale or GtkVScale)
*/
obj->role = ATK_ROLE_SLIDER;
}
static void
atk_value_interface_init (AtkValueIface *iface)
gtk_range_accessible_finalize (GObject *object)
{
iface->get_current_value = gail_range_get_current_value;
iface->get_maximum_value = gail_range_get_maximum_value;
iface->get_minimum_value = gail_range_get_minimum_value;
iface->get_minimum_increment = gail_range_get_minimum_increment;
iface->set_current_value = gail_range_set_current_value;
GtkRangeAccessible *range = GTK_RANGE_ACCESSIBLE (object);
if (range->adjustment)
{
/* The GtkAdjustment may live on so we need to disconnect
* the signal handler
*/
if (GAIL_ADJUSTMENT (range->adjustment)->adjustment)
g_signal_handlers_disconnect_by_func (GAIL_ADJUSTMENT (range->adjustment)->adjustment,
(void *)gtk_range_accessible_value_changed,
range);
g_object_unref (range->adjustment);
range->adjustment = NULL;
}
if (range->action_idle_handler)
{
g_source_remove (range->action_idle_handler);
range->action_idle_handler = 0;
}
G_OBJECT_CLASS (gtk_range_accessible_parent_class)->finalize (object);
}
static void
gail_range_get_current_value (AtkValue *obj,
GValue *value)
gtk_range_accessible_notify_gtk (GObject *obj,
GParamSpec *pspec)
{
GailRange *range;
GtkAdjustment *adj;
GtkWidget *widget = GTK_WIDGET (obj);
GtkRangeAccessible *range = GTK_RANGE_ACCESSIBLE (gtk_widget_get_accessible (widget));
g_return_if_fail (GAIL_IS_RANGE (obj));
if (strcmp (pspec->name, "adjustment") == 0)
{
/* Get rid of the GailAdjustment for the GtkAdjustment
* which was associated with the range.
*/
if (range->adjustment)
{
g_object_unref (range->adjustment);
range->adjustment = NULL;
}
/* Create the GailAdjustment when notify for "adjustment" property
* is received
*/
adj = gtk_range_get_adjustment (GTK_RANGE (widget));
range->adjustment = gail_adjustment_new (adj);
g_signal_connect (adj,
"value-changed",
G_CALLBACK (gtk_range_accessible_value_changed),
range);
}
else
GAIL_WIDGET_CLASS (gtk_range_accessible_parent_class)->notify_gtk (obj, pspec);
}
static void
gtk_range_accessible_class_init (GtkRangeAccessibleClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
GailWidgetClass *widget_class = (GailWidgetClass*)klass;
widget_class->notify_gtk = gtk_range_accessible_notify_gtk;
class->initialize = gtk_range_accessible_initialize;
gobject_class->finalize = gtk_range_accessible_finalize;
}
static void
gtk_range_accessible_init (GtkRangeAccessible *range)
{
}
static void
gtk_range_accessible_get_current_value (AtkValue *obj,
GValue *value)
{
GtkRangeAccessible *range = GTK_RANGE_ACCESSIBLE (obj);
range = GAIL_RANGE (obj);
if (range->adjustment == NULL)
/*
* Adjustment has not been specified
*/
return;
atk_value_get_current_value (ATK_VALUE (range->adjustment), value);
}
static void
gail_range_get_maximum_value (AtkValue *obj,
GValue *value)
static void
gtk_range_accessible_get_maximum_value (AtkValue *obj,
GValue *value)
{
GailRange *range;
GtkRangeAccessible *range = GTK_RANGE_ACCESSIBLE (obj);
GtkRange *gtk_range;
GtkAdjustment *gtk_adjustment;
gdouble max = 0;
g_return_if_fail (GAIL_IS_RANGE (obj));
range = GAIL_RANGE (obj);
if (range->adjustment == NULL)
/*
* Adjustment has not been specified
*/
return;
atk_value_get_maximum_value (ATK_VALUE (range->adjustment), value);
gtk_range = GTK_RANGE (gtk_accessible_get_widget (GTK_ACCESSIBLE (range)));
g_return_if_fail (gtk_range);
gtk_adjustment = gtk_range_get_adjustment (gtk_range);
max = g_value_get_double (value);
......@@ -181,48 +189,36 @@ gail_range_get_maximum_value (AtkValue *obj,
g_value_set_double (value, max);
}
static void
gail_range_get_minimum_value (AtkValue *obj,
GValue *value)
static void
gtk_range_accessible_get_minimum_value (AtkValue *obj,
GValue *value)
{
GailRange *range;
GtkRangeAccessible *range = GTK_RANGE_ACCESSIBLE (obj);
g_return_if_fail (GAIL_IS_RANGE (obj));
range = GAIL_RANGE (obj);
if (range->adjustment == NULL)
/*
* Adjustment has not been specified
*/
return;
atk_value_get_minimum_value (ATK_VALUE (range->adjustment), value);
}
static void
gail_range_get_minimum_increment (AtkValue *obj, GValue *value)
gtk_range_accessible_get_minimum_increment (AtkValue *obj,
GValue *value)
{
GailRange *range;
g_return_if_fail (GAIL_IS_RANGE (obj));
GtkRangeAccessible *range = GTK_RANGE_ACCESSIBLE (obj);
range = GAIL_RANGE (obj);
if (range->adjustment == NULL)
/*
* Adjustment has not been specified
*/
return;
atk_value_get_minimum_increment (ATK_VALUE (range->adjustment), value);
}
static gboolean gail_range_set_current_value (AtkValue *obj,
const GValue *value)
static gboolean
gtk_range_accessible_set_current_value (AtkValue *obj,
const GValue *value)
{
GtkWidget *widget;
g_return_val_if_fail (GAIL_IS_RANGE (obj), FALSE);
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
if (widget == NULL)
return FALSE;
......@@ -234,6 +230,7 @@ static gboolean gail_range_set_current_value (AtkValue *obj,
new_value = g_value_get_double (value);
gtk_range_set_value (range, new_value);
return TRUE;
}
else
......@@ -243,203 +240,126 @@ static gboolean gail_range_set_current_value (AtkValue *obj,
}
static void
gail_range_finalize (GObject *object)
{
GailRange *range = GAIL_RANGE (object);
if (range->adjustment)
{
/*
* The GtkAdjustment may live on so we need to dicsonnect the
* signal handler
*/
if (GAIL_ADJUSTMENT (range->adjustment)->adjustment)
{
g_signal_handlers_disconnect_by_func (GAIL_ADJUSTMENT (range->adjustment)->adjustment,
(void *)gail_range_value_changed,
range);
}
g_object_unref (range->adjustment);
range->adjustment = NULL;
}
range->activate_keybinding=NULL;
if (range->action_idle_handler)
{
g_source_remove (range->action_idle_handler);
range->action_idle_handler = 0;
}
G_OBJECT_CLASS (gail_range_parent_class)->finalize (object);
}
static void
gail_range_real_notify_gtk (GObject *obj,
GParamSpec *pspec)
atk_value_interface_init (AtkValueIface *iface)
{
GtkAdjustment *adj;
GtkWidget *widget = GTK_WIDGET (obj);
GailRange *range = GAIL_RANGE (gtk_widget_get_accessible (widget));
if (strcmp (pspec->name, "adjustment") == 0)
{
/*
* Get rid of the GailAdjustment for the GtkAdjustment
* which was associated with the range.
*/
if (range->adjustment)
{
g_object_unref (range->adjustment);
range->adjustment = NULL;
}
/*
* Create the GailAdjustment when notify for "adjustment" property
* is received
*/
adj = gtk_range_get_adjustment (GTK_RANGE (widget));
range->adjustment = gail_adjustment_new (adj);
g_signal_connect (adj,
"value-changed",
G_CALLBACK (gail_range_value_changed),
range);
}
else
GAIL_WIDGET_CLASS (gail_range_parent_class)->notify_gtk (obj, pspec);
iface->get_current_value = gtk_range_accessible_get_current_value;
iface->get_maximum_value = gtk_range_accessible_get_maximum_value;
iface->get_minimum_value = gtk_range_accessible_get_minimum_value;
iface->get_minimum_increment = gtk_range_accessible_get_minimum_increment;
iface->set_current_value = gtk_range_accessible_set_current_value;
}
static void
gail_range_value_changed (GtkAdjustment *adjustment,
gpointer data)
static gboolean
idle_do_action (gpointer data)
{
GailRange *range;
GtkRangeAccessible *range = GTK_RANGE_ACCESSIBLE (data);
GtkWidget *widget;
g_return_if_fail (adjustment != NULL);
gail_return_if_fail (data != NULL);
range->action_idle_handler = 0;
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (range));
if (widget == NULL)
return FALSE;
range = GAIL_RANGE (data);
if (!gtk_widget_get_sensitive (widget) || !gtk_widget_get_visible (widget))
return FALSE;
g_object_notify (G_OBJECT (range), "accessible-value");
}
gtk_widget_activate (widget);
static void
atk_action_interface_init (AtkActionIface *iface)
{
iface->do_action = gail_range_do_action;
iface->get_n_actions = gail_range_get_n_actions;
iface->get_keybinding = gail_range_get_keybinding;
iface->get_name = gail_range_action_get_name;
return TRUE;
}
static gboolean
gail_range_do_action (AtkAction *action,
gint i)
gtk_range_accessible_do_action (AtkAction *action,
gint i)
{
GailRange *range;
GtkRangeAccessible *range = GTK_RANGE_ACCESSIBLE (action);
GtkWidget *widget;
gboolean return_value = TRUE;
range = GAIL_RANGE (action);
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (action));
if (widget == NULL)
/*
* State is defunct
*/
return FALSE;
if (!gtk_widget_get_sensitive (widget) || !gtk_widget_get_visible (widget))
return FALSE;
if(i==0)
{
if (range->action_idle_handler)
return_value = FALSE;
else
range->action_idle_handler = gdk_threads_add_idle (idle_do_action, range);
}
else
return_value = FALSE;
return return_value;
}
static gboolean
idle_do_action (gpointer data)
{
GailRange *range;
GtkWidget *widget;
if (i != 0)
return FALSE;
range = GAIL_RANGE (data);
range->action_idle_handler = 0;
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (range));
if (widget == NULL /* State is defunct */ ||
!gtk_widget_get_sensitive (widget) || !gtk_widget_get_visible (widget))
if (range->action_idle_handler)
return FALSE;
gtk_widget_activate (widget);
range->action_idle_handler = gdk_threads_add_idle (idle_do_action, range);
return FALSE;
return TRUE;
}
static gint
gail_range_get_n_actions (AtkAction *action)
gtk_range_accessible_get_n_actions (AtkAction *action)
{
return 1;
}
static const gchar*
gail_range_get_keybinding (AtkAction *action,
gint i)
static const gchar *
gtk_range_accessible_get_keybinding (AtkAction *action,
gint i)
{
GailRange *range;
GtkRangeAccessible *range = GTK_RANGE_ACCESSIBLE (action);
GtkWidget *widget;
GtkWidget *label;
AtkRelationSet *set;
AtkRelation *relation;
GPtrArray *target;
gpointer target_object;
guint key_val;
gchar *return_value = NULL;
range = GAIL_RANGE (action);
if(i==0)
{
GtkWidget *widget;
GtkWidget *label;
AtkRelationSet *set;
AtkRelation *relation;
GPtrArray *target;
gpointer target_object;
guint key_val;
range = GAIL_RANGE (action);
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (range));
if (widget == NULL)
return NULL;
set = atk_object_ref_relation_set (ATK_OBJECT (action));
if (!set)
return NULL;
label = NULL;
relation = atk_relation_set_get_relation_by_type (set, ATK_RELATION_LABELLED_BY);
if (relation)
{
if (i != 0)
return NULL;
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (range));
if (widget == NULL)
return NULL;
set = atk_object_ref_relation_set (ATK_OBJECT (action));
if (!set)
return NULL;
label = NULL;
relation = atk_relation_set_get_relation_by_type (set, ATK_RELATION_LABELLED_BY);
if (relation)
{
target = atk_relation_get_target (relation);
target_object = g_ptr_array_index (target, 0);
label = gtk_accessible_get_widget (GTK_ACCESSIBLE (target_object));
}
g_object_unref (set);
if (GTK_IS_LABEL (label))
{
}
g_object_unref (set);
if (GTK_IS_LABEL (label))
{
key_val = gtk_label_get_mnemonic_keyval (GTK_LABEL (label));
if (key_val != GDK_KEY_VoidSymbol)
return_value = gtk_accelerator_name (key_val, GDK_MOD1_MASK);
}
g_free (range->activate_keybinding);
range->activate_keybinding = return_value;
}
}
return return_value;
}
static const gchar*
gail_range_action_get_name (AtkAction *action,
gint i)
static const gchar *
gtk_range_accessible_action_get_name (AtkAction *action,
gint i)
{
const gchar *return_value;
if (i==0)
return_value = "activate";
else
return_value = NULL;
if (i != 0)
return NULL;
return return_value;
return "activate";
}
static void
atk_action_interface_init (AtkActionIface *iface)
{
iface->do_action = gtk_range_accessible_do_action;
iface->get_n_actions = gtk_range_accessible_get_n_actions;
iface->get_keybinding = gtk_range_accessible_get_keybinding;
iface->get_name = gtk_range_accessible_action_get_name;
}
......@@ -8,7 +8,7 @@
*
* 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
* 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
......@@ -17,40 +17,38 @@
* Boston, MA 02111-1307, USA.
*/
#ifndef __GAIL_RANGE_H__
#define __GAIL_RANGE_H__
#ifndef __GTK_RANGE_ACCESSIBLE_H__
#define __GTK_RANGE_ACCESSIBLE_H__
#include "gailwidget.h"
G_BEGIN_DECLS
#define GAIL_TYPE_RANGE (gail_range_get_type ())
#define GAIL_RANGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAIL_TYPE_RANGE, GailRange))
#define GAIL_RANGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAIL_TYPE_RANGE, GailRangeClass))
#define GAIL_IS_RANGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAIL_TYPE_RANGE))
#define GAIL_IS_RANGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAIL_TYPE_RANGE))
#define GAIL_RANGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAIL_TYPE_RANGE, GailRangeClass))
#define GTK_TYPE_RANGE_ACCESSIBLE (gtk_range_accessible_get_type ())
#define GTK_RANGE_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_RANGE_ACCESSIBLE, GtkRangeAccessible))
#define GTK_RANGE_ACCESSIBLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_RANGE_ACCESSIBLE, GtkRangeAccessibleClass))
#define GTK_IS_RANGE_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_RANGE_ACCESSIBLE))
#define GTK_IS_RANGE_ACCESSIBLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_RANGE_ACCESSIBLE))
#define GTK_RANGE_ACCESSIBLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_RANGE_ACCESSIBLE, GtkRangeAccessibleClass))
typedef struct _GailRange GailRange;
typedef struct _GailRangeClass GailRangeClass;
typedef struct _GtkRangeAccessible GtkRangeAccessible;
typedef struct _GtkRangeAccessibleClass GtkRangeAccessibleClass;
struct _GailRange
struct _GtkRangeAccessible
{
GailWidget parent;
AtkObject *adjustment;
gchar *activate_keybinding;
guint action_idle_handler;
};
GType gail_range_get_type (void);
struct _GailRangeClass
struct _GtkRangeAccessibleClass
{
GailWidgetClass parent_class;
};
GType gtk_range_accessible_get_type (void);
G_END_DECLS
#endif /* __GAIL_RANGE_H__ */
#endif /* __GTK_RANGE_ACCESSIBLE_H__ */
......@@ -22,7 +22,7 @@
#include <gtk/gtk.h>
#include "gtkscaleaccessible.h"
G_DEFINE_TYPE (GtkScaleAccessible, gtk_scale_accessible, GAIL_TYPE_RANGE)
G_DEFINE_TYPE (GtkScaleAccessible, gtk_scale_accessible, GTK_TYPE_RANGE_ACCESSIBLE)
static const gchar *
gtk_scale_accessible_get_description (AtkObject *object)
......
......@@ -20,8 +20,7 @@
#ifndef __GTK_SCALE_ACCESSIBLE_H__
#define __GTK_SCALE_ACCESSIBLE_H__
#include "gailrange.h"
#include "gailtextutil.h"
#include "gtkrangeaccessible.h"
G_BEGIN_DECLS
......@@ -37,12 +36,12 @@ typedef struct _GtkScaleAccessibleClass GtkScaleAccessibleClass;
struct _GtkScaleAccessible
{
GailRange parent;
GtkRangeAccessible parent;
};
struct _GtkScaleAccessibleClass
{
GailRangeClass parent_class;
GtkRangeAccessibleClass parent_class;
};
GType gtk_scale_accessible_get_type (void);
......
......@@ -23,7 +23,7 @@
#include "gtkscrollbaraccessible.h"
G_DEFINE_TYPE (GtkScrollbarAccessible, gtk_scrollbar_accessible, GAIL_TYPE_RANGE)
G_DEFINE_TYPE (GtkScrollbarAccessible, gtk_scrollbar_accessible, GTK_TYPE_RANGE_ACCESSIBLE)
static void
gtk_scrollbar_accessible_init (GtkScrollbarAccessible *accessible)
......
......@@ -20,7 +20,7 @@
#ifndef __GTK_SCROLLBAR_ACCESSIBLE_H__
#define __GTK_SCROLLBAR_ACCESSIBLE_H__
#include "gailrange.h"
#include "gtkrangeaccessible.h"
G_BEGIN_DECLS
......@@ -36,12 +36,12 @@ typedef struct _GtkScrollbarAccessibleClass GtkScrollbarAccessibleClass;
struct _GtkScrollbarAccessible
{
GailRange parent;