Fly my pretties!
[ardour.git] / gtk2_ardour / keyboard_target.h
1 /*
2     Copyright (C) 2001 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     $Id$
19 */
20
21 #ifndef __ardour_keyboard_target_h__
22 #define __ardour_keyboard_target_h__
23
24 #include <map>
25 #include <string>
26 #include <sigc++/signal.h>
27 #include <gdk/gdk.h>
28 #include <gtkmm/window.h>
29 #include <pbd/xml++.h>
30
31 #include "keyboard.h"
32
33 using std::map;
34 using std::string;
35
36 class KeyboardTarget 
37 {
38   public:
39         KeyboardTarget(Gtk::Window& w, string name);
40         virtual ~KeyboardTarget();
41
42         sigc::signal<void> Hiding;
43         sigc::signal<void> GoingAway;
44
45         typedef sigc::slot<void> KeyAction;
46
47         string name() const { return _name; }
48
49         void key_press_event (GdkEventKey *, Keyboard::State&, bool& handled);
50         void key_release_event (GdkEventKey *, Keyboard::State&);
51
52         int add_binding (string keys, string name);
53         string get_binding (string name); /* returns keys bound to name */
54
55         XMLNode& get_binding_state () const;
56         int set_binding_state (const XMLNode&);
57
58         static int32_t add_action (string, KeyAction);
59         static int32_t find_action (string, KeyAction&);
60         static int32_t remove_action (string);
61         static void show_all_actions();
62
63         Gtk::Window& window() const { return _window; }
64         
65   protected:
66         typedef map<Keyboard::State,KeyAction> KeyMap;
67         typedef map<string,string> BindingMap;
68
69         KeyMap     keymap;
70         BindingMap bindings;
71
72   private:
73         typedef map<string,KeyAction> ActionMap; 
74         static ActionMap actions;
75         string _name;
76         Gtk::Window& _window;
77
78         int load_bindings (const XMLNode&);
79 };
80
81 #endif /* __ardour_keyboard_target_h__ */
82