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.
28 #include "pbd/pathscanner.h"
30 #include "gtkmm2ext/keyboard.h"
31 #include "gtkmm2ext/selector.h"
32 #include "gtkmm2ext/utils.h"
35 using namespace Gtkmm2ext;
37 Selector::Selector (void (*func)(Glib::RefPtr<Gtk::ListStore>, void *), void *arg,
38 vector<string> titles)
41 scroll.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
43 pack_start (scroll, true, true);
45 vector<string>::iterator i;
46 for (i = titles.begin(); i != titles.end(); ++i) {
47 Gtk::TreeModelColumn<Glib::ustring> title;
48 column_records.add(title);
51 lstore = Gtk::ListStore::create(column_records);
52 tview.set_model(lstore);
54 update_contents.connect(mem_fun(*this,&Selector::rescan));
64 Selector::~Selector ()
67 /* ensure that any row data set with set_row_data_full() is deleted */
92 Selector::reset (void (*func)(Glib::RefPtr<Gtk::ListStore>, void *), void *arg)
109 refiller (lstore, refill_arg);
114 Selector::_accept (gpointer arg)
117 ((Selector *) arg)->accept ();
122 Selector::_chosen (gpointer arg)
125 ((Selector *) arg)->chosen ();
130 Selector::_shift_clicked (gpointer arg)
132 ((Selector *) arg)->shift_clicked ();
137 Selector::_control_clicked (gpointer arg)
139 ((Selector *) arg)->control_clicked ();
146 Glib::RefPtr<Gtk::TreeSelection> tree_sel = tview.get_selection();
147 Gtk::TreeModel::iterator iter = tree_sel->get_selected();
151 selection_made (new Result (tview, tree_sel));
160 Glib::RefPtr<Gtk::TreeSelection> tree_sel = tview.get_selection();
161 Gtk::TreeModel::iterator iter = tree_sel->get_selected();
164 choice_made (new Result (tview, tree_sel));
171 Selector::shift_clicked ()
173 Glib::RefPtr<Gtk::TreeSelection> tree_sel = tview.get_selection();
174 Gtk::TreeModel::iterator iter = tree_sel->get_selected();
177 shift_made (new Result (tview, tree_sel));
184 Selector::control_clicked ()
186 Glib::RefPtr<Gtk::TreeSelection> tree_sel = tview.get_selection();
187 Gtk::TreeModel::iterator iter = tree_sel->get_selected();
190 control_made (new Result (tview, tree_sel));
199 Glib::RefPtr<Gtk::TreeSelection> tree_sel = tview.get_selection();
200 tree_sel->unselect_all();
202 selection_made (new Result (tview, tree_sel));
210 selected_column = -1;
216 bool operator()(const string* a, const string* b) {
222 TreeView_Selector::on_button_press_event(GdkEventButton* ev)
224 bool return_value = TreeView::on_button_press_event(ev);
226 if (ev && (ev->type == GDK_BUTTON_RELEASE || ev->type == GDK_2BUTTON_PRESS)) {
227 if (ev->state & Keyboard::PrimaryModifier) {
228 g_idle_add (Selector::_control_clicked, this);
229 } else if (ev->state & Keyboard::TertiaryModifier) {
230 g_idle_add (Selector::_shift_clicked, this);
231 } else if (ev->type == GDK_2BUTTON_PRESS) {
232 g_idle_add (Selector::_accept, this);
234 g_idle_add (Selector::_chosen, this);