Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/* vim:set et ts=4 sts=4:
*
* ibus-pinyin - The Chinese PinYin engine for IBus
*
* Copyright (c) 2008-2010 Peng Huang <shawn.p.huang@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __INPUT_CONTEXT_H_
#define __INPUT_CONTEXT_H_
#include <string>
#include <vector>
namespace PyZy {
class Config;
enum CandidateType {
NORMAL_PHRASE,
USER_PHRASE,
SPECIAL_PHRASE,
};
struct Candidate {
std::string text;
CandidateType type;
};
// lower 8bits of vkey_code should be zero.
enum vkey_code {
VKEY_FIRST = 1 << 8,
VKEY_COMMIT = (10 << 8),
VKEY_RESET = (11 << 8),
VKEY_CURSOR_RIGHT = (20 << 8),
VKEY_CURSOR_LEFT = (21 << 8),
VKEY_CURSOR_RIGHT_BY_WORD = (22 << 8),
VKEY_CURSOR_LEFT_BY_WORD = (23 << 8),
VKEY_CURSOR_TO_BEGIN = (24 << 8),
VKEY_CURSOR_TO_END = (25 << 8),
VKEY_CANDIDATE_SELECT = (30 << 8),
VKEY_CANDIDATE_FOCUS = (31 << 8),
VKEY_CANDIDATE_RESET = (32 << 8),
VKEY_PAGE_PREVIOUS = (40 << 8),
VKEY_PAGE_NEXT = (41 << 8),
VKEY_PAGE_BEGIN = (42 << 8),
VKEY_PAGE_END = (43 << 8),
VKEY_DELETE_CHARACTER_BEFORE = (50 << 8),
VKEY_DELETE_CHARACTER_AFTER = (51 << 8),
VKEY_DELETE_WORD_BEFORE = (52 << 8),
VKEY_DELETE_WORD_AFTER = (53 << 8),
VKEY_BOPOMOFO_SELECT_MODE = (60 << 8),
};
class InputContext {
public:
virtual ~InputContext (void) { }
class Observer {
public:
virtual ~Observer () { }
virtual void commitText (const std::string &commit_text) = 0;
virtual void preeditTextChanged () = 0;
virtual void auxiliaryTextChanged () = 0;
virtual void lookupTableChanged () = 0;
};
enum InputType {
FULL_PINYIN,
DOUBLE_PINYIN,
BOPOMOFO,
};
/* static functions */
static void init ();
static void init (const std::string & user_data_dir);
static void finalize ();
static InputContext * create (InputContext::InputType type,
Config & config,
InputContext::Observer * observer);
virtual bool processKeyEvent (unsigned short key_event) = 0;
virtual void update (void) = 0;
virtual void commit (void) = 0;
virtual void reset (void) = 0;
virtual std::string selectedText (void) const = 0;
virtual std::string conversionText (void) const = 0;
virtual std::string restText (void) const = 0;
virtual std::string auxiliaryText (void) const = 0;
virtual std::vector<Candidate> candidates () const = 0;
virtual std::string inputText () const = 0;
virtual unsigned int cursor () const = 0;
virtual unsigned int focusedCandidate () const = 0;
virtual unsigned int page () const = 0;
};
}; // namespace PyZy
#endif // __INPUT_CONTEXT_H_