]> Pileus Git - ~andy/gtk/commitdiff
Add a AtkHypertext implementation for GtkLinkButton
authorMatthias Clasen <mclasen@redhat.com>
Thu, 17 Feb 2011 12:10:31 +0000 (07:10 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 17 Feb 2011 12:36:42 +0000 (07:36 -0500)
https://bugzilla.gnome.org/show_bug.cgi?id=586201

modules/other/gail/Makefile.am
modules/other/gail/gail.c
modules/other/gail/gaillinkbutton.c [new file with mode: 0644]
modules/other/gail/gaillinkbutton.h [new file with mode: 0644]

index 7285efbec86a08dd7368c648200f6e5fe9001d05..0a8bcc386c50601ba5473f57ce9d3f6d67dd6945 100644 (file)
@@ -31,6 +31,7 @@ gail_c_sources =                      \
        gailimage.c                     \
        gailimagecell.c                 \
        gaillabel.c                     \
+       gaillinkbutton.c                \
        gailmenu.c                      \
        gailmenushell.c                 \
        gailmenuitem.c                  \
index 0c2693703c3d2f0c886f37ed04d712558a0f9a63..28a99968eebdff00da320596db40c6f403630ef1 100644 (file)
@@ -74,6 +74,7 @@ static GQuark quark_focus_object = 0;
 GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_WIDGET, GailWidget, gail_widget, GTK_TYPE_WIDGET)
 GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_CONTAINER, GailContainer, gail_container, GTK_TYPE_CONTAINER)
 GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_BUTTON, GailButton, gail_button, GTK_TYPE_BUTTON)
+GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_LINK_BUTTON, GailLinkButton, gail_link_button, GTK_TYPE_LINK_BUTTON)
 GAIL_IMPLEMENT_FACTORY_WITH_FUNC (GAIL_TYPE_MENU_ITEM, GailMenuItem, gail_menu_item, gail_menu_item_new)
 GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_TOGGLE_BUTTON, GailToggleButton, gail_toggle_button, GTK_TYPE_TOGGLE_BUTTON)
 GAIL_IMPLEMENT_FACTORY (GAIL_TYPE_IMAGE, GailImage, gail_image, GTK_TYPE_IMAGE)
@@ -880,6 +881,7 @@ gail_accessibility_module_init (void)
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_WIDGET, gail_widget);
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_CONTAINER, gail_container);
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_BUTTON, gail_button);
+  GAIL_WIDGET_SET_FACTORY (GTK_TYPE_LINK_BUTTON, gail_link_button);
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_MENU_ITEM, gail_menu_item);
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_TOGGLE_BUTTON, gail_toggle_button);
   GAIL_WIDGET_SET_FACTORY (GTK_TYPE_IMAGE, gail_image);
diff --git a/modules/other/gail/gaillinkbutton.c b/modules/other/gail/gaillinkbutton.c
new file mode 100644 (file)
index 0000000..cfb212c
--- /dev/null
@@ -0,0 +1,188 @@
+/* GAIL - The GNOME Accessibility Implementation Library
+ * Copyright 2011 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include <gtk/gtk.h>
+#include "gaillinkbutton.h"
+
+typedef struct _GailLinkButtonLink GailLinkButtonLink;
+typedef struct _GailLinkButtonLinkClass GailLinkButtonLinkClass;
+
+struct _GailLinkButtonLink
+{
+  AtkHyperlink parent;
+
+  GailLinkButton *button;
+};
+
+struct _GailLinkButtonLinkClass
+{
+  AtkHyperlinkClass parent_class;
+};
+
+G_DEFINE_TYPE (GailLinkButtonLink, gail_link_button_link, ATK_TYPE_HYPERLINK)
+
+static gchar *
+gail_link_button_link_get_uri (AtkHyperlink *link,
+                               gint          i)
+{
+  GailLinkButtonLink *l = (GailLinkButtonLink *)link;
+  GtkWidget *widget;
+  const gchar *uri;
+
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (l->button));
+  uri = gtk_link_button_get_uri (GTK_LINK_BUTTON (widget));
+
+  return g_strdup (uri);
+}
+
+static gint
+gail_link_button_link_get_n_anchors (AtkHyperlink *link)
+{
+  return 1;
+}
+
+static gboolean
+gail_link_button_link_is_valid (AtkHyperlink *link)
+{
+  return TRUE;
+}
+
+static AtkObject *
+gail_link_button_link_get_object (AtkHyperlink *link,
+                                  gint          i)
+{
+  GailLinkButtonLink *l = (GailLinkButtonLink *)link;
+
+  return ATK_OBJECT (l->button);
+}
+
+static gint
+gail_link_button_link_get_start_index (AtkHyperlink *link)
+{
+  return 0;
+}
+
+static gint
+gail_link_button_link_get_end_index (AtkHyperlink *link)
+{
+  GailLinkButtonLink *l = (GailLinkButtonLink *)link;
+
+  return atk_text_get_character_count (ATK_TEXT (l->button));
+}
+
+static void
+gail_link_button_link_init (GailLinkButtonLink *link)
+{
+}
+
+static void
+gail_link_button_link_class_init (GailLinkButtonLinkClass *class)
+{
+  AtkHyperlinkClass *hyperlink_class = ATK_HYPERLINK_CLASS (class);
+
+  hyperlink_class->get_uri = gail_link_button_link_get_uri;
+  hyperlink_class->get_n_anchors = gail_link_button_link_get_n_anchors;
+  hyperlink_class->is_valid = gail_link_button_link_is_valid;
+  hyperlink_class->get_object = gail_link_button_link_get_object;
+  hyperlink_class->get_start_index = gail_link_button_link_get_start_index;
+  hyperlink_class->get_end_index = gail_link_button_link_get_end_index;
+}
+
+static gboolean
+activate_link (GtkLinkButton *button, AtkHyperlink *link)
+{
+  g_signal_emit_by_name (link, "link-activated");
+
+  return FALSE;
+}
+
+static AtkHyperlink *
+gail_link_button_link_new (GailLinkButton *button)
+{
+  GailLinkButtonLink *link;
+
+  link = g_object_new (gail_link_button_link_get_type (), NULL);
+  link->button = button;
+  g_signal_connect (gtk_accessible_get_widget (GTK_ACCESSIBLE (button)),
+                    "activate-link", G_CALLBACK (activate_link), link);
+
+  return ATK_HYPERLINK (link);
+}
+
+static void atk_hypertext_interface_init (AtkHypertextIface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (GailLinkButton, gail_link_button, GAIL_TYPE_BUTTON,
+                         G_IMPLEMENT_INTERFACE (ATK_TYPE_HYPERTEXT, atk_hypertext_interface_init))
+
+static void
+gail_link_button_init (GailLinkButton *button)
+{
+}
+
+static void
+gail_link_button_finalize (GObject *object)
+{
+  GailLinkButton *button = GAIL_LINK_BUTTON (object);
+
+  if (button->link)
+    g_object_unref (button->link);
+
+  G_OBJECT_CLASS (gail_link_button_parent_class)->finalize (object);
+}
+
+static void
+gail_link_button_class_init (GailLinkButtonClass *klass)
+{
+  G_OBJECT_CLASS (klass)->finalize = gail_link_button_finalize;
+}
+
+static gint
+gail_link_button_get_n_links (AtkHypertext *hypertext)
+{
+  return 1;
+}
+
+static gint
+gail_link_button_get_link_index (AtkHypertext *hypertext,
+                                 gint          char_index)
+{
+  return 0;
+}
+
+static AtkHyperlink *
+gail_link_button_get_link (AtkHypertext *hypertext,
+                           gint          link_index)
+{
+  GailLinkButton *button = GAIL_LINK_BUTTON (hypertext);
+
+  if (!button->link)
+    button->link = gail_link_button_link_new (button);
+
+  return button->link;
+}
+
+static void
+atk_hypertext_interface_init (AtkHypertextIface *iface)
+{
+  iface->get_link = gail_link_button_get_link;
+  iface->get_n_links = gail_link_button_get_n_links;
+  iface->get_link_index = gail_link_button_get_link_index;
+}
diff --git a/modules/other/gail/gaillinkbutton.h b/modules/other/gail/gaillinkbutton.h
new file mode 100644 (file)
index 0000000..97e5214
--- /dev/null
@@ -0,0 +1,53 @@
+/* GAIL - The GNOME Accessibility Implementation Library
+ * Copyright 2011 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GAIL_LINK_BUTTON_H__
+#define __GAIL_LINK_BUTTON_H__
+
+#include <gail/gailbutton.h>
+
+G_BEGIN_DECLS
+
+#define GAIL_TYPE_LINK_BUTTON                (gail_link_button_get_type ())
+#define GAIL_LINK_BUTTON(obj)                (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAIL_TYPE_LINK_BUTTON, GailLinkButton))
+#define GAIL_LINK_BUTTON_CLASS(klass)        (G_TYPE_CHECK_CLASS_CAST ((klass), GAIL_TYPE_LINK_BUTTON, GailLinkButtonClass))
+#define GAIL_IS_LINK_BUTTON(obj)             (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAIL_TYPE_LINK_BUTTON))
+#define GAIL_IS_LINK_BUTTON_CLASS(klass)     (G_TYPE_CHECK_CLASS_TYPE ((klass), GAIL_TYPE_LINK_BUTTON))
+#define GAIL_LINK_BUTTON_GET_CLASS(obj)      (G_TYPE_INSTANCE_GET_CLASS ((obj), GAIL_TYPE_LINK_BUTTON, GailLinkButtonClass))
+
+typedef struct _GailLinkButton                   GailLinkButton;
+typedef struct _GailLinkButtonClass              GailLinkButtonClass;
+
+struct _GailLinkButton
+{
+  GailButton parent;
+
+  AtkHyperlink *link;
+};
+
+GType gail_link_button_get_type (void);
+
+struct _GailLinkButtonClass
+{
+  GailButtonClass parent_class;
+};
+
+G_END_DECLS
+
+#endif /* __GAIL_LINK_BUTTON_H__ */