Gnime::Canvas::Points init fix
[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_list.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
123         RouteGroup* group;
124         TreeIter iter;
125         TreeModel::Path path;
126         TreeViewColumn* column;
127         int cellx;
128         int celly;
129         
130         if (!edit_group_list.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
131                 return false;
132         }
133
134         switch (GPOINTER_TO_UINT (column->get_data (X_("colnum")))) {
135           
136         case 1:
137
138                 if (Keyboard::is_edit_event (ev)) {
139                         // RouteGroup* group = (RouteGroup *) edit_group_list.row(row).get_data ();
140                         // edit_route_group (group);
141
142                         return stop_signal (edit_group_list, "button_press_event");
143
144                 } else {
145                         /* allow regular select to occur */
146                         return FALSE;
147                 }
148                 break;
149
150         case 0:
151                 if ((iter = group_model->get_iter (path))) {
152                         /* path points to a valid node */
153                         
154                         if ((group = (*iter)[group_columns.routegroup]) != 0) {
155                                 group->set_active (!group->is_active (), this);
156                         }
157                 }
158                 break;
159         }
160       
161         return stop_signal (edit_group_list, "button_press_event");
162 }
163
164 void
165 Editor::edit_group_selection_changed ()
166 {
167         TreeModel::iterator i;
168         TreeModel::Children rows = group_model->children();
169         Glib::RefPtr<TreeSelection> selection = edit_group_list.get_selection();
170
171         for (i = rows.begin(); i != rows.end(); ++i) {
172                 RouteGroup* group;
173
174                 group = (*i)[group_columns.routegroup];
175
176                 if (selection->is_selected (i)) {
177                   for (TrackViewList::iterator j = track_views.begin(); j != track_views.end(); ++j) {
178                     if ((*j)->edit_group() == group) {
179                       select_strip_in_display (*j);
180                     }
181                   }
182                 } else {
183                   for (TrackViewList::iterator j = track_views.begin(); j != track_views.end(); ++j) {
184                     if ((*j)->edit_group() == group) {
185                       unselect_strip_in_display (*j);
186                     }
187                   }
188                 }
189         }
190 }
191
192 void
193 Editor::add_edit_group (RouteGroup* group)
194
195 {
196         
197         ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::add_edit_group), group));
198
199         TreeModel::Row row = *(group_model->append());
200         row[group_columns.is_active] = group->is_active();
201         row[group_columns.text] = group->name();
202         row[group_columns.routegroup] = group;
203
204         group->FlagsChanged.connect (bind (mem_fun(*this, &Editor::group_flags_changed), group));
205 }
206
207 void
208 Editor::group_flags_changed (void* src, RouteGroup* group)
209 {
210   /* GTK2FIX not needed in gtk2?
211
212         if (src != this) {
213                 // select row
214         }
215
216         CList_Helpers::RowIterator ri = edit_group_list.rows().find_data (group);
217
218         if (group->is_active()) {
219                 edit_group_list.cell (ri->get_row_num(),0).set_pixmap (check_pixmap, check_mask);
220         } else {
221                 edit_group_list.cell (ri->get_row_num(),0).set_pixmap (empty_pixmap, empty_mask);
222         }
223   */
224 }
225
226