⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 imecomm.c

📁 好记星的控件,包括button,list,对文件操作
💻 C
📖 第 1 页 / 共 2 页
字号:
/* OUTPUTS:    Ture/False												 */
/*************************************************************************/
/*  NAME           DATE               REMARKS                            */
/* ==========  ============   ===========================================*/
/*  zfs			2003-04-8     创建初始版本                               */
/*************************************************************************/
FOR_IME_WUBI
BOOL _ImWbGetWord(void)
{
    BOOL wBgetData;
    
    wBgetData = FALSE;
    switch (g_pIMEInputednum) {
    case 1:
    case 2:
        wBgetData = _ImWbOneTwoCode();
        break;
    case 3:
        wBgetData = _ImWbThreeCode();
        break;
    case 4:
        wBgetData = _ImWbFourCode();
        break;
    default:
        break;
    }
    
    if (wBgetData)
    {
        g_pIMECandiPos = 0;
    }
    
    g_pIMEWordTypeNum = HZ_PER_PAGE;
    
    return wBgetData;
}
FOR_IME_PINYIN
VOID _ImPyGetIndex(UINT index)
{
    UINT8 *pPinYin;
    
	if(ImeGetSystem()->uImeCurrentType == IME_PINYIN){
		pPinYin = (UINT8*)(GBKPY_ADDRESS + index * (IMPY_INDEX_LEN + 1));
	}
	else{
		pPinYin = (UINT8*)(JAPAN_INPUT_ADDRESS + index * (IMPY_INDEX_LEN + 1));
	}
    memmove(g_pIMEPyIndexBuffer, pPinYin, IMPY_INDEX_LEN + 1);
}

FOR_IME_PINYIN
INT _ImCmpPyIndex(UINT index)
{
    UINT8   pInput[IM_INBUFF_LEN], pIndex[IM_INBUFF_LEN];
    UINT32  len;
    UINT8   *pTail;
    INT     ret;
    
    _ImPyGetIndex(index);
    memset(pInput, 0, IM_INBUFF_LEN);
    memset(pIndex, 0, IM_INBUFF_LEN);
    strcpy(pInput, g_pIMEInBuffer);
    strcpy(pIndex, g_pIMEPyIndexBuffer);
    len = strlen(pInput);
    pTail = pInput + len - 1;
    if (MyIsAlpha(*pTail))
    {
        ret = memcmp(pInput, pIndex, IMPY_INPUT_LEN);
        if (ret == 0)
        {
            return ret;
        }
	if(len != 1)		//MANN: 对于单字母输入应该精确匹配
	        *(pInput + len) = '0';
    }
    return memcmp(pInput, pIndex, IMPY_INPUT_LEN);
}

FOR_IME_PINYIN
BOOL __ImPyGetWord(VOID)
{
    return __ImGBKGetWord();
}

BOOL __ImGBKGetWord(VOID)
{
    UINT32 imPyWordStart, imPyWordEnd;
    INT nResult;
    
	if(ImeGetSystem()->uImeCurrentType == IME_PINYIN){
		nResult = _ImDichSearch(0, GBKPY_INDEX_NUM, (VOID*)_ImCmpPyIndex);
	}
	else{
		nResult = _ImDichSearch(0, JAPAN_INDEX_NUM, (VOID*)_ImCmpPyIndex);
	}

    if(nResult == -1)
    {
        return FALSE;
    }
    else
    {
        imPyWordStart = 0;
        imPyWordEnd = 0;
        memmove((UINT8 *)&imPyWordStart,
            g_pIMEPyIndexBuffer + IMPY_INPUT_LEN, 3);
        
        _ImPyGetIndex(++nResult);
        memmove((UINT8 *)&imPyWordEnd,
            g_pIMEPyIndexBuffer + IMPY_INPUT_LEN, 3);
        g_pIMEWordNum = (UINT16)((imPyWordEnd - imPyWordStart) / 2);
		if(ImeGetSystem()->uImeCurrentType == IME_PINYIN){
			g_pIMEDataAddr = (UINT8 *)GBKPY_ADDRESS + imPyWordStart;
		}
		else{
			g_pIMEDataAddr = (UINT8 *)JAPAN_INPUT_ADDRESS + imPyWordStart;
		}
        g_pIMECandiPos = 0;
        
        g_pIMEWordTypeNum = PY_PER_PAGE;
        return TRUE;
    }
    
}

/**********************************************************/
/*           匹配两个字符的五笔数据                       */
/**********************************************************/
FOR_IME_WUBI
BOOL _ImWbOneTwoCode(void)
{
    UINT32 dataOffset, dataAddr;
    
    if (g_pIMEInputednum == 1){
        dataOffset = IMWB_FIRSTLEVEL_OFF;
        dataOffset += (((UINT32)*g_pIMEInBuffer - 'a') * 2);
    }
    else
    {
        dataOffset = (((UINT32)*g_pIMEInBuffer - 'a') * 25 + ((UINT32)*(g_pIMEInBuffer+1) - 'a')) * 2;
        dataOffset += IMWB_SECONDLEVEL_OFF;
    }
    
    dataAddr = (UINT32)IMWB_DATA_ADDR + dataOffset;
    memset(g_pIMEOutWordBuf,0,3);
    memcpy(g_pIMEOutWordBuf,(UINT8 *)dataAddr,2);
    g_pIMEWordNum = 0;
    if(*g_pIMEOutWordBuf != 0x20 && *(g_pIMEOutWordBuf + 1) != 0x20)
    {
        g_pIMEDataAddr = g_pIMEOutWordBuf;
        g_pIMEWordNum = 1;
        return TRUE;
    }
    
    return	FALSE;
}

/**********************************************************/
/*           匹配三个字符的五笔数据                       */
/**********************************************************/
FOR_IME_WUBI
BOOL _ImWbThreeCode(void)
{
	UINT32 dataOffset, dataAddr, tmpAddr, dataAddr1;
	UINT16 wHigh, wLow;
	UINT16 dResult;
	UINT8  dOrder, tmpStr[2], indexStr[4];

	memset(g_pIMEWordBuffer,0,IM_WORD_MAX*2);
	dataOffset = (((UINT32)*g_pIMEInBuffer-'a')*25 + ((UINT32)*(g_pIMEInBuffer+1)-'a'))*2;
	dataOffset += (IMWB_SECONDINDEX_OFF - 2);
	dataAddr = (UINT32)IMWB_DATA_ADDR + dataOffset;
	memcpy(indexStr,(UINT8 *)dataAddr,4);
	dataOffset = (((UINT32)*g_pIMEInBuffer-'a') * 25 + ((UINT32)*(g_pIMEInBuffer+1)-'a')) * 2;

	if(dataOffset != 0)
	{
		dataOffset =* (indexStr + 1);
		dataOffset <<= 8;
		dataOffset += *indexStr;
	}
	else
	{
		dataOffset = IMWB_SECONDSAME_OFF;
	}

	g_pIMEWordIndexNum =* (indexStr + 3);
	g_pIMEWordIndexNum <<= 8;
	g_pIMEWordIndexNum += *(indexStr + 2);
	g_pIMEWordIndexNum -= (UINT16)dataOffset;
	dataAddr = (UINT32)IMWB_DATA_ADDR + dataOffset;
	g_pIMECurIndex = 0;
	g_pIMEWordNum = 0;
	while(g_pIMECurIndex < g_pIMEWordIndexNum)
	{
		tmpAddr = dataAddr + g_pIMECurIndex;
		memcpy(tmpStr,(UINT8 *)tmpAddr,2);
		wHigh = tmpStr[0] * 256;
		wLow = tmpStr[1];
		g_pIMEWbOrderNum = _ImGetCodeNum((UINT16)(wHigh + wLow));
		dResult = _ImGetOrderValue(IMWB_THIRDORDER_OFF);

		if(dResult == *(g_pIMEInBuffer + 2))
		{
			dataOffset = g_pIMEWbOrderNum / 8;
			dResult = g_pIMEWbOrderNum % 8;
			dataOffset += IMWB_THIRDLEVEL_OFF;
			dataAddr1 = (UINT32)IMWB_DATA_ADDR + dataOffset;
			memcpy(&dOrder,(UINT8 *)dataAddr1,1);

			if(dResult != 0)	//这句多余
			{
				for(; dResult != 0; dResult--)
				{
					dOrder *= 2;
				}
			}

			if(dOrder & 0x80)
			{
				*(g_pIMEWordBuffer + g_pIMEWordNum * 2) = tmpStr[0];
				*(g_pIMEWordBuffer + g_pIMEWordNum * 2 + 1) = tmpStr[1];
				g_pIMEWordNum++;
				g_pIMECurIndex += 2;	// while中的所有分支都有这一句,多余
			}
			else
			{
				g_pIMECurIndex += 2;
			}
		}
		else
		{
			g_pIMECurIndex += 2;
		}
	}
	if(g_pIMEWordNum == 0)
	{
		return FALSE;
	}
	else
	{
		g_pIMEDataAddr = g_pIMEWordBuffer;
		return TRUE;
	}
}

/**********************************************************/
/*           匹配四个字符的五笔数据                       */
/**********************************************************/
FOR_IME_WUBI
BOOL _ImWbFourCode(void)
{
	UINT32 dataOffset, dataAddr, tmpAddr;
	UINT16 wHigh, wLow;
	UINT16 dResult;
	UINT8  tmpStr[2], indexStr[4];

	memset(g_pIMEWordBuffer,0,IM_WORD_MAX * 2);
	dataOffset = (((UINT32)*g_pIMEInBuffer-'a') * 25 + ((UINT32)*(g_pIMEInBuffer+1)-'a')) * 2;
	dataOffset += (IMWB_SECONDINDEX_OFF - 2);
	dataAddr = (UINT32)IMWB_DATA_ADDR + dataOffset;
	memcpy(indexStr,(UINT8 *)dataAddr,4);
	dataOffset = (((UINT32)*g_pIMEInBuffer-'a') * 25 + ((UINT32)*(g_pIMEInBuffer+1)-'a')) * 2;

	if(dataOffset != 0)
	{
		dataOffset =* (indexStr + 1);
		dataOffset <<= 8;
		dataOffset += *indexStr;
	}
	else
	{
		dataOffset = IMWB_SECONDSAME_OFF;
	}

	g_pIMEWordIndexNum =* (indexStr + 3);
	g_pIMEWordIndexNum <<= 8;
	g_pIMEWordIndexNum += *(indexStr + 2);
	g_pIMEWordIndexNum -= (UINT16)dataOffset;

	dataAddr = (UINT32)IMWB_DATA_ADDR + dataOffset;
	g_pIMEWordNum = 0;
	g_pIMECurIndex = 0;
	while(g_pIMECurIndex < g_pIMEWordIndexNum)
	{
		tmpAddr = dataAddr + g_pIMECurIndex;
		memcpy(tmpStr,(UINT8 *)tmpAddr,2);
		wHigh = tmpStr[0] * 256;
		wLow = tmpStr[1];
		g_pIMEWbOrderNum = _ImGetCodeNum((UINT16)(wHigh + wLow));
		dResult = _ImGetOrderValue(IMWB_THIRDORDER_OFF);

		if(dResult == *(g_pIMEInBuffer+2))
		{
			dResult = _ImGetOrderValue(IMWB_FOURTHORDER_OFF);
			if(dResult == *(g_pIMEInBuffer + 3))
			{
				*(g_pIMEWordBuffer + g_pIMEWordNum * 2) = tmpStr[0];
				*(g_pIMEWordBuffer + g_pIMEWordNum * 2 + 1) = tmpStr[1];
				g_pIMEWordNum++;
				g_pIMECurIndex += 2;
			}
			else
			{
				g_pIMECurIndex += 2;
			}
		}
		else
		{
			g_pIMECurIndex += 2;
		}
	}
	if(g_pIMEWordNum == 0)
	{
		return FALSE;
	}
	else
	{
		g_pIMEDataAddr = g_pIMEWordBuffer;
		return TRUE;
	}
}

FOR_IME_WUBI
UINT16 _ImGetCodeNum(UINT16 xCode)
{
    return ((xCode >> 8) - 0xB0) * 94 + ((UINT8)xCode - 0xA1);
}

FOR_IME_WUBI
UINT8 _ImGetOrderValue(UINT16 xOff)
{
    UINT32 offset,res,addr;
    UINT8 order[2];
    UINT16 imOrderValue;
    
    offset = g_pIMEWbOrderNum * 5;
    res = 8 - offset % 8;
    offset /= 8;
    offset += xOff;
    addr = (UINT32)IMWB_DATA_ADDR + offset;
    memcpy((UINT8 *)&imOrderValue + 1,(UINT8 *)addr,1);
    memcpy((UINT8 *)&imOrderValue,(UINT8 *)(addr+1),1);
    order[0] = (UINT8)imOrderValue;
    order[1] = (UINT8)(imOrderValue >> 8);
    
    if(res >= 5)
    {
        res -= 5;
        while(res != 0)
        {
            order[1] /= 2;
            res--;
        }
    }
    else
    {
        res = 5 - res;
        while(res != 0)
        {
            imOrderValue *= 2;
            order[0] = (UINT8)imOrderValue;
            order[1] = (UINT8)(imOrderValue>>8);
            res--;
        }
    }
    
    res = order[1];
    res &= 0x01F;
    res += ('a' - 1);
    
    return (UINT8)res;
}

/*************************************************************************/
/*                             画输入法的左右图标                        */
/*************************************************************************/
FOR_IME_ALL
void _imDrawArrow(void)
{	
	UINT32 dwArrowId;
	UINT  uWidth,uHeight;

	if (g_pIMEWordNum > HZ_PER_PAGE){
		if (g_pIMECandiPos == 0)
		{
			dwArrowId = IDB_IME_ARROWR;
		}
		else if(g_pIMECandiPos + HZ_PER_PAGE>= g_pIMEWordNum)
		{
			dwArrowId =  IDB_IME_ARROWL;
		}
		else
		{
			dwArrowId =  IDB_IME_ARROWLR;
		}
		GraphGetIconSize(&uWidth,&uHeight,MAKE_ID(dwArrowId ) ) ;		
		GraphDrawIcon(g_mInputBox.rect.x+g_mInputBox.rect.width - uWidth-2,
			g_mInputBox.rect.y+(g_mInputBox.rect.height - 12) / 2,0, 0, MAKE_ID(dwArrowId));
	}
}
/****************************************************************************/
/* FUNCTION:   __ImeDrawInputBoxHead										*/
/* DESCRIPTION:输入法的输入框的绘制										*/
/* INPUTS:     uType      输入法				                            */
/* OUTPUTS:    NONE														*/
/* RETURN:     NONE														*/
/****************************************************************************/
/*  NAME           DATE               REMARKS                               */
/* ==========  ============   ==============================================*/
/*  Qorse		2003-03-25     创建初始版本                                 */
/****************************************************************************/
VOID ImeDrawSplit()
{
	UINT16	wPenStyle;
	wPenStyle = GraphGetPenStyle( );
	GraphSetPenStyle( PS_DOT);
	
	GraphDrawLine(g_mInputBox.rect.x, g_mInputBox.rect.y-1,
		g_mInputBox.rect.x+g_mInputBox.rect.width - 1,g_mInputBox.rect.y-1);
	GraphSetPenStyle(wPenStyle);
}

VOID __ImeDrawInputBoxHead(UINT uType)
{
	
	
	GraphDisableRefresh();
	
	GraphClearRect(g_mInputBox.rect.x, g_mInputBox.rect.y,
		g_mInputBox.rect.x+g_mInputBox.rect.width - 1,g_mInputBox.rect.y+g_mInputBox.rect.height - 1);
	
	ImeDrawSplit();
	if(uType == IME_ENGLISH ||( g_mInputBox.state != IM_INPUT_LX && g_mInputBox.state != IM_INPUT_LXZC))
	{
		GraphDrawText(g_mInputBox.rect.x, g_mInputBox.rect.y, 0, 0, (UINT8*)ime_InputBoxHead[uType - 1]);
	}
	else
	{
		GraphDrawText(g_mInputBox.rect.x, g_mInputBox.rect.y, 0, 0, "联");
	}
	
	GraphInvertRect(g_mInputBox.rect.x,g_mInputBox.rect.y,
		g_mInputBox.rect.x+g_mInputBox.rect.height-1,g_mInputBox.rect.y+g_mInputBox.rect.height-1);
	GraphEnableRefresh();
}
VOID ImeDrawIndexNum(UINT8 index,UINT uType)
{
	UINT uIconID;
	INT x;
	
	switch(index)
	{
	case 0:
		uIconID = IDB_IME_NUM1;
		break;
	case 1:
		uIconID = IDB_IME_NUM2;
		break;
	case 2:
		uIconID = IDB_IME_NUM3;
		break;
	case 3:
		uIconID = IDB_IME_NUM4;
		break;
	case 4:
		uIconID = IDB_IME_NUM5;
		break;
	case 5:
		uIconID = IDB_IME_NUM6;
		break;
	case 6:
		uIconID = IDB_IME_NUM7;
		break;
	case 7:
		uIconID = IDB_IME_NUM8;
		break;
	case 8:
		uIconID = IDB_IME_NUM9;
		break;
	case 9:
		uIconID = IDB_IME_NUM0;
		break;
	default:
		return;
		break;
	}
	switch (uType)
	{
	case IME_PINYIN:
	case IME_WUBI:
		x = PY_CANDI_X + index*IME_CANDI_INTERVAL - 7;
		break;
	default:
		x = IME_CANDI_X + index*IME_CANDI_INTERVAL - 7;
		break;
	}
	GraphDrawIcon( g_mInputBox.rect.x+x, g_mInputBox.rect.y, 0, 0, MAKE_ID(uIconID));
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -