Adds sorting the toe keyeditor
[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 "ardour_window.h"
32
33 namespace Gtkmm2ext {
34         class Bindings;
35 }
36
37 class KeyEditor : public ArdourWindow
38 {
39   public:
40         KeyEditor ();
41
42         void add_tab (std::string const &name, Gtkmm2ext::Bindings&);
43
44   protected:
45         bool on_key_press_event (GdkEventKey*);
46         bool on_key_release_event (GdkEventKey*);
47
48   private:
49         class Tab : public Gtk::VBox
50         {
51            public:
52                 Tab (KeyEditor&, std::string const &name, Gtkmm2ext::Bindings*);
53
54                 void populate ();
55                 void unbind ();
56                 void bind (GdkEventKey* release_event, guint pressed_key);
57                 void action_selected ();
58                 void sort_column_changed ();
59                 void tab_mapped ();
60
61                 struct KeyEditorColumns : public Gtk::TreeModel::ColumnRecord {
62                         KeyEditorColumns () {
63                                 add (name);
64                                 add (binding);
65                                 add (path);
66                                 add (bindable);
67                                 add (action);
68                         }
69                         Gtk::TreeModelColumn<std::string> name;
70                         Gtk::TreeModelColumn<std::string> binding;
71                         Gtk::TreeModelColumn<std::string> path;
72                         Gtk::TreeModelColumn<bool> bindable;
73                         Gtk::TreeModelColumn<Glib::RefPtr<Gtk::Action> > action;
74                 };
75
76                 Gtk::VBox vpacker;
77                 /* give KeyEditor full access to these. This is just a helper
78                    class with no special semantics
79                 */
80
81                 KeyEditor& owner;
82                 std::string name;
83                 Gtkmm2ext::Bindings* bindings;
84                 Gtk::ScrolledWindow scroller;
85                 Gtk::TreeView view;
86                 Glib::RefPtr<Gtk::TreeStore> model;
87                 KeyEditorColumns columns;
88         };
89
90         friend class Tab;
91
92         Gtk::VBox vpacker;
93         Gtk::Notebook notebook;
94         Gtk::Button unbind_button;
95         Gtk::HButtonBox unbind_box;
96         Gtk::HBox reset_box;
97         Gtk::Button reset_button;
98         Gtk::Label reset_label;
99         guint last_keyval;
100
101         typedef std::vector<Tab*> Tabs;
102
103         Tabs tabs;
104         Tab* current_tab();
105
106         void unbind ();
107         void reset ();
108         void page_change (GtkNotebookPage*, guint);
109
110         unsigned int sort_column;
111         Gtk::SortType sort_type;
112         void toggle_sort_type ();
113 };
114
115 #endif /* __ardour_gtk_key_editor_h__ */