3 * Copyright 1995-2002 the LyX Team
4 * Read the file COPYING
6 * \author John Levon <moz@compsoc.man.ac.uk>
14 #pragma implementation
17 #include "frontends/mouse_state.h"
18 #include "frontends/LyXKeySymFactory.h"
19 #include "kbsequence.h"
21 #include "commandtags.h"
32 int kb_sequence::addkey(LyXKeySymPtr key,
33 key_modifier::state mod, key_modifier::state nmod)
35 // adding a key to a deleted sequence
36 // starts a new sequence
43 modifiers.push_back(make_pair(mod, nmod));
44 sequence.push_back(key);
47 return curmap->lookup(key, mod, this);
50 return LFUN_UNKNOWN_ACTION;
54 string::size_type kb_sequence::parse(string const & s)
56 if (s.empty()) return 1;
58 string::size_type i = 0;
59 key_modifier::state mod = key_modifier::none;
60 key_modifier::state nmod = key_modifier::none;
62 while (i < s.length()) {
68 if (i + 1 < s.length() && s[i + 1] == '-') {
71 mod |= key_modifier::shift;
75 mod |= key_modifier::ctrl;
79 mod |= key_modifier::alt;
85 } else if (i + 2 < s.length() && s[i] == '~'
89 nmod |= key_modifier::shift;
93 nmod |= key_modifier::ctrl;
97 nmod |= key_modifier::alt;
105 string::size_type j = i;
106 for (; j < s.length() && s[j] != ' '; ++j)
107 tbuf += s[j]; // (!!!check bounds :-)
109 LyXKeySymPtr key(LyXKeySymFactory::create());
112 if ( ! key->isOK() ) {
118 addkey(key, mod, nmod);
119 mod = key_modifier::none;
124 if (sequence.size() == 0)
127 // everything is fine
132 string const kb_sequence::print() const
139 KeySequence::size_type i, length = sequence.size();
141 for (i = 0; i < length; ++i) {
142 buf += kb_keymap::printKeysym(sequence[i], modifiers[i].first);
145 if (i + 1 < length) {
153 string const kb_sequence::printOptions() const
162 buf += _(" options: ");
163 buf += curmap->print();
168 void kb_sequence::mark_deleted()
174 LyXKeySymPtr kb_sequence::getsym() const
176 if (sequence.size() == 0)
177 return LyXKeySymPtr(LyXKeySymFactory::create());
178 return sequence.back();
182 char kb_sequence::getLastKeyEncoded() const
184 return getsym()->getISOEncoded();
188 void kb_sequence::reset()
194 void kb_sequence::clear()