change Metric element of a Canvas::Ruler item into a pointer internally
[ardour.git] / libs / canvas / canvas / item.h
index 5483c5124cc3cb4975048a930a575c367a854624..9b058ab83afd1d366d4b809899d04191ac07033b 100644 (file)
 
 #include "canvas/visibility.h"
 #include "canvas/types.h"
+#include "canvas/fill.h"
+#include "canvas/outline.h"
+#include "canvas/lookup_table.h"
 
 namespace ArdourCanvas
 {
+struct Rect;   
 
 class Canvas;
-class Group;
-class Rect;    
 class ScrollGroup;
 
 /** The parent class for anything that goes on the canvas.
@@ -50,12 +52,12 @@ class ScrollGroup;
  *  and all except the `root group' have a pointer to their parent group.
  */
        
-class LIBCANVAS_API Item
+class LIBCANVAS_API Item : public Fill, public Outline
 {
 public:
        Item (Canvas *);
-       Item (Group *);
-       Item (Group *, Duple);
+       Item (Item *);
+       Item (Item *, Duple const& p);
        virtual ~Item ();
 
         void redraw () const;
@@ -78,13 +80,11 @@ public:
         *
         * Note that Item::add_items_at_window_point() is only intended to be 
         * called on items already looked up in a LookupTable (i.e. by a
-        * parent group) and thus known to cover @param point already.
+        * parent) and thus known to cover @param point already.
         *
-        * Derived classes may add more items than themselves (e.g. Group).
+        * Derived classes may add more items than themselves (e.g. containers).
         */
-       virtual void add_items_at_point (Duple /*point*/, std::vector<Item const *>& items) const {
-               items.push_back (this);
-       }
+       virtual void add_items_at_point (Duple /*point*/, std::vector<Item const *>& items) const;
 
         virtual bool covers (Duple const &) const;
 
@@ -95,10 +95,10 @@ public:
        void ungrab ();
        
        void unparent ();
-       void reparent (Group *);
+       void reparent (Item *);
 
        /** @return Parent group, or 0 if this is the root group */
-       Group* parent () const {
+       Item* parent () const {
                return _parent;
        }
     
@@ -122,14 +122,13 @@ public:
        void set_y_position (Coord);
        void move (Duple);
 
-       virtual void scroll_to (Duple const&) {}
-
        /** @return Position of this item in the parent's coordinates */
        Duple position () const {
                return _position;
        }
 
        Duple window_origin() const;
+       Duple canvas_origin() const;
 
        ScrollGroup* scroll_parent() const { return _scroll_parent; }
 
@@ -148,6 +147,11 @@ public:
         void canvas_to_item (Coord &, Coord &) const;
        void item_to_canvas (Coord &, Coord &) const;
 
+        Duple canvas_to_item (Duple const&) const;
+       Rect item_to_canvas (Rect const&) const;
+        Duple item_to_canvas (Duple const&) const;
+       Rect canvas_to_item (Rect const&) const;
+
         Duple item_to_window (Duple const&, bool rounded = true) const;
         Duple window_to_item (Duple const&) const;
         Rect item_to_window (Rect const&) const;
@@ -179,6 +183,21 @@ public:
 
        void set_data (std::string const &, void *);
        void* get_data (std::string const &) const;
+
+       /* nested item ("grouping") API */
+       void add (Item *);
+       void remove (Item *);
+        void clear (bool with_delete = false);
+       std::list<Item*> const & items () const {
+               return _items;
+       }
+       void raise_child_to_top (Item *);
+       void raise_child (Item *, int);
+       void lower_child_to_bottom (Item *);
+       void child_changed ();
+
+       static int default_items_per_cell;
+
        
        /* This is a sigc++ signal because it is solely
           concerned with GUI stuff and is thus single-threaded
@@ -213,6 +232,8 @@ public:
         std::string whatami() const;
 
 protected:
+       friend class Fill;
+       friend class Outline;
 
         /** To be called at the beginning of any property change that
         *  may alter the bounding box of this item
@@ -233,7 +254,7 @@ protected:
 
        Canvas* _canvas;
        /** parent group; may be 0 if we are the root group or if we have been unparent()ed */
-       Group* _parent;
+       Item* _parent;
        /** scroll parent group; may be 0 if we are the root group or if we have been unparent()ed */
        ScrollGroup* _scroll_parent;
        /** position of this item in parent coordinates */
@@ -251,6 +272,19 @@ protected:
        /* XXX: this is a bit grubby */
        std::map<std::string, void *> _data;
 
+       /* nesting ("grouping") API */
+
+       void invalidate_lut () const;
+       void clear_items (bool with_delete);
+
+       void ensure_lut () const;
+       mutable LookupTable* _lut;
+       /* our items, from lowest to highest in the stack */
+       std::list<Item*> _items;
+
+       void add_child_bounding_boxes() const;
+       void render_children (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const;
+
 private:
        void init ();