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
|
|
|
*/
|
|
|
|
|
2008-06-22 14:28:52 +00:00
|
|
|
#include "config.h"
|
2007-12-23 12:27:33 +00:00
|
|
|
|
2017-08-28 22:53:40 +00:00
|
|
|
#include "gdk/gdkeventsprivate.h"
|
|
|
|
|
2013-02-04 05:53:48 +00:00
|
|
|
#include <glib/gi18n-lib.h>
|
2012-11-11 17:00:49 +00:00
|
|
|
#include <string.h>
|
2007-12-18 13:51:12 +00:00
|
|
|
#include <gtk/gtk.h>
|
2011-06-25 18:43:59 +00:00
|
|
|
#include "gtkpango.h"
|
2011-06-25 02:12:55 +00:00
|
|
|
#include "gtkentryaccessible.h"
|
2012-08-10 16:04:57 +00:00
|
|
|
#include "gtkentryprivate.h"
|
2019-02-22 20:49:47 +00:00
|
|
|
#include "gtksearchentryprivate.h"
|
|
|
|
#include "gtkpasswordentry.h"
|
2019-02-16 05:50:12 +00:00
|
|
|
#include "gtktextprivate.h"
|
2011-06-29 21:31:09 +00:00
|
|
|
#include "gtkcomboboxaccessible.h"
|
2014-06-15 16:03:59 +00:00
|
|
|
#include "gtkstylecontextprivate.h"
|
2017-10-15 11:55:22 +00:00
|
|
|
#include "gtkwidgetprivate.h"
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2012-12-27 06:04:46 +00:00
|
|
|
#define GTK_TYPE_ENTRY_ICON_ACCESSIBLE (gtk_entry_icon_accessible_get_type ())
|
2012-11-11 17:00:49 +00:00
|
|
|
#define GTK_ENTRY_ICON_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ENTRY_ICON_ACCESSIBLE, GtkEntryIconAccessible))
|
|
|
|
#define GTK_IS_ENTRY_ICON_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ENTRY_ICON_ACCESSIBLE))
|
|
|
|
|
2012-10-14 19:59:58 +00:00
|
|
|
struct _GtkEntryAccessiblePrivate
|
|
|
|
{
|
|
|
|
gint cursor_position;
|
|
|
|
gint selection_bound;
|
2012-11-11 17:00:49 +00:00
|
|
|
AtkObject *icons[2];
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct _GtkEntryIconAccessible GtkEntryIconAccessible;
|
|
|
|
typedef struct _GtkEntryIconAccessibleClass GtkEntryIconAccessibleClass;
|
|
|
|
|
|
|
|
struct _GtkEntryIconAccessible
|
|
|
|
{
|
|
|
|
AtkObject parent;
|
|
|
|
|
|
|
|
GtkEntryAccessible *entry;
|
|
|
|
GtkEntryIconPosition pos;
|
2012-10-14 19:59:58 +00:00
|
|
|
};
|
|
|
|
|
2012-11-11 17:00:49 +00:00
|
|
|
struct _GtkEntryIconAccessibleClass
|
|
|
|
{
|
|
|
|
AtkObjectClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void icon_atk_action_interface_init (AtkActionIface *iface);
|
|
|
|
static void icon_atk_component_interface_init (AtkComponentIface *iface);
|
|
|
|
|
2012-12-27 06:04:46 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkEntryIconAccessible, gtk_entry_icon_accessible, ATK_TYPE_OBJECT,
|
2012-11-11 17:00:49 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION, icon_atk_action_interface_init)
|
|
|
|
G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT, icon_atk_component_interface_init))
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_entry_icon_accessible_remove_entry (gpointer data, GObject *obj)
|
|
|
|
{
|
|
|
|
GtkEntryIconAccessible *icon = data;
|
|
|
|
|
|
|
|
if (icon->entry)
|
|
|
|
{
|
|
|
|
icon->entry = NULL;
|
|
|
|
g_object_notify (G_OBJECT (icon), "accessible-parent");
|
|
|
|
atk_object_notify_state_change (ATK_OBJECT (icon), ATK_STATE_DEFUNCT, TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static AtkObject *
|
|
|
|
gtk_entry_icon_accessible_new (GtkEntryAccessible *entry,
|
|
|
|
GtkEntryIconPosition pos)
|
|
|
|
{
|
|
|
|
GtkEntryIconAccessible *icon;
|
|
|
|
AtkObject *accessible;
|
|
|
|
|
2012-12-27 06:04:46 +00:00
|
|
|
icon = g_object_new (gtk_entry_icon_accessible_get_type (), NULL);
|
2012-11-11 17:00:49 +00:00
|
|
|
icon->entry = entry;
|
|
|
|
g_object_weak_ref (G_OBJECT (entry),
|
|
|
|
gtk_entry_icon_accessible_remove_entry,
|
|
|
|
icon);
|
|
|
|
icon->pos = pos;
|
|
|
|
|
|
|
|
accessible = ATK_OBJECT (icon);
|
|
|
|
atk_object_initialize (accessible, NULL);
|
|
|
|
return accessible;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-12-27 06:04:46 +00:00
|
|
|
gtk_entry_icon_accessible_init (GtkEntryIconAccessible *icon)
|
2012-11-11 17:00:49 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_entry_icon_accessible_initialize (AtkObject *obj,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkEntryIconAccessible *icon = GTK_ENTRY_ICON_ACCESSIBLE (obj);
|
|
|
|
GtkWidget *widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (icon->entry));
|
|
|
|
GtkEntry *gtk_entry = GTK_ENTRY (widget);
|
|
|
|
const gchar *name;
|
|
|
|
gchar *text;
|
|
|
|
|
2012-12-27 06:04:46 +00:00
|
|
|
ATK_OBJECT_CLASS (gtk_entry_icon_accessible_parent_class)->initialize (obj, data);
|
2012-11-11 17:00:49 +00:00
|
|
|
atk_object_set_role (obj, ATK_ROLE_ICON);
|
|
|
|
|
|
|
|
name = gtk_entry_get_icon_name (gtk_entry, icon->pos);
|
|
|
|
if (name)
|
|
|
|
atk_object_set_name (obj, name);
|
|
|
|
|
|
|
|
text = gtk_entry_get_icon_tooltip_text (gtk_entry, icon->pos);
|
|
|
|
if (text)
|
|
|
|
{
|
|
|
|
atk_object_set_description (obj, text);
|
|
|
|
g_free (text);
|
|
|
|
}
|
|
|
|
|
|
|
|
atk_object_set_parent (obj, ATK_OBJECT (icon->entry));
|
|
|
|
}
|
|
|
|
|
|
|
|
static AtkObject *
|
|
|
|
gtk_entry_icon_accessible_get_parent (AtkObject *accessible)
|
|
|
|
{
|
|
|
|
GtkEntryIconAccessible *icon = GTK_ENTRY_ICON_ACCESSIBLE (accessible);
|
|
|
|
|
|
|
|
return ATK_OBJECT (icon->entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
static AtkStateSet *
|
|
|
|
gtk_entry_icon_accessible_ref_state_set (AtkObject *accessible)
|
|
|
|
{
|
|
|
|
GtkEntryIconAccessible *icon = GTK_ENTRY_ICON_ACCESSIBLE (accessible);
|
|
|
|
AtkStateSet *set = atk_state_set_new ();
|
|
|
|
AtkStateSet *entry_set;
|
|
|
|
GtkWidget *widget;
|
|
|
|
GtkEntry *gtk_entry;
|
|
|
|
|
|
|
|
if (!icon->entry)
|
|
|
|
{
|
|
|
|
atk_state_set_add_state (set, ATK_STATE_DEFUNCT);
|
|
|
|
return set;
|
|
|
|
}
|
|
|
|
|
|
|
|
entry_set = atk_object_ref_state_set (ATK_OBJECT (icon->entry));
|
|
|
|
if (!entry_set || atk_state_set_contains_state (entry_set, ATK_STATE_DEFUNCT))
|
|
|
|
{
|
|
|
|
atk_state_set_add_state (set, ATK_STATE_DEFUNCT);
|
|
|
|
g_clear_object (&entry_set);
|
|
|
|
return set;
|
|
|
|
}
|
|
|
|
|
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (icon->entry));
|
|
|
|
gtk_entry = GTK_ENTRY (widget);
|
|
|
|
|
|
|
|
if (atk_state_set_contains_state (entry_set, ATK_STATE_ENABLED))
|
|
|
|
atk_state_set_add_state (set, ATK_STATE_ENABLED);
|
|
|
|
if (atk_state_set_contains_state (entry_set, ATK_STATE_SENSITIVE))
|
|
|
|
atk_state_set_add_state (set, ATK_STATE_SENSITIVE);
|
|
|
|
if (atk_state_set_contains_state (entry_set, ATK_STATE_SHOWING))
|
|
|
|
atk_state_set_add_state (set, ATK_STATE_SHOWING);
|
|
|
|
if (atk_state_set_contains_state (entry_set, ATK_STATE_VISIBLE))
|
|
|
|
atk_state_set_add_state (set, ATK_STATE_VISIBLE);
|
|
|
|
|
|
|
|
if (!gtk_entry_get_icon_sensitive (gtk_entry, icon->pos))
|
|
|
|
atk_state_set_remove_state (set, ATK_STATE_SENSITIVE);
|
|
|
|
if (!gtk_entry_get_icon_activatable (gtk_entry, icon->pos))
|
|
|
|
atk_state_set_remove_state (set, ATK_STATE_ENABLED);
|
|
|
|
|
|
|
|
g_object_unref (entry_set);
|
|
|
|
return set;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_entry_icon_accessible_invalidate (GtkEntryIconAccessible *icon)
|
|
|
|
{
|
|
|
|
if (!icon->entry)
|
|
|
|
return;
|
|
|
|
g_object_weak_unref (G_OBJECT (icon->entry),
|
|
|
|
gtk_entry_icon_accessible_remove_entry,
|
|
|
|
icon);
|
|
|
|
gtk_entry_icon_accessible_remove_entry (icon, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_entry_icon_accessible_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GtkEntryIconAccessible *icon = GTK_ENTRY_ICON_ACCESSIBLE (object);
|
|
|
|
|
|
|
|
gtk_entry_icon_accessible_invalidate (icon);
|
|
|
|
|
2012-12-27 06:04:46 +00:00
|
|
|
G_OBJECT_CLASS (gtk_entry_icon_accessible_parent_class)->finalize (object);
|
2012-11-11 17:00:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-12-27 06:04:46 +00:00
|
|
|
gtk_entry_icon_accessible_class_init (GtkEntryIconAccessibleClass *klass)
|
2012-11-11 17:00:49 +00:00
|
|
|
{
|
|
|
|
AtkObjectClass *atk_class = ATK_OBJECT_CLASS (klass);
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
atk_class->initialize = gtk_entry_icon_accessible_initialize;
|
|
|
|
atk_class->get_parent = gtk_entry_icon_accessible_get_parent;
|
|
|
|
atk_class->ref_state_set = gtk_entry_icon_accessible_ref_state_set;
|
|
|
|
|
|
|
|
gobject_class->finalize = gtk_entry_icon_accessible_finalize;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_entry_icon_accessible_do_action (AtkAction *action,
|
|
|
|
gint i)
|
|
|
|
{
|
|
|
|
GtkEntryIconAccessible *icon = (GtkEntryIconAccessible *)action;
|
|
|
|
GtkWidget *widget;
|
|
|
|
GtkEntry *gtk_entry;
|
|
|
|
|
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (icon->entry));
|
|
|
|
if (widget == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (i != 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!gtk_widget_is_sensitive (widget) || !gtk_widget_get_visible (widget))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
gtk_entry = GTK_ENTRY (widget);
|
|
|
|
|
|
|
|
if (!gtk_entry_get_icon_sensitive (gtk_entry, icon->pos) ||
|
|
|
|
!gtk_entry_get_icon_activatable (gtk_entry, icon->pos))
|
|
|
|
return FALSE;
|
|
|
|
|
2018-06-06 11:52:08 +00:00
|
|
|
g_signal_emit_by_name (widget, "icon-press", 0, icon->pos);
|
2012-11-11 17:00:49 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
gtk_entry_icon_accessible_get_n_actions (AtkAction *action)
|
|
|
|
{
|
|
|
|
GtkEntryIconAccessible *icon = GTK_ENTRY_ICON_ACCESSIBLE (action);
|
|
|
|
GtkWidget *widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (icon->entry));
|
|
|
|
GtkEntry *gtk_entry = GTK_ENTRY (widget);
|
|
|
|
|
|
|
|
return (gtk_entry_get_icon_activatable (gtk_entry, icon->pos) ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const gchar *
|
|
|
|
gtk_entry_icon_accessible_get_name (AtkAction *action,
|
|
|
|
gint i)
|
|
|
|
{
|
|
|
|
GtkEntryIconAccessible *icon = GTK_ENTRY_ICON_ACCESSIBLE (action);
|
|
|
|
GtkWidget *widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (icon->entry));
|
|
|
|
GtkEntry *gtk_entry = GTK_ENTRY (widget);
|
|
|
|
|
|
|
|
if (i != 0)
|
|
|
|
return NULL;
|
|
|
|
if (!gtk_entry_get_icon_activatable (gtk_entry, icon->pos))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return "activate";
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
icon_atk_action_interface_init (AtkActionIface *iface)
|
|
|
|
{
|
|
|
|
iface->do_action = gtk_entry_icon_accessible_do_action;
|
|
|
|
iface->get_n_actions = gtk_entry_icon_accessible_get_n_actions;
|
|
|
|
iface->get_name = gtk_entry_icon_accessible_get_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_entry_icon_accessible_get_extents (AtkComponent *component,
|
|
|
|
gint *x,
|
|
|
|
gint *y,
|
|
|
|
gint *width,
|
|
|
|
gint *height,
|
|
|
|
AtkCoordType coord_type)
|
|
|
|
{
|
|
|
|
GtkEntryIconAccessible *icon = GTK_ENTRY_ICON_ACCESSIBLE (component);
|
|
|
|
GdkRectangle icon_area;
|
|
|
|
GtkEntry *gtk_entry;
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
|
|
|
*x = G_MININT;
|
|
|
|
atk_component_get_extents (ATK_COMPONENT (icon->entry), x, y, width, height,
|
|
|
|
coord_type);
|
|
|
|
if (*x == G_MININT)
|
|
|
|
return;
|
|
|
|
|
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (icon->entry));
|
|
|
|
gtk_entry = GTK_ENTRY (widget);
|
|
|
|
gtk_entry_get_icon_area (gtk_entry, icon->pos, &icon_area);
|
|
|
|
*width = icon_area.width;
|
|
|
|
*height = icon_area.height;
|
|
|
|
*x += icon_area.x;
|
|
|
|
*y += icon_area.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_entry_icon_accessible_get_position (AtkComponent *component,
|
|
|
|
gint *x,
|
|
|
|
gint *y,
|
|
|
|
AtkCoordType coord_type)
|
|
|
|
{
|
|
|
|
GtkEntryIconAccessible *icon = GTK_ENTRY_ICON_ACCESSIBLE (component);
|
|
|
|
GdkRectangle icon_area;
|
|
|
|
GtkEntry *gtk_entry;
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
|
|
|
*x = G_MININT;
|
2014-03-29 20:48:43 +00:00
|
|
|
atk_component_get_extents (ATK_COMPONENT (icon->entry), x, y, NULL, NULL,
|
|
|
|
coord_type);
|
2012-11-11 17:00:49 +00:00
|
|
|
if (*x == G_MININT)
|
|
|
|
return;
|
|
|
|
|
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (icon->entry));
|
|
|
|
gtk_entry = GTK_ENTRY (widget);
|
|
|
|
gtk_entry_get_icon_area (gtk_entry, icon->pos, &icon_area);
|
|
|
|
*x += icon_area.x;
|
|
|
|
*y += icon_area.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_entry_icon_accessible_get_size (AtkComponent *component,
|
|
|
|
gint *width,
|
|
|
|
gint *height)
|
|
|
|
{
|
|
|
|
GtkEntryIconAccessible *icon = GTK_ENTRY_ICON_ACCESSIBLE (component);
|
|
|
|
GdkRectangle icon_area;
|
|
|
|
GtkEntry *gtk_entry;
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (icon->entry));
|
|
|
|
gtk_entry = GTK_ENTRY (widget);
|
|
|
|
gtk_entry_get_icon_area (gtk_entry, icon->pos, &icon_area);
|
|
|
|
*width = icon_area.width;
|
|
|
|
*height = icon_area.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
icon_atk_component_interface_init (AtkComponentIface *iface)
|
|
|
|
{
|
|
|
|
iface->get_extents = gtk_entry_icon_accessible_get_extents;
|
|
|
|
iface->get_size = gtk_entry_icon_accessible_get_size;
|
|
|
|
iface->get_position = gtk_entry_icon_accessible_get_position;
|
|
|
|
}
|
|
|
|
|
2007-12-18 13:51:12 +00:00
|
|
|
/* Callbacks */
|
|
|
|
|
2011-06-26 01:53:00 +00:00
|
|
|
static void insert_text_cb (GtkEditable *editable,
|
|
|
|
gchar *new_text,
|
|
|
|
gint new_text_length,
|
|
|
|
gint *position);
|
|
|
|
static void delete_text_cb (GtkEditable *editable,
|
|
|
|
gint start,
|
|
|
|
gint end);
|
|
|
|
|
|
|
|
static gboolean check_for_selection_change (GtkEntryAccessible *entry,
|
2019-03-13 21:44:01 +00:00
|
|
|
GtkEditable *editable);
|
2011-06-26 01:53:00 +00:00
|
|
|
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-25 18:43:59 +00:00
|
|
|
static void atk_editable_text_interface_init (AtkEditableTextIface *iface);
|
|
|
|
static void atk_text_interface_init (AtkTextIface *iface);
|
|
|
|
static void atk_action_interface_init (AtkActionIface *iface);
|
|
|
|
|
2011-06-26 01:53:00 +00:00
|
|
|
|
2012-12-27 06:04:46 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkEntryAccessible, gtk_entry_accessible, GTK_TYPE_WIDGET_ACCESSIBLE,
|
2013-06-24 18:13:44 +00:00
|
|
|
G_ADD_PRIVATE (GtkEntryAccessible)
|
2007-12-23 12:24:59 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (ATK_TYPE_EDITABLE_TEXT, atk_editable_text_interface_init)
|
|
|
|
G_IMPLEMENT_INTERFACE (ATK_TYPE_TEXT, atk_text_interface_init)
|
|
|
|
G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION, atk_action_interface_init))
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-26 01:53:00 +00:00
|
|
|
|
2011-07-09 20:32:40 +00:00
|
|
|
static AtkStateSet *
|
2011-06-25 18:43:59 +00:00
|
|
|
gtk_entry_accessible_ref_state_set (AtkObject *accessible)
|
|
|
|
{
|
|
|
|
AtkStateSet *state_set;
|
|
|
|
gboolean value;
|
|
|
|
GtkWidget *widget;
|
2020-03-30 01:48:57 +00:00
|
|
|
GtkWidget *text;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-25 18:43:59 +00:00
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
|
|
|
|
if (widget == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2020-03-30 01:48:57 +00:00
|
|
|
text = gtk_widget_get_first_child (widget);
|
|
|
|
|
2012-12-27 06:04:46 +00:00
|
|
|
state_set = ATK_OBJECT_CLASS (gtk_entry_accessible_parent_class)->ref_state_set (accessible);
|
2011-06-25 18:43:59 +00:00
|
|
|
|
2020-03-30 01:48:57 +00:00
|
|
|
atk_state_set_add_state (state_set, ATK_STATE_FOCUSABLE);
|
|
|
|
if (gtk_widget_has_focus (text))
|
|
|
|
atk_state_set_add_state (state_set, ATK_STATE_FOCUSED);
|
|
|
|
|
2011-06-25 18:43:59 +00:00
|
|
|
g_object_get (G_OBJECT (widget), "editable", &value, NULL);
|
|
|
|
if (value)
|
|
|
|
atk_state_set_add_state (state_set, ATK_STATE_EDITABLE);
|
|
|
|
atk_state_set_add_state (state_set, ATK_STATE_SINGLE_LINE);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-25 18:43:59 +00:00
|
|
|
return state_set;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
2011-06-25 18:43:59 +00:00
|
|
|
static AtkAttributeSet *
|
|
|
|
gtk_entry_accessible_get_attributes (AtkObject *accessible)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-25 18:43:59 +00:00
|
|
|
GtkWidget *widget;
|
|
|
|
AtkAttributeSet *attributes;
|
|
|
|
AtkAttribute *placeholder_text;
|
2019-02-22 20:49:47 +00:00
|
|
|
char *text = NULL;
|
2011-06-25 18:43:59 +00:00
|
|
|
|
2012-12-27 06:04:46 +00:00
|
|
|
attributes = ATK_OBJECT_CLASS (gtk_entry_accessible_parent_class)->get_attributes (accessible);
|
2011-06-25 18:43:59 +00:00
|
|
|
|
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
|
|
|
|
if (widget == NULL)
|
|
|
|
return attributes;
|
|
|
|
|
2019-02-22 20:49:47 +00:00
|
|
|
if (GTK_IS_ENTRY (widget) || GTK_IS_SEARCH_ENTRY (widget))
|
|
|
|
g_object_get (widget, "placeholder-text", &text, NULL);
|
|
|
|
|
2011-06-25 18:43:59 +00:00
|
|
|
if (text == NULL)
|
|
|
|
return attributes;
|
|
|
|
|
|
|
|
placeholder_text = g_malloc (sizeof (AtkAttribute));
|
|
|
|
placeholder_text->name = g_strdup ("placeholder-text");
|
2019-02-22 20:49:47 +00:00
|
|
|
placeholder_text->value = text;
|
2011-06-25 18:43:59 +00:00
|
|
|
|
|
|
|
attributes = g_slist_append (attributes, placeholder_text);
|
|
|
|
|
|
|
|
return attributes;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-06-25 18:43:59 +00:00
|
|
|
gtk_entry_accessible_initialize (AtkObject *obj,
|
|
|
|
gpointer data)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2019-02-22 20:49:47 +00:00
|
|
|
GtkWidget *widget;
|
2011-06-25 02:12:55 +00:00
|
|
|
GtkEntryAccessible *gtk_entry_accessible;
|
2010-10-20 17:22:46 +00:00
|
|
|
gint start_pos, end_pos;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2012-12-27 06:04:46 +00:00
|
|
|
ATK_OBJECT_CLASS (gtk_entry_accessible_parent_class)->initialize (obj, data);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-25 02:12:55 +00:00
|
|
|
gtk_entry_accessible = GTK_ENTRY_ACCESSIBLE (obj);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2019-02-22 20:49:47 +00:00
|
|
|
widget = GTK_WIDGET (data);
|
|
|
|
gtk_editable_get_selection_bounds (GTK_EDITABLE (widget), &start_pos, &end_pos);
|
2012-10-14 19:59:58 +00:00
|
|
|
gtk_entry_accessible->priv->cursor_position = end_pos;
|
|
|
|
gtk_entry_accessible->priv->selection_bound = start_pos;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
/* Set up signal callbacks */
|
2019-02-22 20:49:47 +00:00
|
|
|
g_signal_connect_after (widget, "insert-text", G_CALLBACK (insert_text_cb), NULL);
|
|
|
|
g_signal_connect (widget, "delete-text", G_CALLBACK (delete_text_cb), NULL);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2019-02-22 20:49:47 +00:00
|
|
|
if (GTK_IS_PASSWORD_ENTRY (widget))
|
2007-12-18 13:51:12 +00:00
|
|
|
obj->role = ATK_ROLE_PASSWORD_TEXT;
|
2019-02-22 20:49:47 +00:00
|
|
|
else
|
|
|
|
obj->role = ATK_ROLE_TEXT;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-06-25 18:43:59 +00:00
|
|
|
gtk_entry_accessible_notify_gtk (GObject *obj,
|
|
|
|
GParamSpec *pspec)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
AtkObject* atk_obj;
|
2011-06-25 02:12:55 +00:00
|
|
|
GtkEntryAccessible* entry;
|
2012-11-11 17:00:49 +00:00
|
|
|
GtkEntryAccessiblePrivate *priv;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
widget = GTK_WIDGET (obj);
|
|
|
|
atk_obj = gtk_widget_get_accessible (widget);
|
2011-06-25 02:12:55 +00:00
|
|
|
entry = GTK_ENTRY_ACCESSIBLE (atk_obj);
|
2012-11-11 17:00:49 +00:00
|
|
|
priv = entry->priv;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-07-10 04:02:02 +00:00
|
|
|
if (g_strcmp0 (pspec->name, "cursor-position") == 0)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2019-03-13 21:44:01 +00:00
|
|
|
if (check_for_selection_change (entry, GTK_EDITABLE (widget)))
|
2011-07-17 22:47:19 +00:00
|
|
|
g_signal_emit_by_name (atk_obj, "text-selection-changed");
|
2007-12-18 13:51:12 +00:00
|
|
|
/*
|
|
|
|
* The entry cursor position has moved so generate the signal.
|
|
|
|
*/
|
2011-07-17 22:47:19 +00:00
|
|
|
g_signal_emit_by_name (atk_obj, "text-caret-moved",
|
2019-03-13 21:44:01 +00:00
|
|
|
gtk_editable_get_position (GTK_EDITABLE (widget)));
|
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)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2019-03-13 21:44:01 +00:00
|
|
|
if (check_for_selection_change (entry, GTK_EDITABLE (widget)))
|
2011-07-17 22:47:19 +00:00
|
|
|
g_signal_emit_by_name (atk_obj, "text-selection-changed");
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
2019-03-13 21:44:01 +00:00
|
|
|
else if (GTK_IS_ENTRY (widget) &&
|
|
|
|
g_strcmp0 (pspec->name, "editable") == 0)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
gboolean value;
|
|
|
|
|
|
|
|
g_object_get (obj, "editable", &value, NULL);
|
2011-06-25 18:43:59 +00:00
|
|
|
atk_object_notify_state_change (atk_obj, ATK_STATE_EDITABLE, value);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
2019-03-13 21:44:01 +00:00
|
|
|
else if (GTK_IS_ENTRY (widget) &&
|
|
|
|
g_strcmp0 (pspec->name, "visibility") == 0)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
gboolean visibility;
|
|
|
|
AtkRole new_role;
|
|
|
|
|
2019-03-13 21:44:01 +00:00
|
|
|
visibility = gtk_entry_get_visibility (GTK_ENTRY (widget));
|
2007-12-18 13:51:12 +00:00
|
|
|
new_role = visibility ? ATK_ROLE_TEXT : ATK_ROLE_PASSWORD_TEXT;
|
|
|
|
atk_object_set_role (atk_obj, new_role);
|
|
|
|
}
|
2019-03-13 21:44:01 +00:00
|
|
|
else if (GTK_IS_ENTRY (widget) &&
|
|
|
|
g_strcmp0 (pspec->name, "primary-icon-storage-type") == 0)
|
2012-11-11 17:00:49 +00:00
|
|
|
{
|
2019-03-13 21:44:01 +00:00
|
|
|
if (gtk_entry_get_icon_storage_type (GTK_ENTRY (widget), GTK_ENTRY_ICON_PRIMARY) != GTK_IMAGE_EMPTY && !priv->icons[GTK_ENTRY_ICON_PRIMARY])
|
2012-11-11 17:00:49 +00:00
|
|
|
{
|
|
|
|
priv->icons[GTK_ENTRY_ICON_PRIMARY] = gtk_entry_icon_accessible_new (entry, GTK_ENTRY_ICON_PRIMARY);
|
|
|
|
g_signal_emit_by_name (entry, "children-changed::add", 0,
|
|
|
|
priv->icons[GTK_ENTRY_ICON_PRIMARY], NULL);
|
|
|
|
}
|
2019-03-13 21:44:01 +00:00
|
|
|
else if (gtk_entry_get_icon_storage_type (GTK_ENTRY (widget), GTK_ENTRY_ICON_PRIMARY) == GTK_IMAGE_EMPTY && priv->icons[GTK_ENTRY_ICON_PRIMARY])
|
2012-11-11 17:00:49 +00:00
|
|
|
{
|
|
|
|
gtk_entry_icon_accessible_invalidate (GTK_ENTRY_ICON_ACCESSIBLE (priv->icons[GTK_ENTRY_ICON_PRIMARY]));
|
|
|
|
g_signal_emit_by_name (entry, "children-changed::remove", 0,
|
|
|
|
priv->icons[GTK_ENTRY_ICON_PRIMARY], NULL);
|
|
|
|
g_clear_object (&priv->icons[GTK_ENTRY_ICON_PRIMARY]);
|
|
|
|
}
|
|
|
|
}
|
2019-03-13 21:44:01 +00:00
|
|
|
else if (GTK_IS_ENTRY (widget) &&
|
|
|
|
g_strcmp0 (pspec->name, "secondary-icon-storage-type") == 0)
|
2012-11-11 17:00:49 +00:00
|
|
|
{
|
|
|
|
gint index = (priv->icons[GTK_ENTRY_ICON_PRIMARY] ? 1 : 0);
|
2019-03-13 21:44:01 +00:00
|
|
|
if (gtk_entry_get_icon_storage_type (GTK_ENTRY (widget), GTK_ENTRY_ICON_SECONDARY) != GTK_IMAGE_EMPTY && !priv->icons[GTK_ENTRY_ICON_SECONDARY])
|
2012-11-11 17:00:49 +00:00
|
|
|
{
|
|
|
|
priv->icons[GTK_ENTRY_ICON_SECONDARY] = gtk_entry_icon_accessible_new (entry, GTK_ENTRY_ICON_SECONDARY);
|
|
|
|
g_signal_emit_by_name (entry, "children-changed::add", index,
|
|
|
|
priv->icons[GTK_ENTRY_ICON_SECONDARY], NULL);
|
|
|
|
}
|
2019-03-13 21:44:01 +00:00
|
|
|
else if (gtk_entry_get_icon_storage_type (GTK_ENTRY (widget), GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY && priv->icons[GTK_ENTRY_ICON_SECONDARY])
|
2012-11-11 17:00:49 +00:00
|
|
|
{
|
|
|
|
gtk_entry_icon_accessible_invalidate (GTK_ENTRY_ICON_ACCESSIBLE (priv->icons[GTK_ENTRY_ICON_SECONDARY]));
|
|
|
|
g_signal_emit_by_name (entry, "children-changed::remove", index,
|
|
|
|
priv->icons[GTK_ENTRY_ICON_SECONDARY], NULL);
|
|
|
|
g_clear_object (&priv->icons[GTK_ENTRY_ICON_SECONDARY]);
|
|
|
|
}
|
|
|
|
}
|
2019-03-13 21:44:01 +00:00
|
|
|
else if (GTK_IS_ENTRY (widget) &&
|
|
|
|
g_strcmp0 (pspec->name, "primary-icon-name") == 0)
|
2012-11-11 17:00:49 +00:00
|
|
|
{
|
|
|
|
if (priv->icons[GTK_ENTRY_ICON_PRIMARY])
|
|
|
|
{
|
|
|
|
const gchar *name;
|
2019-03-13 21:44:01 +00:00
|
|
|
name = gtk_entry_get_icon_name (GTK_ENTRY (widget), GTK_ENTRY_ICON_PRIMARY);
|
2012-12-09 10:49:35 +00:00
|
|
|
if (name)
|
|
|
|
atk_object_set_name (priv->icons[GTK_ENTRY_ICON_PRIMARY], name);
|
2012-11-11 17:00:49 +00:00
|
|
|
}
|
|
|
|
}
|
2019-03-13 21:44:01 +00:00
|
|
|
else if (GTK_IS_ENTRY (widget) &&
|
|
|
|
g_strcmp0 (pspec->name, "secondary-icon-name") == 0)
|
2012-11-11 17:00:49 +00:00
|
|
|
{
|
|
|
|
if (priv->icons[GTK_ENTRY_ICON_SECONDARY])
|
|
|
|
{
|
|
|
|
const gchar *name;
|
2019-03-13 21:44:01 +00:00
|
|
|
name = gtk_entry_get_icon_name (GTK_ENTRY (widget), GTK_ENTRY_ICON_SECONDARY);
|
2012-12-09 10:49:35 +00:00
|
|
|
if (name)
|
|
|
|
atk_object_set_name (priv->icons[GTK_ENTRY_ICON_SECONDARY], name);
|
2012-11-11 17:00:49 +00:00
|
|
|
}
|
|
|
|
}
|
2019-03-13 21:44:01 +00:00
|
|
|
else if (GTK_IS_ENTRY (widget) &&
|
|
|
|
g_strcmp0 (pspec->name, "primary-icon-tooltip-text") == 0)
|
2012-11-11 17:00:49 +00:00
|
|
|
{
|
|
|
|
if (priv->icons[GTK_ENTRY_ICON_PRIMARY])
|
|
|
|
{
|
|
|
|
gchar *text;
|
2019-03-13 21:44:01 +00:00
|
|
|
text = gtk_entry_get_icon_tooltip_text (GTK_ENTRY (widget), GTK_ENTRY_ICON_PRIMARY);
|
2013-03-07 14:54:04 +00:00
|
|
|
if (text)
|
|
|
|
{
|
2019-03-13 21:44:01 +00:00
|
|
|
atk_object_set_description (priv->icons[GTK_ENTRY_ICON_PRIMARY], text);
|
2013-03-07 14:54:04 +00:00
|
|
|
g_free (text);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-13 21:44:01 +00:00
|
|
|
atk_object_set_description (priv->icons[GTK_ENTRY_ICON_PRIMARY], "");
|
2013-03-07 14:54:04 +00:00
|
|
|
}
|
2012-11-11 17:00:49 +00:00
|
|
|
}
|
|
|
|
}
|
2019-03-13 21:44:01 +00:00
|
|
|
else if (GTK_IS_ENTRY (widget) &&
|
|
|
|
g_strcmp0 (pspec->name, "secondary-icon-tooltip-text") == 0)
|
2012-11-11 17:00:49 +00:00
|
|
|
{
|
|
|
|
if (priv->icons[GTK_ENTRY_ICON_SECONDARY])
|
|
|
|
{
|
|
|
|
gchar *text;
|
2019-03-13 21:44:01 +00:00
|
|
|
text = gtk_entry_get_icon_tooltip_text (GTK_ENTRY (widget), GTK_ENTRY_ICON_SECONDARY);
|
2013-03-07 14:54:04 +00:00
|
|
|
if (text)
|
|
|
|
{
|
2019-03-13 21:44:01 +00:00
|
|
|
atk_object_set_description (priv->icons[GTK_ENTRY_ICON_SECONDARY], text);
|
2013-03-07 14:54:04 +00:00
|
|
|
g_free (text);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-13 21:44:01 +00:00
|
|
|
atk_object_set_description (priv->icons[GTK_ENTRY_ICON_SECONDARY], "");
|
2013-03-07 14:54:04 +00:00
|
|
|
}
|
2012-11-11 17:00:49 +00:00
|
|
|
}
|
|
|
|
}
|
2019-03-13 21:44:01 +00:00
|
|
|
else if (GTK_IS_ENTRY (widget) &&
|
|
|
|
g_strcmp0 (pspec->name, "primary-icon-activatable") == 0)
|
2012-11-11 17:00:49 +00:00
|
|
|
{
|
|
|
|
if (priv->icons[GTK_ENTRY_ICON_PRIMARY])
|
|
|
|
{
|
2019-03-13 21:44:01 +00:00
|
|
|
gboolean on = gtk_entry_get_icon_activatable (GTK_ENTRY (widget), GTK_ENTRY_ICON_PRIMARY);
|
2012-11-11 17:00:49 +00:00
|
|
|
atk_object_notify_state_change (priv->icons[GTK_ENTRY_ICON_PRIMARY],
|
|
|
|
ATK_STATE_ENABLED, on);
|
|
|
|
}
|
|
|
|
}
|
2019-03-13 21:44:01 +00:00
|
|
|
else if (GTK_IS_ENTRY (widget) &&
|
|
|
|
g_strcmp0 (pspec->name, "secondary-icon-activatable") == 0)
|
2012-11-11 17:00:49 +00:00
|
|
|
{
|
|
|
|
if (priv->icons[GTK_ENTRY_ICON_SECONDARY])
|
|
|
|
{
|
2019-03-13 21:44:01 +00:00
|
|
|
gboolean on = gtk_entry_get_icon_activatable (GTK_ENTRY (widget), GTK_ENTRY_ICON_SECONDARY);
|
2012-11-11 17:00:49 +00:00
|
|
|
atk_object_notify_state_change (priv->icons[GTK_ENTRY_ICON_SECONDARY],
|
|
|
|
ATK_STATE_ENABLED, on);
|
|
|
|
}
|
|
|
|
}
|
2019-03-13 21:44:01 +00:00
|
|
|
else if (GTK_IS_ENTRY (widget) &&
|
|
|
|
g_strcmp0 (pspec->name, "primary-icon-sensitive") == 0)
|
2012-11-11 17:00:49 +00:00
|
|
|
{
|
|
|
|
if (priv->icons[GTK_ENTRY_ICON_PRIMARY])
|
|
|
|
{
|
2019-03-13 21:44:01 +00:00
|
|
|
gboolean on = gtk_entry_get_icon_sensitive (GTK_ENTRY (widget), GTK_ENTRY_ICON_PRIMARY);
|
2012-11-11 17:00:49 +00:00
|
|
|
atk_object_notify_state_change (priv->icons[GTK_ENTRY_ICON_PRIMARY],
|
|
|
|
ATK_STATE_SENSITIVE, on);
|
|
|
|
}
|
|
|
|
}
|
2019-03-13 21:44:01 +00:00
|
|
|
else if (GTK_IS_ENTRY (widget) &&
|
|
|
|
g_strcmp0 (pspec->name, "secondary-icon-sensitive") == 0)
|
2012-11-11 17:00:49 +00:00
|
|
|
{
|
|
|
|
if (priv->icons[GTK_ENTRY_ICON_SECONDARY])
|
|
|
|
{
|
2019-03-13 21:44:01 +00:00
|
|
|
gboolean on = gtk_entry_get_icon_sensitive (GTK_ENTRY (widget), GTK_ENTRY_ICON_SECONDARY);
|
2012-11-11 17:00:49 +00:00
|
|
|
atk_object_notify_state_change (priv->icons[GTK_ENTRY_ICON_SECONDARY],
|
|
|
|
ATK_STATE_SENSITIVE, on);
|
|
|
|
}
|
|
|
|
}
|
2007-12-18 13:51:12 +00:00
|
|
|
else
|
2012-12-27 06:04:46 +00:00
|
|
|
GTK_WIDGET_ACCESSIBLE_CLASS (gtk_entry_accessible_parent_class)->notify_gtk (obj, pspec);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
2011-06-25 02:12:55 +00:00
|
|
|
gtk_entry_accessible_get_index_in_parent (AtkObject *accessible)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* If the parent widget is a combo box then the index is 1
|
|
|
|
* otherwise do the normal thing.
|
|
|
|
*/
|
|
|
|
if (accessible->accessible_parent)
|
2011-06-29 21:31:09 +00:00
|
|
|
if (GTK_IS_COMBO_BOX_ACCESSIBLE (accessible->accessible_parent))
|
2007-12-18 13:51:12 +00:00
|
|
|
return 1;
|
|
|
|
|
2012-12-27 06:04:46 +00:00
|
|
|
return ATK_OBJECT_CLASS (gtk_entry_accessible_parent_class)->get_index_in_parent (accessible);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
2012-11-11 17:00:49 +00:00
|
|
|
static gint
|
|
|
|
gtk_entry_accessible_get_n_children (AtkObject* obj)
|
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
gint count = 0;
|
|
|
|
|
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
|
|
|
|
if (widget == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2019-02-22 20:49:47 +00:00
|
|
|
if (GTK_IS_ENTRY (widget))
|
|
|
|
{
|
|
|
|
if (gtk_entry_get_icon_storage_type (GTK_ENTRY (widget), GTK_ENTRY_ICON_PRIMARY) != GTK_IMAGE_EMPTY)
|
|
|
|
count++;
|
|
|
|
if (gtk_entry_get_icon_storage_type (GTK_ENTRY (widget), GTK_ENTRY_ICON_SECONDARY) != GTK_IMAGE_EMPTY)
|
|
|
|
count++;
|
|
|
|
}
|
2012-11-11 17:00:49 +00:00
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static AtkObject *
|
|
|
|
gtk_entry_accessible_ref_child (AtkObject *obj,
|
|
|
|
gint i)
|
|
|
|
{
|
|
|
|
GtkEntryAccessible *accessible = GTK_ENTRY_ACCESSIBLE (obj);
|
|
|
|
GtkEntryAccessiblePrivate *priv = accessible->priv;
|
|
|
|
GtkWidget *widget;
|
|
|
|
GtkEntryIconPosition pos;
|
|
|
|
|
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
|
|
|
|
if (widget == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2019-02-22 20:49:47 +00:00
|
|
|
if (!GTK_IS_ENTRY (widget))
|
|
|
|
return NULL;
|
2012-11-11 17:00:49 +00:00
|
|
|
|
|
|
|
switch (i)
|
|
|
|
{
|
|
|
|
case 0:
|
2019-02-22 20:49:47 +00:00
|
|
|
if (gtk_entry_get_icon_storage_type (GTK_ENTRY (widget), GTK_ENTRY_ICON_PRIMARY) != GTK_IMAGE_EMPTY)
|
2012-11-11 17:00:49 +00:00
|
|
|
pos = GTK_ENTRY_ICON_PRIMARY;
|
2019-02-22 20:49:47 +00:00
|
|
|
else if (gtk_entry_get_icon_storage_type (GTK_ENTRY (widget), GTK_ENTRY_ICON_SECONDARY) != GTK_IMAGE_EMPTY)
|
2012-11-11 17:00:49 +00:00
|
|
|
pos = GTK_ENTRY_ICON_SECONDARY;
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
break;
|
|
|
|
case 1:
|
2019-02-22 20:49:47 +00:00
|
|
|
if (gtk_entry_get_icon_storage_type (GTK_ENTRY (widget), GTK_ENTRY_ICON_PRIMARY) == GTK_IMAGE_EMPTY)
|
2012-11-11 17:00:49 +00:00
|
|
|
return NULL;
|
2019-02-22 20:49:47 +00:00
|
|
|
if (gtk_entry_get_icon_storage_type (GTK_ENTRY (widget), GTK_ENTRY_ICON_SECONDARY) == GTK_IMAGE_EMPTY)
|
2012-11-11 17:00:49 +00:00
|
|
|
return NULL;
|
|
|
|
pos = GTK_ENTRY_ICON_SECONDARY;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!priv->icons[pos])
|
|
|
|
priv->icons[pos] = gtk_entry_icon_accessible_new (accessible, pos);
|
|
|
|
return g_object_ref (priv->icons[pos]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_entry_accessible_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GtkEntryAccessible *entry = GTK_ENTRY_ACCESSIBLE (object);
|
|
|
|
GtkEntryAccessiblePrivate *priv = entry->priv;
|
|
|
|
|
|
|
|
g_clear_object (&priv->icons[GTK_ENTRY_ICON_PRIMARY]);
|
|
|
|
g_clear_object (&priv->icons[GTK_ENTRY_ICON_SECONDARY]);
|
|
|
|
|
2012-12-27 06:04:46 +00:00
|
|
|
G_OBJECT_CLASS (gtk_entry_accessible_parent_class)->finalize (object);
|
2012-11-11 17:00:49 +00:00
|
|
|
}
|
|
|
|
|
2011-06-25 18:43:59 +00:00
|
|
|
static void
|
2012-12-27 06:04:46 +00:00
|
|
|
gtk_entry_accessible_class_init (GtkEntryAccessibleClass *klass)
|
2011-03-02 17:17:05 +00:00
|
|
|
{
|
2011-06-25 18:43:59 +00:00
|
|
|
AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
|
2011-07-02 19:23:52 +00:00
|
|
|
GtkWidgetAccessibleClass *widget_class = (GtkWidgetAccessibleClass*)klass;
|
2012-11-11 17:00:49 +00:00
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
2011-03-02 17:17:05 +00:00
|
|
|
|
2011-06-25 18:43:59 +00:00
|
|
|
class->ref_state_set = gtk_entry_accessible_ref_state_set;
|
|
|
|
class->get_index_in_parent = gtk_entry_accessible_get_index_in_parent;
|
|
|
|
class->initialize = gtk_entry_accessible_initialize;
|
|
|
|
class->get_attributes = gtk_entry_accessible_get_attributes;
|
2012-11-11 17:00:49 +00:00
|
|
|
class->get_n_children = gtk_entry_accessible_get_n_children;
|
|
|
|
class->ref_child = gtk_entry_accessible_ref_child;
|
2011-03-02 17:17:05 +00:00
|
|
|
|
2011-06-25 18:43:59 +00:00
|
|
|
widget_class->notify_gtk = gtk_entry_accessible_notify_gtk;
|
2012-10-14 19:59:58 +00:00
|
|
|
|
2012-11-11 17:00:49 +00:00
|
|
|
gobject_class->finalize = gtk_entry_accessible_finalize;
|
2011-03-02 17:17:05 +00:00
|
|
|
}
|
|
|
|
|
2007-12-18 13:51:12 +00:00
|
|
|
static void
|
2012-12-27 06:04:46 +00:00
|
|
|
gtk_entry_accessible_init (GtkEntryAccessible *entry)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2013-06-24 18:13:44 +00:00
|
|
|
entry->priv = gtk_entry_accessible_get_instance_private (entry);
|
2012-10-14 19:59:58 +00:00
|
|
|
entry->priv->cursor_position = 0;
|
|
|
|
entry->priv->selection_bound = 0;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
2019-02-22 20:49:47 +00:00
|
|
|
static GtkText *
|
|
|
|
get_text (AtkText *atk_text)
|
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (atk_text));
|
|
|
|
if (widget == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (GTK_IS_ENTRY (widget))
|
|
|
|
return gtk_entry_get_text_widget (GTK_ENTRY (widget));
|
|
|
|
else if (GTK_IS_SEARCH_ENTRY (widget))
|
|
|
|
return gtk_search_entry_get_text_widget (GTK_SEARCH_ENTRY (widget));
|
|
|
|
else
|
|
|
|
return NULL; // FIXME;
|
|
|
|
}
|
|
|
|
|
2011-06-25 18:43:59 +00:00
|
|
|
static gchar *
|
|
|
|
gtk_entry_accessible_get_text (AtkText *atk_text,
|
|
|
|
gint start_pos,
|
|
|
|
gint end_pos)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2019-02-22 20:49:47 +00:00
|
|
|
GtkText *text;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2019-02-22 20:49:47 +00:00
|
|
|
text = get_text (atk_text);
|
|
|
|
|
|
|
|
if (text == NULL)
|
2007-12-18 13:51:12 +00:00
|
|
|
return NULL;
|
|
|
|
|
2019-02-22 20:49:47 +00:00
|
|
|
return gtk_text_get_display_text (text, start_pos, end_pos);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
2011-06-25 18:43:59 +00:00
|
|
|
static gchar *
|
2019-02-22 20:49:47 +00:00
|
|
|
gtk_entry_accessible_get_text_before_offset (AtkText *atk_text,
|
2011-06-25 18:43:59 +00:00
|
|
|
gint offset,
|
|
|
|
AtkTextBoundary boundary_type,
|
|
|
|
gint *start_offset,
|
|
|
|
gint *end_offset)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2019-02-22 20:49:47 +00:00
|
|
|
GtkText *text;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2019-02-22 20:49:47 +00:00
|
|
|
text = get_text (atk_text);
|
|
|
|
|
|
|
|
if (text == NULL)
|
2007-12-18 13:51:12 +00:00
|
|
|
return NULL;
|
|
|
|
|
2019-02-22 20:49:47 +00:00
|
|
|
return _gtk_pango_get_text_before (gtk_text_get_layout (text),
|
2011-06-25 18:43:59 +00:00
|
|
|
boundary_type, offset,
|
|
|
|
start_offset, end_offset);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
2011-06-25 18:43:59 +00:00
|
|
|
static gchar *
|
2019-02-22 20:49:47 +00:00
|
|
|
gtk_entry_accessible_get_text_at_offset (AtkText *atk_text,
|
2011-06-25 18:43:59 +00:00
|
|
|
gint offset,
|
|
|
|
AtkTextBoundary boundary_type,
|
|
|
|
gint *start_offset,
|
|
|
|
gint *end_offset)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2019-02-22 20:49:47 +00:00
|
|
|
GtkText *text;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2019-02-22 20:49:47 +00:00
|
|
|
text = get_text (atk_text);
|
|
|
|
|
|
|
|
if (text == NULL)
|
2007-12-18 13:51:12 +00:00
|
|
|
return NULL;
|
|
|
|
|
2019-02-22 20:49:47 +00:00
|
|
|
return _gtk_pango_get_text_at (gtk_text_get_layout (text),
|
2011-06-25 18:43:59 +00:00
|
|
|
boundary_type, offset,
|
|
|
|
start_offset, end_offset);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
2011-06-25 18:43:59 +00:00
|
|
|
static gchar *
|
2019-02-22 20:49:47 +00:00
|
|
|
gtk_entry_accessible_get_text_after_offset (AtkText *atk_text,
|
2011-06-25 18:43:59 +00:00
|
|
|
gint offset,
|
|
|
|
AtkTextBoundary boundary_type,
|
|
|
|
gint *start_offset,
|
|
|
|
gint *end_offset)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2019-02-22 20:49:47 +00:00
|
|
|
GtkText *text;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2019-02-22 20:49:47 +00:00
|
|
|
text = get_text (atk_text);
|
|
|
|
|
|
|
|
if (text == NULL)
|
2007-12-18 13:51:12 +00:00
|
|
|
return NULL;
|
|
|
|
|
2019-02-22 20:49:47 +00:00
|
|
|
return _gtk_pango_get_text_after (gtk_text_get_layout (text),
|
2011-06-25 18:43:59 +00:00
|
|
|
boundary_type, offset,
|
|
|
|
start_offset, end_offset);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
2011-06-25 18:43:59 +00:00
|
|
|
gtk_entry_accessible_get_character_count (AtkText *atk_text)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2019-02-22 20:49:47 +00:00
|
|
|
GtkText *text;
|
|
|
|
char *display_text;
|
|
|
|
int char_count;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2019-02-22 20:49:47 +00:00
|
|
|
text = get_text (atk_text);
|
|
|
|
|
|
|
|
if (text == NULL)
|
2007-12-18 13:51:12 +00:00
|
|
|
return 0;
|
|
|
|
|
2019-02-22 20:49:47 +00:00
|
|
|
display_text = gtk_text_get_display_text (text, 0, -1);
|
2011-06-25 18:43:59 +00:00
|
|
|
|
2012-08-10 16:04:57 +00:00
|
|
|
char_count = 0;
|
2019-02-22 20:49:47 +00:00
|
|
|
if (display_text)
|
2012-08-10 16:04:57 +00:00
|
|
|
{
|
2019-02-22 20:49:47 +00:00
|
|
|
char_count = g_utf8_strlen (display_text, -1);
|
|
|
|
g_free (display_text);
|
2012-08-10 16:04:57 +00:00
|
|
|
}
|
2011-06-25 18:43:59 +00:00
|
|
|
|
2012-08-10 16:04:57 +00:00
|
|
|
return char_count;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
2011-06-25 02:12:55 +00:00
|
|
|
gtk_entry_accessible_get_caret_offset (AtkText *text)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
2019-03-26 14:28:03 +00:00
|
|
|
gboolean result;
|
|
|
|
int cursor_position;
|
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)
|
2019-03-26 14:28:03 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
result = gtk_editable_get_selection_bounds (GTK_EDITABLE (widget), NULL, &cursor_position);
|
|
|
|
if (!result)
|
|
|
|
return -1;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2019-03-26 14:28:03 +00:00
|
|
|
return cursor_position;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-06-25 18:43:59 +00:00
|
|
|
gtk_entry_accessible_set_caret_offset (AtkText *text,
|
|
|
|
gint 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 FALSE;
|
|
|
|
|
2011-06-25 18:43:59 +00:00
|
|
|
gtk_editable_set_position (GTK_EDITABLE (widget), offset);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-06-25 18:43:59 +00:00
|
|
|
static AtkAttributeSet *
|
2011-06-27 00:42:54 +00:00
|
|
|
add_text_attribute (AtkAttributeSet *attributes,
|
|
|
|
AtkTextAttribute attr,
|
|
|
|
gint i)
|
2011-06-25 18:43:59 +00:00
|
|
|
{
|
|
|
|
AtkAttribute *at;
|
|
|
|
|
|
|
|
at = g_new (AtkAttribute, 1);
|
|
|
|
at->name = g_strdup (atk_text_attribute_get_name (attr));
|
2011-06-27 00:42:54 +00:00
|
|
|
at->value = g_strdup (atk_text_attribute_get_value (attr, i));
|
2011-06-25 18:43:59 +00:00
|
|
|
|
|
|
|
return g_slist_prepend (attributes, at);
|
|
|
|
}
|
|
|
|
|
|
|
|
static AtkAttributeSet *
|
2019-02-22 20:49:47 +00:00
|
|
|
gtk_entry_accessible_get_run_attributes (AtkText *atk_text,
|
2011-06-25 18:43:59 +00:00
|
|
|
gint offset,
|
|
|
|
gint *start_offset,
|
|
|
|
gint *end_offset)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2019-02-22 20:49:47 +00:00
|
|
|
GtkText *text;
|
2011-06-25 18:43:59 +00:00
|
|
|
AtkAttributeSet *attributes;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2019-02-22 20:49:47 +00:00
|
|
|
text = get_text (atk_text);
|
|
|
|
|
|
|
|
if (text == NULL)
|
2007-12-18 13:51:12 +00:00
|
|
|
return NULL;
|
|
|
|
|
2011-06-25 18:43:59 +00:00
|
|
|
attributes = NULL;
|
2011-06-27 00:42:54 +00:00
|
|
|
attributes = add_text_attribute (attributes, ATK_TEXT_ATTR_DIRECTION,
|
2019-02-22 20:49:47 +00:00
|
|
|
gtk_widget_get_direction (GTK_WIDGET (text)));
|
2011-06-25 18:43:59 +00:00
|
|
|
attributes = _gtk_pango_get_run_attributes (attributes,
|
2019-02-22 20:49:47 +00:00
|
|
|
gtk_text_get_layout (text),
|
2011-06-25 18:43:59 +00:00
|
|
|
offset,
|
|
|
|
start_offset,
|
|
|
|
end_offset);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-25 18:43:59 +00:00
|
|
|
return attributes;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
2011-06-25 18:43:59 +00:00
|
|
|
static AtkAttributeSet *
|
2019-02-22 20:49:47 +00:00
|
|
|
gtk_entry_accessible_get_default_attributes (AtkText *atk_text)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2019-02-22 20:49:47 +00:00
|
|
|
GtkText *text;
|
2011-06-25 18:43:59 +00:00
|
|
|
AtkAttributeSet *attributes;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2019-02-22 20:49:47 +00:00
|
|
|
text = get_text (atk_text);
|
|
|
|
|
|
|
|
if (text == NULL)
|
2007-12-18 13:51:12 +00:00
|
|
|
return NULL;
|
|
|
|
|
2011-06-25 18:43:59 +00:00
|
|
|
attributes = NULL;
|
2011-06-27 00:42:54 +00:00
|
|
|
attributes = add_text_attribute (attributes, ATK_TEXT_ATTR_DIRECTION,
|
2019-02-22 20:49:47 +00:00
|
|
|
gtk_widget_get_direction (GTK_WIDGET (text)));
|
2011-06-25 18:43:59 +00:00
|
|
|
attributes = _gtk_pango_get_default_attributes (attributes,
|
2019-02-22 20:49:47 +00:00
|
|
|
gtk_text_get_layout (text));
|
2011-06-25 18:43:59 +00:00
|
|
|
attributes = _gtk_style_context_get_attributes (attributes,
|
2019-02-22 20:49:47 +00:00
|
|
|
gtk_widget_get_style_context (GTK_WIDGET (text)));
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-25 18:43:59 +00:00
|
|
|
return attributes;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
2011-06-25 18:43:59 +00:00
|
|
|
|
2007-12-18 13:51:12 +00:00
|
|
|
static void
|
2019-02-22 20:49:47 +00:00
|
|
|
gtk_entry_accessible_get_character_extents (AtkText *atk_text,
|
2011-06-25 18:43:59 +00:00
|
|
|
gint offset,
|
|
|
|
gint *x,
|
|
|
|
gint *y,
|
|
|
|
gint *width,
|
|
|
|
gint *height,
|
|
|
|
AtkCoordType coords)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2019-02-16 05:50:12 +00:00
|
|
|
GtkText *textw;
|
2007-12-18 13:51:12 +00:00
|
|
|
PangoRectangle char_rect;
|
2012-08-10 16:04:57 +00:00
|
|
|
gchar *entry_text;
|
2011-06-25 18:43:59 +00:00
|
|
|
gint index, x_layout, y_layout;
|
2017-10-15 11:55:22 +00:00
|
|
|
GtkAllocation allocation;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2019-02-22 20:49:47 +00:00
|
|
|
textw = get_text (atk_text);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2019-02-22 20:49:47 +00:00
|
|
|
if (textw == NULL)
|
|
|
|
return;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2019-02-16 05:50:12 +00:00
|
|
|
gtk_text_get_layout_offsets (textw, &x_layout, &y_layout);
|
|
|
|
entry_text = gtk_text_get_display_text (textw, 0, -1);
|
2009-03-27 05:22:23 +00:00
|
|
|
index = g_utf8_offset_to_pointer (entry_text, offset) - entry_text;
|
2012-08-10 16:04:57 +00:00
|
|
|
g_free (entry_text);
|
|
|
|
|
2019-02-16 05:50:12 +00:00
|
|
|
pango_layout_index_to_pos (gtk_text_get_layout (textw), index, &char_rect);
|
2011-06-25 18:43:59 +00:00
|
|
|
pango_extents_to_pixels (&char_rect, NULL);
|
|
|
|
|
2019-02-22 20:49:47 +00:00
|
|
|
gtk_widget_get_allocation (GTK_WIDGET (textw), &allocation);
|
2017-10-05 15:49:00 +00:00
|
|
|
|
2019-03-23 05:59:47 +00:00
|
|
|
*x = allocation.x + x_layout + char_rect.x;
|
|
|
|
*y = allocation.y + y_layout + char_rect.y;
|
2011-06-25 18:43:59 +00:00
|
|
|
*width = char_rect.width;
|
|
|
|
*height = char_rect.height;
|
|
|
|
}
|
2011-01-30 07:14:08 +00:00
|
|
|
|
2011-06-25 18:43:59 +00:00
|
|
|
static gint
|
|
|
|
gtk_entry_accessible_get_offset_at_point (AtkText *atk_text,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
AtkCoordType coords)
|
|
|
|
{
|
2019-02-16 05:50:12 +00:00
|
|
|
GtkText *textw;
|
2012-08-10 16:04:57 +00:00
|
|
|
gchar *text;
|
2011-01-30 07:14:08 +00:00
|
|
|
gint index, x_layout, y_layout;
|
2011-06-25 18:43:59 +00:00
|
|
|
gint x_local, y_local;
|
2012-08-10 16:04:57 +00:00
|
|
|
glong offset;
|
2010-05-22 23:55:33 +00:00
|
|
|
|
2019-02-22 20:49:47 +00:00
|
|
|
textw = get_text (atk_text);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2019-02-22 20:49:47 +00:00
|
|
|
if (textw == NULL)
|
|
|
|
return 1;
|
2011-06-25 18:43:59 +00:00
|
|
|
|
2019-02-16 05:50:12 +00:00
|
|
|
gtk_text_get_layout_offsets (textw, &x_layout, &y_layout);
|
2011-06-25 18:43:59 +00:00
|
|
|
|
2019-03-23 05:59:47 +00:00
|
|
|
x_local = x - x_layout;
|
|
|
|
y_local = y - y_layout;
|
2011-06-25 18:43:59 +00:00
|
|
|
|
2019-02-16 05:50:12 +00:00
|
|
|
if (!pango_layout_xy_to_index (gtk_text_get_layout (textw),
|
2011-06-25 18:43:59 +00:00
|
|
|
x_local * PANGO_SCALE,
|
|
|
|
y_local * PANGO_SCALE,
|
|
|
|
&index, NULL))
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-25 18:43:59 +00:00
|
|
|
if (x_local < 0 || y_local < 0)
|
|
|
|
index = 0;
|
|
|
|
else
|
|
|
|
index = -1;
|
|
|
|
}
|
2010-10-20 17:22:46 +00:00
|
|
|
|
2012-08-10 16:04:57 +00:00
|
|
|
offset = -1;
|
2011-06-25 18:43:59 +00:00
|
|
|
if (index != -1)
|
|
|
|
{
|
2019-02-16 05:50:12 +00:00
|
|
|
text = gtk_text_get_display_text (textw, 0, -1);
|
2012-08-10 16:04:57 +00:00
|
|
|
offset = g_utf8_pointer_to_offset (text, text + index);
|
|
|
|
g_free (text);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
2011-06-25 18:43:59 +00:00
|
|
|
|
2012-08-10 16:04:57 +00:00
|
|
|
return offset;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
2011-06-25 18:43:59 +00:00
|
|
|
gtk_entry_accessible_get_n_selections (AtkText *text)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
2011-06-25 18:43:59 +00:00
|
|
|
gint start, end;
|
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 18:43:59 +00:00
|
|
|
return 0;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-25 18:43:59 +00:00
|
|
|
if (gtk_editable_get_selection_bounds (GTK_EDITABLE (widget), &start, &end))
|
2007-12-18 13:51:12 +00:00
|
|
|
return 1;
|
2011-06-25 18:43:59 +00:00
|
|
|
|
|
|
|
return 0;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
2011-06-25 18:43:59 +00:00
|
|
|
static gchar *
|
2011-06-25 02:12:55 +00:00
|
|
|
gtk_entry_accessible_get_selection (AtkText *text,
|
2011-06-25 18:43:59 +00:00
|
|
|
gint selection_num,
|
|
|
|
gint *start_pos,
|
|
|
|
gint *end_pos)
|
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;
|
|
|
|
|
|
|
|
if (selection_num != 0)
|
|
|
|
return NULL;
|
|
|
|
|
2011-06-25 18:43:59 +00:00
|
|
|
if (gtk_editable_get_selection_bounds (GTK_EDITABLE (widget), start_pos, end_pos))
|
|
|
|
return gtk_editable_get_chars (GTK_EDITABLE (widget), *start_pos, *end_pos);
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-25 18:43:59 +00:00
|
|
|
return NULL;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-06-25 02:12:55 +00:00
|
|
|
gtk_entry_accessible_add_selection (AtkText *text,
|
2011-06-25 18:43:59 +00:00
|
|
|
gint start_pos,
|
|
|
|
gint end_pos)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkEntry *entry;
|
|
|
|
GtkWidget *widget;
|
2011-06-25 18:43:59 +00:00
|
|
|
gint start, end;
|
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 FALSE;
|
|
|
|
|
|
|
|
entry = GTK_ENTRY (widget);
|
|
|
|
|
2011-06-25 18:43:59 +00:00
|
|
|
if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-25 18:43:59 +00:00
|
|
|
gtk_editable_select_region (GTK_EDITABLE (entry), start_pos, end_pos);
|
|
|
|
return TRUE;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
else
|
2011-06-25 18:43:59 +00:00
|
|
|
return FALSE;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-06-25 02:12:55 +00:00
|
|
|
gtk_entry_accessible_remove_selection (AtkText *text,
|
2011-06-25 18:43:59 +00:00
|
|
|
gint selection_num)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
2011-06-26 02:44:07 +00:00
|
|
|
gint start, end;
|
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 FALSE;
|
|
|
|
|
|
|
|
if (selection_num != 0)
|
|
|
|
return FALSE;
|
|
|
|
|
2011-06-25 18:43:59 +00:00
|
|
|
if (gtk_editable_get_selection_bounds (GTK_EDITABLE (widget), &start, &end))
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-26 02:44:07 +00:00
|
|
|
gtk_editable_select_region (GTK_EDITABLE (widget), end, end);
|
2007-12-18 13:51:12 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-06-25 02:12:55 +00:00
|
|
|
gtk_entry_accessible_set_selection (AtkText *text,
|
2011-06-25 18:43:59 +00:00
|
|
|
gint selection_num,
|
|
|
|
gint start_pos,
|
|
|
|
gint end_pos)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
2011-06-25 18:43:59 +00:00
|
|
|
gint start, end;
|
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 FALSE;
|
|
|
|
|
|
|
|
if (selection_num != 0)
|
|
|
|
return FALSE;
|
|
|
|
|
2011-06-25 18:43:59 +00:00
|
|
|
if (gtk_editable_get_selection_bounds (GTK_EDITABLE (widget), &start, &end))
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-25 18:43:59 +00:00
|
|
|
gtk_editable_select_region (GTK_EDITABLE (widget), start_pos, end_pos);
|
2007-12-18 13:51:12 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-06-25 18:43:59 +00:00
|
|
|
static gunichar
|
|
|
|
gtk_entry_accessible_get_character_at_offset (AtkText *atk_text,
|
|
|
|
gint offset)
|
|
|
|
{
|
2019-02-22 20:49:47 +00:00
|
|
|
GtkText *textw;
|
2012-08-10 16:04:57 +00:00
|
|
|
gchar *text;
|
2011-06-25 18:43:59 +00:00
|
|
|
gchar *index;
|
2012-08-10 16:04:57 +00:00
|
|
|
gunichar result;
|
|
|
|
|
|
|
|
result = '\0';
|
2011-06-25 18:43:59 +00:00
|
|
|
|
2019-02-22 20:49:47 +00:00
|
|
|
textw = get_text (atk_text);
|
|
|
|
|
|
|
|
if (textw == NULL)
|
|
|
|
return 0;
|
2011-06-25 18:43:59 +00:00
|
|
|
|
2019-02-22 20:49:47 +00:00
|
|
|
if (!gtk_text_get_visibility (textw))
|
2012-08-10 16:04:57 +00:00
|
|
|
return result;
|
2011-06-25 18:43:59 +00:00
|
|
|
|
2019-02-22 20:49:47 +00:00
|
|
|
text = gtk_text_get_display_text (textw, 0, -1);
|
2012-08-10 16:04:57 +00:00
|
|
|
if (offset < g_utf8_strlen (text, -1))
|
|
|
|
{
|
|
|
|
index = g_utf8_offset_to_pointer (text, offset);
|
|
|
|
result = g_utf8_get_char (index);
|
|
|
|
g_free (text);
|
|
|
|
}
|
2011-06-25 18:43:59 +00:00
|
|
|
|
2012-08-10 16:04:57 +00:00
|
|
|
return result;
|
2011-06-25 18:43:59 +00:00
|
|
|
}
|
|
|
|
|
2007-12-18 13:51:12 +00:00
|
|
|
static void
|
2011-06-25 18:43:59 +00:00
|
|
|
atk_text_interface_init (AtkTextIface *iface)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-25 18:43:59 +00:00
|
|
|
iface->get_text = gtk_entry_accessible_get_text;
|
|
|
|
iface->get_character_at_offset = gtk_entry_accessible_get_character_at_offset;
|
|
|
|
iface->get_text_before_offset = gtk_entry_accessible_get_text_before_offset;
|
|
|
|
iface->get_text_at_offset = gtk_entry_accessible_get_text_at_offset;
|
|
|
|
iface->get_text_after_offset = gtk_entry_accessible_get_text_after_offset;
|
|
|
|
iface->get_caret_offset = gtk_entry_accessible_get_caret_offset;
|
|
|
|
iface->set_caret_offset = gtk_entry_accessible_set_caret_offset;
|
|
|
|
iface->get_character_count = gtk_entry_accessible_get_character_count;
|
|
|
|
iface->get_n_selections = gtk_entry_accessible_get_n_selections;
|
|
|
|
iface->get_selection = gtk_entry_accessible_get_selection;
|
|
|
|
iface->add_selection = gtk_entry_accessible_add_selection;
|
|
|
|
iface->remove_selection = gtk_entry_accessible_remove_selection;
|
|
|
|
iface->set_selection = gtk_entry_accessible_set_selection;
|
|
|
|
iface->get_run_attributes = gtk_entry_accessible_get_run_attributes;
|
|
|
|
iface->get_default_attributes = gtk_entry_accessible_get_default_attributes;
|
|
|
|
iface->get_character_extents = gtk_entry_accessible_get_character_extents;
|
|
|
|
iface->get_offset_at_point = gtk_entry_accessible_get_offset_at_point;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-06-25 02:12:55 +00:00
|
|
|
gtk_entry_accessible_set_text_contents (AtkEditableText *text,
|
2011-06-25 18:43:59 +00:00
|
|
|
const gchar *string)
|
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;
|
|
|
|
|
2011-06-25 18:43:59 +00:00
|
|
|
if (!gtk_editable_get_editable (GTK_EDITABLE (widget)))
|
2007-12-18 13:51:12 +00:00
|
|
|
return;
|
|
|
|
|
2019-02-22 20:49:47 +00:00
|
|
|
gtk_editable_set_text (GTK_EDITABLE (widget), string);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-06-25 02:12:55 +00:00
|
|
|
gtk_entry_accessible_insert_text (AtkEditableText *text,
|
2011-06-25 18:43:59 +00:00
|
|
|
const gchar *string,
|
|
|
|
gint length,
|
|
|
|
gint *position)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
GtkEditable *editable;
|
|
|
|
|
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;
|
|
|
|
|
2011-06-25 18:43:59 +00:00
|
|
|
editable = GTK_EDITABLE (widget);
|
2007-12-18 13:51:12 +00:00
|
|
|
if (!gtk_editable_get_editable (editable))
|
|
|
|
return;
|
|
|
|
|
|
|
|
gtk_editable_insert_text (editable, string, length, position);
|
2010-01-29 06:16:24 +00:00
|
|
|
gtk_editable_set_position (editable, *position);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-06-25 18:43:59 +00:00
|
|
|
gtk_entry_accessible_copy_text (AtkEditableText *text,
|
|
|
|
gint start_pos,
|
|
|
|
gint end_pos)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
GtkEditable *editable;
|
|
|
|
gchar *str;
|
2017-11-26 06:35:19 +00:00
|
|
|
GdkClipboard *clipboard;
|
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;
|
|
|
|
|
2011-06-25 18:43:59 +00:00
|
|
|
editable = GTK_EDITABLE (widget);
|
2007-12-18 13:51:12 +00:00
|
|
|
str = gtk_editable_get_chars (editable, start_pos, end_pos);
|
2017-11-26 06:35:19 +00:00
|
|
|
clipboard = gtk_widget_get_clipboard (widget);
|
|
|
|
gdk_clipboard_set_text (clipboard, str);
|
2011-06-25 18:43:59 +00:00
|
|
|
g_free (str);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-06-25 02:12:55 +00:00
|
|
|
gtk_entry_accessible_cut_text (AtkEditableText *text,
|
2011-06-25 18:43:59 +00:00
|
|
|
gint start_pos,
|
|
|
|
gint end_pos)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
GtkEditable *editable;
|
|
|
|
gchar *str;
|
2017-11-26 06:35:19 +00:00
|
|
|
GdkClipboard *clipboard;
|
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;
|
|
|
|
|
2011-06-25 18:43:59 +00:00
|
|
|
editable = GTK_EDITABLE (widget);
|
2007-12-18 13:51:12 +00:00
|
|
|
if (!gtk_editable_get_editable (editable))
|
|
|
|
return;
|
2011-06-25 18:43:59 +00:00
|
|
|
|
2007-12-18 13:51:12 +00:00
|
|
|
str = gtk_editable_get_chars (editable, start_pos, end_pos);
|
2017-11-26 06:35:19 +00:00
|
|
|
clipboard = gtk_widget_get_clipboard (widget);
|
|
|
|
gdk_clipboard_set_text (clipboard, str);
|
2007-12-18 13:51:12 +00:00
|
|
|
gtk_editable_delete_text (editable, start_pos, end_pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-06-25 02:12:55 +00:00
|
|
|
gtk_entry_accessible_delete_text (AtkEditableText *text,
|
2011-06-25 18:43:59 +00:00
|
|
|
gint start_pos,
|
|
|
|
gint end_pos)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
GtkEditable *editable;
|
|
|
|
|
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;
|
|
|
|
|
2011-06-25 18:43:59 +00:00
|
|
|
editable = GTK_EDITABLE (widget);
|
2007-12-18 13:51:12 +00:00
|
|
|
if (!gtk_editable_get_editable (editable))
|
|
|
|
return;
|
|
|
|
|
|
|
|
gtk_editable_delete_text (editable, start_pos, end_pos);
|
|
|
|
}
|
|
|
|
|
2011-06-26 01:53:00 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GtkEntry* entry;
|
|
|
|
gint position;
|
|
|
|
} PasteData;
|
|
|
|
|
2011-06-25 18:43:59 +00:00
|
|
|
static void
|
2017-11-26 06:35:19 +00:00
|
|
|
paste_received_cb (GObject *clipboard,
|
|
|
|
GAsyncResult *result,
|
2011-06-26 01:53:00 +00:00
|
|
|
gpointer data)
|
2011-06-25 18:43:59 +00:00
|
|
|
{
|
2011-06-26 01:53:00 +00:00
|
|
|
PasteData *paste = data;
|
2017-11-26 06:35:19 +00:00
|
|
|
char *text;
|
2011-06-25 18:43:59 +00:00
|
|
|
|
2017-11-26 06:35:19 +00:00
|
|
|
text = gdk_clipboard_read_text_finish (GDK_CLIPBOARD (clipboard), result, NULL);
|
2011-06-25 18:43:59 +00:00
|
|
|
if (text)
|
|
|
|
gtk_editable_insert_text (GTK_EDITABLE (paste->entry), text, -1,
|
|
|
|
&paste->position);
|
|
|
|
|
|
|
|
g_object_unref (paste->entry);
|
|
|
|
g_free (paste);
|
2017-11-26 06:35:19 +00:00
|
|
|
g_free (text);
|
2011-06-25 18:43:59 +00:00
|
|
|
}
|
|
|
|
|
2007-12-18 13:51:12 +00:00
|
|
|
static void
|
2011-06-25 02:12:55 +00:00
|
|
|
gtk_entry_accessible_paste_text (AtkEditableText *text,
|
2011-06-25 18:43:59 +00:00
|
|
|
gint position)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
GtkEditable *editable;
|
2011-06-26 01:53:00 +00:00
|
|
|
PasteData *paste;
|
2017-11-26 06:35:19 +00:00
|
|
|
GdkClipboard *clipboard;
|
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 18:43:59 +00:00
|
|
|
return;
|
|
|
|
|
2007-12-18 13:51:12 +00:00
|
|
|
editable = GTK_EDITABLE (widget);
|
|
|
|
if (!gtk_editable_get_editable (editable))
|
|
|
|
return;
|
2011-06-25 18:43:59 +00:00
|
|
|
|
2011-06-26 01:53:00 +00:00
|
|
|
paste = g_new0 (PasteData, 1);
|
2011-06-25 18:43:59 +00:00
|
|
|
paste->entry = GTK_ENTRY (widget);
|
|
|
|
paste->position = position;
|
|
|
|
|
|
|
|
g_object_ref (paste->entry);
|
2017-11-26 06:35:19 +00:00
|
|
|
clipboard = gtk_widget_get_clipboard (widget);
|
|
|
|
gdk_clipboard_read_text_async (clipboard, NULL, paste_received_cb, paste);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-06-25 18:43:59 +00:00
|
|
|
atk_editable_text_interface_init (AtkEditableTextIface *iface)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-25 18:43:59 +00:00
|
|
|
iface->set_text_contents = gtk_entry_accessible_set_text_contents;
|
|
|
|
iface->insert_text = gtk_entry_accessible_insert_text;
|
|
|
|
iface->copy_text = gtk_entry_accessible_copy_text;
|
|
|
|
iface->cut_text = gtk_entry_accessible_cut_text;
|
|
|
|
iface->delete_text = gtk_entry_accessible_delete_text;
|
|
|
|
iface->paste_text = gtk_entry_accessible_paste_text;
|
|
|
|
iface->set_run_attributes = NULL;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-06-26 01:53:00 +00:00
|
|
|
insert_text_cb (GtkEditable *editable,
|
|
|
|
gchar *new_text,
|
|
|
|
gint new_text_length,
|
|
|
|
gint *position)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-26 01:00:02 +00:00
|
|
|
GtkEntryAccessible *accessible;
|
2014-06-09 22:31:19 +00:00
|
|
|
gint length;
|
2010-05-27 06:57:38 +00:00
|
|
|
|
2011-06-26 01:00:02 +00:00
|
|
|
if (new_text_length == 0)
|
2010-05-27 06:57:38 +00:00
|
|
|
return;
|
|
|
|
|
2011-06-26 01:53:00 +00:00
|
|
|
accessible = GTK_ENTRY_ACCESSIBLE (gtk_widget_get_accessible (GTK_WIDGET (editable)));
|
2014-06-09 22:31:19 +00:00
|
|
|
length = g_utf8_strlen (new_text, new_text_length);
|
2011-12-19 15:15:52 +00:00
|
|
|
|
|
|
|
g_signal_emit_by_name (accessible,
|
|
|
|
"text-changed::insert",
|
2014-06-09 22:31:19 +00:00
|
|
|
*position - length,
|
|
|
|
length);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
2011-06-26 01:00:02 +00:00
|
|
|
/* We connect to GtkEditable::delete-text, since it carries
|
|
|
|
* the information we need. But we delay emitting our own
|
|
|
|
* text_changed::delete signal until the entry has update
|
|
|
|
* all its internal state and emits GtkEntry::changed.
|
2007-12-18 13:51:12 +00:00
|
|
|
*/
|
2011-06-25 18:43:59 +00:00
|
|
|
static void
|
2011-06-26 01:53:00 +00:00
|
|
|
delete_text_cb (GtkEditable *editable,
|
|
|
|
gint start,
|
|
|
|
gint end)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-26 01:00:02 +00:00
|
|
|
GtkEntryAccessible *accessible;
|
2019-02-22 20:49:47 +00:00
|
|
|
GtkText *textw;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-12-19 15:15:52 +00:00
|
|
|
accessible = GTK_ENTRY_ACCESSIBLE (gtk_widget_get_accessible (GTK_WIDGET (editable)));
|
|
|
|
|
2019-02-22 20:49:47 +00:00
|
|
|
textw = get_text (ATK_TEXT (accessible));
|
|
|
|
if (textw == NULL)
|
|
|
|
return;
|
|
|
|
|
2011-06-26 01:00:02 +00:00
|
|
|
if (end < 0)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2012-08-10 16:04:57 +00:00
|
|
|
gchar *text;
|
2011-06-26 01:00:02 +00:00
|
|
|
|
2019-02-22 20:49:47 +00:00
|
|
|
text = gtk_text_get_display_text (textw, 0, -1);
|
2011-06-26 01:00:02 +00:00
|
|
|
end = g_utf8_strlen (text, -1);
|
2012-08-10 16:04:57 +00:00
|
|
|
g_free (text);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
2011-06-26 01:00:02 +00:00
|
|
|
if (end == start)
|
|
|
|
return;
|
|
|
|
|
2011-12-19 15:15:52 +00:00
|
|
|
g_signal_emit_by_name (accessible,
|
|
|
|
"text-changed::delete",
|
|
|
|
start,
|
2018-04-04 15:56:38 +00:00
|
|
|
end - start);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
2011-06-25 18:43:59 +00:00
|
|
|
static gboolean
|
2011-06-26 01:53:00 +00:00
|
|
|
check_for_selection_change (GtkEntryAccessible *accessible,
|
2019-03-13 21:44:01 +00:00
|
|
|
GtkEditable *editable)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-26 01:53:00 +00:00
|
|
|
gboolean ret_val = FALSE;
|
|
|
|
gint start, end;
|
2010-10-20 17:22:46 +00:00
|
|
|
|
2019-03-13 21:44:01 +00:00
|
|
|
if (gtk_editable_get_selection_bounds (editable, &start, &end))
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2012-10-14 19:59:58 +00:00
|
|
|
if (end != accessible->priv->cursor_position ||
|
|
|
|
start != accessible->priv->selection_bound)
|
2007-12-18 13:51:12 +00:00
|
|
|
/*
|
|
|
|
* This check is here as this function can be called
|
|
|
|
* for notification of selection_bound and current_pos.
|
2011-06-25 18:43:59 +00:00
|
|
|
* The values of current_pos and selection_bound may be the same
|
2007-12-18 13:51:12 +00:00
|
|
|
* for both notifications and we only want to generate one
|
|
|
|
* text_selection_changed signal.
|
|
|
|
*/
|
|
|
|
ret_val = TRUE;
|
|
|
|
}
|
2011-06-25 18:43:59 +00:00
|
|
|
else
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
/* We had a selection */
|
2012-10-14 19:59:58 +00:00
|
|
|
ret_val = (accessible->priv->cursor_position != accessible->priv->selection_bound);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
2011-06-26 01:53:00 +00:00
|
|
|
|
2012-10-14 19:59:58 +00:00
|
|
|
accessible->priv->cursor_position = end;
|
|
|
|
accessible->priv->selection_bound = start;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
|
|
|
return ret_val;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-06-25 02:12:55 +00:00
|
|
|
gtk_entry_accessible_do_action (AtkAction *action,
|
2011-06-26 01:26:51 +00:00
|
|
|
gint i)
|
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 (action));
|
2007-12-18 13:51:12 +00:00
|
|
|
if (widget == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
2010-03-01 06:47:38 +00:00
|
|
|
if (!gtk_widget_get_sensitive (widget) || !gtk_widget_get_visible (widget))
|
2007-12-18 13:51:12 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2011-06-26 01:26:51 +00:00
|
|
|
if (i != 0)
|
|
|
|
return FALSE;
|
|
|
|
|
2011-07-05 12:30:49 +00:00
|
|
|
gtk_widget_activate (widget);
|
2011-06-26 01:26:51 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
2011-06-25 02:12:55 +00:00
|
|
|
gtk_entry_accessible_get_n_actions (AtkAction *action)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-06-26 01:26:51 +00:00
|
|
|
static const gchar *
|
2011-06-25 02:12:55 +00:00
|
|
|
gtk_entry_accessible_get_keybinding (AtkAction *action,
|
2011-06-26 01:26:51 +00:00
|
|
|
gint i)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-26 01:26:51 +00:00
|
|
|
GtkWidget *widget;
|
|
|
|
GtkWidget *label;
|
|
|
|
AtkRelationSet *set;
|
|
|
|
AtkRelation *relation;
|
|
|
|
GPtrArray *target;
|
|
|
|
gpointer target_object;
|
|
|
|
guint key_val;
|
|
|
|
|
|
|
|
if (i != 0)
|
|
|
|
return NULL;
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2011-06-26 01:26:51 +00:00
|
|
|
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (action));
|
|
|
|
if (widget == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
set = atk_object_ref_relation_set (ATK_OBJECT (action));
|
|
|
|
if (!set)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
label = NULL;
|
|
|
|
relation = atk_relation_set_get_relation_by_type (set, ATK_RELATION_LABELLED_BY);
|
|
|
|
if (relation)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2011-06-26 01:26:51 +00:00
|
|
|
target = atk_relation_get_target (relation);
|
|
|
|
|
|
|
|
target_object = g_ptr_array_index (target, 0);
|
|
|
|
label = gtk_accessible_get_widget (GTK_ACCESSIBLE (target_object));
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (set);
|
|
|
|
|
|
|
|
if (GTK_IS_LABEL (label))
|
|
|
|
{
|
|
|
|
key_val = gtk_label_get_mnemonic_keyval (GTK_LABEL (label));
|
|
|
|
if (key_val != GDK_KEY_VoidSymbol)
|
2020-04-05 13:39:03 +00:00
|
|
|
return gtk_accelerator_name (key_val, GDK_ALT_MASK);
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
2011-06-26 01:26:51 +00:00
|
|
|
|
|
|
|
return NULL;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|
|
|
|
|
2011-06-06 18:02:06 +00:00
|
|
|
static const gchar*
|
2011-06-25 02:12:55 +00:00
|
|
|
gtk_entry_accessible_action_get_name (AtkAction *action,
|
2011-06-26 01:26:51 +00:00
|
|
|
gint i)
|
2007-12-18 13:51:12 +00:00
|
|
|
{
|
2013-02-04 05:53:48 +00:00
|
|
|
if (i == 0)
|
|
|
|
return "activate";
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-12-18 13:51:12 +00:00
|
|
|
|
2013-02-04 05:53:48 +00:00
|
|
|
static const gchar*
|
|
|
|
gtk_entry_accessible_action_get_localized_name (AtkAction *action,
|
|
|
|
gint i)
|
|
|
|
{
|
|
|
|
if (i == 0)
|
|
|
|
return C_("Action name", "Activate");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const gchar*
|
|
|
|
gtk_entry_accessible_action_get_description (AtkAction *action,
|
|
|
|
gint i)
|
|
|
|
{
|
|
|
|
if (i == 0)
|
|
|
|
return C_("Action description", "Activates the entry");
|
|
|
|
return NULL;
|
2011-06-26 01:26:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
atk_action_interface_init (AtkActionIface *iface)
|
|
|
|
{
|
|
|
|
iface->do_action = gtk_entry_accessible_do_action;
|
|
|
|
iface->get_n_actions = gtk_entry_accessible_get_n_actions;
|
|
|
|
iface->get_keybinding = gtk_entry_accessible_get_keybinding;
|
|
|
|
iface->get_name = gtk_entry_accessible_action_get_name;
|
2013-02-04 05:53:48 +00:00
|
|
|
iface->get_localized_name = gtk_entry_accessible_action_get_localized_name;
|
|
|
|
iface->get_description = gtk_entry_accessible_action_get_description;
|
2007-12-18 13:51:12 +00:00
|
|
|
}
|