GtkLabelAccessible: reorganize the code

Separate the GtkLabelAccessible, GtkLabelAccessibleLink and
GtkLabelAccessibleLinkImpl implementations more clearly.
This commit is contained in:
Matthias Clasen 2014-01-04 10:47:22 -05:00
parent b85a8001e0
commit 9bf89f2b5e

View File

@ -15,6 +15,8 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/ */
/* Preamble {{{1 */
#include "config.h" #include "config.h"
#include <gtk/gtk.h> #include <gtk/gtk.h>
@ -49,6 +51,9 @@ struct _GtkLabelAccessibleLinkClass
AtkHyperlinkClass parent_class; AtkHyperlinkClass parent_class;
}; };
static GtkLabelAccessibleLink *gtk_label_accessible_link_new (GtkLabelAccessible *label,
gint idx);
typedef struct _GtkLabelAccessibleLinkImpl GtkLabelAccessibleLinkImpl; typedef struct _GtkLabelAccessibleLinkImpl GtkLabelAccessibleLinkImpl;
typedef struct _GtkLabelAccessibleLinkImplClass GtkLabelAccessibleLinkImplClass; typedef struct _GtkLabelAccessibleLinkImplClass GtkLabelAccessibleLinkImplClass;
@ -64,44 +69,15 @@ struct _GtkLabelAccessibleLinkImplClass
AtkObjectClass parent_class; AtkObjectClass parent_class;
}; };
static void atk_action_interface_init (AtkActionIface *iface); /* GtkLabelAccessibleLinkImpl {{{1 */
static void atk_hyperlink_impl_interface_init (AtkHyperlinkImplIface *iface);
GType _gtk_label_accessible_link_get_type (void);
GType _gtk_label_accessible_link_impl_get_type (void); GType _gtk_label_accessible_link_impl_get_type (void);
G_DEFINE_TYPE_WITH_CODE (GtkLabelAccessibleLink, _gtk_label_accessible_link, ATK_TYPE_HYPERLINK, static void atk_hyperlink_impl_interface_init (AtkHyperlinkImplIface *iface);
G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION, atk_action_interface_init))
G_DEFINE_TYPE_WITH_CODE (GtkLabelAccessibleLinkImpl, _gtk_label_accessible_link_impl, ATK_TYPE_OBJECT, G_DEFINE_TYPE_WITH_CODE (GtkLabelAccessibleLinkImpl, _gtk_label_accessible_link_impl, ATK_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (ATK_TYPE_HYPERLINK_IMPL, atk_hyperlink_impl_interface_init)) G_IMPLEMENT_INTERFACE (ATK_TYPE_HYPERLINK_IMPL, atk_hyperlink_impl_interface_init))
static GtkLabelAccessibleLink *
gtk_label_accessible_link_new (GtkLabelAccessible *label,
gint idx)
{
GtkLabelAccessibleLink *link;
link = g_object_new (_gtk_label_accessible_link_get_type (), NULL);
link->label = label;
link->index = idx;
return link;
}
static GtkLabelAccessibleLinkImpl *
gtk_label_accessible_link_impl_new (GtkLabelAccessible *label,
gint idx)
{
GtkLabelAccessibleLinkImpl *impl;
impl = g_object_new (_gtk_label_accessible_link_impl_get_type (), NULL);
atk_object_set_parent (ATK_OBJECT (impl), ATK_OBJECT (label));
impl->link = gtk_label_accessible_link_new (label, idx);
return impl;
}
static AtkHyperlink * static AtkHyperlink *
gtk_label_accessible_link_impl_get_hyperlink (AtkHyperlinkImpl *atk_impl) gtk_label_accessible_link_impl_get_hyperlink (AtkHyperlinkImpl *atk_impl)
{ {
@ -172,6 +148,30 @@ _gtk_label_accessible_link_impl_class_init (GtkLabelAccessibleLinkImplClass *cla
atk_obj_class->ref_state_set = gtk_label_accessible_link_impl_ref_state_set; atk_obj_class->ref_state_set = gtk_label_accessible_link_impl_ref_state_set;
} }
/* 'Public' API {{{2 */
static GtkLabelAccessibleLinkImpl *
gtk_label_accessible_link_impl_new (GtkLabelAccessible *label,
gint idx)
{
GtkLabelAccessibleLinkImpl *impl;
impl = g_object_new (_gtk_label_accessible_link_impl_get_type (), NULL);
atk_object_set_parent (ATK_OBJECT (impl), ATK_OBJECT (label));
impl->link = gtk_label_accessible_link_new (label, idx);
return impl;
}
/* GtkLabelAccessibleLink {{{1 */
GType _gtk_label_accessible_link_get_type (void);
static void atk_action_interface_init (AtkActionIface *iface);
G_DEFINE_TYPE_WITH_CODE (GtkLabelAccessibleLink, _gtk_label_accessible_link, ATK_TYPE_HYPERLINK,
G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION, atk_action_interface_init))
static gchar * static gchar *
gtk_label_accessible_link_get_uri (AtkHyperlink *atk_link, gtk_label_accessible_link_get_uri (AtkHyperlink *atk_link,
gint i) gint i)
@ -264,6 +264,23 @@ _gtk_label_accessible_link_class_init (GtkLabelAccessibleLinkClass *class)
atk_link_class->get_end_index = gtk_label_accessible_link_get_end_index; atk_link_class->get_end_index = gtk_label_accessible_link_get_end_index;
} }
/* 'Public' API {{{2 */
static GtkLabelAccessibleLink *
gtk_label_accessible_link_new (GtkLabelAccessible *label,
gint idx)
{
GtkLabelAccessibleLink *link;
link = g_object_new (_gtk_label_accessible_link_get_type (), NULL);
link->label = label;
link->index = idx;
return link;
}
/* AtkAction implementation {{{2 */
static gboolean static gboolean
gtk_label_accessible_link_do_action (AtkAction *action, gtk_label_accessible_link_do_action (AtkAction *action,
gint i) gint i)
@ -313,6 +330,8 @@ atk_action_interface_init (AtkActionIface *iface)
iface->get_name = gtk_label_accessible_link_get_name; iface->get_name = gtk_label_accessible_link_get_name;
} }
/* GtkLabelAccessible {{{1 */
static void atk_text_interface_init (AtkTextIface *iface); static void atk_text_interface_init (AtkTextIface *iface);
static void atk_hypertext_interface_init (AtkHypertextIface *iface); static void atk_hypertext_interface_init (AtkHypertextIface *iface);
@ -379,46 +398,6 @@ check_for_selection_change (GtkLabelAccessible *accessible,
return ret_val; return ret_val;
} }
void
_gtk_label_accessible_text_deleted (GtkLabel *label)
{
AtkObject *obj;
const char *text;
guint length;
obj = _gtk_widget_peek_accessible (GTK_WIDGET (label));
if (obj == NULL)
return;
text = gtk_label_get_text (label);
length = g_utf8_strlen (text, -1);
if (length > 0)
g_signal_emit_by_name (obj, "text-changed::delete", 0, length);
}
void
_gtk_label_accessible_text_inserted (GtkLabel *label)
{
AtkObject *obj;
const char *text;
guint length;
obj = _gtk_widget_peek_accessible (GTK_WIDGET (label));
if (obj == NULL)
return;
text = gtk_label_get_text (label);
length = g_utf8_strlen (text, -1);
if (length > 0)
g_signal_emit_by_name (obj, "text-changed::insert", 0, length);
if (obj->name == NULL)
/* The label has changed so notify a change in accessible-name */
g_object_notify (G_OBJECT (obj), "accessible-name");
g_signal_emit_by_name (obj, "visible-data-changed");
}
static void static void
gtk_label_accessible_notify_gtk (GObject *obj, gtk_label_accessible_notify_gtk (GObject *obj,
GParamSpec *pspec) GParamSpec *pspec)
@ -609,7 +588,125 @@ gtk_label_accessible_class_init (GtkLabelAccessibleClass *klass)
widget_class->notify_gtk = gtk_label_accessible_notify_gtk; widget_class->notify_gtk = gtk_label_accessible_notify_gtk;
} }
/* atktext.h */ /* 'Public' API {{{2 */
void
_gtk_label_accessible_text_deleted (GtkLabel *label)
{
AtkObject *obj;
const char *text;
guint length;
obj = _gtk_widget_peek_accessible (GTK_WIDGET (label));
if (obj == NULL)
return;
text = gtk_label_get_text (label);
length = g_utf8_strlen (text, -1);
if (length > 0)
g_signal_emit_by_name (obj, "text-changed::delete", 0, length);
}
void
_gtk_label_accessible_text_inserted (GtkLabel *label)
{
AtkObject *obj;
const char *text;
guint length;
obj = _gtk_widget_peek_accessible (GTK_WIDGET (label));
if (obj == NULL)
return;
text = gtk_label_get_text (label);
length = g_utf8_strlen (text, -1);
if (length > 0)
g_signal_emit_by_name (obj, "text-changed::insert", 0, length);
if (obj->name == NULL)
/* The label has changed so notify a change in accessible-name */
g_object_notify (G_OBJECT (obj), "accessible-name");
g_signal_emit_by_name (obj, "visible-data-changed");
}
static void
clear_links (GtkLabelAccessible *accessible)
{
GList *l;
gint i;
GtkLabelAccessibleLinkImpl *impl;
for (l = accessible->priv->links, i = 0; l; l = l->next, i++)
{
impl = l->data;
g_signal_emit_by_name (accessible, "children-changed::remove", i, impl, NULL);
atk_object_set_parent (ATK_OBJECT (impl), NULL);
impl->link->label = NULL;
}
g_list_free_full (accessible->priv->links, g_object_unref);
accessible->priv->links = NULL;
}
static void
create_links (GtkLabelAccessible *accessible)
{
GtkWidget *widget;
gint n, i;
GtkLabelAccessibleLinkImpl *impl;
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
n = _gtk_label_get_n_links (GTK_LABEL (widget));
for (i = 0; i < n; i++)
{
impl = gtk_label_accessible_link_impl_new (accessible, i);
accessible->priv->links = g_list_append (accessible->priv->links, impl);
g_signal_emit_by_name (accessible, "children-changed::add", i, impl, NULL);
}
}
void
_gtk_label_accessible_update_links (GtkLabel *label)
{
AtkObject *obj;
obj = _gtk_widget_peek_accessible (GTK_WIDGET (label));
if (obj == NULL)
return;
clear_links (GTK_LABEL_ACCESSIBLE (obj));
create_links (GTK_LABEL_ACCESSIBLE (obj));
}
void
_gtk_label_accessible_focus_link_changed (GtkLabel *label)
{
AtkObject *obj;
GtkLabelAccessible *accessible;
GList *l;
GtkLabelAccessibleLinkImpl *impl;
gboolean focused;
obj = _gtk_widget_peek_accessible (GTK_WIDGET (label));
if (obj == NULL)
return;
accessible = GTK_LABEL_ACCESSIBLE (obj);
for (l = accessible->priv->links; l; l = l->next)
{
impl = l->data;
focused = _gtk_label_get_link_focused (label, impl->link->index);
if (impl->link->focused != focused)
{
impl->link->focused = focused;
atk_object_notify_state_change (ATK_OBJECT (impl), ATK_STATE_FOCUSED, focused);
}
}
}
/* AtkText implementation {{{2 */
static gchar* static gchar*
gtk_label_accessible_get_text (AtkText *atk_text, gtk_label_accessible_get_text (AtkText *atk_text,
@ -1093,81 +1190,7 @@ atk_text_interface_init (AtkTextIface *iface)
iface->get_default_attributes = gtk_label_accessible_get_default_attributes; iface->get_default_attributes = gtk_label_accessible_get_default_attributes;
} }
static void /* AtkHypertext implementation {{{2 */
clear_links (GtkLabelAccessible *accessible)
{
GList *l;
gint i;
GtkLabelAccessibleLinkImpl *impl;
for (l = accessible->priv->links, i = 0; l; l = l->next, i++)
{
impl = l->data;
g_signal_emit_by_name (accessible, "children-changed::remove", i, impl, NULL);
atk_object_set_parent (ATK_OBJECT (impl), NULL);
impl->link->label = NULL;
}
g_list_free_full (accessible->priv->links, g_object_unref);
accessible->priv->links = NULL;
}
static void
create_links (GtkLabelAccessible *accessible)
{
GtkWidget *widget;
gint n, i;
GtkLabelAccessibleLinkImpl *impl;
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
n = _gtk_label_get_n_links (GTK_LABEL (widget));
for (i = 0; i < n; i++)
{
impl = gtk_label_accessible_link_impl_new (accessible, i);
accessible->priv->links = g_list_append (accessible->priv->links, impl);
g_signal_emit_by_name (accessible, "children-changed::add", i, impl, NULL);
}
}
void
_gtk_label_accessible_update_links (GtkLabel *label)
{
AtkObject *obj;
obj = _gtk_widget_peek_accessible (GTK_WIDGET (label));
if (obj == NULL)
return;
clear_links (GTK_LABEL_ACCESSIBLE (obj));
create_links (GTK_LABEL_ACCESSIBLE (obj));
}
void
_gtk_label_accessible_focus_link_changed (GtkLabel *label)
{
AtkObject *obj;
GtkLabelAccessible *accessible;
GList *l;
GtkLabelAccessibleLinkImpl *impl;
gboolean focused;
obj = _gtk_widget_peek_accessible (GTK_WIDGET (label));
if (obj == NULL)
return;
accessible = GTK_LABEL_ACCESSIBLE (obj);
for (l = accessible->priv->links; l; l = l->next)
{
impl = l->data;
focused = _gtk_label_get_link_focused (label, impl->link->index);
if (impl->link->focused != focused)
{
impl->link->focused = focused;
atk_object_notify_state_change (ATK_OBJECT (impl), ATK_STATE_FOCUSED, focused);
}
}
}
static AtkHyperlink * static AtkHyperlink *
gtk_label_accessible_get_link (AtkHypertext *hypertext, gtk_label_accessible_get_link (AtkHypertext *hypertext,
@ -1212,3 +1235,5 @@ atk_hypertext_interface_init (AtkHypertextIface *iface)
iface->get_n_links = gtk_label_accessible_get_n_links; iface->get_n_links = gtk_label_accessible_get_n_links;
iface->get_link_index = gtk_label_accessible_get_link_index; iface->get_link_index = gtk_label_accessible_get_link_index;
} }
/* vim:set foldmethod=marker expandtab: */