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