e31ad9643e519d7d880f7d13ca419c9b6ec7da4d
[ardour.git] / gtk2_ardour / group_tabs.h
1 /*
2     Copyright (C) 2009 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <gtkmm/menu.h>
21 #include "editor_component.h"
22 #include "gtkmm2ext/cairo_widget.h"
23
24 namespace ARDOUR {
25         class Session;
26         class RouteGroup;
27 }
28
29 class Editor;
30
31 /** Parent class for tabs which represent route groups as colored tabs;
32  *  Currently used on the left-hand side of the editor and at the top of the mixer.
33  *
34  *  This class also contains a fair bit of code to handle changes to route
35  *  group colours; it seems a bit out of place, but I could not really think
36  *  of a better place to put it.
37  */
38 class GroupTabs : public CairoWidget, public ARDOUR::SessionHandlePtr
39 {
40 public:
41         GroupTabs ();
42         virtual ~GroupTabs ();
43
44         void set_session (ARDOUR::Session *);
45
46         /** @param g Route group, or 0.
47          *  @return Menu to be popped up on right-click over the given route group.
48          */
49         Gtk::Menu* get_menu (ARDOUR::RouteGroup* g, bool tabArea = false);
50
51         void run_new_group_dialog (ARDOUR::RouteList const &);
52
53         static void set_group_color (ARDOUR::RouteGroup *, uint32_t);
54         static std::string group_gui_id (ARDOUR::RouteGroup *);
55         static uint32_t group_color (ARDOUR::RouteGroup *);
56
57 protected:
58
59         struct Tab {
60                 Tab () : group (0) {}
61
62                 double from;
63                 double to;
64                 uint32_t color; ///< color
65                 ARDOUR::RouteGroup* group; ///< route group
66         };
67
68 private:
69         static void emit_gui_changed_for_members (ARDOUR::RouteGroup *);
70
71         /** Compute all the tabs for this widget.
72          *  @return Tabs.
73          */
74         virtual std::list<Tab> compute_tabs () const = 0;
75
76         /** Draw a tab.
77          *  @param cr Cairo context.
78          *  @param t Tab.
79          */
80         virtual void draw_tab (cairo_t* cr, Tab const & t) const = 0;
81
82         /** @param x x coordinate
83          *  @param y y coordinate
84          *  @return x or y, depending on which is the primary coordinate for this widget.
85          */
86         virtual double primary_coordinate (double, double) const = 0;
87
88         virtual ARDOUR::RouteList routes_for_tab (Tab const * t) const = 0;
89
90         /** @return Size of the widget along the primary axis */
91         virtual double extent () const = 0;
92
93         virtual void add_menu_items (Gtk::Menu *, ARDOUR::RouteGroup *) {}
94         virtual ARDOUR::RouteList selected_routes () const = 0;
95         virtual void sync_order_keys () = 0;
96
97         void new_from_selection ();
98         void new_from_rec_enabled ();
99         void new_from_soloed ();
100         ARDOUR::RouteGroup* create_and_add_group () const;
101         void collect (ARDOUR::RouteGroup *);
102         void set_activation (ARDOUR::RouteGroup *, bool);
103         void edit_group (ARDOUR::RouteGroup *);
104         void subgroup (ARDOUR::RouteGroup *, bool, ARDOUR::Placement);
105         void un_subgroup (ARDOUR::RouteGroup *);
106         void activate_all ();
107         void disable_all ();
108         void remove_group (ARDOUR::RouteGroup *);
109
110         void render (cairo_t *, cairo_rectangle_t*);
111         void on_size_request (Gtk::Requisition *);
112         bool on_button_press_event (GdkEventButton *);
113         bool on_motion_notify_event (GdkEventMotion *);
114         bool on_button_release_event (GdkEventButton *);
115
116         Tab * click_to_tab (double, std::list<Tab>::iterator *, std::list<Tab>::iterator *);
117
118         void route_group_property_changed (ARDOUR::RouteGroup *);
119         void route_added_to_route_group (ARDOUR::RouteGroup *, boost::weak_ptr<ARDOUR::Route>);
120         void route_removed_from_route_group (ARDOUR::RouteGroup *, boost::weak_ptr<ARDOUR::Route>);
121
122         Gtk::Menu* _menu;
123         std::list<Tab> _tabs; ///< current list of tabs
124         Tab* _dragging; ///< tab being dragged, or 0
125         /** routes that were in the tab that is being dragged when the drag started */
126         ARDOUR::RouteList _initial_dragging_routes;
127         bool _dragging_new_tab; ///< true if we're dragging a new tab
128         bool _drag_moved; ///< true if there has been movement during any current drag
129         double _drag_fixed; ///< the position of the fixed end of the tab being dragged
130         double _drag_moving; ///< the position of the moving end of the tab being dragged
131         double _drag_offset; ///< offset from the mouse to the end of the tab being dragged
132         double _drag_min; ///< minimum position for drag
133         double _drag_max; ///< maximum position for drag
134         double _drag_first; ///< first mouse pointer position during drag
135
136         /** colors that have been used for new route group tabs */
137         static std::list<Gdk::Color> _used_colors;
138 };