Code

Corrected focus problems by moving flag setting back to first thing
[inkscape.git] / src / rect-context.cpp
index be56047f04d108df57587d9d5ca64f0252a2b2c5..fd3d05a30ba45875f811cb5e130c1f4fdd195fe3 100644 (file)
@@ -7,6 +7,7 @@
  *   Lauris Kaplinski <lauris@kaplinski.com>
  *   bulia byak <buliabyak@users.sf.net>
  *
+ * Copyright (C) 2006      Johan Engelen <johan@shouraizou.nl>
  * Copyright (C) 2000-2005 authors
  * Copyright (C) 2000-2001 Ximian, Inc.
  *
@@ -181,7 +182,6 @@ void sp_rect_context_selection_changed(Inkscape::Selection *selection, gpointer
             ec->shape_repr = shape_repr;
             Inkscape::GC::anchor(shape_repr);
             sp_repr_add_listener(shape_repr, &ec_shape_repr_events, ec);
-            sp_repr_synthesize_events(shape_repr, &ec_shape_repr_events, ec);
         }
     }
 }
@@ -194,7 +194,7 @@ static void sp_rect_context_setup(SPEventContext *ec)
         ((SPEventContextClass *) parent_class)->setup(ec);
     }
 
-    SPItem *item = SP_DT_SELECTION(ec->desktop)->singleItem();
+    SPItem *item = sp_desktop_selection(ec->desktop)->singleItem();
     if (item) {
         ec->shape_knot_holder = sp_item_knot_holder(item, ec->desktop);
         Inkscape::XML::Node *shape_repr = SP_OBJECT_REPR(item);
@@ -202,12 +202,11 @@ static void sp_rect_context_setup(SPEventContext *ec)
             ec->shape_repr = shape_repr;
             Inkscape::GC::anchor(shape_repr);
             sp_repr_add_listener(shape_repr, &ec_shape_repr_events, ec);
-            sp_repr_synthesize_events(shape_repr, &ec_shape_repr_events, ec);
         }
     }
 
     rc->sel_changed_connection.disconnect();
-    rc->sel_changed_connection = SP_DT_SELECTION(ec->desktop)->connectChanged(
+    rc->sel_changed_connection = sp_desktop_selection(ec->desktop)->connectChanged(
         sigc::bind(sigc::ptr_fun(&sp_rect_context_selection_changed), (gpointer)rc)
     );
 
@@ -272,7 +271,7 @@ static gint sp_rect_context_root_handler(SPEventContext *event_context, GdkEvent
     static bool dragging;
 
     SPDesktop *desktop = event_context->desktop;
-    Inkscape::Selection *selection = SP_DT_SELECTION (desktop);
+    Inkscape::Selection *selection = sp_desktop_selection (desktop);
 
     SPRectContext *rc = SP_RECT_CONTEXT(event_context);
 
@@ -299,15 +298,14 @@ static gint sp_rect_context_root_handler(SPEventContext *event_context, GdkEvent
             NR::Point const button_dt(desktop->w2d(button_w));
 
             /* Snap center */
-            SnapManager const m(desktop->namedview);
+            SnapManager const &m = desktop->namedview->snap_manager;
             rc->center = m.freeSnap(Inkscape::Snapper::SNAP_POINT | Inkscape::Snapper::BBOX_POINT,
                                     button_dt, rc->item).getPoint();
-            
+
             sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate),
-                                ( GDK_KEY_PRESS_MASK | 
+                                ( GDK_KEY_PRESS_MASK |
                                   GDK_BUTTON_RELEASE_MASK       |
                                   GDK_POINTER_MOTION_MASK       |
-                                  GDK_POINTER_MOTION_HINT_MASK  |
                                   GDK_BUTTON_PRESS_MASK ),
                                 NULL, event->button.time);
             ret = TRUE;
@@ -370,10 +368,12 @@ static gint sp_rect_context_root_handler(SPEventContext *event_context, GdkEvent
         case GDK_Shift_R:
         case GDK_Meta_L:  // Meta is when you press Shift+Alt (at least on my machine)
         case GDK_Meta_R:
-            sp_event_show_modifier_tip (event_context->defaultMessageContext(), event,
-                                        _("<b>Ctrl</b>: make square or integer-ratio rect, lock a rounded corner circular"),
-                                        _("<b>Shift</b>: draw around the starting point"),
-                                        NULL);
+            if (!dragging){
+                sp_event_show_modifier_tip (event_context->defaultMessageContext(), event,
+                                            _("<b>Ctrl</b>: make square or integer-ratio rect, lock a rounded corner circular"),
+                                            _("<b>Shift</b>: draw around the starting point"),
+                                            NULL);
+            }
             break;
         case GDK_Up:
         case GDK_Down:
@@ -393,7 +393,7 @@ static gint sp_rect_context_root_handler(SPEventContext *event_context, GdkEvent
             break;
 
         case GDK_Escape:
-            SP_DT_SELECTION(desktop)->clear();
+            sp_desktop_selection(desktop)->clear();
             //TODO: make dragging escapable by Esc
         default:
             break;
@@ -448,10 +448,12 @@ static void sp_rect_drag(SPRectContext &rc, NR::Point const pt, guint state)
         Inkscape::GC::release(repr);
         rc.item->transform = SP_ITEM(desktop->currentRoot())->getRelativeTransform(desktop->currentLayer());
         rc.item->updateRepr();
+
+        sp_canvas_force_full_redraw_after_interruptions(desktop->canvas, 5);
     }
 
     NR::Rect const r = Inkscape::snap_rectangular_box(desktop, rc.item, pt, rc.center, state);
-    
+
     sp_rect_position_set(SP_RECT(rc.item), r.min()[NR::X], r.min()[NR::Y], r.dimensions()[NR::X], r.dimensions()[NR::Y]);
     if ( rc.rx != 0.0 ) {
         sp_rect_set_rx (SP_RECT(rc.item), TRUE, rc.rx);
@@ -459,7 +461,7 @@ static void sp_rect_drag(SPRectContext &rc, NR::Point const pt, guint state)
     if ( rc.ry != 0.0 ) {
         if (rc.rx == 0.0)
             sp_rect_set_ry (SP_RECT(rc.item), TRUE, CLAMP(rc.ry, 0, MIN(r.dimensions()[NR::X], r.dimensions()[NR::Y])/2));
-        else 
+        else
             sp_rect_set_ry (SP_RECT(rc.item), TRUE, CLAMP(rc.ry, 0, r.dimensions()[NR::Y]));
     }
 
@@ -476,14 +478,17 @@ static void sp_rect_finish(SPRectContext *rc)
     rc->_message_context->clear();
 
     if ( rc->item != NULL ) {
-        SPDesktop * dt;
+        SPDesktop * desktop;
 
-        dt = SP_EVENT_CONTEXT_DESKTOP(rc);
+        desktop = SP_EVENT_CONTEXT_DESKTOP(rc);
 
         SP_OBJECT(rc->item)->updateRepr();
 
-        SP_DT_SELECTION(dt)->set(rc->item);
-        sp_document_done(SP_DT_DOCUMENT(dt));
+        sp_canvas_end_forced_full_redraws(desktop->canvas);
+
+        sp_desktop_selection(desktop)->set(rc->item);
+        sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_RECT,
+                         _("Create rectangle"));
 
         rc->item = NULL;
     }