Changes to disable cut/copy with images (fixes NB#80355).
[modest] / src / maemo / modest-msg-edit-window.c
index 4196068..639ecb4 100644 (file)
@@ -169,7 +169,7 @@ static void init_window (ModestMsgEditWindow *obj);
 
 gboolean scroll_drag_timeout (gpointer userdata);
 static void correct_scroll (ModestMsgEditWindow *w);
-static void correct_scroll_without_drag_check (ModestMsgEditWindow *w);
+static void correct_scroll_without_drag_check (ModestMsgEditWindow *w, gboolean only_if_focused);
 static void text_buffer_end_user_action (GtkTextBuffer *buffer,
                                         ModestMsgEditWindow *userdata);
 static void text_buffer_mark_set (GtkTextBuffer *buffer,
@@ -245,6 +245,7 @@ struct _ModestMsgEditWindowPrivate {
        
        ModestPairList *from_field_protos;
        GtkWidget   *from_field;
+       const gchar *original_account_name;
        
        GtkWidget   *to_field;
        GtkWidget   *cc_field;
@@ -544,7 +545,7 @@ scroll_drag_timeout (gpointer userdata)
 
        priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE(win);
 
-       correct_scroll_without_drag_check (win);
+       correct_scroll_without_drag_check (win, TRUE);
 
        priv->scroll_drag_timeout_id = 0;
 
@@ -552,7 +553,7 @@ scroll_drag_timeout (gpointer userdata)
 }
 
 static void
-correct_scroll_without_drag_check (ModestMsgEditWindow *w)
+correct_scroll_without_drag_check (ModestMsgEditWindow *w, gboolean only_if_focused)
 {
        ModestMsgEditWindowPrivate *priv;
        GtkTextMark *insert;
@@ -565,7 +566,7 @@ correct_scroll_without_drag_check (ModestMsgEditWindow *w)
 
        priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE(w);
 
-       if (!gtk_widget_is_focus (priv->msg_body))
+       if (only_if_focused && !gtk_widget_is_focus (priv->msg_body))
                return;
 
        insert = gtk_text_buffer_get_insert (priv->text_buffer);
@@ -579,7 +580,7 @@ correct_scroll_without_drag_check (ModestMsgEditWindow *w)
        
        if ((offset + rectangle.y + rectangle.height) > 
            ((gint) (vadj->value +vadj->page_size))) {
-               new_value = (offset + rectangle.y) + vadj->page_size * 0.75;
+               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)) {
@@ -619,7 +620,7 @@ correct_scroll (ModestMsgEditWindow *w)
                return;
        }
 
-       correct_scroll_without_drag_check (w);
+       correct_scroll_without_drag_check (w, TRUE);
 }
 
 static void
@@ -640,6 +641,30 @@ text_buffer_mark_set (GtkTextBuffer *buffer,
        gtk_text_buffer_end_user_action (buffer);
 }
 
+static void
+cut_clipboard_check (GtkTextView *text_view,
+                    gpointer userdata)
+{
+       GtkTextBuffer *buffer;
+       
+       buffer = gtk_text_view_get_buffer (text_view);
+       if (!modest_text_utils_buffer_selection_is_valid (buffer)) {
+               g_signal_stop_emission_by_name ((gpointer )text_view, "cut-clipboard");
+       }
+}
+
+static void
+copy_clipboard_check (GtkTextView *text_view,
+                    gpointer userdata)
+{
+       GtkTextBuffer *buffer;
+       
+       buffer = gtk_text_view_get_buffer (text_view);
+       if (!modest_text_utils_buffer_selection_is_valid (buffer)) {
+               g_signal_stop_emission_by_name ((gpointer )text_view, "copy-clipboard");
+       }
+}
+
 void vadj_changed (GtkAdjustment *adj,
                   ModestMsgEditWindow *window)
 {
@@ -719,6 +744,9 @@ connect_signals (ModestMsgEditWindow *obj)
                g_signal_connect (G_OBJECT (gtk_clipboard_get (GDK_SELECTION_CLIPBOARD)), "owner-change",
                                  G_CALLBACK (modest_msg_edit_window_clipboard_owner_change), obj);
 
+       g_signal_connect (G_OBJECT (priv->msg_body), "cut-clipboard", G_CALLBACK (cut_clipboard_check), NULL);
+       g_signal_connect (G_OBJECT (priv->msg_body), "copy-clipboard", G_CALLBACK (copy_clipboard_check), NULL);
+
 }
 
 static void
@@ -1491,6 +1519,8 @@ modest_msg_edit_window_new (TnyMsg *msg, const gchar *account_name, gboolean pre
        if (account_pair != NULL)
                modest_combo_box_set_active_id (MODEST_COMBO_BOX (priv->from_field), account_pair->first);
 
+       priv->original_account_name = account_pair ? (const gchar *) account_pair->first : 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);
@@ -3010,6 +3040,7 @@ gboolean
 modest_msg_edit_window_is_modified (ModestMsgEditWindow *editor)
 {
        ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (editor);
+       const char *account_name;
        GtkTextBuffer *buffer;
 
        buffer = modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR(priv->to_field));
@@ -3023,6 +3054,10 @@ modest_msg_edit_window_is_modified (ModestMsgEditWindow *editor)
                return TRUE;
        if (gtk_text_buffer_get_modified (priv->text_buffer))
                return TRUE;
+       account_name = modest_combo_box_get_active_id (MODEST_COMBO_BOX (priv->from_field));
+       if (!priv->original_account_name || strcmp(account_name, priv->original_account_name)) {
+               return TRUE;
+       }
 
        return FALSE;
 }
@@ -3366,6 +3401,7 @@ modest_msg_edit_window_find_toolbar_search (GtkWidget *widget,
        if (result) {
                gtk_text_buffer_select_range (priv->text_buffer, &match_start, &match_end);
                gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW (priv->msg_body), &match_start, 0.0, TRUE, 0.0, 0.0);
+               correct_scroll_without_drag_check (MODEST_MSG_EDIT_WINDOW (window), FALSE);
        } else {
                g_free (priv->last_search);
                priv->last_search = NULL;