[vte/vte-next: 191/223] Add get_selection_bounds



commit 82685bb43e711d34a8ad9e4f4375a8e80a988c54
Author: Christian Persch <chpe gnome org>
Date:   Tue Jun 14 20:29:34 2011 +0200

    Add get_selection_bounds
    
    Bug #617607.

 doc/reference/vte-sections.txt |    1 +
 src/vte-private.h              |    6 +++-
 src/vte.c                      |   67 ++++++++++++++++++++++++++++++++++++++++
 src/vte.h                      |    3 ++
 src/vteaccess.c                |    8 +++-
 5 files changed, 82 insertions(+), 3 deletions(-)
---
diff --git a/doc/reference/vte-sections.txt b/doc/reference/vte-sections.txt
index cc754ec..8c0267a 100644
--- a/doc/reference/vte-sections.txt
+++ b/doc/reference/vte-sections.txt
@@ -25,6 +25,7 @@ vte_terminal_get_visible_bell
 vte_terminal_set_scroll_on_output
 vte_terminal_set_scroll_on_keystroke
 vte_terminal_get_has_selection
+vte_terminal_get_selection_bounds
 vte_terminal_set_word_chars
 vte_terminal_set_mouse_autohide
 vte_terminal_get_mouse_autohide
diff --git a/src/vte-private.h b/src/vte-private.h
index 0350c60..55c967b 100644
--- a/src/vte-private.h
+++ b/src/vte-private.h
@@ -149,7 +149,7 @@ typedef struct _VteVisualPosition {
 
 typedef struct _VteBufferIterReal VteBufferIterReal;
 struct _VteBufferIterReal {
-        VteVisualPosition pos;
+        VteVisualPosition position;
         VteBuffer *buffer;
 };
 G_STATIC_ASSERT(sizeof(VteBufferIterReal) <= sizeof(VteBufferIter));
@@ -504,6 +504,10 @@ void _vte_buffer_view_invalidate_cells(VteBuffer *buffer,
 void _vte_buffer_view_scroll_region(VteBuffer *buffer,
                                     glong row, glong count, glong delta);
 
+/* private VteBufferIter methods */
+void _vte_buffer_iter_init(VteBufferIterReal *iter, VteBuffer *buffer);
+void _vte_buffer_iter_get_position(VteBufferIter *iter, glong *row, glong *column);
+
 /* private VteScreen methods */
 void _vte_screen_set_default_attributes(VteScreen *screen);
 
diff --git a/src/vte.c b/src/vte.c
index 0363648..b124d4a 100644
--- a/src/vte.c
+++ b/src/vte.c
@@ -11810,6 +11810,48 @@ vte_terminal_get_has_selection(VteTerminal *terminal)
 	return terminal->pvt->has_selection;
 }
 
+/**
+ * vte_terminal_get_selection_bounds:
+ * @terminal: a #VteTerminal
+ * @start: (allow-none): a #VteBufferIter, or %NULL
+ * @end: (allow-none): a #VteBufferIter, or %NULL
+ *
+ * Returns whether text is selected in a @terminal. If @start or @end
+ * are non-%NULL, they are filled in with the start resp. end of the selection.
+ *
+ * Returns: %TRUE if there is text selected in @terminal
+ */ 
+gboolean
+vte_terminal_get_selection_bounds(VteTerminal *terminal,
+                                  VteBufferIter *start,
+                                  VteBufferIter *end)
+{
+        VteTerminalRealPrivate *pvt;
+        VteBufferIterReal *real_start, *real_end;
+
+        g_return_val_if_fail(VTE_IS_TERMINAL(terminal), FALSE);
+
+        pvt = terminal->term_pvt;
+        if (pvt->buffer == NULL)
+                return FALSE;
+
+        if (!terminal->pvt->has_selection)
+                return FALSE;
+
+        if (start) {
+                real_start = (VteBufferIterReal *) start;
+                _vte_buffer_iter_init(real_start, pvt->buffer);
+                real_start->position = terminal->pvt->selection_start;
+        }
+        if (end) {
+                real_end = (VteBufferIterReal *) end;
+                _vte_buffer_iter_init(real_end, pvt->buffer);
+                real_end->position = terminal->pvt->selection_end;
+        }
+
+        return TRUE;
+}
+
 static void
 vte_terminal_set_cursor_blinks_internal(VteTerminal *terminal, gboolean blink)
 {
@@ -14157,6 +14199,31 @@ G_DEFINE_BOXED_TYPE(VteBufferIter, vte_buffer_iter,
                     vte_buffer_iter_copy,
                     vte_buffer_iter_free);
 
+void
+_vte_buffer_iter_init(VteBufferIterReal *real_iter,
+                      VteBuffer *buffer)
+{
+        g_return_if_fail(real_iter != NULL);
+
+        real_iter->buffer = buffer;
+        memset(&real_iter->position, 0, sizeof(real_iter->position));
+}
+
+void
+_vte_buffer_iter_get_position(VteBufferIter *iter,
+                              glong *row,
+                              glong *column)
+{
+        VteBufferIterReal *real_iter = (VteBufferIterReal *) iter;
+
+        g_return_if_fail(iter != NULL);
+
+        if (row)
+                *row = real_iter->position.row;
+        if (column)
+                *column = real_iter->position.col;
+}
+
 /**
  * vte_buffer_iter_copy:
  * @iter: a #VteBufferIter
diff --git a/src/vte.h b/src/vte.h
index 9d6a449..4d815a9 100644
--- a/src/vte.h
+++ b/src/vte.h
@@ -142,6 +142,9 @@ void vte_terminal_im_append_menuitems(VteTerminal *terminal,
 
 /* Check if the terminal is the current selection owner. */
 gboolean vte_terminal_get_has_selection(VteTerminal *terminal);
+gboolean vte_terminal_get_selection_bounds(VteTerminal *terminal,
+                                           VteBufferIter *start,
+                                           VteBufferIter *end);
 
 /* Set the list of word chars, optionally using hyphens to specify ranges
  * (to get a hyphen, place it first), and check if a character is in the
diff --git a/src/vteaccess.c b/src/vteaccess.c
index 1d7c49a..48c5e9e 100644
--- a/src/vteaccess.c
+++ b/src/vteaccess.c
@@ -1521,6 +1521,7 @@ vte_terminal_accessible_get_selection(AtkText *text, gint selection_number,
 	GtkWidget *widget;
 	VteTerminal *terminal;
 	VteTerminalAccessiblePrivate *priv;
+        VteBufferIter start, end;
 	long start_x, start_y, end_x, end_y;
 
 	g_assert(VTE_IS_TERMINAL_ACCESSIBLE(text));
@@ -1542,9 +1543,12 @@ vte_terminal_accessible_get_selection(AtkText *text, gint selection_number,
 
 	priv = g_object_get_data(G_OBJECT(text),
 				 VTE_TERMINAL_ACCESSIBLE_PRIVATE_DATA);
-	_vte_terminal_get_start_selection (terminal, &start_x, &start_y);
+        if (!vte_terminal_get_selection_bounds(terminal, &start, &end))
+                return NULL;
+
+        _vte_buffer_iter_get_position(&start, &start_y, &start_x);
+        _vte_buffer_iter_get_position(&end, &end_y, &end_x);
 	*start_offset = offset_from_xy (priv, start_x, start_y);
-	_vte_terminal_get_end_selection (terminal, &end_x, &end_y);
 	*end_offset = offset_from_xy (priv, end_x, end_y);
 	return _vte_terminal_get_selection (terminal);
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]