tizen 2.3.1 release
[framework/uifw/ise-engine-tables.git] / src / scim_table_imengine.h
1 /** @file scim_table_imengine.h
2  * definition of Table related classes.
3  */
4
5 /* 
6  * Smart Common Input Method
7  * 
8  * Copyright (c) 2002-2005 James Su <suzhe@tsinghua.org.cn>
9  * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24  *
25  * $Id: scim_table_imengine.h,v 1.3 2005/10/26 07:53:53 suzhe Exp $
26  *
27  * Modifications by Samsung Electronics Co., Ltd.
28  *
29  * 1.Added auto commit feature for mobile user
30  */
31
32 #if !defined (__SCIM_TABLE_IMENGINE_H)
33 #define __SCIM_TABLE_IMENGINE_H
34 #include "scim_generic_table.h"
35
36 /* phrase frequency cannot larger than this value (2^16 - 1) */
37 #define SCIM_GT_MAX_PHRASE_FREQ            0xFFFF
38
39 /* when a phrase is input,
40  * increase the freq by ((max_freq - cur_freq) >> delta)
41  */
42 #define SCIM_GT_PHRASE_FREQ_DELTA_SHIFT    10
43
44 using namespace scim;
45
46 class TableFactory : public IMEngineFactoryBase
47 {
48     GenericTableLibrary   m_table;
49
50     ConfigPointer         m_config;
51
52     std::vector<KeyEvent> m_full_width_punct_keys;
53     std::vector<KeyEvent> m_full_width_letter_keys;
54     std::vector<KeyEvent> m_mode_switch_keys;
55     std::vector<KeyEvent> m_add_phrase_keys;
56     std::vector<KeyEvent> m_del_phrase_keys;
57
58     String                m_table_filename;
59
60     bool                  m_is_user_table;
61
62     bool                  m_show_prompt;
63
64     bool                  m_show_key_hint;
65
66     bool                  m_user_table_binary;
67
68     bool                  m_user_phrase_first;
69
70     bool                  m_long_phrase_first;
71
72     time_t                m_last_time;
73
74     Connection            m_reload_signal_connection;
75
76     Property              m_status_property;
77     Property              m_letter_property;
78     Property              m_punct_property;
79
80     friend class TableInstance;
81
82 public:
83     TableFactory (const ConfigPointer &config);
84
85     virtual ~TableFactory ();
86
87     virtual WideString  get_name () const;
88     virtual WideString  get_authors () const;
89     virtual WideString  get_credits () const;
90     virtual WideString  get_help () const;
91     virtual String      get_uuid () const;
92     virtual String      get_icon_file () const;
93
94     virtual IMEngineInstancePointer create_instance (const String& encoding, int id = -1);
95
96     bool load_table (const String &table_file, bool user_table=false);
97
98     bool valid () const {
99         return m_table.valid ();
100     }
101
102 private:
103     void init (const ConfigPointer &config);
104
105     void save ();
106
107     String get_sys_table_freq_file ();
108     String get_sys_table_user_file ();
109
110     void refresh (bool rightnow = false);
111 };
112
113 class TableInstance : public IMEngineInstanceBase
114 {
115     Pointer <TableFactory>  m_factory;
116
117     bool m_double_quotation_state;
118     bool m_single_quotation_state;
119
120     bool m_full_width_punct [2];
121     bool m_full_width_letter [2];
122
123     bool m_forward;
124     bool m_focused;
125
126     std::vector<String>     m_inputted_keys;
127     std::vector<WideString> m_converted_strings;
128     std::vector<uint32>     m_converted_indexes;
129
130     CommonLookupTable       m_lookup_table;
131     CommonLookupTable       m_common_lookup_table;
132     std::vector <uint32>    m_lookup_table_indexes;
133
134     uint32                  m_inputing_caret;
135     uint32                  m_inputing_key;
136
137     IConvert                m_iconv;
138
139     KeyEvent                m_prev_key;
140
141     // 0 : Normal input mode
142     // 1 : Add phrase mode
143     // 2 : Add phrase success
144     // 3 : Add phrase failed
145     int                     m_add_phrase_mode;
146
147     WideString              m_last_committed;
148     WideString              m_preedit_string;
149
150 public:
151     TableInstance (TableFactory *factory,
152                          const String& encoding,
153                          int id = -1);
154     virtual ~TableInstance ();
155
156     virtual bool process_key_event (const KeyEvent& key);
157     virtual void move_preedit_caret (unsigned int pos);
158     virtual void select_candidate (unsigned int item);
159     virtual void update_lookup_table_page_size (unsigned int page_size);
160     virtual void lookup_table_page_up ();
161     virtual void lookup_table_page_down ();
162     virtual void reset ();
163     virtual void focus_in ();
164     virtual void focus_out ();
165     virtual void trigger_property (const String &property);
166
167     /**
168      * decide whether to display candidate window according to layout
169      */
170     virtual void set_layout (unsigned int layout);
171
172 private:
173     bool caret_left ();
174     bool caret_right ();
175     bool caret_home ();
176     bool caret_end ();
177     bool insert (char key);
178     bool test_insert (char key);
179     bool erase (bool backspace = true);
180     bool space_hit ();
181     bool enter_hit ();
182     bool lookup_cursor_up ();
183     bool lookup_cursor_down ();
184     bool lookup_cursor_up_to_longer ();
185     bool lookup_cursor_down_to_shorter ();
186     bool lookup_page_up ();
187     bool lookup_page_down ();
188     bool lookup_select (int index);
189     bool delete_phrase ();
190     bool post_process (char key);
191     void lookup_to_converted (int index);
192     void commit_converted ();
193
194     void refresh_preedit ();
195     /**
196      * @param show if show the lookup table
197      * @param refresh if refresh the content of lookup table.
198      */
199     void refresh_lookup_table (bool show=true, bool refresh=true);
200     void refresh_aux_string ();
201
202     void initialize_properties ();
203
204     void refresh_status_property ();
205     void refresh_letter_property ();
206     void refresh_punct_property ();
207
208     bool match_key_event (const std::vector<KeyEvent>& keyvec, const KeyEvent& key);
209 };
210
211 #endif
212 /*
213 vi:ts=4:nowrap:ai:expandtab
214 */
215