t-suw****@users*****
t-suw****@users*****
2007年 9月 24日 (月) 07:58:11 JST
Index: AquaSKK/src/context/SKKContext.cpp diff -u AquaSKK/src/context/SKKContext.cpp:1.1.2.2 AquaSKK/src/context/SKKContext.cpp:1.1.2.3 --- AquaSKK/src/context/SKKContext.cpp:1.1.2.2 Sun Sep 16 09:15:12 2007 +++ AquaSKK/src/context/SKKContext.cpp Mon Sep 24 07:58:10 2007 @@ -1,5 +1,5 @@ /* -*- C++ -*- - $Id: SKKContext.cpp,v 1.1.2.2 2007/09/16 00:15:12 t-suwa Exp $ + $Id: SKKContext.cpp,v 1.1.2.3 2007/09/23 22:58:10 t-suwa Exp $ MacOS X implementation of the SKK input method. @@ -21,26 +21,27 @@ */ #include "SKKContext.h" +#include "SKKRegistrationOutputPort.h" SKKContext::SKKContext() { + initialize(); } -SKKContext::SKKContext(const std::string& prompt) : prompt_(prompt_) { +SKKContext::SKKContext(const std::string& prompt) : prompt_(prompt) { + initialize(); } -SKKContext::SKKContext(const SKKContext& src) : prompt_(src.prompt_), result_(src.result_) { +SKKContext::SKKContext(const SKKContext& src) + : prompt_(src.prompt_), input_(src.input_), entry_(src.entry_), word_(src.word_) { + initialize(); } -const std::string& SKKContext::Prompt() const { - return prompt_; -} - -SKKEventResult& SKKContext::Result() { - return result_; +SKKContext::~SKKContext() { + delete port_; } -const SKKEventResult& SKKContext::Result() const { - return result_; +const std::string& SKKContext::Prompt() const { + return prompt_; } SKKInputBuffer& SKKContext::InputBuffer() { @@ -50,3 +51,22 @@ SKKEditBuffer& SKKContext::EditBuffer() { return entry_; } + +SKKEditBuffer& SKKContext::WordBuffer() { + return word_; +} + +SKKOutputPort& SKKContext::OutputPort() { + return *port_; +} + +// ====================================================================== +// private method +// ====================================================================== +void SKKContext::initialize() { + if(prompt_.empty()) { + port_ = new SKKOutputPort(*this); + } else { + port_ = new SKKRegistrationOutputPort(*this); + } +} Index: AquaSKK/src/context/SKKContext.h diff -u AquaSKK/src/context/SKKContext.h:1.1.2.2 AquaSKK/src/context/SKKContext.h:1.1.2.3 --- AquaSKK/src/context/SKKContext.h:1.1.2.2 Sun Sep 16 09:15:12 2007 +++ AquaSKK/src/context/SKKContext.h Mon Sep 24 07:58:10 2007 @@ -22,28 +22,32 @@ #define INC__SKKContext__ #include <string> -#include "SKKEventResult.h" #include "SKKInputBuffer.h" #include "SKKEditBuffer.h" +#include "SKKOutputPort.h" // å ¥åã³ã³ããã¹ã class SKKContext { std::string prompt_; // ç»é²ç¨è¦åºãèª - SKKEventResult result_; // å¦ççµæ SKKInputBuffer input_; // å ¥åãããã¡ SKKEditBuffer entry_; // è¦åºãèªãããã¡ + SKKEditBuffer word_; // ç»é²ãããã¡ + SKKOutputPort* port_; // åºåãã¼ã + + void initialize(); public: SKKContext(); SKKContext(const std::string& prompt); SKKContext(const SKKContext& src); + ~SKKContext(); const std::string& Prompt() const; - SKKEventResult& Result(); - const SKKEventResult& Result() const; SKKInputBuffer& InputBuffer(); SKKEditBuffer& EditBuffer(); + SKKEditBuffer& WordBuffer(); + SKKOutputPort& OutputPort(); }; #endif Index: AquaSKK/src/context/SKKEditBuffer.cpp diff -u AquaSKK/src/context/SKKEditBuffer.cpp:1.1.2.1 AquaSKK/src/context/SKKEditBuffer.cpp:1.1.2.2 --- AquaSKK/src/context/SKKEditBuffer.cpp:1.1.2.1 Sun Sep 16 09:15:12 2007 +++ AquaSKK/src/context/SKKEditBuffer.cpp Mon Sep 24 07:58:10 2007 @@ -22,7 +22,7 @@ #include "utf8util.h" /* - â ã«ã¼ã½ã«ä½ç½®ã«ã¤ã㦠+ << ã«ã¼ã½ã«ä½ç½®ã«ã¤ã㦠>> å ¥åå¦çã®ã»ã¨ãã©ãæååæ«å°¾ã¸ã®è¿½å ã¨åé¤ã§ãããããå é¨çã«ä¿æ ããã«ã¼ã½ã«ä½ç½®ã¯ãæååæ«å°¾ããã®ãªãã»ããã¨ãã¦ããã @@ -37,11 +37,7 @@ } void SKKEditBuffer::Insert(unsigned char ch) { - std::string tmp; - - tmp += ch; - - Insert(tmp); + Insert(std::string(1, ch)); } void SKKEditBuffer::Insert(const std::string& str) { Index: AquaSKK/src/context/SKKOutputPort.cpp diff -u /dev/null AquaSKK/src/context/SKKOutputPort.cpp:1.1.2.1 --- /dev/null Mon Sep 24 07:58:11 2007 +++ AquaSKK/src/context/SKKOutputPort.cpp Mon Sep 24 07:58:10 2007 @@ -0,0 +1,97 @@ +/* -*- 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 "SKKOutputPort.h" +#include "SKKComponent.h" +#include "SKKSession.h" +#include "utf8util.h" + +SKKOutputPort::SKKOutputPort(SKKContext& context) : context_(context) { +} + +SKKOutputPort::~SKKOutputPort() { +} + +void SKKOutputPort::DisplayString(const std::string& str) { + DisplayString(str, utf8::length(str)); +} + +void SKKOutputPort::DisplayString(const std::string& str, int cursorPosition) { +#if 1 + std::string tmp(str); + + utf8::push(tmp, "[I]", cursorPosition - utf8::length(str)); + + std::cerr << tmp << std::endl; +#else + SKKSession& active = SKKComponent::theInstance().Session(); + + CFStringRef cfstr = CFStringCreateWithCString(0, str.c_str(), kCFStringEncodingUTF8); + + active.DisplayString(cfstr, 0, cursorPosition); + + CFRelease(cfstr); +#endif +} + +void SKKOutputPort::FixString(const std::string& str) { +#if 1 + std::cerr << str; +#else + SKKSession& active = SKKComponent::theInstance().Session(); + + CFStringRef cfstr = CFStringCreateWithCString(0, str.c_str(), kCFStringEncodingUTF8); + + active.FixString(cfstr); + + CFRelease(cfstr); +#endif +} + +void SKKOutputPort::Terminate() { +#if 1 + std::cerr << "[terminate]" << std::endl; +#else + SKKSession& active = SKKComponent::theInstance().Session(); + + active.Terminate(); +#endif +} + +void SKKOutputPort::Ignore(char) { +} + +void SKKOutputPort::BackSpace() { +} + +void SKKOutputPort::Delete() { +} + +void SKKOutputPort::CursorLeft() { +} + +void SKKOutputPort::CursorRight() { +} + +void SKKOutputPort::CursorUp() { +} + +void SKKOutputPort::CursorDown() { +} Index: AquaSKK/src/context/SKKOutputPort.h diff -u /dev/null AquaSKK/src/context/SKKOutputPort.h:1.1.2.1 --- /dev/null Mon Sep 24 07:58:11 2007 +++ AquaSKK/src/context/SKKOutputPort.h Mon Sep 24 07:58:10 2007 @@ -0,0 +1,51 @@ +/* -*- 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__SKKOutputPort__ +#define INC__SKKOutputPort__ + +#include <string> + +class SKKContext; + +// åºåãã¼ãåºåºã¯ã©ã¹ +class SKKOutputPort { +protected: + SKKContext& context_; + +public: + SKKOutputPort(SKKContext& context); + virtual ~SKKOutputPort(); + + virtual void DisplayString(const std::string& str); + virtual void DisplayString(const std::string& str, int cursorPosition); + virtual void FixString(const std::string& str); + virtual void Terminate(); + + virtual void Ignore(char ch); + virtual void BackSpace(); + virtual void Delete(); + virtual void CursorLeft(); + virtual void CursorRight(); + virtual void CursorUp(); + virtual void CursorDown(); +}; + +#endif Index: AquaSKK/src/context/SKKRegistrationOutputPort.cpp diff -u /dev/null AquaSKK/src/context/SKKRegistrationOutputPort.cpp:1.1.2.1 --- /dev/null Mon Sep 24 07:58:11 2007 +++ AquaSKK/src/context/SKKRegistrationOutputPort.cpp Mon Sep 24 07:58:10 2007 @@ -0,0 +1,103 @@ +/* -*- 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 "SKKComponent.h" +#include "SKKSession.h" +#include "SKKContext.h" +#include "SKKRegistrationOutputPort.h" +#include "utf8util.h" + +SKKRegistrationOutputPort::SKKRegistrationOutputPort(SKKContext& context) + : SKKOutputPort(context), prompt_("[ç»é²ï¼" + context.Prompt() + "] ") { +} + +void SKKRegistrationOutputPort::DisplayString(const std::string& str) { + DisplayString(str, utf8::length(str)); +} + +void SKKRegistrationOutputPort::DisplayString(const std::string& str, int cursorPosition) { + SKKEditBuffer word(context_.WordBuffer()); + int insertPosition = utf8::length(prompt_) + word.CursorPosition(); + + word.Insert(str); + + std::string result(prompt_ + word.EditString()); + + SKKOutputPort::DisplayString(result, insertPosition + cursorPosition); +} + +void SKKRegistrationOutputPort::FixString(const std::string& str) { + SKKEditBuffer& word = context_.WordBuffer(); + + word.Insert(str); + + std::string result(prompt_ + word.EditString()); + + SKKOutputPort::DisplayString(result, utf8::length(prompt_) + word.CursorPosition()); +} + +void SKKRegistrationOutputPort::Ignore(char ch) { + DisplayString(std::string(1, ch)); +} + +void SKKRegistrationOutputPort::BackSpace() { + context_.WordBuffer().BackSpace(); + + display(); +} + +void SKKRegistrationOutputPort::Delete() { + context_.WordBuffer().Delete(); + + display(); +} + +void SKKRegistrationOutputPort::CursorLeft() { + context_.WordBuffer().CursorLeft(); + + display(); +} + +void SKKRegistrationOutputPort::CursorRight() { + context_.WordBuffer().CursorRight(); + + display(); +} + +void SKKRegistrationOutputPort::CursorUp() { + context_.WordBuffer().CursorUp(); + + display(); +} + +void SKKRegistrationOutputPort::CursorDown() { + context_.WordBuffer().CursorDown(); + + display(); +} + +// ====================================================================== +// private method +// ====================================================================== +void SKKRegistrationOutputPort::display() { + SKKEditBuffer& word = context_.WordBuffer(); + + DisplayString(prompt_ + word.EditString(), word.CursorPosition()); +} Index: AquaSKK/src/context/SKKRegistrationOutputPort.h diff -u /dev/null AquaSKK/src/context/SKKRegistrationOutputPort.h:1.1.2.1 --- /dev/null Mon Sep 24 07:58:11 2007 +++ AquaSKK/src/context/SKKRegistrationOutputPort.h Mon Sep 24 07:58:10 2007 @@ -0,0 +1,48 @@ +/* -*- 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__SKKRegistrationOutputPort__ +#define INC__SKKRegistrationOutputPort__ + +#include "SKKOutputPort.h" + +// åºåãã¼ã +class SKKRegistrationOutputPort : public SKKOutputPort { + const std::string prompt_; + + void display(); + +public: + SKKRegistrationOutputPort(SKKContext& context); + + virtual void DisplayString(const std::string& str); + virtual void DisplayString(const std::string& str, int cursorPosition); + virtual void FixString(const std::string& str); + + virtual void Ignore(char ch); + virtual void BackSpace(); + virtual void Delete(); + virtual void CursorLeft(); + virtual void CursorRight(); + virtual void CursorUp(); + virtual void CursorDown(); +}; + +#endif