t-suw****@users*****
t-suw****@users*****
2007年 9月 2日 (日) 12:36:25 JST
Index: AquaSKK/src/controller/SKKController.cpp diff -u /dev/null AquaSKK/src/controller/SKKController.cpp:1.1.2.1 --- /dev/null Sun Sep 2 12:36:25 2007 +++ AquaSKK/src/controller/SKKController.cpp Sun Sep 2 12:36:25 2007 @@ -0,0 +1,136 @@ +/* -*- 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 "SKKController.h" +#include "SKKSubController.h" + +typedef SKKController::Event Event; +typedef SKKController::State State; +typedef SKKController::Handler Handler; +typedef SKKController::Output Output; + +static SKKEventParam dummy; + +SKKController::SKKController() { + // ãã©ã¤ããªã¨ãã£ã¿ãçæ + stack_.push_back(SKKEditor()); +} + +// å¦ççµæ +const Output& SKKController::Result() const { + return editor().Result(); +} + +// ãã¼å ¥åå¦ç +State SKKController::HandleInput(const SKKEventParam& param) { + return invoke(&SKKEditor::HandleInput, param); +} + +State SKKController::HandleJmode() { + return invoke(&SKKEditor::HandleJmode, dummy); +} + +State SKKController::HandleEnter() { + return invoke(&SKKEditor::HandleEnter, dummy); +} + +State SKKController::HandleCancel() { + return invoke(&SKKEditor::HandleCancel, dummy); +} + +State SKKController::HandleBackSpace() { + return invoke(&SKKEditor::HandleBackSpace, dummy); +} + +State SKKController::HandleDelete() { + return invoke(&SKKEditor::HandleDelete, dummy); +} + +State SKKController::HandleTab() { + return invoke(&SKKEditor::HandleTab, dummy); +} + +State SKKController::HandlePaste() { + return invoke(&SKKEditor::HandlePaste, dummy); +} + +State SKKController::HandleCursorLeft() { + return invoke(&SKKEditor::HandleCursorLeft, dummy); +} + +State SKKController::HandleCursorRight() { + return invoke(&SKKEditor::HandleCursorRight, dummy); +} + +State SKKController::HandleCursorUp() { + return invoke(&SKKEditor::HandleCursorUp, dummy); +} + +State SKKController::HandleCursorDown() { + return invoke(&SKKEditor::HandleCursorDown, dummy); +} + +// å ¥åã¢ã¼ãå¤æ´ +void SKKController::SelectInputMode(SKK::InputMode mode) { + editor().SelectInputMode(mode); +} + +// å é¨ç¶æ å¤æ´ +void SKKController::ChangeState(SKK::EditState state) { + editor().ChangeState(state); +} + +// ç»é²éå§ +void SKKController::BeginRegistration(const std::string& prompt) { + stack_.push_back(SKKEditor(prompt)); +} + +// ç»é²çµäº +void SKKController::EndRegistration(bool commit) { + if(stack_.size() == 1) return; + + std::string result = editor().EditString(); + + stack_.pop_back(); + + if(commit) { + editor().Commit(result); + } +} + +// ====================================================================== +// private method +// ====================================================================== +SKKEditor& SKKController::editor() { + return stack_.back(); +} + +const SKKEditor& SKKController::editor() const { + return stack_.back(); +} + +State SKKController::invoke(SKKEditor::Handler handler, const SKKEventParam& param) { + // SKKEditor.HandleXXX ãèµ·åãã + std::auto_ptr<SKKSubController> sub((editor().*handler)(param)); + + // å¯ä½ç¨ãé©ç¨ãã + return sub->Apply(*this); +} Index: AquaSKK/src/controller/SKKController.h diff -u /dev/null AquaSKK/src/controller/SKKController.h:1.1.2.1 --- /dev/null Sun Sep 2 12:36:25 2007 +++ AquaSKK/src/controller/SKKController.h Sun Sep 2 12:36:25 2007 @@ -0,0 +1,77 @@ +/* -*- C++ -*- + $Id: SKKController.h,v 1.1.2.1 2007/09/02 03:36:25 t-suwa Exp $ + + 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__SKKController__ +#define INC__SKKController__ + +#include <string> +#include <vector> +#include "SKK.h" +#include "SKKEventParam.h" +#include "SKKEnvironment.h" +#include "SKKEditor.h" + +struct SKKController { + typedef SKKEnvironment::State State; + typedef SKKEnvironment::Event Event; + typedef SKKEnvironment::Handler Handler; + typedef SKKEnvironment::Output Output; + + SKKController(); + + // å¦ççµæ + const Output& Result() const; + + // ãã¼å ¥åå¦ç + State HandleInput(const SKKEventParam& param); + State HandleJmode(); + State HandleEnter(); + State HandleCancel(); + State HandleBackSpace(); + State HandleDelete(); + State HandleTab(); + State HandlePaste(); + State HandleCursorLeft(); + State HandleCursorRight(); + State HandleCursorUp(); + State HandleCursorDown(); + + // å ¥åã¢ã¼ãå¤æ´ + void SelectInputMode(SKK::InputMode); + + // å é¨ç¶æ å¤æ´ + void ChangeState(SKK::EditState); + + // å帰çè¾æ¸ç»é² + void BeginRegistration(const std::string& prompt); + void EndRegistration(bool commit); + +private: + std::vector<SKKEditor> stack_; + + SKKEditor& editor(); + const SKKEditor& editor() const; + + State invoke(SKKEditor::Handler handler, const SKKEventParam& param); +}; + +#endif Index: AquaSKK/src/controller/SKKEmptySubController.cpp diff -u /dev/null AquaSKK/src/controller/SKKEmptySubController.cpp:1.1.2.1 --- /dev/null Sun Sep 2 12:36:25 2007 +++ AquaSKK/src/controller/SKKEmptySubController.cpp Sun Sep 2 12:36:25 2007 @@ -0,0 +1,29 @@ +/* -*- 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 "SKKEmptySubController.h" + +SKKEmptySubController::SKKEmptySubController(State target) : state_(target) { +} + +SKKEmptySubController::State SKKEmptySubController::Apply(SKKController&) { + return state_; +} Index: AquaSKK/src/controller/SKKEmptySubController.h diff -u /dev/null AquaSKK/src/controller/SKKEmptySubController.h:1.1.2.1 --- /dev/null Sun Sep 2 12:36:25 2007 +++ AquaSKK/src/controller/SKKEmptySubController.h Sun Sep 2 12:36:25 2007 @@ -0,0 +1,39 @@ +/* -*- 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__SKKEmptySubController__ +#define INC__SKKEmptySubController__ + +#include "SKKSubController.h" + +// 空ã®ãããã¥ã¬ã¼ã¿ã¼ +class SKKEmptySubController : public SKKSubController { + State state_; + + SKKEmptySubController(); + +public: + SKKEmptySubController(State target); + + virtual State Apply(SKKController& controller); +}; + +#endif Index: AquaSKK/src/controller/SKKSubController.h diff -u /dev/null AquaSKK/src/controller/SKKSubController.h:1.1.2.1 --- /dev/null Sun Sep 2 12:36:25 2007 +++ AquaSKK/src/controller/SKKSubController.h Sun Sep 2 12:36:25 2007 @@ -0,0 +1,37 @@ +/* -*- 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__SKKSubController__ +#define INC__SKKSubController__ + +#include "SKKController.h" + +// SKKController ç¨ãããã¥ã¬ã¼ã¿ã¼ +struct SKKSubController { + typedef SKKController::State State; + typedef SKKController::Event Event; + typedef SKKController::Handler Handler; + typedef SKKController::Output Output; + + virtual State Apply(SKKController& controller) = 0; +}; + +#endif