[evolution-patches] [Fwd: Re: [gtkhtml] inserting nested cluevs fix]



Hello,

please review patch in forwarded message for the gtkhtml/gnome-2-10 release.

Cheers
Radek
--
Radek Doulík <rodo novell com>
Novell, Inc.
--- Begin Message --- Attaching updated patch, which doesn't change htmlobject api and is also logically cleaner.

Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gtkhtml/src/ChangeLog,v
retrieving revision 1.2099
diff -u -p -r1.2099 ChangeLog
--- ChangeLog	28 Feb 2005 15:36:25 -0000	1.2099
+++ ChangeLog	7 Mar 2005 17:27:58 -0000
@@ -1,3 +1,13 @@
+2005-03-03  Radek Doulik  <rodo novell com>
+
+	* test-suite.c (test_insert_nested_cluevs): added test for
+	inserting nested cluevs
+
+	* htmlengine-edit.c (html_engine_get_insert_level_for_object): new
+	helper function, calculates insert level at cursor position for
+	object. it makes sure that insert level isn't greater than cursor
+	level
+
 2005-02-28  Radek Doulik  <rodo novell com>
 
 	* htmltext.c (html_text_direction_pango_to_html): new helper
Index: gtkhtml.c
===================================================================
RCS file: /cvs/gnome/gtkhtml/src/gtkhtml.c,v
retrieving revision 1.592
diff -u -p -r1.592 gtkhtml.c
--- gtkhtml.c	28 Feb 2005 15:36:25 -0000	1.592
+++ gtkhtml.c	7 Mar 2005 17:28:18 -0000
@@ -5593,7 +5593,7 @@ gtk_html_insert_html_generic (GtkHTML *h
 		tmp->engine->clue = NULL;
 		html_engine_insert_object (html->engine, o,
 					   html_object_get_recursive_length (o),
-					   html_object_get_insert_level (o));
+					   html_engine_get_insert_level_for_object (html->engine, o));
 	}
 	gtk_widget_destroy (window);
 	html_engine_thaw (html->engine);
Index: htmlengine-edit-cut-and-paste.c
===================================================================
RCS file: /cvs/gnome/gtkhtml/src/htmlengine-edit-cut-and-paste.c,v
retrieving revision 1.108
diff -u -p -r1.108 htmlengine-edit-cut-and-paste.c
--- htmlengine-edit-cut-and-paste.c	28 Feb 2005 15:36:25 -0000	1.108
+++ htmlengine-edit-cut-and-paste.c	7 Mar 2005 17:28:21 -0000
@@ -1102,7 +1102,7 @@ html_engine_paste_object (HTMLEngine *e,
 {
 	html_undo_level_begin (e->undo, "Paste", "Paste");
 	html_engine_delete (e);
-	html_engine_insert_object (e, o, len, html_object_get_insert_level (o));
+	html_engine_insert_object (e, o, len, html_engine_get_insert_level_for_object (e, o));
 	html_undo_level_end (e->undo);
 }
 
Index: htmlengine-edit.c
===================================================================
RCS file: /cvs/gnome/gtkhtml/src/htmlengine-edit.c,v
retrieving revision 1.108
diff -u -p -r1.108 htmlengine-edit.c
--- htmlengine-edit.c	28 Feb 2005 15:36:25 -0000	1.108
+++ htmlengine-edit.c	7 Mar 2005 17:28:22 -0000
@@ -37,6 +37,7 @@
 #include "htmlcursor.h"
 #include "htmlobject.h"
 #include "htmltable.h"
+#include "htmltablecell.h"
 #include "htmltext.h"
 #include "htmltextslave.h"
 #include "htmlimage.h"
@@ -761,4 +762,21 @@ void html_engine_edit_set_direction (HTM
 		cf->dir = dir;
 		html_engine_thaw (e);
 	}
+}
+
+int
+html_engine_get_insert_level_for_object (HTMLEngine *e, HTMLObject *o)
+{
+	int cursor_level = 3, level = html_object_get_insert_level (o);
+
+	if (level > 3) {
+		if (e && e->cursor->object && e->cursor->object->parent && e->cursor->object->parent->parent && html_object_is_clue (e->cursor->object->parent->parent)) {
+			HTMLObject *clue = e->cursor->object->parent->parent;
+
+			while (clue && clue->parent && (HTML_IS_CLUEV (clue->parent) || HTML_IS_TABLE_CELL (clue->parent)))
+			       cursor_level ++;
+		}
+	}
+
+	return MIN (level, cursor_level);
 }
Index: htmlengine-edit.h
===================================================================
RCS file: /cvs/gnome/gtkhtml/src/htmlengine-edit.h,v
retrieving revision 1.45
diff -u -p -r1.45 htmlengine-edit.h
--- htmlengine-edit.h	28 Feb 2005 15:36:25 -0000	1.45
+++ htmlengine-edit.h	7 Mar 2005 17:28:22 -0000
@@ -84,6 +84,8 @@ gboolean                   html_engine_n
 gboolean                   html_engine_prev_cell                   (HTMLEngine                *e);
 void                       html_engine_set_title                   (HTMLEngine                *e,
 								    const gchar               *title);
+int                        html_engine_get_insert_level_for_object (HTMLEngine                *e,
+								    HTMLObject                *o);
 void html_engine_edit_set_direction (HTMLEngine *e,
 				     HTMLDirection dir);
 /*
Index: htmlobject.c
===================================================================
RCS file: /cvs/gnome/gtkhtml/src/htmlobject.c,v
retrieving revision 1.186
diff -u -p -r1.186 htmlobject.c
--- htmlobject.c	3 Feb 2005 17:18:43 -0000	1.186
+++ htmlobject.c	7 Mar 2005 17:28:25 -0000
@@ -41,6 +41,7 @@
 #include "htmlobject.h"
 #include "htmlpainter.h"
 #include "htmltable.h"
+#include "htmltablecell.h"
 #include "htmltext.h"
 #include "htmlrule.h"
 #include "htmltype.h"
@@ -2069,7 +2070,8 @@ html_object_get_insert_level (HTMLObject
 	case HTML_TYPE_CLUEV: {
 		int level = 3;
 
-		while (o && HTML_IS_CLUEV (o) && HTML_CLUE (o)->head && HTML_IS_CLUEV (HTML_CLUE (o)->head)) {
+		while (o && (HTML_IS_CLUEV (o) || HTML_IS_TABLE_CELL (o))
+		       && HTML_CLUE (o)->head && (HTML_IS_CLUEV (HTML_CLUE (o)->head) || HTML_IS_TABLE_CELL (HTML_CLUE (o)->head))) {
 			level ++;
 			o = HTML_CLUE (o)->head;
 		}
Index: test-suite.c
===================================================================
RCS file: /cvs/gnome/gtkhtml/src/test-suite.c,v
retrieving revision 1.10
diff -u -p -r1.10 test-suite.c
--- test-suite.c	21 Feb 2005 16:34:49 -0000	1.10
+++ test-suite.c	7 Mar 2005 17:29:07 -0000
@@ -36,6 +36,7 @@ static int test_quotes_in_div_block (Gtk
 static int test_quotes_in_table (GtkHTML *html);
 static int test_capitalize_upcase_lowcase_word (GtkHTML *html);
 static int test_delete_nested_cluevs_and_undo (GtkHTML *html);
+static int test_insert_nested_cluevs (GtkHTML *html);
 static int test_indentation_plain_text (GtkHTML *html);
 static int test_indentation_plain_text_rtl (GtkHTML *html);
 
@@ -53,6 +54,7 @@ static Test tests[] = {
 	{ "outer quotes inside table", test_quotes_in_table },
 	{ "capitalize, upcase/lowcase word", test_capitalize_upcase_lowcase_word },
 	{ "delete across nested cluev's and undo", test_delete_nested_cluevs_and_undo },
+	{ "insert nested cluev's", test_insert_nested_cluevs },
 	{ "indentation in plain text", test_indentation_plain_text },
 	{ "indentation in plain text (RTL)", test_indentation_plain_text_rtl },
 	{ NULL, NULL }
@@ -118,6 +120,15 @@ static int test_delete_nested_cluevs_and
 	if (html->engine->cursor->offset != 3
 	    || html->engine->cursor->position != 7)
 		return FALSE;
+
+	return TRUE;
+}
+
+static int test_insert_nested_cluevs (GtkHTML *html)
+{
+	load_editable (html, "text");
+
+	gtk_html_insert_html (html, "<div>text in div block</div>");
 
 	return TRUE;
 }

--- End Message ---


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