[gtk/wip/ebassi/a11y-2: 438/442] a11y: Simplify GtkScrollbarAccessible
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/ebassi/a11y-2: 438/442] a11y: Simplify GtkScrollbarAccessible
- Date: Fri, 5 Jun 2020 19:38:07 +0000 (UTC)
commit 7c2c795681b405c971b5f3e7f2c0704bf481dcbf
Author: Emmanuele Bassi <ebassi gnome org>
Date: Fri Jun 5 15:52:53 2020 +0100
a11y: Simplify GtkScrollbarAccessible
gtk/a11y/gtkscrollbaraccessible.c | 109 ++++++++++++++++++++------------------
gtk/a11y/gtkscrollbaraccessible.h | 3 --
2 files changed, 56 insertions(+), 56 deletions(-)
---
diff --git a/gtk/a11y/gtkscrollbaraccessible.c b/gtk/a11y/gtkscrollbaraccessible.c
index 8a045cc697..6a65ecf9de 100644
--- a/gtk/a11y/gtkscrollbaraccessible.c
+++ b/gtk/a11y/gtkscrollbaraccessible.c
@@ -21,10 +21,11 @@
#include <gtk/gtk.h>
#include "gtkscrollbaraccessible.h"
-struct _GtkScrollbarAccessiblePrivate
+typedef struct
{
GtkAdjustment *adjustment;
-};
+ gulong value_changed_id;
+} GtkScrollbarAccessiblePrivate;
static void atk_value_interface_init (AtkValueIface *iface);
@@ -33,91 +34,93 @@ G_DEFINE_TYPE_WITH_CODE (GtkScrollbarAccessible, gtk_scrollbar_accessible, GTK_T
G_IMPLEMENT_INTERFACE (ATK_TYPE_VALUE, atk_value_interface_init))
static void
-gtk_scrollbar_accessible_value_changed (GtkAdjustment *adjustment,
- gpointer data)
+on_value_changed (GtkAdjustment *adjustment,
+ gpointer data)
{
- g_object_notify (G_OBJECT (data), "accessible-value");
+ GtkScrollbarAccessible *self = data;
+
+ g_object_notify (G_OBJECT (self), "accessible-value");
}
static void
-gtk_scrollbar_accessible_widget_set (GtkAccessible *accessible)
+on_adjustment_changed (GObject *gobject,
+ GParamSpec *pspec,
+ gpointer data)
{
- GtkScrollbarAccessiblePrivate *priv = GTK_SCROLLBAR_ACCESSIBLE (accessible)->priv;
- GtkWidget *scrollbar;
- GtkAdjustment *adj;
+ GtkScrollbar *scrollbar = GTK_SCROLLBAR (gobject);
+ GtkScrollbarAccessible *self = data;
+ GtkScrollbarAccessiblePrivate *priv =
+ gtk_scrollbar_accessible_get_instance_private (self);
+ GtkAdjustment *adjustment =
+ gtk_scrollbar_get_adjustment (scrollbar);
+
+ if (priv->adjustment == adjustment)
+ return;
- scrollbar = gtk_accessible_get_widget (accessible);
- adj = gtk_scrollbar_get_adjustment (GTK_SCROLLBAR (scrollbar));
- if (adj)
+ if (priv->adjustment != NULL && priv->value_changed_id != 0)
{
- priv->adjustment = adj;
- g_object_ref (priv->adjustment);
- g_signal_connect (priv->adjustment, "value-changed",
- G_CALLBACK (gtk_scrollbar_accessible_value_changed),
- accessible);
+ g_signal_handler_disconnect (priv->adjustment, priv->value_changed_id);
+ priv->value_changed_id = 0;
+ }
+
+ g_clear_object (&priv->adjustment);
+
+ if (adjustment != NULL)
+ {
+ priv->adjustment = g_object_ref (adjustment);
+ priv->value_changed_id =
+ g_signal_connect (priv->adjustment, "value-changed",
+ G_CALLBACK (on_value_changed),
+ self);
}
}
static void
-gtk_scrollbar_accessible_widget_unset (GtkAccessible *accessible)
+gtk_scrollbar_accessible_dispose (GObject *gobject)
{
- GtkScrollbarAccessiblePrivate *priv = GTK_SCROLLBAR_ACCESSIBLE (accessible)->priv;
+ GtkScrollbarAccessible *self = GTK_SCROLLBAR_ACCESSIBLE (gobject);
+ GtkScrollbarAccessiblePrivate *priv =
+ gtk_scrollbar_accessible_get_instance_private (self);
- if (priv->adjustment)
+ if (priv->adjustment != NULL && priv->value_changed_id != 0)
{
- g_signal_handlers_disconnect_by_func (priv->adjustment,
- G_CALLBACK (gtk_scrollbar_accessible_value_changed),
- accessible);
- g_object_unref (priv->adjustment);
- priv->adjustment = NULL;
+ g_signal_handler_disconnect (priv->adjustment, priv->value_changed_id);
+ priv->value_changed_id = 0;
}
+
+ g_clear_object (&priv->adjustment);
+
+ G_OBJECT_CLASS (gtk_scrollbar_accessible_parent_class)->dispose (gobject);
}
static void
gtk_scrollbar_accessible_initialize (AtkObject *obj,
gpointer data)
{
- ATK_OBJECT_CLASS (gtk_scrollbar_accessible_parent_class)->initialize (obj, data);
- obj->role = ATK_ROLE_SCROLL_BAR;
-}
+ GtkScrollbar *scrollbar = data;
-static void
-gtk_scrollbar_accessible_notify_gtk (GObject *obj,
- GParamSpec *pspec)
-{
- GtkWidget *widget = GTK_WIDGET (obj);
- AtkObject *scrollbar;
+ ATK_OBJECT_CLASS (gtk_scrollbar_accessible_parent_class)->initialize (obj, data);
- if (strcmp (pspec->name, "adjustment") == 0)
- {
- scrollbar = gtk_widget_get_accessible (widget);
- gtk_scrollbar_accessible_widget_unset (GTK_ACCESSIBLE (scrollbar));
- gtk_scrollbar_accessible_widget_set (GTK_ACCESSIBLE (scrollbar));
- }
- else
- GTK_WIDGET_ACCESSIBLE_CLASS (gtk_scrollbar_accessible_parent_class)->notify_gtk (obj, pspec);
+ g_signal_connect (scrollbar, "notify::adjustment",
+ G_CALLBACK (on_adjustment_changed),
+ obj);
}
-
static void
gtk_scrollbar_accessible_class_init (GtkScrollbarAccessibleClass *klass)
{
- AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
- GtkAccessibleClass *accessible_class = (GtkAccessibleClass*)klass;
- GtkWidgetAccessibleClass *widget_class = (GtkWidgetAccessibleClass*)klass;
-
- class->initialize = gtk_scrollbar_accessible_initialize;
+ AtkObjectClass *atk_object_class = ATK_OBJECT_CLASS (klass);
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
- accessible_class->widget_set = gtk_scrollbar_accessible_widget_set;
- accessible_class->widget_unset = gtk_scrollbar_accessible_widget_unset;
+ atk_object_class->initialize = gtk_scrollbar_accessible_initialize;
- widget_class->notify_gtk = gtk_scrollbar_accessible_notify_gtk;
+ gobject_class->dispose = gtk_scrollbar_accessible_dispose;
}
static void
-gtk_scrollbar_accessible_init (GtkScrollbarAccessible *scrollbar)
+gtk_scrollbar_accessible_init (GtkScrollbarAccessible *self)
{
- scrollbar->priv = gtk_scrollbar_accessible_get_instance_private (scrollbar);
+ ATK_OBJECT (self)->role = ATK_ROLE_SCROLL_BAR;
}
static void
diff --git a/gtk/a11y/gtkscrollbaraccessible.h b/gtk/a11y/gtkscrollbaraccessible.h
index 93515bc856..bac0e3fd48 100644
--- a/gtk/a11y/gtkscrollbaraccessible.h
+++ b/gtk/a11y/gtkscrollbaraccessible.h
@@ -35,13 +35,10 @@ G_BEGIN_DECLS
typedef struct _GtkScrollbarAccessible GtkScrollbarAccessible;
typedef struct _GtkScrollbarAccessibleClass GtkScrollbarAccessibleClass;
-typedef struct _GtkScrollbarAccessiblePrivate GtkScrollbarAccessiblePrivate;
struct _GtkScrollbarAccessible
{
GtkWidgetAccessible parent;
-
- GtkScrollbarAccessiblePrivate *priv;
};
struct _GtkScrollbarAccessibleClass
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]