r269@gandalf: fugalh | 2006-08-03 20:18:05 -0600
[ardour.git] / gtk2_ardour / keyboard.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_h__
22 #define __ardour_keyboard_h__
23
24 #include <vector>
25 #include <string>
26
27 #include <sigc++/signal.h>
28 #include <gtk/gtk.h>
29
30 #include <ardour/types.h>
31 #include <pbd/stateful.h>
32
33 #include "selection.h"
34
35 using std::vector;
36 using std::string;
37
38 class Keyboard : public sigc::trackable, Stateful
39 {
40   public:
41         Keyboard ();
42         ~Keyboard ();
43
44         XMLNode& get_state (void);
45         int set_state (const XMLNode&);
46
47         typedef vector<uint32_t> State;
48         
49         int  get_prefix(float&, bool& was_floating);
50         void start_prefix ();
51
52         static State  translate_key_name (const string&);
53         static string get_real_keyname (const string& name);
54
55         typedef uint32_t ModifierMask;
56
57         static uint32_t Control;
58         static uint32_t Shift;
59         static uint32_t Alt;
60         static uint32_t Meta;
61
62         bool key_is_down (uint32_t keyval);
63
64         static GdkModifierType RelevantModifierKeyMask;
65
66         static bool no_modifier_keys_pressed(GdkEventButton* ev) {
67                 return (ev->state & RelevantModifierKeyMask) == 0;
68         }
69
70         bool leave_window (GdkEventCrossing *ev, Gtk::Window*);
71         bool enter_window (GdkEventCrossing *ev, Gtk::Window*);
72
73         static bool modifier_state_contains (guint state, ModifierMask);
74         static bool modifier_state_equals   (guint state, ModifierMask);
75
76         static Selection::Operation selection_type (guint state);
77
78         static bool no_modifiers_active (guint state);
79
80         static void set_meta_modifier (guint);
81
82         static void set_snap_modifier (guint);
83         static ModifierMask snap_modifier () { return ModifierMask (snap_mod); }
84
85         static guint edit_button() { return edit_but; }
86         static void set_edit_button (guint);
87         static guint edit_modifier() { return edit_mod; }
88         static void set_edit_modifier(guint);
89
90         static guint delete_button() { return delete_but; }
91         static void set_delete_button(guint);
92         static guint delete_modifier() { return delete_mod; }
93         static void set_delete_modifier(guint);
94
95         static bool is_edit_event (GdkEventButton*);
96         static bool is_delete_event (GdkEventButton*);
97         static bool is_context_menu_event (GdkEventButton*);
98
99         static Keyboard& the_keyboard() { return *_the_keyboard; }
100
101   private:
102         static Keyboard* _the_keyboard;
103
104         bool   _queue_events;
105         bool   _flush_queue;
106
107         guint           snooper_id;
108         State           state;
109         bool            collecting_prefix;
110         string          current_prefix;
111         int*            modifier_masks;
112         int             modifier_mask;
113         int             min_keycode;
114         int             max_keycode;
115
116         static guint     edit_but;
117         static guint     edit_mod;
118         static guint     delete_but;
119         static guint     delete_mod;
120         static guint     snap_mod;
121
122         static gint _snooper (GtkWidget*, GdkEventKey*, gpointer);
123         gint snooper (GtkWidget*, GdkEventKey*);
124         
125         void queue_event (GdkEventKey*);
126         void get_modifier_masks ();
127         void check_modifier_state ();
128         void clear_modifier_state ();
129
130         void check_meta_numlock (char keycode, guint mod, string modname);
131 };
132
133 #endif /* __ardour_keyboard_h__ */