]> git.lyx.org Git - lyx.git/blob - src/kbmap.h
Replace LString.h with support/std_string.h,
[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 "support/std_string.h"
18 #include "frontends/key_state.h"
19 #include "frontends/LyXKeySym.h"
20
21 #include <vector>
22
23 class kb_sequence;
24
25 /// Defines key maps and actions for key sequences
26 class kb_keymap {
27 public:
28         /**
29          * Bind a key sequence to an action.
30          * @return 0 on success, or position in string seq where error
31          * occurs.
32          * See kb_sequence::parse for the syntax of the seq string
33          */
34         string::size_type bind(string const & seq, int action);
35
36         // Parse a bind file
37         bool kb_keymap::read(string const & bind_file);
38
39         /// print all available keysyms
40         string const print() const;
41
42         /**
43          * Look up a key press in the keymap.
44          * @param key the keysym
45          * @param mod the modifiers
46          * @param seq the current key sequence so far
47          * @return the action / LFUN_PREFIX / LFUN_UNKNOWN_ACTION
48          */
49         int lookup(LyXKeySymPtr key,
50                    key_modifier::state mod, kb_sequence * seq) const;
51
52         /// Given an action, find all keybindings.
53         string const findbinding(int action,
54                                  string const & prefix = string()) const;
55
56         /**
57          * Returns a string of the given keysym, with modifiers.
58          * @param key the key as a keysym
59          * @param mod the modifiers
60          */
61         static string const printKeysym(LyXKeySymPtr key,
62                                         key_modifier::state mod);
63
64         typedef std::pair<key_modifier::state, key_modifier::state> modifier_pair;
65
66 private:
67         ///
68         struct kb_key {
69                 /// Keysym
70                 LyXKeySymPtr code;
71
72                 /// Modifier masks
73                 modifier_pair mod;
74
75                 /// Keymap for prefix keys
76                 boost::shared_ptr<kb_keymap> table;
77
78                 /// Action for !prefix keys
79                 int action;
80         };
81
82         /**
83          * Define an action for a key sequence.
84          * @param r internal recursion level
85          */
86         void defkey(kb_sequence * seq, int action, unsigned int r = 0);
87
88         ///  Returns a string of the given key
89         string const printKey(kb_key const & key) const;
90
91         /// is the table empty ?
92         bool empty() const {
93                 return table.empty();
94         }
95         ///
96         typedef std::vector<kb_key> Table;
97         ///
98         Table table;
99 };
100
101 #endif // KBMAP_H