Matthew Barnes e1b66c
--- evolution-2.7.4/widgets/table/e-cell-text.c.task	2006-07-13 10:56:19.000000000 -0400
Matthew Barnes e1b66c
+++ evolution-2.7.4/widgets/table/e-cell-text.c	2006-07-13 10:56:27.000000000 -0400
Matthew Barnes e1b66c
@@ -199,6 +199,7 @@
Matthew Barnes e1b66c
 	gboolean im_context_signals_registered;
Matthew Barnes e1b66c
 
Matthew Barnes e1b66c
 	guint16 preedit_length;       /* length of preedit string, in bytes */
Matthew Barnes e1b66c
+	gint preedit_pos;             /* position of preedit cursor */
Matthew Barnes e1b66c
 
Matthew Barnes e1b66c
 	ECellActions actions;
Matthew Barnes e1b66c
 };
Matthew Barnes e1b66c
@@ -222,6 +223,7 @@
Matthew Barnes e1b66c
 static void _insert (ECellTextView *text_view, char *string, int value);
Matthew Barnes e1b66c
 static void _delete_selection (ECellTextView *text_view);
Matthew Barnes e1b66c
 static PangoAttrList* build_attr_list (ECellTextView *text_view, int row, int text_length);
Matthew Barnes e1b66c
+static void update_im_cursor_location (ECellTextView *tv);
Matthew Barnes e1b66c
 
Matthew Barnes e1b66c
 static ECellClass *parent_class;
Matthew Barnes e1b66c
 
Matthew Barnes e1b66c
@@ -560,6 +562,9 @@
Matthew Barnes e1b66c
 	if (preedit_attrs)
Matthew Barnes e1b66c
 		pango_attr_list_unref (preedit_attrs);
Matthew Barnes e1b66c
 	pango_attr_list_unref (attrs);
Matthew Barnes e1b66c
+
Matthew Barnes e1b66c
+	update_im_cursor_location (text_view);
Matthew Barnes e1b66c
+
Matthew Barnes e1b66c
 	return layout;
Matthew Barnes e1b66c
 }
Matthew Barnes e1b66c
 
Matthew Barnes e1b66c
@@ -1863,6 +1868,66 @@
Matthew Barnes e1b66c
 /* IM Context Callbacks */
Matthew Barnes e1b66c
 
Matthew Barnes e1b66c
 static void
Matthew Barnes e1b66c
+e_cell_text_get_cursor_locations (ECellTextView *tv,
Matthew Barnes e1b66c
+				  GdkRectangle *strong_pos,
Matthew Barnes e1b66c
+				  GdkRectangle *weak_pos)
Matthew Barnes e1b66c
+{
Matthew Barnes e1b66c
+	GdkRectangle area;
Matthew Barnes e1b66c
+	CellEdit *edit=tv->edit;
Matthew Barnes e1b66c
+	ECellView *cell_view = (ECellView *)tv;
Matthew Barnes e1b66c
+	ETableItem *item = E_TABLE_ITEM ((cell_view)->e_table_item_view);
Matthew Barnes e1b66c
+	GnomeCanvasItem *parent_item = GNOME_CANVAS_ITEM (item)->parent;
Matthew Barnes e1b66c
+	PangoRectangle pango_strong_pos;
Matthew Barnes e1b66c
+	PangoRectangle pango_weak_pos;
Matthew Barnes e1b66c
+	gint x, y, col, row;
Matthew Barnes e1b66c
+	gdouble x1,y1;
Matthew Barnes e1b66c
+	gint cx, cy;
Matthew Barnes e1b66c
+	gint index;
Matthew Barnes e1b66c
+
Matthew Barnes e1b66c
+	row = edit->row;
Matthew Barnes e1b66c
+	col = edit->view_col;
Matthew Barnes e1b66c
+
Matthew Barnes e1b66c
+	e_table_item_get_cell_geometry (item, &row, &col,
Matthew Barnes e1b66c
+					&x, &y, NULL, &area.height);
Matthew Barnes e1b66c
+
Matthew Barnes e1b66c
+	gnome_canvas_item_get_bounds (GNOME_CANVAS_ITEM (parent_item), &x1, &y1, NULL, NULL);
Matthew Barnes e1b66c
+	
Matthew Barnes e1b66c
+	gnome_canvas_get_scroll_offsets (GNOME_CANVAS (GNOME_CANVAS_ITEM (parent_item)->canvas), &cx, &cy);
Matthew Barnes e1b66c
+
Matthew Barnes e1b66c
+	index = edit->selection_end + edit->preedit_pos;
Matthew Barnes e1b66c
+
Matthew Barnes e1b66c
+	pango_layout_get_cursor_pos (edit->layout, 
Matthew Barnes e1b66c
+				     index,
Matthew Barnes e1b66c
+				     strong_pos ? &pango_strong_pos : NULL,
Matthew Barnes e1b66c
+				     weak_pos ? &pango_weak_pos : NULL);
Matthew Barnes e1b66c
+
Matthew Barnes e1b66c
+	if (strong_pos) {
Matthew Barnes e1b66c
+		strong_pos->x = x + x1 - cx - edit->xofs_edit + pango_strong_pos.x / PANGO_SCALE;
Matthew Barnes e1b66c
+		strong_pos->y = y + y1 - cy - edit->yofs_edit + pango_strong_pos.y / PANGO_SCALE;
Matthew Barnes e1b66c
+		strong_pos->width = 0;
Matthew Barnes e1b66c
+		strong_pos->height = pango_strong_pos.height / PANGO_SCALE;
Matthew Barnes e1b66c
+	}
Matthew Barnes e1b66c
+
Matthew Barnes e1b66c
+	if (weak_pos) {
Matthew Barnes e1b66c
+		weak_pos->x = x + x1 - cx - edit->xofs_edit + pango_weak_pos.x / PANGO_SCALE;
Matthew Barnes e1b66c
+		weak_pos->y = y + y1 - cy - edit->yofs_edit + pango_weak_pos.y / PANGO_SCALE;
Matthew Barnes e1b66c
+		weak_pos->width = 0;
Matthew Barnes e1b66c
+		weak_pos->height = pango_weak_pos.height / PANGO_SCALE;
Matthew Barnes e1b66c
+	}
Matthew Barnes e1b66c
+}
Matthew Barnes e1b66c
+
Matthew Barnes e1b66c
+static void
Matthew Barnes e1b66c
+update_im_cursor_location (ECellTextView *tv)
Matthew Barnes e1b66c
+{
Matthew Barnes e1b66c
+	CellEdit *edit=tv->edit;
Matthew Barnes e1b66c
+	GdkRectangle area;
Matthew Barnes e1b66c
+	
Matthew Barnes e1b66c
+	e_cell_text_get_cursor_locations (tv, &area, NULL);
Matthew Barnes e1b66c
+
Matthew Barnes e1b66c
+	gtk_im_context_set_cursor_location (edit->im_context, &area);
Matthew Barnes e1b66c
+}
Matthew Barnes e1b66c
+
Matthew Barnes e1b66c
+static void
Matthew Barnes e1b66c
 e_cell_text_preedit_changed_cb (GtkIMContext *context,
Matthew Barnes e1b66c
 		  ECellTextView    *tv)
Matthew Barnes e1b66c
 {
Matthew Barnes e1b66c
@@ -1871,10 +1936,12 @@
Matthew Barnes e1b66c
 	CellEdit *edit=tv->edit;
Matthew Barnes e1b66c
 	gtk_im_context_get_preedit_string (edit->im_context, &preedit_string, 
Matthew Barnes e1b66c
 					NULL, &cursor_pos);
Matthew Barnes e1b66c
-	                                                  
Matthew Barnes e1b66c
+
Matthew Barnes e1b66c
 	edit->preedit_length = strlen (preedit_string);
Matthew Barnes e1b66c
-	cursor_pos =  CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1)); 
Matthew Barnes e1b66c
+	cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
Matthew Barnes e1b66c
+	edit->preedit_pos = g_utf8_offset_to_pointer (preedit_string, cursor_pos) - preedit_string;
Matthew Barnes e1b66c
 	g_free (preedit_string);
Matthew Barnes e1b66c
+
Matthew Barnes e1b66c
 	ect_queue_redraw (tv, edit->view_col, edit->row);
Matthew Barnes e1b66c
 }
Matthew Barnes e1b66c