* src/widgets/modest-attachment-view.c:
[modest] / src / widgets / modest-attachments-view.c
index e03795a..bc5f823 100644 (file)
@@ -323,8 +323,10 @@ button_press_event (GtkWidget *widget,
                gtk_widget_grab_focus (widget);
 
        if (event->button == 1 && event->type == GDK_BUTTON_PRESS) {
-               GtkWidget *att_view = get_att_view_at_coords (MODEST_ATTACHMENTS_VIEW (widget), 
-                                                             event->x, event->y);
+               GtkWidget *att_view = NULL;
+
+               att_view = get_att_view_at_coords (MODEST_ATTACHMENTS_VIEW (widget), 
+                                                  (gint) event->x_root, (gint) event->y_root);
 
                if (att_view != NULL) {
                        if (GTK_WIDGET_STATE (att_view) == GTK_STATE_SELECTED && (g_list_length (priv->selected) < 2)) {
@@ -351,8 +353,10 @@ button_release_event (GtkWidget *widget,
 {
        ModestAttachmentsViewPrivate *priv = MODEST_ATTACHMENTS_VIEW_GET_PRIVATE (atts_view);
        if (widget == gtk_grab_get_current ()) {
-               GtkWidget *att_view = get_att_view_at_coords (MODEST_ATTACHMENTS_VIEW (widget), 
-                                                             event->x, event->y);
+               GtkWidget *att_view = NULL;
+
+               att_view = get_att_view_at_coords (MODEST_ATTACHMENTS_VIEW (widget), 
+                                                  (gint) event->x_root, (gint) event->y_root);
 
                if (att_view != NULL) {
                        unselect_all (MODEST_ATTACHMENTS_VIEW (widget));
@@ -361,7 +365,6 @@ button_release_event (GtkWidget *widget,
                                      MODEST_ATTACHMENT_VIEW (att_view));
                }
                priv->rubber_start = NULL;
-               
                gtk_grab_remove (widget);
        }
        return TRUE;
@@ -374,8 +377,10 @@ motion_notify_event (GtkWidget *widget,
 {
        ModestAttachmentsViewPrivate *priv = MODEST_ATTACHMENTS_VIEW_GET_PRIVATE (atts_view);
        if (gtk_grab_get_current () == widget) {
-               GtkWidget *att_view = get_att_view_at_coords (MODEST_ATTACHMENTS_VIEW (widget), 
-                                                             event->x, event->y);
+               GtkWidget *att_view = NULL;
+
+               att_view = get_att_view_at_coords (MODEST_ATTACHMENTS_VIEW (widget), 
+                                                  (gint) event->x_root, (gint) event->y_root);
 
                if (att_view != NULL) {
                        unselect_all (MODEST_ATTACHMENTS_VIEW (widget));
@@ -504,14 +509,17 @@ get_att_view_at_coords (ModestAttachmentsView *atts_view,
        for (node = att_view_list; node != NULL; node = g_list_next (node)) {
                GtkWidget *att_view = (GtkWidget *) node->data;
                gint pos_x, pos_y, w, h, int_x, int_y;
+               gint widget_x, widget_y;
+
+               gdk_window_get_origin (att_view->window, &widget_x, &widget_y);
 
-               pos_x = att_view->allocation.x;
-               pos_y = att_view->allocation.y;
+               pos_x = widget_x;
+               pos_y = widget_y;
                w = att_view->allocation.width;
                h = att_view->allocation.height;
 
-               int_x = (gint) x;
-               int_y = (gint) y;
+               int_x = (gint) x - GTK_WIDGET (atts_view)->allocation.x;
+               int_y = (gint) y - GTK_WIDGET (atts_view)->allocation.y;
 
                if ((x >= pos_x) && (x <= (pos_x + w)) && (y >= pos_y) && (y <= (pos_y + h))) {
                        result = att_view;
@@ -655,6 +663,27 @@ modest_attachments_view_get_selection (ModestAttachmentsView *atts_view)
        return selection;
 }
 
+GList *
+modest_attachments_view_get_attachments (ModestAttachmentsView *atts_view)
+{
+       ModestAttachmentsViewPrivate *priv;
+       GList *children, *node, *att_list = NULL;
+
+       g_return_val_if_fail (MODEST_IS_ATTACHMENTS_VIEW (atts_view), NULL);
+       priv = MODEST_ATTACHMENTS_VIEW_GET_PRIVATE (atts_view);
+
+       children = gtk_container_get_children (GTK_CONTAINER (priv->box));
+       for (node = children; node != NULL; node = g_list_next (node)) {
+               GtkWidget *att_view = GTK_WIDGET (node->data);
+               TnyMimePart *mime_part = tny_mime_part_view_get_part (TNY_MIME_PART_VIEW (att_view));
+               att_list = g_list_prepend (att_list, mime_part);
+       }
+       g_list_free (children);
+       att_list = g_list_reverse (att_list);
+       return att_list;
+
+}
+
 void
 modest_attachments_view_select_all (ModestAttachmentsView *atts_view)
 {
@@ -678,6 +707,23 @@ modest_attachments_view_select_all (ModestAttachmentsView *atts_view)
        own_clipboard (atts_view);
 }
 
+gboolean
+modest_attachments_view_has_attachments (ModestAttachmentsView *atts_view)
+{
+       ModestAttachmentsViewPrivate *priv;
+       GList *children;
+       gboolean result;
+
+       g_return_val_if_fail (MODEST_IS_ATTACHMENTS_VIEW (atts_view), FALSE);
+       priv = MODEST_ATTACHMENTS_VIEW_GET_PRIVATE (atts_view);
+
+       children = gtk_container_get_children (GTK_CONTAINER (priv->box));
+       result = (children != NULL);
+       g_list_free (children);
+
+       return result;
+}
+
 static void
 own_clipboard (ModestAttachmentsView *atts_view)
 {