]> git.lyx.org Git - lyx.git/blobdiff - src/KeyMap.cpp
Fix memory leak.
[lyx.git] / src / KeyMap.cpp
index 354a8d62bfe1bf1484a73ee5b71380e3a3610337..8e4458d48593caf76cbf5aef41031c4a8a2f2bcf 100644 (file)
 #include "KeyMap.h"
 
 #include "debug.h"
-#include "kb_sequence.h"
+#include "KeySequence.h"
 #include "LyXAction.h"
 #include "Lexer.h"
 
-#include "frontends/LyXKeySym.h"
-
 #include "support/filetools.h"
 
 #include <sstream>
 
+using std::endl;
+using std::string;
+
 
 namespace lyx {
 
 using support::FileName;
 using support::i18nLibFileSearch;
 
-using std::endl;
-using std::string;
 
-
-string const KeyMap::printKeySym(LyXKeySym const & key,
-                                   key_modifier::state mod)
+string const KeyMap::printKeySym(KeySymbol const & key, KeyModifier mod)
 {
        string buf;
 
        string const s = key.getSymbolName();
 
-       if (mod & key_modifier::shift)
+       if (mod & ShiftModifier)
                buf += "S-";
-       if (mod & key_modifier::ctrl)
+       if (mod & ControlModifier)
                buf += "C-";
-       if (mod & key_modifier::alt)
+       if (mod & AltModifier)
                buf += "M-";
 
        buf += s;
@@ -61,7 +58,7 @@ size_t KeyMap::bind(string const & seq, FuncRequest const & func)
               << seq << "' Action `"
               << func.action << '\'' << endl;
 
-       kb_sequence k(0, 0);
+       KeySequence k(0, 0);
 
        string::size_type const res = k.parse(seq);
        if (res == string::npos) {
@@ -170,9 +167,8 @@ bool KeyMap::read(string const & bind_file)
 }
 
 
-FuncRequest const &
-KeyMap::lookup(LyXKeySymPtr key,
-                 key_modifier::state mod, kb_sequence * seq) const
+FuncRequest const & KeyMap::lookup(KeySymbol const &key,
+                 KeyModifier mod, KeySequence * seq) const
 {
        static FuncRequest const unknown(LFUN_UNKNOWN_ACTION);
 
@@ -184,11 +180,10 @@ KeyMap::lookup(LyXKeySymPtr key,
 
        Table::const_iterator end = table.end();
        for (Table::const_iterator cit = table.begin(); cit != end; ++cit) {
-               key_modifier::state mask(cit->mod.second);
-               key_modifier::state check =
-                       static_cast<key_modifier::state>(mod & ~mask);
+               KeyModifier mask = cit->mod.second;
+               KeyModifier check = static_cast<KeyModifier>(mod & ~mask);
 
-               if (*(cit->code) == *key && cit->mod.first == check) {
+               if (cit->code == key && cit->mod.first == check) {
                        // match found
                        if (cit->table.get()) {
                                // this is a prefix key - set new map
@@ -217,26 +212,26 @@ docstring const KeyMap::print(bool forgui) const
        docstring buf;
        Table::const_iterator end = table.end();
        for (Table::const_iterator cit = table.begin(); cit != end; ++cit) {
-               buf += cit->code->print(cit->mod.first, forgui);
+               buf += cit->code.print(cit->mod.first, forgui);
                buf += ' ';
        }
        return buf;
 }
 
 
-void KeyMap::defkey(kb_sequence * seq, FuncRequest const & func, unsigned int r)
+void KeyMap::defkey(KeySequence * seq, FuncRequest const & func, unsigned int r)
 {
-       LyXKeySymPtr code = seq->sequence[r];
-       if (!code->isOK())
+       KeySymbol code = seq->sequence[r];
+       if (!code.isOK())
                return;
 
-       key_modifier::state const mod1 = seq->modifiers[r].first;
-       key_modifier::state const mod2 = seq->modifiers[r].second;
+       KeyModifier const mod1 = seq->modifiers[r].first;
+       KeyModifier const mod2 = seq->modifiers[r].second;
 
        // check if key is already there
        Table::iterator end = table.end();
        for (Table::iterator it = table.begin(); it != end; ++it) {
-               if (*(code) == *(it->code)
+               if (code == it->code
                    && mod1 == it->mod.first
                    && mod2 == it->mod.second) {
                        // overwrite binding
@@ -253,7 +248,7 @@ void KeyMap::defkey(kb_sequence * seq, FuncRequest const & func, unsigned int r)
                                it->func.origin = FuncRequest::KEYBOARD;
                                return;
                        } else if (!it->table.get()) {
-                               lyxerr << "Error: New binding for '" 
+                               lyxerr << "Error: New binding for '"
                                       << to_utf8(seq->print(false))
                                       << "' is overriding old binding..."
                                               << endl;
@@ -292,12 +287,12 @@ docstring const KeyMap::printbindings(FuncRequest const & func) const
 
 KeyMap::Bindings KeyMap::findbindings(FuncRequest const & func) const
 {
-       return findbindings(func, kb_sequence(0, 0));
+       return findbindings(func, KeySequence(0, 0));
 }
 
 
 KeyMap::Bindings KeyMap::findbindings(FuncRequest const & func,
-                       kb_sequence const & prefix) const
+                       KeySequence const & prefix) const
 {
        Bindings res;
        if (table.empty()) return res;
@@ -306,13 +301,13 @@ KeyMap::Bindings KeyMap::findbindings(FuncRequest const & func,
        for (Table::const_iterator cit = table.begin();
            cit != end; ++cit) {
                if (cit->table.get()) {
-                       kb_sequence seq = prefix;
+                       KeySequence seq = prefix;
                        seq.addkey(cit->code, cit->mod.first);
                        Bindings res2 =
                                cit->table->findbindings(func, seq);
                        res.insert(res.end(), res2.begin(), res2.end());
                } else if (cit->func == func) {
-                       kb_sequence seq = prefix;
+                       KeySequence seq = prefix;
                        seq.addkey(cit->code, cit->mod.first);
                        res.push_back(seq);
                }
@@ -322,18 +317,4 @@ KeyMap::Bindings KeyMap::findbindings(FuncRequest const & func,
 }
 
 
-std::pair<LyXKeySym const *, key_modifier::state>
-KeyMap::find1keybinding(FuncRequest const & func) const
-{
-       Table::const_iterator end = table.end();
-       for (Table::const_iterator cit = table.begin();
-           cit != end; ++cit) {
-               if (!cit->table.get() && cit->func == func)
-                       return std::make_pair(cit->code.get(), cit->mod.first);
-       }
-
-       return std::make_pair<LyXKeySym const *, key_modifier::state>(0, key_modifier::none);
-}
-
-
 } // namespace lyx