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 "kbsequence.h"
20 #include "commandtags.h"
32 // The only modifiers that we handle. We want to throw away things
34 enum { ModsMask = ShiftMask | ControlMask | Mod1Mask };
37 int kb_sequence::addkey(unsigned int key, key_modifier::state mod, key_modifier::state nmod)
39 // adding a key to a deleted sequence
40 // starts a new sequence
48 modifiers.push_back(make_pair(mod, nmod));
49 sequence.push_back(key);
53 return curmap->lookup(key, mod, this);
56 return LFUN_UNKNOWN_ACTION;
60 string::size_type kb_sequence::parse(string const & s)
62 if (s.empty()) return 1;
64 string::size_type i = 0;
65 key_modifier::state mod = key_modifier::none;
66 key_modifier::state nmod = key_modifier::none;
68 while (i < s.length()) {
74 if (i + 1 < s.length() && s[i + 1] == '-') {
77 mod |= key_modifier::shift;
81 mod |= key_modifier::ctrl;
85 mod |= key_modifier::alt;
91 } else if (i + 2 < s.length() && s[i] == '~'
95 nmod |= key_modifier::shift;
99 nmod |= key_modifier::ctrl;
103 nmod |= key_modifier::alt;
111 string::size_type j = i;
112 for (; j < s.length() && s[j] != ' '; ++j)
113 tbuf += s[j]; // (!!!check bounds :-)
115 KeySym key = XStringToKeysym(tbuf.c_str());
116 if (key == NoSymbol) {
118 << "kbmap.C: No such keysym: "
124 addkey(key, mod, nmod);
125 mod = key_modifier::none;
133 // everything is fine
138 string const kb_sequence::print() const
145 for (vector<unsigned int>::size_type i = 0; i < length_; ++i) {
146 buf += kb_keymap::printKeysym(sequence[i], modifiers[i].first);
149 if (i + 1 < length_) {
157 string const kb_sequence::printOptions() const
166 buf += _(" options: ");
167 buf += curmap->print();
172 void kb_sequence::mark_deleted()
178 unsigned int kb_sequence::getsym() const
180 if (length_ == 0) return NoSymbol;
181 return sequence[length_ - 1];
185 char kb_sequence::getiso() const
187 unsigned int const c = getsym();
189 lyxerr[Debug::KBMAP] << "Raw keysym: "
190 << hex << c << dec << endl;
191 lyxerr[Debug::KBMAP] << "byte 3: "
192 << hex << (c & 0xff00) << dec
194 return kb_keymap::getiso(c);
198 void kb_sequence::reset()
204 void kb_sequence::clear()