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