]> git.lyx.org Git - lyx.git/blobdiff - src/kbsequence.C
Add GTK bibitem dialog
[lyx.git] / src / kbsequence.C
index b3865a1a65ef6904c4f31ca729afa91673132ebd..0d701cdb28ea982ad740bf828fecd98f9f4d7287 100644 (file)
@@ -1,59 +1,51 @@
 /**
  * \file kbsequence.C
- * Copyright 1995-2002 the LyX Team
- * Read the file COPYING
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- * \author John Levon <moz@compsoc.man.ac.uk>
+ * \author Lars Gullik Bjønnes
+ * \author Jean-Marc Lasgouttes
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS.
  */
 
 #include <config.h>
 
-#include "gettext.h"
-
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
-#include "frontends/mouse_state.h"
 #include "kbsequence.h"
+
+#include "gettext.h"
 #include "kbmap.h"
-#include "commandtags.h"
-#include "debug.h"
+#include "lfuns.h"
 
-#include <X11/Xlib.h>
+#include "frontends/LyXKeySym.h"
+#include "frontends/LyXKeySymFactory.h"
 
 using std::make_pair;
-using std::vector;
-using std::endl;
-using std::hex;
-using std::dec;
-
-
-// The only modifiers that we handle. We want to throw away things
-// like NumLock.
-enum { ModsMask = ShiftMask | ControlMask | Mod1Mask };
+using std::string;
 
 
-int kb_sequence::addkey(unsigned int key, key_modifier::state mod, key_modifier::state 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(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;
 }
 
 
@@ -64,7 +56,7 @@ string::size_type kb_sequence::parse(string const & s)
        string::size_type i = 0;
        key_modifier::state mod = key_modifier::none;
        key_modifier::state nmod = key_modifier::none;
+
        while (i < s.length()) {
                if (s[i] == ' ')
                        ++i;
@@ -112,13 +104,13 @@ string::size_type kb_sequence::parse(string const & s)
                        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);
@@ -127,7 +119,7 @@ string::size_type kb_sequence::parse(string const & s)
        }
 
        // empty sequence?
-       if (!length_)
+       if (sequence.size() == 0)
                return 0;
 
        // everything is fine
@@ -142,11 +134,13 @@ string const kb_sequence::print() const
        //if (deleted_)
        //      return buf;
 
-       for (vector<unsigned int>::size_type i = 0; i < length_; ++i) {
-               buf += kb_keymap::printKeysym(sequence[i], modifiers[i].first);
+       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 += ' ';
                }
        }
@@ -175,26 +169,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: "
-                            << hex << c << dec << endl;
-       lyxerr[Debug::KBMAP] << "byte 3: "
-                            << hex << (c & 0xff00) << dec
-                            << endl;
-       return kb_keymap::getiso(c);
-}
-
-
 void kb_sequence::reset()
 {
        mark_deleted();
@@ -203,6 +177,6 @@ void kb_sequence::reset()
 
 void kb_sequence::clear()
 {
-       length_ = 0;
+       sequence.clear();
        reset();
 }