o allow toggling of image scaling by clicking on image
authorLuke Plant <L.Plant.98@cantab.net>
Tue, 4 Nov 2003 01:20:11 +0000 (01:20 +0000)
committerLuke Plant <L.Plant.98@cantab.net>
Tue, 4 Nov 2003 01:20:11 +0000 (01:20 +0000)
o  respond to image's container widget resize

src/plugins/image_viewer/viewer.c
src/plugins/image_viewer/viewerprefs.c
src/plugins/image_viewer/viewerprefs.glade

index d525794..77359b8 100644 (file)
@@ -53,6 +53,7 @@ struct _ImageViewer
 
        gchar     *file;
        MimeInfo  *mimeinfo;
+       gboolean   resize_img;
 
        GtkWidget *scrolledwin;
        GtkWidget *image;
@@ -91,7 +92,7 @@ static void image_viewer_load_file(ImageViewer *imageviewer, const gchar *imgfil
                return;
        }
 
-       if (imageviewerprefs.resize_img) {
+       if (imageviewer->resize_img) {
                avail_width = imageviewer->notebook->parent->allocation.width;
                avail_height = imageviewer->notebook->parent->allocation.height;
                if (avail_width > 8) avail_width -= 8;
@@ -141,7 +142,7 @@ static void image_viewer_load_file(ImageViewer *imageviewer, const gchar *imgfil
                return;
        }
 
-       if (imageviewerprefs.resize_img) {
+       if (imageviewer->resize_img) {
                avail_width = imageviewer->notebook->parent->allocation.width;
                avail_height = imageviewer->notebook->parent->allocation.height;
                if (avail_width > 8) avail_width -= 8;
@@ -240,6 +241,7 @@ static void image_viewer_clear_viewer(MimeViewer *_mimeviewer)
        g_free(imageviewer->file);
        imageviewer->file = NULL;
        imageviewer->mimeinfo = NULL;
+       imageviewer->resize_img   = imageviewerprefs.resize_img;
 }
 
 static void image_viewer_destroy_viewer(MimeViewer *_mimeviewer)
@@ -283,6 +285,24 @@ static void load_cb(GtkButton *button, ImageViewer *imageviewer)
        image_viewer_load_image(imageviewer);
 }
 
+static gboolean scrolledwin_button_cb(GtkWidget *scrolledwin, GdkEventButton *event,
+                                     ImageViewer *imageviewer)
+{
+       if (event->button == 1 && imageviewer->image) {
+               imageviewer->resize_img = !imageviewer->resize_img;
+               image_viewer_load_image(imageviewer);
+               return TRUE;
+       }
+       return FALSE;
+}
+
+static void scrolledwin_resize_cb(GtkWidget *scrolledwin, GtkAllocation *alloc,
+                                 ImageViewer *imageviewer)
+{
+       if (imageviewer->resize_img)
+               image_viewer_load_image(imageviewer);
+}
+
 MimeViewer *image_viewer_create(void)
 {
        ImageViewer *imageviewer;
@@ -380,6 +400,8 @@ MimeViewer *image_viewer_create(void)
        imageviewer->mimeviewer.clear_viewer = image_viewer_clear_viewer;
        imageviewer->mimeviewer.destroy_viewer = image_viewer_destroy_viewer;
 
+       imageviewer->resize_img   = imageviewerprefs.resize_img;
+
        imageviewer->scrolledwin  = scrolledwin;
        imageviewer->image        = NULL;
        imageviewer->notebook     = notebook;
@@ -391,6 +413,10 @@ MimeViewer *image_viewer_create(void)
 
        gtk_signal_connect(GTK_OBJECT(load_button), "released",
                           GTK_SIGNAL_FUNC(load_cb), imageviewer);
+       gtk_signal_connect(GTK_OBJECT(scrolledwin), "button-press-event",
+                          GTK_SIGNAL_FUNC(scrolledwin_button_cb), imageviewer);
+       gtk_signal_connect(GTK_OBJECT(scrolledwin), "size-allocate",
+                          GTK_SIGNAL_FUNC(scrolledwin_resize_cb), imageviewer);
 
        image_viewer_set_notebook_page((MimeViewer *)imageviewer);
 
index 5abba59..612176d 100644 (file)
@@ -82,7 +82,7 @@ static void imageviewer_create_widget_func(PrefsPage * _page,
                         (GtkAttachOptions) (0), 0, 0);
        gtk_misc_set_alignment(GTK_MISC(label14), 0, 0.5);
 
-       label15 = gtk_label_new(_("Resize attached images"));
+       label15 = gtk_label_new(_("Resize attached images by default\n(Clicking image toggles scaling)"));
        gtk_widget_show(label15);
        gtk_table_attach(GTK_TABLE(table2), label15, 0, 1, 1, 2,
                         (GtkAttachOptions) (GTK_FILL),
index 9501349..06ff17d 100644 (file)
@@ -62,8 +62,9 @@
     <widget>
       <class>GtkLabel</class>
       <name>label15</name>
-      <label>Resize attached images</label>
-      <justify>GTK_JUSTIFY_CENTER</justify>
+      <label>Resize attached images
+(Clicking image toggles scaling)</label>
+      <justify>GTK_JUSTIFY_LEFT</justify>
       <wrap>False</wrap>
       <xalign>0</xalign>
       <yalign>0.5</yalign>