Remove autofocus handling with gtk_container in editor
[modest] / src / hildon2 / modest-msg-edit-window.c
index 16d6157..4f77d83 100644 (file)
 #include "modest-address-book.h"
 #include "modest-text-utils.h"
 #include <tny-simple-list.h>
-#include <wptextview.h>
+#include <modest-wp-text-view.h>
 #include <wptextbuffer.h>
-#include "modest-scroll-area.h"
+#include <hildon/hildon-pannable-area.h>
+#include <hildon/hildon-touch-selector.h>
+#include <hildon/hildon-picker-dialog.h>
 #include "modest-msg-edit-window-ui-dimming.h"
 
 #include "modest-hildon-includes.h"
@@ -88,6 +90,7 @@
 #define SUBJECT_MAX_LENGTH 1000
 #define IMAGE_MAX_WIDTH 560
 #define DEFAULT_FONT_SCALE 1.5
+#define ATTACHMENT_BUTTON_WIDTH 118
 
 static gboolean is_wp_text_buffer_started = FALSE;
 
@@ -114,14 +117,8 @@ static void  subject_field_insert_text (GtkEditable *editable,
                                        ModestMsgEditWindow *window);
 static void  modest_msg_edit_window_color_button_change (ModestMsgEditWindow *window,
                                                         gpointer userdata);
-static void  modest_msg_edit_window_size_change (GtkCheckMenuItem *menu_item,
-                                                gpointer userdata);
-static void  modest_msg_edit_window_font_change (GtkCheckMenuItem *menu_item,
-                                                gpointer userdata);
 static void  modest_msg_edit_window_setup_toolbar (ModestMsgEditWindow *window);
-static gboolean modest_msg_edit_window_window_state_event (GtkWidget *widget, 
-                                                          GdkEventWindowState *event, 
-                                                          gpointer userdata);
+
 static void modest_msg_edit_window_open_addressbook (ModestMsgEditWindow *window,
                                                     ModestRecptEditor *editor);
 static void modest_msg_edit_window_add_attachment_clicked (GtkButton *button,
@@ -158,10 +155,6 @@ static void on_account_removed (TnyAccountStore *account_store,
                                TnyAccount *account,
                                gpointer user_data);
 
-static gboolean on_zoom_minus_plus_not_implemented (ModestWindow *window);
-static void set_zoom_do_nothing (ModestWindow *window, gdouble zoom);
-static gdouble get_zoom_do_nothing (ModestWindow *window);
-
 static void init_window (ModestMsgEditWindow *obj);
 
 gboolean scroll_drag_timeout (gpointer userdata);
@@ -173,9 +166,16 @@ static void text_buffer_mark_set (GtkTextBuffer *buffer,
                                  GtkTextIter *iter,
                                  GtkTextMark *mark,
                                  ModestMsgEditWindow *userdata);
-static void vadj_changed (GtkAdjustment *adj, 
-                         ModestMsgEditWindow *window);
-
+static void on_message_settings (GtkAction *action,
+                                ModestMsgEditWindow *window);
+static void setup_menu (ModestMsgEditWindow *self);
+
+static void from_field_changed (HildonPickerButton *button,
+                               ModestMsgEditWindow *self);
+static void font_size_clicked (GtkToolButton *button,
+                              ModestMsgEditWindow *window);
+static void font_face_clicked (GtkToolButton *button,
+                              ModestMsgEditWindow *window);
 static void DEBUG_BUFFER (WPTextBuffer *buffer)
 {
 #ifdef DEBUG
@@ -215,6 +215,10 @@ static void DEBUG_BUFFER (WPTextBuffer *buffer)
 #endif
 }
 
+static const GtkActionEntry hildon2_msg_edit_action_entries [] = {
+       { "MessageSettings", NULL, N_("mcen_me_message_settings"), NULL, NULL, G_CALLBACK (on_message_settings)},
+};
+
 
 /* static gboolean */
 /* on_key_pressed (GtkWidget *self, */
@@ -231,12 +235,15 @@ enum {
 typedef struct _ModestMsgEditWindowPrivate ModestMsgEditWindowPrivate;
 struct _ModestMsgEditWindowPrivate {
        GtkWidget   *msg_body;
-       GtkWidget   *frame;
        GtkWidget   *header_box;
        
        ModestPairList *from_field_protos;
        GtkWidget   *from_field;
+       gchar       *last_from_account;
        gchar       *original_account_name;
+
+       gchar       *references;
+       gchar       *in_reply_to;
        
        GtkWidget   *to_field;
        GtkWidget   *cc_field;
@@ -244,6 +251,7 @@ struct _ModestMsgEditWindowPrivate {
        GtkWidget   *subject_field;
        GtkWidget   *attachments_view;
        GtkWidget   *priority_icon;
+       GtkWidget   *subject_box;
        GtkWidget   *add_attachment_button;
 
        GtkWidget   *cc_caption;
@@ -256,17 +264,22 @@ struct _ModestMsgEditWindowPrivate {
        GtkWidget   *font_size_toolitem;
        GtkWidget   *font_face_toolitem;
        GtkWidget   *font_color_button;
+       GtkWidget   *font_color_toolitem;
        GSList      *font_items_group;
+       GtkTreeModel *faces_model;
+       gint         current_face_index;
        GtkWidget   *font_tool_button_label;
-       GSList      *size_items_group;
+       GtkTreeModel *sizes_model;
+       gint         current_size_index;
        GtkWidget   *size_tool_button_label;
-       
+
        GtkWidget   *find_toolbar;
        gchar       *last_search;
 
        GtkWidget   *font_dialog;
 
-       GtkWidget   *scroll;
+       GtkWidget   *pannable;
+       guint        correct_scroll_idle;
        guint        scroll_drag_timeout_id;
        gdouble      last_upper;
 
@@ -277,7 +290,7 @@ struct _ModestMsgEditWindowPrivate {
        gint images_count;
 
        TnyHeaderFlags priority_flags;
-       
+
        gboolean    can_undo, can_redo;
        gulong      clipboard_change_handler_id;
        gulong      default_clipboard_change_handler_id;
@@ -290,6 +303,10 @@ struct _ModestMsgEditWindowPrivate {
        gchar       *msg_uid;
 
        gboolean    sent;
+
+       GtkWidget   *app_menu;
+       GtkWidget   *cc_button;
+       GtkWidget   *bcc_button;
 };
 
 #define MODEST_MSG_EDIT_WINDOW_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
@@ -318,7 +335,7 @@ modest_msg_edit_window_get_type (void)
                        (GInstanceInitFunc) modest_msg_edit_window_init,
                        NULL
                };
-               my_type = g_type_register_static (MODEST_TYPE_WINDOW,
+               my_type = g_type_register_static (MODEST_TYPE_HILDON2_WINDOW,
                                                  "ModestMsgEditWindow",
                                                  &my_info, 0);
 
@@ -338,37 +355,11 @@ static void
 restore_settings (ModestMsgEditWindow *self)
 {
        ModestConf *conf = NULL;
-       GtkAction *action;
-       ModestWindowPrivate *parent_priv = MODEST_WINDOW_GET_PRIVATE (self);
 
        conf = modest_runtime_get_conf ();
-       action = gtk_ui_manager_get_action (parent_priv->ui_manager, 
-                                           "/MenuBar/ViewMenu/ShowToolbarMenu/ViewShowToolbarNormalScreenMenu");
-       modest_utils_toggle_action_set_active_block_notify (GTK_TOGGLE_ACTION (action),
-                                     modest_conf_get_bool (conf, MODEST_CONF_EDIT_WINDOW_SHOW_TOOLBAR, NULL));
-       action = gtk_ui_manager_get_action (parent_priv->ui_manager, 
-                                           "/MenuBar/ViewMenu/ShowToolbarMenu/ViewShowToolbarFullScreenMenu");
-       modest_utils_toggle_action_set_active_block_notify (GTK_TOGGLE_ACTION (action),
-                                     modest_conf_get_bool (conf, MODEST_CONF_EDIT_WINDOW_SHOW_TOOLBAR_FULLSCREEN, NULL));
-
-       /* set initial state of cc and bcc */
-       action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/ViewMenu/ViewCcFieldMenu");
-       modest_utils_toggle_action_set_active_block_notify (GTK_TOGGLE_ACTION (action),
-                                              modest_conf_get_bool(modest_runtime_get_conf(), MODEST_CONF_SHOW_CC, NULL));
-       action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/ViewMenu/ViewBccFieldMenu");
-       modest_utils_toggle_action_set_active_block_notify (GTK_TOGGLE_ACTION (action),
-                                              modest_conf_get_bool(modest_runtime_get_conf(), MODEST_CONF_SHOW_BCC, NULL));
 
        /* Dim at start clipboard actions */
-       action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/EditMenu/CutMenu");
-       gtk_action_set_sensitive (action, FALSE);
-       action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/EditMenu/CopyMenu");
-       gtk_action_set_sensitive (action, FALSE);
-       action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/AttachmentsMenu/RemoveAttachmentsMenu");
-       gtk_action_set_sensitive (action, FALSE);
-
-       modest_widget_memory_restore (conf,
-                                     G_OBJECT(self), MODEST_CONF_EDIT_WINDOW_KEY);
+       modest_widget_memory_restore (conf, G_OBJECT(self), MODEST_CONF_EDIT_WINDOW_KEY);
 }
 
 
@@ -383,10 +374,6 @@ modest_msg_edit_window_class_init (ModestMsgEditWindowClass *klass)
        parent_class            = g_type_class_peek_parent (klass);
        gobject_class->finalize = modest_msg_edit_window_finalize;
 
-       modest_window_class->set_zoom_func = set_zoom_do_nothing;
-       modest_window_class->get_zoom_func = get_zoom_do_nothing;
-       modest_window_class->zoom_plus_func = on_zoom_minus_plus_not_implemented;
-       modest_window_class->zoom_minus_func = on_zoom_minus_plus_not_implemented;
        modest_window_class->show_toolbar_func = modest_msg_edit_window_show_toolbar;
        modest_window_class->save_state_func = save_state;
        modest_window_class->disconnect_signals_func = modest_msg_edit_window_disconnect_signals;
@@ -401,7 +388,6 @@ modest_msg_edit_window_init (ModestMsgEditWindow *obj)
        priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE(obj);
 
        priv->msg_body      = NULL;
-       priv->frame         = NULL;
        priv->from_field    = NULL;
        priv->to_field      = NULL;
        priv->cc_field      = NULL;
@@ -436,12 +422,14 @@ modest_msg_edit_window_init (ModestMsgEditWindow *obj)
        priv->sent = FALSE;
 
        priv->scroll_drag_timeout_id = 0;
+       priv->correct_scroll_idle = 0;
        priv->last_upper = 0.0;
 
        priv->font_dialog = NULL;
+       priv->app_menu = NULL;
 
-       modest_window_mgr_register_help_id (modest_runtime_get_window_mgr(),
-                                           GTK_WINDOW(obj),"applications_email_editor");
+       priv->references = NULL;
+       priv->in_reply_to = NULL;
 
        if (!is_wp_text_buffer_started) {
                is_wp_text_buffer_started = TRUE;
@@ -455,8 +443,6 @@ modest_msg_edit_window_init (ModestMsgEditWindow *obj)
 }
 
 
-/* FIXME: this is a dup from the one in gtk/ */
-
 /** 
  * @result: A ModestPairList, which must be freed with modest_pair_list_free().
  */
@@ -505,6 +491,10 @@ scroll_drag_timeout (gpointer userdata)
        ModestMsgEditWindow *win = (ModestMsgEditWindow *) userdata;
        ModestMsgEditWindowPrivate *priv;
 
+       /* It could happen that the window was already closed */
+       if (!GTK_WIDGET_VISIBLE (win))
+               return FALSE;
+
        priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE(win);
 
        correct_scroll_without_drag_check (win, TRUE);
@@ -514,58 +504,58 @@ scroll_drag_timeout (gpointer userdata)
        return FALSE;
 }
 
-static void
-correct_scroll_without_drag_check (ModestMsgEditWindow *w, gboolean only_if_focused)
+static gboolean 
+correct_scroll_without_drag_check_idle (gpointer userdata)
 {
+       ModestMsgEditWindow *w = (ModestMsgEditWindow *) userdata;
        ModestMsgEditWindowPrivate *priv;
-       GtkTextMark *insert;
        GtkTextIter iter;
        GdkRectangle rectangle;
+       gint offset_min, offset_max;
+       GtkTextMark *insert;
        GtkAdjustment *vadj;
-       gdouble new_value;
-       gint offset;
-       GdkWindow *window;
 
-       priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE(w);
+       /* It could happen that the window was already closed */
+       if (!GTK_WIDGET_VISIBLE (w))
+               return FALSE;
 
-       if (only_if_focused && !gtk_widget_is_focus (priv->msg_body))
-               return;
+       priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE(w);
 
        insert = gtk_text_buffer_get_insert (priv->text_buffer);
        gtk_text_buffer_get_iter_at_mark (priv->text_buffer, &iter, insert);
 
        gtk_text_view_get_iter_location (GTK_TEXT_VIEW (priv->msg_body), &iter, &rectangle);
-       vadj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (priv->scroll));
-       offset = priv->msg_body->allocation.y;
+       offset_min = priv->msg_body->allocation.y + rectangle.y;
+       offset_max = offset_min + rectangle.height;
 
-       new_value = vadj->value;
-       
-       if ((offset + rectangle.y + rectangle.height) > 
-           ((gint) (vadj->value +vadj->page_size))) {
-               new_value = (offset + rectangle.y) - vadj->page_size * 0.25;
-               if (new_value > vadj->upper - vadj->page_size)
-                       new_value = vadj->upper - vadj->page_size;
-       } else if ((offset + rectangle.y) < ((gint) vadj->value)) {
-               new_value = (offset + rectangle.y - vadj->page_size * 0.75);
-               if (((gint) (new_value + vadj->page_size)) < (offset + rectangle.y + rectangle.height))
-                       new_value = offset + rectangle.y + rectangle.height - (gint) vadj->page_size;
-               if (new_value < 0.0)
-                       new_value = 0.0;
-               if (new_value > vadj->value)
-                       new_value = vadj->value;
-       }
-
-       if (vadj->value != new_value) {
-               g_signal_emit_by_name (GTK_TEXT_VIEW(priv->msg_body)->layout,
-                                      "invalidated");
-               vadj->value = new_value;
-               gtk_adjustment_value_changed (vadj);
-               /* invalidate body */
-               window = gtk_widget_get_parent_window (priv->msg_body);
-               if (window)
-                       gdk_window_invalidate_rect (window, NULL, TRUE);
+       vadj = hildon_pannable_area_get_vadjustment (HILDON_PANNABLE_AREA (priv->pannable));
+       offset_min = MAX (offset_min - 48, 0);
+       offset_max = MIN (offset_max + 48, vadj->upper);
+
+       gtk_adjustment_clamp_page (vadj, (gdouble) offset_min, (gdouble) offset_max);
+
+       priv->correct_scroll_idle = 0;
+       return FALSE;
+}
+
+static void
+correct_scroll_without_drag_check (ModestMsgEditWindow *w, gboolean only_if_focused)
+{
+       ModestMsgEditWindowPrivate *priv;
+
+       priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE(w);
+
+       if (only_if_focused && !gtk_widget_is_focus (priv->msg_body))
+               return;
+
+       if (priv->correct_scroll_idle > 0) {
+               return;
        }
 
+       priv->correct_scroll_idle = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
+                                                    (GSourceFunc) correct_scroll_without_drag_check_idle,
+                                                    g_object_ref (w),
+                                                    g_object_unref);
 }
 
 static void
@@ -576,8 +566,11 @@ correct_scroll (ModestMsgEditWindow *w)
        priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE(w);
        if (gtk_grab_get_current () == priv->msg_body) {
                if (priv->scroll_drag_timeout_id == 0) {
-                       priv->scroll_drag_timeout_id = g_timeout_add (500, (GSourceFunc) scroll_drag_timeout,
-                                                                     (gpointer) w);
+                       priv->scroll_drag_timeout_id = g_timeout_add_full (G_PRIORITY_DEFAULT,
+                                                                          500,
+                                                                          (GSourceFunc) scroll_drag_timeout,
+                                                                          g_object_ref (w),
+                                                                          g_object_unref);
                }
                return;
        }
@@ -627,20 +620,6 @@ copy_clipboard_check (GtkTextView *text_view,
        }
 }
 
-static void 
-vadj_changed (GtkAdjustment *adj,
-             ModestMsgEditWindow *window)
-{
-       ModestMsgEditWindowPrivate *priv;
-
-       priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
-
-       if (priv->last_upper != adj->upper) {
-               priv->last_upper = adj->upper;
-               correct_scroll (window);
-       }
-}
-
 static void
 attachment_deleted (ModestAttachmentsView *attachments_view,
                    gpointer user_data)
@@ -666,9 +645,6 @@ connect_signals (ModestMsgEditWindow *obj)
                           G_CALLBACK (body_changed), obj);
        g_signal_connect (G_OBJECT (priv->text_buffer), "modified-changed",
                           G_CALLBACK (body_changed), obj);
-       g_signal_connect (G_OBJECT (obj), "window-state-event",
-                         G_CALLBACK (modest_msg_edit_window_window_state_event),
-                         NULL);
        g_signal_connect (G_OBJECT (priv->text_buffer), "end-user-action",
                          G_CALLBACK (text_buffer_end_user_action), obj);
        g_signal_connect (G_OBJECT (priv->text_buffer), "mark-set",
@@ -684,6 +660,8 @@ connect_signals (ModestMsgEditWindow *obj)
 
        g_signal_connect (G_OBJECT (priv->add_attachment_button), "clicked",
                          G_CALLBACK (modest_msg_edit_window_add_attachment_clicked), obj);
+       g_signal_connect (G_OBJECT (priv->from_field), "value-changed",
+                         G_CALLBACK (from_field_changed), obj);
 
        g_signal_connect (G_OBJECT (priv->msg_body), "focus-in-event",
                          G_CALLBACK (msg_body_focus), obj);
@@ -700,14 +678,9 @@ connect_signals (ModestMsgEditWindow *obj)
        g_signal_connect_after (G_OBJECT (priv->subject_field), "move-cursor", G_CALLBACK (subject_field_move_cursor), obj);
        g_signal_connect (G_OBJECT (priv->subject_field), "insert-text", G_CALLBACK (subject_field_insert_text), obj);
 
-       g_signal_connect (G_OBJECT (priv->find_toolbar), "close", G_CALLBACK (modest_msg_edit_window_find_toolbar_close), obj);
        g_signal_connect (G_OBJECT (priv->find_toolbar), "search", G_CALLBACK (modest_msg_edit_window_find_toolbar_search), obj);
-
-       g_signal_connect (G_OBJECT (gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (priv->scroll))),
-                         "changed",
-                         G_CALLBACK (vadj_changed),
-                         obj);
-
+       g_signal_connect (G_OBJECT (priv->find_toolbar), "close", G_CALLBACK (modest_msg_edit_window_find_toolbar_close), obj);
        priv->clipboard_change_handler_id = 
                g_signal_connect (G_OBJECT (gtk_clipboard_get (GDK_SELECTION_PRIMARY)), "owner-change",
                                  G_CALLBACK (modest_msg_edit_window_clipboard_owner_change), obj);
@@ -721,20 +694,33 @@ connect_signals (ModestMsgEditWindow *obj)
 }
 
 static void
+init_wp_text_view_style ()
+{
+       static gboolean initialized = FALSE;
+
+       if (!initialized) {
+               gtk_rc_parse_string ("class \"WPTextView\" style \"fremantle-textview\"");
+               initialized = TRUE;
+       }
+}      
+
+static void
 init_window (ModestMsgEditWindow *obj)
 {
        GtkWidget *to_caption, *subject_caption;
        GtkWidget *main_vbox;
+       GtkWidget *add_attachment_align;
        ModestMsgEditWindowPrivate *priv;
        GtkActionGroup *action_group;
        ModestWindowPrivate *parent_priv;
        GdkPixbuf *window_icon = NULL;
        GError *error = NULL;
 
-       GtkSizeGroup *size_group;
-       GtkWidget *subject_box;
+       GtkSizeGroup *title_size_group;
+       GtkSizeGroup *value_size_group;
        GtkWidget *attachment_icon;
        GtkWidget *window_box;
+       GtkWidget *window_align;
 #if (GTK_MINOR_VERSION >= 10)
        GdkAtom deserialize_type;
 #endif
@@ -751,6 +737,10 @@ init_window (ModestMsgEditWindow *obj)
                                      modest_msg_edit_action_entries,
                                      G_N_ELEMENTS (modest_msg_edit_action_entries),
                                      obj);
+       gtk_action_group_add_actions (action_group,
+                                     hildon2_msg_edit_action_entries,
+                                     G_N_ELEMENTS (hildon2_msg_edit_action_entries),
+                                     obj);
        gtk_action_group_add_toggle_actions (action_group,
                                             modest_msg_edit_toggle_action_entries,
                                             G_N_ELEMENTS (modest_msg_edit_toggle_action_entries),
@@ -790,58 +780,71 @@ init_window (ModestMsgEditWindow *obj)
 
        parent_priv->menubar = NULL;
 
-       size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
+       title_size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
+       value_size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
 
        /* Note: This ModestPairList* must exist for as long as the picker
         * that uses it, because the ModestSelectorPicker uses the ID opaquely, 
         * so it can't know how to manage its memory. */ 
        priv->from_field    = modest_selector_picker_new (MODEST_EDITABLE_SIZE,
-                                                         MODEST_EDITABLE_ARRANGEMENT,
+                                                         HILDON_BUTTON_ARRANGEMENT_HORIZONTAL,
                                                          NULL, g_str_equal);
-       hildon_button_set_alignment (HILDON_BUTTON (priv->from_field), 0.0, 0.5, 1.0, 0.0);
-       hildon_button_set_title_alignment (HILDON_BUTTON (priv->from_field), 0.0, 0.5);
-       hildon_button_set_value_alignment (HILDON_BUTTON (priv->from_field), 0.0, 0.5);
+       modest_maemo_utils_set_hbutton_layout (title_size_group, value_size_group, 
+                                              _("mail_va_from"), priv->from_field);
 
        priv->to_field      = modest_recpt_editor_new ();
        priv->cc_field      = modest_recpt_editor_new ();
        priv->bcc_field     = modest_recpt_editor_new ();
-       subject_box = gtk_hbox_new (FALSE, 0);
+       priv->subject_box = gtk_hbox_new (FALSE, MODEST_MARGIN_NONE);
        priv->priority_icon = gtk_image_new ();
-       gtk_box_pack_start (GTK_BOX (subject_box), priv->priority_icon, FALSE, FALSE, 0);
+       gtk_box_pack_start (GTK_BOX (priv->subject_box), priv->priority_icon, FALSE, FALSE, 0);
        priv->subject_field = hildon_entry_new (MODEST_EDITABLE_SIZE);
        gtk_entry_set_max_length (GTK_ENTRY (priv->subject_field) ,SUBJECT_MAX_LENGTH);
        g_object_set (G_OBJECT (priv->subject_field), "truncate-multiline", TRUE, NULL);
        hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->subject_field), 
                                         HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
-       gtk_box_pack_start (GTK_BOX (subject_box), priv->subject_field, TRUE, TRUE, 0);
-       priv->add_attachment_button = gtk_button_new ();
+       gtk_box_pack_start (GTK_BOX (priv->subject_box), priv->subject_field, TRUE, TRUE, 0);
+       priv->add_attachment_button = hildon_button_new (MODEST_EDITABLE_SIZE, HILDON_BUTTON_ARRANGEMENT_VERTICAL);
+       gtk_widget_set_size_request (priv->add_attachment_button, ATTACHMENT_BUTTON_WIDTH, -1);
        GTK_WIDGET_UNSET_FLAGS (GTK_WIDGET (priv->add_attachment_button), GTK_CAN_FOCUS);
-       gtk_button_set_relief (GTK_BUTTON (priv->add_attachment_button), GTK_RELIEF_NONE);
        gtk_button_set_focus_on_click (GTK_BUTTON (priv->add_attachment_button), FALSE);
-       gtk_button_set_alignment (GTK_BUTTON (priv->add_attachment_button), 1.0, 0.5);
-       attachment_icon = gtk_image_new_from_icon_name (MODEST_HEADER_ICON_ATTACH, GTK_ICON_SIZE_BUTTON);
-       gtk_container_add (GTK_CONTAINER (priv->add_attachment_button), attachment_icon);
-       gtk_box_pack_start (GTK_BOX (subject_box), priv->add_attachment_button, FALSE, FALSE, 0);
+       attachment_icon = gtk_image_new_from_icon_name (MODEST_HEADER_ICON_ATTACH, HILDON_ICON_SIZE_FINGER);
+       hildon_button_set_image (HILDON_BUTTON (priv->add_attachment_button), attachment_icon);
+       add_attachment_align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
+       gtk_alignment_set_padding (GTK_ALIGNMENT (add_attachment_align), 0, 0, MODEST_MARGIN_DEFAULT, 0);
+       gtk_container_add (GTK_CONTAINER (add_attachment_align), priv->add_attachment_button);
+       gtk_box_pack_start (GTK_BOX (priv->subject_box), add_attachment_align, FALSE, FALSE, 0);
        priv->attachments_view = modest_attachments_view_new (NULL);
+       modest_attachments_view_set_style (MODEST_ATTACHMENTS_VIEW (priv->attachments_view),
+                                          MODEST_ATTACHMENTS_VIEW_STYLE_NO_FOCUS);
        
        priv->header_box = gtk_vbox_new (FALSE, 0);
        
-       hildon_button_add_title_size_group (HILDON_BUTTON (priv->from_field), size_group);
-       to_caption = modest_maemo_utils_create_captioned (size_group, _("mail_va_to"), priv->to_field);
-       priv->cc_caption = modest_maemo_utils_create_captioned (size_group, _("mail_va_cc"), priv->cc_field);
-       priv->bcc_caption = modest_maemo_utils_create_captioned (size_group, _("mail_va_hotfix1"), priv->bcc_field);
-       subject_caption = modest_maemo_utils_create_captioned (size_group, _("mail_va_subject"), subject_box);
-       priv->attachments_caption = modest_maemo_utils_create_captioned (size_group, _("mail_va_attachment"), priv->attachments_view);
-       g_object_unref (size_group);
-
-       size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
-       hildon_button_add_value_size_group (HILDON_BUTTON (priv->from_field), size_group);
-       modest_recpt_editor_set_field_size_group (MODEST_RECPT_EDITOR (priv->to_field), size_group);
-       modest_recpt_editor_set_field_size_group (MODEST_RECPT_EDITOR (priv->cc_field), size_group);
-       modest_recpt_editor_set_field_size_group (MODEST_RECPT_EDITOR (priv->bcc_field), size_group);
-       gtk_size_group_add_widget (size_group, priv->subject_field);
-       gtk_size_group_add_widget (size_group, priv->attachments_view);
-       g_object_unref (size_group);
+       to_caption = modest_maemo_utils_create_captioned_with_size_type 
+               (title_size_group, value_size_group,
+                _("mail_va_to"), FALSE, priv->to_field,
+                HILDON_SIZE_AUTO_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
+       priv->cc_caption = modest_maemo_utils_create_captioned_with_size_type 
+               (title_size_group, value_size_group,
+                _("mail_va_cc"), FALSE, priv->cc_field,
+                HILDON_SIZE_AUTO_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
+       priv->bcc_caption = modest_maemo_utils_create_captioned_with_size_type
+               (title_size_group, value_size_group,
+                _("mail_va_hotfix1"), FALSE, priv->bcc_field,
+                HILDON_SIZE_AUTO_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
+       subject_caption = modest_maemo_utils_create_captioned (title_size_group, value_size_group,
+                                                              _("mail_va_subject"), FALSE, priv->subject_box);
+       priv->attachments_caption = modest_maemo_utils_create_captioned_with_size_type (title_size_group, value_size_group,
+                                                                                       _("mail_va_attachment"), 
+                                                                                       FALSE,
+                                                                                       priv->attachments_view,
+                                                                                       HILDON_SIZE_AUTO_WIDTH |
+                                                                                       HILDON_SIZE_AUTO_HEIGHT);
+       /* modest_recpt_editor_set_field_size_group (MODEST_RECPT_EDITOR (priv->to_field), value_size_group); */
+       /* modest_recpt_editor_set_field_size_group (MODEST_RECPT_EDITOR (priv->cc_field), value_size_group); */
+       /* modest_recpt_editor_set_field_size_group (MODEST_RECPT_EDITOR (priv->bcc_field), value_size_group); */
+       g_object_unref (title_size_group);
+       g_object_unref (value_size_group);
 
        gtk_box_pack_start (GTK_BOX (priv->header_box), priv->from_field, FALSE, FALSE, 0);
        gtk_box_pack_start (GTK_BOX (priv->header_box), to_caption, FALSE, FALSE, 0);
@@ -851,8 +854,11 @@ init_window (ModestMsgEditWindow *obj)
        gtk_box_pack_start (GTK_BOX (priv->header_box), priv->attachments_caption, FALSE, FALSE, 0);
        gtk_widget_set_no_show_all (priv->attachments_caption, TRUE);
 
+       init_wp_text_view_style ();
+
+       priv->msg_body = modest_wp_text_view_new ();
+       
 
-       priv->msg_body = wp_text_view_new ();
        gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (priv->msg_body), GTK_WRAP_WORD_CHAR);
        priv->text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->msg_body));
        g_object_set (priv->text_buffer, "font_scale", DEFAULT_FONT_SCALE, NULL);
@@ -871,27 +877,23 @@ init_window (ModestMsgEditWindow *obj)
 
 /*     g_signal_connect (G_OBJECT (obj), "key_pressed", G_CALLBACK (on_key_pressed), NULL) */
 
-       priv->scroll = gtk_scrolled_window_new (NULL, NULL);
-       gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scroll), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
-       gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (priv->scroll), GTK_SHADOW_NONE);
-       modest_maemo_set_thumbable_scrollbar (GTK_SCROLLED_WINDOW(priv->scroll), TRUE);
-
+       priv->pannable = hildon_pannable_area_new ();
+       
        main_vbox = gtk_vbox_new  (FALSE, DEFAULT_MAIN_VBOX_SPACING);
+       window_align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
+       gtk_alignment_set_padding (GTK_ALIGNMENT (window_align), 0, 0, MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DEFAULT);
 
        gtk_box_pack_start (GTK_BOX(main_vbox), priv->header_box, FALSE, FALSE, 0);
-       priv->frame = gtk_frame_new (NULL);
-       gtk_box_pack_start (GTK_BOX(main_vbox), priv->frame, TRUE, TRUE, 0);
+       gtk_box_pack_start (GTK_BOX(main_vbox), priv->msg_body, TRUE, TRUE, 0);
+       gtk_container_add (GTK_CONTAINER (window_align), main_vbox);
 
-       gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (priv->scroll), main_vbox);
-       gtk_container_set_focus_vadjustment (GTK_CONTAINER (main_vbox), gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (priv->scroll)));
-       gtk_widget_show_all (GTK_WIDGET(priv->scroll));
+       hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA (priv->pannable), window_align);
+       gtk_widget_show_all (GTK_WIDGET(priv->pannable));
        
        window_box = gtk_vbox_new (FALSE, 0);
        gtk_container_add (GTK_CONTAINER(obj), window_box);
 
-       gtk_box_pack_start (GTK_BOX (window_box), priv->scroll, TRUE, TRUE, 0);
-
-       gtk_container_add (GTK_CONTAINER (priv->frame), priv->msg_body);
+       gtk_box_pack_start (GTK_BOX (window_box), priv->pannable, TRUE, TRUE, 0);
 
        /* Set window icon */
        window_icon = modest_platform_get_icon (MODEST_APP_MSG_EDIT_ICON, MODEST_ICON_SIZE_BIG); 
@@ -960,6 +962,10 @@ modest_msg_edit_window_finalize (GObject *obj)
                g_object_unref (priv->outbox_msg);
                priv->outbox_msg = NULL;
        }
+       if (priv->correct_scroll_idle > 0) {
+               g_source_remove (priv->correct_scroll_idle);
+               priv->correct_scroll_idle = 0;
+       }
        if (priv->scroll_drag_timeout_id > 0) {
                g_source_remove (priv->scroll_drag_timeout_id);
                priv->scroll_drag_timeout_id = 0;
@@ -972,8 +978,10 @@ modest_msg_edit_window_finalize (GObject *obj)
                g_free (priv->original_account_name);
        g_free (priv->msg_uid);
        g_free (priv->last_search);
-       g_slist_free (priv->font_items_group);
-       g_slist_free (priv->size_items_group);
+       g_free (priv->references);
+       g_free (priv->in_reply_to);
+       g_object_unref (priv->faces_model);
+       g_object_unref (priv->sizes_model);
        g_object_unref (priv->attachments);
        g_object_unref (priv->images);
 
@@ -983,13 +991,38 @@ modest_msg_edit_window_finalize (GObject *obj)
        G_OBJECT_CLASS(parent_class)->finalize (obj);
 }
 
+static void
+pixbuf_size_prepared (GdkPixbufLoader *loader,
+                     gint width,
+                     gint height,
+                     ModestMsgEditWindow *self)
+{
+       gint new_height, new_width;
+       gboolean set_size;
+       
+       new_height = height;
+       new_width = width;
+       set_size = FALSE;
+
+       if (width > IMAGE_MAX_WIDTH) {
+               new_height = height * IMAGE_MAX_WIDTH / width;
+               new_width = IMAGE_MAX_WIDTH;
+       }
+
+       gdk_pixbuf_loader_set_size (loader, new_width, new_height);
+}
+
 static GdkPixbuf *
-pixbuf_from_stream (TnyStream *stream, const gchar *mime_type, guint64 *stream_size)
+pixbuf_from_stream (TnyStream *stream,
+                   const gchar *mime_type,
+                   guint64 *stream_size,
+                   ModestMsgEditWindow *self)
 {
        GdkPixbufLoader *loader;
        GdkPixbuf *pixbuf;
        guint64 size;
-       
+       GError *error = NULL;
+
        size = 0;
 
        loader = gdk_pixbuf_loader_new_with_mime_type (mime_type, NULL);
@@ -999,10 +1032,12 @@ pixbuf_from_stream (TnyStream *stream, const gchar *mime_type, guint64 *stream_s
                        *stream_size = 0;
                return NULL;
        }
+       g_signal_connect (G_OBJECT (loader), "size-prepared", G_CALLBACK (pixbuf_size_prepared), self);
+
+       hildon_gtk_window_set_progress_indicator (GTK_WINDOW (self), TRUE);
 
        tny_stream_reset (TNY_STREAM (stream));
        while (!tny_stream_is_eos (TNY_STREAM (stream))) {
-               GError *error = NULL;
                unsigned char read_buffer[128];
                gint readed;
                readed = tny_stream_read (TNY_STREAM (stream), (char *) read_buffer, 128);
@@ -1010,12 +1045,19 @@ pixbuf_from_stream (TnyStream *stream, const gchar *mime_type, guint64 *stream_s
                if (!gdk_pixbuf_loader_write (loader, read_buffer, readed, &error)) {
                        break;
                }
+               /* Allow some UI responsiveness */
+               while (gtk_events_pending ())
+                       gtk_main_iteration ();
        }
+       hildon_gtk_window_set_progress_indicator (GTK_WINDOW (self), FALSE);
+
+       gdk_pixbuf_loader_close (loader, &error);
 
+       if (error)
+               g_error_free (error);
        pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
        if (pixbuf) 
                g_object_ref (pixbuf);
-       gdk_pixbuf_loader_close (loader, NULL);
        g_object_unref (loader);
 
        if (!pixbuf)
@@ -1045,6 +1087,7 @@ replace_with_images (ModestMsgEditWindow *self, TnyList *attachments)
 
        priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (self);
 
+       g_object_ref (self);
        for (iter = tny_list_create_iterator (attachments);
             !tny_iterator_is_done (iter);
             tny_iterator_next (iter)) {
@@ -1054,7 +1097,7 @@ replace_with_images (ModestMsgEditWindow *self, TnyList *attachments)
                if ((cid != NULL)&&(mime_type != NULL)) {
                        guint64 stream_size;
                        TnyStream *stream = tny_mime_part_get_decoded_stream (part);
-                       GdkPixbuf *pixbuf = pixbuf_from_stream (stream, mime_type, &stream_size);
+                       GdkPixbuf *pixbuf = pixbuf_from_stream (stream, mime_type, &stream_size, self);
 
 
                        g_object_unref (stream);
@@ -1069,6 +1112,7 @@ replace_with_images (ModestMsgEditWindow *self, TnyList *attachments)
                g_object_unref (part);
        }
        g_object_unref (iter);
+       g_object_unref (self);
 }
 
 static void
@@ -1079,7 +1123,7 @@ get_related_images (ModestMsgEditWindow *self, TnyMsg *msg)
        ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (self);
 
        content_type = tny_mime_part_get_content_type (TNY_MIME_PART (msg));
-       
+
        if (content_type && !g_strcasecmp (content_type, "multipart/related")) {
                parent = g_object_ref (msg);
        } else if (content_type && !g_strcasecmp (content_type, "multipart/mixed")) {
@@ -1156,25 +1200,32 @@ set_msg (ModestMsgEditWindow *self, TnyMsg *msg, gboolean preserve_is_rich)
        gchar *to, *cc, *bcc, *subject;
        gchar *body;
        ModestMsgEditWindowPrivate *priv;
+       ModestWindowPrivate *parent_priv;
        GtkTextIter iter;
        TnyHeaderFlags priority_flags;
        TnyFolder *msg_folder;
        gboolean is_html = FALSE;
+       gboolean field_view_set;
        
        g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (self));
        g_return_if_fail (TNY_IS_MSG (msg));
 
        priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (self);
+       parent_priv = MODEST_WINDOW_GET_PRIVATE (self);
 
        header = tny_msg_get_header (msg);
        to      = tny_header_dup_to (header);
        cc      = tny_header_dup_cc (header);
        bcc     = tny_header_dup_bcc (header);
        subject = tny_header_dup_subject (header);
+
+       modest_tny_msg_get_references (TNY_MSG (msg), NULL, &(priv->references), &(priv->in_reply_to));
        priority_flags = tny_header_get_priority (header);
 
        if (to)
                modest_recpt_editor_set_recipients (MODEST_RECPT_EDITOR (priv->to_field),  to);
+
+       field_view_set = TRUE;
        if (cc) {
                modest_recpt_editor_set_recipients (MODEST_RECPT_EDITOR (priv->cc_field),  cc);
                gtk_widget_set_no_show_all (priv->cc_caption, FALSE);
@@ -1182,7 +1233,11 @@ set_msg (ModestMsgEditWindow *self, TnyMsg *msg, gboolean preserve_is_rich)
        } else if (!modest_conf_get_bool (modest_runtime_get_conf (), MODEST_CONF_SHOW_CC, NULL)) {
                gtk_widget_set_no_show_all (priv->cc_caption, TRUE);
                gtk_widget_hide (priv->cc_caption);
+               field_view_set = FALSE;
        }
+       hildon_check_button_set_active (HILDON_CHECK_BUTTON (priv->cc_button), field_view_set);
+
+       field_view_set = TRUE;
        if (bcc) {
                modest_recpt_editor_set_recipients (MODEST_RECPT_EDITOR (priv->bcc_field), bcc);
                gtk_widget_set_no_show_all (priv->bcc_caption, FALSE);
@@ -1190,7 +1245,11 @@ set_msg (ModestMsgEditWindow *self, TnyMsg *msg, gboolean preserve_is_rich)
        } else if (!modest_conf_get_bool (modest_runtime_get_conf (), MODEST_CONF_SHOW_BCC, NULL)) {
                gtk_widget_set_no_show_all (priv->bcc_caption, TRUE);
                gtk_widget_hide (priv->bcc_caption);
-       } 
+               field_view_set = FALSE;
+       }
+       hildon_check_button_set_active (HILDON_CHECK_BUTTON (priv->bcc_button), field_view_set);
+
+
        if (subject)
                gtk_entry_set_text (GTK_ENTRY(priv->subject_field), subject);
        modest_msg_edit_window_set_priority_flags (MODEST_MSG_EDIT_WINDOW(self),
@@ -1281,45 +1340,6 @@ set_msg (ModestMsgEditWindow *self, TnyMsg *msg, gboolean preserve_is_rich)
        g_free (bcc);
 }
 
-static void
-menu_tool_button_clicked_popup (GtkMenuToolButton *item,
-                               gpointer data)
-{
-       GList *item_children, *node;
-       GtkWidget *bin_child;
-
-       bin_child = gtk_bin_get_child (GTK_BIN(item));
-
-       item_children = gtk_container_get_children (GTK_CONTAINER (bin_child));
-       
-       for (node = item_children; node != NULL; node = g_list_next (node)) {
-               if (GTK_IS_TOGGLE_BUTTON (node->data)) {
-                       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (node->data), TRUE);
-               }
-       }
-       g_list_free (item_children);
-}
-
-static void
-menu_tool_button_dont_expand (GtkMenuToolButton *item)
-{
-       GtkWidget *box;
-       GList *item_children, *node;
-
-       box = gtk_bin_get_child (GTK_BIN (item));
-       gtk_box_set_homogeneous (GTK_BOX (box), TRUE);
-       item_children = gtk_container_get_children (GTK_CONTAINER (box));
-       
-       for (node = item_children; node != NULL; node = g_list_next (node)) {
-               gtk_box_set_child_packing (GTK_BOX (box), GTK_WIDGET (node->data), TRUE, TRUE, 0, GTK_PACK_START);
-               if (GTK_IS_TOGGLE_BUTTON (node->data))
-                       gtk_button_set_alignment (GTK_BUTTON (node->data), 0.0, 0.5);
-               else if (GTK_IS_BUTTON (node->data))
-                       gtk_button_set_alignment (GTK_BUTTON (node->data), 1.0, 0.5);
-       }
-       g_list_free (item_children);
-}
-
 
 static void
 modest_msg_edit_window_setup_toolbar (ModestMsgEditWindow *window)
@@ -1334,12 +1354,14 @@ modest_msg_edit_window_setup_toolbar (ModestMsgEditWindow *window)
        gint font_index;
        GtkWidget *sizes_menu;
        GtkWidget *fonts_menu;
-       GSList *radio_group = NULL;
-       GSList *node = NULL;
        gchar *markup;
+       GtkWidget *arrow;
+       GtkWidget *hbox;
 
        /* Toolbar */
        parent_priv->toolbar = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/ToolBar");
+       gtk_toolbar_set_show_arrow (GTK_TOOLBAR (parent_priv->toolbar), FALSE);
+       gtk_toolbar_set_icon_size (GTK_TOOLBAR (parent_priv->toolbar), HILDON_ICON_SIZE_FINGER);
        hildon_window_add_toolbar (HILDON_WINDOW (window), GTK_TOOLBAR (parent_priv->toolbar));
 
        /* Font color placeholder */
@@ -1347,14 +1369,15 @@ modest_msg_edit_window_setup_toolbar (ModestMsgEditWindow *window)
        insert_index = gtk_toolbar_get_item_index(GTK_TOOLBAR (parent_priv->toolbar), GTK_TOOL_ITEM(placeholder));
 
        /* font color */
-       tool_item = GTK_WIDGET (gtk_tool_item_new ());
+       priv->font_color_toolitem = GTK_WIDGET (gtk_tool_item_new ());
        priv->font_color_button = hildon_color_button_new ();
-       GTK_WIDGET_UNSET_FLAGS (tool_item, GTK_CAN_FOCUS);
+       gtk_widget_set_size_request (priv->font_color_button, -1, 48);
+       GTK_WIDGET_UNSET_FLAGS (priv->font_color_toolitem, GTK_CAN_FOCUS);
        GTK_WIDGET_UNSET_FLAGS (priv->font_color_button, GTK_CAN_FOCUS);
-       gtk_container_add (GTK_CONTAINER (tool_item), priv->font_color_button);
-       gtk_tool_item_set_expand (GTK_TOOL_ITEM (tool_item), TRUE);
-       gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (tool_item), TRUE);
-       gtk_toolbar_insert(GTK_TOOLBAR(parent_priv->toolbar), GTK_TOOL_ITEM (tool_item), insert_index);
+       gtk_container_add (GTK_CONTAINER (priv->font_color_toolitem), priv->font_color_button);
+       gtk_tool_item_set_expand (GTK_TOOL_ITEM (priv->font_color_toolitem), TRUE);
+       gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (priv->font_color_toolitem), TRUE);
+       gtk_toolbar_insert(GTK_TOOLBAR(parent_priv->toolbar), GTK_TOOL_ITEM (priv->font_color_toolitem), insert_index);
        g_signal_connect_swapped (G_OBJECT (priv->font_color_button), 
                                  "notify::color", 
                                  G_CALLBACK (modest_msg_edit_window_color_button_change), 
@@ -1364,87 +1387,78 @@ modest_msg_edit_window_setup_toolbar (ModestMsgEditWindow *window)
        placeholder = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/ToolBar/FontAttributes");
        insert_index = gtk_toolbar_get_item_index(GTK_TOOLBAR (parent_priv->toolbar), GTK_TOOL_ITEM(placeholder));
        /* font_size */
-       tool_item = GTK_WIDGET (gtk_menu_tool_button_new (NULL, NULL));
+       tool_item = GTK_WIDGET (gtk_tool_button_new (NULL, NULL));
        priv->size_tool_button_label = gtk_label_new (NULL);
        snprintf(size_text, sizeof(size_text), "%d", wp_font_size[DEFAULT_FONT_SIZE]);
        markup = g_strconcat ("<span font_family='", DEFAULT_SIZE_BUTTON_FONT_FAMILY, "'>",
-                             size_text,"</span>", NULL);
+                             size_text, "</span>", NULL);
        gtk_label_set_markup (GTK_LABEL (priv->size_tool_button_label), markup);
+       gtk_misc_set_alignment (GTK_MISC (priv->size_tool_button_label), 1.0, 0.5);
        g_free (markup);
-       gtk_tool_button_set_label_widget (GTK_TOOL_BUTTON (tool_item), priv->size_tool_button_label);
+       hildon_helper_set_logical_font (priv->size_tool_button_label, "LargeSystemFont");
+       hbox = gtk_hbox_new (MODEST_MARGIN_DEFAULT, FALSE);
+       gtk_box_pack_start (GTK_BOX (hbox), priv->size_tool_button_label, TRUE, TRUE, 0);
+       arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
+       gtk_misc_set_alignment (GTK_MISC (arrow), 0.0, 0.5);
+       gtk_box_pack_start (GTK_BOX (hbox), arrow, TRUE, TRUE, 0);
+       gtk_widget_set_sensitive (arrow, FALSE);
+       gtk_tool_button_set_label_widget (GTK_TOOL_BUTTON (tool_item), hbox);
        sizes_menu = gtk_menu_new ();
-       priv->size_items_group = NULL;
-       radio_group = NULL;
+       priv->sizes_model = GTK_TREE_MODEL (gtk_list_store_new (1, G_TYPE_STRING));
        for (size_index = 0; size_index < WP_FONT_SIZE_COUNT; size_index++) {
-               GtkWidget *size_menu_item;
+               GtkTreeIter iter;
 
                snprintf(size_text, sizeof(size_text), "%d", wp_font_size[size_index]);
-               size_menu_item = gtk_radio_menu_item_new_with_label (radio_group, size_text);
-               radio_group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (size_menu_item));
-               gtk_menu_shell_append (GTK_MENU_SHELL (sizes_menu), size_menu_item);
-               gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (size_menu_item), (wp_font_size[size_index] == 12));
-               gtk_widget_show (size_menu_item);
+               gtk_list_store_append (GTK_LIST_STORE (priv->sizes_model), &iter);
 
-               priv->size_items_group = g_slist_prepend (priv->size_items_group, size_menu_item);
-                       
-       }
+               gtk_list_store_set (GTK_LIST_STORE (priv->sizes_model), &iter, 
+                                   0, size_text,
+                                   -1);
 
-       for (node = radio_group; node != NULL; node = g_slist_next (node)) {
-               GtkWidget *item = (GtkWidget *) node->data;
-               g_signal_connect (G_OBJECT (item), "toggled", G_CALLBACK (modest_msg_edit_window_size_change),
-                                 window);
+               if (wp_font_size[size_index] == 12)
+                       priv->current_size_index = size_index;
+                                       
        }
 
-       priv->size_items_group = g_slist_reverse (priv->size_items_group);
-       gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (tool_item), sizes_menu);
-       g_signal_connect (G_OBJECT (tool_item), "clicked", G_CALLBACK (menu_tool_button_clicked_popup), NULL);
+       g_signal_connect (G_OBJECT (tool_item), "clicked", G_CALLBACK (font_size_clicked), window);
        gtk_toolbar_insert (GTK_TOOLBAR (parent_priv->toolbar), GTK_TOOL_ITEM (tool_item), insert_index);
        gtk_tool_item_set_expand (GTK_TOOL_ITEM (tool_item), TRUE);
        gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (tool_item), TRUE);
-       menu_tool_button_dont_expand (GTK_MENU_TOOL_BUTTON (tool_item));
        priv->font_size_toolitem = tool_item;
 
        /* font face */
-       tool_item = GTK_WIDGET (gtk_menu_tool_button_new (NULL, NULL));
+       tool_item = GTK_WIDGET (gtk_tool_button_new (NULL, NULL));
        priv->font_tool_button_label = gtk_label_new (NULL);
        markup = g_strconcat ("<span font_family='", wp_get_font_name(DEFAULT_FONT), "'>Tt</span>", NULL);
        gtk_label_set_markup (GTK_LABEL (priv->font_tool_button_label), markup);
+       gtk_misc_set_alignment (GTK_MISC (priv->font_tool_button_label), 1.0, 0.5);
        g_free(markup);
-       gtk_tool_button_set_label_widget (GTK_TOOL_BUTTON (tool_item), priv->font_tool_button_label);
+       hildon_helper_set_logical_font (priv->font_tool_button_label, "LargeSystemFont");
+       hbox = gtk_hbox_new (MODEST_MARGIN_DEFAULT, FALSE);
+       gtk_box_pack_start (GTK_BOX (hbox), priv->font_tool_button_label, TRUE, TRUE, 0);
+       arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
+       gtk_misc_set_alignment (GTK_MISC (arrow), 0.0, 0.5);
+       gtk_box_pack_start (GTK_BOX (hbox), arrow, TRUE, TRUE, 0);
+       gtk_widget_set_sensitive (arrow, FALSE);
+       gtk_tool_button_set_label_widget (GTK_TOOL_BUTTON (tool_item), hbox);
        fonts_menu = gtk_menu_new ();
-       priv->font_items_group = NULL;
-       radio_group = NULL;
+       priv->faces_model = GTK_TREE_MODEL (gtk_list_store_new (1, G_TYPE_STRING));
        for (font_index = 0; font_index < wp_get_font_count (); font_index++) {
-               GtkWidget *font_menu_item;
-               GtkWidget *child_label;
-
-               font_menu_item = gtk_radio_menu_item_new_with_label (radio_group, "");
-               child_label = gtk_bin_get_child (GTK_BIN (font_menu_item));
-               markup = g_strconcat ("<span font_family='", wp_get_font_name (font_index),"'>", 
-                                     wp_get_font_name (font_index), "</span>", NULL);
-               gtk_label_set_markup (GTK_LABEL (child_label), markup);
-               g_free (markup);
-               
-               radio_group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (font_menu_item));
-               gtk_menu_shell_append (GTK_MENU_SHELL (fonts_menu), font_menu_item);
-               gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (font_menu_item), (font_index == DEFAULT_FONT));
-               gtk_widget_show (font_menu_item);
+               GtkTreeIter iter;
 
-               priv->font_items_group = g_slist_prepend (priv->font_items_group, font_menu_item);
-                       
-       }
-       for (node = radio_group; node != NULL; node = g_slist_next (node)) {
-               GtkWidget *item = (GtkWidget *) node->data;
-               g_signal_connect (G_OBJECT (item), "toggled", G_CALLBACK (modest_msg_edit_window_font_change),
-                                 window);
+               gtk_list_store_append (GTK_LIST_STORE (priv->faces_model), &iter);
+
+               gtk_list_store_set (GTK_LIST_STORE (priv->faces_model), &iter, 
+                                   0, wp_get_font_name (font_index),
+                                   -1);
+
+               if (font_index == DEFAULT_FONT)
+                       priv->current_face_index = font_index;
        }
-       priv->font_items_group = g_slist_reverse (priv->font_items_group);
-       gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (tool_item), fonts_menu);
-       g_signal_connect (G_OBJECT (tool_item), "clicked", G_CALLBACK (menu_tool_button_clicked_popup), NULL);
+       g_signal_connect (G_OBJECT (tool_item), "clicked", G_CALLBACK (font_face_clicked), window);
        gtk_toolbar_insert (GTK_TOOLBAR (parent_priv->toolbar), GTK_TOOL_ITEM (tool_item), insert_index);
        gtk_tool_item_set_expand (GTK_TOOL_ITEM (tool_item), TRUE);
        gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (tool_item), TRUE);
-       menu_tool_button_dont_expand (GTK_MENU_TOOL_BUTTON (tool_item));
        priv->font_face_toolitem = tool_item;
 
        /* Set expand and homogeneous for remaining items */
@@ -1477,7 +1491,6 @@ modest_msg_edit_window_new (TnyMsg *msg, const gchar *account_name, gboolean pre
        GObject *obj;
        ModestWindowPrivate *parent_priv;
        ModestMsgEditWindowPrivate *priv;
-       ModestDimmingRulesGroup *menu_rules_group = NULL;
        ModestDimmingRulesGroup *toolbar_rules_group = NULL;
        ModestDimmingRulesGroup *clipboard_rules_group = NULL;
        ModestWindowMgr *mgr = NULL;
@@ -1493,11 +1506,10 @@ modest_msg_edit_window_new (TnyMsg *msg, const gchar *account_name, gboolean pre
        parent_priv = MODEST_WINDOW_GET_PRIVATE (obj);
 
        /* Menubar. Update the state of some toggles */
-       parent_priv->menubar = modest_maemo_utils_get_manager_menubar_as_menu (parent_priv->ui_manager, "/MenuBar");
-       hildon_window_set_menu (HILDON_WINDOW (obj), GTK_MENU (parent_priv->menubar));
        priv->from_field_protos = get_transports ();
        modest_selector_picker_set_pair_list (MODEST_SELECTOR_PICKER (priv->from_field), priv->from_field_protos);
        modest_selector_picker_set_active_id (MODEST_SELECTOR_PICKER (priv->from_field), (gpointer) account_name);
+       priv->last_from_account = modest_selector_picker_get_active_id (MODEST_SELECTOR_PICKER (priv->from_field));
        hildon_button_set_title (HILDON_BUTTON (priv->from_field),
                                 _("mail_va_from"));
        hildon_button_set_value (HILDON_BUTTON (priv->from_field), 
@@ -1515,20 +1527,14 @@ modest_msg_edit_window_new (TnyMsg *msg, const gchar *account_name, gboolean pre
 
        priv->original_account_name = (account_name) ? g_strdup (account_name) : NULL;
 
-       parent_priv->ui_dimming_manager = modest_ui_dimming_manager_new ();
-       menu_rules_group = modest_dimming_rules_group_new (MODEST_DIMMING_RULES_MENU, FALSE);
        toolbar_rules_group = modest_dimming_rules_group_new (MODEST_DIMMING_RULES_TOOLBAR, TRUE);
        clipboard_rules_group = modest_dimming_rules_group_new (MODEST_DIMMING_RULES_CLIPBOARD, FALSE);
        /* Add common dimming rules */
-       modest_dimming_rules_group_add_rules (menu_rules_group, 
-                                             modest_msg_edit_window_menu_dimming_entries,
-                                             G_N_ELEMENTS (modest_msg_edit_window_menu_dimming_entries),
-                                             MODEST_WINDOW (obj));
        modest_dimming_rules_group_add_rules (toolbar_rules_group, 
                                              modest_msg_edit_window_toolbar_dimming_entries,
                                              G_N_ELEMENTS (modest_msg_edit_window_toolbar_dimming_entries),
                                              MODEST_WINDOW (obj));
-       modest_dimming_rules_group_add_widget_rule (toolbar_rules_group, priv->font_color_button,
+       modest_dimming_rules_group_add_widget_rule (toolbar_rules_group, priv->font_color_toolitem,
                                                    G_CALLBACK (modest_ui_dimming_rules_on_set_style),
                                                    MODEST_WINDOW (obj));
        modest_dimming_rules_group_add_widget_rule (toolbar_rules_group, priv->font_size_toolitem,
@@ -1537,18 +1543,18 @@ modest_msg_edit_window_new (TnyMsg *msg, const gchar *account_name, gboolean pre
        modest_dimming_rules_group_add_widget_rule (toolbar_rules_group, priv->font_face_toolitem,
                                                    G_CALLBACK (modest_ui_dimming_rules_on_set_style),
                                                    MODEST_WINDOW (obj));
-       modest_dimming_rules_group_add_rules (clipboard_rules_group, 
-                                             modest_msg_edit_window_clipboard_dimming_entries,
-                                             G_N_ELEMENTS (modest_msg_edit_window_clipboard_dimming_entries),
-                                             MODEST_WINDOW (obj));
        /* Insert dimming rules group for this window */
-       modest_ui_dimming_manager_insert_rules_group (parent_priv->ui_dimming_manager, menu_rules_group);
        modest_ui_dimming_manager_insert_rules_group (parent_priv->ui_dimming_manager, toolbar_rules_group);
        modest_ui_dimming_manager_insert_rules_group (parent_priv->ui_dimming_manager, clipboard_rules_group);
+
+       /* Setup app menu */
+       setup_menu (MODEST_MSG_EDIT_WINDOW (obj));
+
         /* Checks the dimming rules */
-       g_object_unref (menu_rules_group);
        g_object_unref (toolbar_rules_group);
        g_object_unref (clipboard_rules_group);
+       gtk_widget_hide (priv->priority_icon);
+       gtk_widget_queue_resize (priv->subject_box);
        set_msg (MODEST_MSG_EDIT_WINDOW (obj), msg, preserve_is_rich);
 
        text_buffer_refresh_attributes (WP_TEXT_BUFFER (priv->text_buffer), MODEST_MSG_EDIT_WINDOW (obj));
@@ -1630,6 +1636,8 @@ modest_msg_edit_window_get_msg_data (ModestMsgEditWindow *edit_window)
        data->cc      =  g_strdup (modest_recpt_editor_get_recipients (MODEST_RECPT_EDITOR (priv->cc_field)));
        data->bcc     =  g_strdup (modest_recpt_editor_get_recipients (MODEST_RECPT_EDITOR (priv->bcc_field)));
        data->subject =  g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->subject_field)));
+       data->references = g_strdup (priv->references);
+       data->in_reply_to = g_strdup (priv->in_reply_to);
        if (priv->draft_msg) {
                data->draft_msg = g_object_ref (priv->draft_msg);
        } else if (priv->outbox_msg) {
@@ -1729,6 +1737,8 @@ modest_msg_edit_window_free_msg_data (ModestMsgEditWindow *edit_window,
        g_free (data->plain_body);
        g_free (data->html_body);
        g_free (data->account_name);
+       g_free (data->references);
+       g_free (data->in_reply_to);
        
        if (data->draft_msg != NULL) {
                g_object_unref (data->draft_msg);
@@ -1802,9 +1812,11 @@ modest_msg_edit_window_get_format_state (ModestMsgEditWindow *self)
 {
        ModestMsgEditFormatState *format_state = NULL;
        ModestMsgEditWindowPrivate *priv;
-       WPTextBufferFormat *buffer_format = g_new0 (WPTextBufferFormat, 1);
+       WPTextBufferFormat *buffer_format;
 
        g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW (self), NULL);
+
+       buffer_format = g_new0 (WPTextBufferFormat, 1);
        priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (self);
 
        wp_text_buffer_get_attributes (WP_TEXT_BUFFER (priv->text_buffer), buffer_format, TRUE);
@@ -1828,11 +1840,15 @@ modest_msg_edit_window_set_format_state (ModestMsgEditWindow *self,
                                         const ModestMsgEditFormatState *format_state)
 {
        ModestMsgEditWindowPrivate *priv;
-       WPTextBufferFormat *buffer_format = g_new0 (WPTextBufferFormat, 1);
-       WPTextBufferFormat *current_format = g_new0 (WPTextBufferFormat, 1);
+       WPTextBufferFormat *buffer_format;
+       WPTextBufferFormat *current_format;
+
        g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (self));
        g_return_if_fail (format_state != NULL);
 
+       buffer_format = g_new0 (WPTextBufferFormat, 1);
+       current_format = g_new0 (WPTextBufferFormat, 1);
+
        priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (self);
        gtk_widget_grab_focus (priv->msg_body);
        buffer_format->bold = (format_state->bold != FALSE);
@@ -1902,6 +1918,7 @@ modest_msg_edit_window_set_format_state (ModestMsgEditWindow *self,
        
        text_buffer_refresh_attributes (WP_TEXT_BUFFER (priv->text_buffer), self);
        
+       g_free (buffer_format);
        g_free (current_format);
 
        /* Check dimming rules */
@@ -1916,18 +1933,16 @@ text_buffer_refresh_attributes (WPTextBuffer *buffer, ModestMsgEditWindow *windo
        GtkAction *action;
        ModestWindowPrivate *parent_priv;
        ModestMsgEditWindowPrivate *priv;
-       GtkWidget *new_size_menuitem;
-       GtkWidget *new_font_menuitem;
        
        parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
        priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
 
        if (wp_text_buffer_is_rich_text (WP_TEXT_BUFFER (priv->text_buffer))) {
-               action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/FormatMenu/FileFormatMenu/FileFormatFormattedTextMenu");
+               action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/FormatMenu/FileFormatFormattedTextMenu");
                if (!gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)))
                        modest_utils_toggle_action_set_active_block_notify (GTK_TOGGLE_ACTION (action), TRUE);
        } else {
-               action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/FormatMenu/FileFormatMenu/FileFormatPlainTextMenu");
+               action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/FormatMenu/FileFormatPlainTextMenu");
                if (!gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)))
                        modest_utils_toggle_action_set_active_block_notify (GTK_TOGGLE_ACTION (action), TRUE);
        }
@@ -1970,42 +1985,45 @@ text_buffer_refresh_attributes (WPTextBuffer *buffer, ModestMsgEditWindow *windo
                                           G_CALLBACK (modest_msg_edit_window_color_button_change),
                                           window);
 
-       new_size_menuitem = GTK_WIDGET ((g_slist_nth (priv->size_items_group, 
-                                                     buffer_format->font_size))->data);
-       if (!gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (new_size_menuitem))) {
-               GtkWidget *label;
-               gchar *markup;
+       if (priv->current_size_index != buffer_format->font_size) {
+               GtkTreeIter iter;
+               GtkTreePath *path;
 
-               label = gtk_bin_get_child (GTK_BIN (new_size_menuitem));
-               markup = g_strconcat ("<span font_family='Sans'>", gtk_label_get_text (GTK_LABEL (label)), "</span>", NULL);
-               gtk_label_set_markup (GTK_LABEL (priv->size_tool_button_label), markup);
-               g_free (markup);
-               g_signal_handlers_block_by_func (G_OBJECT (new_size_menuitem),
-                                                G_CALLBACK (modest_msg_edit_window_size_change),
-                                                window);
-               gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (new_size_menuitem), TRUE);
-               g_signal_handlers_unblock_by_func (G_OBJECT (new_size_menuitem),
-                                                  G_CALLBACK (modest_msg_edit_window_size_change),
-                                                  window);
-       }
-
-       new_font_menuitem = GTK_WIDGET ((g_slist_nth (priv->font_items_group, 
-                                                     buffer_format->font))->data);
-       if (!gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (new_font_menuitem))) {
-               GtkWidget *label;
-               gchar *markup;
+               path = gtk_tree_path_new_from_indices (buffer_format->font_size, -1);
+               if (gtk_tree_model_get_iter (priv->sizes_model, &iter, path)) {
+                       gchar *size_text;
+                       gchar *markup;
+
+                       priv->current_size_index = buffer_format->font_size;
+
+                       gtk_tree_model_get (priv->sizes_model, &iter, 0, &size_text, -1);
+                       markup = g_strconcat ("<span font_family='Sans'>", 
+                                             size_text, "</span>", NULL);
+                       
+                       gtk_label_set_markup (GTK_LABEL (priv->size_tool_button_label), markup);
+                       g_free (markup);
+                       g_free (size_text);
+               }
+               gtk_tree_path_free (path);              
+       }
+
+       if (priv->current_face_index != buffer_format->font) {
+               GtkTreeIter iter;
+               GtkTreePath *path;
+
+               path = gtk_tree_path_new_from_indices (buffer_format->font, -1);
+               if (gtk_tree_model_get_iter (priv->faces_model, &iter, path)) {
+                       gchar *face_name;
+                       gchar *markup;
+
+                       priv->current_face_index = buffer_format->font;
+                       gtk_tree_model_get (priv->faces_model, &iter, 0, &face_name, -1);
+                       markup = g_strconcat ("<span font_family='", face_name, "'>Tt</span>", NULL);
+                       gtk_label_set_markup (GTK_LABEL (priv->font_tool_button_label), markup);
+                       g_free (face_name);
+                       g_free (markup);
+               }
 
-               label = gtk_bin_get_child (GTK_BIN (new_font_menuitem));
-               markup = g_strconcat ("<span font_family='", gtk_label_get_text (GTK_LABEL (label)),"'>Tt</span>", NULL);
-               gtk_label_set_markup (GTK_LABEL (priv->font_tool_button_label), markup);
-               g_free (markup);
-               g_signal_handlers_block_by_func (G_OBJECT (new_font_menuitem),
-                                                G_CALLBACK (modest_msg_edit_window_font_change),
-                                                window);
-               gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (new_font_menuitem), TRUE);
-               g_signal_handlers_unblock_by_func (G_OBJECT (new_font_menuitem),
-                                                  G_CALLBACK (modest_msg_edit_window_font_change),
-                                                  window);
        }
 
        g_free (buffer_format);
@@ -2159,9 +2177,9 @@ modest_msg_edit_window_insert_image (ModestMsgEditWindow *window)
        gint response = 0;
        GSList *uris = NULL;
        GSList *uri_node = NULL;
-       
+
        priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
-       
+
        dialog = hildon_file_chooser_dialog_new (GTK_WINDOW (window), GTK_FILE_CHOOSER_ACTION_OPEN);
        gtk_window_set_title (GTK_WINDOW (dialog), _("mcen_ia_select_inline_image_title"));
        gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (dialog), TRUE);
@@ -2181,6 +2199,11 @@ modest_msg_edit_window_insert_image (ModestMsgEditWindow *window)
        }
        gtk_widget_destroy (dialog);
 
+       g_object_ref (window);
+       /* The operation could take some time so allow the dialog to be closed */
+       while (gtk_events_pending ())
+               gtk_main_iteration ();
+
        for (uri_node = uris; uri_node != NULL; uri_node = g_slist_next (uri_node)) {
                const gchar *uri;
                GnomeVFSHandle *handle = NULL;
@@ -2216,111 +2239,131 @@ modest_msg_edit_window_insert_image (ModestMsgEditWindow *window)
 
                        mime_part = tny_platform_factory_new_mime_part
                                (modest_runtime_get_platform_factory ());
-                               
+
                        TnyStream *stream = create_stream_for_uri (uri);
 
                        if (stream == NULL) {
 
-                               modest_platform_information_banner (NULL, NULL, dgettext("hildon-fm", "sfil_ib_opening_not_allowed"));
-                               
+                               modest_platform_information_banner (NULL, NULL, 
+                                                                   _FM("sfil_ib_opening_not_allowed"));
+                               g_free (filename);
                                g_object_unref (mime_part);
                                gnome_vfs_file_info_unref (info);
                                continue;
                        }
 
                        tny_mime_part_construct (mime_part, stream, mime_type, "base64");
-                       
+
                        content_id = g_strdup_printf ("%d", priv->next_cid);
                        tny_mime_part_set_content_id (mime_part, content_id);
                        g_free (content_id);
                        priv->next_cid++;
-                       
+
                        basename = g_path_get_basename (filename);
                        tny_mime_part_set_filename (mime_part, basename);
                        g_free (basename);
 
-                       pixbuf = pixbuf_from_stream (stream, mime_type, &stream_size);
-                       
+                       pixbuf = pixbuf_from_stream (stream, mime_type, &stream_size, window);
+
                        if (pixbuf != NULL) {
                                priv->images_size += stream_size;
                                priv->images_count ++;
                                insert_mark = gtk_text_buffer_get_insert (GTK_TEXT_BUFFER (priv->text_buffer));
                                gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (priv->text_buffer), &position, insert_mark);
-                               wp_text_buffer_insert_image (WP_TEXT_BUFFER (priv->text_buffer), &position, g_strdup (tny_mime_part_get_content_id (mime_part)), pixbuf);
-                       } 
+                               wp_text_buffer_insert_image (WP_TEXT_BUFFER (priv->text_buffer), &position, 
+                                                            tny_mime_part_get_content_id (mime_part), pixbuf);
+                               g_object_unref (pixbuf);
+
+                               tny_list_prepend (priv->images, (GObject *) mime_part);
+                               gtk_text_buffer_set_modified (priv->text_buffer, TRUE);
+                       } else {
+                               modest_platform_information_banner (NULL, NULL,
+                                                                   _("mail_ib_file_operation_failed"));
+                       }
 
-                       tny_list_prepend (priv->images, (GObject *) mime_part);
-                       gtk_text_buffer_set_modified (priv->text_buffer, TRUE);
                        g_free (filename);
                        g_object_unref (mime_part);
                        gnome_vfs_file_info_unref (info);
 
                }
        }
-
-
+       g_object_unref (window);
 }
 
-void
-modest_msg_edit_window_offer_attach_file (ModestMsgEditWindow *window)
-{      
-       GtkWidget *dialog = NULL;
-       gint response = 0;
+static void
+on_attach_file_response (GtkDialog *dialog,
+                        gint       arg1,
+                        gpointer   user_data)
+{
        GSList *uris = NULL;
        GSList *uri_node;
        GnomeVFSFileSize total_size, allowed_size;
+       ModestMsgEditWindow *window;
        ModestMsgEditWindowPrivate *priv;
        gint att_num;
        guint64 att_size;
 
-       g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(window));
-               
-       priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
-
-       if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
-               return;
-       
-       dialog = hildon_file_chooser_dialog_new (GTK_WINDOW (window), GTK_FILE_CHOOSER_ACTION_OPEN);
-       gtk_window_set_title (GTK_WINDOW (dialog), _("mcen_ti_select_attachment_title"));
-       gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (dialog), TRUE);
-       modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (dialog), GTK_WINDOW (window));
-
-       response = gtk_dialog_run (GTK_DIALOG (dialog));
-       switch (response) {
+       switch (arg1) {
        case GTK_RESPONSE_OK:
                uris = gtk_file_chooser_get_uris (GTK_FILE_CHOOSER (dialog));
                break;
        default:
                break;
        }
-       gtk_widget_destroy (dialog);
+
+       window = MODEST_MSG_EDIT_WINDOW (user_data);
+       priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
 
        /* allowed size is the maximum size - what's already there */
-       modest_attachments_view_get_sizes (
-               MODEST_ATTACHMENTS_VIEW (priv->attachments_view), 
-               &att_num, &att_size);
+       modest_attachments_view_get_sizes (MODEST_ATTACHMENTS_VIEW (priv->attachments_view),
+                                          &att_num, &att_size);
        allowed_size = MODEST_MAX_ATTACHMENT_SIZE - att_size;
 
        total_size = 0;
        for (uri_node = uris; uri_node != NULL; uri_node = g_slist_next (uri_node)) {
 
                const gchar *uri = (const gchar *) uri_node->data;
-               
-               total_size += modest_msg_edit_window_attach_file_one 
-                       (window, uri, allowed_size);
-               
+
+               total_size += 
+                       modest_msg_edit_window_attach_file_one (window, uri, allowed_size);
+
                if (total_size > allowed_size) {
                        g_warning ("%s: total size: %u", 
                                   __FUNCTION__, (unsigned int)total_size);
                        break;
                }
-
                allowed_size -= total_size;
-               
-
        }
        g_slist_foreach (uris, (GFunc) g_free, NULL);
        g_slist_free (uris);
+
+       gtk_widget_destroy (GTK_WIDGET (dialog));
+}
+
+void
+modest_msg_edit_window_offer_attach_file (ModestMsgEditWindow *window)
+{
+       GtkWidget *dialog = NULL;
+       ModestMsgEditWindowPrivate *priv;
+
+       g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(window));
+
+       priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
+
+       if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
+               return;
+
+       dialog = hildon_file_chooser_dialog_new (GTK_WINDOW (window), 
+                                                GTK_FILE_CHOOSER_ACTION_OPEN);
+       gtk_window_set_title (GTK_WINDOW (dialog), _("mcen_ti_select_attachment_title"));
+       gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (dialog), TRUE);
+       modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), 
+                                    GTK_WINDOW (dialog), GTK_WINDOW (window));
+
+       /* Connect to response & show */
+       g_signal_connect (dialog, "response", 
+                         G_CALLBACK (on_attach_file_response), window);
+       gtk_widget_show (dialog);
 }
 
 
@@ -2336,9 +2379,9 @@ modest_msg_edit_window_attach_file_one (ModestMsgEditWindow *window,
        GnomeVFSFileSize size = 0;
        g_return_val_if_fail (window, 0);
        g_return_val_if_fail (uri, 0);
-               
+
        priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
-       
+
        result = gnome_vfs_open (&handle, uri, GNOME_VFS_OPEN_READ);
        if (result == GNOME_VFS_OK) {
                TnyMimePart *mime_part;
@@ -2377,7 +2420,8 @@ modest_msg_edit_window_attach_file_one (ModestMsgEditWindow *window,
                        size = info->size;
                        if (size > allowed_size) {
                                modest_platform_information_banner (NULL, NULL, 
-                                                                   dgettext("hildon-fm", "sfil_ib_opening_not_allowed"));
+                                                                   _FM("sfil_ib_opening_not_allowed"));
+                               g_free (filename);
                                return 0;
                        }
                } else
@@ -2387,9 +2431,10 @@ modest_msg_edit_window_attach_file_one (ModestMsgEditWindow *window,
                
                if (stream == NULL) {
 
-                       modest_platform_information_banner (NULL, NULL, dgettext("hildon-fm", "sfil_ib_opening_not_allowed"));
+                       modest_platform_information_banner (NULL, NULL, _FM("sfil_ib_opening_not_allowed"));
 
                        g_object_unref (mime_part);
+                       g_free (filename);
                        gnome_vfs_file_info_unref (info);
                        return 0;
                }
@@ -2432,7 +2477,12 @@ modest_msg_edit_window_remove_attachments (ModestMsgEditWindow *window,
        priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
 
        if (att_list == NULL) {
-               att_list = modest_attachments_view_get_selection (MODEST_ATTACHMENTS_VIEW (priv->attachments_view));
+               att_list = modest_attachments_view_get_attachments (MODEST_ATTACHMENTS_VIEW (priv->attachments_view));
+               if (!modest_maemo_utils_select_attachments (GTK_WINDOW (window), att_list, TRUE)) {
+                       g_object_unref (att_list);
+                       return;
+               }
+               
        } else {
                g_object_ref (att_list);
        }
@@ -2465,19 +2515,20 @@ modest_msg_edit_window_remove_attachments (ModestMsgEditWindow *window,
                } else {
                        filename = g_strdup ("");
                }
-               message = g_strdup_printf (ngettext("emev_nc_delete_attachment", "emev_nc_delete_attachments",
+               message = g_strdup_printf (ngettext("emev_nc_delete_attachment", 
+                                                   "emev_nc_delete_attachments",
                                                    tny_list_get_length (att_list)), filename);
                g_free (filename);
 
-               dialog_response = modest_platform_run_confirmation_dialog (GTK_WINDOW (window), message);
+               dialog_response = modest_platform_run_confirmation_dialog (GTK_WINDOW (window), 
+                                                                          message);
                g_free (message);
 
                if (dialog_response != GTK_RESPONSE_OK) {
                        g_object_unref (att_list);
                        return;
                }
-               hildon_banner_show_information (NULL, NULL, _("mcen_ib_removing_attachment"));
-               
+
                for (iter = tny_list_create_iterator (att_list);
                     !tny_iterator_is_done (iter);
                     tny_iterator_next (iter)) {
@@ -2529,98 +2580,108 @@ modest_msg_edit_window_color_button_change (ModestMsgEditWindow *window,
 }
 
 static void
-modest_msg_edit_window_size_change (GtkCheckMenuItem *menu_item,
-                                   gpointer userdata)
+font_size_clicked (GtkToolButton *button,
+                  ModestMsgEditWindow *window)
 {
        ModestMsgEditWindowPrivate *priv;
-       gint new_size_index;
-       ModestMsgEditWindow *window;
-       GtkWidget *label;
+       GtkWidget *selector, *dialog;
        
-       window = MODEST_MSG_EDIT_WINDOW (userdata);
        priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
-       gtk_widget_grab_focus (GTK_WIDGET (priv->msg_body));
 
-       if (gtk_check_menu_item_get_active (menu_item)) {
+       selector = hildon_touch_selector_new ();
+       hildon_touch_selector_append_text_column (HILDON_TOUCH_SELECTOR (selector), priv->sizes_model, TRUE);
+       hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, priv->current_size_index);
+
+       dialog = hildon_picker_dialog_new (GTK_WINDOW (window));
+       hildon_picker_dialog_set_selector (HILDON_PICKER_DIALOG (dialog), HILDON_TOUCH_SELECTOR (selector));
+       gtk_window_set_title (GTK_WINDOW (dialog), _("mcen_ti_font_size"));
+
+       if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) {
+               gint new_index;
+               gchar *size_text;
                gchar *markup;
                WPTextBufferFormat format;
 
+               new_index = hildon_touch_selector_get_active (HILDON_TOUCH_SELECTOR (selector), 0);
+
                memset (&format, 0, sizeof (format));
                wp_text_buffer_get_attributes (WP_TEXT_BUFFER (priv->text_buffer), &format, FALSE);
 
-               label = gtk_bin_get_child (GTK_BIN (menu_item));
-               
-               new_size_index = atoi (gtk_label_get_text (GTK_LABEL (label)));
                format.cs.font_size = TRUE;
                format.cs.text_position = TRUE;
                format.cs.font = TRUE;
-               format.font_size = wp_get_font_size_index (new_size_index, DEFAULT_FONT_SIZE);
+               format.font_size = new_index;
 /*             wp_text_buffer_set_format (WP_TEXT_BUFFER (priv->text_buffer), &format); */
 
                if (!wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_FONT_SIZE,
-                                                  GINT_TO_POINTER (wp_get_font_size_index (new_size_index, 12))))
+                                                  GINT_TO_POINTER (new_index)))
                        wp_text_view_reset_and_show_im (WP_TEXT_VIEW (priv->msg_body));
                
                text_buffer_refresh_attributes (WP_TEXT_BUFFER (priv->text_buffer), MODEST_MSG_EDIT_WINDOW (window));
-               markup = g_strconcat ("<span font_family='", DEFAULT_SIZE_BUTTON_FONT_FAMILY, "'>", gtk_label_get_text (GTK_LABEL (label)), "</span>", NULL);
+               size_text = hildon_touch_selector_get_current_text (HILDON_TOUCH_SELECTOR (selector));
+               markup = g_strconcat ("<span font_family='", DEFAULT_SIZE_BUTTON_FONT_FAMILY, "'>", 
+                                     size_text, "</span>", NULL);
+               g_free (size_text);
                gtk_label_set_markup (GTK_LABEL (priv->size_tool_button_label), markup);
                g_free (markup);
+
        }
+       gtk_widget_destroy (dialog);
+
+       gtk_widget_grab_focus (GTK_WIDGET (priv->msg_body));
+
 }
 
 static void
-modest_msg_edit_window_font_change (GtkCheckMenuItem *menu_item,
-                                   gpointer userdata)
+font_face_clicked (GtkToolButton *button,
+                  ModestMsgEditWindow *window)
 {
        ModestMsgEditWindowPrivate *priv;
-       gint new_font_index;
-       ModestMsgEditWindow *window;
-       GtkWidget *label;
+       GtkWidget *selector, *dialog;
+       GtkCellRenderer *renderer;
        
-       window = MODEST_MSG_EDIT_WINDOW (userdata);
        priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
-       gtk_widget_grab_focus (GTK_WIDGET (priv->msg_body));
 
-       if (gtk_check_menu_item_get_active (menu_item)) {
-               gchar *markup;
+       selector = hildon_touch_selector_new ();
+       renderer = gtk_cell_renderer_text_new ();
+       hildon_touch_selector_append_column (HILDON_TOUCH_SELECTOR (selector), priv->faces_model, 
+                                            renderer, "family", 0, "text", 0, NULL);
+       hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, priv->current_face_index);
 
-               label = gtk_bin_get_child (GTK_BIN (menu_item));
-               
-               new_font_index = wp_get_font_index (gtk_label_get_text (GTK_LABEL (label)), DEFAULT_FONT);
+       dialog = hildon_picker_dialog_new (GTK_WINDOW (window));
+       hildon_picker_dialog_set_selector (HILDON_PICKER_DIALOG (dialog), HILDON_TOUCH_SELECTOR (selector));
+       gtk_window_set_title (GTK_WINDOW (dialog), _("mcen_ti_font_face"));
 
-               if (!wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_FONT, 
-                                                  GINT_TO_POINTER(new_font_index)))
-                       wp_text_view_reset_and_show_im (WP_TEXT_VIEW (priv->msg_body));
-               
-               text_buffer_refresh_attributes (WP_TEXT_BUFFER (priv->text_buffer), MODEST_MSG_EDIT_WINDOW (window));
-                   markup = g_strconcat ("<span font_family='",gtk_label_get_text (GTK_LABEL (label)),"'>Tt</span>", NULL);
-               gtk_label_set_markup (GTK_LABEL (priv->font_tool_button_label), markup);
-               g_free (markup);
-       }
-}
+       if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) {
+               gint new_font_index;
+               GtkTreePath *path;
+               GtkTreeIter iter;
 
-static gboolean
-modest_msg_edit_window_window_state_event (GtkWidget *widget, GdkEventWindowState *event, gpointer userdata)
-{
-       if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN) {
-               ModestWindowPrivate *parent_priv;
-               ModestWindowMgr *mgr;
-               gboolean is_fullscreen;
-               GtkAction *fs_toggle_action;
-               gboolean active;
+               new_font_index = hildon_touch_selector_get_active (HILDON_TOUCH_SELECTOR (selector), 0);
+               path = gtk_tree_path_new_from_indices (new_font_index, -1);
+               if (gtk_tree_model_get_iter (priv->faces_model, &iter, path)) {
+                       gchar *face_name;
+                       gchar *markup;
 
-               mgr = modest_runtime_get_window_mgr ();
-               is_fullscreen = (modest_window_mgr_get_fullscreen_mode (mgr))?1:0;
+                       gtk_tree_model_get (priv->faces_model, &iter, 0, &face_name, -1);
+
+                       if (!wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_FONT, 
+                                                          GINT_TO_POINTER(new_font_index)))
+                               wp_text_view_reset_and_show_im (WP_TEXT_VIEW (priv->msg_body));
+
+                       markup = g_strconcat ("<span font_family='", face_name, "'>Tt</span>", NULL);
+                       gtk_label_set_markup (GTK_LABEL (priv->font_tool_button_label), markup);
+
+                       text_buffer_refresh_attributes (WP_TEXT_BUFFER (priv->text_buffer), MODEST_MSG_EDIT_WINDOW (window));
+                       g_free (face_name);
+                       g_free (markup);
+               }
+               gtk_tree_path_free (path);
 
-               parent_priv = MODEST_WINDOW_GET_PRIVATE (widget);
-               
-               fs_toggle_action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/ViewMenu/ViewToggleFullscreenMenu");
-               active = (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (fs_toggle_action)))?1:0;
-               if (is_fullscreen != active)
-                       gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (fs_toggle_action), is_fullscreen);
        }
+       gtk_widget_destroy (dialog);
 
-       return FALSE;
+       gtk_widget_grab_focus (GTK_WIDGET (priv->msg_body));
 
 }
 
@@ -2724,9 +2785,7 @@ modest_msg_edit_window_show_toolbar (ModestWindow *self,
                                     gboolean show_toolbar)
 {
        ModestWindowPrivate *parent_priv;
-       const gchar *action_name;
-       GtkAction *action;
-       
+
        g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (self));
        parent_priv = MODEST_WINDOW_GET_PRIVATE(self);
 
@@ -2737,21 +2796,6 @@ modest_msg_edit_window_show_toolbar (ModestWindow *self,
                gtk_widget_show (GTK_WIDGET (parent_priv->toolbar));
        else
                gtk_widget_hide (GTK_WIDGET (parent_priv->toolbar));
-
-       /* Update also the actions (to update the toggles in the
-          menus), we have to do it manually because some other window
-          of the same time could have changed it (remember that the
-          toolbar fullscreen mode is shared by all the windows of the
-          same type */
-       if (modest_window_mgr_get_fullscreen_mode (modest_runtime_get_window_mgr ()))
-               action_name = "/MenuBar/ViewMenu/ShowToolbarMenu/ViewShowToolbarFullScreenMenu";
-       else
-               action_name = "/MenuBar/ViewMenu/ShowToolbarMenu/ViewShowToolbarNormalScreenMenu";
-       
-       action = gtk_ui_manager_get_action (parent_priv->ui_manager, action_name);
-       modest_utils_toggle_action_set_active_block_notify (GTK_TOGGLE_ACTION (action),
-                                                           show_toolbar);
-
 }
 
 void
@@ -2773,26 +2817,31 @@ modest_msg_edit_window_set_priority_flags (ModestMsgEditWindow *window,
 
                switch (priority_flags) {
                case TNY_HEADER_FLAG_HIGH_PRIORITY:
-                       gtk_image_set_from_icon_name (GTK_IMAGE (priv->priority_icon), "qgn_list_messaging_high", GTK_ICON_SIZE_MENU);
+                       gtk_image_set_from_icon_name (GTK_IMAGE (priv->priority_icon),
+                                                     MODEST_HEADER_ICON_HIGH, 
+                                                     HILDON_ICON_SIZE_SMALL);
                        gtk_widget_show (priv->priority_icon);
-                       priority_action = gtk_ui_manager_get_action (parent_priv->ui_manager, 
+                       priority_action = gtk_ui_manager_get_action (parent_priv->ui_manager,
                                                                     "/MenuBar/ToolsMenu/MessagePriorityMenu/MessagePriorityHighMenu");
                        break;
                case TNY_HEADER_FLAG_LOW_PRIORITY:
-                       gtk_image_set_from_icon_name (GTK_IMAGE (priv->priority_icon), "qgn_list_messaging_low", GTK_ICON_SIZE_MENU);
+                       gtk_image_set_from_icon_name (GTK_IMAGE (priv->priority_icon),
+                                                     MODEST_HEADER_ICON_LOW,
+                                                     HILDON_ICON_SIZE_SMALL);
                        gtk_widget_show (priv->priority_icon);
-                       priority_action = gtk_ui_manager_get_action (parent_priv->ui_manager, 
+                       priority_action = gtk_ui_manager_get_action (parent_priv->ui_manager,
                                                                     "/MenuBar/ToolsMenu/MessagePriorityMenu/MessagePriorityLowMenu");
                        break;
                default:
                        gtk_widget_hide (priv->priority_icon);
-                       priority_action = gtk_ui_manager_get_action (parent_priv->ui_manager, 
+                       priority_action = gtk_ui_manager_get_action (parent_priv->ui_manager,
                                                                     "/MenuBar/ToolsMenu/MessagePriorityMenu/MessagePriorityNormalMenu");
                        break;
                }
                gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (priority_action), TRUE);
                gtk_text_buffer_set_modified (priv->text_buffer, TRUE);
        }
+       gtk_widget_queue_resize (priv->subject_box);
 }
 
 void
@@ -2827,7 +2876,7 @@ modest_msg_edit_window_set_file_format (ModestMsgEditWindow *window,
                        if (response == GTK_RESPONSE_OK) {
                                wp_text_buffer_enable_rich_text (WP_TEXT_BUFFER (priv->text_buffer), FALSE);
                        } else {
-                               GtkToggleAction *action = GTK_TOGGLE_ACTION (gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/FormatMenu/FileFormatMenu/FileFormatFormattedTextMenu"));
+                               GtkToggleAction *action = GTK_TOGGLE_ACTION (gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/FormatMenu/FileFormatFormattedTextMenu"));
                                modest_utils_toggle_action_set_active_block_notify (action, TRUE);
                        }
                }
@@ -3181,22 +3230,27 @@ modest_msg_edit_window_check_names (ModestMsgEditWindow *window, gboolean add_to
                return FALSE;
        }
 
+       g_object_ref (window);
        if (!modest_address_book_check_names (MODEST_RECPT_EDITOR (priv->to_field),  add_to_addressbook)) {
                modest_recpt_editor_grab_focus (MODEST_RECPT_EDITOR (priv->to_field));
+               g_object_unref (window);
                return FALSE;
        }
        if (!modest_address_book_check_names (MODEST_RECPT_EDITOR (priv->cc_field),  add_to_addressbook)) {
                modest_recpt_editor_grab_focus (MODEST_RECPT_EDITOR (priv->cc_field));
+               g_object_unref (window);
                return FALSE;
        }
        if (!modest_address_book_check_names (MODEST_RECPT_EDITOR (priv->bcc_field), add_to_addressbook)) {
                modest_recpt_editor_grab_focus (MODEST_RECPT_EDITOR (priv->bcc_field));
+               g_object_unref (window);
                return FALSE;
        }
 
        if (!modest_recpt_editor_has_focus (MODEST_RECPT_EDITOR (priv->cc_field)) &&
            !modest_recpt_editor_has_focus (MODEST_RECPT_EDITOR (priv->bcc_field)))
                modest_recpt_editor_grab_focus (MODEST_RECPT_EDITOR (priv->to_field));
+       g_object_unref (window);
 
        return TRUE;
 
@@ -3225,6 +3279,8 @@ modest_msg_edit_window_clipboard_owner_change (GtkClipboard *clipboard,
        ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
        GtkClipboard *selection_clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
        gchar *text = NULL;
+
+       /* It could happen that the window was already closed */
        if (!GTK_WIDGET_VISIBLE (window))
                return;
 
@@ -3236,9 +3292,8 @@ modest_msg_edit_window_clipboard_owner_change (GtkClipboard *clipboard,
        }
        priv->clipboard_text = text;
 
-       if (GTK_WIDGET_VISIBLE (window)) {
-               modest_window_check_dimming_rules_group (MODEST_WINDOW (window), MODEST_DIMMING_RULES_CLIPBOARD);
-       }
+       modest_window_check_dimming_rules_group (MODEST_WINDOW (window), MODEST_DIMMING_RULES_CLIPBOARD);
+
        g_object_unref (window);
 }
 
@@ -3263,7 +3318,10 @@ modest_msg_edit_window_clipboard_owner_handle_change_in_idle (ModestMsgEditWindo
 {
        ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
        if (priv->clipboard_owner_idle == 0) {
-               priv->clipboard_owner_idle = g_idle_add (clipboard_owner_change_idle, window);
+               priv->clipboard_owner_idle = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
+                                                             clipboard_owner_change_idle, 
+                                                             g_object_ref (window),
+                                                             g_object_unref);
        }
 }
 
@@ -3274,6 +3332,7 @@ subject_field_move_cursor (GtkEntry *entry,
                           gboolean a2,
                           gpointer window)
 {
+       /* It could happen that the window was already closed */
        if (!GTK_WIDGET_VISIBLE (window))
                return;
 
@@ -3349,10 +3408,8 @@ subject_field_insert_text (GtkEditable *editable,
 
        if (result_len + old_length > 1000) {
                hildon_banner_show_information (GTK_WIDGET (window), NULL, 
-                                               dgettext("hildon-common-strings",
-                                                        "ckdg_ib_maximum_characters_reached"));
+                                               _CS("ckdg_ib_maximum_characters_reached"));
        }
-       
        g_string_free (result, TRUE);
 }
 
@@ -3374,7 +3431,6 @@ modest_msg_edit_window_toggle_find_toolbar (ModestMsgEditWindow *window,
                gtk_widget_hide_all (priv->find_toolbar);
                gtk_widget_grab_focus (priv->msg_body);
        }
-    
 }
 
 static gboolean 
@@ -3418,8 +3474,10 @@ gtk_text_iter_forward_search_insensitive (const GtkTextIter *iter,
                if (!g_utf8_collate (range_subtext, str_casefold)) {
                        gchar *found_text = g_strndup (range_text + offset, str_chars_n);
                        result = TRUE;
-                       gtk_text_iter_forward_search (iter, found_text, GTK_TEXT_SEARCH_VISIBLE_ONLY|GTK_TEXT_SEARCH_TEXT_ONLY,
-                                                     match_start, match_end, NULL);
+                       if (!gtk_text_iter_forward_search (iter, found_text, GTK_TEXT_SEARCH_VISIBLE_ONLY|GTK_TEXT_SEARCH_TEXT_ONLY,
+                                                          match_start, match_end, NULL)) {
+                               g_warning ("Matched string with collate, but not matched in model");
+                       }
                        g_free (found_text);
                }
                g_free (range_subtext);
@@ -3458,7 +3516,7 @@ modest_msg_edit_window_find_toolbar_search (GtkWidget *widget,
                g_free (priv->last_search);
                priv->last_search = NULL;
                /* Information banner about empty search */
-               hildon_banner_show_information (NULL, NULL, dgettext ("hildon-common-strings", "ecdg_ib_find_rep_enter_text"));
+               hildon_banner_show_information (NULL, NULL, _CS("ecdg_ib_find_rep_enter_text"));
                return;
        }
 
@@ -3474,14 +3532,14 @@ modest_msg_edit_window_find_toolbar_search (GtkWidget *widget,
                result = gtk_text_iter_forward_search_insensitive (&selection_end, current_search, 
                                                                   &match_start, &match_end);
                if (!result)
-                       hildon_banner_show_information (NULL, NULL, dgettext ("hildon-libs", "ckct_ib_find_search_complete"));
+                       hildon_banner_show_information (NULL, NULL, _HL("ckct_ib_find_search_complete"));
        } else {
                GtkTextIter buffer_start;
                gtk_text_buffer_get_start_iter (priv->text_buffer, &buffer_start);
                result = gtk_text_iter_forward_search_insensitive (&buffer_start, current_search, 
                                                                   &match_start, &match_end);
                if (!result)
-                       hildon_banner_show_information (NULL, NULL, dgettext ("hildon-libs", "ckct_ib_find_no_matches"));
+                       hildon_banner_show_information (NULL, NULL, _HL("ckct_ib_find_no_matches"));
        }
 
        /* Mark as selected the string found in search */
@@ -3496,18 +3554,6 @@ modest_msg_edit_window_find_toolbar_search (GtkWidget *widget,
        g_free (current_search);
 }
 
-static void
-modest_msg_edit_window_find_toolbar_close (GtkWidget *widget,
-                                          ModestMsgEditWindow *window)
-{
-       GtkToggleAction *toggle;
-       ModestWindowPrivate *parent_priv;
-       parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
-
-       toggle = GTK_TOGGLE_ACTION (gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/ToolsMenu/FindInMessageMenu"));
-       gtk_toggle_action_set_active (toggle, FALSE);
-}
-
 gboolean 
 modest_msg_edit_window_get_sent (ModestMsgEditWindow *window)
 {
@@ -3527,8 +3573,14 @@ modest_msg_edit_window_set_sent (ModestMsgEditWindow *window,
        priv->sent = sent;
 }
 
+static void
+modest_msg_edit_window_find_toolbar_close (GtkWidget *widget,
+                                          ModestMsgEditWindow *window)
+{
+       modest_msg_edit_window_toggle_find_toolbar (window, FALSE);
+}
 
-void            
+void
 modest_msg_edit_window_set_draft (ModestMsgEditWindow *window,
                                  TnyMsg *draft)
 {
@@ -3539,7 +3591,6 @@ modest_msg_edit_window_set_draft (ModestMsgEditWindow *window,
        g_return_if_fail ((draft == NULL)||(TNY_IS_MSG (draft)));
 
        priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
-       ModestWindowMgr *mgr = modest_runtime_get_window_mgr ();
 
        if (priv->draft_msg != NULL) {
                g_object_unref (priv->draft_msg);
@@ -3553,12 +3604,6 @@ modest_msg_edit_window_set_draft (ModestMsgEditWindow *window,
                        priv->msg_uid = NULL;
                }
                priv->msg_uid = modest_tny_folder_get_header_unique_id (header);
-               if (GTK_WIDGET_REALIZED (window)) {
-                       if (!modest_window_mgr_register_window (mgr, MODEST_WINDOW (window), NULL)) {
-                               gtk_widget_destroy (GTK_WIDGET (window));
-                               return;
-                       }
-               }
        }
 
        priv->draft_msg = draft;
@@ -3573,7 +3618,7 @@ text_buffer_apply_tag (GtkTextBuffer *buffer, GtkTextTag *tag,
        ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (userdata);
        gchar *tag_name;
 
-       if (tag == NULL+13) return;
+       if (tag == NULL) return;
        g_object_get (G_OBJECT (tag), "name", &tag_name, NULL);
        if ((tag_name != NULL) && (g_str_has_prefix (tag_name, "image-tag-replace-"))) {
                replace_with_images (window, priv->images);
@@ -3668,25 +3713,333 @@ on_account_removed (TnyAccountStore *account_store,
        }
 }
 
-static gboolean
-on_zoom_minus_plus_not_implemented (ModestWindow *window)
+static void
+from_field_changed (HildonPickerButton *button,
+                   ModestMsgEditWindow *self)
 {
-       g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window), FALSE);
+       ModestMsgEditWindowPrivate *priv;
+       gboolean has_old_signature, has_new_signature;
+       GtkTextIter iter;
+       GtkTextIter match_start, match_end;
+       ModestAccountMgr *mgr;
+       gchar *signature;
+       gchar *full_signature;
 
-       hildon_banner_show_information (NULL, NULL, dgettext("hildon-common-strings", "ckct_ib_cannot_zoom_here"));
-       return FALSE;
+       priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (self);
+
+       gtk_text_buffer_get_start_iter (priv->text_buffer, &iter);
+       mgr = modest_runtime_get_account_mgr ();
+       signature = modest_account_mgr_get_signature (mgr, priv->last_from_account, &has_old_signature);
+       if (has_old_signature) {
+               full_signature = g_strconcat ("\n--\n", signature, NULL);
+               if (gtk_text_iter_forward_search (&iter, full_signature, 0, &match_start, &match_end, NULL)) {
+                       gtk_text_buffer_delete (priv->text_buffer, &match_start, &match_end);
+                       iter = match_start;
+               } else if (gtk_text_iter_forward_search (&iter, _("mcen_ia_editor_original_message"), 0,
+                                                        &match_start, &match_end, NULL)) {
+                       iter = match_start;
+               }
+               g_free (full_signature);
+       }
+       g_free (signature);
 
+       priv->last_from_account = modest_selector_picker_get_active_id (MODEST_SELECTOR_PICKER (priv->from_field));
+       signature = modest_account_mgr_get_signature (mgr, priv->last_from_account, &has_new_signature);
+       if (has_new_signature) {
+               full_signature = g_strconcat ("\n--\n", signature, NULL);
+               gtk_text_buffer_insert (priv->text_buffer, &iter, full_signature, -1);
+               g_free (full_signature);
+       }
+       g_free (signature);
 }
 
+typedef struct _MessageSettingsHelper {
+       ModestMsgEditWindow *window;
+       GSList *priority_group;
+       GSList *format_group;
+       GtkToggleButton *current_priority;
+       GtkToggleButton *current_format;
+} MessageSettingsHelper;
+
 static void
-set_zoom_do_nothing (ModestWindow *window,
-                                gdouble zoom)
+on_priority_toggle (GtkToggleButton *button, 
+                   MessageSettingsHelper *helper)
 {
+       GSList *node;
+       ModestMsgEditWindowPrivate *priv;
+
+       priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (helper->window);
+       if (gtk_toggle_button_get_active (button)) {
+
+               for (node = helper->priority_group; node != NULL; node = g_slist_next (node)) {
+                       GtkToggleButton *node_button = (GtkToggleButton *) node->data;
+                       if ((node_button != button) &&
+                           gtk_toggle_button_get_active (node_button)) {
+                               gtk_toggle_button_set_active (node_button, FALSE);
+                       }
+               }
+               helper->current_priority = button;
+       } else {
+               gboolean found = FALSE;
+               /* If no one is active, activate it again */
+               for (node = helper->priority_group; node != NULL; node = g_slist_next (node)) {
+                       GtkToggleButton *node_button = (GtkToggleButton *) node->data;
+                       if (gtk_toggle_button_get_active (node_button)) {
+                               found = TRUE;
+                               break;
+                       }
+               }
+               if (!found) {
+                       gtk_toggle_button_set_active (button, TRUE);
+               }
+       }
 }
 
-static gdouble
-get_zoom_do_nothing (ModestWindow *window)
+static void
+on_format_toggle (GtkToggleButton *button,
+                 MessageSettingsHelper *helper)
 {
-       return 1.0;
+       GSList *node;
+       ModestMsgEditWindowPrivate *priv;
+
+       priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (helper->window);
+       if (gtk_toggle_button_get_active (button)) {
+
+               for (node = helper->format_group; node != NULL; node = g_slist_next (node)) {
+                       GtkToggleButton *node_button = (GtkToggleButton *) node->data;
+                       if ((node_button != button) &&
+                           gtk_toggle_button_get_active (node_button)) {
+                               gtk_toggle_button_set_active (node_button, FALSE);
+                       }
+               }
+               helper->current_format = button;
+       } else {
+               gboolean found = FALSE;
+               /* If no one is active, activate it again */
+               for (node = helper->format_group; node != NULL; node = g_slist_next (node)) {
+                       GtkToggleButton *node_button = (GtkToggleButton *) node->data;
+                       if (gtk_toggle_button_get_active (node_button)) {
+                               found = TRUE;
+                               break;
+                       }
+               }
+               if (!found) {
+                       gtk_toggle_button_set_active (button, TRUE);
+               }
+       }
+
+}
+
+static void
+modest_msg_edit_window_show_msg_settings_dialog (ModestMsgEditWindow *window)
+{
+       GtkWidget *dialog;
+       GtkWidget *align;
+       GtkWidget *vbox;
+       GtkWidget *priority_hbox;
+       GtkWidget *high_toggle, *medium_toggle, *low_toggle;
+       GtkWidget *captioned;
+       GtkSizeGroup *title_sizegroup, *value_sizegroup;
+       GtkWidget *format_hbox;
+       GtkWidget *html_toggle, *text_toggle;
+       ModestMsgEditWindowPrivate *priv;
+       MessageSettingsHelper helper = {0,};
+
+       g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
+       priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
+       helper.window = window;
+       helper.priority_group = NULL;
+       helper.format_group = NULL;
+
+       title_sizegroup = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
+       value_sizegroup = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
+
+       dialog = gtk_dialog_new_with_buttons (_("mcen_me_message_settings"), NULL,
+                                             GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+                                             _HL("wdgt_bd_done"), GTK_RESPONSE_ACCEPT, NULL);
+       vbox = gtk_vbox_new (FALSE, 0);
+       align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
+       gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE, 0);
+       gtk_container_add (GTK_CONTAINER (align), vbox);
+       gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), align);
+       gtk_widget_show (align);
+       gtk_widget_show (vbox);
+
+       /* Priority toggles */
+       priority_hbox = gtk_hbox_new (TRUE, 0);
+       high_toggle = hildon_gtk_toggle_button_new (HILDON_SIZE_FINGER_HEIGHT);
+       gtk_button_set_label (GTK_BUTTON (high_toggle), _("mcen_me_editor_priority_high"));
+       helper.priority_group = g_slist_prepend (helper.priority_group, high_toggle);
+       g_object_set_data (G_OBJECT (high_toggle), "priority", GINT_TO_POINTER (TNY_HEADER_FLAG_HIGH_PRIORITY));
+       medium_toggle = hildon_gtk_toggle_button_new (HILDON_SIZE_FINGER_HEIGHT);
+       gtk_button_set_label (GTK_BUTTON (medium_toggle), _("mcen_me_editor_priority_normal"));
+       helper.priority_group = g_slist_prepend (helper.priority_group, medium_toggle);
+       g_object_set_data (G_OBJECT (medium_toggle), "priority", GINT_TO_POINTER (TNY_HEADER_FLAG_NORMAL_PRIORITY));
+       low_toggle = hildon_gtk_toggle_button_new (HILDON_SIZE_FINGER_HEIGHT);
+       gtk_button_set_label (GTK_BUTTON (low_toggle), _("mcen_me_editor_priority_low"));
+       helper.priority_group = g_slist_prepend (helper.priority_group, low_toggle);
+       g_object_set_data (G_OBJECT (low_toggle), "priority", GINT_TO_POINTER (TNY_HEADER_FLAG_LOW_PRIORITY));
+       gtk_box_pack_start (GTK_BOX (priority_hbox), low_toggle, TRUE, TRUE, 0);
+       gtk_box_pack_start (GTK_BOX (priority_hbox), medium_toggle, TRUE, TRUE, 0);
+       gtk_box_pack_start (GTK_BOX (priority_hbox), high_toggle, TRUE, TRUE, 0);
+       gtk_widget_show_all (priority_hbox);
+       captioned = modest_maemo_utils_create_captioned (title_sizegroup, value_sizegroup,
+                                                        _("mcen_me_editor_message_priority"), FALSE, priority_hbox);
+       gtk_widget_show (captioned);
+       gtk_box_pack_start (GTK_BOX (vbox), captioned, FALSE, FALSE, 0);
+
+       /* format toggles */
+       format_hbox = gtk_hbox_new (TRUE, 0);
+       html_toggle = hildon_gtk_toggle_button_new (HILDON_SIZE_FINGER_HEIGHT);
+       gtk_button_set_label (GTK_BUTTON (html_toggle), _("mcen_me_editor_formatted_text"));
+       helper.format_group = g_slist_prepend (helper.format_group, html_toggle);
+       g_object_set_data (G_OBJECT (html_toggle), "format", GINT_TO_POINTER (MODEST_MSG_EDIT_FORMAT_HTML));
+       g_object_set_data (G_OBJECT (html_toggle), "file-format", GINT_TO_POINTER (MODEST_FILE_FORMAT_FORMATTED_TEXT));
+       text_toggle = hildon_gtk_toggle_button_new (HILDON_SIZE_FINGER_HEIGHT);
+       gtk_button_set_label (GTK_BUTTON (text_toggle), _("mcen_me_editor_plain_text"));
+       helper.format_group = g_slist_prepend (helper.format_group, text_toggle);
+       g_object_set_data (G_OBJECT (text_toggle), "format", GINT_TO_POINTER (MODEST_MSG_EDIT_FORMAT_TEXT));
+       g_object_set_data (G_OBJECT (text_toggle), "file-format", GINT_TO_POINTER (MODEST_FILE_FORMAT_PLAIN_TEXT));
+       gtk_box_pack_start (GTK_BOX (format_hbox), html_toggle, TRUE, TRUE, 0);
+       gtk_box_pack_start (GTK_BOX (format_hbox), text_toggle, TRUE, TRUE, 0);
+       gtk_widget_show_all (format_hbox);
+       gtk_widget_show (format_hbox);
+       gtk_box_pack_start (GTK_BOX (vbox), format_hbox, FALSE, FALSE, 0);
+
+
+       g_object_unref (title_sizegroup);
+       g_object_unref (value_sizegroup);
+
+       /* Set current values */
+       switch (priv->priority_flags) {
+       case TNY_HEADER_FLAG_HIGH_PRIORITY:
+               gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (high_toggle), TRUE);
+               helper.current_priority = GTK_TOGGLE_BUTTON (high_toggle);
+               break;
+       case TNY_HEADER_FLAG_LOW_PRIORITY:
+               gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (low_toggle), TRUE);
+               helper.current_priority = GTK_TOGGLE_BUTTON (low_toggle);
+               break;
+       default:
+               gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (medium_toggle), TRUE);
+               helper.current_priority = GTK_TOGGLE_BUTTON (medium_toggle);
+               break;
+       }
+
+       switch (modest_msg_edit_window_get_format (window)) {
+       case MODEST_MSG_EDIT_FORMAT_TEXT:
+               gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (text_toggle), TRUE);
+               helper.current_format = GTK_TOGGLE_BUTTON (text_toggle);
+               break;
+       case MODEST_MSG_EDIT_FORMAT_HTML:
+       default:
+               gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (html_toggle), TRUE);
+               helper.current_format = GTK_TOGGLE_BUTTON (html_toggle);
+               break;
+       }
+
+       /* Signal connects */
+       g_signal_connect (G_OBJECT (high_toggle), "toggled", G_CALLBACK (on_priority_toggle), &helper);
+       g_signal_connect (G_OBJECT (medium_toggle), "toggled", G_CALLBACK (on_priority_toggle), &helper);
+       g_signal_connect (G_OBJECT (low_toggle), "toggled", G_CALLBACK (on_priority_toggle), &helper);
+       g_signal_connect (G_OBJECT (html_toggle), "toggled", G_CALLBACK (on_format_toggle), &helper);
+       g_signal_connect (G_OBJECT (text_toggle), "toggled", G_CALLBACK (on_format_toggle), &helper);
+
+       /* Save settings if the user clicked on done */
+       if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) {
+               TnyHeaderFlags flags;
+               ModestMsgEditFormat old_format, new_format;
+
+               /* Set priority flags */
+               flags = (TnyHeaderFlags) g_object_get_data (G_OBJECT (helper.current_priority), "priority");
+               if (priv->priority_flags !=  flags)
+                       modest_msg_edit_window_set_priority_flags (window, flags);
+
+               /* Set edit format */
+               old_format = modest_msg_edit_window_get_format (window);
+               new_format = (ModestMsgEditFormat) g_object_get_data (G_OBJECT (helper.current_format), "format");
+               if (old_format != new_format) {
+                       gint file_format = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (helper.current_format), "file-format"));
+                       modest_msg_edit_window_set_file_format (window, file_format);
+               }
+       }
+
+       gtk_widget_destroy (dialog);
+       g_slist_free (helper.priority_group);
+}
+
+static void
+on_message_settings (GtkAction *action,
+                    ModestMsgEditWindow *window)
+{
+       modest_msg_edit_window_show_msg_settings_dialog (window);
+}
+
+static void
+on_cc_button_toggled (HildonCheckButton *button,
+                     ModestMsgEditWindow *window)
+{
+       g_return_if_fail (MODEST_MSG_EDIT_WINDOW (window));
+
+       modest_msg_edit_window_show_cc (MODEST_MSG_EDIT_WINDOW (window),
+                                       hildon_check_button_get_active (button));
+}
+
+static void
+on_bcc_button_toggled (HildonCheckButton *button,
+                     ModestMsgEditWindow *window)
+{
+       g_return_if_fail (MODEST_MSG_EDIT_WINDOW (window));
+
+       modest_msg_edit_window_show_bcc (MODEST_MSG_EDIT_WINDOW (window),
+                                       hildon_check_button_get_active (button));
+}
+
+static void 
+setup_menu (ModestMsgEditWindow *self)
+{
+       ModestMsgEditWindowPrivate *priv = NULL;
+
+       g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(self));
+
+       priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (self);
+
+       /* Settings menu buttons */
+       modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_editor_checknames"), NULL,
+                                          APP_MENU_CALLBACK (modest_ui_actions_on_check_names),
+                                          NULL);
+       modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_inbox_undo"), "<Ctrl>z",
+                                          APP_MENU_CALLBACK (modest_ui_actions_on_undo),
+                                          MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_undo));
+
+       priv->cc_button = hildon_check_button_new (0);
+       gtk_button_set_label (GTK_BUTTON (priv->cc_button), _("mcen_me_editor_showcc"));
+       hildon_check_button_set_active (HILDON_CHECK_BUTTON (priv->cc_button),
+                                       FALSE);
+       modest_hildon2_window_add_button_to_menu (MODEST_HILDON2_WINDOW (self), GTK_BUTTON (priv->cc_button),
+                                                 NULL);
+       g_signal_connect (G_OBJECT (priv->cc_button), "toggled",
+                         G_CALLBACK (on_cc_button_toggled), (gpointer) self);
+       priv->bcc_button = hildon_check_button_new (0);
+       gtk_button_set_label (GTK_BUTTON (priv->bcc_button), _("mcen_me_editor_showbcc"));
+       hildon_check_button_set_active (HILDON_CHECK_BUTTON (priv->bcc_button),
+                                       FALSE);
+       modest_hildon2_window_add_button_to_menu (MODEST_HILDON2_WINDOW (self), GTK_BUTTON (priv->bcc_button),
+                                                 NULL);
+       g_signal_connect (G_OBJECT (priv->bcc_button), "toggled",
+                         G_CALLBACK (on_bcc_button_toggled), (gpointer) self);
+
+       modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_editor_attach_inlineimage"), NULL,
+                                          APP_MENU_CALLBACK (modest_ui_actions_on_insert_image),
+                                          MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_set_style));
+       modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_inbox_remove_attachments"), NULL,
+                                          APP_MENU_CALLBACK (modest_ui_actions_on_remove_attachments),
+                                          MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_editor_remove_attachment));
+       modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_message_settings"), NULL,
+                                          APP_MENU_CALLBACK (on_message_settings),
+                                          NULL);
+       modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_viewer_find"), "<Ctrl>f",
+                                          APP_MENU_CALLBACK (modest_ui_actions_on_toggle_find_in_page),
+                                          NULL);
 }