summaryrefslogtreecommitdiff
path: root/libview
diff options
context:
space:
mode:
authorraveit65 <[email protected]>2017-03-05 19:52:47 +0100
committerraveit65 <[email protected]>2017-03-07 13:34:19 +0100
commit3a4d8e93f2293357ec5e887000c54ddbdcc48afe (patch)
tree9653eb54d55b21757514896b379e68cc23e8a6a9 /libview
parent5db08321cfc0edfc2bf374c753a83707f2d7e129 (diff)
downloadatril-3a4d8e93f2293357ec5e887000c54ddbdcc48afe.tar.bz2
atril-3a4d8e93f2293357ec5e887000c54ddbdcc48afe.tar.xz
ev-view-accessible: Add helper function to get text before, at or after offset
To avoid duplicated code. Taken from: https://git.gnome.org/browse/evince/commit/?h=gnome-3-8&id=0897a7d
Diffstat (limited to 'libview')
-rw-r--r--libview/ev-view-accessible.c162
1 files changed, 68 insertions, 94 deletions
diff --git a/libview/ev-view-accessible.c b/libview/ev-view-accessible.c
index e7feda22..588d8646 100644
--- a/libview/ev-view-accessible.c
+++ b/libview/ev-view-accessible.c
@@ -209,100 +209,74 @@ ev_view_accessible_get_character_at_offset (AtkText *text,
return unichar;
}
-static gchar*
-ev_view_accessible_get_text_before_offset (AtkText *text,
- gint offset,
- AtkTextBoundary boundary_type,
- gint *start_offset,
- gint *end_offset)
-{
- GtkWidget *widget;
- gpointer layout = NULL;
- GailTextUtil *gail_text = NULL;
- gchar *retval = NULL;
- GtkTextBuffer *buffer;
-
- widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
- if (widget == NULL)
- /* State is defunct */
- return NULL;
-
- buffer = ev_view_accessible_get_text_buffer (EV_VIEW_ACCESSIBLE (text), EV_VIEW (widget));
- if (!buffer)
- return NULL;
-
- gail_text = gail_text_util_new ();
- gail_text_util_buffer_setup (gail_text, buffer);
- retval = gail_text_util_get_text (gail_text, layout,
- GAIL_BEFORE_OFFSET, boundary_type,
- offset, start_offset, end_offset);
- g_object_unref (gail_text);
-
- return retval;
-}
-
-static gchar*
-ev_view_accessible_get_text_at_offset (AtkText *text,
- gint offset,
- AtkTextBoundary boundary_type,
- gint *start_offset,
- gint *end_offset)
-{
- GtkWidget *widget;
- gpointer layout = NULL;
- GailTextUtil *gail_text = NULL;
- gchar *retval = NULL;
- GtkTextBuffer *buffer;
-
- widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
- if (widget == NULL)
- /* State is defunct */
- return NULL;
-
- buffer = ev_view_accessible_get_text_buffer (EV_VIEW_ACCESSIBLE (text), EV_VIEW (widget));
- if (!buffer)
- return NULL;
-
- gail_text = gail_text_util_new ();
- gail_text_util_buffer_setup (gail_text, buffer);
- retval = gail_text_util_get_text (gail_text, layout,
- GAIL_AT_OFFSET, boundary_type,
- offset, start_offset, end_offset);
- g_object_unref (gail_text);
-
- return retval;
-}
-
-static gchar*
-ev_view_accessible_get_text_after_offset (AtkText *text,
- gint offset,
- AtkTextBoundary boundary_type,
- gint *start_offset,
- gint *end_offset)
-{
- GtkWidget *widget;
- gpointer layout = NULL;
- GailTextUtil *gail_text = NULL;
- gchar *retval = NULL;
- GtkTextBuffer *buffer;
-
- widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
- if (widget == NULL)
- /* State is defunct */
- return NULL;
-
- buffer = ev_view_accessible_get_text_buffer (EV_VIEW_ACCESSIBLE (text), EV_VIEW (widget));
- if (!buffer)
- return NULL;
-
- gail_text = gail_text_util_new ();
- gail_text_util_buffer_setup (gail_text, buffer);
- retval = gail_text_util_get_text (gail_text, layout,
- GAIL_AFTER_OFFSET, boundary_type,
- offset, start_offset, end_offset);
- g_object_unref (gail_text);
-
- return retval;
+static gchar *
+ev_view_accessible_get_text_for_offset (EvViewAccessible *view_accessible,
+ gint offset,
+ GailOffsetType offset_type,
+ AtkTextBoundary boundary_type,
+ gint *start_offset,
+ gint *end_offset)
+{
+ GtkWidget *widget;
+ GtkTextBuffer *buffer;
+ GailTextUtil *gail_text;
+ gchar *retval;
+
+ widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (view_accessible));
+ if (widget == NULL)
+ /* State is defunct */
+ return NULL;
+
+ buffer = ev_view_accessible_get_text_buffer (view_accessible, EV_VIEW (widget));
+ if (!buffer)
+ return NULL;
+
+ gail_text = gail_text_util_new ();
+ gail_text_util_buffer_setup (gail_text, buffer);
+ retval = gail_text_util_get_text (gail_text, NULL, offset_type, boundary_type,
+ offset, start_offset, end_offset);
+ g_object_unref (gail_text);
+
+ return retval;
+}
+
+static gchar *
+ev_view_accessible_get_text_before_offset (AtkText *text,
+ gint offset,
+ AtkTextBoundary boundary_type,
+ gint *start_offset,
+ gint *end_offset)
+{
+ return ev_view_accessible_get_text_for_offset (EV_VIEW_ACCESSIBLE (text),
+ offset, GAIL_BEFORE_OFFSET,
+ boundary_type,
+ start_offset, end_offset);
+}
+
+static gchar *
+ev_view_accessible_get_text_at_offset (AtkText *text,
+ gint offset,
+ AtkTextBoundary boundary_type,
+ gint *start_offset,
+ gint *end_offset)
+{
+ return ev_view_accessible_get_text_for_offset (EV_VIEW_ACCESSIBLE (text),
+ offset, GAIL_AT_OFFSET,
+ boundary_type,
+ start_offset, end_offset);
+}
+
+static gchar *
+ev_view_accessible_get_text_after_offset (AtkText *text,
+ gint offset,
+ AtkTextBoundary boundary_type,
+ gint *start_offset,
+ gint *end_offset)
+{
+ return ev_view_accessible_get_text_for_offset (EV_VIEW_ACCESSIBLE (text),
+ offset, GAIL_AFTER_OFFSET,
+ boundary_type,
+ start_offset, end_offset);
}
static gint