[evolution-patches] patch for e-text preedit area



Hi,
	This patch fixes e-text preedit area not shown issue, pl. check this and 
lemme know (affects the To: field in mail Compose window )
	Here also pango_layout_get_attributes (text->layout) does not seem to 
work, so calling reset_layout_attrs (text) function...
	
Thanks & Regards,
Suresh
? 1
? attrs
? e-text.c-2003-10-09-1522
? e-text.c-2003-10-11-1235
? e-text.c-2003-10-11-1404
Index: e-text.c
===================================================================
RCS file: /cvs/gnome/gal/gal/e-text/e-text.c,v
retrieving revision 1.145.4.1
diff -u -r1.145.4.1 e-text.c
--- e-text.c	16 Aug 2003 07:47:09 -0000	1.145.4.1
+++ e-text.c	12 Oct 2003 19:16:36 -0000
@@ -139,6 +139,8 @@
 static void e_text_paste (EText *text, GdkAtom selection);
 static void e_text_insert(EText *text, const char *string);
 
+static void reset_layout_attrs (EText *text);
+
 /* GtkEditable Methods */
 static void e_text_editable_do_insert_text (GtkEditable    *editable,
 					    const gchar    *text,
@@ -164,6 +166,8 @@
 static void     e_text_commit_cb               (GtkIMContext *context,
 						const gchar  *str,
 						EText        *text);
+static void     e_text_preedit_changed_cb      (GtkIMContext *context,
+						EText        *text);
 static gboolean e_text_retrieve_surrounding_cb (GtkIMContext *context,
 						EText        *text);
 static gboolean e_text_delete_surrounding_cb   (GtkIMContext *context,
@@ -279,6 +283,51 @@
 }
 
 static void
+insert_preedit_text (EText *text)
+{
+	PangoAttrList *attrs = NULL;
+	PangoAttrList *preedit_attrs = NULL;
+	gchar *preedit_string = NULL;
+	GString *tmp_string = g_string_new (NULL);
+	gint length = 0, cpos = 0, preedit_length = 0;
+
+	if (text->layout == NULL)
+		return;
+
+	text->text = e_text_model_get_text(text->model);
+	length = strlen (text->text);
+
+	g_string_prepend_len (tmp_string, text->text,length); 
+
+	attrs = pango_attr_list_new ();
+
+	gtk_im_context_get_preedit_string (text->im_context,
+					&preedit_string, &preedit_attrs,
+					NULL);
+
+	text->preedit_len = preedit_length = strlen (preedit_string);;
+	cpos = g_utf8_offset_to_pointer (text->text, text->selection_start) - text->text;	
+	if (preedit_length)
+		g_string_insert (tmp_string, cpos, preedit_string);
+
+	reset_layout_attrs (text);
+
+	pango_layout_set_text (text->layout, tmp_string->str, tmp_string->len);
+	if (preedit_length)
+		pango_attr_list_splice (attrs, preedit_attrs, cpos, preedit_length);
+	pango_layout_set_attributes (text->layout, attrs);
+
+	if (preedit_string)
+		g_free (preedit_string);
+	if (preedit_attrs)
+		pango_attr_list_unref (preedit_attrs);
+	if (tmp_string)
+		g_string_free (tmp_string, TRUE);
+	if (attrs)
+		pango_attr_list_unref (attrs);
+}
+
+static void
 reset_layout_attrs (EText *text)
 {
 	PangoAttrList *attrs = NULL;
@@ -1433,7 +1482,10 @@
 		}
 	}
 
-	if (!text->text)
+
+	insert_preedit_text (text);	
+
+	if (!pango_layout_get_text (text->layout))
 		return;
 
 	if (text->stipple)
@@ -1555,7 +1607,7 @@
 				PangoRectangle strong_pos, weak_pos;
 				char *offs = g_utf8_offset_to_pointer (text->text, text->selection_start);
 
-				pango_layout_get_cursor_pos (text->layout, offs - text->text, &strong_pos, &weak_pos);
+				pango_layout_get_cursor_pos (text->layout, offs - text->text + text->preedit_len, &strong_pos, &weak_pos);
 				draw_pango_rectangle (drawable, main_gc, xpos, ypos, strong_pos);
 				if (strong_pos.x != weak_pos.x ||
 				    strong_pos.y != weak_pos.y ||
@@ -2113,6 +2165,8 @@
 					if (!text->im_context_signals_registered) {
 						g_signal_connect (text->im_context, "commit",
 								  G_CALLBACK (e_text_commit_cb), text);
+						g_signal_connect (text->im_context, "preedit_changed",
+								  G_CALLBACK (e_text_preedit_changed_cb), text);
 						g_signal_connect (text->im_context, "retrieve_surrounding",
 								  G_CALLBACK (e_text_retrieve_surrounding_cb), text);
 						g_signal_connect (text->im_context, "delete_surrounding",
@@ -3603,6 +3657,7 @@
 {
 	text->model                   = e_text_model_new ();
 	text->text                    = e_text_model_get_text (text->model);
+	text->preedit_len	      = 0;
 	text->layout                  = NULL;
 
 	text->revert                  = NULL;
@@ -3705,6 +3760,7 @@
 	     PARENT_TYPE)
 
 
+
 /* IM Context Callbacks */
 static void
 e_text_commit_cb (GtkIMContext *context,
@@ -3720,11 +3776,25 @@
 	}
 }
 
+static void
+e_text_preedit_changed_cb (GtkIMContext *context,
+				EText        *etext)
+{
+	gchar *preedit_string = NULL;
+
+	gtk_im_context_get_preedit_string (context, &preedit_string, 
+					NULL, NULL);
+
+	etext->preedit_len = strlen (preedit_string);
+
+	g_signal_emit (etext, e_text_signals[E_TEXT_KEYPRESS], 0,
+		       0 /* XXX ugh */, 0 /* XXX ugh */);
+}
+
 static gboolean
 e_text_retrieve_surrounding_cb (GtkIMContext *context,
 				EText        *text)
 {
-	printf ("e_text_retrieve_surrounding_cb\n");
 	gtk_im_context_set_surrounding (context,
 					text->text,
 					strlen (text->text),
@@ -3739,12 +3809,9 @@
 				gint          n_chars,
 				EText        *text)
 {
-	printf ("e_text_delete_surrounding_cb\n");
-#if 0
-	gtk_editable_delete_text (GTK_EDITABLE (entry),
-				  entry->current_pos + offset,
-				  entry->current_pos + offset + n_chars);
-#endif
+	gtk_editable_delete_text (GTK_EDITABLE (text),
+				  text->selection_end + offset,
+				  text->selection_end + offset + n_chars);
 
 	return TRUE;
 }
Index: e-text.h
===================================================================
RCS file: /cvs/gnome/gal/gal/e-text/e-text.h,v
retrieving revision 1.57
diff -u -r1.57 e-text.h
--- e-text.h	23 Jul 2003 14:44:57 -0000	1.57
+++ e-text.h	12 Oct 2003 19:16:36 -0000
@@ -108,6 +108,7 @@
 	gint model_repos_signal_id;
 
 	const gchar *text;              /* Text to display --- from the ETextModel */
+	gint preedit_len;      		/* preedit length to display */
 	PangoLayout *layout;
 	int num_lines;			/* Number of lines of text */
 


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