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

Back to archive index

t-suw****@users***** t-suw****@users*****
2007年 10月 14日 (日) 18:04:18 JST


Index: AquaSKK/src/keybindings/SKKKeyState.h
diff -u AquaSKK/src/keybindings/SKKKeyState.h:1.1.2.1 AquaSKK/src/keybindings/SKKKeyState.h:1.1.2.2
--- AquaSKK/src/keybindings/SKKKeyState.h:1.1.2.1	Sun Aug 26 01:34:45 2007
+++ AquaSKK/src/keybindings/SKKKeyState.h	Sun Oct 14 18:04:18 2007
@@ -25,22 +25,32 @@
 //
 //  31       23       15       7      0 bit
 // +--------+--------+--------+--------+
-// + 未使用 |  ctrl  |key code| ascii  |
+// + 未使用 |modifier|key code| ascii  |
 // +--------+--------+--------+--------+
+//
+// modifier は shift, ctrl, alt(=opt), meta(=cmd)
+//
 class SKKKeyState {
     int state_;
 
     SKKKeyState();
-    SKKKeyState(int ascii, int keycode, bool ctrl) {
-	state_ = (ctrl << 16) | ((0xff & keycode) << 8) | (0xff & ascii);
+    SKKKeyState(int charcode, int keycode, short mods) {
+	state_ = (mods << 16) | ((0xff & keycode) << 8) | (0xff & charcode);
     }
 
 public:
-    static SKKKeyState Keycode(int code, bool ctrl) {
-	return SKKKeyState(0, code, ctrl);
+    enum Modifier {
+	SHIFT	= (1 << 1),
+	CTRL	= (1 << 2),
+	ALT	= (1 << 3),
+	META	= (1 << 4)
+    };
+
+    static SKKKeyState KeyCode(int code, int mods) {
+	return SKKKeyState(0, code, mods);
     }
-    static SKKKeyState Ascii(int code, bool ctrl) {
-	return SKKKeyState(code, 0, ctrl);
+    static SKKKeyState CharCode(int code, int mods) {
+	return SKKKeyState(code, 0, mods);
     }
     operator int() const {
 	return state_;
Index: AquaSKK/src/keybindings/SKKKeymap.cpp
diff -u AquaSKK/src/keybindings/SKKKeymap.cpp:1.1.2.1 AquaSKK/src/keybindings/SKKKeymap.cpp:1.1.2.2
--- AquaSKK/src/keybindings/SKKKeymap.cpp:1.1.2.1	Sun Aug 26 01:34:45 2007
+++ AquaSKK/src/keybindings/SKKKeymap.cpp	Sun Oct 14 18:04:18 2007
@@ -57,37 +57,33 @@
     }
 }
 
-SKKEventParam SKKKeymap::Fetch(int ascii, int keycode, bool ctrl) {
+SKKEventParam SKKKeymap::Fetch(int charcode, int keycode, int mods) {
     SKKEventParam param;
     Keymap* map;
     Keymap::iterator iter;
 
     // 文字コード
-    param.code = ascii;
+    param.code = charcode;
 
     // イベントの検索
     map = &events_;
     do {
 	// keycode イベントを最初に調べる(優先度高)
-	iter = map->find(SKKKeyState::Keycode(keycode, ctrl));
+	iter = map->find(SKKKeyState::KeyCode(keycode, mods));
 	if(iter != map->end()) {
 	    param.event = iter->second;
 	    break;
 	}
 
-	// ascii イベント
-	iter = map->find(SKKKeyState::Ascii(ascii, ctrl));
+	// charcode イベント
+	iter = map->find(SKKKeyState::CharCode(charcode, mods));
 	if(iter != map->end()) {
 	    param.event = iter->second;
 	    break;
 	}
 
 	// デフォルト
-	if(!ctrl) {
-	    param.event = SKK_CHAR;
-	} else {
-	    param.event = SKK_NULL;
-	}
+	param.event = SKK_CHAR;
     } while(0);
 
     // SKK_CHAR イベントなら、属性を調べる
@@ -96,16 +92,21 @@
 
 	do {
 	    // keycode 属性を最初に調べる(優先度高)
-	    iter = map->find(SKKKeyState::Keycode(keycode, ctrl));
+	    iter = map->find(SKKKeyState::KeyCode(keycode, mods));
 	    if(iter != map->end()) {
 		param.attribute = iter->second;
 		break;
 	    }
 
-	    // ascii 属性
-	    iter = map->find(SKKKeyState::Ascii(ascii, ctrl));
+	    // charcode 属性
+	    iter = map->find(SKKKeyState::CharCode(charcode, mods));
 	    if(iter != map->end()) {
 		param.attribute = iter->second;
+		break;
+	    }
+
+	    if(mods != 0) {
+		param.event = SKK_NULL;
 	    }
 	} while(0);
     }
Index: AquaSKK/src/keybindings/SKKKeymap.h
diff -u AquaSKK/src/keybindings/SKKKeymap.h:1.1.2.1 AquaSKK/src/keybindings/SKKKeymap.h:1.1.2.2
--- AquaSKK/src/keybindings/SKKKeymap.h:1.1.2.1	Sun Aug 26 01:34:45 2007
+++ AquaSKK/src/keybindings/SKKKeymap.h	Sun Oct 14 18:04:18 2007
@@ -37,7 +37,7 @@
     void Initialize(const std::string& path_to_config);
 
     // 検索
-    SKKEventParam Fetch(int ascii, int keycode, bool ctrl);
+    SKKEventParam Fetch(int charcode, int keycode, int mods);
 };
 
 #endif
Index: AquaSKK/src/keybindings/SKKKeymapEntry.cpp
diff -u AquaSKK/src/keybindings/SKKKeymapEntry.cpp:1.1.2.2 AquaSKK/src/keybindings/SKKKeymapEntry.cpp:1.1.2.3
--- AquaSKK/src/keybindings/SKKKeymapEntry.cpp:1.1.2.2	Sun Sep  2 12:36:25 2007
+++ AquaSKK/src/keybindings/SKKKeymapEntry.cpp	Sun Oct 14 18:04:18 2007
@@ -145,7 +145,7 @@
 // private method
 // ======================================================================
 std::string SKKKeymapEntry::setup(const std::string& str) {
-    label_ = 0;
+    label_ = mods_ = 0;
 
     // 全ての "::" を空白に置換
     std::string tmp(str);
@@ -154,10 +154,14 @@
     // 各ラベルを解析する
     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;
+	if(tmp == "group")	label_ |= LABEL_GROUP;
+	if(tmp == "hex")	label_ |= LABEL_HEX;
+	if(tmp == "keycode")	label_ |= LABEL_KEYCODE;
+
+	if(tmp == "shift")	mods_ |= SKKKeyState::SHIFT;
+	if(tmp == "ctrl")	mods_ |= SKKKeyState::CTRL;
+	if(tmp == "alt")	mods_ |= SKKKeyState::ALT;
+	if(tmp == "meta")	mods_ |= SKKKeyState::META;
     }
 
     // ラベルを取り除いたキー情報を返す
@@ -223,8 +227,8 @@
     }
 
     if(label_ & LABEL_KEYCODE) {
-	return SKKKeyState::Keycode(key, label_ & LABEL_CTRL);
+	return SKKKeyState::KeyCode(key, mods_);
     } else {
-	return SKKKeyState::Ascii(key, label_ & LABEL_CTRL);
+	return SKKKeyState::CharCode(key, mods_);
     }
 }
Index: AquaSKK/src/keybindings/SKKKeymapEntry.h
diff -u AquaSKK/src/keybindings/SKKKeymapEntry.h:1.1.2.1 AquaSKK/src/keybindings/SKKKeymapEntry.h:1.1.2.2
--- AquaSKK/src/keybindings/SKKKeymapEntry.h:1.1.2.1	Sun Aug 26 01:34:45 2007
+++ AquaSKK/src/keybindings/SKKKeymapEntry.h	Sun Oct 14 18:04:18 2007
@@ -29,12 +29,17 @@
     int type_;
     int symbol_;
     int label_;
+    int mods_;
 
     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 };
+    enum {
+	LABEL_GROUP	= (1 << 1),
+	LABEL_HEX	= (1 << 2),
+	LABEL_KEYCODE	= (1 << 3)
+    };
 
     std::string setup(const std::string& str);
     void parseGroup(const std::string& str);
Index: AquaSKK/src/keybindings/SKKPreProcessor.cpp
diff -u AquaSKK/src/keybindings/SKKPreProcessor.cpp:1.1.2.2 AquaSKK/src/keybindings/SKKPreProcessor.cpp:1.1.2.3
--- AquaSKK/src/keybindings/SKKPreProcessor.cpp:1.1.2.2	Sun Sep 16 09:21:45 2007
+++ AquaSKK/src/keybindings/SKKPreProcessor.cpp	Sun Oct 14 18:04:18 2007
@@ -1,5 +1,5 @@
 /* -*- C++ -*-
-   $Id: SKKPreProcessor.cpp,v 1.1.2.2 2007/09/16 00:21:45 t-suwa Exp $
+   $Id: SKKPreProcessor.cpp,v 1.1.2.3 2007/10/14 09:04:18 t-suwa Exp $
 
    MacOS X implementation of the SKK input method.
 
@@ -20,9 +20,12 @@
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
+#include <iostream>
+#include <cctype>
 #include <fstream>
 #include "SKKConfig.h"
 #include "SKKPreProcessor.h"
+#include "SKKKeyState.h"
 
 SKKPreProcessor::SKKPreProcessor() {
 }
@@ -71,24 +74,42 @@
     GetEventParameter(event, kEventParamKeyboardType, typeUInt32, 0, sizeof(kbdtype), 0, &kbdtype);
     GetEventParameter(event, kEventParamKeyUnicodes, typeUnicodeText, 0, sizeof(uc), 0, &uc);
 
-    // コマンドキーのコンビネーションは扱わない
-    if(modifier & cmdKey) {
-	return SKKEventParam::Null();
+    int mods = 0;
+
+    if(modifier & shiftKey && !std::isgraph(charcode)) {
+	mods += SKKKeyState::SHIFT;
     }
 
     // コントロールキーが押されていた場合は、7bit 目を復元する
     // http://developer.apple.com/qa/qa2005/qa1446.html
     if(modifier & controlKey) {
-	long smv = GetScriptManagerVariable(smKeyScript);
-	Handle uchrHandle = GetResource('uchr', GetScriptVariable(smv, smScriptKeys));
+	UCKeyboardLayout* uchr_ptr = 0;
+	KeyboardLayoutRef layout;
 	UInt32 dummy = 0;
 
-	UCKeyTranslate((UCKeyboardLayout*)*uchrHandle, keycode, kUCKeyActionDisplay,
-		       (modifier & ~controlKey) >> 8, kbdtype, kUCKeyTranslateNoDeadKeysMask, &dummy, 1, &dummy, &uc);
+	KLGetCurrentKeyboardLayout(&layout);
+	KLGetKeyboardLayoutProperty(layout, kKLuchrData, (const void**)&uchr_ptr);
+	if(uchr_ptr) {
+	    UCKeyTranslate(uchr_ptr, keycode, kUCKeyActionDisplay, (modifier & ~controlKey) >> 8,
+			   kbdtype, kUCKeyTranslateNoDeadKeysMask, &dummy, 1, &dummy, &uc);
+	} else {
+	    dummy = 0;
+	    KLGetKeyboardLayoutProperty(layout, kKLKCHRData, (const void**)&uchr_ptr);
+	    uc = KeyTranslate(uchr_ptr, keycode, &dummy);
+	}
 
 	charcode = uc;
+	mods += SKKKeyState::CTRL;
+    }
+
+    if(modifier & optionKey) {
+	mods += SKKKeyState::ALT;
+    }
+
+    if(modifier & cmdKey) {
+	mods += SKKKeyState::META;
     }
 
     // 入力されたキーから SKKEventParam を生成する
-    return keymap_.Fetch(charcode, keycode, modifier & controlKey);
+    return keymap_.Fetch(charcode, keycode, mods);
 }


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