Code

Split SPCanvasItem and SPCanvasGroup to individual .h files. Removed forward header.
[inkscape.git] / src / zoom-context.cpp
index 4566a5ab0ed7f165858a440ef107883acbdac653..45de37652a03caa7a05b2dc8b040923a7d0c74dc 100644 (file)
@@ -1,5 +1,3 @@
-#define __SP_ZOOM_CONTEXT_C__
-
 /*
  * Handy zooming tool
  *
 
 #include "macros.h"
 #include "rubberband.h"
+#include "display/sp-canvas-item.h"
+#include "display/sp-canvas-util.h"
 #include "desktop.h"
 #include "pixmaps/cursor-zoom.xpm"
 #include "pixmaps/cursor-zoom-out.xpm"
-#include "prefs-utils.h"
+#include "preferences.h"
 
 #include "zoom-context.h"
 
@@ -86,15 +86,23 @@ static void sp_zoom_context_init (SPZoomContext *zoom_context)
 static void
 sp_zoom_context_finish (SPEventContext *ec)
 {
+       SPZoomContext *zc = SP_ZOOM_CONTEXT(ec);
+       
        ec->enableGrDrag(false);
+       
+    if (zc->grabbed) {
+        sp_canvas_item_ungrab(zc->grabbed, GDK_CURRENT_TIME);
+        zc->grabbed = NULL;
+    }
 }
 
 static void sp_zoom_context_setup(SPEventContext *ec)
 {
-    if (prefs_get_int_attribute("tools.zoom", "selcue", 0) != 0) {
+    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+    if (prefs->getBool("/tools/zoom/selcue")) {
         ec->enableSelectionCue();
     }
-    if (prefs_get_int_attribute("tools.zoom", "gradientdrag", 0) != 0) {
+    if (prefs->getBool("/tools/zoom/gradientdrag")) {
         ec->enableGrDrag();
     }
 
@@ -117,28 +125,45 @@ static gint sp_zoom_context_item_handler(SPEventContext *event_context, SPItem *
 static gint sp_zoom_context_root_handler(SPEventContext *event_context, GdkEvent *event)
 {
     SPDesktop *desktop = event_context->desktop;
-    tolerance = prefs_get_int_attribute_limited ("options.dragtolerance", "value", 0, 0, 100);
-    double const zoom_inc = prefs_get_double_attribute_limited("options.zoomincrement", "value", M_SQRT2, 1.01, 10);
+    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+       
+       SPZoomContext *zc = SP_ZOOM_CONTEXT(event_context);
+    tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100);
+    double const zoom_inc = prefs->getDoubleLimited("/options/zoomincrement/value", M_SQRT2, 1.01, 10);
 
     gint ret = FALSE;
 
     switch (event->type) {
         case GDK_BUTTON_PRESS:
+        {
+            Geom::Point const button_w(event->button.x, event->button.y);
+            Geom::Point const button_dt(desktop->w2d(button_w));
             if (event->button.button == 1 && !event_context->space_panning) {
                 // save drag origin
                 xp = (gint) event->button.x;
                 yp = (gint) event->button.y;
                 within_tolerance = true;
 
-                NR::Point const button_w(event->button.x, event->button.y);
-                NR::Point const button_dt(desktop->w2d(button_w));
-                Inkscape::Rubberband::get()->start(desktop, button_dt);
+                Inkscape::Rubberband::get(desktop)->start(desktop, button_dt);
 
                 escaped = false;
 
+                ret = TRUE;
+            } else if (event->button.button == 3) {
+                double const zoom_rel( (event->button.state & GDK_SHIFT_MASK)
+                                       ? zoom_inc
+                                       : 1 / zoom_inc );
+                desktop->zoom_relative_keep_point(button_dt, zoom_rel);
                 ret = TRUE;
             }
+                       
+                       sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate),
+                                                               GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK,
+                                                               NULL, event->button.time);
+                       zc->grabbed = SP_CANVAS_ITEM(desktop->acetate);
+                               
             break;
+        }
 
        case GDK_MOTION_NOTIFY:
             if (event->motion.state & GDK_BUTTON1_MASK && !event_context->space_panning) {
@@ -154,36 +179,44 @@ static gint sp_zoom_context_root_handler(SPEventContext *event_context, GdkEvent
                 // motion notify coordinates as given (no snapping back to origin)
                 within_tolerance = false;
 
-                NR::Point const motion_w(event->motion.x, event->motion.y);
-                NR::Point const motion_dt(desktop->w2d(motion_w));
-                Inkscape::Rubberband::get()->move(motion_dt);
+                Geom::Point const motion_w(event->motion.x, event->motion.y);
+                Geom::Point const motion_dt(desktop->w2d(motion_w));
+                Inkscape::Rubberband::get(desktop)->move(motion_dt);
+                gobble_motion_events(GDK_BUTTON1_MASK);
             }
             break;
 
-       case GDK_BUTTON_RELEASE:
+       case GDK_BUTTON_RELEASE:
+        {
+            Geom::Point const button_w(event->button.x, event->button.y);
+            Geom::Point const button_dt(desktop->w2d(button_w));
             if ( event->button.button == 1  && !event_context->space_panning) {
-                NR::Maybe<NR::Rect> const b = Inkscape::Rubberband::get()->getRectangle();
+                Geom::OptRect const b = Inkscape::Rubberband::get(desktop)->getRectangle();
                 if (b && !within_tolerance) {
                     desktop->set_display_area(*b, 10);
                 } else if (!escaped) {
-                    NR::Point const button_w(event->button.x, event->button.y);
-                    NR::Point const button_dt(desktop->w2d(button_w));
                     double const zoom_rel( (event->button.state & GDK_SHIFT_MASK)
                                            ? 1 / zoom_inc
                                            : zoom_inc );
                     desktop->zoom_relative_keep_point(button_dt, zoom_rel);
                 }
                 ret = TRUE;
-            }
-            Inkscape::Rubberband::get()->stop();
+            } 
+            Inkscape::Rubberband::get(desktop)->stop();
+                       
+                       if (zc->grabbed) {
+                               sp_canvas_item_ungrab(zc->grabbed, event->button.time);
+                               zc->grabbed = NULL;
+                       }
+                       
             xp = yp = 0;
             escaped = false;
             break;
-
+        }
         case GDK_KEY_PRESS:
             switch (get_group0_keyval (&event->key)) {
                 case GDK_Escape:
-                    Inkscape::Rubberband::get()->stop();
+                    Inkscape::Rubberband::get(desktop)->stop();
                     xp = yp = 0;
                     escaped = true;
                     ret = TRUE;