Debian Codegraph @

src/preedit.h

raw
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * Copyright (C) 2004 Takuro Ashie
4 * Copyright (C) 2012 CSSlayer
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20
21 #ifndef __FCITX_ANTHY_PREEDIT_H__
22 #define __FCITX_ANTHY_PREEDIT_H__
23
24 #include <anthy/anthy.h>
25 #include "reading.h"
26 #include "conversion.h"
27
28 #define FCITX_ANTHY_PSEUDO_ASCII_TRIGGERED_CAPITALIZED (1 << 0)
29 #define FCITX_ANTHY_PSEUDO_ASCII_TRIGGERED_COUPLE_OF_CAPITAL (1 << 1)
30
31 class AnthyInstance;
32
33 class Preedit
34 {
35 public:
36 Preedit (AnthyInstance &anthy);
37 virtual ~Preedit ();
38
39 // getting status
40 unsigned int get_length (void);
41 unsigned int get_length_by_char (void);
42 std::string get_string (void);
43 void update_preedit (void);
44 Reading &get_reading (void);
45
46 bool is_preediting (void);
47 bool is_converting (void);
48 bool is_predicting (void);
49 bool is_reconverting (void);
50
51 // for handling the preedit string
52 bool can_process_key_event (const KeyEvent & key);
53 // return true if commiting is needed.
54 bool process_key_event (const KeyEvent & key);
55 bool append (const KeyEvent & key,
56 const std::string & string);
57 void erase (bool backward = true);
58 void finish (void);
59
60 // for handling the conversion string
61 void convert (CandidateType type
62 = FCITX_ANTHY_CANDIDATE_DEFAULT,
63 bool single_segment = false);
64 void convert (const std::string &source,
65 bool single_segment = false);
66 void revert (void);
67 void commit (int segment_id = -1,
68 bool lean = true);
69
70 // for prediction
71 void predict (void);
72
73 // segments of the converted sentence
74 int get_nr_segments (void);
75 std::string get_segment_string (int segment_id = -1);
76 int get_selected_segment (void);
77 void select_segment (int segment_id);
78 int get_segment_size (int segment_id = -1);
79 void resize_segment (int relative_size,
80 int segment_id = -1);
81
82 // candidates for a segment
83 void get_candidates (FcitxCandidateWordList *table,
84 int segment_id = -1);
85 int get_selected_candidate (int segment_id = -1);
86 void select_candidate (int candidate_id,
87 int segment_id = -1);
88
89 // for handling the caret
90 unsigned int get_caret_pos (void);
91 void set_caret_pos_by_char (unsigned int pos);
92 void move_caret (int len);
93
94 // clear all or part of the string.
95 void clear (int segment_id = -1);
96
97 // preferences
98 void set_input_mode (InputMode mode);
99 InputMode get_input_mode (void);
100 void set_typing_method (TypingMethod method);
101 TypingMethod get_typing_method (void);
102 void set_period_style (PeriodStyle style);
103 PeriodStyle get_period_style (void);
104 void set_comma_style (CommaStyle style);
105 CommaStyle get_comma_style (void);
106 void set_bracket_style (BracketStyle style);
107 BracketStyle get_bracket_style (void);
108 void set_slash_style (SlashStyle style);
109 SlashStyle get_slash_style (void);
110 void set_symbol_width (bool half);
111 bool get_symbol_width (void);
112 void set_number_width (bool half);
113 bool get_number_width (void);
114 void set_pseudo_ascii_mode (int mode);
115 bool is_pseudo_ascii_mode (void);
116 void reset_pseudo_ascii_mode(void);
117
118 private:
119 void get_reading_substr (std::string & substr,
120 unsigned int start,
121 unsigned int len,
122 CandidateType type);
123 bool is_comma_or_period (const std::string & str);
124
125 private:
126 AnthyInstance &m_anthy;
127
128 // converter objects
129 Reading m_reading;
130 Conversion m_conversion;
131
132 // mode flags
133 InputMode m_input_mode;
134
135 // source string for reconversion
136 std::string m_source;
137 };
138
139 #endif /* __FCITX_ANTHY_PREEDIT_H__ */
140 /*
141 vi:ts=4:nowrap:ai:expandtab
142 */