Index: gnopernicus/srlow/libsrlow/SRObject.c
===================================================================
RCS file: /cvs/gnome/gnopernicus/srlow/libsrlow/SRObject.c,v
retrieving revision 1.122
diff -u -r1.122 SRObject.c
--- gnopernicus/srlow/libsrlow/SRObject.c	28 Feb 2005 13:19:32 -0000	1.122
+++ gnopernicus/srlow/libsrlow/SRObject.c	22 Mar 2005 09:44:13 -0000
@@ -5457,6 +5457,173 @@
 }
 
 
+#define ACCESSIBLE_RELATION_SET_FREE(rel)			\
+    {							\
+	gint k;						\
+	srl_assert (rel);				\
+	for (k = 0; rel[k]; k++)			\
+	    AccessibleRelation_unref (rel[k]);		\
+	g_free (rel);					\
+    }
+
+static Accessible*
+get_flows_from (Accessible *acc)
+{
+    Accessible *rv = NULL;
+    AccessibleRelation **rel;
+    gint k;
+
+    srl_assert (acc);
+
+    rel = Accessible_getRelationSet (acc);
+    if (!rel)
+	return NULL;
+
+    for (k = 0; rel[k]; k++)
+    {
+	if (SPI_RELATION_FLOWS_FROM == AccessibleRelation_getRelationType (rel[k]))
+	{
+	    rv = AccessibleRelation_getTarget (rel[k], 0);
+	    break;
+	}
+    }
+    ACCESSIBLE_RELATION_SET_FREE (rel);
+
+    return rv;
+}
+
+static Accessible*
+get_flows_to (Accessible *acc)
+{
+    Accessible *rv = NULL;
+    AccessibleRelation **rel;
+    gint k;
+
+    srl_assert (acc);
+
+    rel = Accessible_getRelationSet (acc);
+    if (!rel)
+	return NULL;
+
+    for (k = 0; rel[k]; k++)
+    {
+	if (SPI_RELATION_FLOWS_TO == AccessibleRelation_getRelationType (rel[k]))
+	{
+	    rv = AccessibleRelation_getTarget (rel[k], 0);
+	    break;
+	}
+    }
+    ACCESSIBLE_RELATION_SET_FREE (rel);
+
+    return rv;
+}
+
+
+static void
+get_selected_text_from_flows_from (Accessible *acc,
+				   GString *sel)
+{
+    srl_assert (acc && sel);
+
+    Accessible_ref (acc);
+    
+    do
+    {
+	Accessible *tmp = acc;
+	AccessibleText *text;
+	gint cnt;
+
+	acc = get_flows_from (acc);
+	Accessible_unref (tmp);
+	if (!acc)
+	    break;
+	text = Accessible_getText (acc);
+	if (!text)
+	    break;
+	cnt = AccessibleText_getNSelections (text);
+	if (cnt > 0)
+	{
+	    gchar *str = NULL;
+	    long int sp, ep;
+	    AccessibleText_getSelection (text, cnt - 1, &sp, &ep);
+	    str = AccessibleText_getText (text,  sp, ep);
+	    g_string_insert (sel, 0, " ");
+	    g_string_insert (sel, 0, str ? str : "");
+	    SPI_freeString (str); 
+	}
+	AccessibleText_unref (text);
+	if (cnt != 1)
+	    break;
+    }while (TRUE);
+    if (acc)
+	Accessible_unref (acc);
+}
+
+
+static void
+get_selected_text_from_flows_to (Accessible *acc,
+				 GString *sel)
+{
+    srl_assert (acc && sel);
+
+    Accessible_ref (acc);
+    
+    do
+    {
+	Accessible *tmp = acc;
+	AccessibleText *text;
+	gint cnt;
+
+	acc = get_flows_to (acc);
+	Accessible_unref (tmp);
+	if (!acc)
+	    break;
+	text = Accessible_getText (acc);
+	if (!text)
+	    break;
+	cnt = AccessibleText_getNSelections (text);
+	if (cnt > 0)
+	{
+	    gchar *str = NULL;
+	    long int sp, ep;
+	    AccessibleText_getSelection (text, 0, &sp, &ep);
+	    str = AccessibleText_getText (text,  sp, ep);
+	    g_string_append (sel, " ");
+	    g_string_append (sel, str ? str : "");
+	    SPI_freeString (str);
+	}
+	AccessibleText_unref (text);
+	if (cnt != 1)
+	    break;
+    }while (TRUE);
+    if (acc)
+	Accessible_unref (acc);
+}
+
+static gchar*
+text_selections_with_flows_relations (Accessible *acc)
+{
+    AccessibleText *text;
+    GString *sel = g_string_new ("");
+
+    get_selected_text_from_flows_from (acc, sel);
+    text = Accessible_getText (acc);
+    if (text)
+    {
+	gchar *str = NULL;
+	long int sp, ep;
+	AccessibleText_getSelection (text, 0, &sp, &ep);
+	str = AccessibleText_getText (text,  sp, ep);
+	g_string_append (sel, " ");
+	g_string_append (sel, str ? str : "");
+	SPI_freeString (str);
+	AccessibleText_unref (text);
+    }
+    get_selected_text_from_flows_to (acc, sel);
+
+    return g_string_free (sel, FALSE);
+}
+
 gboolean 
 sro_text_get_selections (SRObject *obj,
 			 gchar ***selections,
@@ -5481,16 +5648,26 @@
     n_sel = AccessibleText_getNSelections (acc_text);
     if (n_sel > 0)
     {
-	long i;
 	*selections = (gchar**) g_malloc ((n_sel + 1) * sizeof (gchar*));
-	for (i = 0; i < n_sel; i++)
+	if (n_sel > 1)
+	{
+	    long i;
+	    for (i = 0; i < n_sel; i++)
+	    {
+		gchar *tmp;
+		long int start, end;
+		AccessibleText_getSelection (acc_text, i, &start, &end);
+		tmp = AccessibleText_getText (acc_text, start, end);
+		(*selections)[i] = SR_strdup (tmp);
+		SPI_freeString (tmp);
+	    }
+	}
+	else
 	{
 	    gchar *tmp;
-	    long int start, end;
-	    AccessibleText_getSelection (acc_text, i, &start, &end);
-	    tmp = AccessibleText_getText (acc_text, start, end);
-	    (*selections)[i] = SR_strdup (tmp);
-	    SPI_freeString (tmp);
+	    tmp = text_selections_with_flows_relations (acc);
+	    (*selections)[0] = SR_strdup (tmp);
+	    g_free (tmp);
 	}
 	(*selections)[n_sel] = NULL;
     }
