Fix for bug NB#81584.
[modest] / src / widgets / modest-recpt-view.c
index de48e5b..cb8511c 100644 (file)
@@ -36,6 +36,8 @@
 #include <modest-text-utils.h>
 #include <modest-recpt-view.h>
 
+#define RECPT_VIEW_CLICK_AREA_THRESHOLD 32
+
 static GObjectClass *parent_class = NULL;
 
 /* signals */
@@ -57,6 +59,13 @@ struct _ModestRecptViewPriv
 
 static guint signals[LAST_SIGNAL] = {0};
 
+/* static functions: GObject */
+static void modest_recpt_view_instance_init (GTypeInstance *instance, gpointer g_class);
+static void modest_recpt_view_finalize (GObject *object);
+static void modest_recpt_view_class_init (ModestRecptViewClass *klass);
+/* static functions: GtkWidget */
+static gint button_press_event (GtkWidget *widget, GdkEventButton *event, gpointer user_data);
+static gint button_release_event (GtkWidget *widget, GdkEventButton *event, gpointer user_data);
 
 /**
  * modest_recpt_view_new:
@@ -76,11 +85,19 @@ modest_recpt_view_set_recipients (ModestRecptView *recpt_view, const gchar *reci
 {
        const GtkWidget *text_view = NULL;
        GtkTextBuffer *buffer = NULL;
+       gchar *std_recipients;
 
        text_view = modest_scroll_text_get_text_view (MODEST_SCROLL_TEXT (recpt_view));
        buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
 
-       gtk_text_buffer_set_text (buffer, recipients, -1);
+       if (recipients == NULL) {
+               std_recipients = NULL;
+       } else {
+               std_recipients = modest_text_utils_address_with_standard_length (recipients);
+       }
+
+       gtk_text_buffer_set_text (buffer, std_recipients, -1);
+       g_free (std_recipients);
        if (GTK_WIDGET_REALIZED (recpt_view))
                gtk_widget_queue_resize (GTK_WIDGET (recpt_view));
 
@@ -116,20 +133,23 @@ button_release_event (GtkWidget *widget,
 
        if ((priv->button_pressed) &&
            (event->type == GDK_BUTTON_RELEASE) &&
-           (priv->pressed_x == event->x) &&
-           (priv->pressed_y == event->y)) {
+           ((event->x >= priv->pressed_x - RECPT_VIEW_CLICK_AREA_THRESHOLD)&&
+            (event->x <= priv->pressed_x + RECPT_VIEW_CLICK_AREA_THRESHOLD)) &&
+           ((event->y >= priv->pressed_y - RECPT_VIEW_CLICK_AREA_THRESHOLD)&&
+            (event->y <= priv->pressed_y + RECPT_VIEW_CLICK_AREA_THRESHOLD))) {
                priv->button_pressed = FALSE;
                if (event->button == 1) {
                        gint buffer_x, buffer_y;
                        int index;
                        GtkTextIter iter;
+                       gtk_widget_grab_focus (GTK_WIDGET (text_view));
                        gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view), GTK_TEXT_WINDOW_WIDGET,
                                                               event->x, event->y, &buffer_x, &buffer_y);
                        gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (text_view), &iter, buffer_x, buffer_y);
                        index = gtk_text_iter_get_offset (&iter);
                        
                        if (!gtk_text_iter_is_end (&iter)) {
-                               int selection_start, selection_end;
+                               guint selection_start, selection_end;
                                gboolean selected = FALSE;
                                GtkTextIter start_iter, end_iter;
                                GtkTextBuffer *buffer;
@@ -146,23 +166,24 @@ button_release_event (GtkWidget *widget,
                                        gtk_text_buffer_get_end_iter (buffer, &end_iter);
                                        text = gtk_text_buffer_get_text (buffer, &start_iter, &end_iter, FALSE);
 
-                                       modest_text_utils_address_range_at_position (text,
-                                                                                    index,
-                                                                                    &selection_start, &selection_end);
-                                       /* TODO: now gtk label tries to select more than the label as usual,
-                                        *  and we force it to recover the selected region for the defined area.
-                                        *  It should be fixed (maybe preventing gtklabel to manage selections
-                                        *  in parallel with us
-                                        */
-                                       gtk_text_buffer_get_iter_at_offset (buffer, &start_iter, selection_start);
-                                       gtk_text_buffer_get_iter_at_offset (buffer, &end_iter, selection_end);
-                                       gtk_text_buffer_select_range (buffer, &start_iter, &end_iter);
-                                       
-                                       if (text)
+                                       /* text will not be NULL, but source code checkers should be satisfied */
+                                       if (text) {
+                                               modest_text_utils_address_range_at_position (text,
+                                                                                            index,
+                                                                                            &selection_start, &selection_end);
+                                               /* TODO: now gtk label tries to select more than the label as usual,
+                                                *  and we force it to recover the selected region for the defined area.
+                                                *  It should be fixed (maybe preventing gtklabel to manage selections
+                                                *  in parallel with us
+                                                */
+                                               gtk_text_buffer_get_iter_at_offset (buffer, &start_iter, selection_start);
+                                               gtk_text_buffer_get_iter_at_offset (buffer, &end_iter, selection_end);
+                                               gtk_text_buffer_select_range (buffer, &start_iter, &end_iter);
+                                               
                                                g_free (text);
-                                                                     
+                                       }                     
                                }
-
+                               
                                if (selected) {
                                        gchar *selection;
 
@@ -185,10 +206,10 @@ modest_recpt_view_instance_init (GTypeInstance *instance, gpointer g_class)
 {
        const GtkTextView *text_view = NULL;
 
-       text_view = modest_scroll_text_get_text_view (MODEST_SCROLL_TEXT (instance));
+       text_view = GTK_TEXT_VIEW(modest_scroll_text_get_text_view (MODEST_SCROLL_TEXT (instance)));
 
        g_signal_connect (G_OBJECT (text_view), "button-press-event", G_CALLBACK (button_press_event), instance);
-       g_signal_connect (G_OBJECT (text_view), "button-release-event", G_CALLBACK (button_release_event), instance);
+       g_signal_connect_after (G_OBJECT (text_view), "button-release-event", G_CALLBACK (button_release_event), instance);
 
        return;
 }