Index: ./widgets/text/e-text.c
===================================================================
RCS file: /cvs/gnome/evolution/widgets/text/e-text.c,v
retrieving revision 1.175
diff -u -8 -p -r1.175 e-text.c
--- ./widgets/text/e-text.c	4 Dec 2006 15:45:50 -0000	1.175
+++ ./widgets/text/e-text.c	18 Dec 2006 12:32:48 -0000
@@ -2123,16 +2123,17 @@ _do_tooltip (gpointer data)
 
 static void
 start_editing (EText *text)
 {
 	if (text->editing)
 		return;
 
 	g_free (text->revert);
+	
 	text->revert = g_strdup (text->text);
 
 	text->editing = TRUE;
 	if (text->pointer_in) {
 		if (text->default_cursor_shown && (!text->draw_borders)) {
 			gdk_window_set_cursor (GTK_WIDGET (GNOME_CANVAS_ITEM (text)->canvas)->window, text->i_cursor);
 			text->default_cursor_shown = FALSE;
 		}
@@ -2184,78 +2185,82 @@ _click (gpointer data)
 }
 
 static gint
 e_text_event (GnomeCanvasItem *item, GdkEvent *event)
 {
 	EText *text = E_TEXT(item);
 	ETextEventProcessorEvent e_tep_event;
 
-	static EText *save_text = NULL;
-
 	gint return_val = 0;
 
 	if (!text->model)
 		return FALSE;
 
 	e_tep_event.type = event->type;
 	switch (event->type) {
 	case GDK_FOCUS_CHANGE:
 		if (text->editable) {
 			GdkEventFocus *focus_event;
 			focus_event = (GdkEventFocus *) event;
-			if (focus_event->in) {
-
-				/* Evil hack to disconnect the signal handlers for the previous Etext
-				 * which was not disconnected because of being in preedit mode.
-				 * In preedit mode the widget can go out of focus due to popups associated
-				 * with preedit.,but still the callbacks need to be connected. 
-				 * Here when a new text widget comes into focus we can disconnect the 
-				 * old one.Shouldn't hurt much, as in worst case, save_text which should
-				 * be disconnected will be overwritten and we will have signal 
-			   	 * handlers connect to  multiple e-texts but with subsequent commit these 
-				 * should go away.
-				 */
-
-				if (save_text && save_text->im_context) {
-					g_signal_handlers_disconnect_matched (save_text->im_context,
-									      G_SIGNAL_MATCH_DATA,
-                                                                             0, 0, NULL,
-                                                                             NULL, save_text);
-                                       save_text->im_context_signals_registered = FALSE;
-                                }
-
-				if (text->im_context) {
+			
+			/* Do we need the concept of saved_text anymore - No */
+			if (focus_event->in)
+			{
+				if (text->im_context && GTK_IS_IM_CONTEXT(text->im_context)) {
 					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",
 								  G_CALLBACK (e_text_delete_surrounding_cb), text);
 						text->im_context_signals_registered = TRUE;
+						
+						gtk_im_context_focus_in(text->im_context);
 					}
 				}
 				start_editing (text);
 				text->show_cursor = FALSE; /* so we'll redraw and the cursor will be shown */
-			} else {
-				/* Incase we are not disconnecting the signals 
-				 * for text, we are saving text for 
-				 * disconnecting in the next focus_in.
-				 */
-				if (!text->preedit_len && text->im_context) {
+			} 
+			else
+			{
+				/* If im_context exists, reset any preedit display & disconnect its signals */
+				if (text->im_context && GTK_IS_IM_CONTEXT(text->im_context))
+				{
+					/* We need this temp string because focus_out and im_reset seems to
+					change the committed text->text values. So the idea is to restore the
+					original value of text->text after gtk_im_* calls. */
+					
+					/* g_strdup will return NULL in worst case scenario. */
+					gchar *temp_text = g_strdup(text->text); 
+										
+					gtk_im_context_focus_out(text->im_context);
+					gtk_im_context_reset(text->im_context);					
 					g_signal_handlers_disconnect_matched (text->im_context,
 									      G_SIGNAL_MATCH_DATA,
 									      0, 0, NULL,
 									      NULL, text);
 					text->im_context_signals_registered = FALSE;
-				} else {
-					save_text = text;
+					
+					if (text->revert && text->text)
+					{
+						if (strcmp(text->revert, text->text) || text->preedit_len)
+						{
+							/* Time to update the EText string!
+							We are updating the EText display if current text does
+							not matches revert text of if preedit is not zero. */
+							e_text_model_set_text(text->model, temp_text);
+						}
+					}
+					
+					if (temp_text)
+						g_free (temp_text);
 				}
 
 				e_text_stop_editing (text);
 				if (text->timeout_id) {
 					g_source_remove(text->timeout_id);
 					text->timeout_id = 0;
 				}
 				if (text->show_cursor || text->draw_borders) {
