[aquaskk-changes 373] CVS update: AquaSKK/src/editor

Back to archive index

t-suw****@users***** t-suw****@users*****
2007年 9月 16日 (日) 09:18:52 JST


Index: AquaSKK/src/editor/SKKDirectInputState.cpp
diff -u AquaSKK/src/editor/SKKDirectInputState.cpp:1.1.2.1 AquaSKK/src/editor/SKKDirectInputState.cpp:1.1.2.2
--- AquaSKK/src/editor/SKKDirectInputState.cpp:1.1.2.1	Sun Sep  2 12:36:25 2007
+++ AquaSKK/src/editor/SKKDirectInputState.cpp	Sun Sep 16 09:18:52 2007
@@ -18,6 +18,7 @@
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
+#include <iostream>
 #include "SKKDirectInputState.h"
 #include "SKKContext.h"
 #include "SKKEventParam.h"
@@ -29,49 +30,121 @@
 }
 
 SKKSubController* SKKDirectInputState::HandleInput(SKKContext& context, const SKKEventParam& param) {
-    return new SKKEmptySubController(0);
+    // 直接入力文字は無視する
+    if(param.IsDirect()) {
+	// port 呼び出し
+	return 0;
+    }
+    
+    SKKInputBuffer& buffer = context.InputBuffer();
+    if(buffer.Input(param.code)) {
+	std::cerr << buffer.FixedString();
+    } else {
+	State state = 0;
+	// 確定しないのはかな入力時のみ
+	do {
+	    if(param.IsSwitchToAscii()) {
+		state = State::Transition(&SKKEnvironment::Ascii);
+		break;
+	    }
+
+	    if(param.IsSwitchToJisx0208Latin()) {
+		state = State::Transition(&SKKEnvironment::Jisx0208Latin);
+		break;
+	    }
+
+	    if(param.IsUpperCases()) {
+		state = State::Forward(&SKKEnvironment::Japanese);
+		break;
+	    }
+
+	    if(param.IsEnterJapanese()) {
+		state = State::Transition(&SKKEnvironment::Japanese);
+		break;
+	    }
+
+	    if(param.IsEnterAbbrev()) {
+		state = State::Transition(&SKKEnvironment::Abbreviation);
+		break;
+	    }
+	} while(0);
+
+	if(state) {
+	    buffer.Clear();
+	    return new SKKEmptySubController(state);
+	}
+
+	if(!buffer.FixedString().empty()) {
+	    std::cerr << buffer.FixedString() << std::endl;
+	}
+    }
+    std::cerr << buffer.InputString() << std::endl;
+
+    return 0;
 }
 
-SKKSubController* SKKDirectInputState::HandleEnter(SKKContext& context, const SKKEventParam& param) {
-    return new SKKEmptySubController(0);
+SKKSubController* SKKDirectInputState::HandleEnter(SKKContext&, const SKKEventParam&) {
+    // 登録完了の場合もある
+    return 0;
 }
 
-SKKSubController* SKKDirectInputState::HandleJmode(SKKContext& context, const SKKEventParam& param) {
-    return new SKKEmptySubController(0);
+SKKSubController* SKKDirectInputState::HandleJmode(SKKContext&, const SKKEventParam&) {
+    return 0;
 }
 
-SKKSubController* SKKDirectInputState::HandleCancel(SKKContext& context, const SKKEventParam& param) {
-    return new SKKEmptySubController(0);
+SKKSubController* SKKDirectInputState::HandleCancel(SKKContext& context, const SKKEventParam&) {
+    SKKInputBuffer& buffer = context.InputBuffer();
+
+    if(!buffer.IsEmpty()) {
+	buffer.Clear();
+    } else {
+	// port 呼び出し
+    }
+    std::cerr << buffer.InputString() << std::endl;
+
+    return 0;
 }
 
-SKKSubController* SKKDirectInputState::HandleBackSpace(SKKContext& context, const SKKEventParam& param) {
-    return new SKKEmptySubController(0);
+SKKSubController* SKKDirectInputState::HandleBackSpace(SKKContext& context, const SKKEventParam&) {
+    SKKInputBuffer& buffer = context.InputBuffer();
+
+    if(!buffer.IsEmpty()) {
+	buffer.BackSpace();
+    }
+    std::cerr << buffer.InputString() << std::endl;
+
+    return 0;
 }
 
-SKKSubController* SKKDirectInputState::HandleDelete(SKKContext& context, const SKKEventParam& param) {
-    return new SKKEmptySubController(0);
+SKKSubController* SKKDirectInputState::HandleDelete(SKKContext&, const SKKEventParam&) {
+    return 0;
 }
 
-SKKSubController* SKKDirectInputState::HandleTab(SKKContext& context, const SKKEventParam& param) {
-    return new SKKEmptySubController(0);
+SKKSubController* SKKDirectInputState::HandleTab(SKKContext&, const SKKEventParam&) {
+    return 0;
 }
 
-SKKSubController* SKKDirectInputState::HandlePaste(SKKContext& context, const SKKEventParam& param) {
-    return new SKKEmptySubController(0);
+SKKSubController* SKKDirectInputState::HandlePaste(SKKContext&, const SKKEventParam&) {
+    // port 呼び出し
+    return 0;
 }
 
-SKKSubController* SKKDirectInputState::HandleCursorLeft(SKKContext& context, const SKKEventParam& param) {
-    return new SKKEmptySubController(0);
+SKKSubController* SKKDirectInputState::HandleCursorLeft(SKKContext&, const SKKEventParam&) {
+    // port 呼び出し
+    return 0;
 }
 
-SKKSubController* SKKDirectInputState::HandleCursorRight(SKKContext& context, const SKKEventParam& param) {
-    return new SKKEmptySubController(0);
+SKKSubController* SKKDirectInputState::HandleCursorRight(SKKContext&, const SKKEventParam&) {
+    // port 呼び出し
+    return 0;
 }
 
-SKKSubController* SKKDirectInputState::HandleCursorUp(SKKContext& context, const SKKEventParam& param) {
-    return new SKKEmptySubController(0);
+SKKSubController* SKKDirectInputState::HandleCursorUp(SKKContext&, const SKKEventParam&) {
+    // port 呼び出し
+    return 0;
 }
 
-SKKSubController* SKKDirectInputState::HandleCursorDown(SKKContext& context, const SKKEventParam& param) {
-    return new SKKEmptySubController(0);
+SKKSubController* SKKDirectInputState::HandleCursorDown(SKKContext&, const SKKEventParam&) {
+    // port 呼び出し
+    return 0;
 }
Index: AquaSKK/src/editor/SKKDirectInputState.h
diff -u AquaSKK/src/editor/SKKDirectInputState.h:1.1.2.2 AquaSKK/src/editor/SKKDirectInputState.h:1.1.2.3
--- AquaSKK/src/editor/SKKDirectInputState.h:1.1.2.2	Sun Sep  2 12:45:38 2007
+++ AquaSKK/src/editor/SKKDirectInputState.h	Sun Sep 16 09:18:52 2007
@@ -18,8 +18,8 @@
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
-#ifndef INC__SKKDirectState__
-#define INC__SKKDirectState__
+#ifndef INC__SKKDirectInputState__
+#define INC__SKKDirectInputState__
 
 #include "SKKState.h"
 
Index: AquaSKK/src/editor/SKKEditor.cpp
diff -u AquaSKK/src/editor/SKKEditor.cpp:1.1.2.1 AquaSKK/src/editor/SKKEditor.cpp:1.1.2.2
--- AquaSKK/src/editor/SKKEditor.cpp:1.1.2.1	Sun Sep  2 12:36:25 2007
+++ AquaSKK/src/editor/SKKEditor.cpp	Sun Sep 16 09:18:52 2007
@@ -20,6 +20,7 @@
 
 #include "SKKEditor.h"
 #include "SKKDirectInputState.h"
+#include "SKKEntryInputState.h"
 
 SKKEditor::SKKEditor() {
     initialize();
@@ -90,7 +91,7 @@
 
 // 入力モード変更
 void SKKEditor::SelectInputMode(SKK::InputMode mode) {
-
+    context_.InputBuffer().SelectInputMode(mode);
 }
 
 // 内部状態変更
@@ -101,6 +102,9 @@
 	break;
 
     case SKK::EntryInput:
+	state_ = &SKKEntryInputState::theInstance();
+	break;
+
     case SKK::OkuriInput:
     case SKK::AbbrevInput:
     case SKK::Completion:
Index: AquaSKK/src/editor/SKKEntryInputState.cpp
diff -u /dev/null AquaSKK/src/editor/SKKEntryInputState.cpp:1.1.2.1
--- /dev/null	Sun Sep 16 09:18:52 2007
+++ AquaSKK/src/editor/SKKEntryInputState.cpp	Sun Sep 16 09:18:52 2007
@@ -0,0 +1,300 @@
+/* -*- C++ -*-
+   MacOS X implementation of the SKK input method.
+
+   Copyright (C) 2007 Tomotaka SUWA <t.suw****@mac*****>
+
+   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 of the License, or
+   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
+*/
+
+#include <iostream>
+#include "SKKEntryInputState.h"
+#include "SKKContext.h"
+#include "SKKEventParam.h"
+#include "SKKEmptySubController.h"
+#include "jconv.h"
+
+SKKEntryInputState& SKKEntryInputState::theInstance() {
+    static SKKEntryInputState obj;
+    return obj;
+}
+
+SKKSubController* SKKEntryInputState::HandleInput(SKKContext& context, const SKKEventParam& param) {
+    SKKInputBuffer& buffer = context.InputBuffer();
+    SKKEditBuffer& edit = context.EditBuffer();
+
+    if(!edit.IsEmpty()) {
+	State state = 0;
+
+	do {
+	    // トグル変換 #1
+	    if(param.IsToggleKana()) {
+		std::string result;
+		toggleKana(buffer.InputMode(), edit.EditString(), result);
+		edit.Clear();
+		std::cerr << result << std::endl;
+		state = State::Transition(&SKKEnvironment::KanaInput);
+		break;
+	    }
+
+	    // トグル変換 #2
+	    if(param.IsToggleJisx0201Kana()) {
+		std::string result;
+		toggleJisx0201Kana(buffer.InputMode(), edit.EditString(), result);
+		edit.Clear();
+		std::cerr << result << std::endl;
+		state = State::Transition(&SKKEnvironment::KanaInput);
+		break;
+	    }
+
+	    // 送りあり
+	    if(param.IsUpperCases()) {
+		std::cerr << "送りあり開始" << std::endl;
+		break;
+	    }
+
+	    // 変換
+	    if(param.IsNextCandidate()) {
+		std::cerr << "変換開始" << std::endl;
+		break;
+	    }
+	} while(0);
+
+	if(state) {
+	    return new SKKEmptySubController(state);
+	}
+    }
+
+    if(buffer.Input(std::tolower(param.code))) {
+	edit.Insert(buffer.FixedString());
+    } else {
+	State state = 0;
+
+	do {
+	    if(param.IsSwitchToAscii()) {
+		state = State::Transition(&SKKEnvironment::Ascii);
+		break;
+	    }
+
+	    if(param.IsSwitchToJisx0208Latin()) {
+		state = State::Transition(&SKKEnvironment::Jisx0208Latin);
+		break;
+	    }
+
+	    if(param.IsEnterJapanese() && !edit.IsEmpty()) {
+		state = State::Transition(&SKKEnvironment::Japanese);
+		break;
+	    }
+	} while(0);
+
+	if(state) {
+	    std::cerr << edit.EditString() << std::endl;
+	    edit.Clear();
+	    buffer.Clear();
+	    return new SKKEmptySubController(state);
+	}
+
+	if(!buffer.FixedString().empty()) {
+	    edit.Insert(buffer.FixedString());
+	}
+    }
+    
+    std::cerr << edit.EditString() << buffer.InputString() << std::endl;
+
+    return 0;
+}
+
+SKKSubController* SKKEntryInputState::HandleEnter(SKKContext& context, const SKKEventParam& param) {
+    SKKSubController* result = HandleJmode(context, param);
+
+    // 改行するかどうか?(egg-like-new-line)
+
+    return result;
+}
+
+SKKSubController* SKKEntryInputState::HandleJmode(SKKContext& context, const SKKEventParam&) {
+    SKKInputBuffer& buffer = context.InputBuffer();
+    SKKEditBuffer& edit = context.EditBuffer();
+
+    // 現在の候補で確定
+    std::cerr << edit.EditString() << std::endl;
+
+    edit.Clear();
+    buffer.Clear();
+
+    return new SKKEmptySubController(State::Transition(&SKKEnvironment::KanaInput));
+}
+
+SKKSubController* SKKEntryInputState::HandleCancel(SKKContext& context, const SKKEventParam&) {
+    SKKInputBuffer& buffer = context.InputBuffer();
+    SKKEditBuffer& edit = context.EditBuffer();
+
+    edit.Clear();
+    buffer.Clear();
+
+    // 空にする
+    std::cerr << edit.EditString() << std::endl;
+
+    return new SKKEmptySubController(State::Transition(&SKKEnvironment::KanaInput));
+}
+
+SKKSubController* SKKEntryInputState::HandleBackSpace(SKKContext& context, const SKKEventParam&) {
+    SKKInputBuffer& buffer = context.InputBuffer();
+    SKKEditBuffer& edit = context.EditBuffer();
+
+    if(!buffer.IsEmpty()) {
+	buffer.BackSpace();
+    } else {
+	if(!edit.IsEmpty()) {
+	    edit.BackSpace();
+	} else {
+	    return new SKKEmptySubController(State::Transition(&SKKEnvironment::KanaInput));
+	}
+    }
+
+    std::cerr << edit.EditString() << buffer.InputString() << std::endl;
+
+    return 0;
+}
+
+SKKSubController* SKKEntryInputState::HandleDelete(SKKContext& context, const SKKEventParam&) {
+    SKKInputBuffer& buffer = context.InputBuffer();
+    SKKEditBuffer& edit = context.EditBuffer();
+
+    if(buffer.IsEmpty() && !edit.IsEmpty()) {
+	edit.Delete();
+
+	std::cerr << edit.EditString() << std::endl;
+    }
+
+    return 0;
+}
+
+SKKSubController* SKKEntryInputState::HandleTab(SKKContext& context, const SKKEventParam&) {
+    // 検索できた?
+    if(0) {
+	// 補完モード
+	return new SKKEmptySubController(State::Transition(&SKKEnvironment::EntryCompletion));
+    } else {
+	return 0;
+    }
+}
+
+SKKSubController* SKKEntryInputState::HandlePaste(SKKContext& context, const SKKEventParam&) {
+    // テキストがある?
+    if(0) {
+	SKKInputBuffer& buffer = context.InputBuffer();
+	SKKEditBuffer& edit = context.EditBuffer();
+
+	buffer.Clear();
+	edit.Insert("paste string");
+
+	std::cerr << edit.EditString() << std::endl;
+    }
+
+    return 0;
+}
+
+SKKSubController* SKKEntryInputState::HandleCursorLeft(SKKContext& context, const SKKEventParam&) {
+    SKKInputBuffer& buffer = context.InputBuffer();
+    SKKEditBuffer& edit = context.EditBuffer();
+
+    buffer.Clear();
+    edit.CursorLeft();
+
+    std::cerr << edit.EditString() << std::endl;
+
+    return 0;
+}
+
+SKKSubController* SKKEntryInputState::HandleCursorRight(SKKContext& context, const SKKEventParam&) {
+    SKKInputBuffer& buffer = context.InputBuffer();
+    SKKEditBuffer& edit = context.EditBuffer();
+
+    buffer.Clear();
+    edit.CursorRight();
+
+    std::cerr << edit.EditString() << std::endl;
+
+    return 0;
+}
+
+SKKSubController* SKKEntryInputState::HandleCursorUp(SKKContext& context, const SKKEventParam&) {
+    SKKInputBuffer& buffer = context.InputBuffer();
+    SKKEditBuffer& edit = context.EditBuffer();
+
+    buffer.Clear();
+    edit.CursorUp();
+
+    std::cerr << edit.EditString() << std::endl;
+
+    return 0;
+}
+
+SKKSubController* SKKEntryInputState::HandleCursorDown(SKKContext& context, const SKKEventParam&) {
+    SKKInputBuffer& buffer = context.InputBuffer();
+    SKKEditBuffer& edit = context.EditBuffer();
+
+    buffer.Clear();
+    edit.CursorDown();
+
+    std::cerr << edit.EditString() << std::endl;
+
+    return 0;
+}
+
+// ======================================================================
+// private method
+// ======================================================================
+void SKKEntryInputState::toggleKana(SKK::InputMode mode, const std::string& from, std::string& to) {
+    to.clear();
+
+    switch(mode) {
+    case SKK::Hirakana:
+	jconv::hirakana_to_katakana(from, to);
+	break;
+
+    case SKK::Katakana:
+	jconv::katakana_to_hirakana(from, to);
+	break;
+		
+    case SKK::Jisx0201Kana:
+	jconv::jisx0201_kana_to_katakana(from, to);
+	break;
+
+    default:
+	break;
+    }
+}
+
+void SKKEntryInputState::toggleJisx0201Kana(SKK::InputMode mode, const std::string& from, std::string& to) {
+    to.clear();
+
+    switch(mode) {
+    case SKK::Hirakana:
+	jconv::hirakana_to_jisx0201_kana(from, to);
+	break;
+
+    case SKK::Katakana:
+	jconv::katakana_to_jisx0201_kana(from, to);
+	break;
+		
+    case SKK::Jisx0201Kana:
+	jconv::jisx0201_kana_to_hirakana(from, to);
+	break;
+
+    default:
+	break;
+    }
+}
Index: AquaSKK/src/editor/SKKEntryInputState.h
diff -u /dev/null AquaSKK/src/editor/SKKEntryInputState.h:1.1.2.1
--- /dev/null	Sun Sep 16 09:18:52 2007
+++ AquaSKK/src/editor/SKKEntryInputState.h	Sun Sep 16 09:18:52 2007
@@ -0,0 +1,50 @@
+/* -*- C++ -*-
+   MacOS X implementation of the SKK input method.
+
+   Copyright (C) 2007 Tomotaka SUWA <t.suw****@mac*****>
+
+   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 of the License, or
+   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
+*/
+
+#ifndef INC__SKKEntryInputState__
+#define INC__SKKEntryInputState__
+
+#include <string>
+#include "SKK.h"
+#include "SKKState.h"
+
+// 見出し語入力状態
+struct SKKEntryInputState : public SKKState {
+    static SKKEntryInputState& theInstance();
+
+    virtual SKKSubController* HandleInput(SKKContext& context, const SKKEventParam& param);
+    virtual SKKSubController* HandleEnter(SKKContext& context, const SKKEventParam& param);
+    virtual SKKSubController* HandleJmode(SKKContext& context, const SKKEventParam& param);
+    virtual SKKSubController* HandleCancel(SKKContext& context, const SKKEventParam& param);
+    virtual SKKSubController* HandleBackSpace(SKKContext& context, const SKKEventParam& param);
+    virtual SKKSubController* HandleDelete(SKKContext& context, const SKKEventParam& param);
+    virtual SKKSubController* HandleTab(SKKContext& context, const SKKEventParam& param);
+    virtual SKKSubController* HandlePaste(SKKContext& context, const SKKEventParam& param);
+    virtual SKKSubController* HandleCursorLeft(SKKContext& context, const SKKEventParam& param);
+    virtual SKKSubController* HandleCursorRight(SKKContext& context, const SKKEventParam& param);
+    virtual SKKSubController* HandleCursorUp(SKKContext& context, const SKKEventParam& param);
+    virtual SKKSubController* HandleCursorDown(SKKContext& context, const SKKEventParam& param);
+
+private:
+    void toggleKana(SKK::InputMode mode, const std::string& from, std::string& to);
+    void toggleJisx0201Kana(SKK::InputMode mode, const std::string& from, std::string& to);
+};
+
+#endif
Index: AquaSKK/src/editor/SKKState.h
diff -u AquaSKK/src/editor/SKKState.h:1.1.2.1 AquaSKK/src/editor/SKKState.h:1.1.2.2
--- AquaSKK/src/editor/SKKState.h:1.1.2.1	Sun Sep  2 12:36:25 2007
+++ AquaSKK/src/editor/SKKState.h	Sun Sep 16 09:18:52 2007
@@ -21,12 +21,14 @@
 #ifndef INC__SKKState__
 #define INC__SKKState__
 
+#include "SKKEngine.h"
+
 class SKKContext;
 class SKKEventParam;
 class SKKSubController;
 
 // 状態クラスインタフェース
-struct SKKState {
+struct SKKState : public StateContainerTraits<SKKEngine> {
     virtual SKKSubController* HandleInput(SKKContext& context, const SKKEventParam& param) = 0;
     virtual SKKSubController* HandleEnter(SKKContext& context, const SKKEventParam& param) = 0;
     virtual SKKSubController* HandleJmode(SKKContext& context, const SKKEventParam& param) = 0;


aquaskk-changes メーリングリストの案内
Back to archive index