1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2001 The LyX Team.
9 * ====================================================== */
18 #pragma implementation
21 #include "frontends/mouse_state.h"
22 #include "kbsequence.h"
24 #include "commandtags.h"
35 // The only modifiers that we handle. We want to throw away things
37 enum { ModsMask = ShiftMask | ControlMask | Mod1Mask };
40 int kb_sequence::addkey(unsigned int key, key_modifier::state mod, key_modifier::state nmod)
42 // adding a key to a deleted sequence
43 // starts a new sequence
51 modifiers.push_back(make_pair(mod, nmod));
52 sequence.push_back(key);
56 return curmap->lookup(key, mod, this);
59 return LFUN_UNKNOWN_ACTION;
63 string::size_type kb_sequence::parse(string const & s)
65 if (s.empty()) return 1;
67 string::size_type i = 0;
68 key_modifier::state mod = key_modifier::none;
69 key_modifier::state nmod = key_modifier::none;
70 while (i < s.length()) {
76 if (i + 1 < s.length() && s[i + 1] == '-') {
79 mod |= key_modifier::shift;
83 mod |= key_modifier::ctrl;
87 mod |= key_modifier::alt;
93 } else if (i + 2 < s.length() && s[i] == '~'
97 nmod |= key_modifier::shift;
101 nmod |= key_modifier::ctrl;
105 nmod |= key_modifier::alt;
113 string::size_type j = i;
114 for (; j < s.length() && s[j] != ' '; ++j)
115 tbuf += s[j]; // (!!!check bounds :-)
117 KeySym key = XStringToKeysym(tbuf.c_str());
118 if (key == NoSymbol) {
120 << "kbmap.C: No such keysym: "
126 addkey(key, mod, nmod);
127 mod = key_modifier::none;
135 // everything is fine
140 string const kb_sequence::print() const
147 for (vector<unsigned int>::size_type i = 0; i < length_; ++i) {
148 buf += kb_keymap::printKeysym(sequence[i], modifiers[i].first);
151 if (i + 1 < length_) {
159 string const kb_sequence::printOptions() const
168 buf += _(" options: ");
169 buf += curmap->print();
174 void kb_sequence::mark_deleted()
180 unsigned int kb_sequence::getsym() const
182 if (length_ == 0) return NoSymbol;
183 return sequence[length_ - 1];
187 char kb_sequence::getiso() const
189 unsigned int const c = getsym();
191 lyxerr[Debug::KBMAP] << "Raw keysym: "
192 << hex << c << dec << endl;
193 lyxerr[Debug::KBMAP] << "byte 3: "
194 << hex << (c & 0xff00) << dec
196 return kb_keymap::getiso(c);
200 void kb_sequence::reset()
206 void kb_sequence::clear()