-static void
-get_view_allocation (ModestMsgView *msg_view, GtkAllocation *allocation)
-{
- /* This method gets the allocation of the widget in parent widget. It's the
- real position and size of the widget */
- ModestMsgViewPrivate *priv = MODEST_MSG_VIEW_GET_PRIVATE (msg_view);
-
- allocation->x = 0;
- allocation->y = 0;
-
- if (priv->shadow_type != GTK_SHADOW_NONE) {
- allocation->x = GTK_WIDGET (msg_view)->style->xthickness;
- allocation->y = GTK_WIDGET (msg_view)->style->ythickness;
- }
-
- allocation->width = MAX (1, (GTK_WIDGET (msg_view)->allocation.width) - allocation->x * 2);
- allocation->height = MAX (1, (GTK_WIDGET (msg_view)->allocation.height) - allocation->y * 2);
-
-}
-
-static void
-reclamp_adjustment (GtkAdjustment *adj,
- gboolean *value_changed)
-{
- gdouble value = adj->value;
-
- /* Correct value to be inside the expected values of a scroll */
-
- value = CLAMP (value, 0, adj->upper - adj->page_size);
-
- if (value != adj->value) {
- adj->value = value;
- if (value_changed)
- *value_changed = TRUE;
- } else if (value_changed) {
- *value_changed = FALSE;
- }
-}
-
-static void
-set_hadjustment_values (ModestMsgView *msg_view,
- gboolean *value_changed)
-{
- GtkAllocation view_allocation;
- GtkAdjustment *hadj = modest_msg_view_get_hadjustment (msg_view);
-
- get_view_allocation (msg_view, &view_allocation);
- hadj->page_size = view_allocation.width;
- hadj->step_increment = view_allocation.width * 0.1;
- hadj->page_increment = view_allocation.width * 0.9;
-
- hadj->lower = 0;
- hadj->upper = view_allocation.width;
-
- reclamp_adjustment (hadj, value_changed);
-
-}
-
-static void
-set_vadjustment_values (ModestMsgView *msg_view,
- gboolean *value_changed)
-{
- GtkAllocation view_allocation;
- GtkAdjustment *vadj = modest_msg_view_get_vadjustment (msg_view);
- ModestMsgViewPrivate *priv = MODEST_MSG_VIEW_GET_PRIVATE (msg_view);
- gint full_height = 0;
- GtkAdjustment *html_vadj;
-
- get_view_allocation (msg_view, &view_allocation);
- vadj->page_size = view_allocation.height;
- vadj->step_increment = view_allocation.height * 0.1;
- vadj->page_increment = view_allocation.height * 0.9;
-
- vadj->lower = 0;
-
- if (priv->headers_box && GTK_WIDGET_VISIBLE(priv->headers_box)) {
- GtkRequisition child_requisition;
-
- gtk_widget_get_child_requisition (priv->headers_box, &child_requisition);
- full_height = child_requisition.height;
- } else {
- full_height = 0;
- }
-
- /* Get the real height of the embedded html */
- if (priv->html_scroll && GTK_WIDGET_VISIBLE(priv->html_scroll)) {
- html_vadj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (priv->html_scroll));
- full_height += html_vadj->upper;
- }
-
- vadj->upper = MAX (view_allocation.height, full_height);
-
- reclamp_adjustment (vadj, value_changed);
-
-}
-
-static void
-set_scroll_adjustments (ModestMsgView *msg_view,
- GtkAdjustment *hadj,
- GtkAdjustment *vadj)
-{
- ModestMsgViewPrivate *priv = MODEST_MSG_VIEW_GET_PRIVATE (msg_view);
- modest_msg_view_set_hadjustment (msg_view, hadj);
- modest_msg_view_set_vadjustment (msg_view, vadj);
-
- gtk_container_set_focus_vadjustment (GTK_CONTAINER (priv->gtkhtml), vadj);
-}
-
-static void
-realize (GtkWidget *widget)
-{
- ModestMsgView *msg_view = MODEST_MSG_VIEW (widget);
- ModestMsgViewPrivate *priv = MODEST_MSG_VIEW_GET_PRIVATE (msg_view);
- GtkAdjustment *hadj = modest_msg_view_get_hadjustment (msg_view);
- GtkAdjustment *vadj = modest_msg_view_get_vadjustment (msg_view);
- GdkWindowAttr attributes;
- gint event_mask;
- gint attributes_mask;
- GtkAllocation view_allocation;
-
- GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
-
- /* The structure of the GdkWindow's is:
- * * widget->window: the shown gdkwindow embedding all the stuff inside
- * * view_window: a backing store gdkwindow containing the headers and contents
- * being scrolled. This window should have all the visible and non visible
- * widgets inside.
- * * headers_window: gdk window for headers_box.
- * * html_window: gdk window for html_scroll (the scrolled window containing the
- * gtkhtml showing the contents of the mail).
- */
-
- attributes.x = widget->allocation.x;
- attributes.y = widget->allocation.y;
- attributes.width = widget->allocation.width;
- attributes.height = widget->allocation.height;
- attributes.window_type = GDK_WINDOW_CHILD;
- attributes.wclass = GDK_INPUT_OUTPUT;
- attributes.visual = gtk_widget_get_visual (widget);
- attributes.colormap = gtk_widget_get_colormap (widget);
-
- event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
- attributes.event_mask = event_mask | GDK_BUTTON_PRESS_MASK;
- attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
-
- widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
- &attributes, attributes_mask);
- gdk_window_set_user_data (widget->window, msg_view);
-
- get_view_allocation (msg_view, &view_allocation);
-
- attributes.x = view_allocation.x;
- attributes.y = view_allocation.y;
- attributes.width = view_allocation.width;
- attributes.height = view_allocation.height;
- attributes.event_mask = 0;
- priv->view_window = gdk_window_new (widget->window, &attributes, attributes_mask);
- gdk_window_set_user_data (priv->view_window, msg_view);
- gdk_window_set_back_pixmap (priv->view_window, NULL, FALSE);
-
- attributes.x = -hadj->value;
- attributes.y = -vadj->value;
- attributes.width = hadj->upper;
- if (priv->headers_box)
- attributes.height = GTK_WIDGET (priv->headers_box)->allocation.height;
- else
- attributes.height = 1;
- attributes.event_mask = event_mask;
-
- priv->headers_window = gdk_window_new (priv->view_window, &attributes, attributes_mask);
- gdk_window_set_user_data (priv->headers_window, msg_view);
-
- if (priv->headers_box)
- gtk_widget_set_parent_window (priv->headers_box, priv->headers_window);
-
- attributes.x = -hadj->value;
- if (priv->headers_box)
- attributes.y = GTK_WIDGET (priv->headers_box)->allocation.height - vadj->value;
- else
- attributes.y = -vadj->value;
- attributes.width = hadj->upper;
- if (priv->headers_box)
- attributes.height = vadj->upper - GTK_WIDGET (priv->headers_box)->allocation.height;
- else
- attributes.height = vadj->upper;
- attributes.event_mask = event_mask;
-
- priv->html_window = gdk_window_new (priv->view_window, &attributes, attributes_mask);
- gdk_window_set_user_data (priv->html_window, msg_view);
-
- if (priv->html_scroll)
- gtk_widget_set_parent_window (priv->html_scroll, priv->html_window);
-
- widget->style = gtk_style_attach (widget->style, widget->window);
- gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
- gtk_style_set_background (widget->style, priv->headers_window, GTK_STATE_NORMAL);
- gtk_style_set_background (widget->style, priv->html_window, GTK_STATE_NORMAL);
-
- gtk_paint_flat_box(widget->style, priv->headers_window, GTK_STATE_NORMAL,
- GTK_SHADOW_NONE,
- NULL, widget, "msgviewheaders",
- 0,0,-1,-1);
- gtk_paint_flat_box(widget->style, priv->html_window, GTK_STATE_NORMAL,
- GTK_SHADOW_NONE,
- NULL, widget, "msgviewcontents",
- 0,0,-1,-1);
-
- gdk_window_show (priv->view_window);
- gdk_window_show (priv->headers_window);
- gdk_window_show (priv->html_window);
-
-}
-
-static void
-unrealize (GtkWidget *widget)