Minor updates for PathList and OptionEditor.
[ardour.git] / libs / gtkmm2ext / gtkmm2ext / selector.h
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.
7
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.
12
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.
16
17     $Id$
18 */
19
20 #ifndef __gtkselector_h__
21 #define __gtkselector_h__
22
23 #include <string>
24 #include <vector>
25
26 #include <gtkmm.h>
27
28 namespace Gtkmm2ext {
29
30 class TreeView_Selector : public Gtk::TreeView
31 {
32 public:
33         TreeView_Selector() {}
34         virtual ~TreeView_Selector() {}
35
36 protected:
37         virtual bool on_button_press_event(GdkEventButton *ev);
38 };
39
40 typedef void (SelectorRefillFunction)(Glib::RefPtr<Gtk::ListStore>, void *);
41
42 class Selector : public Gtk::VBox
43 {
44         friend class Gtkmm2ext::TreeView_Selector;
45
46 public:
47         Selector (SelectorRefillFunction, void *arg, 
48                   std::vector<std::string> titles);
49
50         virtual ~Selector ();
51         Glib::RefPtr<Gtk::ListStore> liststore () { return lstore; }
52         void reset (void (*refiller)(Glib::RefPtr<Gtk::ListStore>, void *), void *arg);
53         void set_size (unsigned int w, unsigned int h) {
54                 scroll.set_size_request (w, h);
55                 tview.columns_autosize ();
56         }
57
58         struct Result {
59             Gtk::TreeView& view;
60             Glib::RefPtr<Gtk::TreeSelection> selection;
61
62             Result (Gtk::TreeView& v, Glib::RefPtr<Gtk::TreeSelection> sel)
63                     : view (v), selection (sel) {}
64         };
65
66         /* selection is activated via a double click, choice via
67            a single click.
68         */
69         sigc::signal<void,Result*> selection_made;
70         sigc::signal<void,Result*> choice_made;
71         sigc::signal<void,Result*> shift_made;
72         sigc::signal<void,Result*> control_made;
73
74         sigc::signal<void> update_contents;
75
76         void accept();
77         void cancel();
78         void rescan();
79
80
81   protected:
82         virtual void on_map ();
83         virtual void on_show ();
84
85   private:
86         Gtk::ScrolledWindow scroll;
87         Gtk::TreeModel::ColumnRecord column_records;
88         Glib::RefPtr<Gtk::ListStore> lstore;
89         Gtkmm2ext::TreeView_Selector tview;
90         void (*refiller)(Glib::RefPtr<Gtk::ListStore>, void *);
91         void *refill_arg;
92         gint selected_row;
93         gint selected_column;
94         gint chosen_row;
95         gint chosen_column;
96
97         void refill ();
98         void chosen ();
99         void shift_clicked ();
100         void control_clicked ();
101
102         static gint _accept (gpointer);
103         static gint _chosen (gpointer);
104         static gint _shift_clicked (gpointer);
105         static gint _control_clicked (gpointer);
106
107 };
108
109 } /* namespace */
110
111 #endif // __gtkselector_h__