fix invalid cast runtime warning
[claws.git] / src / plugins / pdf_viewer / poppler_viewer.c
index 60f4a49..5df4661 100644 (file)
@@ -31,6 +31,7 @@
 #include "gtk/inputdialog.h"
 #include "mimeview.h"
 #include "summaryview.h"
+#include "file-utils.h"
 #ifndef POPPLER_WITH_GDK
 #include "stdbool.h"
 #endif
@@ -82,7 +83,7 @@ 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);
 
@@ -90,7 +91,7 @@ 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);
@@ -449,7 +450,7 @@ static gboolean     pdf_viewer_text_search(MimeViewer *_viewer, gboolean backward,
                        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;
@@ -1106,6 +1107,16 @@ 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 &&
            gtk_adjustment_get_value(adj) == gtk_adjustment_get_lower(adj) &&
            cur_p > 1) {
@@ -1177,7 +1188,7 @@ static void pdf_viewer_button_rotate_left_cb(GtkButton *button, PdfViewer *viewe
 }
 
 /* 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);
@@ -1204,8 +1215,9 @@ static void pdf_viewer_button_print_cb(GtkButton *button, PdfViewer *viewer)
 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);
 }
 
 /*
@@ -1621,6 +1633,13 @@ static void pdf_viewer_scroll_one_line(MimeViewer *_viewer, gboolean up)
        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); \
+       col++;
 
 #define ADD_SEP_TO_TABLE \
        sep = gtk_label_new(""); \
@@ -1797,7 +1816,7 @@ static MimeViewer *pdf_viewer_create(void)
        ADD_SEP_TO_TABLE
        ADD_BUTTON_TO_TABLE(viewer->print, STOCK_PIXMAP_PRINTER)
        ADD_BUTTON_TO_TABLE(viewer->doc_info, STOCK_PIXMAP_DOC_INFO)
-       ADD_BUTTON_TO_TABLE(viewer->doc_index, STOCK_PIXMAP_DOC_INDEX)
+       ADD_TOGGLE_BUTTON_TO_TABLE(viewer->doc_index, STOCK_PIXMAP_DOC_INDEX)
 
        gtk_scrolled_window_set_policy(
                        GTK_SCROLLED_WINDOW(viewer->scrollwin), 
@@ -1821,6 +1840,8 @@ 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);         
@@ -2068,6 +2089,7 @@ 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