4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
8 * \author Jean-Marc Lasgouttes
11 * Full author contact details are available in file CREDITS.
17 #include "funcrequest.h"
19 #include "frontends/key_state.h"
20 #include "frontends/LyXKeySym.h"
22 #include "support/docstream.h"
24 #include <boost/shared_ptr.hpp>
34 /// Defines key maps and actions for key sequences
38 * Bind a key sequence to an action.
39 * @return 0 on success, or position in string seq where error
41 * See kb_sequence::parse for the syntax of the seq string
43 std::string::size_type bind(std::string const & seq, FuncRequest const & func);
46 bool read(std::string const & bind_file);
48 /// print all available keysyms
49 docstring const print() const;
52 * Look up a key press in the keymap.
53 * @param key the keysym
54 * @param mod the modifiers
55 * @param seq the current key sequence so far
56 * @return the action / LFUN_COMMAND_PREFIX / LFUN_UNKNOWN_ACTION
59 lookup(LyXKeySymPtr key,
60 key_modifier::state mod, kb_sequence * seq) const;
63 typedef std::deque<kb_sequence> Bindings;
65 /// Given an action, find all keybindings.
66 Bindings findbindings(FuncRequest const & func) const;
68 /// Given an action, print the keybindings.
69 docstring const printbindings(FuncRequest const & func) const;
72 * Given an action, find the first 1-key binding (if it exists).
73 * The LyXKeySym pointer is 0 is no key is found.
74 * [only used by the Qt/Mac frontend]
76 std::pair<LyXKeySym const *, key_modifier::state>
77 find1keybinding(FuncRequest const & func) const;
81 * Returns a string of the given keysym, with modifiers.
82 * @param key the key as a keysym
83 * @param mod the modifiers
85 static std::string const printKeySym(LyXKeySym const & key,
86 key_modifier::state mod);
88 typedef std::pair<key_modifier::state, key_modifier::state> modifier_pair;
99 /// Keymap for prefix keys
100 boost::shared_ptr<kb_keymap> table;
102 /// Action for !prefix keys
107 * Define an action for a key sequence.
108 * @param r internal recursion level
110 void defkey(kb_sequence * seq, FuncRequest const & func,
113 /// Returns a string of the given key
114 docstring const printKey(kb_key const & key) const;
117 * Given an action, find all keybindings
118 * @param func the action
119 * @param prefix a sequence to prepend the results
121 Bindings findbindings(FuncRequest const & func,
122 kb_sequence const & prefix) const;
124 /// is the table empty ?
126 return table.empty();
129 typedef std::vector<kb_key> Table;
134 /// Implementation is in lyx_main.C
135 extern kb_keymap & theTopLevelKeymap();