1 // Copyright (C) 2009-2015 Petr Pavlu <setup@dagobah.cz>
3 // This file is part of CenterIM.
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.
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/>.
19 /// InputProcessor base class implementation.
21 /// @ingroup cppconsui
23 #include "InputProcessor.h"
24 #include "KeyConfig.h"
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
))
38 // Hand of input to a child.
39 if (input_child_
!= nullptr && input_child_
->processInput(key
))
42 // Process other key combinations.
43 if (process(BINDABLE_NORMAL
, key
))
46 // Do non-combo input processing.
47 TermKeyKey keyn
= Keys::refineKey(key
);
48 if (keyn
.type
== TERMKEY_TYPE_UNICODE
&& processInputText(keyn
))
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());
78 KeyConfig::KeyBindContext::const_iterator j
= keys
->find(key
);
82 BindableContext::iterator k
= keybind
.second
.find(j
->second
);
83 if (k
!= keybind
.second
.end() && k
->second
.type
== type
) {
92 bool InputProcessor::processInputText(const TermKeyKey
& /*key*/)
97 } // namespace CppConsUI
99 // vim: set tabstop=2 shiftwidth=2 textwidth=80 expandtab: