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