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