
1: * Anthy Input ライブラリの使用方法の説明 * 2: 3: * 今からアプリケーションを書く場合にはuimの利用をお薦めします。 4: 5: ライブラリのオプション -lanthyinput -lanthy -lanthydic 6: インクルードファイル anthy/anthy.h anthy/input.h 7: (anthy/anthy.h を先にインクルードすること) 8: 9: * データ型の概説 * 10: anthy_input_config ローマ字変換の設定などに用いる。 11: ライブラリのユーザは中身をみてはいけない。 12: anthy_input_context 入力のコンテキストを識別するために用いる。 13: ライブラリのユーザは中身をみてはいけない。 14: anthy_input_preedit ライブラリからプリエディットを得るときに用いられる。 15: プリエディット全体を表す。 16: anthy_input_segment ライブラリからプリエディットを得るときに用いられる。 17: 候補を得るときにも用いられる。文節を表す。 18: 19: char * エンコードにはEUC-JPを利用する。 20: 21: * 関数の概説 * 22: 初期化関数など 23: anthy_input_init ライブラリの初期化 24: anthy_input_set_personality パーソナリティの設定 25: コンテキストの管理 26: anthy_input_create_context 入力コンテキストの作成 27: anthy_input_free_context 入力コンテキストの解放 28: 設定 29: anthy_input_create_config デフォルトの設定の作成 30: anthy_input_free_config デフォルトの設定の解放 31: anthy_input_edit_toggle_config 英数との一時的トグルに使うキーの変更 32: anthy_input_edit_rk_config キーと文字の対応の変更 33: anthy_input_clear_rk_config キーと文字の対応をデフォルトに戻す 34: anthy_input_change_config 設定の変更の通知 35: コンテキストの操作(直接的な操作) 36: anthy_input_str 文字列の追加 37: anthy_input_next_candidate 次の候補(選択中の文節に適用) 38: anthy_input_prev_candidate 前の候補(選択中の文節に適用) 39: anthy_input_quit 変換をキャンセル(1段階) 40: anthy_input_erase_prev カーソル前の文字を削除 41: anthy_input_erase_next カーソル後の文字を削除 42: anthy_input_commit 確定 43: anthy_input_move カーソル、選択中文節を移動 44: anthy_input_resize 選択中文節の長さを変更 45: anthy_input_beginning_of_line プリエディット先頭に移動 46: anthy_input_end_of_line プリエディット末尾に移動 47: anthy_input_cut 文字列の切り取り 48: コンテキストの操作(キーに対応した動作) 49: anthy_input_key 1文字の追加 50: anthy_input_space スペースまたは変換(コンテキスト依存) 51: コンテキストの操作(その他) 52: anthy_input_get_state 現在の状態の取得 53: anthy_input_get_preedit プリエディットを得る 54: anthy_input_map_select ローマ字仮名変換マップの切替え 55: anthy_input_get_selected_map 現在のローマ字仮名変換マップの取得 56: anthy_input_get_candidate 候補番号を指定して候補を得る 57: anthy_input_select_candidate 候補番号を指定して候補を選ぶ 58: anthy_input_free_preedit プリエディットの解放 59: (属する文節構造体も同時に解放する) 60: anthy_input_free_segment 文節の解放 61: 設定の変更 62: anthy_input_map_edit ローマ字仮名変換マップの編集(未対応) 63: 64: * 状態 * 65: 待機状態(1) プリエディットは存在しない 66: 編集中状態(2) ローマ字入力中の状態。 67: カーソル位置の文節に文字列がない。 68: 選択中文節はカーソル位置の文節を指している。 69: 変換中状態(3) 変換中の状態。 70: 文節伸縮状態(4) 文節伸縮中の状態。 71: 選択中文節以降はすべて平仮名になる。 72: 選択中文節より後ろは全てまとめて一文節になる。 73: 74: * 各関数の説明 * 75: int anthy_input_init(void); 76: 引数: 無し 77: 返り値: 0 なら成功 -1 なら失敗 78: ライブラリを初期化する。anthyライブラリも初期化する。 79: 80: struct anthy_input_config* anthy_input_create_config(void); 81: 引数: 無し 82: 返り値: 設定構造体のポインタ 83: 設定構造体を得る。設定構造体はデフォルト値で初期化されている。 84: 85: void anthy_input_free_config(struct anthy_input_config* cfg); 86: 引数: 設定構造体のポインタ 87: 返り値: 無し 88: 設定構造体を解放する。この設定を共有する全ての入力コンテキ 89: ストを事前に解放する事。 90: 91: anthy_input_set_personality(char *personality); 92: 引数: personality パーソナリティの名前 93: 返り値: 無し 94: 95: struct anthy_input_context* 96: anthy_input_create_context(struct anthy_input_config* cfg); 97: 引数: cfg 設定構造体のポインタ 98: 返り値: 入力コンテキストのポインタ 99: 入力コンテキストのポインタを得る。引数に与えた設定構造体に 100: 適用した操作は、入力コンテキストを作った後にでも、すぐに入 101: 力コンテキストに反映される。 102: コンテキストは待機状態で作成される。 103: 104: void anthy_input_free_context(struct anthy_input_context* ictx); 105: 引数: ictx 入力コンテキスト 106: 返り値: なし 107: 入力コンテキストを解放する。 108: 109: void anthy_input_str(struct anthy_input_context* ictx, char* str); 110: 引数: ictx コンテキスト構造体 111: str 追加する文字列 112: 返り値: 無し 113: 追加する文字列はローマ字(半角)で入力する。 114: 待機状態と編集中状態ではプリエディットに文字列を追加する。 115: 変換中状態と文節伸縮状態ではプリエディットをその状態で確定して、 116: 新たにstrだけを持つプリエディットを作る。 117: 呼出後は編集中状態になる。 118: 119: void anthy_input_next_candidate(struct anthy_input_context* ictx); 120: 引数: ictx コンテキスト構造体 121: 返り値: 無し 122: 編集中状態では全文節を変換し、変換中状態にはいる。 123: 変換中状態では選択中文節の候補を次の候補にする。 124: 文節伸縮状態では選択中文節以降を変換し、変換中状態に入る。 125: 126: void anthy_input_prev_candidate(struct anthy_input_context* ictx); 127: 引数: ictx コンテキスト構造体 128: 返り値: 無し 129: 編集中状態では全文節を変換し、変換中状態にはいる。 130: 変換中状態では選択中文節の候補を前の候補にする。 131: 文節伸縮状態では選択中文節以降を変換し、変換中状態に入る。 132: 133: void anthy_input_quit(struct anthy_input_context* ictx); 134: 引数: ictx コンテキスト構造体 135: 返り値: 無し 136: 編集中状態では待機状態になる。 137: 編集中状態と文節伸縮状態では編集中状態になる。 138: 139: void anthy_input_erase_prev(struct anthy_input_context* ictx); 140: 引数: ictx コンテキスト構造体 141: 返り値: 無し 142: 編集中状態だけで有効。 143: カーソルの前1文字を消す。 144: 消した結果プリエディットがなくなれば、待機状態になる。 145: 146: void anthy_input_erase_next(struct anthy_input_context* ictx); 147: 引数: ictx コンテキスト構造体 148: 返り値: 無し 149: 編集中状態だけで有効。 150: カーソルの後1文字を消す。 151: 消した結果プリエディットがなくなれば、待機状態になる。 152: 153: void anthy_input_commit(struct anthy_input_context* ictx); 154: 引数: ictx コンテキスト構造体 155: 返り値: 無し 156: 現在のプリエディットの状態で確定する。 157: 待機状態に戻る。 158: 159: void anthy_input_move(struct anthy_input_context* ictx, int lr); 160: 引数: ictx コンテキスト構造体 161: lr 移動方向 162: 返り値: 無し 163: 編集中状態ではカーソルを移動する。 164: 変換中状態では選択文節を移動する。 165: 文節伸縮状態では変換中状態に戻り、選択文節を移動する。 166: lr = -1 で左移動、 lr = 1 で右移動。 167: 168: void anthy_input_resize(struct anthy_input_context* ictx, int lr); 169: 引数: ictx コンテキスト構造体 170: lr 伸縮方向 171: 返り値: 無し 172: 変換中状態では選択文節を伸縮させ、文節伸縮状態になる。 173: 文節伸縮状態では選択文節を伸縮する。 174: lr = -1 で縮小、 lr = 1 で伸長。 175: 176: void anthy_input_beginning_of_line(struct anthy_input_context* ictx); 177: 引数: ictx コンテキスト構造体 178: 返り値: 無し 179: 編集中状態だけで有効。 180: カーソルをプリエディットの先頭に移動させる。 181: 182: void anthy_input_end_of_line(struct anthy_input_context* ictx); 183: 引数: ictx コンテキスト構造体 184: 返り値: 無し 185: 編集中状態だけで有効。 186: カーソルをプリエディットの末尾に移動させる。 187: 188: void anthy_input_cut(struct anthy_input_context* ictx); 189: 引数: ictx コンテキスト構造体 190: 返り値: 無し 191: 編集中状態だけで有効。 192: カーソル以降の文字列を消す。消した文字列は記憶している。 193: 194: void anthy_input_str(struct anthy_input_context* ictx, char c); 195: 引数: ictx コンテキスト構造体 196: c 追加する文字 197: 返り値: 無し 198: anthy_input_key とほぼ同じ。ただし、 1 文字だけ追加する。 199: 200: void anthy_input_space(struct anthy_input_context* ictx); 201: 引数: ictx コンテキスト構造体 202: 返り値: 無し 203: コンテキストに応じて空白の追加、変換のどちらかになる。 204: 205: struct anthy_input_preedit* 206: anthy_input_get_preedit(struct anthy_input_context* ictx); 207: 引数: ictx コンテキスト構造体 208: 返り値: 現在のプリエディット 209: 現在のプリエディットを得る。得たプリエディットを書き換えてはいけない。 210: プリエディットの中身は後述。 211: 212: int anthy_input_map_select(struct anthy_input_context* ictx, int map); 213: 引数: ictx コンテキスト構造体 214: map マップ番号 215: 返り値: 成功 0 失敗 それ以外 216: ローマ字からの変換マップを変更する。 map に指定できるのは以下の定数 217: MAP_HIRAGANA ひらがな 218: MAP_KATAKANA かたかな 219: MAP_ALPHABET アルファベット 220: MAP_WALPHABET 全角アルファベット 221: 222: struct anthy_input_segment* 223: anthy_input_get_candidate(struct anthy_input_context* ictx, int cand_no); 224: 引数: ictx コンテキスト構造体 225: cand_no 候補番号 226: 返り値: 目的の候補を含んだ文節構造体 227: 変換中状態でだけ有効。 228: 選択中文節の指定した番号の候補を得る。 229: 次に anthy_input_get_candidate でプリエディットを要求した時は、 cand_no 230: の次の候補が返される。 231: 232: int anthy_input_select_candidate(struct anthy_input_context* ictx, int cand); 233: 引数: ictx コンテキスト構造体 234: cand_no 候補番号 235: 返り値: 成功 0 失敗 それ以外 236: 変換中状態でだけ有効。 237: 選択中文節の指定した番号の候補を選択し、選択中文節を右の文節に移動させる。 238: 239: void anthy_input_free_preedit(struct anthy_input_preedit* pedit); 240: 引数: pedit プリエディット構造体 241: 返り値: 無し 242: プリエディット構造体を解放する。 243: 244: void anthy_input_free_segment(struct anthy_input_segment* cand); 245: 引数: cand 文節構造体。 246: 返り値: 無し 247: 文節構造体を解放する。 248: 249: * データ型の説明 * 250: struct anthy_input_preedit { 251: int state; /* 状態 */ 252: 253: char* commit; /* 確定文字列 */ 254: char* cut_buf; /* 切り取った文字列 */ 255: 256: struct anthy_input_segment* segment; /* 文節リスト */ 257: struct anthy_input_segment* cur_segment; /* 選択中の文節 */ 258: }; 259: 260: state: 現在の状態 261: ST_NONE 待機状態 262: ST_EDIT 編集中状態 263: ST_CONV 変換中状態 264: ST_CSEG 文節伸縮状態 265: commit: NULL でなければ、確定された文字列が入っている。 266: commit は一度 anthy_input_get_preedit すると消える。 267: cut_buf: NULL でなければ、 anthy_input_cut により消された文字列が入っている。 268: cut_buf は一度 anthy_input_get_preedit すると消える。 269: segment: 変換中、文節伸縮状態では文節のリスト 270: 編集中状態では、カーソル前文字列、ローマ字文字列、空文節、 271: カーソル後文字列のリスト 272: cur_segment: カーソルのある文節 273: 274: struct anthy_input_segment { 275: char* str; /* 文字列 */ 276: int cand_no; /* 候補番号 */ 277: int noconv_len; /* 無変換状態でのバイト数 */ 278: int nr_cand; /* 候補数 */ 279: int flag; /* フラグ */ 280: 281: struct anthy_input_segment* next; /* 次の文節 */ 282: }; 283: str: 現在の候補の文字列 284: (編集中状態の、カーソルを表す文節では NULL になっている) 285: cand_no: 候補番号 (0 〜 nr_cand - 1, 286: 候補の割り当てられた文節でないときと無変換候補のときは -1) 287: noconv_len: 無変換状態での文節の文字列の長さ (バイト数) 288: nr_cand: 全候補数 (候補の割り当てられた文節でないときは -1) 289: flag: 文節の種類を表すフラグ 290: SF_CURSOR カーソルまたは選択中文節 291: SF_ENUM 数回連続で変換キーが押されるなどしたので、 292: 候補一覧を表示することをライブラリが提案している。 293: これを受け取ると、 anthy_input_get_candidate 294: を使って候補一覧を表示するのが望ましい。 295: SF_ENUM_REVERSE 逆方向の候補一覧を表示することをライブラリが 296: 提案している 297: SF_EDITTING 編集中状態の文字列 298: SF_PENDING まだローマ字のままで、仮名にもなっていない文字列 299: SF_FOLLOWING 文節伸縮状態で、選択中文節より後ろの文字列 300: を 1 文節にした文節