[evolution-patches] patch to implement set/get_caret_offset method of AtkText interface



Hi Radek,

The patch mainly implemented get/set_caret_offset method. After this patch
gnopernicus can report current character when you move cursor, and can set
caret to some text using at-poke.

Some explain of the patch below,

I introduced a method to get/set current gtkhtml widget in html_utils, as below:

+static GtkHTML * gtkhtml = NULL;
+                                                                                
+void
+html_utils_set_gtk_html(GtkHTML * p)
+{
+        gtkhtml = p;
+}
+                                                                                
+GtkHTML *
+html_utils_get_gtk_html(void)
+{
+        return gtkhtml;
 }


I notice original code seems try to using the html_a11y_get_gtkhtml_parent() to reach the same goal.
But the function do not work. We cannot get the gtkhtml widget from a html object.

Other parts is straightforward. Please review,


Thanks
York


Index: object.c
===================================================================
RCS file: /cvs/gnome/gtkhtml/a11y/object.c,v
retrieving revision 1.3
diff -u -r1.3 object.c
--- object.c	24 Jul 2003 08:25:06 -0000	1.3
+++ object.c	24 Jul 2003 09:26:26 -0000
@@ -28,6 +28,7 @@
 #include "object.h"
 #include "paragraph.h"
 #include "utils.h"
+#include "text.h"
 
 static void gtk_html_a11y_class_init (GtkHTMLA11YClass *klass);
 static void gtk_html_a11y_init       (GtkHTMLA11Y *a11y);
@@ -167,6 +168,7 @@
 {
         AtkObject *focus_object, *obj;
 
+        html_utils_set_gtk_html(GTK_HTML(widget));
 
 	 focus_object = gtk_html_a11y_get_focus_object (widget);
         obj = gtk_widget_get_accessible (widget);
@@ -188,7 +190,14 @@
 		prev_object = focus_object;
         	g_object_set_data (G_OBJECT(obj), "gail-focus-object", focus_object);
         	atk_focus_tracker_notify (focus_object);
-	}
+	} else {
+		if (G_IS_HTML_A11Y_TEXT(focus_object)) {
+			gint offset;
+
+			offset = (GTK_HTML(widget))->engine->cursor->offset;
+			g_signal_emit_by_name(focus_object, "text_caret_moved",offset);
+                }
+        }
 }
 
 AtkObject* 
@@ -211,6 +220,7 @@
 	g_signal_connect_after(widget, "cursor_move",
 			G_CALLBACK(gtk_html_a11y_cursor_move_cb),
 			NULL);
+	html_utils_set_gtk_html(GTK_HTML(widget));
 
 	/* printf ("created new gtkhtml accessible object\n"); */
 
Index: text.c
===================================================================
RCS file: /cvs/gnome/gtkhtml/a11y/text.c,v
retrieving revision 1.3
diff -u -r1.3 text.c
--- text.c	15 Nov 2002 13:56:44 -0000	1.3
+++ text.c	24 Jul 2003 09:26:26 -0000
@@ -36,6 +36,7 @@
 #include "object.h"
 #include "html.h"
 #include "text.h"
+#include "utils.h"
 
 static void html_a11y_text_class_init    (HTMLA11YTextClass *klass);
 static void html_a11y_text_init          (HTMLA11YText *a11y_text);
@@ -59,6 +60,8 @@
 static gboolean html_a11y_text_add_selection (AtkText *text, gint start_offset, gint end_offset);
 static gboolean html_a11y_text_remove_selection (AtkText *text, gint selection_num);
 static gboolean html_a11y_text_set_selection (AtkText *text, gint selection_num, gint start_offset, gint end_offset);
+static gint html_a11y_text_get_caret_offset (AtkText *text);
+static gboolean html_a11y_text_set_caret_offset (AtkText *text, gint offset);
 
 static AtkObjectClass *parent_class = NULL;
 
@@ -125,6 +128,9 @@
 	iface->get_selection = html_a11y_text_get_selection;
 	iface->remove_selection = html_a11y_text_remove_selection;
 	iface->set_selection = html_a11y_text_set_selection;
+	iface->add_selection = html_a11y_text_add_selection;
+	iface->get_caret_offset = html_a11y_text_get_caret_offset;
+	iface->set_caret_offset = html_a11y_text_set_caret_offset;
 }
 
 static void
@@ -259,6 +265,44 @@
 	return g_strndup (str, g_utf8_offset_to_pointer (str, end_offset - start_offset) - str);
 }
 
+static gint
+html_a11y_text_get_caret_offset(AtkText * text)
+{
+	HTMLObject * p;
+	HTMLEngine * e;
+	GtkHTML * gtkhtml;
+
+	g_return_val_if_fail(text, 0);
+
+	p= HTML_A11Y_HTML(text);
+	g_return_val_if_fail(p && HTML_IS_TEXT(p), 0);
+
+	gtkhtml = html_utils_get_gtk_html();
+	g_return_val_if_fail(gtkhtml && gtkhtml->engine, 0);
+
+	e = html_engine_get_top_html_engine(gtkhtml->engine);
+	g_return_val_if_fail(e && e->cursor && e->cursor->object == p, 0);
+
+	return e->cursor->offset;
+}
+
+static gboolean
+html_a11y_text_set_caret_offset(AtkText * text, gint offset)
+{
+	GtkHTML * html;
+	HTMLEngine * e;
+	HTMLObject * obj = HTML_A11Y_HTML(text);
+
+	html = html_utils_get_gtk_html();
+
+	g_return_val_if_fail(obj && html && html->engine, FALSE);
+
+	e = html->engine;
+	html_engine_jump_to_object(e, obj, offset);
+
+	return TRUE;
+}
+
 static gchar *
 html_a11y_text_get_text_after_offset (AtkText *text, gint offset, AtkTextBoundary boundary_type,
 				      gint *start_offset, gint *end_offset)
@@ -322,10 +366,13 @@
 static gboolean
 html_a11y_text_add_selection (AtkText *text, gint start_offset, gint end_offset)
 {
-	GtkHTML *html = GTK_HTML_A11Y_GTKHTML (html_a11y_get_gtkhtml_parent (HTML_A11Y (text)));
+	GtkHTML *html ;
 	HTMLObject *obj = HTML_A11Y_HTML (text);
 	HTMLInterval *i;
 
+	html = html_utils_get_gtk_html();
+	g_return_val_if_fail(html && html->engine, FALSE);
+
 	if (html_engine_is_selection_active (html->engine))
 		return FALSE;
 
@@ -357,6 +404,7 @@
 
 	return html_a11y_text_add_selection (text, start_offset, end_offset);
 }
+
 
 /*
   AtkAttributeSet* (* get_run_attributes)         (AtkText	    *text,
Index: utils.c
===================================================================
RCS file: /cvs/gnome/gtkhtml/a11y/utils.c,v
retrieving revision 1.3
diff -u -r1.3 utils.c
--- utils.c	24 Jul 2003 08:25:06 -0000	1.3
+++ utils.c	24 Jul 2003 09:26:26 -0000
@@ -90,7 +90,7 @@
 {
 	AtkObject *accessible;
 
-	if (!o) return NULL;
+	g_return_val_if_fail(o != NULL, NULL);
 
 	accessible = html_object_get_data (o, ACCESSIBLE_ID);
 
@@ -103,4 +103,18 @@
 	}
 
 	return accessible;
+}
+
+static GtkHTML * gtkhtml = NULL;
+                                                                                              
+void
+html_utils_set_gtk_html(GtkHTML * p)
+{
+        gtkhtml = p;
+}
+                                                                                              
+GtkHTML *
+html_utils_get_gtk_html(void)
+{
+        return gtkhtml;
 }
Index: utils.h
===================================================================
RCS file: /cvs/gnome/gtkhtml/a11y/utils.h,v
retrieving revision 1.2
diff -u -r1.2 utils.h
--- utils.h	1 Nov 2002 15:34:27 -0000	1.2
+++ utils.h	24 Jul 2003 09:26:27 -0000
@@ -31,5 +31,7 @@
 #define HTML_OBJECT_ACCESSIBLE(o) ATK_OBJECT (html_object_get_data (HTML_OBJECT (o), ACCESSIBLE_ID))
 
 AtkObject *html_utils_get_accessible (HTMLObject *o, AtkObject *parent);
+GtkHTML	*html_utils_get_gtk_html (void);
+void 	html_utils_set_gtk_html (GtkHTML * gtkhtml);
 
 #endif


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