[evolution-patches] 44619 modified gtkhtml patch for evolution-1-4-branch



Hi,
	Seems like the gtkhtml preedit-changed callback is not implemented in 
the stable 1.4 branch, here's a light weight version of the original patch 
appeared in http://cvs.sourceforge.net/viewcvs.py/im-ja/im-ja/patches/

	The original was having memory leaks, hopefully this one does not, this 
is no frills stuff, so don't expect preedit to appear in underlined font and 
all, did not find any likes of html_engine_insert_text_with_attributes in 1.4 
branch.

Pl. check whether this is worth putting back.
	
Thanks & Regards,
Suresh
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gtkhtml/src/ChangeLog,v
retrieving revision 1.1814.2.13
diff -u -r1.1814.2.13 ChangeLog
--- ChangeLog	24 Sep 2003 17:10:02 -0000	1.1814.2.13
+++ ChangeLog	3 Oct 2003 20:38:10 -0000
@@ -1,3 +1,16 @@
+2003-10-03  Suresh Chandrasekharan <suresh chandrasekharan sun com>
+
+	* gtkhtml.c: Patch for 44619.
+	This is a modified/lightweight version of the one found in 
+	http://cvs.sourceforge.net/viewcvs.py/im-ja/im-ja/patches/
+
+	(gtk_html_im_preedit_changed_cb): Inserts preedit text
+	(gtk_html_im_commit_cb): Support for html->priv->im_block_reset
+	flag
+	(gtk_html_im_reset): Setting/Resetting im_context
+
+	* gtkhtml-private.h: im_block_reset flag added
+
 2003-07-31  Radek Doulik  <rodo ximian com>
 
 	* htmlengine-edit.c (html_engine_select_spell_word_editable): fix
Index: gtkhtml-private.h
===================================================================
RCS file: /cvs/gnome/gtkhtml/src/gtkhtml-private.h,v
retrieving revision 1.40
diff -u -r1.40 gtkhtml-private.h
--- gtkhtml-private.h	25 Jun 2003 08:19:31 -0000	1.40
+++ gtkhtml-private.h	3 Oct 2003 20:38:10 -0000
@@ -53,6 +53,7 @@
 
 	GtkIMContext *im_context;
 	gboolean need_im_reset;
+	gboolean im_block_reset;
 
 	HTMLObject *dnd_object;
 	HTMLObject *dnd_real_object;
Index: gtkhtml.c
===================================================================
RCS file: /cvs/gnome/gtkhtml/src/gtkhtml.c,v
retrieving revision 1.520.2.6
diff -u -r1.520.2.6 gtkhtml.c
--- gtkhtml.c	5 Sep 2003 07:52:24 -0000	1.520.2.6
+++ gtkhtml.c	3 Oct 2003 20:38:11 -0000
@@ -790,12 +790,17 @@
 void
 gtk_html_im_reset (GtkHTML *html)
 {
-	if (html->priv->need_im_reset) {
-		html->priv->need_im_reset = FALSE;
-		gtk_im_context_reset (html->priv->im_context);
+	if (!html->priv->im_block_reset) {
+		if (html->priv->need_im_reset) {
+			if (html->engine->freeze_count == 1)
+				html_engine_thaw_idle_flush (html->engine);
+			html->priv->need_im_reset = FALSE;
+			gtk_im_context_reset (html->priv->im_context);
+		}
 	}
 }
 
+
 static gint
 key_press_event (GtkWidget *widget, GdkEventKey *event)
 {
@@ -2662,16 +2667,43 @@
 	}
 }
 
+static gint preedit_len = 0;
+
 static void
 gtk_html_im_commit_cb (GtkIMContext *context, const gchar *str, GtkHTML *html)
 {
+	gboolean state = html->priv->im_block_reset;
+
+	html->priv->im_block_reset = TRUE;
 	html_engine_paste_text (html->engine, str, -1);
+	html->priv->im_block_reset = state;
 }
 
 static void
 gtk_html_im_preedit_changed_cb (GtkIMContext *context, GtkHTML *html)
 {
-	g_warning ("preedit changed callback: implement me");
+	gint position;
+	gchar *preedit_string;
+	gint preedit_cursor_position;
+	gboolean state = html->priv->im_block_reset;
+
+	html->priv->im_block_reset = TRUE;
+	gtk_im_context_get_preedit_string (context, &preedit_string, \
+			NULL, &preedit_cursor_position);
+
+	html_engine_freeze (html->engine);
+	if (preedit_len > 0) gtk_html_undo (html);
+
+	position = html->engine->cursor->position + preedit_cursor_position;
+	if ((preedit_len = g_utf8_strlen (preedit_string, -1)) > 0) {
+		html_engine_insert_text (html->engine, preedit_string, -1);
+	}
+
+	if (position >= 0) html_cursor_jump_to_position_no_spell (html->engine->cursor, html->engine, position);
+	html_engine_thaw (html->engine);
+	html->priv->im_block_reset = state;
+	
+	g_free (preedit_string);
 }
 
 static gchar *
@@ -2720,7 +2752,6 @@
 {
 	gint offset;
 
-	printf ("gtk_html_im_retrieve_surrounding_cb\n");
 	gtk_im_context_set_surrounding (context, get_surrounding_text (html->engine, &offset), -1, offset);
 
 	return TRUE;
@@ -2729,7 +2760,6 @@
 static gboolean
 gtk_html_im_delete_surrounding_cb (GtkIMContext *slave, gint offset, gint n_chars, GtkHTML *html)
 {
-	printf ("gtk_html_im_delete_surrounding_cb\n");
 	if (html_engine_get_editable (html->engine) && !html_engine_is_selection_active (html->engine)) {
 		gint orig_position = html->engine->cursor->position;
 
@@ -2796,7 +2826,8 @@
 	/* IM Context */
 	html->priv->im_context = gtk_im_multicontext_new ();
 	html->priv->need_im_reset = FALSE;
-  
+	html->priv->im_block_reset = FALSE;
+
 	g_signal_connect (G_OBJECT (html->priv->im_context), "commit",
 			  G_CALLBACK (gtk_html_im_commit_cb), html);
 	g_signal_connect (G_OBJECT (html->priv->im_context), "preedit_changed",
@@ -2805,6 +2836,9 @@
 			  G_CALLBACK (gtk_html_im_retrieve_surrounding_cb), html);
 	g_signal_connect (G_OBJECT (html->priv->im_context), "delete_surrounding",
 			  G_CALLBACK (gtk_html_im_delete_surrounding_cb), html);
+
+	gtk_im_context_set_use_preedit (GTK_IM_CONTEXT (html->priv->im_context), TRUE);
+
 }
 
 GType


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