Code

Translations. French translation minor update.
[inkscape.git] / src / gradient-context.cpp
index b4f52a7c9bf7fa909564ca540d335badf1d677fd..d37e9b02270ba0e21149dda51c2842161893f18e 100644 (file)
@@ -1,11 +1,10 @@
-#define __SP_GRADIENT_CONTEXT_C__
-
 /*
  * Gradient drawing and editing tool
  *
  * Authors:
  *   bulia byak <buliabyak@users.sf.net>
  *   Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
+ *   Abhishek Sharma
  *
  * Copyright (C) 2007 Johan Engelen
  * Copyright (C) 2005 Authors
@@ -47,6 +46,7 @@
 #include "sp-namedview.h"
 #include "rubberband.h"
 
+using Inkscape::DocumentUndo;
 
 
 static void sp_gradient_context_class_init(SPGradientContextClass *klass);
@@ -140,13 +140,16 @@ const gchar *gr_handle_descr [] = {
     N_("Radial gradient <b>mid stop</b>")
 };
 
-static void 
+static void
 gradient_selection_changed (Inkscape::Selection *, gpointer data)
 {
     SPGradientContext *rc = (SPGradientContext *) data;
 
     GrDrag *drag = rc->_grdrag;
     Inkscape::Selection *selection = sp_desktop_selection(SP_EVENT_CONTEXT(rc)->desktop);
+    if (selection == NULL) {
+        return;
+    }
     guint n_obj = g_slist_length((GSList *) selection->itemList());
 
     if (!drag->isNonEmpty() || selection->isEmpty())
@@ -157,34 +160,34 @@ gradient_selection_changed (Inkscape::Selection *, gpointer data)
     //The use of ngettext in the following code is intentional even if the English singular form would never be used
     if (n_sel == 1) {
         if (drag->singleSelectedDraggerNumDraggables() == 1) {
-               gchar * message = g_strconcat(
-                       //TRANSLATORS: %s will be substituted with the point name (see previous messages); This is part of a compound message
-                       _("%s selected"),
-                       //TRANSLATORS: Mind the space in front. This is part of a compound message
-                       ngettext(" out of %d gradient handle"," out of %d gradient handles",n_tot),
-                       ngettext(" on %d selected object"," on %d selected objects",n_obj),NULL);
-               rc->_message_context->setF(Inkscape::NORMAL_MESSAGE,
-                       message,_(gr_handle_descr[drag->singleSelectedDraggerSingleDraggableType()]), n_tot, n_obj);
+            gchar * message = g_strconcat(
+                //TRANSLATORS: %s will be substituted with the point name (see previous messages); This is part of a compound message
+                _("%s selected"),
+                //TRANSLATORS: Mind the space in front. This is part of a compound message
+                ngettext(" out of %d gradient handle"," out of %d gradient handles",n_tot),
+                ngettext(" on %d selected object"," on %d selected objects",n_obj),NULL);
+            rc->_message_context->setF(Inkscape::NORMAL_MESSAGE,
+                                       message,_(gr_handle_descr[drag->singleSelectedDraggerSingleDraggableType()]), n_tot, n_obj);
         } else {
-               gchar * message = g_strconcat(
-                       //TRANSLATORS: This is a part of a compound message (out of two more indicating: grandint handle count & object count)
-                       ngettext("One handle merging %d stop (drag with <b>Shift</b> to separate) selected",
-                               "One handle merging %d stops (drag with <b>Shift</b> to separate) selected",drag->singleSelectedDraggerNumDraggables()),
-                       ngettext(" out of %d gradient handle"," out of %d gradient handles",n_tot),
-                       ngettext(" on %d selected object"," on %d selected objects",n_obj),NULL);
-               rc->_message_context->setF(Inkscape::NORMAL_MESSAGE,message,drag->singleSelectedDraggerNumDraggables(), n_tot, n_obj);
+            gchar * message = g_strconcat(
+                //TRANSLATORS: This is a part of a compound message (out of two more indicating: grandint handle count & object count)
+                ngettext("One handle merging %d stop (drag with <b>Shift</b> to separate) selected",
+                         "One handle merging %d stops (drag with <b>Shift</b> to separate) selected",drag->singleSelectedDraggerNumDraggables()),
+                ngettext(" out of %d gradient handle"," out of %d gradient handles",n_tot),
+                ngettext(" on %d selected object"," on %d selected objects",n_obj),NULL);
+            rc->_message_context->setF(Inkscape::NORMAL_MESSAGE,message,drag->singleSelectedDraggerNumDraggables(), n_tot, n_obj);
         }
     } else if (n_sel > 1) {
-       //TRANSLATORS: The plural refers to number of selected gradient handles. This is part of a compound message (part two indicates selected object count)
-       gchar * message = g_strconcat(ngettext("<b>%d</b> gradient handle selected out of %d","<b>%d</b> gradient handles selected out of %d",n_sel),
-                                     //TRANSLATORS: Mind the space in front. (Refers to gradient handles selected). This is part of a compound message
-                                     ngettext(" on %d selected object"," on %d selected objects",n_obj),NULL);
+        //TRANSLATORS: The plural refers to number of selected gradient handles. This is part of a compound message (part two indicates selected object count)
+        gchar * message = g_strconcat(ngettext("<b>%d</b> gradient handle selected out of %d","<b>%d</b> gradient handles selected out of %d",n_sel),
+                                      //TRANSLATORS: Mind the space in front. (Refers to gradient handles selected). This is part of a compound message
+                                      ngettext(" on %d selected object"," on %d selected objects",n_obj),NULL);
         rc->_message_context->setF(Inkscape::NORMAL_MESSAGE,message, n_sel, n_tot, n_obj);
     } else if (n_sel == 0) {
         rc->_message_context->setF(Inkscape::NORMAL_MESSAGE,
-               //TRANSLATORS: The plural refers to number of selected objects
-                ngettext("<b>No</b> gradient handles selected out of %d on %d selected object",
-                        "<b>No</b> gradient handles selected out of %d on %d selected objects",n_obj), n_tot, n_obj);
+                                   //TRANSLATORS: The plural refers to number of selected objects
+                                   ngettext("<b>No</b> gradient handles selected out of %d on %d selected object",
+                                            "<b>No</b> gradient handles selected out of %d on %d selected objects",n_obj), n_tot, n_obj);
     }
 }
 
@@ -271,7 +274,7 @@ sp_gradient_context_get_stop_intervals (GrDrag *drag, GSList **these_stops, GSLi
         // remember the coord of the dragger to reselect it later
         coords.push_back(dragger->point);
         // for all draggables of dragger
-        for (GSList const* j = dragger->draggables; j != NULL; j = j->next) { 
+        for (GSList const* j = dragger->draggables; j != NULL; j = j->next) {
             GrDraggable *d = (GrDraggable *) j->data;
 
             // find the gradient
@@ -279,16 +282,16 @@ sp_gradient_context_get_stop_intervals (GrDrag *drag, GSList **these_stops, GSLi
             SPGradient *vector = sp_gradient_get_forked_vector_if_necessary (gradient, false);
 
             // these draggable types cannot have a next draggabe to insert a stop between them
-            if (d->point_type == POINT_LG_END || 
-                d->point_type == POINT_RG_FOCUS || 
-                d->point_type == POINT_RG_R1 || 
+            if (d->point_type == POINT_LG_END ||
+                d->point_type == POINT_RG_FOCUS ||
+                d->point_type == POINT_RG_R1 ||
                 d->point_type == POINT_RG_R2) {
                 continue;
             }
 
             // from draggables to stops
             SPStop *this_stop = sp_get_stop_i (vector, d->point_i);
-            SPStop *next_stop = sp_next_stop (this_stop);
+            SPStop *next_stop = this_stop->getNextStop();
             SPStop *last_stop = sp_last_stop (vector);
 
             gint fs = d->fill_or_stroke;
@@ -299,7 +302,7 @@ sp_gradient_context_get_stop_intervals (GrDrag *drag, GSList **these_stops, GSLi
             // if there's a next stop,
             if (next_stop) {
                 GrDragger *dnext = NULL;
-                // find its dragger 
+                // find its dragger
                 // (complex because it may have different types, and because in radial,
                 // more than one dragger may correspond to a stop, so we must distinguish)
                 if (type == POINT_LG_BEGIN || type == POINT_LG_MID) {
@@ -311,14 +314,14 @@ sp_gradient_context_get_stop_intervals (GrDrag *drag, GSList **these_stops, GSLi
                     if (type == POINT_RG_CENTER || type == POINT_RG_MID1) {
                         if (next_stop == last_stop)
                             dnext = drag->getDraggerFor (item, POINT_RG_R1, p_i+1, fs);
-                        else 
+                        else
                             dnext = drag->getDraggerFor (item, POINT_RG_MID1, p_i+1, fs);
-                    } 
-                    if ((type == POINT_RG_MID2) || 
+                    }
+                    if ((type == POINT_RG_MID2) ||
                         (type == POINT_RG_CENTER && dnext && !dnext->isSelected())) {
                         if (next_stop == last_stop)
                             dnext = drag->getDraggerFor (item, POINT_RG_R2, p_i+1, fs);
-                        else 
+                        else
                             dnext = drag->getDraggerFor (item, POINT_RG_MID2, p_i+1, fs);
                     }
                 }
@@ -354,12 +357,12 @@ sp_gradient_context_add_stops_between_selected_stops (SPGradientContext *rc)
     if (g_slist_length(these_stops) == 0 && drag->numSelected() == 1) {
         // if a single stop is selected, add between that stop and the next one
         GrDragger *dragger = (GrDragger *) drag->selected->data;
-        for (GSList const* j = dragger->draggables; j != NULL; j = j->next) { 
+        for (GSList const* j = dragger->draggables; j != NULL; j = j->next) {
             GrDraggable *d = (GrDraggable *) j->data;
             SPGradient *gradient = sp_item_gradient (d->item, d->fill_or_stroke);
             SPGradient *vector = sp_gradient_get_forked_vector_if_necessary (gradient, false);
             SPStop *this_stop = sp_get_stop_i (vector, d->point_i);
-            SPStop *next_stop = sp_next_stop (this_stop);
+            SPStop *next_stop = this_stop->getNextStop();
             if (this_stop && next_stop) {
                 these_stops = g_slist_prepend (these_stops, this_stop);
                 next_stops = g_slist_prepend (next_stops, next_stop);
@@ -378,12 +381,12 @@ sp_gradient_context_add_stops_between_selected_stops (SPGradientContext *rc)
         if (SP_IS_GRADIENT (parent)) {
             doc = SP_OBJECT_DOCUMENT (parent);
             sp_vector_add_stop (SP_GRADIENT (parent), this_stop, next_stop, offset);
-            sp_gradient_ensure_vector (SP_GRADIENT (parent));
+            SP_GRADIENT(parent)->ensureVector();
         }
     }
 
     if (g_slist_length(these_stops) > 0 && doc) {
-        sp_document_done (doc, SP_VERB_CONTEXT_GRADIENT, _("Add gradient stop"));
+        DocumentUndo::done(doc, SP_VERB_CONTEXT_GRADIENT, _("Add gradient stop"));
         drag->updateDraggers();
         // so that it does not automatically update draggers in idle loop, as this would deselect
         drag->local_change = true;
@@ -428,10 +431,10 @@ sp_gradient_simplify(SPGradientContext *rc, double tolerance)
                 guint32 const c0 = sp_stop_get_rgba32(stop0);
                 guint32 const c2 = sp_stop_get_rgba32(stop2);
                 guint32 const c1r = sp_stop_get_rgba32(stop1);
-                guint32 c1 = average_color (c0, c2, 
+                guint32 c1 = average_color (c0, c2,
                        (stop1->offset - stop0->offset) / (stop2->offset - stop0->offset));
 
-                double diff = 
+                double diff =
                     sqr(SP_RGBA32_R_F(c1) - SP_RGBA32_R_F(c1r)) +
                     sqr(SP_RGBA32_G_F(c1) - SP_RGBA32_G_F(c1r)) +
                     sqr(SP_RGBA32_B_F(c1) - SP_RGBA32_B_F(c1r)) +
@@ -451,7 +454,7 @@ sp_gradient_simplify(SPGradientContext *rc, double tolerance)
     }
 
     if (g_slist_length(todel) > 0) {
-        sp_document_done (doc, SP_VERB_CONTEXT_GRADIENT, _("Simplify gradient"));
+        DocumentUndo::done(doc, SP_VERB_CONTEXT_GRADIENT, _("Simplify gradient"));
         drag->local_change = true;
         drag->updateDraggers();
         drag->selectByCoords(coords);
@@ -475,8 +478,8 @@ sp_gradient_context_add_stop_near_point (SPGradientContext *rc, SPItem *item,  G
 
     ec->get_drag()->addStopNearPoint (item, mouse_p, tolerance/desktop->current_zoom());
 
-    sp_document_done (sp_desktop_document (desktop), SP_VERB_CONTEXT_GRADIENT,
-                      _("Add gradient stop"));
+    DocumentUndo::done(sp_desktop_document (desktop), SP_VERB_CONTEXT_GRADIENT,
+                       _("Add gradient stop"));
 
     ec->get_drag()->updateDraggers();
 }
@@ -527,8 +530,8 @@ sp_gradient_context_root_handler(SPEventContext *event_context, GdkEvent *event)
                     sp_gradient_reset_to_userspace(priv, item);
                 }
 
-                sp_document_done (sp_desktop_document (desktop), SP_VERB_CONTEXT_GRADIENT,
-                                  _("Create default gradient"));
+                DocumentUndo::done(sp_desktop_document (desktop), SP_VERB_CONTEXT_GRADIENT,
+                                   _("Create default gradient"));
             }
             ret = TRUE;
         }
@@ -553,10 +556,10 @@ sp_gradient_context_root_handler(SPEventContext *event_context, GdkEvent *event)
                 if (!(event->button.state & GDK_CONTROL_MASK))
                     event_context->item_to_select = sp_event_context_find_item (desktop, button_w, event->button.state & GDK_MOD1_MASK, TRUE);
 
-                /* Snap center to nearest magnetic point */
                 SnapManager &m = desktop->namedview->snap_manager;
                 m.setup(desktop);
-                m.freeSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, button_dt);
+                m.freeSnapReturnByRef(button_dt, Inkscape::SNAPSOURCE_NODE_HANDLE);
+                m.unSetup();
                 rc->origin = from_2geom(button_dt);
             }
 
@@ -591,6 +594,17 @@ sp_gradient_context_root_handler(SPEventContext *event_context, GdkEvent *event)
 
             ret = TRUE;
         } else {
+            if (!drag->mouseOver()) {
+                SnapManager &m = desktop->namedview->snap_manager;
+                m.setup(desktop);
+
+                Geom::Point const motion_w(event->motion.x, event->motion.y);
+                Geom::Point const motion_dt = event_context->desktop->w2d(motion_w);
+
+                m.preSnap(Inkscape::SnapCandidatePoint(motion_dt, Inkscape::SNAPSOURCE_NODE_HANDLE));
+                m.unSetup();
+            }
+
             bool over_line = false;
             if (drag->lines) {
                 for (GSList *l = drag->lines; l != NULL; l = l->next) {
@@ -630,7 +644,7 @@ sp_gradient_context_root_handler(SPEventContext *event_context, GdkEvent *event)
             } else {
                 dragging = false;
 
-                // unless clicked with Ctrl (to enable Ctrl+doubleclick).  
+                // unless clicked with Ctrl (to enable Ctrl+doubleclick).
                 if (event->button.state & GDK_CONTROL_MASK) {
                     ret = TRUE;
                     break;
@@ -639,7 +653,7 @@ sp_gradient_context_root_handler(SPEventContext *event_context, GdkEvent *event)
                 if (!event_context->within_tolerance) {
                     // we've been dragging, either do nothing (grdrag handles that),
                     // or rubberband-select if we have rubberband
-                    Inkscape::Rubberband::Rubberband *r = Inkscape::Rubberband::get(desktop);
+                    Inkscape::Rubberband *r = Inkscape::Rubberband::get(desktop);
                     if (r->is_started() && !event_context->within_tolerance) {
                         // this was a rubberband drag
                         if (r->getMode() == RUBBERBAND_MODE_RECT) {
@@ -667,7 +681,7 @@ sp_gradient_context_root_handler(SPEventContext *event_context, GdkEvent *event)
                 event_context->item_to_select = NULL;
                 ret = TRUE;
             }
-            Inkscape::Rubberband::get(desktop)->stop(); 
+            Inkscape::Rubberband::get(desktop)->stop();
         }
         break;
     case GDK_KEY_PRESS:
@@ -801,8 +815,8 @@ sp_gradient_context_root_handler(SPEventContext *event_context, GdkEvent *event)
                     }
                 }
                 // we did an undoable action
-                sp_document_done (sp_desktop_document (desktop), SP_VERB_CONTEXT_GRADIENT,
-                                  _("Invert gradient"));
+                DocumentUndo::done(sp_desktop_document (desktop), SP_VERB_CONTEXT_GRADIENT,
+                                   _("Invert gradient"));
                 ret = TRUE;
             }
             break;
@@ -913,7 +927,7 @@ static void sp_gradient_drag(SPGradientContext &rc, Geom::Point const pt, guint
                                    -1, // ignore number (though it is always 1)
                                    fill_or_stroke, 99999, 99999, etime);
         }
-        // We did an undoable action, but sp_document_done will be called by the knot when released
+        // We did an undoable action, but SPDocumentUndo::done will be called by the knot when released
 
         // status text; we do not track coords because this branch is run once, not all the time
         // during drag
@@ -937,4 +951,4 @@ static void sp_gradient_drag(SPGradientContext &rc, Geom::Point const pt, guint
   fill-column:99
   End:
 */
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :