replace ::cast_dynamic() with relevant ActionManager::get_*_action() calls
[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/treemodelfilter.h>
29 #include <gtkmm/treestore.h>
30 #include <gtkmm/treeview.h>
31
32 #include "widgets/searchbar.h"
33
34 #include "ardour_window.h"
35
36 namespace Gtkmm2ext {
37         class Bindings;
38 }
39
40 class KeyEditor : public ArdourWindow
41 {
42 public:
43         KeyEditor ();
44
45         void add_tab (std::string const &name, Gtkmm2ext::Bindings&);
46         void remove_tab (std::string const &name);
47
48         static sigc::signal<void> UpdateBindings;
49
50         void disconnect () {
51                 _refresh_connection.disconnect ();
52         }
53
54 private:
55         class Tab : public Gtk::VBox
56         {
57         public:
58                 Tab (KeyEditor&, std::string const &name, Gtkmm2ext::Bindings*);
59
60                 uint32_t populate ();
61                 void unbind ();
62                 void bind (GdkEventKey* release_event, guint pressed_key);
63                 void action_selected ();
64                 void sort_column_changed ();
65                 void tab_mapped ();
66                 bool visible_func(const Gtk::TreeModel::const_iterator& iter) const;
67
68                 struct KeyEditorColumns : public Gtk::TreeModel::ColumnRecord {
69                         KeyEditorColumns () {
70                                 add (name);
71                                 add (binding);
72                                 add (path);
73                                 add (bindable);
74                                 add (action);
75                         }
76                         Gtk::TreeModelColumn<std::string> name;
77                         Gtk::TreeModelColumn<std::string> binding;
78                         Gtk::TreeModelColumn<std::string> path;
79                         Gtk::TreeModelColumn<bool> bindable;
80                         Gtk::TreeModelColumn<Glib::RefPtr<Gtk::Action> > action;
81                 };
82
83                 Gtk::VBox vpacker;
84                 /* give KeyEditor full access to these. This is just a helper
85                  * class with no special semantics
86                  */
87
88                 KeyEditor& owner;
89                 std::string name;
90                 Gtkmm2ext::Bindings* bindings;
91                 Gtk::ScrolledWindow scroller;
92                 Gtk::TreeView view;
93                 Glib::RefPtr<Gtk::TreeStore> data_model;
94                 Glib::RefPtr<Gtk::TreeModelFilter> filter;
95                 Glib::RefPtr<Gtk::TreeModelSort> sorted_filter;
96                 KeyEditorColumns columns;
97                 guint last_keyval;
98
99         protected:
100                 bool key_press_event (GdkEventKey*);
101                 bool key_release_event (GdkEventKey*);
102                 Gtk::TreeModel::iterator find_action_path (Gtk::TreeModel::const_iterator begin, Gtk::TreeModel::const_iterator end, const std::string& path) const;
103         };
104
105         friend class Tab;
106
107         Gtk::VBox vpacker;
108         Gtk::Notebook notebook;
109         Gtk::Button unbind_button;
110         Gtk::HButtonBox unbind_box;
111         Gtk::HBox reset_box;
112         Gtk::Button reset_button;
113         Gtk::Label reset_label;
114         ArdourWidgets::SearchBar filter_entry;
115         std::string filter_string;
116         Gtk::Button print_button;
117         Gtk::Label print_label;
118
119         typedef std::vector<Tab*> Tabs;
120
121         Tabs tabs;
122         Tab* current_tab();
123
124         void unbind ();
125         void reset ();
126         void refresh ();
127         void page_change (GtkNotebookPage*, guint);
128
129         unsigned int sort_column;
130         Gtk::SortType sort_type;
131         void toggle_sort_type ();
132         void search_string_updated (const std::string&);
133         void print () const;
134
135         sigc::connection _refresh_connection;
136 };
137
138 #endif /* __ardour_gtk_key_editor_h__ */