BalsaMimeWidget * balsa_mime_widget_new_image(BalsaMessage * bm, LibBalsaMessageBody * mime_body, const gchar * content_type, gpointer data) { GdkPixbuf *pixbuf; GtkWidget *image; GError * load_err = NULL; BalsaMimeWidgetImage *mwi; BalsaMimeWidget *mw; g_return_val_if_fail(mime_body != NULL, NULL); g_return_val_if_fail(content_type != NULL, NULL); pixbuf = libbalsa_message_body_get_pixbuf(mime_body, &load_err); if (!pixbuf) { if (load_err) { balsa_information(LIBBALSA_INFORMATION_ERROR, _("Error loading attached image: %s\n"), load_err->message); g_error_free(load_err); } return NULL; } mwi = g_object_new(BALSA_TYPE_MIME_WIDGET_IMAGE, NULL); mw = (BalsaMimeWidget *) mwi; mw->widget = gtk_event_box_new(); g_signal_connect(G_OBJECT(mw->widget), "button-press-event", G_CALLBACK(balsa_image_button_press_cb), data); #if !GTK_CHECK_VERSION(3, 15, 0) mwi->context = gtk_widget_get_style_context(GTK_WIDGET(bm->scroll)); bmwi_context_changed_cb(mwi->context, mw); mwi->context_changed_handler_id = g_signal_connect(mwi->context, "changed", G_CALLBACK(bmwi_context_changed_cb), mw); #endif image = gtk_image_new_from_icon_name("image-missing", GTK_ICON_SIZE_BUTTON); g_object_set_data(G_OBJECT(image), "orig-width", GINT_TO_POINTER(gdk_pixbuf_get_width(pixbuf))); g_object_set_data(G_OBJECT(image), "mime-body", mime_body); g_object_unref(pixbuf); gtk_container_add(GTK_CONTAINER(mw->widget), image); return mw; }
GList * balsa_print_object_image(GList * list, GtkPrintContext *context, LibBalsaMessageBody *body, BalsaPrintSetup * psetup) { BalsaPrintObjectImage *poi; BalsaPrintObject *po; GdkPixbuf *pixbuf; GError *err = NULL; gdouble c_use_width; gdouble c_img_width; gdouble c_img_height; /* check if we can handle the image */ pixbuf = libbalsa_message_body_get_pixbuf(body, &err); if (err) { g_message("Error loading image from file: %s", err->message); g_error_free(err); } /* fall back to default if the pixbuf could no be loaded */ if (!pixbuf) return balsa_print_object_default(list, context, body, psetup); /* create the part */ poi = g_object_new(BALSA_TYPE_PRINT_OBJECT_IMAGE, NULL); g_assert(poi != NULL); po = BALSA_PRINT_OBJECT(poi); po->depth = psetup->curr_depth; poi->pixbuf = pixbuf; c_use_width = psetup->c_width - 2 * psetup->curr_depth * C_LABEL_SEP; c_img_width = gdk_pixbuf_get_width(pixbuf); c_img_height = gdk_pixbuf_get_height(pixbuf); poi->scale = 1.0; /* check if we should scale the width */ if (c_img_width > c_use_width) { poi->scale = c_use_width / c_img_width; c_img_height *= poi->scale; c_img_width = c_use_width; } /* check if the image is too high for one full page */ if (c_img_height > psetup->c_height) { gdouble hscale = psetup->c_height / c_img_height; poi->scale *= hscale; c_img_width *= hscale; c_img_height = psetup->c_height; } /* check if we should move to the next page */ if (psetup->c_y_pos + c_img_height > psetup->c_height) { psetup->c_y_pos = 0; psetup->page_count++; } /* remember the extent */ po->on_page = psetup->page_count - 1; po->c_at_x = psetup->c_x0 + psetup->curr_depth * C_LABEL_SEP; po->c_at_y = psetup->c_y0 + psetup->c_y_pos; po->c_width = c_img_width; poi->c_img_offs = 0.5 * (c_use_width - c_img_width); po->c_height = c_img_height; /* adjust the y position */ psetup->c_y_pos += c_img_height; return g_list_append(list, po); }