Tizen 2.0 Release
[framework/uifw/ise-engine-anthy.git] / src / scim_anthy_action.cpp
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, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 #ifdef HAVE_CONFIG_H
21   #include <config.h>
22 #endif
23
24 #include "scim_anthy_action.h"
25 #include "scim_anthy_utils.h"
26
27 using namespace scim_anthy;
28
29 Action::Action (const String &name, const String &key_bindings, PMF pmf)
30     : m_name (name),
31       m_pmf  (pmf),
32       m_func (NULL)
33 {
34     scim_string_to_key_list (m_key_bindings, key_bindings);
35 }
36
37 Action::Action (const String &name, const String &key_bindings, Func func)
38     : m_name (name),
39       m_pmf  (NULL),
40       m_func (func)
41 {
42     scim_string_to_key_list (m_key_bindings, key_bindings);
43 }
44
45 Action::~Action (void)
46 {
47 }
48
49 bool
50 Action::perform (AnthyInstance *performer)
51 {
52     if (m_pmf)
53         return (performer->*m_pmf) ();
54     else if (m_func)
55         return m_func (performer);
56
57     return false;
58 }
59
60 bool
61 Action::perform (AnthyInstance *performer, const KeyEvent &key)
62 {
63     if (!m_pmf && !m_func)
64         return false;
65
66     if (match_key_event (key)) {
67         if (m_pmf)
68             return (performer->*m_pmf) ();
69         else if (m_func)
70             return m_func (performer);
71     }
72
73     return false;
74 }
75
76 bool
77 Action::match_key_event (const KeyEvent &key)
78 {
79     return util_match_key_event (m_key_bindings, key, SCIM_KEY_CapsLockMask);
80 }
81
82 bool
83 Action::match_action_name (const char *name)
84 {
85     return (m_name.compare (name) == 0);
86 }