Hi, In this patch, a gconf key is added (/apps/evolution/mail/display/caret_mode). And a checkbox is added in the preference setting corresponding to the option. The code is in evolution.diff. The attached pref.png is the screenshot, need Anna review? At gtkhtml side, a new style property is also added. In the 'style-set' signal handler we change the gboolean var added into the htmlengine struct, and we use it to control whether to draw cusor. Other part is the same to previous patch. I decide to remove the F7, because all other gconf key settings are handled by prefrence setting dialog. so I think we keep the processsing of gconf settings consistent, and not just mimic mozilla. So Radek and Ettore, you opinion? I have tested the patch. Regards York On Sun, 2003-06-22 at 18:23, Radek Doul? wrote: > On Sat, 2003-06-21 at 17:21, Ettore Perazzoli wrote: > > On Fri, 2003-06-20 at 22:45, yuedong du wrote: > > > We agree to use F7 to enable caret mode. > > > > > > But, what is the best form the option should be implemented as ? Global > > > variable or gconf ? Global variable means the setting will not be saved > > > after you exit evolution. A little inconvinience. > > > > I thought F7 was just supposed to work per-session? > > mozilla remembers it for the next session, so it could make sense to > save it to gconf? I can imagine that user who want this feature would > like to have it enabled all the time. > > I think this setting should be handled in evolution and set by gtkhtml > style property as fonts and other things? > > cheers > Radek > >
Attachment:
pref.png
Description: PNG image
Index: mail/evolution-mail.schemas =================================================================== RCS file: /cvs/gnome/evolution/mail/evolution-mail.schemas,v retrieving revision 1.15 diff -u -r1.15 evolution-mail.schemas --- mail/evolution-mail.schemas 20 May 2003 18:33:32 -0000 1.15 +++ mail/evolution-mail.schemas 25 Jun 2003 05:57:46 -0000 @@ -174,6 +174,20 @@ </schema> <schema> + <key>/schemas/apps/evolution/mail/display/caret_mode</key> + <applyto>/apps/evolution/mail/display/caret_mode</applyto> + <owner>evolution-mail</owner> + <type>boolean</type> + <default>false</default> + <locale name="C"> + <short>Enable/disable caret mode</short> + <long> + Enable caret mode, so that you can see a cursor when reading mail. + </long> + </locale> + </schema> + + <schema> <key>/schemas/apps/evolution/mail/display/load_http_images</key> <applyto>/apps/evolution/mail/display/load_http_images</applyto> <owner>evolution-mail</owner> Index: mail/mail-config.c =================================================================== RCS file: /cvs/gnome/evolution/mail/mail-config.c,v retrieving revision 1.280 diff -u -r1.280 mail-config.c --- mail/mail-config.c 11 Jun 2003 16:19:34 -0000 1.280 +++ mail/mail-config.c 25 Jun 2003 05:57:56 -0000 @@ -85,6 +85,7 @@ guint font_notify_id; guint spell_notify_id; + guint caret_mode_notify_id; GPtrArray *mime_types; guint mime_types_notify_id; @@ -435,6 +436,7 @@ char *fix_font; char *var_font; gint red, green, blue; + gboolean caret_mode; /* * This is the wrong way to get the path but it needs to @@ -461,8 +463,10 @@ red = gconf_client_get_int (config->gconf, "/GNOME/Spell/spell_error_color_red", NULL); green = gconf_client_get_int (config->gconf, "/GNOME/Spell/spell_error_color_green", NULL); blue = gconf_client_get_int (config->gconf, "/GNOME/Spell/spell_error_color_blue", NULL); + caret_mode = gconf_client_get_bool (config->gconf, "/apps/evolution/mail/display/caret_mode", NULL); fprintf (rc, "style \"evolution-mail-custom-fonts\" {\n"); + fprintf (rc, " GtkHTML::caret_mode = %d\n", caret_mode ? 1 :0); fprintf (rc, " GtkHTML::spell_error_color = \"#%02x%02x%02x\"\n", red >> 8, green >> 8, blue >> 8); @@ -536,6 +540,8 @@ gconf_style_changed, NULL, NULL, NULL); config->spell_notify_id = gconf_client_notify_add (config->gconf, "/GNOME/Spell", gconf_style_changed, NULL, NULL, NULL); + config->caret_mode_notify_id = gconf_client_notify_add (config->gconf, "/apps/evolution/mail/display/caret_mode", + gconf_style_changed, NULL, NULL, NULL); gconf_client_add_dir (config->gconf, "/apps/evolution/mail/labels", GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); Index: mail/mail-config.glade =================================================================== RCS file: /cvs/gnome/evolution/mail/mail-config.glade,v retrieving revision 1.120 diff -u -r1.120 mail-config.glade --- mail/mail-config.glade 21 May 2003 15:26:24 -0000 1.120 +++ mail/mail-config.glade 25 Jun 2003 05:58:22 -0000 @@ -3499,6 +3499,24 @@ <property name="fill">True</property> </packing> </child> + + <child> + <widget class="GtkCheckButton" id="caret_mode"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="label" translatable="yes">_Enable caret mode (show cursor when reading mail)</property> + <property name="use_underline">True</property> + <property name="relief">GTK_RELIEF_NORMAL</property> + <property name="active">False</property> + <property name="inconsistent">False</property> + <property name="draw_indicator">True</property> + </widget> + <packing> + <property name="padding">0</property> + <property name="expand">False</property> + <property name="fill">False</property> + </packing> + </child> </widget> </child> Index: mail/mail-preferences.c =================================================================== RCS file: /cvs/gnome/evolution/mail/mail-preferences.c,v retrieving revision 1.32 diff -u -r1.32 mail-preferences.c --- mail/mail-preferences.c 11 Jun 2003 16:19:36 -0000 1.32 +++ mail/mail-preferences.c 25 Jun 2003 05:58:23 -0000 @@ -255,6 +255,11 @@ colorpicker_set_color (prefs->citation_color, buf ? buf : "#737373"); g_signal_connect (prefs->citation_color, "color-set", G_CALLBACK (color_set), prefs); g_free (buf); + + prefs->caret_mode = GTK_TOGGLE_BUTTON(glade_xml_get_widget(gui, "caret_mode")); + bool = gconf_client_get_bool (prefs->gconf, "/apps/evolution/mail/display/caret_mode", NULL); + gtk_toggle_button_set_active (prefs->caret_mode, bool); + g_signal_connect (prefs->caret_mode, "toggled", G_CALLBACK (settings_changed), prefs); /* Deleting Mail */ prefs->empty_trash = GTK_TOGGLE_BUTTON (glade_xml_get_widget (gui, "chkEmptyTrashOnExit")); @@ -408,6 +413,8 @@ sprintf (buf,"#%06x", rgb & 0xffffff); gconf_client_set_string (prefs->gconf, "/apps/evolution/mail/display/citation_colour", buf, NULL); + gconf_client_set_bool (prefs->gconf, "/apps/evolution/mail/display/caret_mode", + gtk_toggle_button_get_active (prefs->caret_mode), NULL); /* Deleting Mail */ gconf_client_set_bool (prefs->gconf, "/apps/evolution/mail/trash/empty_on_exit", gtk_toggle_button_get_active (prefs->empty_trash), NULL); Index: mail/mail-preferences.h =================================================================== RCS file: /cvs/gnome/evolution/mail/mail-preferences.h,v retrieving revision 1.11 diff -u -r1.11 mail-preferences.h --- mail/mail-preferences.h 20 May 2003 18:33:33 -0000 1.11 +++ mail/mail-preferences.h 25 Jun 2003 05:58:23 -0000 @@ -67,6 +67,7 @@ GtkOptionMenu *charset; GtkToggleButton *citation_highlight; GnomeColorPicker *citation_color; + GtkToggleButton *caret_mode; /* Deleting Mail */ GtkToggleButton *empty_trash;
Index: src/gtkhtml.c =================================================================== RCS file: /cvs/gnome/gtkhtml/src/gtkhtml.c,v retrieving revision 1.516 diff -u -4 -r1.516 gtkhtml.c --- src/gtkhtml.c 13 Jun 2003 21:42:59 -0000 1.516 +++ src/gtkhtml.c 25 Jun 2003 06:21:26 -0000 @@ -719,8 +719,22 @@ if (GTK_OBJECT_CLASS (parent_class)->destroy != NULL) (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); } +static void +set_caret_mode(GtkHTML *html, gboolean caret_mode) +{ + g_assert(html->engine); + g_return_if_fail (!html->engine->editable); + + if (caret_mode) + html->engine->caret_mode = TRUE; + else + html->engine->caret_mode = FALSE; + + return; +} + /* GtkWidget methods. */ static void style_set (GtkWidget *widget, GtkStyle *previous_style) { @@ -729,8 +743,9 @@ char *fixed_name = NULL; gint fixed_size = 0; char *font_var = NULL; gint font_var_size = 0; + gboolean caret_mode = FALSE; /* we don't need to set font's in idle time so call idle callback directly to avoid recalculating whole document */ @@ -765,13 +780,16 @@ html_object_change_set_down (engine->clue, HTML_CHANGE_ALL); html_engine_calc_size (engine, FALSE); html_engine_schedule_update (engine); } + g_free (fixed_name); g_free (font_var); } + gtk_widget_style_get (widget, "caret_mode", &caret_mode, NULL); + set_caret_mode(GTK_HTML(widget), caret_mode); html_colorset_set_style (engine->defaultSettings->color_set, widget); html_colorset_set_unchanged (engine->settings->color_set, engine->defaultSettings->color_set); @@ -1476,10 +1494,12 @@ NULL, FALSE); if (obj && ((HTML_IS_IMAGE (obj) && HTML_IMAGE (obj)->url && *HTML_IMAGE (obj)->url) || HTML_IS_LINK_TEXT (obj))) html_engine_set_focus_object (orig_e, obj); - else + else { html_engine_set_focus_object (orig_e, NULL); + html_engine_jump_at (engine, x, y); + } } if (html->allow_selection) { if (event->state & GDK_SHIFT_MASK) html_engine_select_region (engine, @@ -2597,8 +2617,14 @@ _("The color of the spelling error markers"), GDK_TYPE_COLOR, G_PARAM_READABLE)); + gtk_widget_class_install_style_property (widget_class, + g_param_spec_boxed ("caret_mode", + _("Caret Mode"), + _("Enable cursor when reading mail"), + G_TYPE_BOOLEAN, + G_PARAM_READABLE)); widget_class->realize = realize; widget_class->unrealize = unrealize; widget_class->style_set = style_set; widget_class->key_press_event = key_press_event; @@ -3786,10 +3812,8 @@ cursor_move (GtkHTML *html, GtkDirectionType dir_type, GtkHTMLCursorSkipType skip) { gint amount; - if (!html_engine_get_editable (html->engine)) - return; if (html->engine->selection_mode) { if (!html->engine->mark) html_engine_set_mark (html->engine); Index: src/htmlengine-edit-cursor.c =================================================================== RCS file: /cvs/gnome/gtkhtml/src/htmlengine-edit-cursor.c,v retrieving revision 1.22 diff -u -4 -r1.22 htmlengine-edit-cursor.c --- src/htmlengine-edit-cursor.c 2 Apr 2003 05:41:47 -0000 1.22 +++ src/htmlengine-edit-cursor.c 25 Jun 2003 06:21:27 -0000 @@ -28,8 +28,9 @@ #include "htmlengine-edit-cursor.h" #include "htmlengine-edit-table.h" #include "htmlengine-edit-tablecell.h" #include "htmlimage.h" +#include "htmliframe.h" #include "htmlobject.h" #include "htmltable.h" #define BLINK_TIMEOUT 500 @@ -46,39 +47,82 @@ static GdkColor image_stipple_active_on = { 0, 0xffff, 0, 0 }; static GdkColor image_stipple_active_off = { 0, 0xffff, 0xffff, 0xffff }; +static HTMLEngine * +get_direct_engine(HTMLObject * obj) +{ + HTMLObject * parent; + int i = 0; + + parent = obj; + while (parent) { + if ((HTML_OBJECT_TYPE (parent) == HTML_TYPE_FRAME) + || (HTML_OBJECT_TYPE (parent) == HTML_TYPE_IFRAME)) { + return html_object_get_engine (parent, NULL); + } + parent = parent->parent; + } + + return NULL; +} + void html_engine_hide_cursor (HTMLEngine *engine) { + HTMLEngine *e = engine; + g_return_if_fail (engine != NULL); g_return_if_fail (HTML_IS_ENGINE (engine)); - if (engine->editable && engine->cursor_hide_count == 0) - html_engine_draw_cursor_in_area (engine, 0, 0, -1, -1); + if ((engine->editable || engine->caret_mode) && engine->cursor_hide_count == 0) { + if (!engine->editable) { + e = get_direct_engine(engine->cursor->object); + if (e) { + e->caret_mode = engine->caret_mode; + html_cursor_copy(e->cursor, engine->cursor); + } else e = engine; + } + html_engine_draw_cursor_in_area (e, 0, 0, -1, -1); + } engine->cursor_hide_count++; } void html_engine_show_cursor (HTMLEngine *engine) { + HTMLEngine * e = engine; + g_return_if_fail (engine != NULL); g_return_if_fail (HTML_IS_ENGINE (engine)); + g_return_if_fail (engine->cursor != NULL); if (engine->cursor_hide_count > 0) { engine->cursor_hide_count--; - if (engine->editable && engine->cursor_hide_count == 0) - html_engine_draw_cursor_in_area (engine, 0, 0, -1, -1); + if ((engine->editable || engine->caret_mode) && engine->cursor_hide_count == 0) { + if (!engine->editable) { + e = get_direct_engine(engine->cursor->object); + if (e) { + e->caret_mode = engine->caret_mode; + html_cursor_copy(e->cursor, engine->cursor); + } else e = engine; + } + html_engine_draw_cursor_in_area (e, 0, 0, -1, -1); + } } } static gboolean clip_rect (HTMLEngine *engine, gint x, gint y, gint width, gint height, gint *x1, gint *y1, gint *x2, gint *y2) { - if (*x1 >= x + width || *y1 >= y + height || *x2 < x || *y2 < y) + if (*x1 > x + width || *y1 > y + height || *x2 < x || *y2 < y) return FALSE; + if (*x1 == x + width) + *x1 = x + width - 1; + if (*y1 == y + width) + *y1 = y + height - 1; if (*x2 >= x + width) *x2 = x + width - 1; if (*y2 >= y + height) *y2 = y + height - 1; @@ -264,17 +308,15 @@ guint offset; gint x1, y1, x2, y2; GdkRectangle pos; - g_assert (engine->editable); - - if (engine->editable && (engine->cursor_hide_count <= 0 && !engine->thaw_idle_id)) { + if ((engine->editable || engine->caret_mode) && (engine->cursor_hide_count <= 0 && !engine->thaw_idle_id)) { html_engine_draw_table_cursor (engine); html_engine_draw_cell_cursor (engine); html_engine_draw_image_cursor (engine); } - if (!cursor_enabled || engine->cursor_hide_count > 0 || ! engine->editable || engine->thaw_idle_id) + if (!cursor_enabled || engine->cursor_hide_count > 0 || !(engine->editable || engine->caret_mode) || engine->thaw_idle_id) return; obj = engine->cursor->object; if (obj == NULL) @@ -288,16 +330,25 @@ x = 0; y = 0; } - html_object_get_cursor (obj, engine->painter, offset, &x1, &y1, &x2, &y2); - pos.x = x1; pos.y = y1; pos.width = x2 - x1; pos.height = x2 - x1; gtk_im_context_set_cursor_location (GTK_HTML (engine->widget)->priv->im_context, &pos); + + obj = g_object_get_data(G_OBJECT(gtk_widget_get_parent(GTK_WIDGET(engine->widget))), "embeddedelement"); + if (obj) { + HTMLEmbedded * element; + + element = HTML_EMBEDDED(obj); + x1 -= element->abs_x; + x2 -= element->abs_x; + y1 -= element->abs_y; + y2 -= element->abs_y; + } if (clip_rect (engine, x, y, width, height, &x1, &y1, &x2, &y2)) { gdk_draw_line (engine->window, engine->invert_gc, x1, y1, x2, y2); } Index: src/htmlengine-edit-movement.c =================================================================== RCS file: /cvs/gnome/gtkhtml/src/htmlengine-edit-movement.c,v retrieving revision 1.15 diff -u -4 -r1.15 htmlengine-edit-movement.c --- src/htmlengine-edit-movement.c 25 Apr 2001 21:31:53 -0000 1.15 +++ src/htmlengine-edit-movement.c 25 Jun 2003 06:21:28 -0000 @@ -274,10 +274,12 @@ now. */ if (new_y == y) break; - if (new_y < start_y) + if (new_y < start_y) { + html_engine_show_cursor (engine); return 0; + } if (new_y - start_y >= amount) { html_cursor_copy (cursor, &prev_cursor); break; Index: src/htmlengine.c =================================================================== RCS file: /cvs/gnome/gtkhtml/src/htmlengine.c,v retrieving revision 1.544 diff -u -4 -r1.544 htmlengine.c --- src/htmlengine.c 13 Jun 2003 21:42:59 -0000 1.544 +++ src/htmlengine.c 25 Jun 2003 06:21:43 -0000 @@ -3568,8 +3568,9 @@ engine->newPage = FALSE; engine->allow_frameset = FALSE; engine->editable = FALSE; + engine->caret_mode = FALSE; engine->clipboard = NULL; engine->clipboard_stack = NULL; engine->selection_stack = NULL; @@ -4588,14 +4589,16 @@ if (editable) { html_engine_ensure_editable (e); html_cursor_home (e->cursor, e); e->newPage = FALSE; - if (e->have_focus) html_engine_setup_blinking_cursor (e); } else { - if (e->have_focus) - html_engine_stop_blinking_cursor (e); + if (e->have_focus ) + if (e->caret_mode) + html_engine_setup_blinking_cursor (e); + else + html_engine_stop_blinking_cursor (e); } } gboolean @@ -4625,9 +4628,9 @@ { g_return_if_fail (engine != NULL); g_return_if_fail (HTML_IS_ENGINE (engine)); - if (engine->editable) { + if (engine->editable || engine->caret_mode) { if (! engine->have_focus && have_focus) html_engine_setup_blinking_cursor (engine); else if (engine->have_focus && ! have_focus) html_engine_stop_blinking_cursor (engine); @@ -4664,11 +4667,8 @@ { gint x1, y1, x2, y2, xo, yo; g_return_val_if_fail (e != NULL, FALSE); - - if (! e->editable) - return FALSE; if (e->cursor->object == NULL) return FALSE; Index: src/htmlengine.h =================================================================== RCS file: /cvs/gnome/gtkhtml/src/htmlengine.h,v retrieving revision 1.168 diff -u -4 -r1.168 htmlengine.h --- src/htmlengine.h 19 May 2003 12:58:36 -0000 1.168 +++ src/htmlengine.h 25 Jun 2003 06:21:44 -0000 @@ -64,8 +64,9 @@ GdkWindow *window; GdkGC *invert_gc; gboolean editable; + gboolean caret_mode; HTMLObject *clipboard; guint clipboard_len; GList *clipboard_stack; Index: src/htmliframe.c =================================================================== RCS file: /cvs/gnome/gtkhtml/src/htmliframe.c,v retrieving revision 1.74 diff -u -4 -r1.74 htmliframe.c --- src/htmliframe.c 19 May 2003 13:12:04 -0000 1.74 +++ src/htmliframe.c 25 Jun 2003 06:21:45 -0000 @@ -591,8 +591,9 @@ html_iframe_set_scrolling (iframe, GTK_POLICY_AUTOMATIC); new_widget = gtk_html_new (); new_html = GTK_HTML (new_widget); + new_html->engine->cursor_hide_count = 0; new_tokenizer = html_tokenizer_clone (parent_html->engine->ht); html_engine_set_tokenizer (new_html->engine, new_tokenizer);