Remove most using declarations from header files.
[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 */
19
20 #include <cstdlib>
21 #include <cmath>
22
23 #include <gtkmm2ext/stop_signal.h>
24 #include <gtkmm2ext/gtk_ui.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 #include "gui_thread.h"
33
34 #include "ardour/route.h"
35
36 #include "i18n.h"
37
38 using namespace std;
39 using namespace sigc;
40 using namespace ARDOUR;
41 using namespace PBD;
42 using namespace Gtk;
43
44 void
45 Editor::build_edit_group_list_menu ()
46 {
47         using namespace Gtk::Menu_Helpers;
48
49         edit_group_list_menu = new Menu;
50         edit_group_list_menu->set_name ("ArdourContextMenu");
51         MenuList& items = edit_group_list_menu->items();
52
53         items.push_back (MenuElem (_("Activate All"), mem_fun(*this, &Editor::activate_all_edit_groups)));
54         items.push_back (MenuElem (_("Disable All"), mem_fun(*this, &Editor::disable_all_edit_groups)));
55         items.push_back (SeparatorElem());
56         items.push_back (MenuElem (_("Add group"), mem_fun(*this, &Editor::new_edit_group)));
57         
58 }
59
60 void
61 Editor::activate_all_edit_groups ()
62 {
63         Gtk::TreeModel::Children children = group_model->children();
64         for(Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter) {
65                 (*iter)[group_columns.is_active] = true;
66         }
67 }
68
69 void
70 Editor::disable_all_edit_groups ()
71 {
72         Gtk::TreeModel::Children children = group_model->children();
73         for(Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter) {
74                 (*iter)[group_columns.is_active] = false;
75         }
76 }
77
78 void
79 Editor::new_edit_group ()
80 {
81         session->add_edit_group ("");
82 }
83
84 void
85 Editor::remove_selected_edit_group ()
86 {
87         Glib::RefPtr<TreeSelection> selection = edit_group_display.get_selection();
88         TreeView::Selection::ListHandle_Path rows = selection->get_selected_rows ();
89
90         if (rows.empty()) {
91                 return;
92         }
93
94         TreeView::Selection::ListHandle_Path::iterator i = rows.begin();
95         TreeIter iter;
96         
97         /* selection mode is single, so rows.begin() is it */
98
99         if ((iter = group_model->get_iter (*i))) {
100
101                 RouteGroup* rg = (*iter)[group_columns.routegroup];
102
103                 if (rg) {
104                         session->remove_edit_group (*rg);
105                 }
106         }
107 }
108
109 void
110 Editor::edit_group_list_button_clicked ()
111 {
112         new_edit_group ();
113 }
114
115 gint
116 Editor::edit_group_list_button_press_event (GdkEventButton* ev)
117 {
118         if (Keyboard::is_context_menu_event (ev)) {
119                 if (edit_group_list_menu == 0) {
120                         build_edit_group_list_menu ();
121                 }
122                 edit_group_list_menu->popup (1, ev->time);
123                 return true;
124         }
125
126
127         RouteGroup* group;
128         TreeIter iter;
129         TreeModel::Path path;
130         TreeViewColumn* column;
131         int cellx;
132         int celly;
133
134         if (!edit_group_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
135                 return false;
136         }
137
138         switch (GPOINTER_TO_UINT (column->get_data (X_("colnum")))) {
139         case 0:
140                 if (Keyboard::is_edit_event (ev)) {
141                         if ((iter = group_model->get_iter (path))) {
142                                 if ((group = (*iter)[group_columns.routegroup]) != 0) {
143                                         // edit_route_group (group);
144 #ifdef GTKOSX
145                                         edit_group_display.queue_draw();
146 #endif
147                                         return true;
148                                 }
149                         }
150                         
151                 } 
152                 break;
153
154         case 1:
155                 if ((iter = group_model->get_iter (path))) {
156                         bool active = (*iter)[group_columns.is_active];
157                         (*iter)[group_columns.is_active] = !active;
158 #ifdef GTKOSX
159                         edit_group_display.queue_draw();
160 #endif
161                         return true;
162                 }
163                 break;
164                 
165         case 2:
166                 if ((iter = group_model->get_iter (path))) {
167                         bool visible = (*iter)[group_columns.is_visible];
168                         (*iter)[group_columns.is_visible] = !visible;
169 #ifdef GTKOSX
170                         edit_group_display.queue_draw();
171 #endif
172                         return true;
173                 }
174                 break;
175
176         default:
177                 break;
178         }
179         
180         return false;
181  }
182
183 void 
184 Editor::edit_group_row_change (const Gtk::TreeModel::Path& path,const Gtk::TreeModel::iterator& iter)
185 {
186         RouteGroup* group;
187
188         if (in_edit_group_row_change) {
189                 return;
190         }
191
192         if ((group = (*iter)[group_columns.routegroup]) == 0) {
193                 return;
194         }
195
196         if ((*iter)[group_columns.is_visible]) {
197                 for (TrackViewList::iterator j = track_views.begin(); j != track_views.end(); ++j) {
198                         if ((*j)->edit_group() == group) {
199                                 show_track_in_display (**j);
200                         }
201                 }
202         } else {
203                 for (TrackViewList::iterator j = track_views.begin(); j != track_views.end(); ++j) {
204                         if ((*j)->edit_group() == group) {
205                                 hide_track_in_display (**j);
206                         }
207                 }
208         }
209
210         bool active = (*iter)[group_columns.is_active];
211         group->set_active (active, this);
212
213
214         string name = (*iter)[group_columns.text];
215
216         if (name != group->name()) {
217                 group->set_name (name);
218         }
219 }
220
221 void
222 Editor::add_edit_group (RouteGroup* group)
223 {
224         ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::add_edit_group), group));
225         bool focus = false;
226
227         TreeModel::Row row = *(group_model->append());
228         row[group_columns.is_active] = group->is_active();
229         row[group_columns.is_visible] = !group->is_hidden();
230
231         in_edit_group_row_change = true;
232
233         row[group_columns.routegroup] = group;
234
235         if (!group->name().empty()) {
236                 row[group_columns.text] = group->name();
237         } else {
238                 row[group_columns.text] = _("unnamed");
239                 focus = true;
240         }
241
242         group->FlagsChanged.connect (bind (mem_fun(*this, &Editor::group_flags_changed), group));
243
244         if (focus) {
245                 TreeViewColumn* col = edit_group_display.get_column (0);
246                 CellRendererText* name_cell = dynamic_cast<CellRendererText*>(edit_group_display.get_column_cell_renderer (0));
247                 edit_group_display.set_cursor (group_model->get_path (row), *col, *name_cell, true);
248         }
249
250         in_edit_group_row_change = false;
251 }
252
253 void
254 Editor::edit_groups_changed ()
255 {
256         ENSURE_GUI_THREAD (mem_fun (*this, &Editor::edit_groups_changed));
257
258         /* just rebuild the while thing */
259
260         group_model->clear ();
261
262         {
263                 TreeModel::Row row;
264                 row = *(group_model->append());
265                 row[group_columns.is_active] = false;
266                 row[group_columns.is_visible] = true;
267                 row[group_columns.text] = (_("-all-"));
268                 row[group_columns.routegroup] = 0;
269         }
270
271         session->foreach_edit_group (mem_fun (*this, &Editor::add_edit_group));
272 }
273
274 void
275 Editor::group_flags_changed (void* src, RouteGroup* group)
276 {
277         ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::group_flags_changed), src, group));
278
279         in_edit_group_row_change = true;
280
281         Gtk::TreeModel::Children children = group_model->children();
282         for(Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter) {
283                 if (group == (*iter)[group_columns.routegroup]) {
284                         (*iter)[group_columns.is_active] = group->is_active();
285                         (*iter)[group_columns.is_visible] = !group->is_hidden();
286                         (*iter)[group_columns.text] = group->name();
287                 }
288         }
289
290         in_edit_group_row_change = false;
291 }
292
293 void
294 Editor::edit_group_name_edit (const Glib::ustring& path, const Glib::ustring& new_text)
295 {
296         RouteGroup* group;
297         TreeIter iter;
298         
299         if ((iter = group_model->get_iter (path))) {
300         
301                 if ((group = (*iter)[group_columns.routegroup]) == 0) {
302                         return;
303                 }
304                 
305                 if (new_text != group->name()) {
306                         group->set_name (new_text);
307                 }
308         }
309 }