fix invalid cast runtime warning
[claws.git] / src / plugins / pdf_viewer / poppler_viewer.c
index 03b0372..5df4661 100644 (file)
@@ -1,13 +1,11 @@
 /*
  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright(C) 1999-2007 the Claws Mail Team
- * This file Copyright (C) 2007 Salvatore De Paolis 
- * <iwkse@claws-mail.org> 
+ * Copyright (C) 1999-2016 Salvatore De Paolis & 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
  * the Free Software Foundation; either version 3 of the License, or
- *(at your option) any later version.
+ * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -15,8 +13,7 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 
 #ifdef HAVE_CONFIG_H
 #include "printing.h"
 #include "prefs_common.h"
 #include "gtk/gtkutils.h"
+#include "gtk/inputdialog.h"
 #include "mimeview.h"
+#include "summaryview.h"
+#include "file-utils.h"
 #ifndef POPPLER_WITH_GDK
 #include "stdbool.h"
 #endif
@@ -83,14 +83,15 @@ static void pdf_viewer_button_rotate_left_cb(GtkButton *button, PdfViewer *viewe
 static void pdf_viewer_spin_change_page_cb(GtkSpinButton *button, PdfViewer *viewer);
 static void pdf_viewer_spin_zoom_scroll_cb(GtkSpinButton *button, PdfViewer *viewer);
 /* Show/Hide the index pane */
-static void pdf_viewer_show_document_index_cb(GtkButton *button, PdfViewer *viewer);
+static void pdf_viewer_show_document_index_cb(GtkToggleButton *button, PdfViewer *viewer);
+static void pdf_viewer_button_print_cb(GtkButton *button, PdfViewer *viewer);
 static void pdf_viewer_button_document_info_cb(GtkButton *button, PdfViewer *viewer);
 
 static void pdf_viewer_show_controls(PdfViewer *viewer, gboolean show);
 static gboolean pdf_viewer_scroll_page(MimeViewer *_viewer, gboolean up);
 static void pdf_viewer_scroll_one_line(MimeViewer *_viewer, gboolean up);
 
-/** Claws-Mail Plugin functions*/
+/** Claws Mail Plugin functions */
 gint plugin_init(gchar **error);
 const gchar *plugin_name(void);
 const gchar *plugin_desc(void);
@@ -272,25 +273,27 @@ static void pdf_viewer_scroll_to(PdfViewer *viewer, gfloat x, gfloat y)
        GtkAdjustment *hadj;
        vadj = gtk_scrolled_window_get_vadjustment(
                GTK_SCROLLED_WINDOW(viewer->scrollwin));
-       
-       if (y < vadj->value) {
-               vadj->value = y;
+
+       if (y < gtk_adjustment_get_value(vadj)) {
+               gtk_adjustment_set_value(vadj, y);
        }
        else {
-               while(y > vadj->value + vadj->page_size) {
-                       vadj->value += vadj->page_size;
+               while(y > gtk_adjustment_get_value(vadj) + gtk_adjustment_get_page_size(vadj)) {
+                       gtk_adjustment_set_value(vadj,
+                                       gtk_adjustment_get_value(vadj) + gtk_adjustment_get_page_size(vadj));
                }
        }
-       
+
        hadj = gtk_scrolled_window_get_hadjustment(
                GTK_SCROLLED_WINDOW(viewer->scrollwin));
-       
-       if (x < hadj->value) {
-               hadj->value = x;
+
+       if (x < gtk_adjustment_get_value(hadj)) {
+               gtk_adjustment_set_value(hadj, x);
        }
        else {
-               while(x > hadj->value + hadj->page_size) {
-                       hadj->value += hadj->page_size;
+               while(x > gtk_adjustment_get_value(hadj) + gtk_adjustment_get_page_size(hadj)) {
+                       gtk_adjustment_set_value(hadj,
+                                       gtk_adjustment_get_value(hadj) + gtk_adjustment_get_page_size(hadj));
                }
        }
 
@@ -298,21 +301,21 @@ static void pdf_viewer_scroll_to(PdfViewer *viewer, gfloat x, gfloat y)
        g_signal_emit_by_name(G_OBJECT(vadj), "value-changed", 0);      
 }
 static void pdf_viewer_render_page(PopplerPage *page, GtkWidget *view, double width, 
-                                                                                               double height, double zoom, gint rotate)
+                                  double height, double zoom, gint rotate)
 {
        GdkPixbuf *pb;
-       
+
        debug_print("width: %f\n", width);
        pb = gdk_pixbuf_new(GDK_COLORSPACE_RGB, 
                                FALSE, 8, 
                                (int)(width * zoom), 
                                (int)(height * zoom));  
-       
+
                        poppler_page_render_to_pixbuf(page, 0, 0, 
                                (int)(width * zoom), 
                                (int)(height * zoom), 
                                zoom, rotate, pb);
-               
+
                        gtk_image_set_from_pixbuf(GTK_IMAGE(view), pb);
                        g_object_unref(G_OBJECT(pb));
 }
@@ -323,13 +326,13 @@ static void pdf_viewer_render_selection(PdfViewer *viewer, PopplerRectangle *rec
        gint width, height;
        GdkPixbuf *sel_pb, *page_pb;
        gfloat x1, x2, y1, y2;  
-       
+
 
        gint cur_page_num = 
                gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(viewer->cur_page));
-       
+
        viewer->last_match = viewer->res_cnt;
-       
+
        viewer->last_rect = NULL;
        viewer->last_page_result = NULL;
        if (cur_page_num != page_results->page_num) {
@@ -337,12 +340,12 @@ static void pdf_viewer_render_selection(PdfViewer *viewer, PopplerRectangle *rec
                gtk_spin_button_set_value(GTK_SPIN_BUTTON(viewer->cur_page), 
        (gdouble) page_results->page_num);
        }
-                       
+
        viewer->last_rect = rect;
        viewer->last_page_result = page_results;
 
        GTK_EVENTS_FLUSH();
-                               
+
        poppler_page_get_size(POPPLER_PAGE(viewer->pdf_page), &width_points, &height_points);
        width = (int)((width_points * viewer->zoom) + 0.5);
        height = (int)((height_points * viewer->zoom) + 0.5);
@@ -382,19 +385,17 @@ static void pdf_viewer_render_selection(PdfViewer *viewer, PopplerRectangle *rec
                y1 = height - y1;
                y2 = height - y2;
        }
-                               
+
        sel_pb = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, 
                                                        selw, selh);
 
        gdk_pixbuf_fill(sel_pb, SELECTION_COLOR);
-                               
-       page_pb = gtk_image_get_pixbuf(GTK_IMAGE(viewer->pdf_view));
-                               
+
        page_pb = gdk_pixbuf_new(GDK_COLORSPACE_RGB, 
                                        FALSE, 8, 
                                (int)(viewer->width * viewer->zoom), 
                                (int)(viewer->height * viewer->zoom));  
-       
+
        poppler_page_render_to_pixbuf(viewer->pdf_page, 
                                        0, 
                                        0, 
@@ -403,14 +404,14 @@ static void pdf_viewer_render_selection(PdfViewer *viewer, PopplerRectangle *rec
                                        viewer->zoom, 
                                        viewer->rotate, 
                                        page_pb);
-                               
+
        gdk_pixbuf_composite(sel_pb, page_pb, 
                                        x1, y2, selw, selh, 0, 0, 
                                        viewer->zoom, viewer->zoom, 
                                        GDK_INTERP_BILINEAR, ALPHA_CHANNEL);
-                               
+
        gtk_image_set_from_pixbuf(GTK_IMAGE(viewer->pdf_view), page_pb);
-       
+
        pdf_viewer_scroll_to(viewer, MIN(x1,x2), MIN(y1,y2));
 
        g_object_unref(G_OBJECT(sel_pb));
@@ -427,7 +428,7 @@ static gboolean     pdf_viewer_text_search(MimeViewer *_viewer, gboolean backward,
 
        debug_print("pdf_viewer_text_search: %s\n", str);
        main_window_cursor_wait(mainwindow_get_mainwindow());
-       
+
        if (viewer->last_search && strcmp(str, viewer->last_search)) {
                search_matches_free(viewer);
                viewer->last_match = -1;
@@ -440,16 +441,16 @@ static gboolean   pdf_viewer_text_search(MimeViewer *_viewer, gboolean backward,
         * across all pages */
        if (viewer->last_match == -1) {
                gint i; 
-               
+
                for(i = 1; i <= viewer->num_pages; i++) {
-                       
+
                        PopplerPage *pdf_page = poppler_document_get_page(viewer->pdf_doc, i - 1);
                        viewer->page_results = poppler_page_find_text(pdf_page, str);
-                       
+
                        if (viewer->page_results != NULL) {
                                debug_print("page_results %p\n", viewer->page_results);
                                /* store results for this page */
-                               gint num_res = 0;
+                               guint num_res = 0;
                                PageResult *res = g_new0(PageResult, 1);
                                res->results = viewer->page_results;
                                res->page_num = i;
@@ -469,14 +470,14 @@ static gboolean   pdf_viewer_text_search(MimeViewer *_viewer, gboolean backward,
                /* put back the list in the correct order */
                viewer->text_found = g_list_reverse(viewer->text_found);
        } 
-       
+
        if (!viewer->text_found) {
                main_window_cursor_normal(mainwindow_get_mainwindow());
                return FALSE;
        } else {
                viewer->last_search = g_strdup(str);
        }
-       
+
        if (backward) {
                /* if backward, we have to initialize stuff to search 
                 * from the end */
@@ -489,9 +490,9 @@ static gboolean     pdf_viewer_text_search(MimeViewer *_viewer, gboolean backward,
        else {
                all_pages_results = viewer->text_found;
        }
-       
+
        for(; all_pages_results; all_pages_results = (backward?all_pages_results->prev:all_pages_results->next)) {
-               
+
                PageResult * page_results = (PageResult *)all_pages_results->data;
 
                if (backward) {
@@ -519,7 +520,7 @@ static gboolean     pdf_viewer_text_search(MimeViewer *_viewer, gboolean backward,
                                main_window_cursor_normal(mainwindow_get_mainwindow());
                                return TRUE;
                        }
-                       
+
                        if (backward) {
                                viewer->res_cnt--;
                        }
@@ -542,7 +543,7 @@ static void pdf_viewer_get_document_index(PdfViewer *viewer, PopplerIndexIter *i
        debug_print("get document index\n");
        do      {
                gint page_num = 0;
-               
+
                action = poppler_index_iter_get_action(index_iter);
 
                if (action->type != POPPLER_ACTION_GOTO_DEST) {
@@ -558,7 +559,7 @@ static void pdf_viewer_get_document_index(PdfViewer *viewer, PopplerIndexIter *i
                        PopplerDest *dest = poppler_document_find_dest(
                                        viewer->pdf_doc, action->goto_dest.dest->named_dest);
                        if (dest->type != POPPLER_DEST_XYZ) {
-                               g_warning("couldn't figure out link\n");
+                               g_warning("couldn't figure out link");
                                poppler_dest_free(dest);
                                continue;
                        }
@@ -568,9 +569,9 @@ static void pdf_viewer_get_document_index(PdfViewer *viewer, PopplerIndexIter *i
 #endif
                else {
 #ifdef HAVE_POPPLER_DEST_NAMED
-                       g_warning("unhandled link type %d\nplease contact developers\n", action->goto_dest.dest->type);
+                       g_warning("unhandled link type %d. please contact developers", action->goto_dest.dest->type);
 #else
-                       g_warning("unhandled link type %d\nplease upgrade libpoppler-glib to 0.5.4\n", action->goto_dest.dest->type);
+                       g_warning("unhandled link type %d. please upgrade libpoppler-glib to 0.5.4", action->goto_dest.dest->type);
 #endif
                        continue;
                }
@@ -599,7 +600,7 @@ static void pdf_viewer_index_row_activated(GtkTreeView              *tree_view,
        GtkTreeModel *model = gtk_tree_view_get_model(tree_view);
        PdfViewer *viewer = (PdfViewer *)data;
        gint page_num = 0;
-       
+
        debug_print("index_row_activated\n");
        if (!gtk_tree_model_get_iter(model, &iter, path)) return;
 
@@ -642,7 +643,7 @@ static char * pdf_viewer_get_document_format_data(GTime utime)
        if (time == 0 || !localtime_r(&time, &t)) return NULL;
 
        len = strftime(s, sizeof(s), fmt_hack, &t);
-       
+
        if (len == 0 || s[0] == '\0') return NULL;
 
        return g_locale_to_utf8(s, -1, NULL, NULL, NULL);
@@ -660,7 +661,7 @@ static char * pdf_viewer_get_document_format_data(GTime utime)
        gtk_table_attach(viewer->table_doc_info, label, 1, 2, row, row+1, GTK_EXPAND | GTK_FILL, 0, 0, 0); \
        row++;
 
-       
+
 static GtkTable * pdf_viewer_fill_info_table(PdfViewer *viewer)
 {
        GtkWidget *label;
@@ -714,7 +715,7 @@ static GtkTable * pdf_viewer_fill_info_table(PdfViewer *viewer)
        tmp = pdf_viewer_get_document_format_data(mod_date);
        ADD_TO_TABLE(_("Modified:"), tmp)
        g_free(tmp);
-       
+
        ADD_TO_TABLE(_("Format:"), format)
        if (linearized) {
                ADD_TO_TABLE(_("Optimized:"), _("Yes"))
@@ -736,11 +737,11 @@ static FileType pdf_viewer_mimepart_get_type(MimeInfo *partinfo)
        debug_print("mimepart_get_type\n");
        if ((partinfo->type == MIMETYPE_APPLICATION) &&
        (!g_ascii_strcasecmp(partinfo->subtype, "octet-stream"))) {
-               
+
                const gchar *filename;
 
                filename = procmime_mimeinfo_get_parameter(partinfo, "filename");
-               
+
                        if (filename == NULL)
                                filename = procmime_mimeinfo_get_parameter(partinfo, "name");
                        if (filename != NULL)
@@ -754,7 +755,7 @@ static FileType pdf_viewer_mimepart_get_type(MimeInfo *partinfo)
        else if (!strcmp(content_type, "application/pdf")) type = TYPE_PDF;
        else if (!strcmp(content_type, "application/postscript")) type = TYPE_PS;
        else type = TYPE_UNKNOWN;
-       
+
        g_free(content_type);
        return type;
 }
@@ -762,25 +763,25 @@ static FileType pdf_viewer_mimepart_get_type(MimeInfo *partinfo)
 /* Callbacks */
 static void pdf_viewer_button_first_page_cb(GtkButton *button, PdfViewer *viewer) 
 {
-       
+
        gtk_spin_button_spin(GTK_SPIN_BUTTON(viewer->cur_page), GTK_SPIN_HOME, 1);
 }
 
 static void pdf_viewer_button_prev_page_cb(GtkButton *button, PdfViewer *viewer) 
 {
-       
+
        gtk_spin_button_spin(GTK_SPIN_BUTTON(viewer->cur_page), GTK_SPIN_STEP_BACKWARD, 1);
 }
 
 static void pdf_viewer_button_next_page_cb(GtkButton *button, PdfViewer *viewer) 
 {
-       
+
        gtk_spin_button_spin(GTK_SPIN_BUTTON(viewer->cur_page), GTK_SPIN_STEP_FORWARD, 1);
 }
 
 static void pdf_viewer_button_last_page_cb(GtkButton *button, PdfViewer *viewer) 
 {
-       
+
        gtk_spin_button_spin(GTK_SPIN_BUTTON(viewer->cur_page), GTK_SPIN_END, 1);
 }
 
@@ -809,17 +810,18 @@ static void pdf_viewer_button_zoom_out_cb(GtkButton *button, PdfViewer *viewer)
 {
 
        gtk_spin_button_spin(GTK_SPIN_BUTTON(viewer->zoom_scroll), GTK_SPIN_STEP_BACKWARD, ZOOM_FACTOR);
-       
+
 }
 
 static void pdf_viewer_button_press_events_cb(GtkWidget *widget, GdkEventButton *event, PdfViewer *viewer) 
 {
        gchar *uri;
+       GdkWindow *gdkwin;
        #ifdef HAVE_POPPLER_DEST_NAMED
        PopplerDest *dest;
        #endif
        static GdkCursor *hand_cur = NULL;
-       
+
        if (!hand_cur) hand_cur = gdk_cursor_new(GDK_FLEUR);
 
        /* Execute Poppler Links */
@@ -839,7 +841,7 @@ static void pdf_viewer_button_press_events_cb(GtkWidget *widget, GdkEventButton
                                dest = poppler_document_find_dest(
                                        viewer->pdf_doc, viewer->link_action->goto_dest.dest->named_dest);
                        if (dest->type != POPPLER_DEST_XYZ) {
-                               g_warning("couldn't figure out link\n");
+                               g_warning("couldn't figure out link");
                                poppler_dest_free(dest);
                                break;
                        }
@@ -854,7 +856,7 @@ static void pdf_viewer_button_press_events_cb(GtkWidget *widget, GdkEventButton
                        dest = poppler_document_find_dest(
                                        viewer->pdf_doc, viewer->link_action->goto_remote.dest->named_dest);
                        if (dest->type != POPPLER_DEST_XYZ) {
-                               g_warning ("couldn't figure out link\n");
+                               g_warning ("couldn't figure out link");
                                poppler_dest_free(dest);
                                break;
                        }
@@ -877,17 +879,33 @@ static void pdf_viewer_button_press_events_cb(GtkWidget *widget, GdkEventButton
                case POPPLER_ACTION_NAMED:
                        debug_print("action named not yet implemented\n");
                        break;
+               case POPPLER_ACTION_NONE:
+                       debug_print("action none does nothing, surprise!\n");
+                       break;
                case POPPLER_ACTION_MOVIE:
                        debug_print("yoyoyo ;-) a movie?\n");
                        break;
+#if POPPLER_CHECK_VERSION(0,14,0)
+               case POPPLER_ACTION_RENDITION:
+                       debug_print("yoyoyo ;-) multimedia?\n");
+                       break;
+               case POPPLER_ACTION_OCG_STATE:
+                       debug_print("yoyoyo ;-) layer state?\n");
+                       break;
+#if POPPLER_CHECK_VERSION(0,18,0)
+               case POPPLER_ACTION_JAVASCRIPT:
+                       debug_print("yoyoyo ;-) javascript?\n");
+                       break;
+#endif /* 0.18 */
+#endif /* 0.14 */
                }
                if (((MimeViewer *)viewer)->mimeview && 
                        ((MimeViewer *)viewer)->mimeview->messageview && 
                        ((MimeViewer *)viewer)->mimeview->messageview->window && 
-                       ((MimeViewer *)viewer)->mimeview->messageview->window->window) 
-                       gdk_window_set_cursor (((MimeViewer *)viewer)->mimeview->messageview->window->window, NULL);
+                       (gdkwin = gtk_widget_get_window(((MimeViewer *)viewer)->mimeview->messageview->window)) != NULL)
+                       gdk_window_set_cursor (gdkwin, NULL);
                else
-                       gdk_window_set_cursor (mainwindow_get_mainwindow()->window->window, NULL);
+                       gdk_window_set_cursor (gtk_widget_get_window(mainwindow_get_mainwindow()->window), NULL);
        }
 
        /* Init document to be scrolled with left mouse click */
@@ -896,10 +914,10 @@ static void pdf_viewer_button_press_events_cb(GtkWidget *widget, GdkEventButton
                if (((MimeViewer *)viewer)->mimeview && 
                        ((MimeViewer *)viewer)->mimeview->messageview && 
                        ((MimeViewer *)viewer)->mimeview->messageview->window && 
-                       ((MimeViewer *)viewer)->mimeview->messageview->window->window) 
-                       gdk_window_set_cursor (((MimeViewer *)viewer)->mimeview->messageview->window->window, hand_cur);
+                       (gdkwin = gtk_widget_get_window(((MimeViewer *)viewer)->mimeview->messageview->window)) != NULL)
+                       gdk_window_set_cursor (gdkwin, hand_cur);
                else
-                       gdk_window_set_cursor (mainwindow_get_mainwindow()->window->window, hand_cur);
+                       gdk_window_set_cursor (gtk_widget_get_window(mainwindow_get_mainwindow()->window), hand_cur);
 
                viewer->last_x = event->x;
                viewer->last_y = event->y;
@@ -910,40 +928,49 @@ static void pdf_viewer_button_press_events_cb(GtkWidget *widget, GdkEventButton
 /* Set the normal cursor*/
 static void pdf_viewer_mouse_scroll_destroy_cb(GtkWidget *widget, GdkEventButton *event, PdfViewer *viewer) 
 {
-       
+       GdkWindow *gdkwin;
+
        if (event->button == 1) {
                viewer->pdf_view_scroll = FALSE;
                if (((MimeViewer *)viewer)->mimeview && 
                        ((MimeViewer *)viewer)->mimeview->messageview && 
                        ((MimeViewer *)viewer)->mimeview->messageview->window && 
-                       ((MimeViewer *)viewer)->mimeview->messageview->window->window) 
-                       gdk_window_set_cursor (((MimeViewer *)viewer)->mimeview->messageview->window->window, NULL);
+                       (gdkwin = gtk_widget_get_window(((MimeViewer *)viewer)->mimeview->messageview->window)) != NULL)
+                       gdk_window_set_cursor (gdkwin, NULL);
                else
-                       gdk_window_set_cursor (mainwindow_get_mainwindow()->window->window, NULL);
+                       gdk_window_set_cursor (gtk_widget_get_window(mainwindow_get_mainwindow()->window), NULL);
        }
 }
 
 static void pdf_viewer_move_events_cb(GtkWidget *widget, GdkEventMotion *event, PdfViewer *viewer) 
 {
+       GdkWindow *gdkwin;
+
        /* Grab the document and scroll it with mouse */ 
        if (viewer->pdf_view_scroll) {
 
                viewer->pdf_view_vadj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(viewer->scrollwin));
                viewer->pdf_view_hadj = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(viewer->scrollwin));
-                       
+
                        if (event->x < viewer->last_x
-                                       && viewer->pdf_view_hadj->value < (viewer->pdf_view_hadj->upper - viewer->pdf_view_hadj->page_size)) {
+                                       && gtk_adjustment_get_value(viewer->pdf_view_hadj) < (gtk_adjustment_get_upper(viewer->pdf_view_hadj) - gtk_adjustment_get_page_size(viewer->pdf_view_hadj))) {
                                if (viewer->last_dir_x == -1) {
-                                       viewer->pdf_view_hadj->value += viewer->last_x - event->x; 
+                                       gtk_adjustment_set_value(viewer->pdf_view_hadj,
+                                                       gtk_adjustment_get_value(viewer->pdf_view_hadj)
+                                                       + viewer->last_x
+                                                       - event->x);
                                        g_signal_emit_by_name(G_OBJECT(viewer->pdf_view_hadj),
                                                                "value_changed", 0);
                                }
                                viewer->last_dir_x = -1;
                        }
                        else if (event->x > viewer->last_x
-                                       && viewer->pdf_view_hadj->value > 0.0)  {
+                                       && gtk_adjustment_get_value(viewer->pdf_view_hadj) > 0.0)  {
                                if (viewer->last_dir_x == +1) {
-                                       viewer->pdf_view_hadj->value += viewer->last_x - event->x; 
+                                       gtk_adjustment_set_value(viewer->pdf_view_hadj,
+                                                       gtk_adjustment_get_value(viewer->pdf_view_hadj)
+                                                       + viewer->last_x
+                                                       - event->x);
                                        g_signal_emit_by_name(G_OBJECT(viewer->pdf_view_hadj),
                                                                "value_changed", 0);
                                }
@@ -951,18 +978,24 @@ static void pdf_viewer_move_events_cb(GtkWidget *widget, GdkEventMotion *event,
                        }
 
                        if (event->y < viewer->last_y
-                                       && viewer->pdf_view_vadj->value < (viewer->pdf_view_vadj->upper - viewer->pdf_view_vadj->page_size)) {
+                                       && gtk_adjustment_get_value(viewer->pdf_view_vadj) < (gtk_adjustment_get_upper(viewer->pdf_view_vadj) - gtk_adjustment_get_page_size(viewer->pdf_view_vadj))) {
                                if (viewer->last_dir_y == -1) {
-                                       viewer->pdf_view_vadj->value += viewer->last_y - event->y; 
+                                       gtk_adjustment_set_value(viewer->pdf_view_vadj,
+                                                       gtk_adjustment_get_value(viewer->pdf_view_vadj)
+                                                       + viewer->last_y
+                                                       - event->y);
                                        g_signal_emit_by_name(G_OBJECT(viewer->pdf_view_vadj),
                                                                "value_changed", 0);
                                }
                                viewer->last_dir_y = -1;
                        }
                        else if (event->y > viewer->last_y
-                                       && viewer->pdf_view_vadj->value > 0.0)  {
+                                       && gtk_adjustment_get_value(viewer->pdf_view_vadj) > 0.0)  {
                                if (viewer->last_dir_y == +1) {
-                                       viewer->pdf_view_vadj->value += viewer->last_y - event->y; 
+                                       gtk_adjustment_set_value(viewer->pdf_view_vadj,
+                                                       gtk_adjustment_get_value(viewer->pdf_view_vadj)
+                                                       + viewer->last_y
+                                                       - event->y);
                                        g_signal_emit_by_name(G_OBJECT(viewer->pdf_view_vadj),
                                                                "value_changed", 0);
                                }
@@ -979,15 +1012,16 @@ static void pdf_viewer_move_events_cb(GtkWidget *widget, GdkEventMotion *event,
        static GtkRequisition size;
        static gdouble x,y, x1, y1, x2, y2;
        gboolean ccur;
-       
+
        viewer->pdf_view_vadj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(viewer->scrollwin));
        viewer->pdf_view_hadj = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(viewer->scrollwin));
-       
+
        if (!link_cur) link_cur = gdk_cursor_new(GDK_HAND2);
 
        ccur = FALSE;
        viewer->in_link = FALSE;        
        for (l = viewer->link_map; l; l = g_list_next (l)) {
+               gint upper;
                PopplerLinkMapping *lmapping;
                lmapping = (PopplerLinkMapping *)l->data;
 
@@ -996,40 +1030,41 @@ static void pdf_viewer_move_events_cb(GtkWidget *widget, GdkEventMotion *event,
                x2 = lmapping->area.x2;
                y2 = lmapping->area.y2;
                gtk_widget_size_request(viewer->pdf_view, &size);
-               
+
+               upper = gtk_adjustment_get_upper(viewer->pdf_view_hadj);
                switch (viewer->rotate) {
                case 0:
                case 360:
-                               if (size.width != viewer->pdf_view_hadj->upper)
-                                       x = (event->x - (viewer->pdf_view_hadj->upper - size.width) / 2) / viewer->zoom;
+                               if (size.width != upper)
+                                       x = (event->x - (upper - size.width) / 2) / viewer->zoom;
                                else
                                        x = event->x / viewer->zoom;
 
-                               y = (viewer->pdf_view_vadj->upper - event->y) / viewer->zoom;
+                               y = (upper - event->y) / viewer->zoom;
                        break;
                case 90:
-                               if (size.width != viewer->pdf_view_hadj->upper)
-                                       y = (event->x - (viewer->pdf_view_hadj->upper - size.width) / 2) / viewer->zoom;
+                               if (size.width != upper)
+                                       y = (event->x - (upper - size.width) / 2) / viewer->zoom;
                                else
                                        y = event->x / viewer->zoom;
 
                                x = (event->y) / viewer->zoom;
                        break;
                case 180:
-                               if (size.width != viewer->pdf_view_hadj->upper)
-                                       x = ((viewer->pdf_view_hadj->upper -  event->x) - ((viewer->pdf_view_hadj->upper - size.width) / 2)) / viewer->zoom;
+                               if (size.width != upper)
+                                       x = ((upper -  event->x) - ((upper - size.width) / 2)) / viewer->zoom;
                                else
-                                       x =  ((viewer->pdf_view_hadj->upper -  event->x) - (viewer->pdf_view_hadj->upper - size.width)) / viewer->zoom;
+                                       x =  ((upper -  event->x) - (upper - size.width)) / viewer->zoom;
 
                                y = (event->y) / viewer->zoom;
                        break;
                case 270:
-                               if (size.width != viewer->pdf_view_hadj->upper)
-                                       y = ((viewer->pdf_view_hadj->upper -  event->x) - ((viewer->pdf_view_hadj->upper - size.width) / 2)) / viewer->zoom;
+                               if (size.width != upper)
+                                       y = ((upper -  event->x) - ((upper - size.width) / 2)) / viewer->zoom;
                                else
-                                       y =  ((viewer->pdf_view_hadj->upper -  event->x) - (viewer->pdf_view_hadj->upper - size.width)) / viewer->zoom;
+                                       y =  ((upper -  event->x) - (upper - size.width)) / viewer->zoom;
 
-                               x = (viewer->pdf_view_vadj->upper - event->y) / viewer->zoom;
+                               x = (upper - event->y) / viewer->zoom;
                        break;
                }
 
@@ -1038,11 +1073,11 @@ static void pdf_viewer_move_events_cb(GtkWidget *widget, GdkEventMotion *event,
                        if (((MimeViewer *)viewer)->mimeview && 
                                ((MimeViewer *)viewer)->mimeview->messageview && 
                                ((MimeViewer *)viewer)->mimeview->messageview->window && 
-                               ((MimeViewer *)viewer)->mimeview->messageview->window->window) 
-                                       gdk_window_set_cursor (((MimeViewer *)viewer)->mimeview->messageview->window->window, link_cur);
+                               (gdkwin = gtk_widget_get_window(((MimeViewer *)viewer)->mimeview->messageview->window)) != NULL)
+                                       gdk_window_set_cursor (gdkwin, link_cur);
                                else
-                                       gdk_window_set_cursor (mainwindow_get_mainwindow()->window->window, link_cur);
-                               
+                                       gdk_window_set_cursor (gtk_widget_get_window(mainwindow_get_mainwindow()->window), link_cur);
+
                                viewer->link_action = lmapping->action; 
                                ccur = TRUE;
                }
@@ -1050,10 +1085,10 @@ static void pdf_viewer_move_events_cb(GtkWidget *widget, GdkEventMotion *event,
                        if (((MimeViewer *)viewer)->mimeview && 
                                ((MimeViewer *)viewer)->mimeview->messageview && 
                                ((MimeViewer *)viewer)->mimeview->messageview->window && 
-                               ((MimeViewer *)viewer)->mimeview->messageview->window->window) 
-                               gdk_window_set_cursor (((MimeViewer *)viewer)->mimeview->messageview->window->window, NULL);
+                               (gdkwin = gtk_widget_get_window(((MimeViewer *)viewer)->mimeview->messageview->window)) != NULL)
+                               gdk_window_set_cursor (gdkwin, NULL);
                        else
-                               gdk_window_set_cursor (mainwindow_get_mainwindow()->window->window, NULL);
+                               gdk_window_set_cursor (gtk_widget_get_window(mainwindow_get_mainwindow()->window), NULL);
                }
        }
        g_free(l);
@@ -1072,17 +1107,28 @@ static gboolean pdf_viewer_scroll_cb(GtkWidget *widget, GdkEventScroll *event,
 
        in_scroll_cb = TRUE;
 
+       if ((event->state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK) {
+               if (event->direction == GDK_SCROLL_UP) {
+                       pdf_viewer_button_zoom_in_cb(NULL, viewer);
+               } else {
+                       pdf_viewer_button_zoom_out_cb(NULL, viewer);
+               }
+               in_scroll_cb = FALSE;
+               return TRUE;
+       }
+
        if (event->direction == GDK_SCROLL_UP &&
-           adj->value == adj->lower && 
+           gtk_adjustment_get_value(adj) == gtk_adjustment_get_lower(adj) &&
            cur_p > 1) {
                gtk_spin_button_spin(GTK_SPIN_BUTTON(viewer->cur_page), GTK_SPIN_STEP_BACKWARD, 1);
-               adj->value = adj->upper - adj->page_size;
+               gtk_adjustment_set_value(adj,
+                               gtk_adjustment_get_upper(adj) - gtk_adjustment_get_page_size(adj));
                handled = TRUE;
        } else if (event->direction == GDK_SCROLL_DOWN &&
-           adj->value + adj->page_size == adj->upper &&
+           gtk_adjustment_get_value(adj) + gtk_adjustment_get_page_size(adj) == gtk_adjustment_get_upper(adj) &&
            cur_p < viewer->num_pages) {
                gtk_spin_button_spin(GTK_SPIN_BUTTON(viewer->cur_page), GTK_SPIN_STEP_FORWARD, 1);
-               adj->value = 0.0;
+               gtk_adjustment_set_value(adj, 0.0);
                handled = TRUE;
        }
        in_scroll_cb = FALSE;
@@ -1091,13 +1137,13 @@ static gboolean pdf_viewer_scroll_cb(GtkWidget *widget, GdkEventScroll *event,
 
 static void pdf_viewer_button_zoom_fit_cb(GtkButton *button, PdfViewer *viewer)
 {
-       GtkAllocation *allocation;
+       GtkAllocation allocation;
        double xratio, yratio;
-       allocation = &(viewer->scrollwin->allocation);
-       debug_print("width: %d\n", allocation->width);
-       debug_print("height: %d\n", allocation->height);
-       xratio = allocation->width / viewer->width;
-       yratio = allocation->height / viewer->height;
+       gtk_widget_get_allocation(viewer->scrollwin, &allocation);
+       debug_print("width: %d\n", allocation.width);
+       debug_print("height: %d\n", allocation.height);
+       xratio = allocation.width / viewer->width;
+       yratio = allocation.height / viewer->height;
 
        if (xratio >= yratio) {
                viewer->zoom = yratio;
@@ -1111,11 +1157,11 @@ static void pdf_viewer_button_zoom_fit_cb(GtkButton *button, PdfViewer *viewer)
 
 static void pdf_viewer_button_zoom_width_cb(GtkButton *button, PdfViewer *viewer)
 {
-       GtkAllocation *allocation;
+       GtkAllocation allocation;
        double xratio;
-       allocation = &(viewer->scrollwin->allocation);
-       debug_print("width: %d\n", allocation->width);
-       xratio = allocation->width / viewer->width;
+       gtk_widget_get_allocation(viewer->scrollwin, &allocation);
+       debug_print("width: %d\n", allocation.width);
+       xratio = allocation.width / viewer->width;
        gtk_spin_button_set_value(GTK_SPIN_BUTTON(viewer->zoom_scroll), xratio);
 }
 
@@ -1124,7 +1170,7 @@ static void pdf_viewer_button_rotate_right_cb(GtkButton *button, PdfViewer *view
        if (viewer->rotate == 360) {
                viewer->rotate = 0;
        }
-       
+
        viewer->rotate += (gint) ROTATION;
        pdf_viewer_update((MimeViewer *)viewer, FALSE,
                gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(viewer->cur_page)));
@@ -1135,21 +1181,21 @@ static void pdf_viewer_button_rotate_left_cb(GtkButton *button, PdfViewer *viewe
        if (viewer->rotate == 0) {
                viewer->rotate = 360;
        }
-       
+
        viewer->rotate = abs(viewer->rotate -(gint) ROTATION);
        pdf_viewer_update((MimeViewer *)viewer, FALSE,
                gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(viewer->cur_page)));
 }
 
 /* Show/Hide the index pane */
-static void pdf_viewer_show_document_index_cb(GtkButton *button, PdfViewer *viewer)
+static void pdf_viewer_show_document_index_cb(GtkToggleButton *button, PdfViewer *viewer)
 {
        if (!viewer->pdf_index) {
                viewer->pdf_index = poppler_index_iter_new(viewer->pdf_doc);
        }
-       
+
        gtk_tree_store_clear(GTK_TREE_STORE(viewer->index_model));
-       
+
        if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(viewer->doc_index))) {
                pdf_viewer_get_document_index(viewer,(PopplerIndexIter *) viewer->pdf_index, NULL);
                gtk_widget_show(GTK_WIDGET(viewer->frame_index));
@@ -1157,14 +1203,21 @@ static void pdf_viewer_show_document_index_cb(GtkButton *button, PdfViewer *view
        else {
                pdf_viewer_hide_index_pane(viewer);
        }
-               
+
+}
+
+static void pdf_viewer_button_print_cb(GtkButton *button, PdfViewer *viewer)
+{
+       MainWindow *mainwin = mainwindow_get_mainwindow();
+       summary_print(mainwin->summaryview);
 }
 
 static void pdf_viewer_button_document_info_cb(GtkButton *button, PdfViewer *viewer)
 {
        alertpanel_full(_("PDF properties"), NULL, GTK_STOCK_CLOSE, NULL, NULL,
-                       FALSE, (GtkWidget *) pdf_viewer_fill_info_table(viewer), 
-                       ALERT_NOTICE, G_ALERTDEFAULT);
+                       ALERTFOCUS_FIRST, FALSE,
+                       GTK_WIDGET(pdf_viewer_fill_info_table(viewer)), 
+                       ALERT_NOTICE);
 }
 
 /*
@@ -1200,6 +1253,7 @@ static void pdf_viewer_show_controls(PdfViewer *viewer, gboolean show)
                gtk_widget_show(viewer->widgets_table);
                gtk_widget_show(viewer->rotate_right);
                gtk_widget_show(viewer->rotate_left);
+               gtk_widget_show(viewer->print);
                gtk_widget_show(viewer->doc_info);
                gtk_widget_show(viewer->doc_index);
        } else {
@@ -1212,12 +1266,13 @@ static void pdf_viewer_show_controls(PdfViewer *viewer, gboolean show)
                gtk_widget_hide(viewer->zoom_out);
                gtk_widget_hide(viewer->zoom_fit);
                gtk_widget_hide(viewer->zoom_width);
+               gtk_widget_hide(viewer->zoom_scroll);
                gtk_widget_hide(viewer->widgets_table);
                gtk_widget_hide(viewer->rotate_right);
                gtk_widget_hide(viewer->rotate_left);
+               gtk_widget_hide(viewer->print);
                gtk_widget_hide(viewer->doc_info);
                gtk_widget_hide(viewer->doc_index);
-               gtk_widget_hide(viewer->zoom_scroll);
        }
 }
 /** Render the current page, page_num on the viewer */
@@ -1225,36 +1280,33 @@ static void pdf_viewer_update(MimeViewer *_viewer, gboolean reload_file, int pag
 {
 
        PdfViewer *viewer = (PdfViewer *) _viewer;
-       GError *error;
+       GError *error = NULL;
        gchar *tmpfile = NULL;
        gchar *tmp;
+       gchar *password = NULL;
 
        debug_print("pdf_viewer_update\n");
 
-       error = NULL;
        if (reload_file) {
                if (viewer->pdf_doc) {
                        g_object_unref(G_OBJECT(viewer->pdf_doc));
                        viewer->pdf_doc = NULL;
                }
-               
+
                if (pdf_viewer_mimepart_get_type(viewer->to_load) == TYPE_PS) {
-                       stock_pixbuf_gdk(viewer->hbox, 
-                                       STOCK_PIXMAP_MIME_PS, 
+                       stock_pixbuf_gdk(STOCK_PIXMAP_MIME_PS, 
                                        &viewer->icon_pixbuf);
                        gtk_image_set_from_pixbuf(GTK_IMAGE(viewer->icon_type),
                                                                        viewer->icon_pixbuf);
                } 
                else if (pdf_viewer_mimepart_get_type(viewer->to_load) == TYPE_PDF) {
-                       stock_pixbuf_gdk(viewer->hbox, 
-                       STOCK_PIXMAP_MIME_PDF, 
+                       stock_pixbuf_gdk(STOCK_PIXMAP_MIME_PDF, 
                        &viewer->icon_pixbuf);
                        gtk_image_set_from_pixbuf(GTK_IMAGE(viewer->icon_type), 
                                                                        viewer->icon_pixbuf);
                } 
                else {
-                       stock_pixbuf_gdk(viewer->hbox, 
-                       STOCK_PIXMAP_MIME_APPLICATION, 
+                       stock_pixbuf_gdk(STOCK_PIXMAP_MIME_APPLICATION, 
                        &viewer->icon_pixbuf);
                        gtk_image_set_from_pixbuf(GTK_IMAGE(viewer->icon_type), 
                                                                        viewer->icon_pixbuf);
@@ -1278,28 +1330,28 @@ static void pdf_viewer_update(MimeViewer *_viewer, gboolean reload_file, int pag
                                        "gs -dSAFER -dCompatibilityLevel=1.2 -q -dNOPAUSE -dBATCH "
                                          "-sDEVICE=pdfwrite -sOutputFile=%s -c .setpdfwrite -f \"%s\"",
                                        tmpfile, viewer->filename);
-                               result = execute_command_line(cmdline, FALSE);
+                               result = execute_command_line(cmdline, FALSE, NULL);
                                if (result == 0) {
                                        tmp = g_filename_to_uri(tmpfile, NULL, NULL);
                                        viewer->pdf_doc = poppler_document_new_from_file( tmp, NULL, &error);
                                        g_free(tmp);
                                } 
                                else {
-                                       g_warning("gs conversion failed: %s returned %d\n", cmdline, result);
+                                       g_warning("gs conversion failed: %s returned %d", cmdline, result);
                                        tmp = g_strdup_printf("gs: err %d", result);
                                        alertpanel_warning("%s", tmp);
                                        g_free(tmp);
                                }
-       
+
                                g_free(cmdline);
                                claws_unlink(tmpfile);
                                g_free(tmpfile);
                        }
                        else {
-                               g_warning("gs conversion disabled: gs binary was not found\n");
+                               g_warning("gs conversion disabled: gs binary was not found");
                                alertpanel_warning("PostScript view disabled: required gs program not found");
                                result = 1;
-                                       
+
                        }
                        if (result != 0) {
                                main_window_cursor_normal(mainwindow_get_mainwindow());
@@ -1309,7 +1361,15 @@ static void pdf_viewer_update(MimeViewer *_viewer, gboolean reload_file, int pag
                else {
                        viewer->pdf_doc = poppler_document_new_from_file( viewer->fsname, NULL, &error);
                }
-               
+               if (error && g_error_matches(error, POPPLER_ERROR, POPPLER_ERROR_ENCRYPTED)) {
+                       g_clear_error(&error);
+                       password = input_dialog_with_invisible(_("Enter password"),
+                                       _("This document is locked and requires a password before it can be opened."),
+                                       "");
+                       viewer->pdf_doc = poppler_document_new_from_file(viewer->fsname, password, &error);
+                       g_free(password);
+               }
+
                viewer->num_pages = poppler_document_get_n_pages(viewer->pdf_doc);
 
                g_signal_handlers_block_by_func(G_OBJECT(viewer->cur_page), pdf_viewer_spin_change_page_cb,(gpointer *)viewer);
@@ -1333,14 +1393,16 @@ static void pdf_viewer_update(MimeViewer *_viewer, gboolean reload_file, int pag
                main_window_cursor_normal(mainwindow_get_mainwindow());
        } 
        if (viewer->pdf_doc == NULL) {
-               strretchomp(error->message);
-               stock_pixbuf_gdk(viewer->hbox, 
-                               STOCK_PIXMAP_MIME_APPLICATION, 
+               stock_pixbuf_gdk(STOCK_PIXMAP_MIME_APPLICATION, 
                                &viewer->icon_pixbuf);
 
                gtk_image_set_from_pixbuf(GTK_IMAGE(viewer->icon_type), viewer->icon_pixbuf);
-               alertpanel_error("%s", error->message);
-       
+               if (error) {
+                       strretchomp(error->message);
+                       alertpanel_error("%s", error->message);
+               } else {
+                       alertpanel_error(_("PDF rendering failed for an unknown reason."));
+               }
                pdf_viewer_show_controls(viewer, FALSE);
                g_error_free(error);
                return;
@@ -1366,22 +1428,22 @@ static void pdf_viewer_update(MimeViewer *_viewer, gboolean reload_file, int pag
 
        /* check for the index if exists */
        pdf_viewer_set_index_button_sensitive((PdfViewer *) viewer);
-       
+
        if (page_num > 0 && page_num <= viewer->num_pages) {
 
                GTK_EVENTS_FLUSH();
-               
+
                if (viewer->pdf_page) {
                        g_object_unref(G_OBJECT(viewer->pdf_page));
                }
-                       
+
                viewer->pdf_page = poppler_document_get_page(viewer->pdf_doc, page_num - 1);
 
                if (viewer->pdf_page == NULL) {
-                       g_warning("Page not found\n");
+                       g_warning("Page not found");
                        return;
                }   
-       
+
                if (viewer->rotate == 90 || viewer->rotate == 270) {
                        poppler_page_get_size(viewer->pdf_page, &viewer->height, &viewer->width);
                } 
@@ -1398,13 +1460,13 @@ static void pdf_viewer_update(MimeViewer *_viewer, gboolean reload_file, int pag
                                                                        viewer->height, viewer->zoom, viewer->rotate);
 
                }
-       
+
        /* Get Links Mapping */
        if (viewer->link_map) {
                poppler_page_free_link_mapping(viewer->link_map);
        }
        viewer->link_map = poppler_page_get_link_mapping(viewer->pdf_page);
-       
+
        }
 }
 
@@ -1422,8 +1484,10 @@ static void pdf_viewer_show_mimepart(MimeViewer *_viewer, const gchar *infile,
        viewer->rotate = 0;
        viewer->to_load = partinfo;
 
+       if (messageview)
+               messageview->updating = TRUE;
+
        memset(buf, 0, sizeof(buf));
-       messageview->updating = TRUE;
        debug_print("pdf_viewer_show_mimepart\n");
 
        if (viewer->filename != NULL) {
@@ -1431,59 +1495,58 @@ static void pdf_viewer_show_mimepart(MimeViewer *_viewer, const gchar *infile,
                g_free(viewer->filename);
                viewer->filename = NULL;
        }
-       
+
        viewer->mimeinfo = NULL;
-       
+
        if (partinfo) {
                viewer->target_filename = procmime_get_part_file_name(partinfo);
                viewer->filename = procmime_get_tmp_file_name(partinfo);
                viewer->fsname = g_filename_to_uri(viewer->filename, NULL, NULL);
        }
-       
+
        if (partinfo && !(procmime_get_part(viewer->filename, partinfo) < 0)) {
 
-               if (_viewer && _viewer->mimeview && 
-                               _viewer->mimeview->messageview->forced_charset) {
+               if (messageview && messageview->forced_charset)
                        charset = _viewer->mimeview->messageview->forced_charset;
-               }
-               else {
+               else
                        charset = procmime_mimeinfo_get_parameter(partinfo, "charset");
-               }
+
                if (charset == NULL) {
                        charset = conv_get_locale_charset_str();
                }
 
                debug_print("using charset %s\n", charset);
-               
+
                viewer->mimeinfo = partinfo;
        }
-       
+
        pdf_viewer_update((MimeViewer *)viewer, TRUE, 1);
-       
-       messageview->updating = FALSE;
+
+       if (messageview)
+               messageview->updating = FALSE;
 }
 
 static void pdf_viewer_clear(MimeViewer *_viewer)
 {
        PdfViewer *viewer = (PdfViewer *) _viewer;
        GtkAdjustment *vadj;
-               
+
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(viewer->doc_index), FALSE);
        gtk_widget_hide(viewer->frame_index);
 
        debug_print("pdf_viewer_clear\n");
        viewer->to_load = NULL;
-       
+
        if (viewer->pdf_doc) {
                g_object_unref(G_OBJECT(viewer->pdf_doc));
                viewer->pdf_doc = NULL;
        }
-       
+
        vadj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(viewer->scrollwin));
-       vadj->value = 0.0;
+       gtk_adjustment_set_value(vadj, 0.0);
        g_signal_emit_by_name(G_OBJECT(vadj), "value-changed", 0);
        vadj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(viewer->scrollwin_index));
-       vadj->value = 0.0;
+       gtk_adjustment_set_value(vadj, 0.0);
        g_signal_emit_by_name(G_OBJECT(vadj), "value-changed", 0);
        gtk_tree_store_clear(GTK_TREE_STORE(viewer->index_model));
        gtk_image_set_from_pixbuf(GTK_IMAGE(viewer->pdf_view), NULL);
@@ -1494,7 +1557,7 @@ static void pdf_viewer_destroy(MimeViewer *_viewer)
        PdfViewer *viewer = (PdfViewer *) _viewer;
 
        debug_print("pdf_viewer_destroy\n");
-       
+
        if (viewer->pdf_index) poppler_index_iter_free(viewer->pdf_index);
 
        poppler_page_free_link_mapping (viewer->link_map);
@@ -1513,9 +1576,9 @@ static gboolean pdf_viewer_scroll_page(MimeViewer *_viewer, gboolean up)
        PdfViewer *viewer = (PdfViewer *)_viewer;
        GtkAdjustment *vadj = gtk_scrolled_window_get_vadjustment(
                                GTK_SCROLLED_WINDOW(viewer->scrollwin));
-       
+
        gint cur_p = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(viewer->cur_page));
-       
+
        if (viewer->pdf_view == NULL) return FALSE;
 
        if (!gtkutils_scroll_page(GTK_WIDGET(viewer->pdf_view), vadj, up)) {
@@ -1523,7 +1586,7 @@ static gboolean pdf_viewer_scroll_page(MimeViewer *_viewer, gboolean up)
                        gtk_spin_button_spin(GTK_SPIN_BUTTON(viewer->cur_page), GTK_SPIN_STEP_FORWARD, 1);
                        vadj = gtk_scrolled_window_get_vadjustment(
                                        GTK_SCROLLED_WINDOW(viewer->scrollwin));
-                       vadj->value = 0.0;
+                       gtk_adjustment_set_value(vadj, 0.0);
                        g_signal_emit_by_name(G_OBJECT(vadj), "value-changed", 0);
                        return TRUE;
                } 
@@ -1531,7 +1594,8 @@ static gboolean pdf_viewer_scroll_page(MimeViewer *_viewer, gboolean up)
                        gtk_spin_button_spin(GTK_SPIN_BUTTON(viewer->cur_page), GTK_SPIN_STEP_BACKWARD, 1);
                        vadj = gtk_scrolled_window_get_vadjustment(
                                        GTK_SCROLLED_WINDOW(viewer->scrollwin));
-                       vadj->value = vadj->upper - vadj->page_size;
+                       gtk_adjustment_set_value(vadj,
+                                       gtk_adjustment_get_upper(vadj) - gtk_adjustment_get_page_size(vadj));
                        g_signal_emit_by_name(G_OBJECT(vadj), "value-changed", 0);
                        return TRUE;
                } 
@@ -1550,7 +1614,7 @@ static void pdf_viewer_scroll_one_line(MimeViewer *_viewer, gboolean up)
 
        if (viewer->pdf_view == NULL) return; 
                debug_print("up: %d\n", up);    
-               if (vadj->value <(vadj->upper - vadj->page_size))  {
+               if (gtk_adjustment_get_value(vadj) < (gtk_adjustment_get_upper(vadj) - gtk_adjustment_get_page_size(vadj)))  {
                        gtkutils_scroll_one_line(GTK_WIDGET(viewer->pdf_view), vadj, up);
                }
                else {
@@ -1564,7 +1628,14 @@ static void pdf_viewer_scroll_one_line(MimeViewer *_viewer, gboolean up)
 #define BUTTON_H_PADDING 3
 #define ADD_BUTTON_TO_TABLE(widget, stock_image) \
        widget = gtk_button_new(); \
-       img = gtk_image_new_from_stock(stock_image, GTK_ICON_SIZE_MENU); \
+       img = stock_pixmap_widget(stock_image); \
+       gtk_button_set_image(GTK_BUTTON(widget), img); \
+       gtk_table_attach(GTK_TABLE(viewer->widgets_table), GTK_WIDGET(widget), \
+                               col, col+1, 0, 1, 0, 0, BUTTON_H_PADDING, 0); \
+       col++;
+#define ADD_TOGGLE_BUTTON_TO_TABLE(widget, stock_image) \
+       widget = gtk_toggle_button_new(); \
+       img = stock_pixmap_widget(stock_image); \
        gtk_button_set_image(GTK_BUTTON(widget), img); \
        gtk_table_attach(GTK_TABLE(viewer->widgets_table), GTK_WIDGET(widget), \
                                col, col+1, 0, 1, 0, 0, BUTTON_H_PADDING, 0); \
@@ -1577,7 +1648,7 @@ static void pdf_viewer_scroll_one_line(MimeViewer *_viewer, gboolean up)
        gtk_table_set_col_spacing(GTK_TABLE(viewer->widgets_table), col, 3*BUTTON_H_PADDING); \
        col++;
 
-#if GTK_CHECK_VERSION(2,10,0) && POPPLER_HAS_CAIRO && !USE_LIBGNOMEPRINT
+#if POPPLER_HAS_CAIRO
 static PangoContext *pdf_viewer_get_pango_context(gpointer data)
 {
        return NULL;
@@ -1622,7 +1693,7 @@ static void pdf_viewer_cb_draw_page(GtkPrintOperation *op, GtkPrintContext *cont
   cairo_scale(cr, printing_get_zoom(print_data), printing_get_zoom(print_data));
   cairo_set_source_rgb(cr, 0., 0., 0.);
 
-  poppler_page_render(pdf_page, cr);
+  poppler_page_render_for_printing(pdf_page, cr);
 
   g_object_unref(G_OBJECT(pdf_page));
 
@@ -1634,15 +1705,15 @@ static void pdf_viewer_print(MimeViewer *mviewer)
        PdfViewer *viewer = (PdfViewer *)mviewer;
        PrintRenderer *pdf_renderer = g_new0(PrintRenderer, 1);
        MainWindow *mainwin = mainwindow_get_mainwindow();
-       
+
        pdf_renderer->get_pango_context = pdf_viewer_get_pango_context;
        pdf_renderer->get_data_to_print = pdf_viewer_get_data_to_print;
        pdf_renderer->cb_begin_print    = pdf_viewer_cb_begin_print;
        pdf_renderer->cb_draw_page      = pdf_viewer_cb_draw_page;
 
-       printing_print_full(mainwin ? GTK_WINDOW(mainwin->window):NULL, 
-                       pdf_renderer, viewer->pdf_doc, -1, -1);
-       
+       printing_print_full(mainwin ? GTK_WINDOW(mainwin->window):NULL,
+                       pdf_renderer, viewer->pdf_doc, -1, -1, NULL);
+
        g_free(pdf_renderer);
 }
 #endif
@@ -1670,14 +1741,14 @@ static MimeViewer *pdf_viewer_create(void)
        viewer->mimeviewer.text_search = pdf_viewer_text_search;
        viewer->mimeviewer.scroll_page = pdf_viewer_scroll_page;
        viewer->mimeviewer.scroll_one_line = pdf_viewer_scroll_one_line;
-#if GTK_CHECK_VERSION(2,10,0) && POPPLER_HAS_CAIRO && !USE_LIBGNOMEPRINT
+#if POPPLER_HAS_CAIRO
        viewer->mimeviewer.print = pdf_viewer_print;
 #endif
        viewer->scrollwin = gtk_scrolled_window_new(NULL, NULL);
        viewer->scrollwin_index = gtk_scrolled_window_new(NULL, NULL);
        viewer->pdf_view_ebox = gtk_event_box_new();
        gtk_event_box_set_visible_window(GTK_EVENT_BOX(viewer->pdf_view_ebox), FALSE);
-                                                       
+
        viewer->mimeinfo  = NULL;
 
        viewer->pdf_view = gtk_image_new();
@@ -1704,13 +1775,9 @@ static MimeViewer *pdf_viewer_create(void)
        gtk_widget_set_size_request(viewer->frame_index, 18, -1);
        gtk_frame_set_label(GTK_FRAME(viewer->frame_index), _("Document Index"));
 
-#if !(GTK_CHECK_VERSION(2,12,0))
-       viewer->button_bar_tips = tips;
-#endif
-
        ADD_SEP_TO_TABLE
-       ADD_BUTTON_TO_TABLE(viewer->first_page, GTK_STOCK_GOTO_FIRST)
-       ADD_BUTTON_TO_TABLE(viewer->prev_page, GTK_STOCK_GO_BACK)
+       ADD_BUTTON_TO_TABLE(viewer->first_page, STOCK_PIXMAP_FIRST_ARROW)
+       ADD_BUTTON_TO_TABLE(viewer->prev_page, STOCK_PIXMAP_LEFT_ARROW)
        viewer->cur_page = gtk_spin_button_new_with_range(0.0, 0.0, 1.0);
        viewer->zoom_scroll = gtk_spin_button_new_with_range(0.20, 8.0, 0.20);
        gtk_spin_button_set_value(GTK_SPIN_BUTTON(viewer->zoom_scroll), 1.0);
@@ -1730,34 +1797,27 @@ static MimeViewer *pdf_viewer_create(void)
                                        0);
        col++;
 
-       ADD_BUTTON_TO_TABLE(viewer->next_page, GTK_STOCK_GO_FORWARD)
-       ADD_BUTTON_TO_TABLE(viewer->last_page, GTK_STOCK_GOTO_LAST)
+       ADD_BUTTON_TO_TABLE(viewer->next_page, STOCK_PIXMAP_RIGHT_ARROW)
+       ADD_BUTTON_TO_TABLE(viewer->last_page, STOCK_PIXMAP_LAST_ARROW)
        ADD_SEP_TO_TABLE
-       ADD_BUTTON_TO_TABLE(viewer->zoom_fit, GTK_STOCK_ZOOM_FIT)
-       ADD_BUTTON_TO_TABLE(viewer->zoom_in, GTK_STOCK_ZOOM_IN)
+       ADD_BUTTON_TO_TABLE(viewer->zoom_fit, STOCK_PIXMAP_ZOOM_FIT)
+       ADD_BUTTON_TO_TABLE(viewer->zoom_in, STOCK_PIXMAP_ZOOM_IN)
        gtk_table_attach(GTK_TABLE(viewer->widgets_table), GTK_WIDGET(viewer->zoom_scroll),
                                        col, col+1, 
                                        0, 1, 0, 0, 
                                        BUTTON_H_PADDING, 
                                        0);
        col++;
-       ADD_BUTTON_TO_TABLE(viewer->zoom_out, GTK_STOCK_ZOOM_OUT)
-       ADD_BUTTON_TO_TABLE(viewer->zoom_width, GTK_STOCK_FULLSCREEN)
+       ADD_BUTTON_TO_TABLE(viewer->zoom_out, STOCK_PIXMAP_ZOOM_OUT)
+       ADD_BUTTON_TO_TABLE(viewer->zoom_width, STOCK_PIXMAP_ZOOM_WIDTH)
        ADD_SEP_TO_TABLE
-       ADD_BUTTON_TO_TABLE(viewer->rotate_left, GTK_STOCK_UNDO)
-       ADD_BUTTON_TO_TABLE(viewer->rotate_right, GTK_STOCK_REDO)
+       ADD_BUTTON_TO_TABLE(viewer->rotate_left, STOCK_PIXMAP_ROTATE_LEFT)
+       ADD_BUTTON_TO_TABLE(viewer->rotate_right, STOCK_PIXMAP_ROTATE_RIGHT)
        ADD_SEP_TO_TABLE
-       ADD_BUTTON_TO_TABLE(viewer->doc_info, GTK_STOCK_INFO)
+       ADD_BUTTON_TO_TABLE(viewer->print, STOCK_PIXMAP_PRINTER)
+       ADD_BUTTON_TO_TABLE(viewer->doc_info, STOCK_PIXMAP_DOC_INFO)
+       ADD_TOGGLE_BUTTON_TO_TABLE(viewer->doc_index, STOCK_PIXMAP_DOC_INDEX)
 
-       viewer->doc_index = GTK_WIDGET(gtk_toggle_tool_button_new_from_stock(GTK_STOCK_INDEX));
-       gtk_widget_set_size_request(GTK_WIDGET(viewer->doc_index), 26, 26);
-       gtk_table_attach(GTK_TABLE(viewer->widgets_table), GTK_WIDGET(viewer->doc_index),
-                                       col, col+1, 
-                                       0, 1, 0, 0, 
-                                       BUTTON_H_PADDING, 
-                                       0);
-       col++;
-       
        gtk_scrolled_window_set_policy(
                        GTK_SCROLLED_WINDOW(viewer->scrollwin), 
                        GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
@@ -1780,11 +1840,13 @@ static MimeViewer *pdf_viewer_create(void)
                                        G_TYPE_DOUBLE);
 
        viewer->index_list = gtk_tree_view_new_with_model(GTK_TREE_MODEL(tree_store));
+       g_object_unref(tree_store);
+
        renderer = gtk_cell_renderer_text_new();
        column = gtk_tree_view_column_new_with_attributes(_("Name"),  renderer, "text", 0,  NULL);
        gtk_tree_view_append_column(GTK_TREE_VIEW(viewer->index_list), column);         
        gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(viewer->index_list), FALSE);
-       
+
        viewer->index_model = GTK_TREE_MODEL(tree_store);
 
        gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(viewer->index_list)), 
@@ -1808,8 +1870,7 @@ static MimeViewer *pdf_viewer_create(void)
 
        /* end treeview */
 
-       stock_pixbuf_gdk(viewer->hbox, 
-                       STOCK_PIXMAP_MIME_TEXT_PLAIN, 
+       stock_pixbuf_gdk(STOCK_PIXMAP_MIME_TEXT_PLAIN, 
                        &viewer->icon_pixbuf);
 
        gtk_image_set_from_pixbuf(GTK_IMAGE(viewer->icon_type), 
@@ -1873,6 +1934,8 @@ static MimeViewer *pdf_viewer_create(void)
        g_object_ref(GTK_WIDGET(viewer->rotate_right));
        gtk_widget_show(GTK_WIDGET(viewer->rotate_left));
        g_object_ref(GTK_WIDGET(viewer->rotate_left));
+       gtk_widget_show(GTK_WIDGET(viewer->print));
+       g_object_ref(GTK_WIDGET(viewer->print));
        gtk_widget_show(GTK_WIDGET(viewer->doc_info));
        g_object_ref(GTK_WIDGET(viewer->doc_info));
        gtk_widget_show(GTK_WIDGET(viewer->doc_index));
@@ -1899,7 +1962,7 @@ static MimeViewer *pdf_viewer_create(void)
 
        CLAWS_SET_TIP(viewer->next_page,
                                _("Next Page"));
-       
+
        CLAWS_SET_TIP(viewer->last_page,
                                _("Last Page"));
 
@@ -1920,6 +1983,9 @@ static MimeViewer *pdf_viewer_create(void)
        CLAWS_SET_TIP(viewer->rotate_right,
                                _("Rotate Right"));
 
+       CLAWS_SET_TIP(viewer->print,
+                               _("Print Document"));
+
        CLAWS_SET_TIP(viewer->doc_info,
                                _("Document Info"));
 
@@ -1978,17 +2044,22 @@ static MimeViewer *pdf_viewer_create(void)
                                    "clicked", 
                                    G_CALLBACK(pdf_viewer_button_rotate_right_cb), 
                                   (gpointer) viewer);
-       
+
        g_signal_connect(G_OBJECT(viewer->rotate_left), 
                                    "clicked", 
                                    G_CALLBACK(pdf_viewer_button_rotate_left_cb), 
                                   (gpointer) viewer);
-       
+
+       g_signal_connect(G_OBJECT(viewer->print), 
+                                   "clicked", 
+                                   G_CALLBACK(pdf_viewer_button_print_cb), 
+                                  (gpointer) viewer);
+
        g_signal_connect(G_OBJECT(viewer->doc_info), 
                                    "clicked", 
                                    G_CALLBACK(pdf_viewer_button_document_info_cb), 
                                   (gpointer) viewer);  
-       
+
        g_signal_connect(G_OBJECT(viewer->doc_index), 
                                    "clicked", 
                                    G_CALLBACK(pdf_viewer_show_document_index_cb), 
@@ -2018,10 +2089,11 @@ static MimeViewer *pdf_viewer_create(void)
 }
 
 #undef ADD_BUTTON_TO_TABLE
+#undef ADD_TOGGLE_BUTTON_TO_TABLE
 #undef ADD_SEP_TO_TABLE
 #undef BUTTON_H_PADDING
 #undef SEP_H_PADDING
-               
+
 static MimeViewerFactory pdf_viewer_factory =
 {
        content_types,
@@ -2053,7 +2125,7 @@ gint plugin_init(gchar **error)
        else {
                g_free(gspath);
        }
-       
+
        mimeview_register_viewer_factory(&pdf_viewer_factory);
        return 0;
 }