Added zoom support.
authorSimone Rota <sip@varlock.com>
Thu, 16 Aug 2007 10:53:00 +0000 (12:53 +0200)
committerTilman Sauerbeck <tilman@code-monkey.de>
Thu, 16 Aug 2007 10:53:00 +0000 (12:53 +0200)
src/rakt-window.c

index 9f25fb882fa5900d2fa87498623aef26b1a8c05f..f83cb6e524b7a5b247928c2b0a5f1e56867df0e5 100644 (file)
@@ -38,10 +38,15 @@ typedef struct {
        GtkAction *action_prev;
        GtkAction *action_next;
 
        GtkAction *action_prev;
        GtkAction *action_next;
 
+       GtkAction *action_zoom_in;
+       GtkAction *action_zoom_out;
+       GtkAction *action_zoom_100;
+
        GtkWidget *drawing_area;
        PopplerDocument *document;
        PopplerPage *page;
        gint page_no;
        GtkWidget *drawing_area;
        PopplerDocument *document;
        PopplerPage *page;
        gint page_no;
+       gdouble scale;
 } RaktWindowPriv;
 
 static void window_finalize (GObject *object);
 } RaktWindowPriv;
 
 static void window_finalize (GObject *object);
@@ -52,6 +57,7 @@ static void on_action_quit (GtkAction *action, RaktWindow *window);
 static void on_action_open (GtkAction *action, RaktWindow *window);
 static void on_action_go_next (GtkAction *action, RaktWindow *window);
 static void on_action_go_previous (GtkAction *action, RaktWindow *window);
 static void on_action_open (GtkAction *action, RaktWindow *window);
 static void on_action_go_next (GtkAction *action, RaktWindow *window);
 static void on_action_go_previous (GtkAction *action, RaktWindow *window);
+static void on_action_zoom (GtkAction *action, RaktWindow *window);
 static void on_action_about (GtkAction *action, RaktWindow *window);
 
 static const GtkActionEntry action_entries[] = {
 static void on_action_about (GtkAction *action, RaktWindow *window);
 
 static const GtkActionEntry action_entries[] = {
@@ -61,6 +67,9 @@ static const GtkActionEntry action_entries[] = {
        {
                "GoMenu", NULL, "_Go", NULL, NULL, NULL
        },
        {
                "GoMenu", NULL, "_Go", NULL, NULL, NULL
        },
+       {
+               "ViewMenu", NULL, "_View", NULL, NULL, NULL
+       },
        {
                "HelpMenu", NULL, "_Help", NULL, NULL, NULL
        },
        {
                "HelpMenu", NULL, "_Help", NULL, NULL, NULL
        },
@@ -79,6 +88,21 @@ static const GtkActionEntry action_entries[] = {
                "<control>p", "Previous",
                G_CALLBACK (on_action_go_previous)
        },
                "<control>p", "Previous",
                G_CALLBACK (on_action_go_previous)
        },
+       {
+               "Zoom In", GTK_STOCK_ZOOM_IN, "Zoom _In",
+               "<control>plus", "Zoom In",
+               G_CALLBACK (on_action_zoom)
+       },
+       {
+               "Zoom Out", GTK_STOCK_ZOOM_OUT, "Zoom _Out",
+               "<control>minus", "Zoom Out",
+               G_CALLBACK (on_action_zoom)
+       },
+       {
+               "Zoom 100", GTK_STOCK_ZOOM_100, "Zoom 100%",
+               NULL, "Zoom 100%",
+               G_CALLBACK (on_action_zoom)
+       },
        {
                "Quit", GTK_STOCK_QUIT, "_Quit",
                "<control>Q", "Quit the application",
        {
                "Quit", GTK_STOCK_QUIT, "_Quit",
                "<control>Q", "Quit the application",
@@ -103,6 +127,11 @@ static const gchar *ui_layout =
        "                       <menuitem action='Previous'/>"
        "                       <menuitem action='Next'/>"
        "               </menu>"
        "                       <menuitem action='Previous'/>"
        "                       <menuitem action='Next'/>"
        "               </menu>"
+       "               <menu action='ViewMenu'>"
+       "                       <menuitem action='Zoom In'/>"
+       "                       <menuitem action='Zoom Out'/>"
+       "                       <menuitem action='Zoom 100'/>"
+       "               </menu>"
        "               <menu action='HelpMenu'>"
        "                       <menuitem action='About'/>"
        "               </menu>"
        "               <menu action='HelpMenu'>"
        "                       <menuitem action='About'/>"
        "               </menu>"
@@ -111,6 +140,9 @@ static const gchar *ui_layout =
        "               <toolitem action='Open'/>"
        "               <toolitem action='Previous'/>"
        "               <toolitem action='Next'/>"
        "               <toolitem action='Open'/>"
        "               <toolitem action='Previous'/>"
        "               <toolitem action='Next'/>"
+       "               <toolitem action='Zoom In'/>"
+       "               <toolitem action='Zoom Out'/>"
+       "               <toolitem action='Zoom 100'/>"
        "       </toolbar>"
        "</ui>";
 
        "       </toolbar>"
        "</ui>";
 
@@ -142,12 +174,16 @@ render_page (RaktWindow *window)
        gtk_action_set_sensitive (priv->action_prev, priv->page_no > 0);
        gtk_action_set_sensitive (priv->action_next, priv->page_no < n_pages - 1);
 
        gtk_action_set_sensitive (priv->action_prev, priv->page_no > 0);
        gtk_action_set_sensitive (priv->action_next, priv->page_no < n_pages - 1);
 
+       gtk_action_set_sensitive (priv->action_zoom_in, priv->scale < 3.0);
+       gtk_action_set_sensitive (priv->action_zoom_out, priv->scale > 0.4);
+       gtk_action_set_sensitive (priv->action_zoom_100, priv->scale != 1.0);
+
        priv->page = poppler_document_get_page (priv->document, priv->page_no);
 
        poppler_page_get_size (priv->page, &tmpw, &tmph);
 
        priv->page = poppler_document_get_page (priv->document, priv->page_no);
 
        poppler_page_get_size (priv->page, &tmpw, &tmph);
 
-       width = (int) (tmpw + 0.5);
-       height = (int) (tmph + 0.5);
+       width = (int) (tmpw * priv->scale + 0.5);
+       height = (int) (tmph * priv->scale + 0.5);
 
        gtk_widget_set_size_request (priv->drawing_area, width, height);
        gtk_widget_queue_draw_area (priv->drawing_area, 0, 0, width, height);
 
        gtk_widget_set_size_request (priv->drawing_area, width, height);
        gtk_widget_queue_draw_area (priv->drawing_area, 0, 0, width, height);
@@ -205,9 +241,19 @@ window_create_menu (RaktWindow *window)
                                                       "ui/ToolBar/Previous");
        priv->action_next = gtk_ui_manager_get_action (priv->ui_manager,
                                                       "ui/ToolBar/Next");
                                                       "ui/ToolBar/Previous");
        priv->action_next = gtk_ui_manager_get_action (priv->ui_manager,
                                                       "ui/ToolBar/Next");
+       priv->action_zoom_in = gtk_ui_manager_get_action (priv->ui_manager,
+                                                         "ui/ToolBar/Zoom In");
+       priv->action_zoom_out = gtk_ui_manager_get_action (priv->ui_manager,
+                                                          "ui/ToolBar/Zoom Out");
+       priv->action_zoom_100 = gtk_ui_manager_get_action (priv->ui_manager,
+                                                          "ui/ToolBar/Zoom 100");
 
        gtk_action_set_sensitive (priv->action_prev, false);
        gtk_action_set_sensitive (priv->action_next, false);
 
        gtk_action_set_sensitive (priv->action_prev, false);
        gtk_action_set_sensitive (priv->action_next, false);
+
+       gtk_action_set_sensitive (priv->action_zoom_in, false);
+       gtk_action_set_sensitive (priv->action_zoom_out, false);
+       gtk_action_set_sensitive (priv->action_zoom_100, false);
 }
 
 static gboolean
 }
 
 static gboolean
@@ -223,6 +269,8 @@ on_expose_event (GtkWidget *widget, GdkEvent *event, gpointer user_data)
        cairo_set_source_rgb (cr, 255, 255, 255);
        cairo_paint (cr);
 
        cairo_set_source_rgb (cr, 255, 255, 255);
        cairo_paint (cr);
 
+       cairo_scale (cr, priv->scale, priv->scale);
+
        if (priv->page)
                poppler_page_render (priv->page, cr);
 
        if (priv->page)
                poppler_page_render (priv->page, cr);
 
@@ -247,6 +295,8 @@ rakt_window_init (RaktWindow *window)
 
        priv = GET_PRIV (window);
 
 
        priv = GET_PRIV (window);
 
+       priv->scale = 1.0;
+
        gtk_window_set_default_size (GTK_WINDOW (window), 640, 480);
        gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
 
        gtk_window_set_default_size (GTK_WINDOW (window), 640, 480);
        gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
 
@@ -364,6 +414,23 @@ on_action_go_previous (GtkAction *action, RaktWindow *window)
        render_page (window);
 }
 
        render_page (window);
 }
 
+static void
+on_action_zoom (GtkAction *action, RaktWindow *window)
+{
+       RaktWindowPriv *priv;
+
+       priv = GET_PRIV (window);
+
+       if (action == priv->action_zoom_in)
+               priv->scale += 0.2;
+       else if (action == priv->action_zoom_out)
+               priv->scale -= 0.2;
+       else
+               priv->scale = 1.0;
+
+       render_page (window);
+}
+
 static void
 on_action_about (GtkAction *action, RaktWindow *window)
 {
 static void
 on_action_about (GtkAction *action, RaktWindow *window)
 {