Code

Patch from codedread. Prevents rendering of title/desc/metadata elements in text...
[inkscape.git] / src / gradient-drag.h
index 72e9ce0dd5a31d30d6b87f4ad8becf0306edaf03..ed0887e9810ab2ab4c8b6272ef5ac0f78c6ddcee 100644 (file)
@@ -6,7 +6,9 @@
  *
  * Authors:
  *   bulia byak <bulia@users.sf.net>
+ *   Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
  *
+ * Copyright (C) 2007 Johan Engelen
  * Copyright (C) 2005 Authors
  *
  * Released under GNU GPL, read the file 'COPYING' for more information
 #include <vector>
 
 #include <forward.h>
+#include <libnr/nr-forward.h>
 #include <knot-enums.h>
 
 struct SPItem;
 struct SPKnot;
-namespace NR {
-class Point;
-}
 
 /**
 This class represents a single draggable point of a gradient. It remembers the item
@@ -32,13 +32,15 @@ GrPointType enum), and the point number (needed if more than 2 stops are present
 */
 struct GrDraggable {
        GrDraggable(SPItem *item, guint point_type, guint point_i, bool fill_or_stroke);
-       ~GrDraggable();
+    virtual ~GrDraggable();
 
        SPItem *item;
-       guint point_type;
-       guint point_i;  // the stop number of this point ( = 0 for all types except POINT_LG_MID)
+       gint point_type;
+       gint point_i;  // the stop number of this point ( = 0 POINT_LG_BEGIN and POINT_RG_CENTER)
        bool fill_or_stroke;
 
+       SPObject *getServer();
+
        bool mayMerge (GrDraggable *da2);
 
     inline int equals (GrDraggable *other) {
@@ -46,7 +48,7 @@ struct GrDraggable {
     }
 };
 
-struct GrDrag;
+class GrDrag;
 
 /**
 This class holds together a visible on-canvas knot and a list of draggables that need to
@@ -55,7 +57,7 @@ be more when draggers are snapped together.
 */
 struct GrDragger {
        GrDragger (GrDrag *parent, NR::Point p, GrDraggable *draggable);
-       ~GrDragger();
+    virtual ~GrDragger();
 
        GrDrag *parent;
 
@@ -75,16 +77,22 @@ struct GrDragger {
 
        void updateKnotShape();
        void updateTip();
+       
+       void select();
+       void deselect();
+       bool isSelected();
 
-       void moveThisToDraggable (SPItem *item, guint point_type, guint point_i, bool fill_or_stroke, bool write_repr);
-       void moveOtherToDraggable (SPItem *item, guint point_type, guint point_i, bool fill_or_stroke, bool write_repr);
-       void updateDependencies (bool write_repr);
+       void moveThisToDraggable (SPItem *item, gint point_type, gint point_i, bool fill_or_stroke, bool write_repr);
+       void moveOtherToDraggable (SPItem *item, gint point_type, gint point_i, bool fill_or_stroke, bool write_repr);
+    void updateMidstopDependencies (GrDraggable *draggable, bool write_repr);
+    void updateDependencies (bool write_repr);
 
        bool mayMerge (GrDragger *other);
        bool mayMerge (GrDraggable *da2);
 
-       bool isA (guint point_type);
-       bool isA (SPItem *item, guint point_type, guint point_i, bool fill_or_stroke);
+    bool isA (gint point_type);
+    bool isA (SPItem *item, gint point_type, bool fill_or_stroke);
+    bool isA (SPItem *item, gint point_type, gint point_i, bool fill_or_stroke);
 
        void fireDraggables (bool write_repr, bool scale_radial = false, bool merging_focus = false);
 };
@@ -93,52 +101,83 @@ struct GrDragger {
 This is the root class of the gradient dragging machinery. It holds lists of GrDraggers
 and of lines (simple canvas items). It also remembers one of the draggers as selected.
 */
-struct GrDrag {
-       GrDrag(SPDesktop *desktop);
-       ~GrDrag();
+class GrDrag {
+public: // FIXME: make more of this private!
+
+    GrDrag(SPDesktop *desktop);
+    virtual ~GrDrag();
+
+               bool isNonEmpty() {return (draggers != NULL);}
+               bool hasSelection() {return (selected != NULL);}
+               guint numSelected() {return (selected? g_list_length(selected) : 0);}
+               guint numDraggers() {return (draggers? g_list_length(draggers) : 0);}
+               guint singleSelectedDraggerNumDraggables() {return (selected? g_slist_length(((GrDragger *) selected->data)->draggables) : 0);}
+               guint singleSelectedDraggerSingleDraggableType() {return (selected? ((GrDraggable *) ((GrDragger *) selected->data)->draggables->data)->point_type : 0);}
+
+    // especially the selection must be private, fix gradient-context to remove direct access to it
+    GList *selected; // list of GrDragger*
+    void setSelected (GrDragger *dragger, bool add_to_selection = false, bool override = true);
+    void setDeselected (GrDragger *dragger);
+    void deselectAll();
+               void selectAll();
+               void selectByCoords(std::vector<NR::Point> coords);
+    void selectRect(NR::Rect const &r);
+
+    bool dropColor(SPItem *item, gchar *c, NR::Point p);
+
+               SPStop *addStopNearPoint (SPItem *item, NR::Point mouse_p, double tolerance);
+    
+    void deleteSelected (bool just_one = false);
+
+    guint32 getColor();
+    
+    bool keep_selection;    
+    
+    GrDragger *getDraggerFor (SPItem *item, gint point_type, gint point_i, bool fill_or_stroke);
 
-       void addLine (NR::Point p1, NR::Point p2, guint32 rgba);
+    void grabKnot (GrDragger *dragger, gint x, gint y, guint32 etime);
+    void grabKnot (SPItem *item, gint point_type, gint point_i, bool fill_or_stroke, gint x, gint y, guint32 etime);
 
-       void addDragger (GrDraggable *draggable);
+    bool local_change;
 
-       void addDraggersRadial (SPRadialGradient *rg, SPItem *item, bool fill_or_stroke);
-       void addDraggersLinear (SPLinearGradient *lg, SPItem *item, bool fill_or_stroke);
+    SPDesktop *desktop;
 
-       GrDragger *selected;
-       void setSelected (GrDragger *dragger);
+    // lists of edges of selection bboxes, to snap draggers to
+    std::vector<double> hor_levels;
+    std::vector<double> vert_levels;
 
-       GrDragger *getDraggerFor (SPItem *item, guint point_type, guint point_i, bool fill_or_stroke);
+    GList *draggers;
+    GSList *lines;
 
-       void grabKnot (SPItem *item, guint point_type, guint point_i, bool fill_or_stroke, gint x, gint y, guint32 etime);
+    void updateDraggers ();
+    void updateLines ();
+    void updateLevels ();
 
-       bool local_change;
+    void selected_move_nowrite (double x, double y, bool scale_radial);
+    void selected_move (double x, double y, bool write_repr = true, bool scale_radial = false);
+    void selected_move_screen (double x, double y);
 
-       SPDesktop *desktop;
-       Inkscape::Selection *selection;
-       sigc::connection sel_changed_connection;
-       sigc::connection sel_modified_connection;
+    GrDragger *select_next ();
+    GrDragger *select_prev ();
 
-       sigc::connection style_set_connection;
-       sigc::connection style_query_connection;
+    void selected_reverse_vector ();
 
-       // lists of edges of selection bboxes, to snap draggers to
-       std::vector<double> hor_levels;
-       std::vector<double> vert_levels;
+private: 
+    void deselect_all();
 
-       GList *draggers;
-       GSList *lines;
+    void addLine (SPItem *item, NR::Point p1, NR::Point p2, guint32 rgba);
 
-       void updateDraggers ();
-       void updateLines ();
-       void updateLevels ();
+    void addDragger (GrDraggable *draggable);
 
-       void selected_move (double x, double y);
-       void selected_move_screen (double x, double y);
+    void addDraggersRadial (SPRadialGradient *rg, SPItem *item, bool fill_or_stroke);
+    void addDraggersLinear (SPLinearGradient *lg, SPItem *item, bool fill_or_stroke);
 
-       void select_next ();
-       void select_prev ();
+    Inkscape::Selection *selection;
+    sigc::connection sel_changed_connection;
+    sigc::connection sel_modified_connection;
 
-       void selected_reverse_vector ();
+    sigc::connection style_set_connection;
+    sigc::connection style_query_connection;
 };
 
 #endif