]> git.lyx.org Git - lyx.git/blob - src/kbmap.h
* lyxfunc.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 "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 class kb_sequence;
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         std::string::size_type bind(std::string const & seq, FuncRequest const & func);
39
40         // Parse a bind file
41         bool read(std::string const & bind_file);
42
43         /// print all available keysyms
44         std::string const print() const;
45
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         FuncRequest const &
54         lookup(LyXKeySymPtr key,
55                key_modifier::state mod, kb_sequence * seq) const;
56
57         ///
58         typedef std::deque<kb_sequence> Bindings;
59
60         /// Given an action, find all keybindings.
61         Bindings findbindings(FuncRequest const & func) const;
62
63         /// Given an action, print the keybindings.
64         std::string const printbindings(FuncRequest const & func) const;
65
66         /**
67          *  Given an action, find the first 1-key binding (if it exists).
68          *  The LyXKeySym pointer is 0 is no key is found.
69          *  [only used by the Qt/Mac frontend]
70          */
71         std::pair<LyXKeySym const *, key_modifier::state>
72         find1keybinding(FuncRequest const & func) const;
73
74
75         /**
76          * Returns a string of the given keysym, with modifiers.
77          * @param key the key as a keysym
78          * @param mod the modifiers
79          */
80         static std::string const printKeySym(LyXKeySym const & key,
81                                              key_modifier::state mod);
82
83         typedef std::pair<key_modifier::state, key_modifier::state> modifier_pair;
84
85 private:
86         ///
87         struct kb_key {
88                 /// Keysym
89                 LyXKeySymPtr code;
90
91                 /// Modifier masks
92                 modifier_pair mod;
93
94                 /// Keymap for prefix keys
95                 boost::shared_ptr<kb_keymap> table;
96
97                 /// Action for !prefix keys
98                 FuncRequest func;
99         };
100
101         /**
102          * Define an action for a key sequence.
103          * @param r internal recursion level
104          */
105         void defkey(kb_sequence * seq, FuncRequest const & func,
106                     unsigned int r = 0);
107
108         ///  Returns a string of the given key
109         std::string const printKey(kb_key const & key) const;
110
111         /**
112          * Given an action, find all keybindings
113          * @param func the action
114          * @param prefix a sequence to prepend the results
115          */
116         Bindings findbindings(FuncRequest const & func,
117                               kb_sequence const & prefix) const;
118
119         /// is the table empty ?
120         bool empty() const {
121                 return table.empty();
122         }
123         ///
124         typedef std::vector<kb_key> Table;
125         ///
126         Table table;
127 };
128
129 #endif // KBMAP_H