fix keyboard event handling for host-provided plugin GUIs
[ardour2.git] / gtk2_ardour / editor_edit_groups.cc
blob2bd31e55f68d7d8f54f731ec1ced084aba88e9a5
1 /*
2 Copyright (C) 2000 Paul Davis
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.
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.
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.
20 #include <cstdlib>
21 #include <cmath>
23 #include <gtkmm2ext/stop_signal.h>
24 #include <gtkmm2ext/gtk_ui.h>
25 #include <ardour/route_group.h>
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"
34 #include <ardour/route.h>
36 #include "i18n.h"
38 using namespace sigc;
39 using namespace ARDOUR;
40 using namespace PBD;
41 using namespace Gtk;
43 void
44 Editor::build_edit_group_list_menu ()
46 using namespace Gtk::Menu_Helpers;
48 edit_group_list_menu = new Menu;
49 edit_group_list_menu->set_name ("ArdourContextMenu");
50 MenuList& items = edit_group_list_menu->items();
52 items.push_back (MenuElem (_("Activate All"), mem_fun(*this, &Editor::activate_all_edit_groups)));
53 items.push_back (MenuElem (_("Disable All"), mem_fun(*this, &Editor::disable_all_edit_groups)));
54 items.push_back (SeparatorElem());
55 items.push_back (MenuElem (_("Show All"), mem_fun(*this, &Editor::show_all_edit_groups)));
56 items.push_back (MenuElem (_("Hide All"), mem_fun(*this, &Editor::hide_all_edit_groups)));
57 items.push_back (SeparatorElem());
58 items.push_back (MenuElem (_("Add group"), mem_fun(*this, &Editor::new_edit_group)));
62 void
63 Editor::activate_all_edit_groups ()
65 Gtk::TreeModel::Children children = group_model->children();
66 for(Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter) {
67 (*iter)[group_columns.is_active] = true;
71 void
72 Editor::disable_all_edit_groups ()
74 Gtk::TreeModel::Children children = group_model->children();
75 for(Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter) {
76 (*iter)[group_columns.is_active] = false;
80 void
81 Editor::show_all_edit_groups ()
83 Gtk::TreeModel::Children children = group_model->children();
84 for(Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter) {
85 (*iter)[group_columns.is_visible] = true;
89 void
90 Editor::hide_all_edit_groups ()
92 Gtk::TreeModel::Children children = group_model->children();
93 for(Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter) {
94 (*iter)[group_columns.is_visible] = false;
98 void
99 Editor::new_edit_group ()
101 session->add_edit_group ("");
104 void
105 Editor::remove_selected_edit_group ()
107 Glib::RefPtr<TreeSelection> selection = edit_group_display.get_selection();
108 TreeView::Selection::ListHandle_Path rows = selection->get_selected_rows ();
110 if (rows.empty()) {
111 return;
114 TreeView::Selection::ListHandle_Path::iterator i = rows.begin();
115 TreeIter iter;
117 /* selection mode is single, so rows.begin() is it */
119 if ((iter = group_model->get_iter (*i))) {
121 RouteGroup* rg = (*iter)[group_columns.routegroup];
123 if (rg) {
124 session->remove_edit_group (*rg);
129 void
130 Editor::edit_group_list_button_clicked ()
132 new_edit_group ();
135 gint
136 Editor::edit_group_list_button_press_event (GdkEventButton* ev)
138 if (Keyboard::is_context_menu_event (ev)) {
139 if (edit_group_list_menu == 0) {
140 build_edit_group_list_menu ();
142 edit_group_list_menu->popup (1, ev->time);
143 return true;
147 RouteGroup* group;
148 TreeIter iter;
149 TreeModel::Path path;
150 TreeViewColumn* column;
151 int cellx;
152 int celly;
154 if (!edit_group_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
155 return false;
158 switch (GPOINTER_TO_UINT (column->get_data (X_("colnum")))) {
159 case 0:
160 if (Keyboard::is_edit_event (ev)) {
161 if ((iter = group_model->get_iter (path))) {
162 if ((group = (*iter)[group_columns.routegroup]) != 0) {
163 // edit_route_group (group);
164 #ifdef GTKOSX
165 edit_group_display.queue_draw();
166 #endif
167 return true;
172 break;
174 case 1:
175 if ((iter = group_model->get_iter (path))) {
176 bool active = (*iter)[group_columns.is_active];
177 (*iter)[group_columns.is_active] = !active;
178 #ifdef GTKOSX
179 edit_group_display.queue_draw();
180 #endif
181 return true;
183 break;
185 case 2:
186 if ((iter = group_model->get_iter (path))) {
187 bool visible = (*iter)[group_columns.is_visible];
188 (*iter)[group_columns.is_visible] = !visible;
189 #ifdef GTKOSX
190 edit_group_display.queue_draw();
191 #endif
192 return true;
194 break;
196 default:
197 break;
200 return false;
203 void
204 Editor::edit_group_row_change (const Gtk::TreeModel::Path& path,const Gtk::TreeModel::iterator& iter)
206 RouteGroup* group;
208 if (in_edit_group_row_change) {
209 return;
212 if ((group = (*iter)[group_columns.routegroup]) == 0) {
213 string name = (*iter)[group_columns.text];
214 if (name == "-all-")
215 all_group_is_active = (*iter)[group_columns.is_active];
216 return;
219 if ((*iter)[group_columns.is_visible]) {
220 for (TrackViewList::iterator j = track_views.begin(); j != track_views.end(); ++j) {
221 if ((*j)->edit_group() == group) {
222 show_track_in_display (**j);
225 } else {
226 for (TrackViewList::iterator j = track_views.begin(); j != track_views.end(); ++j) {
227 if ((*j)->edit_group() == group) {
228 hide_track_in_display (**j);
233 bool active = (*iter)[group_columns.is_active];
234 group->set_active (active, this);
236 bool visible = (*iter)[group_columns.is_visible];
237 group->set_hidden (!visible, this);
239 string name = (*iter)[group_columns.text];
241 if (name != group->name()) {
242 group->set_name (name);
246 void
247 Editor::add_edit_group (RouteGroup* group)
249 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::add_edit_group), group));
250 bool focus = false;
252 TreeModel::Row row = *(group_model->append());
253 row[group_columns.is_active] = group->is_active();
254 row[group_columns.is_visible] = !group->is_hidden();
256 in_edit_group_row_change = true;
258 row[group_columns.routegroup] = group;
260 if (!group->name().empty()) {
261 row[group_columns.text] = group->name();
262 } else {
263 row[group_columns.text] = _("unnamed");
264 focus = true;
267 group->FlagsChanged.connect (bind (mem_fun(*this, &Editor::group_flags_changed), group));
269 if (focus) {
270 TreeViewColumn* col = edit_group_display.get_column (0);
271 CellRendererText* name_cell = dynamic_cast<CellRendererText*>(edit_group_display.get_column_cell_renderer (0));
272 edit_group_display.set_cursor (group_model->get_path (row), *col, *name_cell, true);
275 in_edit_group_row_change = false;
278 void
279 Editor::edit_groups_changed ()
281 ENSURE_GUI_THREAD (mem_fun (*this, &Editor::edit_groups_changed));
283 /* just rebuild the while thing */
285 group_model->clear ();
288 TreeModel::Row row;
289 row = *(group_model->append());
290 row[group_columns.is_active] = false;
291 row[group_columns.is_visible] = true;
292 row[group_columns.text] = (_("-all-"));
293 row[group_columns.routegroup] = 0;
296 session->foreach_edit_group (mem_fun (*this, &Editor::add_edit_group));
299 void
300 Editor::group_flags_changed (void* src, RouteGroup* group)
302 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::group_flags_changed), src, group));
304 in_edit_group_row_change = true;
306 Gtk::TreeModel::Children children = group_model->children();
307 for(Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter) {
308 if (group == (*iter)[group_columns.routegroup]) {
309 (*iter)[group_columns.is_active] = group->is_active();
310 (*iter)[group_columns.is_visible] = !group->is_hidden();
311 (*iter)[group_columns.text] = group->name();
315 in_edit_group_row_change = false;
318 void
319 Editor::edit_group_name_edit (const Glib::ustring& path, const Glib::ustring& new_text)
321 RouteGroup* group;
322 TreeIter iter;
324 if ((iter = group_model->get_iter (path))) {
326 if ((group = (*iter)[group_columns.routegroup]) == 0) {
327 return;
330 if (new_text != group->name()) {
331 group->set_name (new_text);