parametize modifier key usage; fix keyboard-driven sync point setting; add ladspa...
[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 */
19
20 #ifndef __ardour_keyboard_h__
21 #define __ardour_keyboard_h__
22
23 #include <vector>
24 #include <string>
25
26 #include <sigc++/signal.h>
27 #include <gtk/gtk.h>
28 #include <gtkmm/window.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         typedef uint32_t ModifierMask;
49
50         static uint32_t PrimaryModifier;
51         static uint32_t SecondaryModifier;
52         static uint32_t TertiaryModifier;
53         static uint32_t CopyModifier;
54         static uint32_t RangeSelectModifier;
55
56         static void set_primary_modifier (uint32_t newval) {
57                 set_modifier (newval, PrimaryModifier);
58         }
59         static void set_secondary_modifier (uint32_t newval) {
60                 set_modifier (newval, SecondaryModifier);
61         }
62         static void set_tertiary_modifier (uint32_t newval) {
63                 set_modifier (newval, TertiaryModifier);
64         }
65         static void set_copy_modifier (uint32_t newval) {
66                 set_modifier (newval, CopyModifier);
67         }
68         static void set_range_select_modifier (uint32_t newval) {
69                 set_modifier (newval, RangeSelectModifier);
70         }
71
72         bool key_is_down (uint32_t keyval);
73
74         static GdkModifierType RelevantModifierKeyMask;
75
76         static bool no_modifier_keys_pressed(GdkEventButton* ev) {
77                 return (ev->state & RelevantModifierKeyMask) == 0;
78         }
79
80         bool leave_window (GdkEventCrossing *ev, Gtk::Window*);
81         bool enter_window (GdkEventCrossing *ev, Gtk::Window*);
82
83         static bool modifier_state_contains (guint state, ModifierMask);
84         static bool modifier_state_equals   (guint state, ModifierMask);
85
86         static Selection::Operation selection_type (guint state);
87
88         static bool no_modifiers_active (guint state);
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         static bool some_magic_widget_has_focus ();
110         static void magic_widget_grab_focus ();
111         static void magic_widget_drop_focus ();
112
113   private:
114         static Keyboard* _the_keyboard;
115
116         guint           snooper_id;
117         State           state;
118
119         static guint     edit_but;
120         static guint     edit_mod;
121         static guint     delete_but;
122         static guint     delete_mod;
123         static guint     snap_mod;
124         static Gtk::Window* current_window;
125
126         static gint _snooper (GtkWidget*, GdkEventKey*, gpointer);
127         gint snooper (GtkWidget*, GdkEventKey*);
128
129         static void set_modifier (uint32_t newval, uint32_t& variable);
130
131         static bool _some_magic_widget_has_focus;
132 };
133
134 #endif /* __ardour_keyboard_h__ */