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