2 cleanup patches from nickm, plus work on mixer_ui.cc so that it compiles
[ardour.git] / gtk2_ardour / editor_edit_groups.cc
1 /*
2     Copyright (C) 2000 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     $Id$
19 */
20
21 #include <cstdlib>
22 #include <cmath>
23
24 #include <gtkmm2ext/stop_signal.h>
25 #include <ardour/route_group.h>
26
27 #include "editor.h"
28 #include "keyboard.h"
29 #include "marker.h"
30 #include "time_axis_view.h"
31 #include "prompter.h"
32
33 #include <ardour/route.h>
34
35 #include "i18n.h"
36
37 using namespace sigc;
38 using namespace ARDOUR;
39 using namespace Gtk;
40
41 void
42 Editor::edit_group_list_column_click (gint col)
43
44 {
45         if (edit_group_list_menu == 0) {
46                 build_edit_group_list_menu ();
47         }
48
49         edit_group_list_menu->popup (0, 0);
50 }
51
52 void
53 Editor::build_edit_group_list_menu ()
54
55 {
56         using namespace Gtk::Menu_Helpers;
57
58         edit_group_list_menu = new Menu;
59         edit_group_list_menu->set_name ("ArdourContextMenu");
60         MenuList& items = edit_group_list_menu->items();
61
62         items.push_back (MenuElem (_("Show All"), mem_fun(*this, &Editor::select_all_edit_groups)));
63         items.push_back (MenuElem (_("Hide All"), mem_fun(*this, &Editor::unselect_all_edit_groups)));
64 }
65
66 void
67 Editor::unselect_all_edit_groups ()
68
69 {
70 }
71
72 void
73 Editor::select_all_edit_groups ()
74
75 {
76         CList_Helpers::RowList::iterator i;
77
78         /* XXX potential race with remove_track(), but the select operation
79            cannot be done with the track_lock held.
80         */
81
82         for (i = route_list.rows().begin(); i != route_list.rows().end(); ++i) {
83                 i->select ();
84         }
85 }
86
87 void
88 Editor::new_edit_group ()
89
90 {
91         if (session == 0) {
92                 return;
93         }
94
95         ArdourPrompter prompter;
96         string result;
97
98         prompter.set_prompt (_("Name for new edit group"));
99         prompter.done.connect (Gtk::Main::quit.slot());
100
101         prompter.show_all ();
102         
103         Gtk::Main::run ();
104         
105         if (prompter.status != Gtkmm2ext::Prompter::entered) {
106                 return;
107         }
108         
109         prompter.get_result (result);
110
111         if (result.length()) {
112                 session->add_edit_group (result);
113         }
114 }
115
116 void
117 Editor::edit_group_list_button_clicked ()
118 {
119         new_edit_group ();
120 }
121
122 gint
123 Editor::edit_group_list_button_press_event (GdkEventButton* ev)
124 {
125         gint row, col;
126
127         if (edit_group_list.get_selection_info ((int)ev->x, (int)ev->y, &row, &col) == 0) {
128                 return FALSE;
129         }
130
131         if (col == 1) {
132
133                 if (Keyboard::is_edit_event (ev)) {
134                         // RouteGroup* group = (RouteGroup *) edit_group_list.row(row).get_data ();
135                         // edit_route_group (group);
136
137                         return stop_signal (edit_group_list, "button_press_event");
138
139                 } else {
140                         /* allow regular select to occur */
141                         return FALSE;
142                 }
143
144         } else if (col == 0) {
145
146                 RouteGroup* group = reinterpret_cast<RouteGroup *>(edit_group_list.row(row).get_data ());
147
148                 if (group) {
149                         group->set_active (!group->is_active(), this);
150                 }
151         }
152         
153         return stop_signal (edit_group_list, "button_press_event");
154 }
155
156 void
157 Editor::edit_group_selected (gint row, gint col, GdkEvent* ev)
158 {
159         RouteGroup* group = (RouteGroup *) edit_group_list.row(row).get_data ();
160
161         for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
162                 if ((*i)->edit_group() == group) {
163                         select_strip_in_display (*(*i));
164                 }
165         }
166 }
167
168 void
169 Editor::edit_group_unselected (gint row, gint col, GdkEvent* ev)
170 {
171         RouteGroup* group = (RouteGroup *) edit_group_list.row(row).get_data ();
172
173         for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
174                 if ((*i)->edit_group() == group) {
175                         unselect_strip_in_display (*(*i));
176                 }
177         }
178 }
179
180 void
181 Editor::add_edit_group (RouteGroup* group)
182 {
183         list<string> names;
184
185         names.push_back ("*");
186         names.push_back (group->name());
187
188         edit_group_list.rows().push_back (names);
189         edit_group_list.rows().back().set_data (group);
190         edit_group_list.rows().back().select();
191
192         group->FlagsChanged.connect (bind (mem_fun(*this, &Editor::group_flags_changed), group));
193 }
194
195 void
196 Editor::group_flags_changed (void* src, RouteGroup* group)
197 {
198         if (src != this) {
199                 // select row
200         }
201
202         CList_Helpers::RowIterator ri = edit_group_list.rows().find_data (group);
203
204         if (group->is_active()) {
205                 edit_group_list.cell (ri->get_row_num(),0).set_pixmap (check_pixmap, check_mask);
206         } else {
207                 edit_group_list.cell (ri->get_row_num(),0).set_pixmap (empty_pixmap, empty_mask);
208         }
209 }
210