rework image viewer
authorPaul <paul@claws-mail.org>
Wed, 30 Dec 2020 15:03:40 +0000 (15:03 +0000)
committerPaul <paul@claws-mail.org>
Wed, 30 Dec 2020 15:03:40 +0000 (15:03 +0000)
add options, when resizing images, to either fit the image width or fit the image height. image height is the default. regardless of this setting, when displaying images inline they will fit the height

src/gtk/gtkutils.c
src/gtk/gtkutils.h
src/image_viewer.c
src/prefs_common.c
src/prefs_common.h
src/prefs_image_viewer.c
src/textview.c

index 0e8bf48915f42751e3ad364b74df98aef8377dc1..60bf674fc039f138b2227fffad29880326127a8c 100644 (file)
@@ -1707,8 +1707,8 @@ claws_input_add    (gint        source,
  *
  * @return a GdkPixbuf
  */
-GdkPixbuf *claws_load_pixbuf_fitting(GdkPixbuf *src_pixbuf, int box_width,
-                                    int box_height)
+GdkPixbuf *claws_load_pixbuf_fitting(GdkPixbuf *src_pixbuf, gboolean inline_img,
+                                    gboolean fit_img_height, int box_width, int box_height)
 {
        gint w, h, orientation, angle;
        gint avail_width, avail_height;
@@ -1779,9 +1779,20 @@ GdkPixbuf *claws_load_pixbuf_fitting(GdkPixbuf *src_pixbuf, int box_width,
        avail_height = box_height;
                
        if (box_width != -1 && box_height != -1 && avail_width - 100 > 0) {
-               if (w > avail_width || h > avail_height) {
-                       h = (avail_width * h) / w;
-                       w = avail_width;
+               if (inline_img || fit_img_height) {
+                       if (w > avail_width) {
+                               h = (avail_width * h) / w;
+                               w = avail_width;
+                       }
+                       if (h > avail_height) {
+                               w = (avail_height * w) / h;
+                               h = avail_height;
+                       }
+               } else {
+                       if (w > avail_width || h > avail_height) {
+                               h = (avail_width * h) / w;
+                               w = avail_width;
+                       }
                }
                t_pixbuf = gdk_pixbuf_scale_simple(pixbuf, 
                        w, h, GDK_INTERP_BILINEAR);
index 8bfb68a0b3f1aef4ed5fb728a66deb69259e216f..a8dafcba472150e93eb34dfe7c05e122b628f6df 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2017 Hiroyuki Yamamoto and the Claws Mail team
+ * Copyright (C) 1999-2020 the Claws Mail team and Hiroyuki Yamamoto
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -181,8 +181,9 @@ gboolean gtkut_list_view_select_row(GtkWidget *list, gint row);
 GtkUIManager *gtkut_create_ui_manager(void);
 GtkUIManager *gtkut_ui_manager(void);
 
-GdkPixbuf *claws_load_pixbuf_fitting(GdkPixbuf *pixbuf, int box_width,
-                                    int box_height);
+GdkPixbuf *claws_load_pixbuf_fitting(GdkPixbuf *pixbuf, gboolean inline_img,
+                                    gboolean fit_img_height,
+                                    int box_width, int box_height);
 
 GtkWidget *gtkut_time_select_combo_new();
 void gtkut_time_select_select_by_time(GtkComboBox *combo, int hour, int minute);
index 6a0ce40f4954cb98b51bee711c6e927eb1d75773..ca9e67c310eb7120dc70641a3462c1801fb3e4bb 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2012 Hiroyuki Yamamoto and the Claws Mail team
+ * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2020 the Claws Mail team and Hiroyuki Yamamoto
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -48,6 +48,7 @@ struct _ImageViewer
        gchar     *file;
        MimeInfo  *mimeinfo;
        gboolean   resize_img;
+       gboolean   fit_img_height;
 
        GtkWidget *scrolledwin;
        GtkWidget *image;
@@ -103,24 +104,24 @@ static void image_viewer_load_image(ImageViewer *imageviewer)
 
 #if GDK_PIXBUF_MINOR >= 28
        if (gdk_pixbuf_animation_is_static_image(animation)
-           || imageviewer->resize_img) {
+           || imageviewer->resize_img || imageviewer->fit_img_height) {
                pixbuf = gdk_pixbuf_animation_get_static_image(animation);
                g_object_ref(pixbuf);
                g_object_unref(animation);
                animation = NULL;
 #else
-       if (imageviewer->resize_img) {
+       if (imageviewer->resize_img || imageviewer->fit_img_height) {
 #endif
 
                if (imageviewer->resize_img) {
-                       gtk_widget_get_allocation(
-                               gtk_widget_get_parent(imageviewer->notebook), &allocation);
-                       pixbuf = claws_load_pixbuf_fitting(pixbuf,
+                       gtk_widget_get_allocation(imageviewer->scrolledwin, &allocation);
+                       pixbuf = claws_load_pixbuf_fitting(pixbuf, FALSE,
+                               imageviewer->fit_img_height,
                                allocation.width,
                                allocation.height);
                }
                else
-                       pixbuf = claws_load_pixbuf_fitting(pixbuf, -1, -1);
+                       pixbuf = claws_load_pixbuf_fitting(pixbuf, FALSE, imageviewer->fit_img_height, -1, -1);
        }
 
        if (error && !pixbuf && !animation) {
@@ -216,6 +217,7 @@ static void image_viewer_clear_viewer(MimeViewer *_mimeviewer)
        imageviewer->file = NULL;
        imageviewer->mimeinfo = NULL;
        imageviewer->resize_img = prefs_common.resize_img;
+       imageviewer->fit_img_height = prefs_common.fit_img_height;
 }
 
 static void image_viewer_destroy_viewer(MimeViewer *_mimeviewer)
@@ -266,6 +268,10 @@ static gboolean scrolledwin_button_cb(GtkWidget *scrolledwin, GdkEventButton *ev
                imageviewer->resize_img = !imageviewer->resize_img;
                image_viewer_load_image(imageviewer);
                return TRUE;
+       } else if (event->button == 3 && imageviewer->image) {
+               imageviewer->fit_img_height = !imageviewer->fit_img_height;
+               image_viewer_load_image(imageviewer);
+               return TRUE;
        }
        return FALSE;
 }
@@ -392,6 +398,7 @@ static MimeViewer *image_viewer_create(void)
        imageviewer->mimeviewer.get_selection = NULL;
 
        imageviewer->resize_img   = prefs_common.resize_img;
+       imageviewer->fit_img_height   = prefs_common.fit_img_height;
 
        imageviewer->scrolledwin  = scrolledwin;
        imageviewer->image = gtk_image_new();
index 0d4f6f08049b27718bb4d95c3fab8d7d5ae8eaaa..8ca507ab0968d17d0d5f5ca47c769573902214e2 100644 (file)
@@ -428,6 +428,8 @@ static PrefParam param[] = {
         NULL, NULL, NULL},
        {"inline_image", "TRUE", &prefs_common.inline_img, P_BOOL,
         NULL, NULL, NULL},
+       {"fit_image_height", "TRUE", &prefs_common.fit_img_height, P_BOOL,
+        NULL, NULL, NULL},
 
        {"display_folder_unread_num", "0",
         &prefs_common.display_folder_unread, P_INT,
index eae0ab76d7a85f7e0e26e3693145eae2e21992cc..12689763b438334915372fd8626fde803903ed33 100644 (file)
@@ -246,6 +246,7 @@ struct _PrefsCommon
        gboolean display_img;
        gboolean resize_img;
        gboolean inline_img;
+       gboolean fit_img_height;
 
        gboolean trans_hdr;
        gint display_folder_unread;
index 0edf109d844637c69afa753a85d20fbbe537a029..d7748db54c15e518cd2a371aa31fda84614b59a5 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2012 Hiroyuki Yamamoto and the Claws Mail Team
+ * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2020 the Claws Mail Team
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -44,6 +44,8 @@ typedef struct _ImageViewerPage
 
        GtkWidget *autoload_img;
        GtkWidget *resize_img;
+       GtkWidget *fit_img_height_radiobtn;
+       GtkWidget *fit_img_width_radiobtn;
        GtkWidget *inline_img;
        GtkWidget *print_imgs;
 }ImageViewerPage;
@@ -57,6 +59,11 @@ static void imageviewer_create_widget_func(PrefsPage * _page,
        GtkWidget *table;
        GtkWidget *autoload_img;
        GtkWidget *resize_img;
+       GtkWidget *vbox;
+       GtkWidget *hbox;
+       GtkWidget *fit_img_label;
+       GtkWidget *fit_img_height_radiobtn;
+       GtkWidget *fit_img_width_radiobtn;
        GtkWidget *inline_img;
        GtkWidget *print_imgs;
 
@@ -80,26 +87,58 @@ static void imageviewer_create_widget_func(PrefsPage * _page,
                         (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                         (GtkAttachOptions) (0), 0, 0);
 
+       vbox = gtk_vbox_new(FALSE, VSPACING);
+       hbox = gtk_hbox_new(FALSE, 8);
+       gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
+       gtk_widget_show(vbox);
+       gtk_widget_show(hbox);
+
+       fit_img_label = gtk_label_new (_("Fit image"));
+       gtk_widget_show(fit_img_label);
+       CLAWS_SET_TIP(fit_img_label,
+                            _("Right-clicking image toggles fitting height/width"));
+       gtk_box_pack_start(GTK_BOX(hbox), fit_img_label, FALSE, FALSE, 0);
+
+       fit_img_height_radiobtn = gtk_radio_button_new_with_label(NULL, _("Height"));
+       gtk_widget_show(fit_img_height_radiobtn);
+       gtk_box_pack_start(GTK_BOX(hbox), fit_img_height_radiobtn, FALSE, FALSE, 0);
+
+       fit_img_width_radiobtn = gtk_radio_button_new_with_label_from_widget(
+                                          GTK_RADIO_BUTTON(fit_img_height_radiobtn), _("Width"));
+       gtk_widget_show(fit_img_width_radiobtn);
+       gtk_box_pack_start(GTK_BOX(hbox), fit_img_width_radiobtn, FALSE, FALSE, 0);
+       gtk_table_attach(GTK_TABLE(table), vbox, 0, 1, 2, 3,
+                        (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
+                        (GtkAttachOptions) (0), 0, 0);
+
        inline_img = gtk_check_button_new_with_label(_("Display images inline"));
        gtk_widget_show(inline_img);
-       gtk_table_attach(GTK_TABLE(table), inline_img, 0, 1, 2, 3,
+       gtk_table_attach(GTK_TABLE(table), inline_img, 0, 1, 3, 4,
                         (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                         (GtkAttachOptions) (0), 0, 0);
        
        print_imgs = gtk_check_button_new_with_label(_("Print images"));
        gtk_widget_show(print_imgs);
-       gtk_table_attach(GTK_TABLE(table), print_imgs, 0, 1, 3, 4,
+       gtk_table_attach(GTK_TABLE(table), print_imgs, 0, 1, 4, 5,
                         (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                         (GtkAttachOptions) (0), 0, 0);
        
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(resize_img), prefs_common.resize_img);
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(autoload_img), prefs_common.display_img);
+       if (prefs_common.fit_img_height)
+               gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(fit_img_height_radiobtn), TRUE);
+       else
+               gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(fit_img_width_radiobtn), TRUE);
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(inline_img), prefs_common.inline_img);
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(print_imgs), prefs_common.print_imgs);
+       
+       SET_TOGGLE_SENSITIVITY(resize_img, vbox);
 
        prefs_imageviewer->window       = GTK_WIDGET(window);
        prefs_imageviewer->autoload_img = autoload_img;
        prefs_imageviewer->resize_img   = resize_img;
+       prefs_imageviewer->fit_img_height_radiobtn      = fit_img_height_radiobtn;
+       prefs_imageviewer->fit_img_width_radiobtn       = fit_img_width_radiobtn;
        prefs_imageviewer->inline_img   = inline_img;
        prefs_imageviewer->print_imgs   = print_imgs;
 
@@ -120,6 +159,9 @@ static void imageviewer_save_func(PrefsPage * _page)
        prefs_common.resize_img =
            gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
                                         (imageviewer->resize_img));
+       prefs_common.fit_img_height =
+           gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
+                                       (imageviewer->fit_img_height_radiobtn));
        prefs_common.inline_img =
            gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
                                         (imageviewer->inline_img));
index 230639ce50d7ab321f8319070e542d4247b7063a..62ad46eaf6735fc368aeb8dc569ead7ad9cd2b50 100644 (file)
@@ -735,8 +735,8 @@ static void textview_add_part(TextView *textview, MimeInfo *mimeinfo)
                        }
 
                        gtk_widget_get_allocation(textview->scrolledwin, &allocation);
-                       pixbuf = claws_load_pixbuf_fitting(pixbuf,
-                                       allocation.width,
+                       pixbuf = claws_load_pixbuf_fitting(pixbuf, prefs_common.inline_img,
+                                       prefs_common.fit_img_height, allocation.width,
                                        allocation.height);
 
                        if (textview->stop_loading) {