]> git.lyx.org Git - lyx.git/blob - src/kbmap.h
typos
[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 #include "frontends/LyXKeySym.h"
21
22 #include "support/docstream.h"
23
24 #include <boost/shared_ptr.hpp>
25
26 #include <vector>
27 #include <deque>
28
29
30 namespace lyx {
31
32 class kb_sequence;
33
34 /// Defines key maps and actions for key sequences
35 class kb_keymap {
36 public:
37         /**
38          * Bind a key sequence to an action.
39          * @return 0 on success, or position in string seq where error
40          * occurs.
41          * See kb_sequence::parse for the syntax of the seq string
42          */
43         std::string::size_type bind(std::string const & seq, FuncRequest const & func);
44
45         // Parse a bind file
46         bool read(std::string const & bind_file);
47
48         /**
49          * print all available keysyms
50          * @param forgui true if the string should use translations and 
51          *   special characters. 
52          */
53         docstring const print(bool forgui) const;
54
55         /**
56          * Look up a key press in the keymap.
57          * @param key the keysym
58          * @param mod the modifiers
59          * @param seq the current key sequence so far
60          * @return the action / LFUN_COMMAND_PREFIX / LFUN_UNKNOWN_ACTION
61          */
62         FuncRequest const &
63         lookup(LyXKeySymPtr key,
64                key_modifier::state mod, kb_sequence * seq) const;
65
66         ///
67         typedef std::deque<kb_sequence> Bindings;
68
69         /// Given an action, find all keybindings.
70         Bindings findbindings(FuncRequest const & func) const;
71
72         /// Given an action, print the keybindings.
73         docstring const printbindings(FuncRequest const & func) const;
74
75         /**
76          *  Given an action, find the first 1-key binding (if it exists).
77          *  The LyXKeySym pointer is 0 is no key is found.
78          *  [only used by the Qt/Mac frontend]
79          */
80         std::pair<LyXKeySym const *, key_modifier::state>
81         find1keybinding(FuncRequest const & func) const;
82
83
84         /**
85          * Returns a string of the given keysym, with modifiers.
86          * @param key the key as a keysym
87          * @param mod the modifiers
88          */
89         static std::string const printKeySym(LyXKeySym const & key,
90                                              key_modifier::state mod);
91
92         typedef std::pair<key_modifier::state, key_modifier::state> modifier_pair;
93
94 private:
95         ///
96         struct kb_key {
97                 /// Keysym
98                 LyXKeySymPtr code;
99
100                 /// Modifier masks
101                 modifier_pair mod;
102
103                 /// Keymap for prefix keys
104                 boost::shared_ptr<kb_keymap> table;
105
106                 /// Action for !prefix keys
107                 FuncRequest func;
108         };
109
110         /**
111          * Define an action for a key sequence.
112          * @param r internal recursion level
113          */
114         void defkey(kb_sequence * seq, FuncRequest const & func,
115                     unsigned int r = 0);
116
117         /**
118          * Given an action, find all keybindings
119          * @param func the action
120          * @param prefix a sequence to prepend the results
121          */
122         Bindings findbindings(FuncRequest const & func,
123                               kb_sequence const & prefix) const;
124
125         /// is the table empty ?
126         bool empty() const {
127                 return table.empty();
128         }
129         ///
130         typedef std::vector<kb_key> Table;
131         ///
132         Table table;
133 };
134
135 /// Implementation is in lyx_main.C
136 extern kb_keymap & theTopLevelKeymap();
137
138
139 } // namespace lyx
140
141 #endif // KBMAP_H