Fix include name for the ncursesw library
[centerim5.git] / cppconsui / InputProcessor.cpp
blob42e137eb9726055eb1b0ace8b7c51cfbd37f66db
1 // Copyright (C) 2009-2015 Petr Pavlu <setup@dagobah.cz>
2 //
3 // This file is part of CenterIM.
4 //
5 // CenterIM is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // CenterIM is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with CenterIM. If not, see <http://www.gnu.org/licenses/>.
18 /// @file
19 /// InputProcessor base class implementation.
20 ///
21 /// @ingroup cppconsui
23 #include "InputProcessor.h"
24 #include "KeyConfig.h"
26 namespace CppConsUI {
28 InputProcessor::InputProcessor() : input_child_(nullptr)
32 bool InputProcessor::processInput(const TermKeyKey &key)
34 // Process overriding key combinations first.
35 if (process(BINDABLE_OVERRIDE, key))
36 return true;
38 // Hand of input to a child.
39 if (input_child_ != nullptr && input_child_->processInput(key))
40 return true;
42 // Process other key combinations.
43 if (process(BINDABLE_NORMAL, key))
44 return true;
46 // Do non-combo input processing.
47 TermKeyKey keyn = Keys::refineKey(key);
48 if (keyn.type == TERMKEY_TYPE_UNICODE && processInputText(keyn))
49 return true;
51 return false;
54 void InputProcessor::setInputChild(InputProcessor &child)
56 input_child_ = &child;
59 void InputProcessor::clearInputChild()
61 input_child_ = nullptr;
64 void InputProcessor::declareBindable(const char *context, const char *action,
65 const sigc::slot<void> &function, BindableType type)
67 keybindings_[context][action] = Bindable(function, type);
70 bool InputProcessor::process(BindableType type, const TermKeyKey &key)
72 for (Bindables::value_type &keybind : keybindings_) {
73 // Get keys for this context.
74 const KeyConfig::KeyBindContext *keys =
75 KEYCONFIG->getKeyBinds(keybind.first.c_str());
76 if (keys == nullptr)
77 continue;
78 KeyConfig::KeyBindContext::const_iterator j = keys->find(key);
79 if (j == keys->end())
80 continue;
82 BindableContext::iterator k = keybind.second.find(j->second);
83 if (k != keybind.second.end() && k->second.type == type) {
84 k->second.function();
85 return true;
89 return false;
92 bool InputProcessor::processInputText(const TermKeyKey & /*key*/)
94 return false;
97 } // namespace CppConsUI
99 // vim: set tabstop=2 shiftwidth=2 textwidth=80 expandtab: