static void html_adjustment_changed (GtkAdjustment *adj, gpointer data);
static void disconnect_vadjustment (ModestMsgView *obj);
static void disconnect_hadjustment (ModestMsgView *obj);
+static gboolean idle_readjust_scroll (ModestMsgView *obj);
/* GtkContainer methods */
static void forall (GtkContainer *container, gboolean include_internals,
priv->headers_window = NULL;
priv->html_window = NULL;
-
gtk_widget_push_composite_child ();
priv->html_scroll = gtk_scrolled_window_new (NULL, NULL);
gtk_widget_set_composite_name (priv->html_scroll, "contents");
if (part_cid && strcmp (cid, part_cid) == 0)
break;
- g_object_unref (G_OBJECT(part));
+ if (part)
+ g_object_unref (G_OBJECT(part));
part = NULL;
tny_iterator_next (iter);
gtk_html_load_from_string (GTK_HTML(priv->gtkhtml),
"", 1);
+
return TRUE;
}
TnyMimePart *body;
ModestMsgViewPrivate *priv;
TnyHeader *header;
+ GtkAdjustment *html_vadj;
g_return_if_fail (self);
modest_attachments_view_set_message (MODEST_ATTACHMENTS_VIEW(priv->attachments_view),
msg);
- body = modest_tny_msg_find_body_part (msg,TRUE);
+ body = modest_tny_msg_find_body_part (msg, TRUE);
if (body) {
- GList *att_children;
if (tny_mime_part_content_type_is (body, "text/html"))
set_html_message (self, body, msg);
else
set_text_message (self, body, msg);
- att_children = gtk_container_get_children (GTK_CONTAINER (priv->attachments_view));
- if (att_children != NULL) {
+ if(modest_attachments_view_has_attachments (MODEST_ATTACHMENTS_VIEW (priv->attachments_view))) {
gtk_widget_show_all (priv->attachments_box);
- g_list_free (att_children);
} else {
gtk_widget_hide_all (priv->attachments_box);
}
if (priv->vadj != NULL)
priv->vadj->value = 0.0;
+ html_vadj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (priv->html_scroll));
+
+ g_signal_emit_by_name (G_OBJECT (html_vadj), "changed");
+
+ /* This is a hack to force reallocation of scroll after drawing all the stuff. This
+ * makes the html view get the proper and expected size and prevent being able to scroll
+ * the buffer when it shouldn't be scrollable */
+ g_object_ref (self);
+ g_timeout_add (250, (GSourceFunc) idle_readjust_scroll, self);
}
return msg;
}
+static gboolean
+has_contents_receiver (gpointer engine, const gchar *data,
+ size_t len, gboolean *has_contents)
+{
+ if (len > 1 || ((len == 1)&&(data[0]!='\n'))) {
+ *has_contents = TRUE;
+ return FALSE;
+ }
+ return TRUE;
+}
+
+gboolean
+modest_msg_view_get_message_is_empty (ModestMsgView *self)
+{
+ /* TODO: Find some gtkhtml API to check whether there is any (visible, non markup)
+ * text in the message:
+ */
+ ModestMsgViewPrivate *priv = MODEST_MSG_VIEW_GET_PRIVATE (self);
+ gboolean has_contents = FALSE;
+
+ gtk_html_export (GTK_HTML (priv->gtkhtml), "text/plain",
+ (GtkHTMLSaveReceiverFn) has_contents_receiver, &has_contents);
+
+ return !has_contents;
+}
+
+
gboolean
modest_msg_view_search (ModestMsgView *self, const gchar *search)
{
gtk_layout_set_vadjustment (GTK_LAYOUT (priv->gtkhtml), tmp_vadj);
result = gtk_html_engine_search (GTK_HTML (priv->gtkhtml),
search,
- FALSE, TRUE, TRUE);
+ FALSE, /* case sensitive */
+ TRUE, /* forward */
+ FALSE); /* regexp */
+
+// wait for the updated gtkhtml (w27) to enable this
+#if 0
+ if (result) {
+ gint x, y, w, h;
+ gdouble offset_top, offset_bottom;
+ GtkAdjustment *adj;
+ gtk_html_get_selection_area (GTK_HTML (priv->gtkhtml), &x, &y, &w, &h);
+ offset_top = (gdouble) (priv->headers_box->requisition.height + y);
+ offset_bottom = (gdouble) (priv->headers_box->requisition.height + y + h);
+ adj = GTK_ADJUSTMENT (priv->vadj);
+ if (offset_top < adj->value)
+ gtk_adjustment_set_value (adj, offset_top + adj->page_increment - adj->page_size);
+ else if (offset_bottom > adj->value + adj->page_increment)
+ gtk_adjustment_set_value (adj, offset_bottom - adj->page_increment);
+ }
+#endif
+
y_offset = tmp_vadj->value;
gtk_layout_set_vadjustment (GTK_LAYOUT (priv->gtkhtml), vadj);
g_object_unref (vadj);
priv = MODEST_MSG_VIEW_GET_PRIVATE (self);
result = gtk_html_engine_search_next (GTK_HTML (priv->gtkhtml));
-/*
- {
+// fixme wait for new gtkhtml
+#if 0
+ if (result) {
+ gint x, y, w, h;
+ gdouble offset_top, offset_bottom;
GtkAdjustment *adj;
-
- adj = gtk_container_get_focus_vadjustment (GTK_CONTAINER (priv->gtkhtml));
+ gtk_html_get_selection_area (GTK_HTML (priv->gtkhtml), &x, &y, &w, &h);
+ g_message ("SELECTION AREA x%d y%d w%d h%d", x, y, w, h);
+ offset_top = (gdouble) (priv->headers_box->requisition.height + y);
+ offset_bottom = (gdouble) (priv->headers_box->requisition.height + y + h);
+ adj = GTK_ADJUSTMENT (priv->vadj);
+ if (offset_top < adj->value)
+ gtk_adjustment_set_value (adj, offset_top + adj->page_increment - adj->page_size);
+ else if (offset_bottom > adj->value + adj->page_increment)
+ gtk_adjustment_set_value (adj, offset_bottom - adj->page_increment);
}
-*/
-
+#endif
return result;
}
return modest_attachments_view_get_selection (MODEST_ATTACHMENTS_VIEW (priv->attachments_view));
}
+
+GList *
+modest_msg_view_get_attachments (ModestMsgView *self)
+{
+ ModestMsgViewPrivate *priv;
+
+ g_return_val_if_fail (MODEST_IS_MSG_VIEW (self), NULL);
+ priv = MODEST_MSG_VIEW_GET_PRIVATE (self);
+
+ return modest_attachments_view_get_attachments (MODEST_ATTACHMENTS_VIEW (priv->attachments_view));
+
+}
+
+void
+modest_msg_view_grab_focus (ModestMsgView *view)
+{
+ ModestMsgViewPrivate *priv = NULL;
+
+ g_return_if_fail (MODEST_IS_MSG_VIEW (view));
+ priv = MODEST_MSG_VIEW_GET_PRIVATE (view);
+
+ gtk_widget_grab_focus (priv->gtkhtml);
+}
+
+void
+modest_msg_view_remove_attachment (ModestMsgView *view, TnyMimePart *attachment)
+{
+ TnyMsg *msg;
+ ModestMsgViewPrivate *priv;
+
+ g_return_if_fail (MODEST_IS_MSG_VIEW (view));
+ g_return_if_fail (TNY_IS_MIME_PART (attachment));
+ priv = MODEST_MSG_VIEW_GET_PRIVATE (view);
+
+ msg = modest_msg_view_get_message (view);
+ modest_attachments_view_remove_attachment (MODEST_ATTACHMENTS_VIEW (priv->attachments_view),
+ attachment);
+
+}
+
+gboolean
+idle_readjust_scroll (ModestMsgView *view)
+{
+ if (GTK_WIDGET_DRAWABLE (view)) {
+ ModestMsgViewPrivate *priv = MODEST_MSG_VIEW_GET_PRIVATE (view);
+ GtkAdjustment *html_vadj;
+ html_vadj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (priv->html_scroll));
+ html_vadj->upper = html_vadj->page_size;
+ gtk_adjustment_changed (html_vadj);
+ gtk_widget_queue_resize (GTK_WIDGET (view));
+ gtk_widget_queue_draw (GTK_WIDGET (view));
+ }
+ g_object_unref (G_OBJECT (view));
+ return FALSE;
+}