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 "gtkmm2ext/keyboard.h"
29 #include "gtkmm2ext/selector.h"
30 #include "gtkmm2ext/utils.h"
33 using namespace Gtkmm2ext;
35 Selector::Selector (void (*func)(Glib::RefPtr<Gtk::ListStore>, void *), void *arg,
36 vector<string> titles)
39 scroll.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
41 pack_start (scroll, true, true);
43 vector<string>::iterator i;
44 for (i = titles.begin(); i != titles.end(); ++i) {
45 Gtk::TreeModelColumn<Glib::ustring> title;
46 column_records.add(title);
49 lstore = Gtk::ListStore::create(column_records);
50 tview.set_model(lstore);
52 update_contents.connect(mem_fun(*this,&Selector::rescan));
62 Selector::~Selector ()
65 /* ensure that any row data set with set_row_data_full() is deleted */
90 Selector::reset (void (*func)(Glib::RefPtr<Gtk::ListStore>, void *), void *arg)
107 refiller (lstore, refill_arg);
112 Selector::_accept (gpointer arg)
115 ((Selector *) arg)->accept ();
120 Selector::_chosen (gpointer arg)
123 ((Selector *) arg)->chosen ();
128 Selector::_shift_clicked (gpointer arg)
130 ((Selector *) arg)->shift_clicked ();
135 Selector::_control_clicked (gpointer arg)
137 ((Selector *) arg)->control_clicked ();
144 Glib::RefPtr<Gtk::TreeSelection> tree_sel = tview.get_selection();
145 Gtk::TreeModel::iterator iter = tree_sel->get_selected();
149 selection_made (new Result (tview, tree_sel));
158 Glib::RefPtr<Gtk::TreeSelection> tree_sel = tview.get_selection();
159 Gtk::TreeModel::iterator iter = tree_sel->get_selected();
162 choice_made (new Result (tview, tree_sel));
169 Selector::shift_clicked ()
171 Glib::RefPtr<Gtk::TreeSelection> tree_sel = tview.get_selection();
172 Gtk::TreeModel::iterator iter = tree_sel->get_selected();
175 shift_made (new Result (tview, tree_sel));
182 Selector::control_clicked ()
184 Glib::RefPtr<Gtk::TreeSelection> tree_sel = tview.get_selection();
185 Gtk::TreeModel::iterator iter = tree_sel->get_selected();
188 control_made (new Result (tview, tree_sel));
197 Glib::RefPtr<Gtk::TreeSelection> tree_sel = tview.get_selection();
198 tree_sel->unselect_all();
200 selection_made (new Result (tview, tree_sel));
208 selected_column = -1;
214 bool operator()(const string* a, const string* b) {
220 TreeView_Selector::on_button_press_event(GdkEventButton* ev)
222 bool return_value = TreeView::on_button_press_event(ev);
224 if (ev && (ev->type == GDK_BUTTON_RELEASE || ev->type == GDK_2BUTTON_PRESS)) {
225 if (ev->state & Keyboard::PrimaryModifier) {
226 g_idle_add (Selector::_control_clicked, this);
227 } else if (ev->state & Keyboard::TertiaryModifier) {
228 g_idle_add (Selector::_shift_clicked, this);
229 } else if (ev->type == GDK_2BUTTON_PRESS) {
230 g_idle_add (Selector::_accept, this);
232 g_idle_add (Selector::_chosen, this);