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