Code

tpdfview: Use the tpdfv-ctl module to manage the GtkTPDFV widget.
authorSebastian Harl <sh@tokkee.org>
Fri, 30 Dec 2011 23:24:16 +0000 (00:24 +0100)
committerSebastian Harl <sh@tokkee.org>
Fri, 30 Dec 2011 23:24:16 +0000 (00:24 +0100)
This is in preparation for managing multiple widgets through that interface.

src/tpdfview.c

index e6fee214669f91edc7a8f68fa661d361229ef402..9ae1b792ff4ab6ece44103765d78282d61bf9d44 100644 (file)
@@ -37,6 +37,7 @@
 #include "tpdfv_features.h"
 
 #include "gtk-tpdfv.h"
+#include "tpdfv-ctl.h"
 
 #if HAVE_LIBGEN_H
 #      include <libgen.h>
@@ -119,10 +120,10 @@ on_destroy(GtkWidget __attribute__((unused)) *widget,
 static gboolean
 key_press(GtkWidget *window, GdkEventKey *event, gpointer data)
 {
-       GtkWidget *tpdfv;
+       GObject *obj;
 
-       tpdfv = (GtkWidget *)data;
-       assert(tpdfv);
+       obj = G_OBJECT(data);
+       assert(obj);
 
        switch (event->keyval) {
                case GDK_q:
@@ -130,7 +131,7 @@ key_press(GtkWidget *window, GdkEventKey *event, gpointer data)
                        break;
 
                case GDK_r:
-                       gtk_tpdfv_reload(tpdfv);
+                       tpdfv_ctl_reload(obj);
                        break;
 
                case GDK_F:
@@ -139,52 +140,52 @@ key_press(GtkWidget *window, GdkEventKey *event, gpointer data)
 
                /* navigation */
                case GDK_Page_Up:
-                       gtk_tpdfv_page_up(tpdfv);
+                       tpdfv_ctl_page_up(obj);
                        break;
                case GDK_Page_Down:
                        /* fall through */
                case GDK_space:
-                       gtk_tpdfv_page_down(tpdfv);
+                       tpdfv_ctl_page_down(obj);
                        break;
                case GDK_Home:
-                       gtk_tpdfv_first_page(tpdfv);
+                       tpdfv_ctl_first_page(obj);
                        break;
                case GDK_End:
-                       gtk_tpdfv_last_page(tpdfv);
+                       tpdfv_ctl_last_page(obj);
                        break;
 
                /* zoom */
                case GDK_plus:
-                       gtk_tpdfv_zoom_in(tpdfv);
+                       tpdfv_ctl_zoom_in(obj);
                        break;
                case GDK_minus:
-                       gtk_tpdfv_zoom_out(tpdfv);
+                       tpdfv_ctl_zoom_out(obj);
                        break;
                case GDK_1:
-                       gtk_tpdfv_zoom_1(tpdfv);
+                       tpdfv_ctl_zoom_1(obj);
                        break;
                case GDK_w:
-                       gtk_tpdfv_zoom_width(tpdfv);
+                       tpdfv_ctl_zoom_width(obj);
                        break;
                case GDK_h:
-                       gtk_tpdfv_zoom_height(tpdfv);
+                       tpdfv_ctl_zoom_height(obj);
                        break;
                case GDK_z:
-                       gtk_tpdfv_zoom_fit(tpdfv);
+                       tpdfv_ctl_zoom_fit(obj);
                        break;
 
                /* scrolling */
                case GDK_Up:
-                       gtk_tpdfv_scroll_up(tpdfv);
+                       tpdfv_ctl_scroll_up(obj);
                        break;
                case GDK_Down:
-                       gtk_tpdfv_scroll_down(tpdfv);
+                       tpdfv_ctl_scroll_down(obj);
                        break;
                case GDK_Left:
-                       gtk_tpdfv_scroll_left(tpdfv);
+                       tpdfv_ctl_scroll_left(obj);
                        break;
                case GDK_Right:
-                       gtk_tpdfv_scroll_right(tpdfv);
+                       tpdfv_ctl_scroll_right(obj);
                        break;
 
                /* screen management */
@@ -205,8 +206,10 @@ key_press(GtkWidget *window, GdkEventKey *event, gpointer data)
 int
 main(int argc, char **argv)
 {
-       GtkWidget *win   = NULL;
-       GtkWidget *tpdfv = NULL;
+       GtkWidget *win;
+       GtkWidget *tpdfv;
+
+       GObject *ctl;
 
        char win_title[1024];
 
@@ -259,10 +262,14 @@ main(int argc, char **argv)
 
        gtk_container_add(GTK_CONTAINER(win), tpdfv);
 
+       ctl = tpdfv_ctl_new(GTK_TPDFV(tpdfv));
+       if (! ctl)
+               return 1;
+
        g_signal_connect(G_OBJECT(win), "destroy",
                        G_CALLBACK(on_destroy), NULL);
        g_signal_connect(G_OBJECT(win), "key-press-event",
-                       G_CALLBACK(key_press), tpdfv);
+                       G_CALLBACK(key_press), ctl);
 
        /* TODO: use resource file */
        gdk_color_parse("#000000", &bg_color);