Code

Fixing preview/swatch sizes.
[inkscape.git] / src / event-context.cpp
index 47c5fac269ed7e2d6b4185bd6c40e583dfbd85a0..f482c99fb0dc6d0880591e0c37e4d19f6ee9fde8 100644 (file)
 # include "config.h"
 #endif
 
+#include <string.h>
 #include <gdk/gdkkeysyms.h>
 #include <gtk/gtkmain.h>
 #include <gtk/gtkmenu.h>
 #include <glibmm/i18n.h>
+#include <cstring>
+#include <string>
 
 #include "display/sp-canvas.h"
 #include "xml/node-event-vector.h"
@@ -69,6 +72,10 @@ static GObjectClass *parent_class;
 static bool selector_toggled = FALSE;
 static int switch_selector_to = 0;
 
+// globals for temporary switching to dropper by 'D'
+static bool dropper_toggled = FALSE;
+static int switch_dropper_to = 0;
+
 static gint xp = 0, yp = 0; // where drag started
 static gint tolerance = 0;
 static bool within_tolerance = false;
@@ -215,14 +222,15 @@ gint gobble_key_events(guint keyval, gint mask)
 
     event_next = gdk_event_get();
     // while the next event is also a key notify with the same keyval and mask,
-    while (event_next && event_next->type == GDK_KEY_PRESS
+    while (event_next && (event_next->type == GDK_KEY_PRESS || event_next->type == GDK_KEY_RELEASE)
            && event_next->key.keyval == keyval
-           && (event_next->key.state & mask)) {
+           && (!mask || (event_next->key.state & mask))) {
+        if (event_next->type == GDK_KEY_PRESS)
+            i ++; 
         // kill it
         gdk_event_free(event_next);
         // get next
         event_next = gdk_event_get();
-        i ++;
     }
     // otherwise, put it back onto the queue
     if (event_next) gdk_event_put(event_next);
@@ -275,21 +283,34 @@ sp_toggle_selector(SPDesktop *dt)
     }
 }
 
+/**
+ * Toggles current tool between active tool and dropper tool.
+ * Subroutine of sp_event_context_private_root_handler().
+ */
+static void
+sp_toggle_dropper(SPDesktop *dt)
+{
+    if (!dt->event_context) return;
+
+    if (tools_isactive(dt, TOOLS_DROPPER)) {
+        if (dropper_toggled) {
+            if (switch_dropper_to) tools_switch (dt, switch_dropper_to);
+            dropper_toggled = FALSE;
+        } else return;
+    } else {
+        dropper_toggled = TRUE;
+        switch_dropper_to = tools_active(dt);
+        tools_switch (dt, TOOLS_DROPPER);
+    }
+}
+
 /**
  * Calculates and keeps track of scroll acceleration.
  * Subroutine of sp_event_context_private_root_handler().
  */
-static gdouble accelerate_scroll(GdkEvent *event, gdouble acceleration, SPCanvas *canvas)
+static gdouble accelerate_scroll(GdkEvent *event, gdouble acceleration, SPCanvas */*canvas*/)
 {
     guint32 time_diff = ((GdkEventKey *) event)->time - scroll_event_time;
-    glong slowest_buffer = canvas->slowest_buffer / 1000; // the buffer time is in usec, but event time is in msec
-
-    // reduce time interval by the time it took to paint slowest buffer, 
-    // so that acceleration does not hiccup on complex slow-rendering drawings
-    if ((guint32) slowest_buffer <= time_diff)
-        time_diff -= slowest_buffer;
-    else
-        time_diff = 0;
 
     /* key pressed within 500ms ? (1/2 second) */
     if (time_diff > 500 || event->key.keyval != scroll_keyval) {
@@ -440,6 +461,8 @@ static gint sp_event_context_private_root_handler(SPEventContext *event_context,
                 } else {
                     Inkscape::Rubberband::get()->start(desktop, motion_dt);
                 } 
+                if (zoom_rb == 2)
+                    gobble_motion_events(GDK_BUTTON2_MASK);
             }
             break;
         case GDK_BUTTON_RELEASE:
@@ -500,6 +523,13 @@ static gint sp_event_context_private_root_handler(SPEventContext *event_context,
                     ret = sp_shortcut_invoke(shortcut, desktop);
                     break;
 
+                case GDK_D:
+                case GDK_d:
+                    if (!MOD__SHIFT && !MOD__CTRL && !MOD__ALT) {
+                        sp_toggle_dropper(desktop);
+                        ret = TRUE;
+                    }
+                    break;
                 case GDK_W:
                 case GDK_w:
                 case GDK_F4:
@@ -600,6 +630,9 @@ static gint sp_event_context_private_root_handler(SPEventContext *event_context,
             }
             break;
         case GDK_SCROLL:
+        {
+            bool ctrl = (event->scroll.state & GDK_CONTROL_MASK);
+            bool wheelzooms = (prefs_get_int_attribute("options.wheelzooms","value", 0) == 1);
             /* shift + wheel, pan left--right */
             if (event->scroll.state & GDK_SHIFT_MASK) {
                 switch (event->scroll.direction) {
@@ -614,7 +647,7 @@ static gint sp_event_context_private_root_handler(SPEventContext *event_context,
                 }
 
                 /* ctrl + wheel, zoom in--out */
-            } else if (event->scroll.state & GDK_CONTROL_MASK) {
+            } else if ((ctrl && !wheelzooms) || (!ctrl && wheelzooms)) {
                 double rel_zoom;
                 switch (event->scroll.direction) {
                     case GDK_SCROLL_UP:
@@ -650,6 +683,7 @@ static gint sp_event_context_private_root_handler(SPEventContext *event_context,
                 }
             }
             break;
+        }
         default:
             break;
     }
@@ -687,8 +721,8 @@ sp_event_context_private_item_handler(SPEventContext *ec, SPItem *item, GdkEvent
  * Gets called when attribute changes value.
  */
 static void
-sp_ec_repr_attr_changed(Inkscape::XML::Node *prefs_repr, gchar const *key, gchar const *oldval, gchar const *newval,
-                        bool is_interactive, gpointer data)
+sp_ec_repr_attr_changed(Inkscape::XML::Node */*prefs_repr*/, gchar const *key, gchar const */*oldval*/, gchar const *newval,
+                        bool /*is_interactive*/, gpointer data)
 {
     SPEventContext *ec;
 
@@ -1005,9 +1039,9 @@ sp_event_context_over_item (SPDesktop *desktop, SPItem *item, NR::Point const p)
  * Called when SPEventContext subclass node attribute changed.
  */
 void
-ec_shape_event_attr_changed(Inkscape::XML::Node *shape_repr, gchar const *name,
-        gchar const *old_value, gchar const *new_value,
-        bool const is_interactive, gpointer const data)
+ec_shape_event_attr_changed(Inkscape::XML::Node */*shape_repr*/, gchar const *name,
+                            gchar const */*old_value*/, gchar const */*new_value*/,
+                            bool const /*is_interactive*/, gpointer const data)
 {
     if (!name
             || !strcmp(name, "style")