]> git.lyx.org Git - lyx.git/blobdiff - src/KeyMap.cpp
Fix memory leak.
[lyx.git] / src / KeyMap.cpp
index fe3092b50931cd50ab81d3169ebd9e3aff4a9d56..8e4458d48593caf76cbf5aef41031c4a8a2f2bcf 100644 (file)
 #include "LyXAction.h"
 #include "Lexer.h"
 
-#include "frontends/KeySymbol.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(KeySymbol 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;
@@ -170,9 +167,8 @@ bool KeyMap::read(string const & bind_file)
 }
 
 
-FuncRequest const &
-KeyMap::lookup(KeySymbolPtr key,
-                 key_modifier::state mod, KeySequence * 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(KeySymbolPtr 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,7 +212,7 @@ 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;
@@ -226,17 +221,17 @@ docstring const KeyMap::print(bool forgui) const
 
 void KeyMap::defkey(KeySequence * seq, FuncRequest const & func, unsigned int r)
 {
-       KeySymbolPtr 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
@@ -322,18 +317,4 @@ KeyMap::Bindings KeyMap::findbindings(FuncRequest const & func,
 }
 
 
-std::pair<KeySymbol 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<KeySymbol const *, key_modifier::state>(0, key_modifier::none);
-}
-
-
 } // namespace lyx