a reverb is a reverb is a reverb
[ardour.git] / gtk2_ardour / keyeditor.h
1 /*
2     Copyright (C) 2012 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #ifndef __ardour_gtk_key_editor_h__
21 #define __ardour_gtk_key_editor_h__
22
23 #include <string>
24
25 #include <gtkmm/buttonbox.h>
26 #include <gtkmm/notebook.h>
27 #include <gtkmm/scrolledwindow.h>
28 #include <gtkmm/treeview.h>
29 #include <gtkmm/treestore.h>
30 #include "gtkmm2ext/searchbar.h"
31
32 #include "ardour_window.h"
33
34 namespace Gtkmm2ext {
35         class Bindings;
36 }
37
38 class KeyEditor : public ArdourWindow
39 {
40   public:
41         KeyEditor ();
42
43         void add_tab (std::string const &name, Gtkmm2ext::Bindings&);
44         void remove_tab (std::string const &name);
45
46         static sigc::signal<void> UpdateBindings;
47
48         void disconnect () {
49                 _refresh_connection.disconnect ();
50         }
51
52         private:
53         class Tab : public Gtk::VBox
54         {
55                 public:
56                 Tab (KeyEditor&, std::string const &name, Gtkmm2ext::Bindings*);
57
58                 uint32_t populate ();
59                 void unbind ();
60                 void bind (GdkEventKey* release_event, guint pressed_key);
61                 void action_selected ();
62                 void sort_column_changed ();
63                 void tab_mapped ();
64                 bool visible_func(const Gtk::TreeModel::const_iterator& iter) const;
65
66                 struct KeyEditorColumns : public Gtk::TreeModel::ColumnRecord {
67                         KeyEditorColumns () {
68                                 add (name);
69                                 add (binding);
70                                 add (path);
71                                 add (bindable);
72                                 add (action);
73                         }
74                         Gtk::TreeModelColumn<std::string> name;
75                         Gtk::TreeModelColumn<std::string> binding;
76                         Gtk::TreeModelColumn<std::string> path;
77                         Gtk::TreeModelColumn<bool> bindable;
78                         Gtk::TreeModelColumn<Glib::RefPtr<Gtk::Action> > action;
79                 };
80
81                 Gtk::VBox vpacker;
82                 /* give KeyEditor full access to these. This is just a helper
83                    class with no special semantics
84                 */
85
86                 KeyEditor& owner;
87                 std::string name;
88                 Gtkmm2ext::Bindings* bindings;
89                 Gtk::ScrolledWindow scroller;
90                 Gtk::TreeView view;
91                 Glib::RefPtr<Gtk::TreeStore> data_model;
92                 Glib::RefPtr<Gtk::TreeModelFilter> filter;
93                 Glib::RefPtr<Gtk::TreeModelSort> sorted_filter;
94                 KeyEditorColumns columns;
95                 guint last_keyval;
96
97                 protected:
98                 bool key_press_event (GdkEventKey*);
99                 bool key_release_event (GdkEventKey*);
100                 Gtk::TreeModel::iterator find_action_path (Gtk::TreeModel::const_iterator begin, Gtk::TreeModel::const_iterator end, const std::string& path) const;
101         };
102
103         friend class Tab;
104
105         Gtk::VBox vpacker;
106         Gtk::Notebook notebook;
107         Gtk::Button unbind_button;
108         Gtk::HButtonBox unbind_box;
109         Gtk::HBox reset_box;
110         Gtk::Button reset_button;
111         Gtk::Label reset_label;
112         Gtkmm2ext::SearchBar filter_entry;
113         std::string filter_string;
114         Gtk::Button print_button;
115
116         typedef std::vector<Tab*> Tabs;
117
118         Tabs tabs;
119         Tab* current_tab();
120
121         void unbind ();
122         void reset ();
123         void refresh ();
124         void page_change (GtkNotebookPage*, guint);
125
126         unsigned int sort_column;
127         Gtk::SortType sort_type;
128         void toggle_sort_type ();
129         void search_string_updated (const std::string&);
130         void print () const;
131
132         sigc::connection _refresh_connection;
133 };
134
135 #endif /* __ardour_gtk_key_editor_h__ */