Code

Indent support for XSLT extensions output.
[inkscape.git] / src / selection.h
index 407854406e32bb023d179bc8ae5e581c778fce64..9ac49ae12c698ec51c9427b00cd57734038c597e 100644 (file)
  */
 
 #include <vector>
+#include <map>
+#include <list>
 #include <sigc++/sigc++.h>
 
-#include "libnr/nr-rect.h"
+//#include "libnr/nr-rect.h"
 #include "libnr/nr-convex-hull.h"
 #include "forward.h"
 #include "gc-managed.h"
 #include "gc-finalized.h"
 #include "gc-anchored.h"
+#include "gc-soft-ptr.h"
 #include "util/list.h"
+#include "sp-item.h"
+#include "snapped-point.h"
 
 class SPItem;
+class SPBox3D;
+class Persp3D;
 
 namespace Inkscape {
 namespace XML {
@@ -51,7 +58,7 @@ namespace Inkscape {
  * at the given desktop. Both SPItem and SPRepr lists can be retrieved
  * from the selection. Many actions operate on the selection, so it is
  * widely used throughout the code.
- * It also implements its own asynchronous notification signals that 
+ * It also implements its own asynchronous notification signals that
  * UI elements can listen to.
  */
 class Selection : public Inkscape::GC::Managed<>,
@@ -69,18 +76,25 @@ public:
     ~Selection();
 
     /**
-     * @brief Returns the desktop the seoection is bound to
+     * @brief Returns the desktop the selection is bound to
      *
      * @return the desktop the selection is bound to
      */
     SPDesktop *desktop() { return _desktop; }
 
+    /**
+     * @brief Returns active layer for selection (currentLayer or its parent)
+     *
+     * @return layer item the selection is bound to
+     */
+    SPObject *activeContext();
+
     /**
      * @brief Add an SPObject to the set of selected objects
      *
      * @param obj the SPObject to add
      */
-    void add(SPObject *obj);
+    void add(SPObject *obj, bool persist_selection_context = false);
 
     /**
      * @brief Add an XML node's SPObject to the set of selected objects
@@ -94,7 +108,7 @@ public:
      *
      * @param obj the object to select
      */
-    void set(SPObject *obj);
+    void set(SPObject *obj, bool persist_selection_context = false);
 
     /**
      * @brief Set the selection to an XML node's SPObject
@@ -215,45 +229,58 @@ public:
     ///      method for that
     GSList const *reprList();
 
+    /** @brief Returns a list of all perspectives which have a 3D box in the current selection
+       (these may also be nested in groups) */
+    std::list<Persp3D *> const perspList();
+
+    /** @brief Returns a list of all 3D boxes in the current selection which are associated to @c
+       persp. If @c pers is @c NULL, return all selected boxes.
+    */
+    std::list<SPBox3D *> const box3DList(Persp3D *persp = NULL);
+
     /** @brief Returns the number of layers in which there are selected objects */
     guint numberOfLayers();
 
+    /** @brief Returns the number of parents to which the selected objects belong */
+    guint numberOfParents();
+
     /** @brief Returns the bounding rectangle of the selection */
-    NRRect *bounds(NRRect *dest) const;
+    NRRect *bounds(NRRect *dest, SPItem::BBoxType type = SPItem::APPROXIMATE_BBOX) const;
     /** @brief Returns the bounding rectangle of the selection */
-    ::NR::Rect bounds() const;
+    Geom::OptRect bounds(SPItem::BBoxType type = SPItem::APPROXIMATE_BBOX) const;
 
     /**
      * @brief Returns the bounding rectangle of the selection
      *
-     * \todo how is this different from bounds()?
-     */ 
-    NRRect *boundsInDocument(NRRect *dest) const;
+     * Gives the coordinates in internal format, does not match onscreen guides.
+     * (0,0 is the upper left corner, not the lower left corner)
+     */
+    NRRect *boundsInDocument(NRRect *dest, SPItem::BBoxType type = SPItem::APPROXIMATE_BBOX) const;
 
     /**
      * @brief Returns the bounding rectangle of the selection
      *
-     * \todo how is this different from bounds()?
+     * Gives the coordinates in internal format, does not match onscreen guides.
+     * (0,0 is the upper left corner, not the lower left corner)
      */
-    ::NR::Rect boundsInDocument() const;
+    Geom::OptRect boundsInDocument(SPItem::BBoxType type = SPItem::APPROXIMATE_BBOX) const;
+
+    /**
+     * @brief Returns the rotation/skew center of the selection
+     */
+    boost::optional<Geom::Point> center() const;
 
     /**
      * @brief Gets the selection's snap points.
      * @return Selection's snap points
      */
-    std::vector<NR::Point> getSnapPoints() const;
+    std::vector<Inkscape::SnapCandidatePoint> getSnapPoints(SnapPreferences const *snapprefs) const;
 
     /**
      * @brief Gets the snap points of a selection that form a convex hull.
      * @return Selection's convex hull points
      */
-    std::vector<NR::Point> getSnapPointsConvexHull() const;
-
-    /**
-     * @return A vector containing the top-left and bottom-right
-     * corners of each selected object's bounding box.
-     */
-    std::vector<NR::Point> getBBoxPoints() const;
+    std::vector<Inkscape::SnapCandidatePoint> getSnapPointsConvexHull(SnapPreferences const *snapprefs) const;
 
     /**
      * @brief Connects a slot to be notified of selection changes
@@ -270,8 +297,8 @@ public:
     }
 
     /**
-     * @brief Connects a slot to be notified of selected 
-     *        object modifications 
+     * @brief Connects a slot to be notified of selected
+     *        object modifications
      *
      * This method connects the given slot such that it will
      * receive notifications whenever any selected item is
@@ -296,14 +323,12 @@ private:
     /** @brief Issues modification notification signals */
     static gboolean _emit_modified(Selection *selection);
     /** @brief Schedules an item modification signal to be sent */
-    static void _schedule_modified(SPObject *obj, guint flags, Selection *selection);
-    /** @brief Releases a selected object that is being removed */
-    static void _release(SPObject *obj, Selection *selection);
+    void _schedule_modified(SPObject *obj, guint flags);
 
     /** @brief Issues modified selection signal */
     void _emitModified(guint flags);
     /** @brief Issues changed selection signal */
-    void _emitChanged();
+    void _emitChanged(bool persist_selection_context = false);
 
     void _invalidateCachedLists();
 
@@ -319,15 +344,29 @@ private:
     void _remove(SPObject *obj);
     /** @brief returns the SPObject corresponding to an xml node (if any) */
     SPObject *_objectForXMLNode(XML::Node *repr) const;
+    /** @brief Releases an active layer object that is being removed */
+    void _releaseContext(SPObject *obj);
 
     mutable GSList *_objs;
     mutable GSList *_reprs;
     mutable GSList *_items;
 
-    SPDesktop *_desktop;
+    void add_box_perspective(SPBox3D *box);
+    void add_3D_boxes_recursively(SPObject *obj);
+    void remove_box_perspective(SPBox3D *box);
+    void remove_3D_boxes_recursively(SPObject *obj);
+
+    std::list<SPBox3D *> _3dboxes;
+
+    GC::soft_ptr<SPDesktop> _desktop;
+    SPObject* _selection_context;
     guint _flags;
     guint _idle;
 
+    std::map<SPObject *, sigc::connection> _modified_connections;
+    std::map<SPObject *, sigc::connection> _release_connections;
+    sigc::connection _context_release_connection;
+
     sigc::signal<void, Selection *> _changed_signal;
     sigc::signal<void, Selection *, guint> _modified_signal;
 };
@@ -344,4 +383,4 @@ private:
   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 :