Debian Codegraph @

src/action.cpp

raw
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * Copyright (C) 2005 Takuro Ashie
4 *
5 * This program 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, or (at your option)
8 * any later version.
9 *
10 * This program 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.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23
24 #include "action.h"
25 #include "utils.h"
26
27 Action::Action () :
28 m_name(""),
29 m_pmf(NULL),
30 m_key_bindings(NULL)
31 {
32 }
33
34
35 Action::Action (const std::string &name, FcitxHotkey* hotkey, PMF pmf)
36 : m_name (name),
37 m_pmf (pmf),
38 m_key_bindings(hotkey)
39 {
40 }
41
42 bool
43 Action::perform (AnthyInstance *performer)
44 {
45 if (m_pmf)
46 return (performer->*m_pmf) ();
47
48 return false;
49 }
50
51 bool
52 Action::perform (AnthyInstance *performer, const KeyEvent &key)
53 {
54 if (!m_pmf)
55 return false;
56
57 if (match_key_event (key)) {
58 if (m_pmf)
59 return (performer->*m_pmf) ();
60 }
61
62 return false;
63 }
64
65 bool
66 Action::match_key_event (const KeyEvent &key)
67 {
68 return util_match_key_event (m_key_bindings, key, FcitxKeyState_CapsLock);
69 }
70
71 bool
72 Action::match_action_name (const char *name)
73 {
74 return (m_name.compare (name) == 0);
75 }