GtkAction *action_prev;
GtkAction *action_next;
- GtkWidget *image;
- GdkPixbuf *pixbuf;
+ GtkWidget *drawing_area;
PopplerDocument *document;
+ PopplerPage *page;
gint page_no;
} RaktWindowPriv;
render_page (RaktWindow *window)
{
RaktWindowPriv *priv;
- PopplerPage *page;
double tmpw, tmph;
int width, height, n_pages;
gtk_action_set_sensitive (priv->action_prev, priv->page_no > 0);
gtk_action_set_sensitive (priv->action_next, priv->page_no < n_pages - 1);
- page = poppler_document_get_page (priv->document, priv->page_no);
-
- poppler_page_get_size (page, &tmpw, &tmph);
+ priv->page = poppler_document_get_page (priv->document, priv->page_no);
- width = (int) tmpw;
- height = (int) tmph;
+ poppler_page_get_size (priv->page, &tmpw, &tmph);
- priv->pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8,
- width, height);
+ width = (int) (tmpw + 0.5);
+ height = (int) (tmph + 0.5);
- poppler_page_render_to_pixbuf (page, 0, 0, width, height, 1.0, 0,
- priv->pixbuf);
- gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), priv->pixbuf);
- gtk_widget_show (priv->image);
+ gtk_widget_set_size_request (priv->drawing_area, width, height);
+ gtk_widget_queue_draw_area (priv->drawing_area, 0, 0, width, height);
}
static void
gtk_action_set_sensitive (priv->action_next, false);
}
+static gboolean
+on_expose_event (GtkWidget *widget, GdkEvent *event, gpointer user_data)
+{
+ RaktWindowPriv *priv;
+ cairo_t *cr;
+
+ priv = GET_PRIV (user_data);
+
+ cr = gdk_cairo_create (priv->drawing_area->window);
+
+ cairo_set_source_rgb (cr, 255, 255, 255);
+ cairo_paint (cr);
+
+ if (priv->page)
+ poppler_page_render (priv->page, cr);
+
+ cairo_destroy (cr);
+
+ return FALSE;
+}
+
static gboolean
on_delete_event (GtkWidget *widget, GdkEvent *event, gpointer user_data)
{
rakt_window_init (RaktWindow *window)
{
RaktWindowPriv *priv;
+ GtkWidget *scrolled;
priv = GET_PRIV (window);
window_create_menu (window);
- priv->image = gtk_image_new ();
+ priv->drawing_area = gtk_drawing_area_new ();
+ gtk_widget_show (priv->drawing_area);
+
+ g_signal_connect (priv->drawing_area, "expose-event",
+ G_CALLBACK (on_expose_event), window);
+
+ scrolled = gtk_scrolled_window_new (NULL, NULL);
+
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
+ GTK_POLICY_AUTOMATIC,
+ GTK_POLICY_AUTOMATIC);
+
+ gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled),
+ priv->drawing_area);
+ gtk_widget_show (scrolled);
- gtk_box_pack_start (GTK_BOX (priv->content_vbox), priv->image,
+ gtk_box_pack_start (GTK_BOX (priv->content_vbox), scrolled,
TRUE, TRUE, 0);
g_signal_connect (GTK_WINDOW (window), "delete-event",