Consider the case where there is not any layout name.
[lyx.git] / src / kbsequence.h
blob3d894a1ec31c54d1fe602cb7db77656a7d757095
1 // -*- C++ -*-
2 /**
3 * \file kbsequence.h
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
10 * Full author contact details are available in file CREDITS.
13 #ifndef KBSEQUENCE_H
14 #define KBSEQUENCE_H
16 #include "frontends/key_state.h"
18 #include <boost/shared_ptr.hpp>
20 #include <string>
21 #include <vector>
23 class kb_keymap;
24 class LyXKeySym;
25 class FuncRequest;
27 /// Holds a key sequence and the current and standard keymaps
28 class kb_sequence {
29 public:
30 typedef boost::shared_ptr<LyXKeySym> LyXKeySymPtr;
31 typedef std::vector<LyXKeySymPtr> KeySequence;
33 friend class kb_keymap;
35 ///
36 kb_sequence(kb_keymap * std, kb_keymap * cur)
37 : stdmap(std), curmap(cur), deleted_(false) {}
39 /**
40 * Add a key to the key sequence and look it up in the curmap
41 * if the latter is defined.
42 * @param keysym the key to add
43 * @param mod modifier mask
44 * @param nmod which modifiers to mask out for equality test
45 * @return the action matching this key sequence or LFUN_UNKNOWN_ACTION
47 FuncRequest const &
48 addkey(LyXKeySymPtr keysym, key_modifier::state mod,
49 key_modifier::state nmod = key_modifier::none);
51 /**
52 * Add a sequence of keys from a string to the sequence
53 * @return string::npos if OK, else error position in string
55 * Keys in the string must be separated with whitespace;
56 * Use the keysym names used by XStringToKeysym, f.ex.
57 * "Space", "a", "Return", ...
58 * Prefixes are S-, C-, M- for shift, control, meta
59 * Prefixes can also be ignored by using the Tilde "~"
60 * f.ex.: "~S-Space".
62 std::string::size_type parse(std::string const & s);
64 /**
65 * Return the current sequence as a string.
66 * @see parse()
68 std::string const print() const;
70 /**
71 * Return the current sequence and available options as
72 * a string. No options are added if no curmap kb map exists.
74 std::string const printOptions() const;
76 /// Mark the sequence as deleted.
77 void mark_deleted();
79 /// Reset sequence to become "deleted"
80 void reset();
82 /// clear in full
83 void clear();
85 bool deleted() const {
86 return deleted_;
89 /// length of sequence
90 KeySequence::size_type length() const {
91 return sequence.size();
94 /// Keymap to use if a new sequence is starting
95 kb_keymap * stdmap;
97 /// Keymap to use for the next key
98 kb_keymap * curmap;
100 private:
102 * Array holding the current key sequence as KeySyms.
103 * If sequence[length - 1] < 0xff it can be used as ISO8859 char
105 KeySequence sequence;
107 typedef std::pair<key_modifier::state, key_modifier::state>
108 modifier_pair;
110 /// modifiers for keys in the sequence
111 std::vector<modifier_pair> modifiers;
113 /// is keysequence deleted ?
114 bool deleted_;
117 #endif