]> git.lyx.org Git - lyx.git/blob - src/kbmap.h
38516d8644bc512fbab831eab05721cd7bd9e8da
[lyx.git] / src / kbmap.h
1 // -*- C++ -*-
2 /**
3  * \file kbmap.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  * \author Jean-Marc Lasgouttes
9  * \author John Levon
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #ifndef KBMAP_H
15 #define KBMAP_H
16
17 #include "frontends/key_state.h"
18
19 #include <boost/shared_ptr.hpp>
20
21 #include "support/std_string.h"
22 #include <vector>
23
24 class kb_sequence;
25 class LyXKeySym;
26
27 /// Defines key maps and actions for key sequences
28 class kb_keymap {
29 public:
30         /**
31          * Bind a key sequence to an action.
32          * @return 0 on success, or position in string seq where error
33          * occurs.
34          * See kb_sequence::parse for the syntax of the seq string
35          */
36         string::size_type bind(string const & seq, int action);
37
38         // Parse a bind file
39         bool kb_keymap::read(string const & bind_file);
40
41         /// print all available keysyms
42         string const print() const;
43
44         ///
45         typedef boost::shared_ptr<LyXKeySym> LyXKeySymPtr;
46         /**
47          * Look up a key press in the keymap.
48          * @param key the keysym
49          * @param mod the modifiers
50          * @param seq the current key sequence so far
51          * @return the action / LFUN_PREFIX / LFUN_UNKNOWN_ACTION
52          */
53         int lookup(LyXKeySymPtr key,
54                    key_modifier::state mod, kb_sequence * seq) const;
55
56         /// Given an action, find all keybindings.
57         string const findbinding(int action,
58                                  string const & prefix = string()) const;
59
60         /**
61          * Returns a string of the given keysym, with modifiers.
62          * @param key the key as a keysym
63          * @param mod the modifiers
64          */
65         static string const printKeysym(LyXKeySymPtr key,
66                                         key_modifier::state mod);
67
68         typedef std::pair<key_modifier::state, key_modifier::state> modifier_pair;
69
70 private:
71         ///
72         struct kb_key {
73                 /// Keysym
74                 LyXKeySymPtr code;
75
76                 /// Modifier masks
77                 modifier_pair mod;
78
79                 /// Keymap for prefix keys
80                 boost::shared_ptr<kb_keymap> table;
81
82                 /// Action for !prefix keys
83                 int action;
84         };
85
86         /**
87          * Define an action for a key sequence.
88          * @param r internal recursion level
89          */
90         void defkey(kb_sequence * seq, int action, unsigned int r = 0);
91
92         ///  Returns a string of the given key
93         string const printKey(kb_key const & key) const;
94
95         /// is the table empty ?
96         bool empty() const {
97                 return table.empty();
98         }
99         ///
100         typedef std::vector<kb_key> Table;
101         ///
102         Table table;
103 };
104
105 #endif // KBMAP_H