many changes, read the diffs
[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 <gtkmm2ext/gtk_ui.h>
26 #include <ardour/route_group.h>
27
28 #include "editor.h"
29 #include "keyboard.h"
30 #include "marker.h"
31 #include "time_axis_view.h"
32 #include "prompter.h"
33 #include "gui_thread.h"
34
35 #include <ardour/route.h>
36
37 #include "i18n.h"
38
39 using namespace sigc;
40 using namespace ARDOUR;
41 using namespace Gtk;
42
43 void
44 Editor::edit_group_list_column_click (gint col)
45
46 {
47         if (edit_group_list_menu == 0) {
48                 build_edit_group_list_menu ();
49         }
50
51         edit_group_list_menu->popup (0, 0);
52 }
53
54 void
55 Editor::build_edit_group_list_menu ()
56
57 {
58         using namespace Gtk::Menu_Helpers;
59
60         edit_group_list_menu = new Menu;
61         edit_group_list_menu->set_name ("ArdourContextMenu");
62         MenuList& items = edit_group_list_menu->items();
63
64         items.push_back (MenuElem (_("Show All"), mem_fun(*this, &Editor::select_all_edit_groups)));
65         items.push_back (MenuElem (_("Hide All"), mem_fun(*this, &Editor::unselect_all_edit_groups)));
66 }
67
68 void
69 Editor::unselect_all_edit_groups ()
70
71 {
72 }
73
74 void
75 Editor::select_all_edit_groups ()
76
77 {
78  
79         /* XXX potential race with remove_track(), but the select operation
80            cannot be done with the track_lock held.
81         */
82
83         Gtk::TreeModel::Children children = group_model->children();
84         for(Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter) {
85                 edit_group_display.get_selection()->select (iter);
86         }
87 }
88
89 void
90 Editor::new_edit_group ()
91
92 {
93         if (session == 0) {
94                 return;
95         }
96
97         ArdourPrompter prompter;
98         string result;
99
100         prompter.set_prompt (_("Name for new edit group"));
101         prompter.show_all ();
102
103         switch (prompter.run ()) {
104         case GTK_RESPONSE_ACCEPT:
105                 prompter.get_result (result);
106                 if (result.length()) {
107                   session->add_edit_group (result);
108                 }
109                 break;
110         }
111 }
112
113 void
114 Editor::edit_group_list_button_clicked ()
115 {
116         new_edit_group ();
117 }
118
119 gint
120 Editor::edit_group_list_button_press_event (GdkEventButton* ev)
121 {
122         RouteGroup* group;
123         TreeIter iter;
124         TreeModel::Path path;
125         TreeViewColumn* column;
126         int cellx;
127         int celly;
128         
129         if (!edit_group_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
130                 return false;
131         }
132
133         switch (GPOINTER_TO_UINT (column->get_data (X_("colnum")))) {
134           
135         case 1:
136
137                 if (Keyboard::is_edit_event (ev)) {
138                         // RouteGroup* group = (RouteGroup *) edit_group_display.row(row).get_data ();
139                         // edit_route_group (group);
140
141                         return stop_signal (edit_group_display, "button_press_event");
142
143                 } else {
144                         /* allow regular select to occur */
145                         return FALSE;
146                 }
147                 break;
148
149         case 0:
150                 if ((iter = group_model->get_iter (path))) {
151                         /* path points to a valid node */
152                         
153                         if ((group = (*iter)[group_columns.routegroup]) != 0) {
154                                 group->set_active (!group->is_active (), this);
155                         }
156                 }
157                 break;
158         }
159       
160         return stop_signal (edit_group_display, "button_press_event");
161 }
162
163 void
164 Editor::edit_group_selection_changed ()
165 {
166         TreeModel::iterator i;
167         TreeModel::Children rows = group_model->children();
168         Glib::RefPtr<TreeSelection> selection = edit_group_display.get_selection();
169
170         for (i = rows.begin(); i != rows.end(); ++i) {
171                 RouteGroup* group;
172
173                 group = (*i)[group_columns.routegroup];
174
175                 if (selection->is_selected (i)) {
176                   for (TrackViewList::iterator j = track_views.begin(); j != track_views.end(); ++j) {
177                     if ((*j)->edit_group() == group) {
178                       select_strip_in_display (*j);
179                     }
180                   }
181                 } else {
182                   for (TrackViewList::iterator j = track_views.begin(); j != track_views.end(); ++j) {
183                     if ((*j)->edit_group() == group) {
184                       unselect_strip_in_display (**j);
185                     }
186                   }
187                 }
188         }
189 }
190
191 void
192 Editor::add_edit_group (RouteGroup* group)
193
194 {
195         
196         ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::add_edit_group), group));
197
198         TreeModel::Row row = *(group_model->append());
199         row[group_columns.is_active] = group->is_active();
200         row[group_columns.text] = group->name();
201         row[group_columns.routegroup] = group;
202
203         group->FlagsChanged.connect (bind (mem_fun(*this, &Editor::group_flags_changed), group));
204 }
205
206 void
207 Editor::group_flags_changed (void* src, RouteGroup* group)
208 {
209   /* GTK2FIX not needed in gtk2?
210
211         if (src != this) {
212                 // select row
213         }
214
215         CList_Helpers::RowIterator ri = edit_group_display.rows().find_data (group);
216
217         if (group->is_active()) {
218                 edit_group_display.cell (ri->get_row_num(),0).set_pixmap (check_pixmap, check_mask);
219         } else {
220                 edit_group_display.cell (ri->get_row_num(),0).set_pixmap (empty_pixmap, empty_mask);
221         }
222   */
223 }
224
225