Debian Codegraph @

src/common.h

raw
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * Copyright (C) 2012 CSSlayer
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 #ifndef __FCITX_ANTHY_COMMON_H__
21 #define __FCITX_ANTHY_COMMON_H__
22
23 #include <fcitx-config/hotkey.h>
24 #include <string>
25 #include <vector>
26 #include <libintl.h>
27
28 #define FCITX_ANTHY_CONFIG_DICT_ENCODING_DEFAULT "UTF-8"
29
30 class KeyEvent {
31 public:
32 FcitxKeySym sym;
33 unsigned int state;
34 unsigned int keycode;
35 bool is_release;
36
37 KeyEvent() {
38 sym = FcitxKey_None;
39 state = FcitxKeyState_None;
40 is_release = false;
41 }
42
43 unsigned char get_ascii_code() const {
44
45 if (sym >= FcitxKey_space && sym <= FcitxKey_asciitilde)
46 return (char) sym;
47
48 if (sym >= FcitxKey_KP_0 && sym <= FcitxKey_KP_9)
49 return (char) (sym - FcitxKey_KP_0 + FcitxKey_0);
50
51 if (sym == FcitxKey_Return)
52 return 0x0d;
53 if (sym == FcitxKey_Linefeed)
54 return 0x0a;
55 if (sym == FcitxKey_Tab)
56 return 0x09;
57 if (sym == FcitxKey_BackSpace)
58 return 0x08;
59 if (sym == FcitxKey_Escape)
60 return 0x1b;
61
62 return 0;
63 }
64
65 bool operator == (const KeyEvent& event) const {
66 return sym == event.sym && state == event.state;
67 }
68
69 bool empty() const {
70 return sym == FcitxKey_None;
71 }
72 };
73
74 #define _(x) dgettext("fcitx-anthy", (x))
75
76 typedef std::vector<KeyEvent> KeyEventList;
77
78 #endif