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