📄 uiime_zy.c
字号:
#include "uiIme_zy.h"
#include "uiZY_Tbl.res"
#include "uisw_kbd.h"
/***********************************************************************
*
* Internal Constants
*
***********************************************************************/
#define BOPOMOFO_KEY_NUMBER 52 // 注音键盘按键个数
#define BOPOMOFO_KEY_INDEX_BACKSPACE 21 // backspace的索引
#define BOPOMOFO_KEY_INDEX_ADDRESS 44
#define BOPOMOFO_KEY_INDEX_SYMBOL 45
#define BOPOMOFO_KEY_INDEX_SPACE 46 // 空白键的索引
#define BOPOMOFO_GRP_1 1 // 第一类由 0开始
#define BOPOMOFO_GRP_2 22 // 第二类由21开始
#define BOPOMOFO_GRP_3 25
#define BOPOMOFO_GRP_4 38
#if 0//Useless
static WORD BopomofoKey[BOPOMOFO_KEY_NUMBER] = {
//ㄅ ㄉ ˇ ㄓ ㄚ ㄞ ㄢ ㄦ
1, 5, 41, 42, 15, 40, 39, 25, 29, 33, 37,
//ㄆ ㄊ ㄍ ㄐ ㄔ ㄗ ㄧ ㄛ ㄟ ㄣ BK
2, 6, 9, 12, 16, 19, 22, 26, 30, 34, KEY_BACKSPACE,
//ㄇ ㄋ ㄎ ㄑ ㄕ ㄘ ㄨ ㄜ ㄠ ㄤ TAB
3, 7, 10, 13, 17, 20, 23, 27, 31, 35, KEY_TAB,
//ㄈ ㄌ ㄏ ㄒ ㄖ ㄙ ㄩ ㄝ ㄡ ㄥ
4, 8, 11, 14, 18, 21, 24, 28, 32, 36, KEY_ENTER,
//址 符 space 、 , . 。 DEL
38, 39, 40, 0xa142,0xa141,0xa145,0xa143, KEY_DELETE
};
#endif
/*
* 第一类 声母 21个 ㄅ..ㄙ
* 第二类 介音 3个 ㄧㄨㄩ
* 第三类 韵母 13个 ㄚ..ㄦ
* 第四类 声符 4个 space, ˇ
* 共42个
*/
static WORD BopomofoCodeMap[43] =
{
/* null */
0x0020,
#ifndef __WIN32__
/* 第一类 声母 */
//01ㄅ 02 ㄆ 03 ㄇ 04 ㄈ 05 ㄉ 06 ㄊ 07 ㄋ 08 ㄌ 09 ㄍ 10 ㄎ 11 ㄏ
0xa374, 0xa375, 0xa376, 0xa377, 0xa378, 0xa379, 0xa37a, 0xa37b, 0xa37c, 0xa37d, 0xa37e,
//12ㄐ 13 ㄑ 14 ㄒ 15 ㄓ 16 ㄔ 17 ㄕ 18 ㄖ 19 ㄗ 20 ㄘ 21 ㄙ
0xa3a1, 0xa3a2, 0xa3a3, 0xa3a4, 0xa3a5, 0xa3a6, 0xa3a7, 0xa3a8, 0xa3a9, 0xa3aa,
/* 第二类 介音 */
//22ㄧ 23 ㄨ 24 ㄩ
0xa3b8, 0xa3b9, 0xa3ba,
/* 第三类 韵母 */
//25ㄚ 26 ㄛ 27 ㄜ 28 ㄝ 29 ㄞ 30 ㄟ 31 ㄠ 32 ㄡ 33 ㄢ 34 ㄣ 35 ㄤ
0xa3ab, 0xa3ac, 0xa3ad, 0xa3ae, 0xa3af, 0xa3b0, 0xa3b1, 0xa3b2, 0xa3b3, 0xa3b4, 0xa3b5,
//36ㄥ 37 ㄦ
0xa3b6, 0xa3b7,
/* 第四类 声母 */
// space,不应该用到 39 40 41 ˇ 42
0xa374, 0xa3bb, 0xa3bd, 0xa3be, 0xa3bf
#else
0x74a3, 0x75a3, 0x76a3, 0x77a3, 0x78a3, 0x79a3, 0x7aa3, 0x7ba3, 0x7ca3, 0x7da3, 0x7ea3,
0xa1a3, 0xa2a3, 0xa3a3, 0xa4a3, 0xa5a3, 0xa6a3, 0xa7a3, 0xa8a3, 0xa9a3, 0xaaa3,
0xb8a3, 0xb9a3, 0xbaa3,
0xaba3, 0xaca3, 0xada3, 0xaea3, 0xafa3, 0xb0a3, 0xb1a3, 0xb2a3, 0xb3a3, 0xb4a3, 0xb5a3,
0xb6a3, 0xb7a3,
0x74a3, 0xbba3, 0xbda3, 0xbea3, 0xbfa3
#endif
};
//static char ImeBpmfStrAddress[] = "县市乡镇路街段巷弄号楼";
//static char ImeBpmfStrSymbol[] = "!:;、。,·? 〃‘’“”『』※《》";
/***********************************************************************
* FUNCTION: ImeLookupBPMF
* DESCRIPTION: Bopomofo IME's lookup function, responsible for converting
* the composition string into candidate characters.
* PARAMETERS: key - the newly pressed key
* pCmp - pointer to composition
* pCdd - pointer to candidate
*
* RETURNED: TRUE, if keyboard need repaint
* FALSE, if keyboard need not repaint
***********************************************************************/
#if 0
BOOL ImeLookupBPMF(char key, IMM_COMPOSITION* pCmp, IMM_CANDIDATE* pCdd)
{
char ch[3];
char iGrp;
ch[2] = 0;
// 0. if key index is invalid, do nothing
if (key == -1)
return FALSE;
// 1. bpmf key
if (BpmfKeyIsBpmfCode(key))
{
iGrp = BpmfGetCodeGroup(BopomofoKey[key]);
if ( iGrp == 4 )
{
// if the key is space, then convert the character directly
if (key == BOPOMOFO_KEY_INDEX_SPACE)
{
if (pCmp->count == 0)
ImmAddCddByPCH(" ");
} else {
BpmfPushBPMFKeyToCmp(key, iGrp, pCmp);
}
BpmfConvertBPMFCode(pCmp, pCdd);
} else {
BpmfPushBPMFKeyToCmp(key, iGrp, pCmp);
}
}
// 2. "back space"
else if (key == BOPOMOFO_KEY_INDEX_BACKSPACE)
{
BpmfRemoveBPMFCode(pCmp, pCdd);
}
// 3. "address" & "symbol"
else if (key == BOPOMOFO_KEY_INDEX_ADDRESS || key == BOPOMOFO_KEY_INDEX_SYMBOL)
{
BpmfKeyAddrSymbol(key);
}
// 4. else add the key into cmp window
else
{
ImmAddCddByWord(BopomofoKey[key]);
}
return FALSE;
}
#endif
/***********************************************************************
* FUNCTION: BpmfConvertBPMFCode
* DESCRIPTION: convert the bopomofo codes in composition into chinese characters
* and put them in candidate
* PARAMETERS: pCmp - pointer to composition
* pCdd - pointer to candidate
* RETURNED: nothing
***********************************************************************/
//static void BpmfConvertBPMFCode(IMM_COMPOSITION* pCmp, IMM_CANDIDATE* pCdd)
int guiIme_zy(char *zyStr, unsigned short *pBig5Code)
{
CC cc;
WORD i = 0;
DWORD ValueA = 0;
BYTE ValueB = 0;
BYTE Start[2], End[2], Big5Code[2];
WORD StartAddr = 0, EndAddr = 0;
//BOOL bMatch = FALSE;
int foundCnt=0;
// get the index value A, B
if (zyStr[0] != 0)
ValueA += (zyStr[0]-BOPOMOFO_GRP_1+1)*5;
if (zyStr[3] != 0)
ValueA += zyStr[3]-BOPOMOFO_GRP_4; // 第四类由 0开始
ValueA *= 2;
if (zyStr[1] != 0)
ValueB += (zyStr[1]-BOPOMOFO_GRP_2+1)*16;
if (zyStr[2] != 0)
ValueB += zyStr[2]-BOPOMOFO_GRP_3+1;
// get the range to scan
Start[0] = BopomofoTable[ValueA++]; // low BYTE
Start[1] = BopomofoTable[ValueA++]; // high BYTE
End[0] = BopomofoTable[ValueA++]; // low BYTE
End[1] = BopomofoTable[ValueA]; // high BYTE
cc.b.l = Start[0];
cc.b.h = Start[1];
StartAddr = cc.w;
cc.b.l = End[0];
cc.b.h = End[1];
EndAddr = cc.w;
// scan for matching characters
for(i = StartAddr; i < EndAddr; i++)
{
if(ValueB == BopomofoTable[i])
{
Big5Code[0] = BopomofoTable[++i]; // high BYTE
Big5Code[1] = BopomofoTable[++i]; // low BYTE
while(Big5Code[0] > 128)
{
// add the character to candidate
//bMatch = TRUE;
//ImmAddCddByPCH((char*)&Big5Code[0]);
pBig5Code[foundCnt] = *(unsigned short*)Big5Code;
foundCnt++;
Big5Code[0] = BopomofoTable[++i];
Big5Code[1] = BopomofoTable[++i];
}
break;
}
}
pBig5Code[foundCnt] = 0x0000;
return foundCnt;
}
void ConvertNumToCode_ZY(char *numStr, unsigned short *codeStr)
{
int i, len, number;
/*
len = strlen(numStr);
for(i=0; i<len; i++)
{
number = numStr[i];
codeStr[i] = BopomofoCodeMap[number] ;
}
*/
len = 4;
for(i=0; i<len; i++)
{
number = numStr[i];
if(!number)
codeStr[i] = 0x2020;
else
codeStr[i] = BopomofoCodeMap[number] ;
}
codeStr[i] = 0;
}
/***********************************************************************
* DESCRIPTION: if specify key is the key that represent a BPMF code
* PARAMETERS: key - specify the key
* RETURNED: TRUE, if given key is a BPMF code key
* FALSE, if not
***********************************************************************/
BOOL BpmfKeyIsBpmfCode(char key)
{
/* Kevin update, 2003/11/4 */
if ((key < 0) || (key > 42))
return FALSE;
return TRUE;
}
/***********************************************************************
* FUNCTION: BpmfGetCodeGroup
* DESCRIPTION: return the group that the code belongs
* PARAMETERS: key - the key that user pressed, bopomofo code (should be ranged 0~41)
* RETURNED: the group that the code belongs
***********************************************************************/
int BpmfGetCodeGroup(char code)
{
if (code < 00 || code >= BOPOMOFO_KEY_NUMBER)
return -1;
// group 1: 00 ~ 20
if (code < BOPOMOFO_GRP_2)
return 1;
// group 2: 21~23
if (code < BOPOMOFO_GRP_3)
return 2;
// group 3: 24 ~ 36
if (code < BOPOMOFO_GRP_4)
return 3;
// group 4: 37~41
return 4;
}
int guiGetCandidate_zy(unsigned short totalCount, unsigned short toReadCount,unsigned short startPos, unsigned short *pWordText, unsigned short *pSrcWord)
{
unsigned short *pWord;
int readCount, i;
if(startPos>totalCount)
return 0;
readCount = (totalCount>startPos+toReadCount)?toReadCount:(totalCount-startPos);
for(i=0; i<readCount; i++)
pWordText[i] = pSrcWord[startPos+i];
pWordText[readCount] = 0x0000;
return readCount;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -