Merge libs/ardour and gtk2_ardour with 2.0-ongoing R2837.
[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
29 #include <ardour/types.h>
30 #include <pbd/stateful.h>
31
32 #include "selection.h"
33
34 using std::vector;
35 using std::string;
36
37 class Keyboard : public sigc::trackable, PBD::Stateful
38 {
39   public:
40         Keyboard ();
41         ~Keyboard ();
42
43         XMLNode& get_state (void);
44         int set_state (const XMLNode&);
45
46         typedef vector<uint32_t> State;
47         typedef uint32_t ModifierMask;
48
49         static uint32_t PrimaryModifier;
50         static uint32_t SecondaryModifier;
51         static uint32_t TertiaryModifier;
52         static uint32_t CopyModifier;
53         static uint32_t RangeSelectModifier;
54
55         static void set_primary_modifier (uint32_t newval) {
56                 set_modifier (newval, PrimaryModifier);
57         }
58         static void set_secondary_modifier (uint32_t newval) {
59                 set_modifier (newval, SecondaryModifier);
60         }
61         static void set_tertiary_modifier (uint32_t newval) {
62                 set_modifier (newval, TertiaryModifier);
63         }
64         static void set_copy_modifier (uint32_t newval) {
65                 set_modifier (newval, CopyModifier);
66         }
67         static void set_range_select_modifier (uint32_t newval) {
68                 set_modifier (newval, RangeSelectModifier);
69         }
70
71         bool key_is_down (uint32_t keyval);
72
73         static GdkModifierType RelevantModifierKeyMask;
74
75         static bool no_modifier_keys_pressed(GdkEventButton* ev) {
76                 return (ev->state & RelevantModifierKeyMask) == 0;
77         }
78
79         bool leave_window (GdkEventCrossing *ev, Gtk::Window*);
80         bool enter_window (GdkEventCrossing *ev, Gtk::Window*);
81
82         static bool modifier_state_contains (guint state, ModifierMask);
83         static bool modifier_state_equals   (guint state, ModifierMask);
84
85         static Selection::Operation selection_type (guint state);
86
87         static bool no_modifiers_active (guint state);
88
89         static void set_snap_modifier (guint);
90         static ModifierMask snap_modifier () { return ModifierMask (snap_mod); }
91
92         static guint edit_button() { return edit_but; }
93         static void set_edit_button (guint);
94         static guint edit_modifier() { return edit_mod; }
95         static void set_edit_modifier(guint);
96
97         static guint delete_button() { return delete_but; }
98         static void set_delete_button(guint);
99         static guint delete_modifier() { return delete_mod; }
100         static void set_delete_modifier(guint);
101
102         static bool is_edit_event (GdkEventButton*);
103         static bool is_delete_event (GdkEventButton*);
104         static bool is_context_menu_event (GdkEventButton*);
105
106         static Keyboard& the_keyboard() { return *_the_keyboard; }
107
108         static bool some_magic_widget_has_focus ();
109         static void magic_widget_grab_focus ();
110         static void magic_widget_drop_focus ();
111
112   private:
113         static Keyboard* _the_keyboard;
114
115         guint           snooper_id;
116         State           state;
117
118         static guint     edit_but;
119         static guint     edit_mod;
120         static guint     delete_but;
121         static guint     delete_mod;
122         static guint     snap_mod;
123         static Gtk::Window* current_window;
124
125         static gint _snooper (GtkWidget*, GdkEventKey*, gpointer);
126         gint snooper (GtkWidget*, GdkEventKey*);
127
128         static void set_modifier (uint32_t newval, uint32_t& variable);
129
130         static bool _some_magic_widget_has_focus;
131 };
132
133 #endif /* __ardour_keyboard_h__ */