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