[evolution-patches] Changed gal patch for 44222
- From: Suresh Chandrasekharan <suresh chandrasekharan sun com>
- To: evolution-patches ximian com, sceri-evolution sun com
- Subject: [evolution-patches] Changed gal patch for 44222
- Date: Thu, 09 Oct 2003 14:50:11 -0700
Hi Mike Kestner,
I have redone the patch according to your feedback, which is attached,
pl. check it to see whether it is allright and lemme know.
Regards,
Suresh
? 44222.patch
? autom4te.cache
? cscope.out
? files
? docs/gal-api.html
? gal/e-table/.e-cell-text.c.swp
? gal/e-table/e-cell-text.c-2003-10-07-1042
? gal/e-table/e-cell-text.c-2003-10-09-0947
? gal/e-table/e-cell-text.c-2003-10-09-1125
? gal/e-table/e-cell-text.c-2003-10-09-1311
? gal/e-table/e-cell-text.c-2003-10-09-1408
? gal/e-table/e-table-item.c-2003-10-07-1029
? gal/e-table/nohup.out
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gal/ChangeLog,v
retrieving revision 1.800.2.5
diff -u -r1.800.2.5 ChangeLog
--- ChangeLog 12 Sep 2003 15:59:16 -0000 1.800.2.5
+++ ChangeLog 9 Oct 2003 21:44:37 -0000
@@ -1,3 +1,76 @@
+2003-09-25 Suresh Chandrasekharan <suresh chandrasekharan sun com>
+
+ * Fix for "44222 task summary entry widget not i18ned". The following
+ files are changed.
+
+ * gal/gal/e-table/e-cell-text.c: Lots of changes for i18n
+ selection/input support. Added these functions for input method support.
+
+ (e_cell_text_preedit_changed_cb)
+ (e_cell_text_commit_cb)
+ (e_cell_text_retrieve_surrounding_cb)
+ (e_cell_text_delete_surrounding_cb)
+
+ (layout_with_preedit) This function inserts the preedit string
+ with the right attribs to the layout text.
+
+ The following functions are modified.
+
+ (ect_stop_editing): disconnect signal handlers when editing stops
+
+ (ect_draw): Changes for including the preedit only to the currently
+ selected row/col. Also display the cursor at the end of preedit text.
+
+ (ect_event): Connects the IM callbacks to the key press event.
+ Disconnect when not in editing mode. Also a special flag to see
+ when Enter key pressed in preedit mode, the text is committed only
+ not a new row is created. This woks in conjunction with the changes
+ made in the eti_event in e-table-item.c file and e-cell.h.
+
+ (ect_height): Changes due to parameters changing for generate_layout
+
+ (ect_enter_edit): Initialization of im_context for a cell text and
+ assoociated flags.
+
+ (ect_max_width): Changes due to parameters changing for
+ generate_layout.
+
+ (ect_max_width_by_row): Changes due to parameters changing for
+ generate_layout.
+
+ (ect_show_tooltip): Changes due to parameters changing for
+ generate_layout.
+
+ (e_cell_text_construct): check whether paramters are NULL.
+
+ (get_position_from_xy): Changes due to parameters changing for
+ generate_layout.
+
+ (_insert): Set the selection_start as the minimum of strlen(edit->text)
+ and selection_start. Used to correct the preedit_string length
+ which may have added to the selection_start.
+
+ (e_cell_text_view_command): When inserting, if in the preedit mode
+ do not delete the selection.
+
+ (_selection_get): Set utf8 data instead of string data.
+
+ (_selection_received): Take in UTF8_ATOM inaddition to
+ GDK_SELECTION_TYPE_STRING.
+
+ (e_cell_text_view_get_selection): Make utf8 data when acting as a
+ selection source.
+
+ * gal/e-table/e-cell-text.h : Included <gtk/gtkmenu.h>
+
+ * gal/e-table/e-cell.h: Added enum E_CELL_PREEDIT to ECellFlags
+
+ * gal/e-table/e-table-item.c: (eti_event) Changes for not committing
+ the edited text as a seperate row in preedit mode.
+
+ * gal/e-table/e-table.c: (table_canvas_focus_event_cb) To have
+ proper im_context focus for the ecanvas holding the e-table.
+
2003-09-12 Mike Kestner <mkestner ximian com>
* configure.in : releasing 1.99.10
Index: gal/e-table/e-cell-text.c
===================================================================
RCS file: /cvs/gnome/gal/gal/e-table/e-cell-text.c,v
retrieving revision 1.130
diff -u -r1.130 e-cell-text.c
--- gal/e-table/e-cell-text.c 23 Jun 2003 20:30:22 -0000 1.130
+++ gal/e-table/e-cell-text.c 9 Oct 2003 21:44:37 -0000
@@ -96,6 +96,8 @@
#define PARENT_TYPE e_cell_get_type ()
+#define UTF8_ATOM gdk_atom_intern ("UTF8_STRING", FALSE)
+
#define TEXT_PAD 4
typedef struct {
@@ -177,6 +179,11 @@
guint pointer_in : 1;
guint default_cursor_shown : 1;
+ GtkIMContext *im_context;
+ gboolean need_im_reset;
+ gboolean im_context_signals_registered;
+
+ guint16 preedit_length; /* length of preedit string, in bytes */
ECellActions actions;
};
@@ -193,6 +200,12 @@
static void ect_free_color (gchar *color_spec, GdkColor *color, GdkColormap *colormap);
static GdkColor* e_cell_text_get_color (ECellTextView *cell_view, gchar *color_spec);
+static void e_cell_text_preedit_changed_cb (GtkIMContext *context, ECellTextView *text_view);
+static void e_cell_text_commit_cb (GtkIMContext *context, const gchar *str, ECellTextView *text_view);
+static gboolean e_cell_text_retrieve_surrounding_cb (GtkIMContext *context, ECellTextView *text_view);
+static gboolean e_cell_text_delete_surrounding_cb (GtkIMContext *context, gint offset, gint n_chars, ECellTextView *text_view);
+static void _insert (ECellTextView *text_view, char *string, int value);
+static void _delete_selection (ECellTextView *text_view);
static ECellClass *parent_class;
@@ -290,6 +303,11 @@
g_timer_destroy (edit->timer);
edit->timer = NULL;
}
+
+ g_signal_handlers_disconnect_matched (
+ edit->im_context,
+ G_SIGNAL_MATCH_DATA, 0, 0,
+ NULL, NULL, text_view);
if (edit->layout)
g_object_unref (edit->layout);
@@ -425,6 +443,98 @@
}
static PangoLayout *
+layout_with_preedit (ECellTextView *text_view, int row, const char *text, gint width)
+{
+ gboolean bold, strikeout, underline;
+ ECellView *ecell_view = (ECellView *) text_view;
+ ECellText *ect = E_CELL_TEXT (ecell_view->ecell);
+ CellEdit *edit = text_view->edit;
+ PangoLayout *layout;
+ GString *tmp_string = g_string_new (NULL);
+ PangoAttrList *preedit_attrs = NULL;
+ PangoAttrList *attrs = pango_attr_list_new ();
+ gchar *preedit_string = NULL;
+ gint preedit_length = 0;
+ gint length = strlen (text);
+ gint mlen = MIN(edit->selection_start,length);
+
+
+ gtk_im_context_get_preedit_string (edit->im_context,
+ &preedit_string,&preedit_attrs,
+ NULL);
+ preedit_length = edit->preedit_length = strlen (preedit_string);;
+
+ layout = edit->layout;
+ g_string_prepend_len (tmp_string, text,length);
+
+ if (preedit_length) {
+
+ /* mlen is the length in bytes, not chars
+ * check whether we are not inserting into
+ * the middle of a utf8 character
+ */
+
+ if (mlen < length) {
+ if (!g_utf8_validate (text+mlen, -1, NULL)) {
+ gchar *tc;
+ tc = g_utf8_find_next_char (text+mlen,NULL);
+ if (tc) {
+ mlen = (gint) (tc - text);
+ }
+ }
+ }
+
+ g_string_insert (tmp_string, mlen, preedit_string);
+ }
+
+ bold = ect->bold_column >= 0 &&
+ row >= 0 &&
+ e_table_model_value_at(ecell_view->e_table_model, ect->bold_column, row);
+ strikeout = ect->strikeout_column >= 0 &&
+ row >= 0 &&
+ e_table_model_value_at(ecell_view->e_table_model, ect->strikeout_column, row);
+ underline = ect->underline_column >= 0 &&
+ row >= 0 &&
+ e_table_model_value_at(ecell_view->e_table_model, ect->underline_column, row);
+
+ if (bold || strikeout || underline) {
+ if (bold) {
+ PangoAttribute *attr = pango_attr_weight_new (PANGO_WEIGHT_BOLD);
+ attr->start_index = 0;
+ attr->end_index = length;
+
+ pango_attr_list_insert_before (attrs, attr);
+ }
+ if (strikeout) {
+ PangoAttribute *attr = pango_attr_strikethrough_new (TRUE);
+ attr->start_index = 0;
+ attr->end_index = length;
+
+ pango_attr_list_insert_before (attrs, attr);
+ }
+ if (underline) {
+ PangoAttribute *attr = pango_attr_underline_new (TRUE);
+ attr->start_index = 0;
+ attr->end_index = length;
+
+ pango_attr_list_insert_before (attrs, attr);
+ }
+ }
+
+ pango_layout_set_text (layout, tmp_string->str, tmp_string->len);
+ if (preedit_length)
+ pango_attr_list_splice (attrs, preedit_attrs, mlen, preedit_length);
+ pango_layout_set_attributes (layout, attrs);
+ g_string_free (tmp_string, TRUE);
+ if (preedit_string)
+ g_free (preedit_string);
+ if (preedit_attrs)
+ pango_attr_list_unref (preedit_attrs);
+ pango_attr_list_unref (attrs);
+ return layout;
+}
+
+static PangoLayout *
build_layout (ECellTextView *text_view, int row, const char *text, gint width)
{
ECellView *ecell_view = (ECellView *) text_view;
@@ -533,6 +643,7 @@
return layout;
}
+
static void
draw_pango_rectangle (GdkDrawable *drawable, GdkGC *gc, int x1, int y1, PangoRectangle rect)
{
@@ -648,6 +759,10 @@
layout = generate_layout (text_view, model_col, view_col, row, x2 - x1);
+ if (edit && edit->view_col == view_col && edit->row == row) {
+ layout = layout_with_preedit (text_view, row, edit->text ? edit->text : "?", x2 - x1);
+ }
+
gdk_draw_layout (drawable, text_view->gc,
x_origin, y_origin,
layout);
@@ -713,7 +828,8 @@
} else {
if (edit->show_cursor) {
PangoRectangle strong_pos, weak_pos;
- pango_layout_get_cursor_pos (layout, edit->selection_start, &strong_pos, &weak_pos);
+ pango_layout_get_cursor_pos (layout, edit->selection_start + edit->preedit_length, &strong_pos, &weak_pos);
+
draw_pango_rectangle (drawable, text_view->gc, x_origin, y_origin, strong_pos);
if (strong_pos.x != weak_pos.x ||
strong_pos.y != weak_pos.y ||
@@ -749,6 +865,7 @@
/*
* Selects the entire string
*/
+
static void
ect_edit_select_all (ECellTextView *text_view)
{
@@ -774,8 +891,10 @@
ect_event (ECellView *ecell_view, GdkEvent *event, int model_col, int view_col, int row, ECellFlags flags, ECellActions *actions)
{
ECellTextView *text_view = (ECellTextView *) ecell_view;
+ ECellText *ect = (ECellText *) ((ECellView *)text_view)->ecell;
ETextEventProcessorEvent e_tep_event;
gboolean edit_display = FALSE;
+ gint preedit_len;
CellEdit *edit = text_view->edit;
GtkWidget *canvas = GTK_WIDGET (text_view->canvas);
gint return_val = 0;
@@ -793,7 +912,70 @@
case GDK_FOCUS_CHANGE:
break;
case GDK_KEY_PRESS: /* Fall Through */
+ if (edit_display) {
+ if (edit->im_context &&
+ !edit->im_context_signals_registered) {
+
+ g_signal_connect (edit->im_context,
+ "preedit_changed",
+ G_CALLBACK (\
+ e_cell_text_preedit_changed_cb),
+ text_view);
+
+ g_signal_connect (edit->im_context,
+ "commit",
+ G_CALLBACK (\
+ e_cell_text_commit_cb),
+ text_view);
+
+ g_signal_connect (edit->im_context,
+ "retrieve_surrounding",
+ G_CALLBACK (\
+ e_cell_text_retrieve_surrounding_cb),
+ text_view);
+
+ g_signal_connect (edit->im_context,
+ "delete_surrounding",
+ G_CALLBACK (\
+ e_cell_text_delete_surrounding_cb),
+ text_view);
+
+ edit->im_context_signals_registered = TRUE;
+ }
+
+ edit->show_cursor = FALSE;
+
+ } else {
+ if (edit->im_context) {
+ g_signal_handlers_disconnect_matched (
+ edit->im_context,
+ G_SIGNAL_MATCH_DATA, 0, 0,
+ NULL, NULL, edit);
+ edit->im_context_signals_registered = FALSE;
+ }
+
+ ect_stop_editing (text_view, TRUE);
+ if (edit->timeout_id) {
+ g_source_remove(edit->timeout_id);
+ edit->timeout_id = 0;
+ }
+ }
+ return_val = TRUE;
+ /* Fallthrough */
case GDK_KEY_RELEASE:
+ preedit_len = edit->preedit_length;
+ if (edit_display && edit->im_context &&
+ gtk_im_context_filter_keypress (\
+ edit->im_context,
+ (GdkEventKey*)event)) {
+
+ edit->need_im_reset = TRUE;
+ if (preedit_len && flags & E_CELL_PREEDIT)
+ return FALSE;
+ else
+ return TRUE;
+ }
+
if (event->key.keyval == GDK_Escape){
ect_cancel_edit (text_view);
return_val = TRUE;
@@ -829,12 +1011,10 @@
e_tep_event.key.length = 0;
}
#endif
-
_get_tep (edit);
- edit->actions = 0;
return_val = e_text_event_processor_handle_event (edit->tep, &e_tep_event);
- *actions = edit->actions;
- if (e_tep_event.key.string) g_free (e_tep_event.key.string);
+ if (e_tep_event.key.string)
+ g_free (e_tep_event.key.string);
break;
}
}
@@ -944,15 +1124,7 @@
break;
}
- if (return_val)
- return return_val;
-#if 0
- if (GNOME_CANVAS_ITEM_CLASS(parent_class)->event)
- return GNOME_CANVAS_ITEM_CLASS(parent_class)->event (item, event);
-#endif
- else
- return 0;
-
+ return return_val;
}
/*
@@ -985,6 +1157,9 @@
edit = g_new0 (CellEdit, 1);
text_view->edit = edit;
+ edit->im_context = E_CANVAS (text_view->canvas)->im_context;
+ edit->need_im_reset = FALSE;
+ edit->im_context_signals_registered = FALSE;
edit->view_col = -1;
edit->model_col = -1;
edit->row = -1;
@@ -1045,7 +1220,6 @@
}
}
#endif
-
ect_queue_redraw (text_view, view_col, row);
return NULL;
@@ -1566,6 +1740,77 @@
}
}
+
+/* IM Context Callbacks */
+
+static void
+e_cell_text_preedit_changed_cb (GtkIMContext *context,
+ ECellTextView *tv)
+{
+ gchar *preedit_string;
+ gint cursor_pos;
+ CellEdit *edit=tv->edit;
+ gtk_im_context_get_preedit_string (edit->im_context, &preedit_string,
+ NULL, &cursor_pos);
+
+ edit->preedit_length = strlen (preedit_string);
+ cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
+ g_free (preedit_string);
+ ect_queue_redraw (tv, edit->view_col, edit->row);
+}
+
+static void
+e_cell_text_commit_cb (GtkIMContext *context,
+ const gchar *str,
+ ECellTextView *tv)
+{
+ CellEdit *edit = tv->edit;
+ ECellText *ect = (ECellText *) ((ECellView *)tv)->ecell;
+ ETextEventProcessorCommand command;
+
+ if (g_utf8_validate (str, strlen (str), NULL)) {
+ command.action = E_TEP_INSERT;
+ command.position = E_TEP_SELECTION;
+ command.string = (gchar *)str;
+ command.value = strlen(str);
+ e_cell_text_view_command (edit->tep, &command, edit);
+ }
+
+}
+
+static gboolean
+e_cell_text_retrieve_surrounding_cb (GtkIMContext *context,
+ ECellTextView *tv)
+{
+ int cur_pos = 0;
+ CellEdit *edit = tv->edit;
+
+ cur_pos = g_utf8_pointer_to_offset (edit->text, edit->text + edit->selection_start);
+
+ gtk_im_context_set_surrounding (context,
+ edit->text,
+ strlen (edit->text),
+ cur_pos
+ );
+
+ return TRUE;
+}
+
+static gboolean
+e_cell_text_delete_surrounding_cb (GtkIMContext *context,
+ gint offset,
+ gint n_chars,
+ ECellTextView *tv)
+{
+ CellEdit *edit = tv->edit;
+
+ gtk_editable_delete_text (GTK_EDITABLE (edit),
+ edit->selection_end + offset,
+ edit->selection_end + offset + n_chars);
+
+ return TRUE;
+}
+
static void
e_cell_text_init (ECellText *ect)
{
@@ -1595,7 +1840,10 @@
ECell *
e_cell_text_construct (ECellText *cell, const char *fontname, GtkJustification justify)
{
- cell->font_name = g_strdup (fontname);
+ if(!cell)
+ return E_CELL(NULL);
+ if(fontname)
+ cell->font_name = g_strdup (fontname);
cell->justify = justify;
return E_CELL(cell);
}
@@ -1645,6 +1893,7 @@
int index;
int trailing;
const char *text;
+
PangoLayout *layout = generate_layout (edit->text_view, edit->model_col, edit->view_col, edit->row, edit->cell_width);
ECellTextView *text_view = edit->text_view;
ECellText *ect = (ECellText *) ((ECellView *)text_view)->ecell;
@@ -1932,6 +2181,8 @@
if (value <= 0) return;
+ edit->selection_start = MIN (strlen(edit->text), edit->selection_start);
+
temp = g_new (gchar, strlen (edit->text) + value + 1);
strncpy (temp, edit->text, edit->selection_start);
@@ -2052,7 +2303,7 @@
break;
case E_TEP_INSERT:
- if (edit->selection_end != edit->selection_start) {
+ if (!edit->preedit_length && edit->selection_end != edit->selection_start) {
_delete_selection (text_view);
}
_insert (text_view, command->string, command->value);
@@ -2173,12 +2424,14 @@
{
switch (info) {
case E_SELECTION_PRIMARY:
- gtk_selection_data_set (selection_data, GDK_SELECTION_TYPE_STRING,
- 8, edit->primary_selection, edit->primary_length);
+ gtk_selection_data_set (selection_data, UTF8_ATOM,
+ 8, edit->primary_selection,
+ edit->primary_length);
break;
case E_SELECTION_CLIPBOARD:
- gtk_selection_data_set (selection_data, GDK_SELECTION_TYPE_STRING,
- 8, edit->clipboard_selection, edit->clipboard_length);
+ gtk_selection_data_set (selection_data, UTF8_ATOM,
+ 8, edit->clipboard_selection,
+ edit->clipboard_length);
break;
}
}
@@ -2191,7 +2444,9 @@
guint time,
CellEdit *edit)
{
- if (selection_data->length < 0 || selection_data->type != GDK_SELECTION_TYPE_STRING) {
+ if (selection_data->length < 0 ||
+ !(selection_data->type == UTF8_ATOM ||
+ selection_data->type == GDK_SELECTION_TYPE_STRING)) {
return;
} else {
ETextEventProcessorCommand command;
@@ -2212,11 +2467,11 @@
gtk_selection_add_target (invisible,
GDK_SELECTION_PRIMARY,
- GDK_SELECTION_TYPE_STRING,
+ UTF8_ATOM,
E_SELECTION_PRIMARY);
gtk_selection_add_target (invisible,
clipboard_atom,
- GDK_SELECTION_TYPE_STRING,
+ UTF8_ATOM,
E_SELECTION_CLIPBOARD);
g_signal_connect (invisible, "selection_get",
@@ -2273,7 +2528,7 @@
invisible = e_cell_text_view_get_invisible (edit);
gtk_selection_convert (invisible,
selection,
- GDK_SELECTION_TYPE_STRING,
+ UTF8_ATOM,
time);
#endif
}
Index: gal/e-table/e-cell-text.h
===================================================================
RCS file: /cvs/gnome/gal/gal/e-table/e-cell-text.h,v
retrieving revision 1.30
diff -u -r1.30 e-cell-text.h
--- gal/e-table/e-cell-text.h 18 Mar 2003 20:49:59 -0000 1.30
+++ gal/e-table/e-cell-text.h 9 Oct 2003 21:44:37 -0000
@@ -36,7 +36,7 @@
#ifndef _E_CELL_TEXT_H_
#define _E_CELL_TEXT_H_
-
+#include <gtk/gtkmenu.h>
#include <libgnomecanvas/gnome-canvas.h>
#include <gal/e-table/e-cell.h>
Index: gal/e-table/e-cell.h
===================================================================
RCS file: /cvs/gnome/gal/gal/e-table/e-cell.h,v
retrieving revision 1.36
diff -u -r1.36 e-cell.h
--- gal/e-table/e-cell.h 17 Nov 2002 00:02:53 -0000 1.36
+++ gal/e-table/e-cell.h 9 Oct 2003 21:44:37 -0000
@@ -59,7 +59,9 @@
E_CELL_EDITING = 1 << 4,
- E_CELL_CURSOR = 1 << 5
+ E_CELL_CURSOR = 1 << 5,
+
+ E_CELL_PREEDIT = 1 << 6
} ECellFlags;
typedef enum {
Index: gal/e-table/e-table-item.c
===================================================================
RCS file: /cvs/gnome/gal/gal/e-table/e-table-item.c,v
retrieving revision 1.224
diff -u -r1.224 e-table-item.c
--- gal/e-table/e-table-item.c 13 Jun 2003 22:27:03 -0000 1.224
+++ gal/e-table/e-table-item.c 9 Oct 2003 21:44:37 -0000
@@ -2684,18 +2684,17 @@
case GDK_ISO_Enter:
case GDK_3270_Enter:
if (eti_editing (eti)){
- e_table_item_leave_edit_(eti);
-#if 0
ecell_view = eti->cell_views [eti->editing_col];
return_val = eti_e_cell_event (eti, ecell_view, e, e->key.time,
- view_to_model_col(eti, eti->editing_col),
- eti->editing_col, eti->editing_row, E_CELL_EDITING | E_CELL_CURSOR);
-#endif
+ view_to_model_col (eti, eti->editing_col),
+ eti->editing_col, eti->editing_row, E_CELL_EDITING | E_CELL_CURSOR | E_CELL_PREEDIT);
+ if (!return_val)
+ break;
}
g_signal_emit (eti, eti_signals [KEY_PRESS], 0,
- model_to_view_row(eti, cursor_row), cursor_col, e, &return_val);
+ model_to_view_row (eti, cursor_row), cursor_col, e, &return_val);
if (!return_val)
- return_val = e_selection_model_key_press(E_SELECTION_MODEL (eti->selection), (GdkEventKey *) e);
+ return_val = e_selection_model_key_press (E_SELECTION_MODEL (eti->selection), (GdkEventKey *) e);
break;
default:
Index: gal/e-table/e-table.c
===================================================================
RCS file: /cvs/gnome/gal/gal/e-table/e-table.c,v
retrieving revision 1.225
diff -u -r1.225 e-table.c
--- gal/e-table/e-table.c 1 Jul 2003 13:16:43 -0000 1.225
+++ gal/e-table/e-table.c 9 Oct 2003 21:44:38 -0000
@@ -1099,14 +1099,20 @@
table_canvas_focus_event_cb (GtkWidget *widget, GdkEventFocus *event, gpointer data)
{
GnomeCanvas *canvas;
+ ECanvas *ecanvas;
ETable *etable;
gtk_widget_queue_draw (widget);
+ canvas = GNOME_CANVAS (widget);
+ ecanvas = E_CANVAS (widget);
- if (!event->in)
+ if (!event->in) {
+ gtk_im_context_focus_out(ecanvas->im_context);
return TRUE;
+ } else {
+ gtk_im_context_focus_in(ecanvas->im_context);
+ }
- canvas = GNOME_CANVAS (widget);
etable = E_TABLE (data);
if (!canvas->focused_item && etable->group)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]