[aquaskk-changes 371] CVS update: AquaSKK/src/context

Back to archive index

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;


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