]> www.fi.muni.cz Git - evince.git/commitdiff
Add key bindings to the view. Now if the focus would work right...
authorMarco Pesenti Gritti <marco@gnome.org>
Sun, 2 Jan 2005 15:07:30 +0000 (15:07 +0000)
committerMarco Pesenti Gritti <marco@src.gnome.org>
Sun, 2 Jan 2005 15:07:30 +0000 (15:07 +0000)
2005-01-02  Marco Pesenti Gritti  <marco@gnome.org>

        * shell/ev-marshal.list:
        * shell/ev-view.c: (ev_view_realize), (add_scroll_binding),
        (ev_view_scroll_view), (ev_view_class_init), (ev_view_init):

        Add key bindings to the view. Now if the focus would work
        right...

ChangeLog
shell/ev-marshal.list
shell/ev-view.c

index d4e01e55ecd8753819e3a85e35f1f4f98af5d10a..db1caa871ca73b52ddc48342241a12a04ab243da 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2005-01-02  Marco Pesenti Gritti  <marco@gnome.org>
+
+       * shell/ev-marshal.list:
+       * shell/ev-view.c: (ev_view_realize), (add_scroll_binding),
+       (ev_view_scroll_view), (ev_view_class_init), (ev_view_init):
+
+       Add key bindings to the view. Now if the focus would work
+       right...
+
 2005-01-02  Marco Pesenti Gritti  <marco@gnome.org>
 
        * Makefile.am:
index 559b357a1a51bb8cd0af4f54d0282178ed20076f..c2a026bf2dd58e05e4386f63aeef73611d36e0bb 100644 (file)
@@ -1,2 +1,3 @@
 VOID:NONE
 VOID:OBJECT,OBJECT
+VOID:ENUM,BOOLEAN
index 99c688e9445a65a5e6dea04d33875d8833dbe24f..3a23cc3ee377c059b5dbb434d6aec701f21e3069 100644 (file)
@@ -20,6 +20,8 @@
 
 #include <gtk/gtkalignment.h>
 #include <glib/gi18n.h>
+#include <gtk/gtkbindings.h>
+#include <gdk/gdkkeysyms.h>
 
 #include "ev-marshal.h"
 #include "ev-view.h"
@@ -56,6 +58,9 @@ struct _EvViewClass {
        void    (*set_scroll_adjustments) (EvView         *view,
                                           GtkAdjustment  *hadjustment,
                                           GtkAdjustment  *vadjustment);
+       void    (*scroll_view)            (EvView         *view,
+                                          GtkScrollType   scroll,
+                                          gboolean        horizontal);
        
        /* Should this be notify::page? */
        void    (*page_changed)           (EvView         *view);
@@ -240,7 +245,9 @@ ev_view_realize (GtkWidget *widget)
        attributes.y = 0;
        attributes.width = MAX (widget->allocation.width, widget->requisition.width);
        attributes.height = MAX (widget->allocation.height, widget->requisition.height);
-       attributes.event_mask = GDK_EXPOSURE_MASK | GDK_SCROLL_MASK;
+       attributes.event_mask = GDK_EXPOSURE_MASK |
+                               GDK_SCROLL_MASK |
+                               GDK_KEY_PRESS_MASK;
   
        view->bin_window = gdk_window_new (widget->window,
                                           &attributes,
@@ -423,12 +430,69 @@ ev_view_set_scroll_adjustments (EvView *view,
        view_update_adjustments (view);
 }
 
+static void
+add_scroll_binding (GtkBindingSet  *binding_set,
+                   guint           keyval,
+                   GtkScrollType   scroll,
+                   gboolean        horizontal)
+{
+  guint keypad_keyval = keyval - GDK_Left + GDK_KP_Left;
+  
+  gtk_binding_entry_add_signal (binding_set, keyval, 0,
+                                "scroll_view", 2,
+                                GTK_TYPE_SCROLL_TYPE, scroll,
+                               G_TYPE_BOOLEAN, horizontal);
+  gtk_binding_entry_add_signal (binding_set, keypad_keyval, 0,
+                                "scroll_view", 2,
+                                GTK_TYPE_SCROLL_TYPE, scroll,
+                               G_TYPE_BOOLEAN, horizontal);
+}
+
+static void
+ev_view_scroll_view (EvView *view,
+                     GtkScrollType scroll,
+                     gboolean horizontal)
+{
+       GtkAdjustment *adjustment;
+       double value;
+
+       if (horizontal) {
+               adjustment = view->hadjustment; 
+       } else {
+               adjustment = view->vadjustment;
+       }
+
+       value = adjustment->value;
+
+       switch (scroll) {
+               case GTK_SCROLL_STEP_BACKWARD:  
+                       value -= adjustment->step_increment; 
+                       break;
+               case GTK_SCROLL_STEP_FORWARD:
+                       value += adjustment->step_increment; 
+                       break;
+               case GTK_SCROLL_PAGE_BACKWARD:  
+                       value -= adjustment->page_increment; 
+                       break;
+               case GTK_SCROLL_PAGE_FORWARD:
+                       value += adjustment->page_increment; 
+                       break;
+               default:
+                       break;
+       }
+
+       value = CLAMP (value, adjustment->lower, adjustment->upper - adjustment->page_size);
+
+       gtk_adjustment_set_value (adjustment, value);
+}
+
 static void
 ev_view_class_init (EvViewClass *class)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (class);
        GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (class);
        GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
+       GtkBindingSet *binding_set;
 
        object_class->finalize = ev_view_finalize;
 
@@ -443,8 +507,9 @@ ev_view_class_init (EvViewClass *class)
        widget_class->style_set = ev_view_style_set;
        widget_class->state_changed = ev_view_state_changed;
        gtk_object_class->destroy = ev_view_destroy;
-  
+
        class->set_scroll_adjustments = ev_view_set_scroll_adjustments;
+       class->scroll_view = ev_view_scroll_view;
 
        widget_class->set_scroll_adjustments_signal =  g_signal_new ("set-scroll-adjustments",
                                                                     G_OBJECT_CLASS_TYPE (object_class),
@@ -470,6 +535,26 @@ ev_view_class_init (EvViewClass *class)
                      NULL, NULL,
                      ev_marshal_VOID__NONE,
                      G_TYPE_NONE, 0);
+
+       g_signal_new ("scroll_view",
+                     G_TYPE_FROM_CLASS (object_class),
+                     G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+                     G_STRUCT_OFFSET (EvViewClass, scroll_view),
+                     NULL, NULL,
+                     ev_marshal_VOID__ENUM_BOOLEAN,
+                     G_TYPE_NONE, 2,
+                     GTK_TYPE_SCROLL_TYPE,
+                     G_TYPE_BOOLEAN);
+
+       binding_set = gtk_binding_set_by_class (class);
+
+       add_scroll_binding (binding_set, GDK_Left,  GTK_SCROLL_STEP_BACKWARD, TRUE);
+       add_scroll_binding (binding_set, GDK_Right, GTK_SCROLL_STEP_FORWARD,  TRUE);
+       add_scroll_binding (binding_set, GDK_Up,    GTK_SCROLL_STEP_BACKWARD, FALSE);
+       add_scroll_binding (binding_set, GDK_Down,  GTK_SCROLL_STEP_FORWARD,  FALSE);
+
+       add_scroll_binding (binding_set, GDK_Page_Up,   GTK_SCROLL_PAGE_BACKWARD, FALSE);
+       add_scroll_binding (binding_set, GDK_Page_Down, GTK_SCROLL_PAGE_FORWARD,  FALSE);
 }
 
 static void
@@ -477,6 +562,8 @@ ev_view_init (EvView *view)
 {
        static const GdkColor white = { 0, 0xffff, 0xffff, 0xffff };
 
+       GTK_WIDGET_SET_FLAGS (view, GTK_CAN_FOCUS);
+
        view->scale = 1.0;
        
        gtk_widget_modify_bg (GTK_WIDGET (view), GTK_STATE_NORMAL, &white);