[aquaskk-changes 348] CVS update: AquaSKK/src/keybindings

アーカイブの一覧に戻る

t-suw****@users***** t-suw****@users*****
2007年 8月 26日 (日) 01:34:45 JST


Index: AquaSKK/src/keybindings/SKKEventParam.h
diff -u /dev/null AquaSKK/src/keybindings/SKKEventParam.h:1.1.2.1
--- /dev/null	Sun Aug 26 01:34:45 2007
+++ AquaSKK/src/keybindings/SKKEventParam.h	Sun Aug 26 01:34:45 2007
@@ -0,0 +1,139 @@
+/* -*- 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__SKKEventParam__
+#define INC__SKKEventParam__
+
+#include <sstream>
+#include "GenericStateMachine.h"
+
+// キー入力イベント
+enum {
+    SKK_NULL = statemachinecxx_sourceforge_jp::USER_EVENT, // 無効なイベント
+    SKK_JMODE,			// Ctrl-J
+    SKK_ENTER,			// Ctrl-M
+    SKK_BACKSPACE,		// Ctrl-H
+    SKK_DELETE,			// Ctrl-D
+    SKK_TAB,			// Ctrl-I
+    SKK_CANCEL,			// Ctrl-G
+    SKK_PASTE,			// Ctrl-Y
+    SKK_LEFT,			// ←
+    SKK_UP,			// ↑
+    SKK_RIGHT,			// →
+    SKK_DOWN,			// ↓
+    SKK_CHAR,			// その他全てのキー入力
+    SKK_YES,			// 仮想イベント
+    SKK_NO,			// 仮想イベント
+    SKK_ON,			// 仮想イベント
+    SKK_OFF,			// 仮想イベント
+    SKK_HIRAKANA,		// 入力モード「ひらかな」
+    SKK_KATAKANA,		// 入力モード「カタカナ」
+    SKK_JISX0201KANA,		// 入力モード「半角カナ」
+    SKK_JISX0208LATIN,		// 入力モード「全角英数」
+    SKK_ASCII			// 入力モード「ASCII」
+};
+
+// SKK_CHAR 属性
+enum {
+    None,
+    Direct			= 1,
+    UpperCases			= 2,
+    ToggleKana			= 4,
+    ToggleJisx0201Kana		= 8,
+    SwitchToAscii		= 16,
+    SwitchToJisx0208Latin	= 32,
+    EnterJapanese		= 64,
+    EnterAbbrev			= 128,
+    NextCompletion		= 256,
+    PrevCompletion		= 512,
+    NextCandidate		= 1024,
+    PrevCandidate		= 2048,
+    RemoveTrigger		= 4096
+};
+
+// イベントパラメータ
+struct SKKEventParam {
+    int event;			// イベント(冗長だが仕方がない)
+    unsigned char code;		// 文字そのもの
+    int attribute;		// SKK_CHAR 属性
+
+    SKKEventParam() : event(0), code(0), attribute(0) {}
+    SKKEventParam(int e, unsigned char c, int a = None) : event(e), code(c), attribute(a) {}
+
+    // SKK_CHAR 属性問い合わせ
+    bool IsDirect() const			{ return attribute & Direct; }
+    bool IsUpperCases() const			{ return attribute & UpperCases; }
+    bool IsToggleKana() const			{ return attribute & ToggleKana; }
+    bool IsToggleJisx0201Kana() const		{ return attribute & ToggleJisx0201Kana; }
+    bool IsSwitchToAscii() const		{ return attribute & SwitchToAscii; }
+    bool IsSwitchToJisx0208Latin() const	{ return attribute & SwitchToJisx0208Latin; }
+    bool IsEnterJapanese() const		{ return attribute & EnterJapanese; }
+    bool IsEnterAbbrev() const			{ return attribute & EnterAbbrev; }
+    bool IsNextCompletion() const		{ return attribute & NextCompletion; }
+    bool IsPrevCompletion() const		{ return attribute & PrevCompletion; }
+    bool IsNextCandidate() const		{ return attribute & NextCandidate; }
+    bool IsPrevCandidate() const		{ return attribute & PrevCandidate; }
+    bool IsRemoveTrigger() const		{ return attribute & RemoveTrigger; }
+
+    const static SKKEventParam& Null() {
+	static SKKEventParam nullEvent(SKK_NULL, 0, 0);
+	return nullEvent;
+    }
+
+    bool operator==(const SKKEventParam& rhs) const {
+	return (event == rhs.event && code == rhs.code && attribute == rhs.attribute);
+    }
+
+    std::string dump() const {
+	const char* event_name[] = {
+	    "SKK_NULL",
+	    "SKK_JMODE",
+	    "SKK_ENTER",
+	    "SKK_BACKSPACE",
+	    "SKK_DELETE",
+	    "SKK_TAB",
+	    "SKK_CANCEL",
+	    "SKK_PASTE",
+	    "SKK_LEFT",
+	    "SKK_UP",
+	    "SKK_RIGHT",
+	    "SKK_DOWN",
+	    "SKK_CHAR",
+	    "SKK_YES",
+	    "SKK_NO",
+	    "SKK_ON",
+	    "SKK_OFF",
+	    "SKK_HIRAKANA",
+	    "SKK_KATAKANA",
+	    "SKK_JISX0201KANA",
+	    "SKK_JISX0208LATIN",
+	    "SKK_ASCII"
+	};
+
+	std::ostringstream buf;
+	buf << "event=" << event_name[event - SKK_NULL] << ", "
+	    << "code=" << std::hex << (unsigned int)code << ", "
+	    << "attr=" << std::dec << attribute;
+
+	return buf.str();
+    }
+};
+
+#endif
Index: AquaSKK/src/keybindings/SKKKeyState.h
diff -u /dev/null AquaSKK/src/keybindings/SKKKeyState.h:1.1.2.1
--- /dev/null	Sun Aug 26 01:34:45 2007
+++ AquaSKK/src/keybindings/SKKKeyState.h	Sun Aug 26 01:34:45 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__SKKKeyState__
+#define INC__SKKKeyState__
+
+// 以下のようなキー状態を作り出すユーティリティクラス
+//
+//  31       23       15       7      0 bit
+// +--------+--------+--------+--------+
+// + 未使用 |  ctrl  |key code| ascii  |
+// +--------+--------+--------+--------+
+class SKKKeyState {
+    int state_;
+
+    SKKKeyState();
+    SKKKeyState(int ascii, int keycode, bool ctrl) {
+	state_ = (ctrl << 16) | ((0xff & keycode) << 8) | (0xff & ascii);
+    }
+
+public:
+    static SKKKeyState Keycode(int code, bool ctrl) {
+	return SKKKeyState(0, code, ctrl);
+    }
+    static SKKKeyState Ascii(int code, bool ctrl) {
+	return SKKKeyState(code, 0, ctrl);
+    }
+    operator int() const {
+	return state_;
+    }
+};
+
+#endif
Index: AquaSKK/src/keybindings/SKKKeymap.cpp
diff -u /dev/null AquaSKK/src/keybindings/SKKKeymap.cpp:1.1.2.1
--- /dev/null	Sun Aug 26 01:34:45 2007
+++ AquaSKK/src/keybindings/SKKKeymap.cpp	Sun Aug 26 01:34:45 2007
@@ -0,0 +1,114 @@
+/* -*- 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 <fstream>
+#include "SKKKeyState.h"
+#include "SKKKeymap.h"
+#include "SKKKeymapEntry.h"
+
+void SKKKeymap::Initialize(const std::string& path) {
+    std::ifstream config(path.c_str());
+
+    if(!config) return;
+
+    // 初期化
+    events_.clear();
+    attributes_.clear();
+
+    std::string configKey;
+    std::string configValue;
+    while(config >> configKey >> configValue) {
+	// コメントは無視
+	if(!configKey.empty() && configKey[0] != '#') {
+	    SKKKeymapEntry entry(configKey, configValue);
+
+	    // キー情報を読み取る
+	    int key;
+	    while(entry >> key) {
+		// 明示的なイベント以外は全て SKK_CHAR として扱う
+		if(entry.IsEvent()) {
+		    events_[key] = entry.Symbol();
+		} else {
+		    events_[key] = SKK_CHAR;
+		    attributes_[key] |= entry.Symbol();
+		}
+	    }
+	}
+
+	// 行末まで読み飛ばす
+	config.ignore(0xff, '\n');
+    }
+}
+
+SKKEventParam SKKKeymap::Fetch(int ascii, int keycode, bool ctrl) {
+    SKKEventParam param;
+    Keymap* map;
+    Keymap::iterator iter;
+
+    // 文字コード
+    param.code = ascii;
+
+    // イベントの検索
+    map = &events_;
+    do {
+	// keycode イベントを最初に調べる(優先度高)
+	iter = map->find(SKKKeyState::Keycode(keycode, ctrl));
+	if(iter != map->end()) {
+	    param.event = iter->second;
+	    break;
+	}
+
+	// ascii イベント
+	iter = map->find(SKKKeyState::Ascii(ascii, ctrl));
+	if(iter != map->end()) {
+	    param.event = iter->second;
+	    break;
+	}
+
+	// デフォルト
+	if(!ctrl) {
+	    param.event = SKK_CHAR;
+	} else {
+	    param.event = SKK_NULL;
+	}
+    } while(0);
+
+    // SKK_CHAR イベントなら、属性を調べる
+    if(param.event == SKK_CHAR) {
+	map = &attributes_;
+
+	do {
+	    // keycode 属性を最初に調べる(優先度高)
+	    iter = map->find(SKKKeyState::Keycode(keycode, ctrl));
+	    if(iter != map->end()) {
+		param.attribute = iter->second;
+		break;
+	    }
+
+	    // ascii 属性
+	    iter = map->find(SKKKeyState::Ascii(ascii, ctrl));
+	    if(iter != map->end()) {
+		param.attribute = iter->second;
+	    }
+	} while(0);
+    }
+
+    return param;
+}
Index: AquaSKK/src/keybindings/SKKKeymap.h
diff -u /dev/null AquaSKK/src/keybindings/SKKKeymap.h:1.1.2.1
--- /dev/null	Sun Aug 26 01:34:45 2007
+++ AquaSKK/src/keybindings/SKKKeymap.h	Sun Aug 26 01:34:45 2007
@@ -0,0 +1,43 @@
+/* -*- 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__SKKKeymap__
+#define INC__SKKKeymap__
+
+#include <map>
+#include <string>
+#include "SKKEventParam.h"
+
+// キーマップ
+class SKKKeymap {
+    typedef std::map<int, int> Keymap;
+
+    Keymap events_;
+    Keymap attributes_;
+
+public:
+    // 初期化
+    void Initialize(const std::string& path_to_config);
+
+    // 検索
+    SKKEventParam Fetch(int ascii, int keycode, bool ctrl);
+};
+
+#endif
Index: AquaSKK/src/keybindings/SKKKeymapEntry.cpp
diff -u /dev/null AquaSKK/src/keybindings/SKKKeymapEntry.cpp:1.1.2.1
--- /dev/null	Sun Aug 26 01:34:45 2007
+++ AquaSKK/src/keybindings/SKKKeymapEntry.cpp	Sun Aug 26 01:34:45 2007
@@ -0,0 +1,230 @@
+/* -*- 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 "SKKEventParam.h"
+#include "SKKKeyState.h"
+#include "SKKKeymapEntry.h"
+
+// エントリーのタイプ
+// TYPE_EVENT は SKK_* を示す
+// TYPE_ATTRIBUTE は SKK_CHAR の属性を示す
+enum KeymapEntryType { TYPE_EVENT, TYPE_ATTRIBUTE };
+
+// ======================================================================
+// キーマップシンボルテーブル
+// ======================================================================
+static const struct {
+    const char* name;
+    int symbol;
+    int type;
+} KeymapTable[] = {
+    { "SKK_JMODE", 		SKK_JMODE,		TYPE_EVENT },
+    { "SKK_ENTER", 		SKK_ENTER,		TYPE_EVENT },
+    { "SKK_BACKSPACE", 		SKK_BACKSPACE,		TYPE_EVENT },
+    { "SKK_DELETE", 		SKK_DELETE,		TYPE_EVENT },
+    { "SKK_TAB", 		SKK_TAB,		TYPE_EVENT },
+    { "SKK_CANCEL", 		SKK_CANCEL,		TYPE_EVENT },
+    { "SKK_PASTE", 		SKK_PASTE,		TYPE_EVENT },
+    { "SKK_LEFT", 		SKK_LEFT,		TYPE_EVENT },
+    { "SKK_UP", 		SKK_UP,			TYPE_EVENT },
+    { "SKK_RIGHT", 		SKK_RIGHT,		TYPE_EVENT },
+    { "SKK_DOWN", 		SKK_DOWN,		TYPE_EVENT },
+    { "SKK_CHAR", 		SKK_CHAR,		TYPE_EVENT },
+    { "SKK_YES", 		SKK_YES,		TYPE_EVENT },
+    { "SKK_NO", 		SKK_NO,			TYPE_EVENT },
+    { "Direct", 		Direct,			TYPE_ATTRIBUTE },
+    { "UpperCases", 		UpperCases,		TYPE_ATTRIBUTE },
+    { "ToggleKana", 		ToggleKana,		TYPE_ATTRIBUTE },
+    { "ToggleJisx0201Kana", 	ToggleJisx0201Kana, 	TYPE_ATTRIBUTE },
+    { "SwitchToAscii", 		SwitchToAscii, 		TYPE_ATTRIBUTE },
+    { "SwitchToJisx0208Latin", 	SwitchToJisx0208Latin,	TYPE_ATTRIBUTE },
+    { "EnterJapanese", 		EnterJapanese, 		TYPE_ATTRIBUTE },
+    { "EnterAbbrev", 		EnterAbbrev, 		TYPE_ATTRIBUTE },
+    { "NextCompletion", 	NextCompletion, 	TYPE_ATTRIBUTE },
+    { "PrevCompletion", 	PrevCompletion,		TYPE_ATTRIBUTE },
+    { "NextCandidate", 		NextCandidate,		TYPE_ATTRIBUTE },
+    { "PrevCandidate", 		PrevCandidate,		TYPE_ATTRIBUTE },
+    { "RemoveTrigger", 		RemoveTrigger,		TYPE_ATTRIBUTE },
+    { 0x00, 			SKK_NULL,		-1 }
+};
+
+// 検索
+int fetchKeymapIndex(const std::string& key) {
+    for(int i = 0; KeymapTable[i].name != 0x00; ++ i) {
+	if(key == KeymapTable[i].name) {
+	    return i;
+	}
+    }
+
+    return -1;
+}
+
+// 文字列一括置換ユーティリティ
+void translate(std::string& src, const std::string& from, const std::string& to) {
+    unsigned pos = 0;
+
+    while((pos = src.find(from, pos)) != std::string::npos) {
+	src.replace(pos, from.size(), to);
+    }
+}
+
+// ======================================================================
+// SKKKeymapEntry インタフェース
+// ======================================================================
+SKKKeymapEntry::SKKKeymapEntry() : pos_(0) {
+    // empty
+}
+
+SKKKeymapEntry::SKKKeymapEntry(const std::string& configKey, const std::string& configValue) : pos_(0) {
+    int index = fetchKeymapIndex(configKey);
+    if(index < 0) {
+	std::cerr << "SKKKeymapEntry::SKKKeymapEntry(): invalid key name[" << configKey << "]" << std::endl;
+	return;
+    }
+
+    type_= KeymapTable[index].type;
+    symbol_ = KeymapTable[index].symbol;
+
+    // 全ての "||" を空白に置換
+    std::string tmp(configValue);
+    translate(tmp, "||", " ");
+
+    // 各エントリをパース
+    std::istringstream buf(tmp);
+    while(buf >> tmp) {
+	tmp = setup(tmp);
+
+	if(label_ & LABEL_GROUP) {
+	    parseGroup(tmp);
+	} else {
+	    parseEntry(tmp);
+	}
+    }
+}
+
+// キーの読み出し
+bool SKKKeymapEntry::operator>>(int& state) {
+    if(!(pos_ < keys_.size())) return false;
+
+    if(keys_[pos_].first <= keys_[pos_].second) {
+	state = keys_[pos_].first ++;
+	return true;
+    } else {
+	++ pos_;
+	return *this >> state; // 再帰
+    }
+}
+
+bool SKKKeymapEntry::IsEvent() const {
+    return type_ == TYPE_EVENT;
+}
+
+int SKKKeymapEntry::Symbol() const {
+    return symbol_;
+}
+
+// ======================================================================
+// private method
+// ======================================================================
+std::string SKKKeymapEntry::setup(const std::string& str) {
+    label_ = 0;
+
+    // 全ての "::" を空白に置換
+    std::string tmp(str);
+    translate(tmp, "::", " ");
+
+    // 各ラベルを解析する
+    std::istringstream buf(tmp);
+    while(buf >> tmp) {
+	if(tmp == "hex")	label_ += LABEL_HEX;
+	if(tmp == "ctrl")	label_ += LABEL_CTRL;
+	if(tmp == "group")	label_ += LABEL_GROUP;
+	if(tmp == "keycode")	label_ += LABEL_KEYCODE;
+    }
+
+    // ラベルを取り除いたキー情報を返す
+    return tmp;
+}
+
+// グループエントリの解析
+void SKKKeymapEntry::parseGroup(const std::string& str) {
+    // 全ての ',' を空白に置換
+    std::string tmp(str);
+    std::replace(tmp.begin(), tmp.end(), ',', ' ');
+
+    // 各エントリを解析
+    std::istringstream buf(tmp);
+    while(buf >> tmp) {
+	int pos = tmp.find_first_of('-');
+
+	// 範囲コードか?
+	if(pos != std::string::npos) {
+	    tmp[pos] = ' ';
+	    parseRange(tmp);
+	} else {
+	    parseEntry(tmp);
+	}
+    }
+}
+
+// 範囲コードの解析
+void SKKKeymapEntry::parseRange(const std::string& str) {
+    std::string tmp(str);
+    std::istringstream buf(tmp);
+    KeyRange range;
+
+    if(buf >> tmp) {
+	range.first = makeKey(tmp);
+
+	if(buf >> tmp) {
+	    range.second = makeKey(tmp);
+	    keys_.push_back(range);
+	}
+    }
+}
+
+// 単一エントリの解析
+void SKKKeymapEntry::parseEntry(const std::string& str) {
+    KeyRange range;
+
+    range.first = range.second = makeKey(str);
+
+    keys_.push_back(range);
+}
+
+// キーの生成
+int SKKKeymapEntry::makeKey(const std::string& str) {
+    int key;
+
+    // 16 進数表記?
+    if(label_ & (LABEL_HEX | LABEL_KEYCODE)) {
+	std::istringstream buf(str);
+	buf >> std::hex >> key;
+    } else {
+	key = str[0];
+    }
+
+    if(label_ & LABEL_KEYCODE) {
+	return SKKKeyState::Keycode(key, label_ & LABEL_CTRL);
+    } else {
+	return SKKKeyState::Ascii(key, label_ & LABEL_CTRL);
+    }
+}
Index: AquaSKK/src/keybindings/SKKKeymapEntry.h
diff -u /dev/null AquaSKK/src/keybindings/SKKKeymapEntry.h:1.1.2.1
--- /dev/null	Sun Aug 26 01:34:45 2007
+++ AquaSKK/src/keybindings/SKKKeymapEntry.h	Sun Aug 26 01:34:45 2007
@@ -0,0 +1,59 @@
+/* -*- 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__SKKKeymapEntry__
+#define INC__SKKKeymapEntry__
+
+#include <vector>
+#include <string>
+
+// キーマップパーサー
+class SKKKeymapEntry {
+    int type_;
+    int symbol_;
+    int label_;
+
+    typedef std::pair<int, int> KeyRange;
+    std::vector<KeyRange> keys_;
+    int pos_;
+
+    enum { LABEL_GROUP = 1, LABEL_CTRL = 2, LABEL_HEX = 4, LABEL_KEYCODE = 8 };
+
+    std::string setup(const std::string& str);
+    void parseGroup(const std::string& str);
+    void parseRange(const std::string& str);
+    void parseEntry(const std::string& str);
+    int makeKey(const std::string& str);
+
+public:
+    SKKKeymapEntry();
+    SKKKeymapEntry(const std::string& configKey, const std::string& configValue);
+
+    // キーの読み出し
+    bool operator>>(int& key);
+
+    // エントリーがイベントかどうか
+    bool IsEvent() const;
+
+    // シンボルの取得
+    int Symbol() const;
+};
+
+#endif
Index: AquaSKK/src/keybindings/SKKPreProcessor.cpp
diff -u /dev/null AquaSKK/src/keybindings/SKKPreProcessor.cpp:1.1.2.1
--- /dev/null	Sun Aug 26 01:34:45 2007
+++ AquaSKK/src/keybindings/SKKPreProcessor.cpp	Sun Aug 26 01:34:45 2007
@@ -0,0 +1,87 @@
+/* -*- C++ -*-
+   $Id: SKKPreProcessor.cpp,v 1.1.2.1 2007/08/25 16:34:45 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
+*/
+
+#include "SKKConfig.h"
+#include "SKKPreProcessor.h"
+
+SKKPreProcessor::SKKPreProcessor() {
+}
+
+SKKPreProcessor& SKKPreProcessor::theInstance() {
+    static SKKPreProcessor obj;
+    return obj;
+}
+
+void SKKPreProcessor::Initialize() {
+    keymap_.Initialize(SKKConfig::ResourceDirectory() + "keymap.conf");
+    keymap_.Initialize(SKKConfig::LibraryDirectory() + "keymap.conf");
+}
+
+SKKEventParam SKKPreProcessor::Execute(const EventRef event) {
+    // キーボードイベント以外は無視
+    if(GetEventClass(event) != kEventClassKeyboard) {
+	return SKKEventParam::Null();
+    }
+
+    // キーダウン以外は無視
+    switch(GetEventKind(event)) {
+    case kEventRawKeyDown:
+    case kEventRawKeyRepeat:
+	break;
+    default:
+	return SKKEventParam::Null();
+    }
+
+    char charcode;
+    UInt32 modifier;
+    UInt32 keycode;
+    UInt32 kbdtype;
+    UniChar uc;
+
+    // イベントパラメータを取得する
+    GetEventParameter(event, kEventParamKeyMacCharCodes, typeChar, 0, sizeof(charcode), 0, &charcode);
+    GetEventParameter(event, kEventParamKeyCode, typeUInt32, 0, sizeof(keycode), 0, &keycode);
+    GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, 0, sizeof(modifier), 0, &modifier);
+    GetEventParameter(event, kEventParamKeyboardType, typeUInt32, 0, sizeof(kbdtype), 0, &kbdtype);
+    GetEventParameter(event, kEventParamKeyUnicodes, typeUnicodeText, 0, sizeof(uc), 0, &uc);
+
+    // コマンドキーのコンビネーションは扱わない
+    if(modifier & cmdKey) {
+	return SKKEventParam::Null();
+    }
+
+    // コントロールキーが押されていた場合は、7bit 目を復元する
+    // http://developer.apple.com/qa/qa2005/qa1446.html
+    if(modifier & controlKey) {
+	long smv = GetScriptManagerVariable(smKeyScript);
+	Handle uchrHandle = GetResource('uchr', GetScriptVariable(smv, smScriptKeys));
+	UInt32 dummy = 0;
+
+	UCKeyTranslate((UCKeyboardLayout*)*uchrHandle, keycode, kUCKeyActionDisplay,
+		       (modifier & ~controlKey) >> 8, kbdtype, kUCKeyTranslateNoDeadKeysMask, &dummy, 1, &dummy, &uc);
+
+	charcode = uc;
+    }
+
+    // 入力されたキーから SKKEventParam を生成する
+    return keymap_.Fetch(charcode, keycode, modifier & controlKey);
+}
Index: AquaSKK/src/keybindings/SKKPreProcessor.h
diff -u /dev/null AquaSKK/src/keybindings/SKKPreProcessor.h:1.1.2.1
--- /dev/null	Sun Aug 26 01:34:45 2007
+++ AquaSKK/src/keybindings/SKKPreProcessor.h	Sun Aug 26 01:34:45 2007
@@ -0,0 +1,46 @@
+/* -*- C++ -*-
+   $Id: SKKPreProcessor.h,v 1.1.2.1 2007/08/25 16:34:45 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__SKKPreProcessor__
+#define INC__SKKPreProcessor__
+
+#include <Carbon/Carbon.h>
+#include "SKKKeymap.h"
+
+// キー入力前処理クラス
+class SKKPreProcessor {
+    SKKKeymap keymap_;
+
+    SKKPreProcessor();
+
+public:
+    // シングルトン    
+    static SKKPreProcessor& theInstance();
+
+    // キーマップのロード
+    void Initialize();
+
+    // キー入力イベント → SKKEventParam 変換
+    SKKEventParam Execute(const EventRef event);
+};
+
+#endif
Index: AquaSKK/src/keybindings/keymap.conf
diff -u /dev/null AquaSKK/src/keybindings/keymap.conf:1.1.2.1
--- /dev/null	Sun Aug 26 01:34:45 2007
+++ AquaSKK/src/keybindings/keymap.conf	Sun Aug 26 01:34:45 2007
@@ -0,0 +1,43 @@
+###
+### keymap.conf
+###
+
+# ======================================================================
+# event section
+# ======================================================================
+
+SKK_JMODE		ctrl::j
+SKK_ENTER		group::hex::0x03,0x0a,0x0d||ctrl::m
+SKK_TAB			hex::0x09||ctrl::i
+SKK_BACKSPACE		hex::0x08
+SKK_BACKSPACE		ctrl::h
+SKK_DELETE		hex::0x7f||ctrl::d
+SKK_CANCEL		ctrl::g
+SKK_PASTE		ctrl::y
+SKK_LEFT		hex::0x1c||ctrl::b
+SKK_RIGHT		hex::0x1d||ctrl::f
+SKK_UP			hex::0x1e||ctrl::p
+SKK_DOWN		hex::0x1f||ctrl::n
+
+# ======================================================================
+# attribute section(for SKK_CHAR)
+# ======================================================================
+
+ToggleKana		q
+ToggleJisx0201Kana	ctrl::q
+SwitchToAscii		l
+SwitchToJisx0208Latin	L
+
+EnterAbbrev		/
+EnterJapanese		Q
+#EnterJapanese		keycode::0x66	# EISU
+#EnterJapanese		keycode::0x68	# KANA
+NextCompletion		.
+PrevCompletion		,
+NextCandidate		hex::0x20
+PrevCandidate		x
+RemoveTrigger		X
+
+UpperCases		group::A-K,M-P,R-W,Z
+
+Direct			group::keycode::0x41,0x43,0x45,0x4b,0x4e,0x51-0x59,0x5b,0x5c,0x5f


aquaskk-changes メーリングリストの案内
アーカイブの一覧に戻る