use -r argument with JACK if realtime is not requested in engine dialog (also applied...
[ArdourMidi.git] / libs / gtkmm2ext / selector.cc
blob85924e82ab728f842d0b67f218d698e00fbf6a91
1 /*
2 Copyright (C) 1999 Paul Barton-Davis
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2 of the License, or
6 (at your option) any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 $Id$
20 #include <algorithm>
21 #include <functional>
22 #include <vector>
23 #include <string>
25 #include "pbd/pathscanner.h"
27 #include "gtkmm2ext/keyboard.h"
28 #include "gtkmm2ext/selector.h"
29 #include "gtkmm2ext/utils.h"
31 using namespace std;
32 using namespace Gtkmm2ext;
34 Selector::Selector (void (*func)(Glib::RefPtr<Gtk::ListStore>, void *), void *arg,
35 vector<string> titles)
37 scroll.add (tview);
38 scroll.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
40 pack_start (scroll, true, true);
42 vector<string>::iterator i;
43 for (i = titles.begin(); i != titles.end(); ++i) {
44 Gtk::TreeModelColumn<Glib::ustring> title;
45 column_records.add(title);
48 lstore = Gtk::ListStore::create(column_records);
49 tview.set_model(lstore);
51 update_contents.connect(mem_fun(*this,&Selector::rescan));
53 tview.show ();
55 refiller = func;
56 refill_arg = arg;
57 selected_row = -1;
58 selected_column = -1;
61 Selector::~Selector ()
64 /* ensure that any row data set with set_row_data_full() is deleted */
65 hide_all ();
66 lstore.clear ();
69 void
70 Selector::on_map()
73 Gtk::VBox::on_map ();
75 selected_row = -1;
76 selected_column = -1;
77 refill();
80 void
81 Selector::on_show()
83 VBox::on_show();
85 rescan();
88 void
89 Selector::reset (void (*func)(Glib::RefPtr<Gtk::ListStore>, void *), void *arg)
92 refiller = func;
93 refill_arg = arg;
94 selected_row = -1;
95 selected_column = -1;
97 refill();
100 void
101 Selector::refill ()
104 if (refiller) {
105 lstore.clear ();
106 refiller (lstore, refill_arg);
110 gint
111 Selector::_accept (gpointer arg)
114 ((Selector *) arg)->accept ();
115 return FALSE;
118 gint
119 Selector::_chosen (gpointer arg)
122 ((Selector *) arg)->chosen ();
123 return FALSE;
126 gint
127 Selector::_shift_clicked (gpointer arg)
129 ((Selector *) arg)->shift_clicked ();
130 return FALSE;
133 gint
134 Selector::_control_clicked (gpointer arg)
136 ((Selector *) arg)->control_clicked ();
137 return FALSE;
140 void
141 Selector::accept ()
143 Glib::RefPtr<Gtk::TreeSelection> tree_sel = tview.get_selection();
144 Gtk::TreeModel::iterator iter = tree_sel->get_selected();
146 if (iter) {
148 selection_made (new Result (tview, tree_sel));
149 } else {
150 cancel ();
154 void
155 Selector::chosen ()
157 Glib::RefPtr<Gtk::TreeSelection> tree_sel = tview.get_selection();
158 Gtk::TreeModel::iterator iter = tree_sel->get_selected();
160 if (iter) {
161 choice_made (new Result (tview, tree_sel));
162 } else {
163 cancel ();
167 void
168 Selector::shift_clicked ()
170 Glib::RefPtr<Gtk::TreeSelection> tree_sel = tview.get_selection();
171 Gtk::TreeModel::iterator iter = tree_sel->get_selected();
173 if (iter) {
174 shift_made (new Result (tview, tree_sel));
175 } else {
176 cancel ();
180 void
181 Selector::control_clicked ()
183 Glib::RefPtr<Gtk::TreeSelection> tree_sel = tview.get_selection();
184 Gtk::TreeModel::iterator iter = tree_sel->get_selected();
186 if (iter) {
187 control_made (new Result (tview, tree_sel));
188 } else {
189 cancel ();
193 void
194 Selector::cancel ()
196 Glib::RefPtr<Gtk::TreeSelection> tree_sel = tview.get_selection();
197 tree_sel->unselect_all();
199 selection_made (new Result (tview, tree_sel));
202 void
203 Selector::rescan ()
206 selected_row = -1;
207 selected_column = -1;
208 refill ();
209 show_all ();
212 struct string_cmp {
213 bool operator()(const string* a, const string* b) {
214 return *a < *b;
218 bool
219 TreeView_Selector::on_button_press_event(GdkEventButton* ev)
221 bool return_value = TreeView::on_button_press_event(ev);
223 if (ev && (ev->type == GDK_BUTTON_RELEASE || ev->type == GDK_2BUTTON_PRESS)) {
224 if (ev->state & Keyboard::PrimaryModifier) {
225 g_idle_add (Selector::_control_clicked, this);
226 } else if (ev->state & Keyboard::TertiaryModifier) {
227 g_idle_add (Selector::_shift_clicked, this);
228 } else if (ev->type == GDK_2BUTTON_PRESS) {
229 g_idle_add (Selector::_accept, this);
230 } else {
231 g_idle_add (Selector::_chosen, this);
235 return return_value;