2012-10-30 14:21:44 +00:00
|
|
|
/* GTK+ - accessibility implementations
|
2011-02-17 12:10:31 +00:00
|
|
|
* 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
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2011-02-17 12:10:31 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
2011-06-27 03:48:54 +00:00
|
|
|
#include "gtklinkbuttonaccessible.h"
|
2011-02-17 12:10:31 +00:00
|
|
|
|
2011-06-27 03:48:54 +00:00
|
|
|
typedef struct _GtkLinkButtonAccessibleLink GtkLinkButtonAccessibleLink;
|
|
|
|
typedef struct _GtkLinkButtonAccessibleLinkClass GtkLinkButtonAccessibleLinkClass;
|
2011-02-17 12:10:31 +00:00
|
|
|
|
2012-10-14 23:55:59 +00:00
|
|
|
struct _GtkLinkButtonAccessiblePrivate
|
|
|
|
{
|
|
|
|
AtkHyperlink *link;
|
|
|
|
};
|
|
|
|
|
2011-06-27 03:48:54 +00:00
|
|
|
struct _GtkLinkButtonAccessibleLink
|
2011-02-17 12:10:31 +00:00
|
|
|
{
|
|
|
|
AtkHyperlink parent;
|
|
|
|
|
2011-06-27 03:48:54 +00:00
|
|
|
GtkLinkButtonAccessible *button;
|
2011-02-17 12:10:31 +00:00
|
|
|
};
|
|
|
|
|
2011-06-27 03:48:54 +00:00
|
|
|
struct _GtkLinkButtonAccessibleLinkClass
|
2011-02-17 12:10:31 +00:00
|
|
|
{
|
|
|
|
AtkHyperlinkClass parent_class;
|
|
|
|
};
|
|
|
|
|
2011-02-18 02:00:35 +00:00
|
|
|
static void atk_action_interface_init (AtkActionIface *iface);
|
|
|
|
|
2012-10-02 17:13:30 +00:00
|
|
|
GType _gtk_link_button_accessible_link_get_type (void);
|
|
|
|
|
2011-07-09 20:32:40 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkLinkButtonAccessibleLink, _gtk_link_button_accessible_link, ATK_TYPE_HYPERLINK,
|
2011-02-18 02:00:35 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION, atk_action_interface_init))
|
2011-02-17 12:10:31 +00:00
|
|
|
|
2011-06-20 11:57:50 +00:00
|
|
|
static AtkHyperlink *
|
2011-06-27 03:48:54 +00:00
|
|
|
gtk_link_button_accessible_link_new (GtkLinkButtonAccessible *button)
|
2011-06-19 22:53:24 +00:00
|
|
|
{
|
2011-07-10 04:16:53 +00:00
|
|
|
GtkLinkButtonAccessibleLink *l;
|
2011-06-19 22:53:24 +00:00
|
|
|
|
2011-07-10 04:16:53 +00:00
|
|
|
l = g_object_new (_gtk_link_button_accessible_link_get_type (), NULL);
|
|
|
|
l->button = button;
|
2011-06-19 22:53:24 +00:00
|
|
|
|
2011-07-10 04:16:53 +00:00
|
|
|
return ATK_HYPERLINK (l);
|
2011-06-19 22:53:24 +00:00
|
|
|
}
|
|
|
|
|
2011-02-17 12:10:31 +00:00
|
|
|
static gchar *
|
2011-07-10 04:16:53 +00:00
|
|
|
gtk_link_button_accessible_link_get_uri (AtkHyperlink *atk_link,
|
2011-07-09 20:32:40 +00:00
|
|
|
gint i)
|
2011-02-17 12:10:31 +00:00
|
|
|
{
|
2011-07-10 04:16:53 +00:00
|
|
|
GtkLinkButtonAccessibleLink *l = (GtkLinkButtonAccessibleLink *)atk_link;
|
2011-02-17 12:10:31 +00:00
|
|
|
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
|
2011-07-10 04:16:53 +00:00
|
|
|
gtk_link_button_accessible_link_get_n_anchors (AtkHyperlink *atk_link)
|
2011-02-17 12:10:31 +00:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-07-10 04:16:53 +00:00
|
|
|
gtk_link_button_accessible_link_is_valid (AtkHyperlink *atk_link)
|
2011-02-17 12:10:31 +00:00
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static AtkObject *
|
2011-07-10 04:16:53 +00:00
|
|
|
gtk_link_button_accessible_link_get_object (AtkHyperlink *atk_link,
|
2011-07-09 20:32:40 +00:00
|
|
|
gint i)
|
2011-02-17 12:10:31 +00:00
|
|
|
{
|
2011-07-10 04:16:53 +00:00
|
|
|
GtkLinkButtonAccessibleLink *l = (GtkLinkButtonAccessibleLink *)atk_link;
|
2011-02-17 12:10:31 +00:00
|
|
|
|
|
|
|
return ATK_OBJECT (l->button);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
2011-07-10 04:16:53 +00:00
|
|
|
gtk_link_button_accessible_link_get_start_index (AtkHyperlink *atk_link)
|
2011-02-17 12:10:31 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
2011-07-10 04:16:53 +00:00
|
|
|
gtk_link_button_accessible_link_get_end_index (AtkHyperlink *atk_link)
|
2011-02-17 12:10:31 +00:00
|
|
|
{
|
2011-07-10 04:16:53 +00:00
|
|
|
GtkLinkButtonAccessibleLink *l = (GtkLinkButtonAccessibleLink *)atk_link;
|
2011-02-17 12:10:31 +00:00
|
|
|
|
|
|
|
return atk_text_get_character_count (ATK_TEXT (l->button));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-07-10 04:16:53 +00:00
|
|
|
_gtk_link_button_accessible_link_init (GtkLinkButtonAccessibleLink *l)
|
2011-02-17 12:10:31 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-07-09 20:32:40 +00:00
|
|
|
_gtk_link_button_accessible_link_class_init (GtkLinkButtonAccessibleLinkClass *class)
|
2011-02-17 12:10:31 +00:00
|
|
|
{
|
2011-07-10 04:16:53 +00:00
|
|
|
AtkHyperlinkClass *atk_link_class = ATK_HYPERLINK_CLASS (class);
|
2011-02-17 12:10:31 +00:00
|
|
|
|
2011-07-10 04:16:53 +00:00
|
|
|
atk_link_class->get_uri = gtk_link_button_accessible_link_get_uri;
|
|
|
|
atk_link_class->get_n_anchors = gtk_link_button_accessible_link_get_n_anchors;
|
|
|
|
atk_link_class->is_valid = gtk_link_button_accessible_link_is_valid;
|
|
|
|
atk_link_class->get_object = gtk_link_button_accessible_link_get_object;
|
|
|
|
atk_link_class->get_start_index = gtk_link_button_accessible_link_get_start_index;
|
|
|
|
atk_link_class->get_end_index = gtk_link_button_accessible_link_get_end_index;
|
2011-02-17 12:10:31 +00:00
|
|
|
}
|
|
|
|
|
2011-02-18 02:00:35 +00:00
|
|
|
static gboolean
|
2011-06-27 03:48:54 +00:00
|
|
|
gtk_link_button_accessible_link_do_action (AtkAction *action,
|
2011-07-09 20:32:40 +00:00
|
|
|
gint i)
|
2011-02-18 02:00:35 +00:00
|
|
|
{
|
2011-07-10 04:16:53 +00:00
|
|
|
GtkLinkButtonAccessibleLink *l = (GtkLinkButtonAccessibleLink *)action;
|
2011-02-18 02:00:35 +00:00
|
|
|
GtkWidget *widget;
|
|
|
|
|
2011-07-10 04:16:53 +00:00
|
|
|
widget = GTK_WIDGET (l->button);
|
2011-02-18 02:00:35 +00:00
|
|
|
if (widget == NULL)
|
2011-07-09 20:32:40 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (i != 0)
|
2011-02-18 02:00:35 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!gtk_widget_is_sensitive (widget) || !gtk_widget_get_visible (widget))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
gtk_button_clicked (GTK_BUTTON (widget));
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
2011-06-27 03:48:54 +00:00
|
|
|
gtk_link_button_accessible_link_get_n_actions (AtkAction *action)
|
2011-02-18 02:00:35 +00:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const gchar *
|
2011-06-27 03:48:54 +00:00
|
|
|
gtk_link_button_accessible_link_get_name (AtkAction *action,
|
|
|
|
gint i)
|
2011-02-18 02:00:35 +00:00
|
|
|
{
|
2011-07-09 20:32:40 +00:00
|
|
|
if (i != 0)
|
|
|
|
return NULL;
|
2011-02-18 02:00:35 +00:00
|
|
|
|
|
|
|
return "activate";
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
atk_action_interface_init (AtkActionIface *iface)
|
|
|
|
{
|
2011-06-27 03:48:54 +00:00
|
|
|
iface->do_action = gtk_link_button_accessible_link_do_action;
|
|
|
|
iface->get_n_actions = gtk_link_button_accessible_link_get_n_actions;
|
|
|
|
iface->get_name = gtk_link_button_accessible_link_get_name;
|
2011-02-18 02:00:35 +00:00
|
|
|
}
|
|
|
|
|
2011-02-17 12:10:31 +00:00
|
|
|
static gboolean
|
2011-07-09 20:32:40 +00:00
|
|
|
activate_link (GtkLinkButton *button,
|
2011-07-10 04:16:53 +00:00
|
|
|
AtkHyperlink *atk_link)
|
2011-02-17 12:10:31 +00:00
|
|
|
{
|
2011-07-10 04:16:53 +00:00
|
|
|
g_signal_emit_by_name (atk_link, "link-activated");
|
2011-02-17 12:10:31 +00:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static AtkHyperlink *
|
2011-06-27 03:48:54 +00:00
|
|
|
gtk_link_button_accessible_get_hyperlink (AtkHyperlinkImpl *impl)
|
2011-02-17 12:10:31 +00:00
|
|
|
{
|
2011-06-27 03:48:54 +00:00
|
|
|
GtkLinkButtonAccessible *button = GTK_LINK_BUTTON_ACCESSIBLE (impl);
|
2011-02-17 12:10:31 +00:00
|
|
|
|
2012-10-14 23:55:59 +00:00
|
|
|
if (!button->priv->link)
|
2011-02-18 02:00:35 +00:00
|
|
|
{
|
2012-10-14 23:55:59 +00:00
|
|
|
button->priv->link = gtk_link_button_accessible_link_new (button);
|
2011-02-18 02:00:35 +00:00
|
|
|
g_signal_connect (gtk_accessible_get_widget (GTK_ACCESSIBLE (button)),
|
2012-10-14 23:55:59 +00:00
|
|
|
"activate-link", G_CALLBACK (activate_link), button->priv->link);
|
2011-02-18 02:00:35 +00:00
|
|
|
}
|
2011-02-17 12:10:31 +00:00
|
|
|
|
2012-10-14 23:55:59 +00:00
|
|
|
return g_object_ref (button->priv->link);
|
2011-02-17 12:10:31 +00:00
|
|
|
}
|
|
|
|
|
2011-02-18 02:00:35 +00:00
|
|
|
static void atk_hypertext_impl_interface_init (AtkHyperlinkImplIface *iface);
|
2011-02-17 12:10:31 +00:00
|
|
|
|
2012-12-27 06:04:46 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkLinkButtonAccessible, gtk_link_button_accessible, GTK_TYPE_BUTTON_ACCESSIBLE,
|
2011-02-18 02:00:35 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (ATK_TYPE_HYPERLINK_IMPL, atk_hypertext_impl_interface_init))
|
2011-02-17 12:10:31 +00:00
|
|
|
|
|
|
|
static void
|
2012-12-27 06:04:46 +00:00
|
|
|
gtk_link_button_accessible_init (GtkLinkButtonAccessible *button)
|
2011-02-17 12:10:31 +00:00
|
|
|
{
|
2012-10-14 23:55:59 +00:00
|
|
|
button->priv = G_TYPE_INSTANCE_GET_PRIVATE (button,
|
|
|
|
GTK_TYPE_LINK_BUTTON_ACCESSIBLE,
|
|
|
|
GtkLinkButtonAccessiblePrivate);
|
2011-02-17 12:10:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-06-27 03:48:54 +00:00
|
|
|
gtk_link_button_accessible_finalize (GObject *object)
|
2011-02-17 12:10:31 +00:00
|
|
|
{
|
2011-06-27 03:48:54 +00:00
|
|
|
GtkLinkButtonAccessible *button = GTK_LINK_BUTTON_ACCESSIBLE (object);
|
2011-02-17 12:10:31 +00:00
|
|
|
|
2012-10-14 23:55:59 +00:00
|
|
|
if (button->priv->link)
|
|
|
|
g_object_unref (button->priv->link);
|
2011-02-17 12:10:31 +00:00
|
|
|
|
2012-12-27 06:04:46 +00:00
|
|
|
G_OBJECT_CLASS (gtk_link_button_accessible_parent_class)->finalize (object);
|
2011-02-17 12:10:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-12-27 06:04:46 +00:00
|
|
|
gtk_link_button_accessible_class_init (GtkLinkButtonAccessibleClass *klass)
|
2011-02-17 12:10:31 +00:00
|
|
|
{
|
2011-06-27 03:48:54 +00:00
|
|
|
G_OBJECT_CLASS (klass)->finalize = gtk_link_button_accessible_finalize;
|
2012-10-14 23:55:59 +00:00
|
|
|
|
|
|
|
g_type_class_add_private (klass, sizeof (GtkLinkButtonAccessiblePrivate));
|
2011-02-17 12:10:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-02-18 02:00:35 +00:00
|
|
|
atk_hypertext_impl_interface_init (AtkHyperlinkImplIface *iface)
|
2011-02-17 12:10:31 +00:00
|
|
|
{
|
2011-06-27 03:48:54 +00:00
|
|
|
iface->get_hyperlink = gtk_link_button_accessible_get_hyperlink;
|
2011-02-17 12:10:31 +00:00
|
|
|
}
|