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