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