1 /** @file scim_table_imengine.h
2 * definition of Table related classes.
6 * Smart Common Input Method
8 * Copyright (c) 2002-2005 James Su <suzhe@tsinghua.org.cn>
9 * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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.
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.
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
25 * $Id: scim_table_imengine.h,v 1.3 2005/10/26 07:53:53 suzhe Exp $
27 * Modifications by Samsung Electronics Co., Ltd.
29 * 1.Added auto commit feature for mobile user
32 #if !defined (__SCIM_TABLE_IMENGINE_H)
33 #define __SCIM_TABLE_IMENGINE_H
34 #include "scim_generic_table.h"
36 /* phrase frequency cannot larger than this value (2^16 - 1) */
37 #define SCIM_GT_MAX_PHRASE_FREQ 0xFFFF
39 /* when a phrase is input,
40 * increase the freq by ((max_freq - cur_freq) >> delta)
42 #define SCIM_GT_PHRASE_FREQ_DELTA_SHIFT 10
46 class TableFactory : public IMEngineFactoryBase
48 GenericTableLibrary m_table;
50 ConfigPointer m_config;
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;
58 String m_table_filename;
66 bool m_user_table_binary;
68 bool m_user_phrase_first;
70 bool m_long_phrase_first;
74 Connection m_reload_signal_connection;
76 Property m_status_property;
77 Property m_letter_property;
78 Property m_punct_property;
80 friend class TableInstance;
83 TableFactory (const ConfigPointer &config);
85 virtual ~TableFactory ();
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;
94 virtual IMEngineInstancePointer create_instance (const String& encoding, int id = -1);
96 bool load_table (const String &table_file, bool user_table=false);
99 return m_table.valid ();
103 void init (const ConfigPointer &config);
107 String get_sys_table_freq_file ();
108 String get_sys_table_user_file ();
110 void refresh (bool rightnow = false);
113 class TableInstance : public IMEngineInstanceBase
115 Pointer <TableFactory> m_factory;
117 bool m_double_quotation_state;
118 bool m_single_quotation_state;
120 bool m_full_width_punct [2];
121 bool m_full_width_letter [2];
126 std::vector<String> m_inputted_keys;
127 std::vector<WideString> m_converted_strings;
128 std::vector<uint32> m_converted_indexes;
130 CommonLookupTable m_lookup_table;
131 CommonLookupTable m_common_lookup_table;
132 std::vector <uint32> m_lookup_table_indexes;
134 uint32 m_inputing_caret;
135 uint32 m_inputing_key;
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;
147 WideString m_last_committed;
148 WideString m_preedit_string;
151 TableInstance (TableFactory *factory,
152 const String& encoding,
154 virtual ~TableInstance ();
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);
168 * decide whether to display candidate window according to layout
170 virtual void set_layout (unsigned int layout);
177 bool insert (char key);
178 bool test_insert (char key);
179 bool erase (bool backspace = true);
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 ();
194 void refresh_preedit ();
196 * @param show if show the lookup table
197 * @param refresh if refresh the content of lookup table.
199 void refresh_lookup_table (bool show=true, bool refresh=true);
200 void refresh_aux_string ();
202 void initialize_properties ();
204 void refresh_status_property ();
205 void refresh_letter_property ();
206 void refresh_punct_property ();
208 bool match_key_event (const std::vector<KeyEvent>& keyvec, const KeyEvent& key);
213 vi:ts=4:nowrap:ai:expandtab