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