2012-10-30 14:21:44 +00:00
|
|
|
/* GTK+ - accessibility implementations
|
2007-12-18 13:51:12 +00:00
|
|
|
* Copyright 2001, 2002, 2003 Sun Microsystems 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/>.
|
2007-12-18 13:51:12 +00:00
|
|
|
*/
|
|
|
|
|
2014-01-04 15:47:22 +00:00
|
|
|
/* Preamble {{{1 */
|
|
|
|
|
2008-06-22 14:28:52 +00:00
|
|
|
#include "config.h"
|
2007-12-23 12:27:33 +00:00
|
|
|
|
2007-12-18 13:51:12 +00:00
|
|
|
#include <gtk/gtk.h>
|
2011-06-25 00:36:05 +00:00
|
|
|
#include <gtk/gtkpango.h>
|
2013-03-14 23:54:26 +00:00
|
|
|
#include "gtkwidgetprivate.h"
|
2014-01-04 01:44:21 +00:00
|
|
|
#include "gtklabelprivate.h"
|
2011-06-23 05:12:29 +00:00
|
|
|
#include "gtklabelaccessible.h"
|
2014-01-04 03:59:37 +00:00
|
|
|
#include "gtklabelaccessibleprivate.h"
|
2014-06-15 16:03:59 +00:00
|
|
|
#include "gtkstylecontextprivate.h"
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2012-10-14 23:51:14 +00:00
|
|
|
struct _GtkLabelAccessiblePrivate
|
|
|
|
{
|
|
|
|
gint cursor_position;
|
|
|
|
gint selection_bound;
|
2014-01-04 03:59:37 +00:00
|
|
|
|
|
|
|
GList *links;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct _GtkLabelAccessibleLink GtkLabelAccessibleLink;
|
|
|
|
typedef struct _GtkLabelAccessibleLinkClass GtkLabelAccessibleLinkClass;
|
|
|
|
|
|
|
|
struct _GtkLabelAccessibleLink
|
|
|
|
{
|
|
|
|
AtkHyperlink parent;
|
|
|
|
|
|
|
|
GtkLabelAccessible *label;
|
|
|
|
gint index;
|
2014-01-04 14:43:23 +00:00
|
|
|
gboolean focused;
|
2014-01-04 03:59:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _GtkLabelAccessibleLinkClass
|
|
|
|
{
|
|
|
|
AtkHyperlinkClass parent_class;
|
2012-10-14 23:51:14 +00:00
|
|
|
};
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2014-01-04 15:47:22 +00:00
|
|
|
static GtkLabelAccessibleLink *gtk_label_accessible_link_new (GtkLabelAccessible *label,
|
|
|
|
gint idx);
|
|
|
|
|
2014-01-04 03:59:37 +00:00
|
|
|
typedef struct _GtkLabelAccessibleLinkImpl GtkLabelAccessibleLinkImpl;
|
|
|
|
typedef struct _GtkLabelAccessibleLinkImplClass GtkLabelAccessibleLinkImplClass;
|
|
|
|
|
|
|
|
struct _GtkLabelAccessibleLinkImpl
|
|
|
|
{
|
|
|
|
AtkObject parent;
|
|
|
|
|
|
|
|
GtkLabelAccessibleLink *link;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _GtkLabelAccessibleLinkImplClass
|
|
|
|
{
|
|
|
|
AtkObjectClass parent_class;
|
|
|
|
};
|
|
|
|
|
2014-01-04 15:47:22 +00:00
|
|
|
/* GtkLabelAccessibleLinkImpl {{{1 */
|
2014-01-04 03:59:37 +00:00
|
|
|
|
|
|
|
GType _gtk_label_accessible_link_impl_get_type (void);
|
|
|
|
|
2014-01-04 15:47:22 +00:00
|
|
|
static void atk_hyperlink_impl_interface_init (AtkHyperlinkImplIface *iface);
|
2014-01-04 03:59:37 +00:00
|
|
|
|
|
|
|
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))
|
|
|
|
|
|
|
|
static AtkHyperlink *
|
|
|
|
gtk_label_accessible_link_impl_get_hyperlink (AtkHyperlinkImpl *atk_impl)
|
|
|
|
{
|
|
|
|
GtkLabelAccessibleLinkImpl *impl = (GtkLabelAccessibleLinkImpl *)atk_impl;
|
|
|
|
|
2017-12-08 22:48:47 +00:00
|
|
|
return (AtkHyperlink *)g_object_ref (impl->link);
|
2014-01-04 03:59:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
atk_hyperlink_impl_interface_init (AtkHyperlinkImplIface *iface)
|
|
|
|
{
|
|
|
|
iface->get_hyperlink = gtk_label_accessible_link_impl_get_hyperlink;
|
|
|
|
}
|
|
|
|
|
2014-01-04 14:43:23 +00:00
|
|
|
static AtkStateSet *
|
|
|
|
gtk_label_accessible_link_impl_ref_state_set (AtkObject *obj)
|
|
|
|
{
|
|
|
|
AtkStateSet *state_set;
|
|
|
|
GtkLabelAccessibleLink *link;
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
|
|
|
link = ((GtkLabelAccessibleLinkImpl *)obj)->link;
|
|
|
|
|
|
|
|
state_set = atk_object_ref_state_set (atk_object_get_parent (obj));
|
|
|
|
|
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (atk_object_get_parent (obj)));
|
|
|
|
if (widget)
|
|
|
|
{
|
|
|
|
if (gtk_widget_get_can_focus (widget))
|
|
|
|
{
|
|
|
|
atk_state_set_add_state (state_set, ATK_STATE_FOCUSABLE);
|
|
|
|
if (_gtk_label_get_link_focused (GTK_LABEL (widget), link->index))
|
|
|
|
atk_state_set_add_state (state_set, ATK_STATE_FOCUSED);
|
|
|
|
else
|
|
|
|
atk_state_set_remove_state (state_set, ATK_STATE_FOCUSED);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_gtk_label_get_link_visited (GTK_LABEL (widget), link->index))
|
|
|
|
atk_state_set_add_state (state_set, ATK_STATE_VISITED);
|
|
|
|
}
|
|
|
|
|
|
|
|
return state_set;
|
|
|
|
}
|
|
|
|
|
2014-01-04 03:59:37 +00:00
|
|
|
static void
|
|
|
|
_gtk_label_accessible_link_impl_init (GtkLabelAccessibleLinkImpl *impl)
|
|
|
|
{
|
|
|
|
atk_object_set_role (ATK_OBJECT (impl), ATK_ROLE_LINK);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_gtk_label_accessible_link_impl_finalize (GObject *obj)
|
|
|
|
{
|
|
|
|
GtkLabelAccessibleLinkImpl *impl = (GtkLabelAccessibleLinkImpl *)obj;
|
|
|
|
|
|
|
|
g_object_unref (impl->link);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (_gtk_label_accessible_link_impl_parent_class)->finalize (obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_gtk_label_accessible_link_impl_class_init (GtkLabelAccessibleLinkImplClass *class)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
2014-01-04 14:43:23 +00:00
|
|
|
AtkObjectClass *atk_obj_class = ATK_OBJECT_CLASS (class);
|
2014-01-04 03:59:37 +00:00
|
|
|
|
|
|
|
object_class->finalize = _gtk_label_accessible_link_impl_finalize;
|
2014-01-04 14:43:23 +00:00
|
|
|
atk_obj_class->ref_state_set = gtk_label_accessible_link_impl_ref_state_set;
|
2014-01-04 03:59:37 +00:00
|
|
|
}
|
|
|
|
|
2014-01-04 15:47:22 +00:00
|
|
|
/* '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);
|
|
|
|
impl->link = gtk_label_accessible_link_new (label, idx);
|
2016-11-23 15:34:15 +00:00
|
|
|
atk_object_set_parent (ATK_OBJECT (impl), ATK_OBJECT (label));
|
2014-01-04 15:47:22 +00:00
|
|
|
|
|
|
|
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))
|
|
|
|
|
2014-01-04 03:59:37 +00:00
|
|
|
static gchar *
|
|
|
|
gtk_label_accessible_link_get_uri (AtkHyperlink *atk_link,
|
|
|
|
gint i)
|
|
|
|
{
|
|
|
|
GtkLabelAccessibleLink *link = (GtkLabelAccessibleLink *)atk_link;
|
|
|
|
GtkWidget *widget;
|
|
|
|
const gchar *uri;
|
|
|
|
|
|
|
|
g_return_val_if_fail (i == 0, NULL);
|
|
|
|
|
|
|
|
if (link->label == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (link->label));
|
|
|
|
uri = _gtk_label_get_link_uri (GTK_LABEL (widget), link->index);
|
|
|
|
|
|
|
|
return g_strdup (uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
gtk_label_accessible_link_get_n_anchors (AtkHyperlink *atk_link)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_label_accessible_link_is_valid (AtkHyperlink *atk_link)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static AtkObject *
|
|
|
|
gtk_label_accessible_link_get_object (AtkHyperlink *atk_link,
|
|
|
|
gint i)
|
|
|
|
{
|
|
|
|
GtkLabelAccessibleLink *link = (GtkLabelAccessibleLink *)atk_link;
|
|
|
|
|
|
|
|
g_return_val_if_fail (i == 0, NULL);
|
|
|
|
|
|
|
|
return ATK_OBJECT (link->label);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
gtk_label_accessible_link_get_start_index (AtkHyperlink *atk_link)
|
|
|
|
{
|
|
|
|
GtkLabelAccessibleLink *link = (GtkLabelAccessibleLink *)atk_link;
|
|
|
|
GtkWidget *widget;
|
|
|
|
gint start, end;
|
|
|
|
|
|
|
|
if (link->label == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (link->label));
|
|
|
|
_gtk_label_get_link_extent (GTK_LABEL (widget), link->index, &start, &end);
|
|
|
|
|
|
|
|
return start;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
gtk_label_accessible_link_get_end_index (AtkHyperlink *atk_link)
|
|
|
|
{
|
|
|
|
GtkLabelAccessibleLink *link = (GtkLabelAccessibleLink *)atk_link;
|
|
|
|
GtkWidget *widget;
|
|
|
|
gint start, end;
|
|
|
|
|
|
|
|
if (link->label == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (link->label));
|
|
|
|
_gtk_label_get_link_extent (GTK_LABEL (widget), link->index, &start, &end);
|
|
|
|
|
|
|
|
return end;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_gtk_label_accessible_link_init (GtkLabelAccessibleLink *link)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_gtk_label_accessible_link_class_init (GtkLabelAccessibleLinkClass *class)
|
|
|
|
{
|
|
|
|
AtkHyperlinkClass *atk_link_class = ATK_HYPERLINK_CLASS (class);
|
|
|
|
|
|
|
|
atk_link_class->get_uri = gtk_label_accessible_link_get_uri;
|
|
|
|
atk_link_class->get_n_anchors = gtk_label_accessible_link_get_n_anchors;
|
|
|
|
atk_link_class->is_valid = gtk_label_accessible_link_is_valid;
|
|
|
|
atk_link_class->get_object = gtk_label_accessible_link_get_object;
|
|
|
|
atk_link_class->get_start_index = gtk_label_accessible_link_get_start_index;
|
|
|
|
atk_link_class->get_end_index = gtk_label_accessible_link_get_end_index;
|
|
|
|
}
|
|
|
|
|
2014-01-04 15:47:22 +00:00
|
|
|
/* '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 */
|
|
|
|
|
2014-01-04 03:59:37 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_label_accessible_link_do_action (AtkAction *action,
|
|
|
|
gint i)
|
|
|
|
{
|
|
|
|
GtkLabelAccessibleLink *link = (GtkLabelAccessibleLink *)action;
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
|
|
|
if (i != 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (link->label == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (link->label));
|
|
|
|
if (widget == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!gtk_widget_is_sensitive (widget) || !gtk_widget_get_visible (widget))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
_gtk_label_activate_link (GTK_LABEL (widget), link->index);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
gtk_label_accessible_link_get_n_actions (AtkAction *action)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const gchar *
|
|
|
|
gtk_label_accessible_link_get_name (AtkAction *action,
|
|
|
|
gint i)
|
|
|
|
{
|
|
|
|
if (i != 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return "activate";
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
atk_action_interface_init (AtkActionIface *iface)
|
|
|
|
{
|
|
|
|
iface->do_action = gtk_label_accessible_link_do_action;
|
|
|
|
iface->get_n_actions = gtk_label_accessible_link_get_n_actions;
|
|
|
|
iface->get_name = gtk_label_accessible_link_get_name;
|
|
|
|
}
|
|
|
|
|
2014-01-04 15:47:22 +00:00
|
|
|
/* GtkLabelAccessible {{{1 */
|
|
|
|
|
2014-01-04 03:59:37 +00:00
|
|
|
static void atk_text_interface_init (AtkTextIface *iface);
|
|
|
|
static void atk_hypertext_interface_init (AtkHypertextIface *iface);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2012-12-27 06:04:46 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkLabelAccessible, gtk_label_accessible, GTK_TYPE_WIDGET_ACCESSIBLE,
|
2013-06-24 18:13:44 +00:00
|
|
|
G_ADD_PRIVATE (GtkLabelAccessible)
|
2014-01-04 03:59:37 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (ATK_TYPE_TEXT, atk_text_interface_init)
|
|
|
|
G_IMPLEMENT_INTERFACE (ATK_TYPE_HYPERTEXT, atk_hypertext_interface_init))
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2007-12-23 12:24:59 +00:00
|
|
|
static void
|
2012-12-27 06:04:46 +00:00
|
|
|
gtk_label_accessible_init (GtkLabelAccessible *label)
|
2007-12-23 12:24:59 +00:00
|
|
|
{
|
2013-06-24 18:13:44 +00:00
|
|
|
label->priv = gtk_label_accessible_get_instance_private (label);
|
2007-12-23 12:24:59 +00:00
|
|
|
}
|
|
|
|
|
2007-12-18 13:51:12 +00:00
|
|
|
static void
|
2011-06-25 00:36:05 +00:00
|
|
|
gtk_label_accessible_initialize (AtkObject *obj,
|
|
|
|
gpointer data)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
2012-12-27 06:04:46 +00:00
|
|
|
ATK_OBJECT_CLASS (gtk_label_accessible_parent_class)->initialize (obj, data);
|
2011-06-25 00:36:05 +00:00
|
|
|
|
2007-12-18 13:51:12 +00:00
|
|
|
widget = GTK_WIDGET (data);
|
|
|
|
|
2014-01-04 03:59:37 +00:00
|
|
|
_gtk_label_accessible_update_links (GTK_LABEL (widget));
|
|
|
|
|
|
|
|
/* Check whether ancestor of GtkLabel is a GtkButton
|
|
|
|
* and if so set accessible parent for GtkLabelAccessible
|
2007-12-18 13:51:12 +00:00
|
|
|
*/
|
|
|
|
while (widget != NULL)
|
|
|
|
{
|
|
|
|
widget = gtk_widget_get_parent (widget);
|
|
|
|
if (GTK_IS_BUTTON (widget))
|
|
|
|
{
|
|
|
|
atk_object_set_parent (obj, gtk_widget_get_accessible (widget));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-18 16:15:47 +00:00
|
|
|
obj->role = ATK_ROLE_LABEL;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
2011-07-16 13:44:02 +00:00
|
|
|
static gboolean
|
|
|
|
check_for_selection_change (GtkLabelAccessible *accessible,
|
|
|
|
GtkLabel *label)
|
|
|
|
{
|
|
|
|
gboolean ret_val = FALSE;
|
|
|
|
gint start, end;
|
|
|
|
|
|
|
|
if (gtk_label_get_selection_bounds (label, &start, &end))
|
|
|
|
{
|
2012-10-14 23:51:14 +00:00
|
|
|
if (end != accessible->priv->cursor_position ||
|
|
|
|
start != accessible->priv->selection_bound)
|
2011-07-16 13:44:02 +00:00
|
|
|
ret_val = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-10-14 23:51:14 +00:00
|
|
|
ret_val = (accessible->priv->cursor_position != accessible->priv->selection_bound);
|
2011-07-16 13:44:02 +00:00
|
|
|
}
|
|
|
|
|
2012-10-14 23:51:14 +00:00
|
|
|
accessible->priv->cursor_position = end;
|
|
|
|
accessible->priv->selection_bound = start;
|
2011-07-16 13:44:02 +00:00
|
|
|
|
|
|
|
return ret_val;
|
|
|
|
}
|
|
|
|
|
2007-12-18 13:51:12 +00:00
|
|
|
static void
|
2011-06-25 00:36:05 +00:00
|
|
|
gtk_label_accessible_notify_gtk (GObject *obj,
|
|
|
|
GParamSpec *pspec)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-25 00:36:05 +00:00
|
|
|
GtkWidget *widget = GTK_WIDGET (obj);
|
|
|
|
AtkObject* atk_obj = gtk_widget_get_accessible (widget);
|
2011-06-23 05:12:29 +00:00
|
|
|
GtkLabelAccessible *accessible;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-23 05:12:29 +00:00
|
|
|
accessible = GTK_LABEL_ACCESSIBLE (atk_obj);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2013-03-14 23:54:26 +00:00
|
|
|
if (g_strcmp0 (pspec->name, "cursor-position") == 0)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-07-16 13:44:02 +00:00
|
|
|
g_signal_emit_by_name (atk_obj, "text-caret-moved",
|
2011-06-25 00:36:05 +00:00
|
|
|
_gtk_label_get_cursor_position (GTK_LABEL (widget)));
|
2011-07-18 03:03:34 +00:00
|
|
|
if (check_for_selection_change (accessible, GTK_LABEL (widget)))
|
2011-07-16 13:44:02 +00:00
|
|
|
g_signal_emit_by_name (atk_obj, "text-selection-changed");
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
2011-07-10 04:02:02 +00:00
|
|
|
else if (g_strcmp0 (pspec->name, "selection-bound") == 0)
|
2011-06-26 02:43:02 +00:00
|
|
|
{
|
2011-07-18 03:03:34 +00:00
|
|
|
if (check_for_selection_change (accessible, GTK_LABEL (widget)))
|
2011-07-16 13:44:02 +00:00
|
|
|
g_signal_emit_by_name (atk_obj, "text-selection-changed");
|
2011-06-26 02:43:02 +00:00
|
|
|
}
|
2007-12-18 13:51:12 +00:00
|
|
|
else
|
2012-12-27 06:04:46 +00:00
|
|
|
GTK_WIDGET_ACCESSIBLE_CLASS (gtk_label_accessible_parent_class)->notify_gtk (obj, pspec);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* atkobject.h */
|
|
|
|
|
2011-06-25 00:36:05 +00:00
|
|
|
static AtkStateSet *
|
2011-06-23 05:12:29 +00:00
|
|
|
gtk_label_accessible_ref_state_set (AtkObject *accessible)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
AtkStateSet *state_set;
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
2010-05-22 23:55:33 +00:00
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
|
2007-12-18 13:51:12 +00:00
|
|
|
if (widget == NULL)
|
2011-06-25 00:36:05 +00:00
|
|
|
return NULL;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2012-12-27 06:04:46 +00:00
|
|
|
state_set = ATK_OBJECT_CLASS (gtk_label_accessible_parent_class)->ref_state_set (accessible);
|
2007-12-18 13:51:12 +00:00
|
|
|
atk_state_set_add_state (state_set, ATK_STATE_MULTI_LINE);
|
|
|
|
|
|
|
|
return state_set;
|
|
|
|
}
|
|
|
|
|
2011-07-09 03:43:31 +00:00
|
|
|
static AtkRelationSet *
|
2011-06-23 05:12:29 +00:00
|
|
|
gtk_label_accessible_ref_relation_set (AtkObject *obj)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
AtkRelationSet *relation_set;
|
|
|
|
|
2011-06-23 05:12:29 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_LABEL_ACCESSIBLE (obj), NULL);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2010-05-22 23:55:33 +00:00
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
|
2007-12-18 13:51:12 +00:00
|
|
|
if (widget == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2012-12-27 06:04:46 +00:00
|
|
|
relation_set = ATK_OBJECT_CLASS (gtk_label_accessible_parent_class)->ref_relation_set (obj);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
if (!atk_relation_set_contains (relation_set, ATK_RELATION_LABEL_FOR))
|
|
|
|
{
|
2011-06-25 00:36:05 +00:00
|
|
|
/* Get the mnemonic widget.
|
2007-12-18 13:51:12 +00:00
|
|
|
* The relation set is not updated if the mnemonic widget is changed
|
|
|
|
*/
|
2011-06-25 00:36:05 +00:00
|
|
|
GtkWidget *mnemonic_widget;
|
|
|
|
|
|
|
|
mnemonic_widget = gtk_label_get_mnemonic_widget (GTK_LABEL (widget));
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
if (mnemonic_widget)
|
|
|
|
{
|
|
|
|
AtkObject *accessible_array[1];
|
|
|
|
AtkRelation* relation;
|
|
|
|
|
2010-01-04 03:56:11 +00:00
|
|
|
if (!gtk_widget_get_can_focus (mnemonic_widget))
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
/*
|
2011-06-25 00:36:05 +00:00
|
|
|
* Handle the case where a GtkFileChooserButton is specified
|
|
|
|
* as the mnemonic widget. use the combobox which is a child of the
|
2007-12-18 13:51:12 +00:00
|
|
|
* GtkFileChooserButton as the mnemonic widget. See bug #359843.
|
|
|
|
*/
|
|
|
|
if (GTK_IS_BOX (mnemonic_widget))
|
|
|
|
{
|
|
|
|
GList *list, *tmpl;
|
|
|
|
|
|
|
|
list = gtk_container_get_children (GTK_CONTAINER (mnemonic_widget));
|
|
|
|
if (g_list_length (list) == 2)
|
|
|
|
{
|
|
|
|
tmpl = g_list_last (list);
|
|
|
|
if (GTK_IS_COMBO_BOX(tmpl->data))
|
|
|
|
{
|
|
|
|
mnemonic_widget = GTK_WIDGET(tmpl->data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_list_free (list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
accessible_array[0] = gtk_widget_get_accessible (mnemonic_widget);
|
|
|
|
relation = atk_relation_new (accessible_array, 1,
|
|
|
|
ATK_RELATION_LABEL_FOR);
|
|
|
|
atk_relation_set_add (relation_set, relation);
|
|
|
|
/*
|
|
|
|
* Unref the relation so that it is not leaked.
|
|
|
|
*/
|
|
|
|
g_object_unref (relation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return relation_set;
|
|
|
|
}
|
|
|
|
|
2011-06-06 18:02:06 +00:00
|
|
|
static const gchar*
|
2011-06-23 05:12:29 +00:00
|
|
|
gtk_label_accessible_get_name (AtkObject *accessible)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-06 18:02:06 +00:00
|
|
|
const gchar *name;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-23 05:12:29 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_LABEL_ACCESSIBLE (accessible), NULL);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2012-12-27 06:04:46 +00:00
|
|
|
name = ATK_OBJECT_CLASS (gtk_label_accessible_parent_class)->get_name (accessible);
|
2007-12-18 13:51:12 +00:00
|
|
|
if (name != NULL)
|
|
|
|
return name;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Get the text on the label
|
|
|
|
*/
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
2010-05-22 23:55:33 +00:00
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
|
2007-12-18 13:51:12 +00:00
|
|
|
if (widget == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_LABEL (widget), NULL);
|
|
|
|
|
|
|
|
return gtk_label_get_text (GTK_LABEL (widget));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-04 03:59:37 +00:00
|
|
|
static gint
|
|
|
|
gtk_label_accessible_get_n_children (AtkObject *obj)
|
|
|
|
{
|
|
|
|
GtkLabelAccessible *accessible = GTK_LABEL_ACCESSIBLE (obj);
|
|
|
|
|
|
|
|
return g_list_length (accessible->priv->links);
|
|
|
|
}
|
|
|
|
|
|
|
|
static AtkObject *
|
|
|
|
gtk_label_accessible_ref_child (AtkObject *obj,
|
|
|
|
gint idx)
|
|
|
|
{
|
|
|
|
GtkLabelAccessible *accessible = GTK_LABEL_ACCESSIBLE (obj);
|
|
|
|
AtkObject *child;
|
|
|
|
|
|
|
|
child = g_list_nth_data (accessible->priv->links, idx);
|
|
|
|
|
|
|
|
if (child)
|
|
|
|
g_object_ref (child);
|
|
|
|
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void clear_links (GtkLabelAccessible *accessible);
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_label_accessible_finalize (GObject *obj)
|
|
|
|
{
|
|
|
|
GtkLabelAccessible *accessible = GTK_LABEL_ACCESSIBLE (obj);
|
|
|
|
|
|
|
|
clear_links (accessible);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_label_accessible_parent_class)->finalize (obj);
|
|
|
|
}
|
|
|
|
|
2007-12-18 13:51:12 +00:00
|
|
|
static void
|
2012-12-27 06:04:46 +00:00
|
|
|
gtk_label_accessible_class_init (GtkLabelAccessibleClass *klass)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2014-01-04 03:59:37 +00:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2011-06-25 00:36:05 +00:00
|
|
|
AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
|
2013-03-14 23:54:26 +00:00
|
|
|
GtkWidgetAccessibleClass *widget_class = GTK_WIDGET_ACCESSIBLE_CLASS (klass);
|
2011-06-25 00:36:05 +00:00
|
|
|
|
2014-01-04 03:59:37 +00:00
|
|
|
object_class->finalize = gtk_label_accessible_finalize;
|
2011-06-25 00:36:05 +00:00
|
|
|
|
|
|
|
class->get_name = gtk_label_accessible_get_name;
|
|
|
|
class->ref_state_set = gtk_label_accessible_ref_state_set;
|
|
|
|
class->ref_relation_set = gtk_label_accessible_ref_relation_set;
|
|
|
|
class->initialize = gtk_label_accessible_initialize;
|
2014-01-04 03:59:37 +00:00
|
|
|
|
|
|
|
class->get_n_children = gtk_label_accessible_get_n_children;
|
|
|
|
class->ref_child = gtk_label_accessible_ref_child;
|
|
|
|
|
|
|
|
widget_class->notify_gtk = gtk_label_accessible_notify_gtk;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
2014-01-04 15:47:22 +00:00
|
|
|
/* '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 */
|
2011-06-25 00:36:05 +00:00
|
|
|
|
2007-12-18 13:51:12 +00:00
|
|
|
static gchar*
|
2011-06-25 00:36:05 +00:00
|
|
|
gtk_label_accessible_get_text (AtkText *atk_text,
|
|
|
|
gint start_pos,
|
|
|
|
gint end_pos)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
2011-06-25 00:36:05 +00:00
|
|
|
const gchar *text;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-25 00:36:05 +00:00
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (atk_text));
|
2007-12-18 13:51:12 +00:00
|
|
|
if (widget == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2011-06-25 00:36:05 +00:00
|
|
|
text = gtk_label_get_text (GTK_LABEL (widget));
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-25 00:36:05 +00:00
|
|
|
if (text)
|
2013-03-06 14:46:51 +00:00
|
|
|
{
|
|
|
|
guint length;
|
|
|
|
const gchar *start, *end;
|
|
|
|
|
|
|
|
length = g_utf8_strlen (text, -1);
|
|
|
|
if (end_pos < 0 || end_pos > length)
|
|
|
|
end_pos = length;
|
|
|
|
if (start_pos > length)
|
|
|
|
start_pos = length;
|
|
|
|
if (end_pos <= start_pos)
|
|
|
|
return g_strdup ("");
|
|
|
|
start = g_utf8_offset_to_pointer (text, start_pos);
|
|
|
|
end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
|
|
|
|
return g_strndup (start, end - start);
|
|
|
|
}
|
2011-06-23 22:18:11 +00:00
|
|
|
|
2011-06-25 00:36:05 +00:00
|
|
|
return NULL;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
2011-06-25 00:36:05 +00:00
|
|
|
static gchar *
|
2011-06-23 05:12:29 +00:00
|
|
|
gtk_label_accessible_get_text_before_offset (AtkText *text,
|
2011-06-25 00:36:05 +00:00
|
|
|
gint offset,
|
|
|
|
AtkTextBoundary boundary_type,
|
|
|
|
gint *start_offset,
|
|
|
|
gint *end_offset)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
2011-06-25 00:36:05 +00:00
|
|
|
|
2010-05-22 23:55:33 +00:00
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
|
2007-12-18 13:51:12 +00:00
|
|
|
if (widget == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2011-06-25 00:36:05 +00:00
|
|
|
return _gtk_pango_get_text_before (gtk_label_get_layout (GTK_LABEL (widget)),
|
|
|
|
boundary_type, offset,
|
|
|
|
start_offset, end_offset);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gchar*
|
2011-06-23 05:12:29 +00:00
|
|
|
gtk_label_accessible_get_text_at_offset (AtkText *text,
|
2011-06-25 00:36:05 +00:00
|
|
|
gint offset,
|
|
|
|
AtkTextBoundary boundary_type,
|
|
|
|
gint *start_offset,
|
|
|
|
gint *end_offset)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
2011-06-25 00:36:05 +00:00
|
|
|
|
2010-05-22 23:55:33 +00:00
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
|
2007-12-18 13:51:12 +00:00
|
|
|
if (widget == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2011-06-25 00:36:05 +00:00
|
|
|
return _gtk_pango_get_text_at (gtk_label_get_layout (GTK_LABEL (widget)),
|
|
|
|
boundary_type, offset,
|
|
|
|
start_offset, end_offset);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gchar*
|
2011-06-23 05:12:29 +00:00
|
|
|
gtk_label_accessible_get_text_after_offset (AtkText *text,
|
2011-06-25 00:36:05 +00:00
|
|
|
gint offset,
|
|
|
|
AtkTextBoundary boundary_type,
|
|
|
|
gint *start_offset,
|
|
|
|
gint *end_offset)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
2010-05-22 23:55:33 +00:00
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
|
2007-12-18 13:51:12 +00:00
|
|
|
if (widget == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2011-06-25 00:36:05 +00:00
|
|
|
return _gtk_pango_get_text_after (gtk_label_get_layout (GTK_LABEL (widget)),
|
|
|
|
boundary_type, offset,
|
|
|
|
start_offset, end_offset);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
2011-06-25 00:36:05 +00:00
|
|
|
gtk_label_accessible_get_character_count (AtkText *atk_text)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
2011-06-25 00:36:05 +00:00
|
|
|
const gchar *text;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-25 00:36:05 +00:00
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (atk_text));
|
2007-12-18 13:51:12 +00:00
|
|
|
if (widget == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2011-06-25 00:36:05 +00:00
|
|
|
text = gtk_label_get_text (GTK_LABEL (widget));
|
|
|
|
|
|
|
|
if (text)
|
|
|
|
return g_utf8_strlen (text, -1);
|
|
|
|
|
|
|
|
return 0;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
2011-06-23 05:12:29 +00:00
|
|
|
gtk_label_accessible_get_caret_offset (AtkText *text)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-25 00:36:05 +00:00
|
|
|
GtkWidget *widget;
|
|
|
|
|
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
|
|
|
|
if (widget == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return _gtk_label_get_cursor_position (GTK_LABEL (widget));
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-06-25 00:36:05 +00:00
|
|
|
gtk_label_accessible_set_caret_offset (AtkText *text,
|
|
|
|
gint offset)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
2011-06-25 00:36:05 +00:00
|
|
|
GtkLabel *label;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2010-05-22 23:55:33 +00:00
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
|
2007-12-18 13:51:12 +00:00
|
|
|
if (widget == NULL)
|
2011-06-25 00:36:05 +00:00
|
|
|
return FALSE;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
label = GTK_LABEL (widget);
|
|
|
|
|
2011-06-25 00:36:05 +00:00
|
|
|
if (!gtk_label_get_selectable (label))
|
2007-12-18 13:51:12 +00:00
|
|
|
return FALSE;
|
2011-06-25 00:36:05 +00:00
|
|
|
|
|
|
|
gtk_label_select_region (label, offset, offset);
|
|
|
|
|
|
|
|
return TRUE;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
2011-06-23 05:12:29 +00:00
|
|
|
gtk_label_accessible_get_n_selections (AtkText *text)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
2010-05-22 23:55:33 +00:00
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
|
2007-12-18 13:51:12 +00:00
|
|
|
if (widget == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2011-06-26 04:38:20 +00:00
|
|
|
if (gtk_label_get_selection_bounds (GTK_LABEL (widget), NULL, NULL))
|
2011-06-25 00:36:05 +00:00
|
|
|
return 1;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-25 00:36:05 +00:00
|
|
|
return 0;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
2011-06-25 00:36:05 +00:00
|
|
|
static gchar *
|
2011-07-10 04:10:54 +00:00
|
|
|
gtk_label_accessible_get_selection (AtkText *atk_text,
|
2011-06-25 00:36:05 +00:00
|
|
|
gint selection_num,
|
|
|
|
gint *start_pos,
|
|
|
|
gint *end_pos)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
GtkLabel *label;
|
|
|
|
|
2011-07-10 04:10:54 +00:00
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (atk_text));
|
2007-12-18 13:51:12 +00:00
|
|
|
if (widget == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2011-06-25 00:36:05 +00:00
|
|
|
if (selection_num != 0)
|
|
|
|
return NULL;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-26 04:38:20 +00:00
|
|
|
label = GTK_LABEL (widget);
|
|
|
|
|
2007-12-18 13:51:12 +00:00
|
|
|
if (gtk_label_get_selection_bounds (label, start_pos, end_pos))
|
|
|
|
{
|
2011-06-25 00:36:05 +00:00
|
|
|
const gchar *text;
|
|
|
|
|
|
|
|
text = gtk_label_get_text (label);
|
|
|
|
|
|
|
|
if (text)
|
|
|
|
return g_utf8_substring (text, *start_pos, *end_pos);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
2011-06-25 00:36:05 +00:00
|
|
|
|
|
|
|
return NULL;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-06-23 05:12:29 +00:00
|
|
|
gtk_label_accessible_add_selection (AtkText *text,
|
2011-06-25 00:36:05 +00:00
|
|
|
gint start_pos,
|
|
|
|
gint end_pos)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
GtkLabel *label;
|
|
|
|
gint start, end;
|
|
|
|
|
2010-05-22 23:55:33 +00:00
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
|
2007-12-18 13:51:12 +00:00
|
|
|
if (widget == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
label = GTK_LABEL (widget);
|
|
|
|
|
|
|
|
if (!gtk_label_get_selectable (label))
|
2011-06-25 00:36:05 +00:00
|
|
|
return FALSE;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-25 00:36:05 +00:00
|
|
|
if (!gtk_label_get_selection_bounds (label, &start, &end))
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
gtk_label_select_region (label, start_pos, end_pos);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-06-23 05:12:29 +00:00
|
|
|
gtk_label_accessible_remove_selection (AtkText *text,
|
2011-06-25 00:36:05 +00:00
|
|
|
gint selection_num)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
GtkLabel *label;
|
|
|
|
gint start, end;
|
|
|
|
|
2010-05-22 23:55:33 +00:00
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
|
2007-12-18 13:51:12 +00:00
|
|
|
if (widget == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (selection_num != 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
label = GTK_LABEL (widget);
|
|
|
|
|
|
|
|
if (!gtk_label_get_selectable (label))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (gtk_label_get_selection_bounds (label, &start, &end))
|
|
|
|
{
|
2011-06-26 02:43:02 +00:00
|
|
|
gtk_label_select_region (label, end, end);
|
2007-12-18 13:51:12 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-06-23 05:12:29 +00:00
|
|
|
gtk_label_accessible_set_selection (AtkText *text,
|
2011-06-25 00:36:05 +00:00
|
|
|
gint selection_num,
|
|
|
|
gint start_pos,
|
|
|
|
gint end_pos)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
GtkLabel *label;
|
|
|
|
gint start, end;
|
|
|
|
|
2010-05-22 23:55:33 +00:00
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
|
2007-12-18 13:51:12 +00:00
|
|
|
if (widget == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (selection_num != 0)
|
2011-06-25 00:36:05 +00:00
|
|
|
return FALSE;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
label = GTK_LABEL (widget);
|
|
|
|
|
|
|
|
if (!gtk_label_get_selectable (label))
|
2011-06-25 00:36:05 +00:00
|
|
|
return FALSE;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
if (gtk_label_get_selection_bounds (label, &start, &end))
|
|
|
|
{
|
|
|
|
gtk_label_select_region (label, start_pos, end_pos);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-06-23 05:12:29 +00:00
|
|
|
gtk_label_accessible_get_character_extents (AtkText *text,
|
2011-06-25 00:36:05 +00:00
|
|
|
gint offset,
|
|
|
|
gint *x,
|
|
|
|
gint *y,
|
|
|
|
gint *width,
|
|
|
|
gint *height,
|
|
|
|
AtkCoordType coords)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
GtkLabel *label;
|
|
|
|
PangoRectangle char_rect;
|
2010-03-27 05:19:10 +00:00
|
|
|
const gchar *label_text;
|
2007-12-18 13:51:12 +00:00
|
|
|
gint index, x_layout, y_layout;
|
2011-06-25 00:36:05 +00:00
|
|
|
GdkWindow *window;
|
|
|
|
gint x_window, y_window;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-25 00:36:05 +00:00
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
|
2007-12-18 13:51:12 +00:00
|
|
|
if (widget == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
label = GTK_LABEL (widget);
|
2011-06-25 00:36:05 +00:00
|
|
|
|
2007-12-18 13:51:12 +00:00
|
|
|
gtk_label_get_layout_offsets (label, &x_layout, &y_layout);
|
2010-03-27 05:19:10 +00:00
|
|
|
label_text = gtk_label_get_text (label);
|
|
|
|
index = g_utf8_offset_to_pointer (label_text, offset) - label_text;
|
2007-12-18 13:51:12 +00:00
|
|
|
pango_layout_index_to_pos (gtk_label_get_layout (label), index, &char_rect);
|
2011-06-25 00:36:05 +00:00
|
|
|
pango_extents_to_pixels (&char_rect, NULL);
|
|
|
|
|
|
|
|
window = gtk_widget_get_window (widget);
|
|
|
|
gdk_window_get_origin (window, &x_window, &y_window);
|
|
|
|
|
|
|
|
*x = x_window + x_layout + char_rect.x;
|
2011-08-10 19:19:56 +00:00
|
|
|
*y = y_window + y_layout + char_rect.y;
|
2011-06-25 00:36:05 +00:00
|
|
|
*width = char_rect.width;
|
|
|
|
*height = char_rect.height;
|
|
|
|
|
|
|
|
if (coords == ATK_XY_WINDOW)
|
|
|
|
{
|
|
|
|
window = gdk_window_get_toplevel (window);
|
|
|
|
gdk_window_get_origin (window, &x_window, &y_window);
|
|
|
|
|
|
|
|
*x -= x_window;
|
|
|
|
*y -= y_window;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
gtk_label_accessible_get_offset_at_point (AtkText *atk_text,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
AtkCoordType coords)
|
|
|
|
{
|
2007-12-18 13:51:12 +00:00
|
|
|
GtkWidget *widget;
|
|
|
|
GtkLabel *label;
|
2011-06-25 00:36:05 +00:00
|
|
|
const gchar *text;
|
2007-12-18 13:51:12 +00:00
|
|
|
gint index, x_layout, y_layout;
|
2011-06-25 00:36:05 +00:00
|
|
|
gint x_window, y_window;
|
|
|
|
gint x_local, y_local;
|
|
|
|
GdkWindow *window;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-25 00:36:05 +00:00
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (atk_text));
|
2007-12-18 13:51:12 +00:00
|
|
|
if (widget == NULL)
|
|
|
|
return -1;
|
2011-06-23 22:18:11 +00:00
|
|
|
|
2007-12-18 13:51:12 +00:00
|
|
|
label = GTK_LABEL (widget);
|
2011-06-25 00:36:05 +00:00
|
|
|
|
2007-12-18 13:51:12 +00:00
|
|
|
gtk_label_get_layout_offsets (label, &x_layout, &y_layout);
|
2011-06-25 00:36:05 +00:00
|
|
|
|
|
|
|
window = gtk_widget_get_window (widget);
|
|
|
|
gdk_window_get_origin (window, &x_window, &y_window);
|
|
|
|
|
|
|
|
x_local = x - x_layout - x_window;
|
|
|
|
y_local = y - y_layout - y_window;
|
|
|
|
|
|
|
|
if (coords == ATK_XY_WINDOW)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-25 00:36:05 +00:00
|
|
|
window = gdk_window_get_toplevel (window);
|
|
|
|
gdk_window_get_origin (window, &x_window, &y_window);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-25 00:36:05 +00:00
|
|
|
x_local += x_window;
|
|
|
|
y_local += y_window;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
2011-06-25 00:36:05 +00:00
|
|
|
|
|
|
|
if (!pango_layout_xy_to_index (gtk_label_get_layout (label),
|
|
|
|
x_local * PANGO_SCALE,
|
|
|
|
y_local * PANGO_SCALE,
|
|
|
|
&index, NULL))
|
|
|
|
{
|
|
|
|
if (x_local < 0 || y_local < 0)
|
|
|
|
index = 0;
|
|
|
|
else
|
|
|
|
index = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (index != -1)
|
|
|
|
{
|
|
|
|
text = gtk_label_get_text (label);
|
|
|
|
return g_utf8_pointer_to_offset (text, text + index);
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static AtkAttributeSet *
|
|
|
|
add_attribute (AtkAttributeSet *attributes,
|
|
|
|
AtkTextAttribute attr,
|
|
|
|
const gchar *value)
|
|
|
|
{
|
|
|
|
AtkAttribute *at;
|
|
|
|
|
|
|
|
at = g_new (AtkAttribute, 1);
|
|
|
|
at->name = g_strdup (atk_text_attribute_get_name (attr));
|
|
|
|
at->value = g_strdup (value);
|
|
|
|
|
|
|
|
return g_slist_prepend (attributes, at);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static AtkAttributeSet*
|
2011-06-25 00:36:05 +00:00
|
|
|
gtk_label_accessible_get_run_attributes (AtkText *text,
|
|
|
|
gint offset,
|
|
|
|
gint *start_offset,
|
|
|
|
gint *end_offset)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
2011-06-25 00:36:05 +00:00
|
|
|
AtkAttributeSet *attributes;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2010-05-22 23:55:33 +00:00
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
|
2007-12-18 13:51:12 +00:00
|
|
|
if (widget == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2011-06-25 00:36:05 +00:00
|
|
|
attributes = NULL;
|
|
|
|
attributes = add_attribute (attributes, ATK_TEXT_ATTR_DIRECTION,
|
|
|
|
atk_text_attribute_get_value (ATK_TEXT_ATTR_DIRECTION,
|
|
|
|
gtk_widget_get_direction (widget)));
|
|
|
|
attributes = _gtk_pango_get_run_attributes (attributes,
|
|
|
|
gtk_label_get_layout (GTK_LABEL (widget)),
|
|
|
|
offset,
|
|
|
|
start_offset,
|
|
|
|
end_offset);
|
|
|
|
|
2011-06-25 17:57:42 +00:00
|
|
|
return attributes;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
2011-06-25 00:36:05 +00:00
|
|
|
static AtkAttributeSet *
|
|
|
|
gtk_label_accessible_get_default_attributes (AtkText *text)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
2011-06-25 00:36:05 +00:00
|
|
|
AtkAttributeSet *attributes;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2010-05-22 23:55:33 +00:00
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
|
2007-12-18 13:51:12 +00:00
|
|
|
if (widget == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2011-06-25 00:36:05 +00:00
|
|
|
attributes = NULL;
|
|
|
|
attributes = add_attribute (attributes, ATK_TEXT_ATTR_DIRECTION,
|
|
|
|
atk_text_attribute_get_value (ATK_TEXT_ATTR_DIRECTION,
|
|
|
|
gtk_widget_get_direction (widget)));
|
|
|
|
attributes = _gtk_pango_get_default_attributes (attributes,
|
|
|
|
gtk_label_get_layout (GTK_LABEL (widget)));
|
|
|
|
attributes = _gtk_style_context_get_attributes (attributes,
|
2016-10-08 03:07:23 +00:00
|
|
|
gtk_widget_get_style_context (widget));
|
2011-06-25 00:36:05 +00:00
|
|
|
|
|
|
|
return attributes;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
2011-06-25 00:36:05 +00:00
|
|
|
static gunichar
|
|
|
|
gtk_label_accessible_get_character_at_offset (AtkText *atk_text,
|
|
|
|
gint offset)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
2011-06-25 00:36:05 +00:00
|
|
|
const gchar *text;
|
2007-12-18 13:51:12 +00:00
|
|
|
gchar *index;
|
|
|
|
|
2011-06-25 00:36:05 +00:00
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (atk_text));
|
2007-12-18 13:51:12 +00:00
|
|
|
if (widget == NULL)
|
|
|
|
return '\0';
|
|
|
|
|
2011-06-25 00:36:05 +00:00
|
|
|
text = gtk_label_get_text (GTK_LABEL (widget));
|
|
|
|
if (offset >= g_utf8_strlen (text, -1))
|
2007-12-18 13:51:12 +00:00
|
|
|
return '\0';
|
2011-06-25 00:36:05 +00:00
|
|
|
|
|
|
|
index = g_utf8_offset_to_pointer (text, offset);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
return g_utf8_get_char (index);
|
|
|
|
}
|
2011-06-25 00:36:05 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
atk_text_interface_init (AtkTextIface *iface)
|
|
|
|
{
|
|
|
|
iface->get_text = gtk_label_accessible_get_text;
|
|
|
|
iface->get_character_at_offset = gtk_label_accessible_get_character_at_offset;
|
|
|
|
iface->get_text_before_offset = gtk_label_accessible_get_text_before_offset;
|
|
|
|
iface->get_text_at_offset = gtk_label_accessible_get_text_at_offset;
|
|
|
|
iface->get_text_after_offset = gtk_label_accessible_get_text_after_offset;
|
|
|
|
iface->get_character_count = gtk_label_accessible_get_character_count;
|
|
|
|
iface->get_caret_offset = gtk_label_accessible_get_caret_offset;
|
|
|
|
iface->set_caret_offset = gtk_label_accessible_set_caret_offset;
|
|
|
|
iface->get_n_selections = gtk_label_accessible_get_n_selections;
|
|
|
|
iface->get_selection = gtk_label_accessible_get_selection;
|
|
|
|
iface->add_selection = gtk_label_accessible_add_selection;
|
|
|
|
iface->remove_selection = gtk_label_accessible_remove_selection;
|
|
|
|
iface->set_selection = gtk_label_accessible_set_selection;
|
|
|
|
iface->get_character_extents = gtk_label_accessible_get_character_extents;
|
|
|
|
iface->get_offset_at_point = gtk_label_accessible_get_offset_at_point;
|
|
|
|
iface->get_run_attributes = gtk_label_accessible_get_run_attributes;
|
|
|
|
iface->get_default_attributes = gtk_label_accessible_get_default_attributes;
|
|
|
|
}
|
|
|
|
|
2014-01-04 15:47:22 +00:00
|
|
|
/* AtkHypertext implementation {{{2 */
|
2014-01-04 14:43:23 +00:00
|
|
|
|
2014-01-04 03:59:37 +00:00
|
|
|
static AtkHyperlink *
|
|
|
|
gtk_label_accessible_get_link (AtkHypertext *hypertext,
|
|
|
|
gint idx)
|
|
|
|
{
|
|
|
|
GtkLabelAccessible *label = GTK_LABEL_ACCESSIBLE (hypertext);
|
|
|
|
GtkLabelAccessibleLinkImpl *impl;
|
|
|
|
|
|
|
|
impl = (GtkLabelAccessibleLinkImpl *)g_list_nth_data (label->priv->links, idx);
|
|
|
|
|
|
|
|
if (impl)
|
|
|
|
return ATK_HYPERLINK (impl->link);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
gtk_label_accessible_get_n_links (AtkHypertext *hypertext)
|
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (hypertext));
|
|
|
|
|
|
|
|
return _gtk_label_get_n_links (GTK_LABEL (widget));
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
gtk_label_accessible_get_link_index (AtkHypertext *hypertext,
|
|
|
|
gint char_index)
|
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (hypertext));
|
|
|
|
|
|
|
|
return _gtk_label_get_link_at (GTK_LABEL (widget), char_index);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
atk_hypertext_interface_init (AtkHypertextIface *iface)
|
|
|
|
{
|
|
|
|
iface->get_link = gtk_label_accessible_get_link;
|
|
|
|
iface->get_n_links = gtk_label_accessible_get_n_links;
|
|
|
|
iface->get_link_index = gtk_label_accessible_get_link_index;
|
|
|
|
}
|
2014-01-04 15:47:22 +00:00
|
|
|
|
|
|
|
/* vim:set foldmethod=marker expandtab: */
|