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.
25 #include "pbd/pathscanner.h"
27 #include "gtkmm2ext/keyboard.h"
28 #include "gtkmm2ext/selector.h"
29 #include "gtkmm2ext/utils.h"
32 using namespace Gtkmm2ext
;
34 Selector::Selector (void (*func
)(Glib::RefPtr
<Gtk::ListStore
>, void *), void *arg
,
35 vector
<string
> titles
)
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
));
61 Selector::~Selector ()
64 /* ensure that any row data set with set_row_data_full() is deleted */
89 Selector::reset (void (*func
)(Glib::RefPtr
<Gtk::ListStore
>, void *), void *arg
)
106 refiller (lstore
, refill_arg
);
111 Selector::_accept (gpointer arg
)
114 ((Selector
*) arg
)->accept ();
119 Selector::_chosen (gpointer arg
)
122 ((Selector
*) arg
)->chosen ();
127 Selector::_shift_clicked (gpointer arg
)
129 ((Selector
*) arg
)->shift_clicked ();
134 Selector::_control_clicked (gpointer arg
)
136 ((Selector
*) arg
)->control_clicked ();
143 Glib::RefPtr
<Gtk::TreeSelection
> tree_sel
= tview
.get_selection();
144 Gtk::TreeModel::iterator iter
= tree_sel
->get_selected();
148 selection_made (new Result (tview
, tree_sel
));
157 Glib::RefPtr
<Gtk::TreeSelection
> tree_sel
= tview
.get_selection();
158 Gtk::TreeModel::iterator iter
= tree_sel
->get_selected();
161 choice_made (new Result (tview
, tree_sel
));
168 Selector::shift_clicked ()
170 Glib::RefPtr
<Gtk::TreeSelection
> tree_sel
= tview
.get_selection();
171 Gtk::TreeModel::iterator iter
= tree_sel
->get_selected();
174 shift_made (new Result (tview
, tree_sel
));
181 Selector::control_clicked ()
183 Glib::RefPtr
<Gtk::TreeSelection
> tree_sel
= tview
.get_selection();
184 Gtk::TreeModel::iterator iter
= tree_sel
->get_selected();
187 control_made (new Result (tview
, tree_sel
));
196 Glib::RefPtr
<Gtk::TreeSelection
> tree_sel
= tview
.get_selection();
197 tree_sel
->unselect_all();
199 selection_made (new Result (tview
, tree_sel
));
207 selected_column
= -1;
213 bool operator()(const string
* a
, const string
* b
) {
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);
231 g_idle_add (Selector::_chosen
, this);