Tizen 2.0 Release
[framework/uifw/ise-engine-anthy.git] / src / scim_anthy_imengine.h
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  *  Copyright (C) 2004 Hiroyuki Ikezoe
4  *  Copyright (C) 2004 Takuro Ashie
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, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  */
20
21 /*
22  * The original code is scim_uim_imengine.cpp in scim-uim-0.1.3. 
23  * Copyright (C) 2004 James Su <suzhe@tsinghua.org.cn>
24  */
25
26 #ifndef __SCIM_ANTHY_IMENGINE_H__
27 #define __SCIM_ANTHY_IMENGINE_H__
28
29 #define Uses_SCIM_IMENGINE
30 #define Uses_SCIM_CONFIG_BASE
31 #include <map>
32 #include <anthy/anthy.h>
33 #include <scim.h>
34 #include "scim_anthy_preedit.h"
35 #include "scim_anthy_key2kana_table.h"
36
37 using namespace scim;
38 using namespace scim_anthy;
39
40 class AnthyFactory;
41
42 namespace scim_anthy {
43
44 typedef enum {
45     SCIM_ANTHY_CONVERSION_MULTI_SEGMENT,
46     SCIM_ANTHY_CONVERSION_SINGLE_SEGMENT,
47     SCIM_ANTHY_CONVERSION_MULTI_SEGMENT_IMMEDIATE,
48     SCIM_ANTHY_CONVERSION_SINGLE_SEGMENT_IMMEDIATE,
49 } ConversionMode;
50
51 typedef void (*timeout_func) (void *data);
52 typedef void (*delete_func)  (void *data);
53
54 class TimeoutClosure
55 {
56 public:
57     TimeoutClosure ()
58         : m_time_msec  (0),
59           m_timeout_fn (NULL),
60           m_data       (NULL),
61           m_delete_fn  (NULL)
62         {}
63     TimeoutClosure  (uint32        time_msec,
64                      timeout_func  timeout_fn,
65                      void         *data,
66                      delete_func   delete_fn)
67         : m_time_msec  (time_msec),
68           m_timeout_fn (timeout_fn),
69           m_data       (data),
70           m_delete_fn  (delete_fn)
71         {}
72     virtual ~TimeoutClosure ()
73         {
74             if (m_delete_fn && m_data)
75                 m_delete_fn (m_data);
76         }
77
78     void close (void) { m_timeout_fn (m_data); }
79 private:
80     uint32        m_time_msec;
81     timeout_func  m_timeout_fn;
82     void         *m_data;
83     delete_func   m_delete_fn;
84 };
85
86 typedef std::map<int, TimeoutClosure>  TimeoutClosures;
87
88 }
89
90 class AnthyInstance : public IMEngineInstanceBase
91 {
92 public:
93     AnthyInstance (AnthyFactory   *factory,
94                    const String   &encoding,
95                    int             id = -1);
96     virtual ~AnthyInstance ();
97
98     virtual bool process_key_event            (const KeyEvent& key);
99     virtual void move_preedit_caret           (unsigned int pos);
100     virtual void select_candidate             (unsigned int item);
101     virtual void update_lookup_table_page_size(unsigned int page_size);
102     virtual void lookup_table_page_up         (void);
103     virtual void lookup_table_page_down       (void);
104     virtual void reset                        (void);
105     virtual void focus_in                     (void);
106     virtual void focus_out                    (void);
107     virtual void trigger_property             (const String &property);
108     virtual void process_helper_event         (const String &helper_uuid,
109                                                const Transaction &trans);
110
111     virtual void reload_config                (const ConfigPointer &config);
112     virtual void flush ();
113
114 public:
115     /* actions */
116     bool   action_do_nothing                  (void);
117
118     bool   action_convert                     (void);
119     bool   action_predict                     (void);
120     bool   action_revert                      (void);
121     bool   action_cancel_all                  (void);
122     bool   action_commit_follow_preference    (void);
123     bool   action_commit_reverse_preference   (void);
124     bool   action_commit_first_segment        (void);
125     bool   action_commit_selected_segment     (void);
126     bool   action_commit_first_segment_reverse_preference
127                                               (void);
128     bool   action_commit_selected_segment_reverse_preference
129                                               (void);
130     bool   action_back                        (void);
131     bool   action_delete                      (void);
132     bool   action_insert_space                (void);
133     bool   action_insert_alternative_space    (void);
134     bool   action_insert_half_space           (void);
135     bool   action_insert_wide_space           (void);
136
137     bool   action_move_caret_backward         (void);
138     bool   action_move_caret_forward          (void);
139     bool   action_move_caret_first            (void);
140     bool   action_move_caret_last             (void);
141
142     bool   action_select_prev_segment         (void);
143     bool   action_select_next_segment         (void);
144     bool   action_select_first_segment        (void);
145     bool   action_select_last_segment         (void);
146     bool   action_shrink_segment              (void);
147     bool   action_expand_segment              (void);
148
149     bool   action_select_first_candidate      (void);
150     bool   action_select_last_candidate       (void);
151     bool   action_select_next_candidate       (void);
152     bool   action_select_prev_candidate       (void);
153     bool   action_candidates_page_up          (void);
154     bool   action_candidates_page_down        (void);
155
156     bool   action_select_candidate_1          (void);
157     bool   action_select_candidate_2          (void);
158     bool   action_select_candidate_3          (void);
159     bool   action_select_candidate_4          (void);
160     bool   action_select_candidate_5          (void);
161     bool   action_select_candidate_6          (void);
162     bool   action_select_candidate_7          (void);
163     bool   action_select_candidate_8          (void);
164     bool   action_select_candidate_9          (void);
165     bool   action_select_candidate_10         (void);
166
167     bool   action_convert_to_hiragana         (void);
168     bool   action_convert_to_katakana         (void);
169     bool   action_convert_to_half             (void);
170     bool   action_convert_to_half_katakana    (void);
171     bool   action_convert_to_latin            (void);
172     bool   action_convert_to_wide_latin       (void);
173     bool   action_convert_char_type_forward   (void);
174     bool   action_convert_char_type_backward  (void);
175     bool   action_reconvert                   (void);
176
177     bool   action_on_off                      (void);
178
179     bool   action_circle_input_mode           (void);
180     bool   action_circle_kana_mode            (void);
181     bool   action_circle_typing_method        (void);
182
183     bool   action_latin_mode                  (void);
184     bool   action_wide_latin_mode             (void);
185     bool   action_hiragana_mode               (void);
186     bool   action_katakana_mode               (void);
187     bool   action_half_katakana_mode          (void);
188     bool   action_cancel_pseudo_ascii_mode    (void);
189
190     bool   action_add_word                    (void);
191     bool   action_launch_dict_admin_tool      (void);
192     /*
193     void   actoin_register_word               (void);
194     */
195
196 public:
197     AnthyFactory *
198            get_factory                        (void);
199     TypingMethod
200            get_typing_method                  (void);
201     InputMode
202            get_input_mode                     (void);
203     int    timeout_add                        (uint32        time_msec,
204                                                timeout_func  timeout_fn,
205                                                void         *data = NULL,
206                                                delete_func   delete_fn = NULL);
207     void   timeout_remove                     (uint32        id);
208     int    get_pseudo_ascii_mode              (void);
209
210 private:
211     /* processing key event */
212     bool   process_key_event_input            (const KeyEvent &key);
213     bool   process_key_event_lookup_keybind   (const KeyEvent &key);
214     bool   process_key_event_latin_mode       (const KeyEvent &key);
215     bool   process_key_event_wide_latin_mode  (const KeyEvent &key);
216
217     /* utility */
218     void   set_preedition                     (void);
219     void   set_aux_string                     (void);
220     void   set_lookup_table                   (void);
221     void   unset_lookup_table                 (void);
222     void   install_properties                 (void);
223     void   set_input_mode                     (InputMode      mode);
224     void   set_conversion_mode                (ConversionMode mode);
225     void   set_typing_method                  (TypingMethod   method);
226     void   set_period_style                   (PeriodStyle    period,
227                                                CommaStyle     comma);
228     void   set_symbol_style                   (BracketStyle   bracket,
229                                                SlashStyle     slash);
230     bool   is_selecting_candidates            (void);
231     void   select_candidate_no_direct         (unsigned int   item);
232     bool   convert_kana                       (CandidateType  type);
233
234     bool   action_commit                      (bool           learn);
235     bool   action_select_candidate            (unsigned int   i);
236
237     bool   is_single_segment                  (void);
238     bool   is_realtime_conversion             (void);
239
240 private: // FIXME!
241     bool   is_nicola_thumb_shift_key          (const KeyEvent &key);
242
243 private:
244     AnthyFactory         *m_factory;
245
246     bool                  m_on_init;
247
248    /* for preedit */
249     Preedit               m_preedit;
250     bool                  m_preedit_string_visible;
251
252     /* for candidates window */
253     CommonLookupTable     m_lookup_table;
254     bool                  m_lookup_table_visible;
255     unsigned int          m_n_conv_key_pressed;
256
257     /* for toggling latin and wide latin */
258     InputMode             m_prev_input_mode;
259
260     /* for toolbar */
261     PropertyList          m_properties;
262
263     /*  */
264     ConversionMode        m_conv_mode;
265
266     /* for action */
267     KeyEvent              m_last_key;
268
269     /* Helper */
270     bool                  m_helper_started;
271
272     /* timeout */
273     uint32                m_timeout_id_seq;
274     TimeoutClosures       m_closures;
275 };
276 #endif /* __SCIM_ANTHY_IMENGINE_H__ */
277 /*
278 vi:ts=4:nowrap:ai:expandtab
279 */