Fly my pretties!
[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 <ardour/stateful.h>
32
33 using std::vector;
34 using std::string;
35
36 class KeyboardTarget;
37 class ArdourDialog;
38
39 class Keyboard : public sigc::trackable, Stateful
40 {
41   public:
42         Keyboard ();
43         ~Keyboard ();
44
45         XMLNode& get_state (void);
46         int set_state (const XMLNode&);
47
48         typedef vector<uint32_t> State;
49         
50         void set_target (KeyboardTarget *);
51         void set_default_target (KeyboardTarget *);
52         void allow_focus (bool);
53
54         gint focus_in_handler (GdkEventFocus*);
55         gint focus_out_handler (GdkEventFocus*);
56
57         int  get_prefix(float&, bool& was_floating);
58         void start_prefix ();
59
60         static State  translate_key_name (const string&);
61         static string get_real_keyname (const string& name);
62
63         void register_target (KeyboardTarget *);
64
65         void set_current_dialog (ArdourDialog*);
66         void close_current_dialog ();
67
68         typedef uint32_t ModifierMask;
69
70         static uint32_t Control;
71         static uint32_t Shift;
72         static uint32_t Alt;
73         static uint32_t Meta;
74
75         bool key_is_down (uint32_t keyval);
76
77         static GdkModifierType RelevantModifierKeyMask;
78
79         static bool no_modifier_keys_pressed(GdkEventButton* ev) {
80                 return (ev->state & RelevantModifierKeyMask) == 0;
81         }
82
83         static bool modifier_state_contains (guint state, ModifierMask);
84         static bool modifier_state_equals   (guint state, ModifierMask);
85
86         static bool no_modifiers_active (guint state);
87
88         static void set_meta_modifier (guint);
89
90         static void set_snap_modifier (guint);
91         static ModifierMask snap_modifier () { return ModifierMask (snap_mod); }
92
93         static guint edit_button() { return edit_but; }
94         static void set_edit_button (guint);
95         static guint edit_modifier() { return edit_mod; }
96         static void set_edit_modifier(guint);
97
98         static guint delete_button() { return delete_but; }
99         static void set_delete_button(guint);
100         static guint delete_modifier() { return delete_mod; }
101         static void set_delete_modifier(guint);
102
103         static bool is_edit_event (GdkEventButton*);
104         static bool is_delete_event (GdkEventButton*);
105         static bool is_context_menu_event (GdkEventButton*);
106
107         static Keyboard& the_keyboard() { return *_the_keyboard; }
108
109   private:
110         static Keyboard* _the_keyboard;
111
112         bool   _queue_events;
113         bool   _flush_queue;
114         guint32 playback_ignore_count;
115
116         guint           snooper_id;
117         State           state;
118         KeyboardTarget* target;
119         KeyboardTarget* default_target;
120         bool            focus_allowed;
121         bool            collecting_prefix;
122         string          current_prefix;
123         int*            modifier_masks;
124         int             modifier_mask;
125         int             min_keycode;
126         int             max_keycode;
127         ArdourDialog*   current_dialog;
128         std::vector<ArdourDialog*> known_dialogs;
129
130         static guint     edit_but;
131         static guint     edit_mod;
132         static guint     delete_but;
133         static guint     delete_mod;
134         static guint     snap_mod;
135
136         static gint _snooper (GtkWidget*, GdkEventKey*, gpointer);
137         gint snooper (GtkWidget*, GdkEventKey*);
138         
139         void maybe_unset_target (KeyboardTarget *);
140         void queue_event (GdkEventKey*);
141         void playback_queue ();
142         void clear_queue ();
143         void get_modifier_masks ();
144         void check_modifier_state ();
145         void clear_modifier_state ();
146         gint enter_window (GdkEventCrossing*, KeyboardTarget*);
147         gint leave_window (GdkEventCrossing*);
148         gint current_dialog_vanished (GdkEventAny*);
149
150         void check_meta_numlock (char keycode, guint mod, string modname);
151 };
152
153 #endif /* __ardour_keyboard_h__ */