globally remove all trailing whitespace from ardour code base.
[ardour.git] / libs / canvas / canvas / canvas.h
index 616336409d49d55c27efa40d236b911808bdb54f..c812f8a869bd5cb4dcb5a0bada3749dab742ef22 100644 (file)
 
 #include "canvas/root_group.h"
 
+namespace Gtk {
+       class Window;
+       class Label;
+}
+
 namespace ArdourCanvas
 {
+struct Rect;
 
-class Rect;
-class Group;   
+class Item;
+class ScrollGroup;
 
 /** The base class for our different types of canvas.
  *
@@ -60,7 +66,7 @@ public:
        Canvas ();
        virtual ~Canvas () {}
 
-       /** called to request a redraw of an area of the canvas */
+       /** called to request a redraw of an area of the canvas in WINDOW coordinates */
        virtual void request_redraw (Rect const &) = 0;
        /** called to ask the canvas to request a particular size from its host */
        virtual void request_size (Duple) = 0;
@@ -77,10 +83,13 @@ public:
        void render (Rect const &, Cairo::RefPtr<Cairo::Context> const &) const;
 
        /** @return root group */
-       Group* root () {
+       Item* root () {
                return &_root;
        }
 
+        void set_background_color (ArdourCanvas::Color);
+        ArdourCanvas::Color background_color() const { return _bg_color; }
+
        /** Called when an item is being destroyed */
        virtual void item_going_away (Item *, boost::optional<Rect>) {}
        void item_shown_or_hidden (Item *);
@@ -88,11 +97,7 @@ public:
        void item_changed (Item *, boost::optional<Rect>);
        void item_moved (Item *, boost::optional<Rect>);
 
-        virtual Cairo::RefPtr<Cairo::Context> context () = 0;
-
-        Rect canvas_to_window (Rect const&) const;
-        Rect window_to_canvas (Rect const&) const;
-        Duple canvas_to_window (Duple const&) const;
+        Duple canvas_to_window (Duple const&, bool rounded = true) const;
         Duple window_to_canvas (Duple const&) const;
 
         void canvas_to_window (Coord cx, Coord cy, Coord& wx, Coord& wy) {
@@ -108,25 +113,58 @@ public:
         }
 
         void scroll_to (Coord x, Coord y);
-        virtual Rect visible_area () const = 0;
+       void add_scroller (ScrollGroup& i);
+
+        virtual Rect  visible_area () const = 0;
+        virtual Coord width () const = 0;
+        virtual Coord height () const = 0;
+
+       /** Store the coordinates of the mouse pointer in window coordinates in
+          @param winpos. Return true if the position was within the window,
+          false otherwise.
+       */
+       virtual bool get_mouse_position (Duple& winpos) const = 0;
+
+       /** Signal to be used by items that need to track the mouse position
+          within the window.
+       */
+       sigc::signal<void,Duple const&> MouseMotion;
+
+       /** Ensures that the position given by @param winpos (in window
+           coordinates) is within the current window area, possibly reduced by
+           @param border.
+       */
+       Duple clamp_to_window (Duple const& winpos, Duple border = Duple());
 
         void zoomed();
-    
+
         std::string indent() const;
         std::string render_indent() const;
         void dump (std::ostream&) const;
-    
-protected:
-       void queue_draw_item_area (Item *, Rect);
+
+       /** Ask the canvas to pick the current item again, and generate
+           an enter event for it.
+       */
+       virtual void re_enter () = 0;
+
+       virtual void start_tooltip_timeout (Item*) {}
+       virtual void stop_tooltip_timeout () {}
+
+       /** Set the timeout used to display tooltips, in milliseconds
+        */
+       static void set_tooltip_timeout (uint32_t msecs);
        
-       /** our root group */
-       RootGroup _root;
+protected:
+       Root  _root;
+        Color _bg_color;
 
-        Coord _scroll_offset_x;
-        Coord _scroll_offset_y;
+       static uint32_t tooltip_timeout_msecs;
 
+       void queue_draw_item_area (Item *, Rect);
         virtual void pick_current_item (int state) = 0;
         virtual void pick_current_item (Duple const &, int state) = 0;
+
+       std::list<ScrollGroup*> scrollers;
 };
 
 /** A canvas which renders onto a GTK EventBox */
@@ -142,12 +180,26 @@ public:
        void focus (Item *);
        void unfocus (Item*);
 
-       Cairo::RefPtr<Cairo::Context> context ();
-
        Rect visible_area () const;
+       Coord width() const;
+       Coord height() const;
+
+       bool get_mouse_position (Duple& winpos) const;
+
+       void set_single_exposure (bool s) { _single_exposure = s; }
+       bool single_exposure () { return _single_exposure; }
+
+       void re_enter ();
+
+       void start_tooltip_timeout (Item*);
+       void stop_tooltip_timeout ();
 
 protected:
+       void on_size_allocate (Gtk::Allocation&);
+       bool on_scroll_event (GdkEventScroll *);
        bool on_expose_event (GdkEventExpose *);
+       bool on_key_press_event (GdkEventKey *);
+       bool on_key_release_event (GdkEventKey *);
        bool on_button_press_event (GdkEventButton *);
        bool on_button_release_event (GdkEventButton* event);
        bool on_motion_notify_event (GdkEventMotion *);
@@ -158,7 +210,7 @@ protected:
        bool motion_notify_handler (GdkEventMotion *);
         bool deliver_event (GdkEvent *);
         void deliver_enter_leave (Duple const & point, int state);
-    
+
         void pick_current_item (int state);
         void pick_current_item (Duple const &, int state);
 
@@ -166,6 +218,8 @@ private:
        void item_going_away (Item *, boost::optional<Rect>);
        bool send_leave_event (Item const *, double, double) const;
 
+       Cairo::RefPtr<Cairo::Surface> canvas_image;
+
         /** Item currently chosen for event delivery based on pointer position */
         Item * _current_item;
         /** Item pending as _current_item */
@@ -174,10 +228,20 @@ private:
        Item * _grabbed_item;
         /** the item that currently has key focus or 0 */
        Item * _focused_item;
+       
+       bool _single_exposure;
+
+       sigc::connection tooltip_timeout_connection;
+       Item* current_tooltip_item;
+       Gtk::Window* tooltip_window;
+       Gtk::Label* tooltip_label;
+       bool show_tooltip ();
+       void hide_tooltip ();
+       bool really_start_tooltip_timeout ();
 };
 
 /** A GTK::Alignment with a GtkCanvas inside it plus some Gtk::Adjustments for
- *   scrolling. 
+ *   scrolling.
  *
  * This provides a GtkCanvas that can be scrolled. It does NOT implement the
  * Gtk::Scrollable interface.