Successfully reported this slideshow.
Your SlideShare is downloading. ×

InputMethodKit超入門

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Loading in …3
×

Check these out next

1 of 36 Ad

More Related Content

Slideshows for you (20)

Advertisement

Similar to InputMethodKit超入門 (20)

InputMethodKit超入門

  1. 1. InputMethodKit超⼊門 Cocoa勉強会�#39�/�2010.02.11�(祝)�/�⽊村渡 Powered by Rabbit 0.6.4 and COZMIXNG
  2. 2. Input�Method ✓ 効率の良い⼊⼒ ✓ さまざまなアプリケーションとコ ミュニケート InputMethodKitは、 後者を⽀援するフレームワーク
  3. 3. InputMethodKit ✓ かな漢字変換などの⼊⼒プログラム をつくるためのフレームワーク ✓ アプリとして⼊⼒プログラムを作成 ✓ Cocoa ✓ Leopardで導⼊された
  4. 4. さまざまな⽇本語⼊⼒プログラム ✓ ことえり ✓ かわせみ ✓ AquaSKK ✓ Google⽇本語⼊⼒         などなど
  5. 5. InputMethodKitの構成 +----------+ +------------------------+ |=user app=| | =input method app= | | Client <------->(Server)<-> Controller | +----------+ +------------------------+
  6. 6. IMK�Classes IMKServer ユーザ操作と⼊⼒操作を仲介 IMKInputController ⼊⼒プログラムの処理本体 IMKCandidates 選択候補のユーザインターフェイスを制御
  7. 7. IMK�Protocols IMKServerInput ⼊⼒プログラムのインターフェイス IMKTextInput ⼊⼒プログラムとやりとりするアプリのイ ンターフェイス IMKStateSetting IMKMouseHandling
  8. 8. 3つの実装手段 IMKServerInputプロトコル ✓ キーバインディング ✓ ⼊⼒⽂字+修飾キーを解釈 ✓ TSMのイベントを利用
  9. 9. キーバインディング inputText:client: ⼊⼒された⽂字を受け取る didCommandBySelector:client: キーバインディングで定義されたコマンド を受け取る "apple"が⼊⼒された "moveForward:"コマンドが指⽰され た
  10. 10. キーバインディング キー(の組み合わせ)をObjective-C メッセージに割り当て StandardKeyBinding.dictを参照 <key>^f</key> <string>moveForward:</string>
  11. 11. ⼊⼒⽂字+修飾キーを解釈 inputText:key:modifiers:client: ⼊⼒された⽂字と修飾キーを受け取る "apple"が⼊⼒された "f"とCtrlキーが⼊⼒された
  12. 12. TSMのイベントを利用 handleEvent:client: よくわからん。 たぶん従来のコンポーネントからの移 ⾏しやすいんじゃないかな。
  13. 13. 3つの実装手段 IMKServerInputプロトコル ✓ キーバインディング ✓ ⼊⼒⽂字+修飾キーを解釈 ✓ TSMのイベントを利用 上のふたつのどちらか
  14. 14. つくってみよう
  15. 15. 偉大なるお手本 AppleのサンプルNumberInput
  16. 16. NumberInput作成の手順 1.�⼊⼒メニューに表⽰ 2.�ユーザ操作から⼊⼒⽂字を決定 3.�複数の変換モード 4.�変換候補の表⽰ 5.�環境設定のUI
  17. 17. 今回のサンプル 単純のため次のように ✓ 英数字のみ扱う ✓ 英単語を候補から選択できる ✓ (できれば)⼊⼒中のテキストから候 補を抽出する
  18. 18. 実装手順 1.�最⼩限。⼊⼒プログラムとして選 択できる 2.�試験的な変換⼊⼒ 3.�目的の変換処理、変換候補の選択
  19. 19. 最⼩限の実装 ✓ Info.plistに記述 ✓ main()でIMKServerを⽣成 ✓ IMKServerControllerのサブクラス
  20. 20. Info.plist LSBackgroundOnly InputMethodConnectionName InputMethodServerControllerClas s tsInputMethodIconFileKey tsInputMethodCharacterRepertoir eKey
  21. 21. Info.plist LSBackgroundOnly 1に。アプリケーションをバックグラ ウンドにします。
  22. 22. Info.plist InputMethodConnectionName アプリケーションと⼊⼒プログラムの 通信に利用する名前を指定します。こ の名前はほかの⼊⼒プログラムと重複 しないように注意してください。
  23. 23. Info.plist InputMethodServerControllerClas s ⼊⼒サービスを提供するクラスを指定 このクラスはIMKServerControllerの サブクラス
  24. 24. Info.plist tsInputMethodIconFileKey ⼊⼒メニューに表⽰するアイコン(こ とえりなら[あ])の画像ファイルを指 定
  25. 25. Info.plist tsInputMethodCharacterRepertoir eKey ⼊⼒するキャラクタセットをISO1592 で指定(複数可)
  26. 26. プログラム ✓ main.m ✓ IMKServerControllerのサブクラス
  27. 27. main.m ここでIMKServerのインスタンスを⽣ 成し、コネクションの名前などを指定 します。
  28. 28. IMKInputController inputText:client: この⼊⼒プログラムで⼊⼒テキストを 処理するならYESを、そうでなければ NOを返します。 とりあえず常にNOにしておきます。
  29. 29. 動作確認�0 ⼊⼒メニューに表⽰できる ✓ /Library/Input Methodsに ✓ ログオフ〜再ログオン 開発時はユーザースイッチを利用する のがよいかも
  30. 30. 試験的な変換⼊⼒を実装 -(BOOL)inputText:(NSString*)string client:(id)sender { if ([string hasPrefix:@"o"]) { [sender insertText:@"Objective-C" replacementRange:NSMakeRange(0, 0)]; return YES; } else { return NO;
  31. 31. 動作確認�1 "o"を⼊⼒すると"Objective-C"が 他の⽂字はそのまま abc..lmnObjective-Cpq..xyz
  32. 32. 変換候補の表示 cancdidates: 候補の配列を返す candidateSelected: 候補が選択された candidateSelectionChanged: 選択候補が変更された
  33. 33. 動作確認�2 ✓ ⼊⼒中にスペースキーで変換候補を 表⽰ ✓ ⼊⼒中の⽂字が表⽰されない...
  34. 34. インライン⼊⼒ これは宿題っ setMarkedText:selectionRange:re placementRange:
  35. 35.
  36. 36. 質問などあれば どうぞ Powered by Rabbit 0.6.4 and COZMIXNG

×