X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fkbsequence.C;h=dc1706dda6939b84980c55bc396ddbecf97b6545;hb=35204f8f33d7400a5fefeffea533fb4cb4097211;hp=afb091ee46d62c0593a3983a7e57b80c1acd6752;hpb=159544464a4e02a702aec062257fc6cce3ec7bfd;p=lyx.git diff --git a/src/kbsequence.C b/src/kbsequence.C index afb091ee46..dc1706dda6 100644 --- a/src/kbsequence.C +++ b/src/kbsequence.C @@ -1,54 +1,54 @@ -/* This file is part of - * ====================================================== +/** + * \file kbsequence.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. * - * LyX, The Document Processor - * - * Copyright 1995 Matthias Ettrich - * Copyright 1995-2001 The LyX Team. + * \author Lars Gullik Bjønnes + * \author Jean-Marc Lasgouttes + * \author John Levon * - * ====================================================== */ + * Full author contact details are available in file CREDITS. + */ #include -//#include -#include + +#include "kbsequence.h" #include "gettext.h" +#include "kbmap.h" +#include "lfuns.h" -#ifdef __GNUG__ -#pragma implementation -#endif +#include "frontends/LyXKeySym.h" +#include "frontends/LyXKeySymFactory.h" -#include "kbsequence.h" -#include "kbmap.h" -#include "debug.h" -using std::endl; +namespace lyx { -// The only modifiers that we handle. We want to throw away things -// like NumLock. -enum { ModsMask = ShiftMask | ControlMask | Mod1Mask }; +using std::make_pair; +using std::string; -kb_action kb_sequence::addkey(unsigned int key, unsigned int mod, unsigned int nmod) +FuncRequest const & +kb_sequence::addkey(LyXKeySymPtr key, + key_modifier::state mod, key_modifier::state nmod) { // adding a key to a deleted sequence // starts a new sequence if (deleted_) { deleted_ = false; - length_ = 0; sequence.clear(); modifiers.clear(); } - modifiers.push_back(mod + (nmod << 16)); + modifiers.push_back(make_pair(mod, nmod)); sequence.push_back(key); - ++length_; if (curmap) { return curmap->lookup(key, mod, this); } - - return LFUN_UNKNOWN_ACTION; + + static FuncRequest unknown(LFUN_UNKNOWN_ACTION); + return unknown; } @@ -57,26 +57,27 @@ string::size_type kb_sequence::parse(string const & s) if (s.empty()) return 1; string::size_type i = 0; - unsigned int mod = 0; - unsigned int nmod = 0; + key_modifier::state mod = key_modifier::none; + key_modifier::state nmod = key_modifier::none; + while (i < s.length()) { if (s[i] == ' ') ++i; if (i >= s.length()) break; - + if (i + 1 < s.length() && s[i + 1] == '-') { switch (s[i]) { case 's': case 'S': - mod |= ShiftMask; + mod |= key_modifier::shift; i += 2; continue; case 'c': case 'C': - mod |= ControlMask; + mod |= key_modifier::ctrl; i += 2; continue; case 'm': case 'M': - mod |= Mod1Mask; + mod |= key_modifier::alt; i += 2; continue; default: @@ -86,15 +87,15 @@ string::size_type kb_sequence::parse(string const & s) && s[i + 2] == '-') { switch (s[i + 1]) { case 's': case 'S': - nmod |= ShiftMask; + nmod |= key_modifier::shift; i += 3; continue; case 'c': case 'C': - nmod |= ControlMask; + nmod |= key_modifier::ctrl; i += 3; continue; case 'm': case 'M': - nmod |= Mod1Mask; + nmod |= key_modifier::alt; i += 3; continue; default: @@ -105,23 +106,23 @@ string::size_type kb_sequence::parse(string const & s) string::size_type j = i; for (; j < s.length() && s[j] != ' '; ++j) tbuf += s[j]; // (!!!check bounds :-) - - KeySym key = XStringToKeysym(tbuf.c_str()); - if (key == NoSymbol) { - lyxerr[Debug::KBMAP] - << "kbmap.C: No such keysym: " - << tbuf << endl; + + LyXKeySymPtr key(LyXKeySymFactory::create()); + key->init(tbuf); + + if ( ! key->isOK() ) { return j; } + i = j; - + addkey(key, mod, nmod); - mod = 0; + mod = key_modifier::none; } } - + // empty sequence? - if (!length_) + if (sequence.size() == 0) return 0; // everything is fine @@ -133,14 +134,16 @@ string const kb_sequence::print() const { string buf; - if (deleted_) - return buf; - - for (std::vector::size_type i = 0; i < length_; ++i) { - buf += kb_keymap::printKeysym(sequence[i], modifiers[i] & 0xffff); + //if (deleted_) + // return buf; + + KeySequence::size_type i, length = sequence.size(); + + for (i = 0; i < length; ++i) { + buf += sequence[i]->print(modifiers[i].first); // append a blank - if (i + 1 < length_) { + if (i + 1 < length) { buf += ' '; } } @@ -157,7 +160,7 @@ string const kb_sequence::printOptions() const if (!curmap) return buf; - buf += _(" options: "); + buf += to_utf8(_(" options: ")); buf += curmap->print(); return buf; } @@ -169,26 +172,6 @@ void kb_sequence::mark_deleted() } -unsigned int kb_sequence::getsym() const -{ - if (length_ == 0) return NoSymbol; - return sequence[length_ - 1]; -} - - -char kb_sequence::getiso() const -{ - unsigned int const c = getsym(); - - lyxerr[Debug::KBMAP] << "Raw keysym: " - << std::hex << c << std::dec << endl; - lyxerr[Debug::KBMAP] << "byte 3: " - << std::hex << (c & 0xff00) << std::dec - << endl; - return kb_keymap::getiso(c); -} - - void kb_sequence::reset() { mark_deleted(); @@ -197,6 +180,9 @@ void kb_sequence::reset() void kb_sequence::clear() { - length_ = 0; + sequence.clear(); reset(); } + + +} // namespace lyx