t-suw****@users*****
t-suw****@users*****
2007年 9月 16日 (日) 09:15:12 JST
Index: AquaSKK/src/context/SKKContext.cpp diff -u AquaSKK/src/context/SKKContext.cpp:1.1.2.1 AquaSKK/src/context/SKKContext.cpp:1.1.2.2 --- AquaSKK/src/context/SKKContext.cpp:1.1.2.1 Sun Sep 2 12:36:25 2007 +++ AquaSKK/src/context/SKKContext.cpp Sun Sep 16 09:15:12 2007 @@ -1,5 +1,5 @@ /* -*- C++ -*- - $Id: SKKContext.cpp,v 1.1.2.1 2007/09/02 03:36:25 t-suwa Exp $ + $Id: SKKContext.cpp,v 1.1.2.2 2007/09/16 00:15:12 t-suwa Exp $ MacOS X implementation of the SKK input method. @@ -31,10 +31,22 @@ SKKContext::SKKContext(const SKKContext& src) : prompt_(src.prompt_), result_(src.result_) { } +const std::string& SKKContext::Prompt() const { + return prompt_; +} + +SKKEventResult& SKKContext::Result() { + return result_; +} + const SKKEventResult& SKKContext::Result() const { return result_; } -const std::string& SKKContext::Prompt() const { - return prompt_; +SKKInputBuffer& SKKContext::InputBuffer() { + return input_; +} + +SKKEditBuffer& SKKContext::EditBuffer() { + return entry_; } Index: AquaSKK/src/context/SKKContext.h diff -u AquaSKK/src/context/SKKContext.h:1.1.2.1 AquaSKK/src/context/SKKContext.h:1.1.2.2 --- AquaSKK/src/context/SKKContext.h:1.1.2.1 Sun Sep 2 12:36:25 2007 +++ AquaSKK/src/context/SKKContext.h Sun Sep 16 09:15:12 2007 @@ -23,21 +23,27 @@ #include <string> #include "SKKEventResult.h" +#include "SKKInputBuffer.h" +#include "SKKEditBuffer.h" // å ¥åã³ã³ããã¹ã class SKKContext { std::string prompt_; // ç»é²ç¨è¦åºãèª - SKKEventResult result_; + SKKEventResult result_; // å¦ççµæ + SKKInputBuffer input_; // å ¥åãããã¡ + SKKEditBuffer entry_; // è¦åºãèªãããã¡ public: SKKContext(); SKKContext(const std::string& prompt); SKKContext(const SKKContext& src); - // å¦ççµæ + const std::string& Prompt() const; + SKKEventResult& Result(); const SKKEventResult& Result() const; - const std::string& Prompt() const; + SKKInputBuffer& InputBuffer(); + SKKEditBuffer& EditBuffer(); }; #endif Index: AquaSKK/src/context/SKKEditBuffer.cpp diff -u /dev/null AquaSKK/src/context/SKKEditBuffer.cpp:1.1.2.1 --- /dev/null Sun Sep 16 09:15:12 2007 +++ AquaSKK/src/context/SKKEditBuffer.cpp Sun Sep 16 09:15:12 2007 @@ -0,0 +1,106 @@ +/* -*- 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 "SKKEditBuffer.h" +#include "utf8util.h" + +/* + â ã«ã¼ã½ã«ä½ç½®ã«ã¤ã㦠+ + å ¥åå¦çã®ã»ã¨ãã©ãæååæ«å°¾ã¸ã®è¿½å ã¨åé¤ã§ãããããå é¨çã«ä¿æ + ããã«ã¼ã½ã«ä½ç½®ã¯ãæååæ«å°¾ããã®ãªãã»ããã¨ãã¦ããã +*/ + +SKKEditBuffer::SKKEditBuffer() { + initialize(); +} + +SKKEditBuffer::SKKEditBuffer(const std::string& buf) : buf_(buf) { + initialize(); +} + +void SKKEditBuffer::Insert(unsigned char ch) { + std::string tmp; + + tmp += ch; + + Insert(tmp); +} + +void SKKEditBuffer::Insert(const std::string& str) { + utf8::push(buf_, str, - cursor_pos_); +} + +void SKKEditBuffer::BackSpace() { + if(cursor_pos_ == utf8::length(buf_)) return; + + utf8::pop(buf_, - cursor_pos_); +} + +void SKKEditBuffer::Delete() { + if(cursor_pos_ == 0) return; + + utf8::pop(buf_, - (cursor_pos_ - 1)); + CursorRight(); +} + +void SKKEditBuffer::Clear() { + buf_.clear(); + cursor_pos_ = 0; +} + +bool SKKEditBuffer::IsEmpty() const { + return buf_.empty(); +} + +void SKKEditBuffer::CursorLeft() { + if(cursor_pos_ < utf8::length(buf_)) { + ++ cursor_pos_; + } +} + +void SKKEditBuffer::CursorRight() { + if(cursor_pos_) { + -- cursor_pos_; + } +} + +void SKKEditBuffer::CursorUp() { + cursor_pos_ = utf8::length(buf_); +} + +void SKKEditBuffer::CursorDown() { + cursor_pos_ = 0; +} + +const std::string& SKKEditBuffer::EditString() const { + return buf_; +} + +unsigned SKKEditBuffer::CursorPosition() const { + return utf8::length(buf_) - cursor_pos_; +} + +// ====================================================================== +// private +// ====================================================================== +void SKKEditBuffer::initialize() { + cursor_pos_ = 0; +} Index: AquaSKK/src/context/SKKEditBuffer.h diff -u /dev/null AquaSKK/src/context/SKKEditBuffer.h:1.1.2.1 --- /dev/null Sun Sep 16 09:15:12 2007 +++ AquaSKK/src/context/SKKEditBuffer.h Sun Sep 16 09:15:12 2007 @@ -0,0 +1,57 @@ +/* -*- 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__SKKEditBuffer__ +#define INC__SKKEditBuffer__ + +#include <string> + +// UTF8 æååã®ç·¨é & ã«ã¼ã½ã«ç§»åããµãã¼ã +class SKKEditBuffer { + std::string buf_; + unsigned cursor_pos_; // æ«å°¾ããã®è·é¢ + + void initialize(); + +public: + SKKEditBuffer(); + SKKEditBuffer(const std::string& buf); + + // ç·¨é + void Insert(unsigned char ch); + void Insert(const std::string& str); + void BackSpace(); + void Delete(); + void Clear(); + + bool IsEmpty() const; + + // ã«ã¼ã½ã«ç§»å + void CursorLeft(); + void CursorRight(); + void CursorUp(); // 左端 + void CursorDown(); // å³ç«¯ + + // ãã®ä» + const std::string& EditString() const; + unsigned CursorPosition() const; // å é ããã®è·é¢(0 ãã¼ã¹) +}; + +#endif Index: AquaSKK/src/context/SKKInputBuffer.cpp diff -u AquaSKK/src/context/SKKInputBuffer.cpp:1.1.2.1 AquaSKK/src/context/SKKInputBuffer.cpp:1.1.2.2 --- AquaSKK/src/context/SKKInputBuffer.cpp:1.1.2.1 Wed Sep 12 22:45:15 2007 +++ AquaSKK/src/context/SKKInputBuffer.cpp Sun Sep 16 09:15:12 2007 @@ -74,6 +74,10 @@ Clear(); } +SKK::InputMode SKKInputBuffer::InputMode() const { + return input_mode_; +} + const std::string& SKKInputBuffer::InputString() const { return buf_; } Index: AquaSKK/src/context/SKKInputBuffer.h diff -u AquaSKK/src/context/SKKInputBuffer.h:1.1.2.1 AquaSKK/src/context/SKKInputBuffer.h:1.1.2.2 --- AquaSKK/src/context/SKKInputBuffer.h:1.1.2.1 Wed Sep 12 22:45:15 2007 +++ AquaSKK/src/context/SKKInputBuffer.h Sun Sep 16 09:15:12 2007 @@ -42,6 +42,7 @@ bool IsEmpty() const; void SelectInputMode(SKK::InputMode mode); + SKK::InputMode InputMode() const; const std::string& InputString() const; const std::string& FixedString() const;