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

📄 w32sys.cpp

📁 Windows CE 6.0 Word Application 源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/*
 *	GetLocaleLCID ()
 *
 *	@mfunc		Maps an LCID for thread to a Code Page
 *
 *	@rdesc		returns Code Page
 */
LCID CW32System::GetLocaleLCID()
{
	return GetThreadLocale();
}


/*
 *	GetLocaleCodePage ()
 *
 *	@mfunc		Maps an LCID for thread to a Code Page
 *
 *	@rdesc		returns Code Page
 */
UINT CW32System::GetLocaleCodePage()
{
	return W32->ConvertLanguageIDtoCodePage(GetThreadLocale());
}

/*
 *	GetKeyboardLCID ()
 *
 *	@mfunc		Gets LCID for keyboard active on current thread
 *
 *	@rdesc		returns Code Page
 */
LCID CW32System::GetKeyboardLCID()
{
	return (WORD)GetKeyboardLayout(0 /*idThread*/);
}

/*
 *	GetKeyboardCodePage ()
 *
 *	@mfunc		Gets Code Page for keyboard active on current thread
 *
 *	@rdesc		returns Code Page
 */
UINT CW32System::GetKeyboardCodePage()
{
	return W32->ConvertLanguageIDtoCodePage((WORD)GetKeyboardLayout(0 /*idThread*/));
}

/*
 *  IsFELCID(lcid)
 *
 *	@mfunc
 *		Returns TRUE iff lcid is for a FE country.
 *
 *	@rdesc
 *		TRUE iff lcid is for a FE country.
 *
 */
BOOL CW32System::IsFELCID(LCID lcid)
{
	switch(PRIMARYLANGID(LANGIDFROMLCID(lcid)))
	{
		case LANG_CHINESE:
		case LANG_JAPANESE:
		case LANG_KOREAN:
			return TRUE;
	}

	return FALSE;
}

/*
 *  IsFECharset(bCHarSet)
 *
 *	@mfunc
 *		Returns TRUE iff charset may be for a FE country.
 *
 *	@rdesc
 *		TRUE iff charset may be for a FE country.
 *
 */
BOOL CW32System::IsFECharset(BYTE bCharSet)
{
	switch(bCharSet)
	{
		case CHINESEBIG5_CHARSET:
		case SHIFTJIS_CHARSET:
		case HANGEUL_CHARSET:
		case JOHAB_CHARSET:
		case GB2312_CHARSET:
			return TRUE;
	}

	return FALSE;
}

/*
 *  IsFEChar(ch)
 *
 *	GUYBARK: ADDED THIS!
 *
 *      Return TRUE, if this input Unicode character lies in a FE range.
 *
 */
BOOL CW32System::IsFEChar(WCHAR ch)
{
    LONG iCharSetIndex;

    iCharSetIndex = CharSetIndexFromChar(ch);

    if(iCharSetIndex == HAN_INDEX ||
       iCharSetIndex == SHIFTJIS_INDEX ||
       iCharSetIndex == HANGUL_INDEX )
    {
        return TRUE;
    }

    return FALSE;
}

typedef struct {
	WCHAR codepoint;
	UCHAR charsets;
	UCHAR runlength;
} Data_125X;

/*
 *  In125x(ch, bCharSet)
 *
 *	@mfunc
 *		Returns non zero iff char is in given 125x charset.
 *      If the charset is any charset other than one corresponding
 *      to a 125x codepage, the return value
 *		is a bit mask identifying a subset of the eight 125x code
 *      pages (bit 1 = 1250, bit 2 = 1251, ... bit 8 = 1257) to which
 *		the input char belongs.
 *
 *	@rdesc
 *		TRUE iff char is in input 125x charset.
 *
 */
INT CW32System::In125x( TCHAR ch, BYTE bCharSet )
{
	static const Data_125X Table_125X[] = {
		{   0x80, 0xfd,   1},
		{   0x81, 0xbd,   1},
		{   0x83, 0x81,   1},
		{   0x88, 0x8b,   1},
		{   0x8a, 0xe8,   1},
		{   0x8c, 0xa8,   1},
		{   0x8d, 0x3c,   2},
		{   0x8f, 0x7c,   1},
		{   0x90, 0xbd,   1},
		{   0x98, 0xcb,   1},
		{   0x9a, 0xe8,   1},
		{   0x9c, 0xa8,   1},
		{   0x9d, 0x3c,   2},
		{   0x9f, 0xe8,   1},
		{   0xa0, 0xff,   1},
		{   0xa1, 0x34,   1},
		{   0xa2, 0xf4,   1},
		{   0xa3, 0xfc,   1},
		{   0xa4, 0xff,   1},
		{   0xa5, 0x7c,   1},
		{   0xa6, 0xff,   2},
		{   0xa8, 0xfd,   1},
		{   0xa9, 0xff,   1},
		{   0xaa, 0x14,   1},
		{   0xab, 0xff,   4},
		{   0xaf, 0xf4,   1},
		{   0xb0, 0xff,   2},
		{   0xb2, 0xfc,   2},
		{   0xb4, 0xf5,   1},
		{   0xb5, 0xff,   3},
		{   0xb8, 0xf5,   1},
		{   0xb9, 0xf4,   1},
		{   0xba, 0x14,   1},
		{   0xbb, 0xff,   1},
		{   0xbc, 0xf4,   1},
		{   0xbd, 0xfc,   1},
		{   0xbe, 0xf4,   1},
		{   0xbf, 0x34,   1},
		{   0xc0, 0x14,   1},
		{   0xc1, 0x15,   2},
		{   0xc3, 0x14,   1},
		{   0xc4, 0x95,   1},
		{   0xc5, 0x94,   2},
		{   0xc7, 0x15,   1},
		{   0xc8, 0x14,   1},
		{   0xc9, 0x95,   1},
		{   0xca, 0x14,   1},
		{   0xcb, 0x15,   1},
		{   0xcc, 0x14,   1},
		{   0xcd, 0x15,   2},
		{   0xcf, 0x14,   1},
		{   0xd0,  0x4,   1},
		{   0xd1, 0x14,   2},
		{   0xd3, 0x95,   1},
		{   0xd4, 0x15,   1},
		{   0xd5, 0x94,   1},
		{   0xd6, 0x95,   1},
		{   0xd7, 0xf5,   1},
		{   0xd8, 0x94,   1},
		{   0xd9, 0x14,   1},
		{   0xda, 0x15,   1},
		{   0xdb, 0x14,   1},
		{   0xdc, 0x95,   1},
		{   0xdd,  0x5,   1},
		{   0xde,  0x4,   1},
		{   0xdf, 0x95,   1},
		{   0xe0, 0x54,   1},
		{   0xe1, 0x15,   1},
		{   0xe2, 0x55,   1},
		{   0xe3, 0x14,   1},
		{   0xe4, 0x95,   1},
		{   0xe5, 0x94,   2},
		{   0xe7, 0x55,   1},
		{   0xe8, 0x54,   1},
		{   0xe9, 0xd5,   1},
		{   0xea, 0x54,   1},
		{   0xeb, 0x55,   1},
		{   0xec, 0x14,   1},
		{   0xed, 0x15,   1},
		{   0xee, 0x55,   1},
		{   0xef, 0x54,   1},
		{   0xf0,  0x4,   1},
		{   0xf1, 0x14,   2},
		{   0xf3, 0x95,   1},
		{   0xf4, 0x55,   1},
		{   0xf5, 0x94,   1},
		{   0xf6, 0x95,   1},
		{   0xf7, 0xf5,   1},
		{   0xf8, 0x94,   1},
		{   0xf9, 0x54,   1},
		{   0xfa, 0x15,   1},
		{   0xfb, 0x54,   1},
		{   0xfc, 0xd5,   1},
		{   0xfd,  0x5,   1},
		{   0xfe,  0x4,   1},
		{   0xff, 0x14,   1},
		{  0x100, 0x80,   2},
		{  0x102,  0x1,   2},
		{  0x104, 0x81,   4},
		{  0x10c, 0x81,   2},
		{  0x10e,  0x1,   4},
		{  0x112, 0x80,   2},
		{  0x116, 0x80,   2},
		{  0x118, 0x81,   2},
		{  0x11a,  0x1,   2},
		{  0x11e, 0x10,   2},
		{  0x122, 0x80,   2},
		{  0x12a, 0x80,   2},
		{  0x12e, 0x80,   2},
		{  0x130, 0x10,   2},
		{  0x136, 0x80,   2},
		{  0x139,  0x1,   2},
		{  0x13b, 0x80,   2},
		{  0x13d,  0x1,   2},
		{  0x141, 0x81,   4},
		{  0x145, 0x80,   2},
		{  0x147,  0x1,   2},
		{  0x14c, 0x80,   2},
		{  0x150,  0x1,   2},
		{  0x152, 0x54,   2},
		{  0x154,  0x1,   2},
		{  0x156, 0x80,   2},
		{  0x158,  0x1,   2},
		{  0x15a, 0x81,   2},
		{  0x15e, 0x11,   2},
		{  0x160, 0x95,   2},
		{  0x162,  0x1,   4},
		{  0x16a, 0x80,   2},
		{  0x16e,  0x1,   4},
		{  0x172, 0x80,   2},
		{  0x178, 0x14,   1},
		{  0x179, 0x81,   6},
		{  0x192, 0x7c,   1},
		{  0x2c6, 0x74,   1},
		{  0x2c7, 0x81,   1},
		{  0x2d8,  0x1,   1},
		{  0x2d9, 0x81,   1},
		{  0x2db, 0x81,   1},
		{  0x2dc, 0x34,   1},
		{  0x2dd,  0x1,   1},
		{  0x384,  0x8,   3},
		{  0x388,  0x8,   3},
		{  0x38c,  0x8,   1},
		{  0x38e,  0x8,  20},
		{  0x3a3,  0x8,  44},
		{  0x401,  0x2,  12},
		{  0x40e,  0x2,  66},
		{  0x451,  0x2,  12},
		{  0x45e,  0x2,   2},
		{  0x490,  0x2,   2},
		{  0x5b0, 0x20,  20},
		{  0x5d0, 0x20,  27},
		{  0x60c, 0x40,   1},
		{  0x61b, 0x40,   1},
		{  0x61f, 0x40,   1},
		{  0x621, 0x40,  26},
		{  0x640, 0x40,  19},
		{  0x67e, 0x40,   1},
		{  0x686, 0x40,   1},
		{  0x698, 0x40,   1},
		{  0x6af, 0x40,   1},
		{ 0x200c, 0x40,   2},
		{ 0x200e, 0x60,   2},
		{ 0x2013, 0xff,   2},
		{ 0x2015,  0x8,   1},
		{ 0x2018, 0xff,   3},
		{ 0x201c, 0xff,   3},
		{ 0x2020, 0xff,   3},
		{ 0x2026, 0xff,   1},
		{ 0x2030, 0xff,   1},
		{ 0x2039, 0xff,   2},
		{ 0x2116,  0x2,   1},
		{ 0x2122, 0xff,   1}
	};

	// Easy check for ASCII
	if (ch <= 0x7f)
	{
		return 0xff;
	}

	// Easy check for missing codes
	if (ch > 0x2122)
	{
		return 0;
	}

	// Perform binary search to find entry in table
	int low = 0;
	int high = sizeof( Table_125X ) / sizeof( Data_125X ) - 1;
	int middle;
	int midval;
	int runlength;
	int result = 0;

	while (low <= high)
	{
		middle = (high + low) / 2;
		midval = Table_125X[middle].codepoint;
		if (midval > ch)
		{
			high = middle - 1;
		}
		else
		{
			low = middle + 1;
		}
		runlength = Table_125X[middle].runlength;
		if (ch >= midval && ch <= midval + runlength - 1)
		{
			result = Table_125X[middle].charsets;
			break;
		}
	}

	switch (bCharSet)
	{
	case EASTEUROPE_CHARSET :
		// Code Page 1250
		result &= 0x1;
		break;
	case RUSSIAN_CHARSET :
		// Code Page 1251
		result &= 0x2;
		break;
	case ANSI_CHARSET :
		// Code Page 1252
		result &= 0x4;
		break;
	case GREEK_CHARSET :
		// Code Page 1253
		result &= 0x8;
		break;
	case TURKISH_CHARSET :
		// Code Page 1254
		result &= 0x10;
		break;
	case HEBREW_CHARSET :
		// Code Page 1255
		result &= 0x20;
		break;
	case ARABIC_CHARSET :
		// Code Page 1255
		result &= 0x40;
		break;
	case BALTIC_CHARSET :
		// Code Page 1255
		result &= 0x80;
		break;
	default :
		break;
	}

	return result;
}

/*
 *	IsLeadByte(ach, cpg)
 *
 *	@mfunc
 *		Returns TRUE iff the byte ach is a lead byte for the code page cpg.
 *
 *	@rdesc
 *		TRUE if ach is lead byte for cpg
 *
 *	@comm
 *		This function potentially doesn't support as many code pages as the
 *		Win32 IsDBCSLeadByte() function (and it might not be as up-to-date).
 *		An AssertSz() is included to compare the results when the code page
 *		is supported by the system.
 *
 *		Reference: \\sparrow\sysnls\cptable\win95. See code-page txt files
 *		in subdirectories windows\txt and others\txt.
 */
BOOL CW32System::IsLeadByte(BYTE ach, UINT cpg)
{
	if(ach < 0x81 || cpg == CP_UTF8)				// Smallest known lead
		return FALSE;								//  byte = 0x81:
													//  early out
	BOOL fRet = FALSE;								// Variable to check
													//  result with system
	if (cpg > 950)									//  ifdef DEBUG
	{
		if (cpg < 1361)								// E.g., the 125x's are
			return FALSE;							//  SBCSs: early out

		else if (cpg == 1361)						// Korean Johab
			fRet = IN_RANGE(0x84, ach, 0xd3) ||		// 0x84 <= ach <= 0xd3
				   IN_RANGE(0xd8, ach, 0xde) ||		// 0xd8 <= ach <= 0xde
				   IN_RANGE(0xe0, ach, 0xf9);		// 0xe0 <= ach <= 0xf9

		else if (cpg == 10001)						// Mac Japanese
			goto JIS;

		else if (cpg == 10002)						// Mac Trad Chinese (Big5)
			fRet = ach <= 0xfe;

		else if (cpg == 10003)						// Mac Korean
			fRet = IN_RANGE(0xa1, ach, 0xac) ||		// 0xa1 <= ach <= 0xac
				   IN_RANGE(0xb0, ach, 0xc8) ||		// 0xb0 <= ach <= 0xc8
				   IN_RANGE(0xca, ach, 0xfd);		// 0xca <= ach <= 0xfd

		else if (cpg == 10008)						// Mac Simplified Chinese
			fRet = IN_RANGE(0xa1, ach, 0xa9) ||		// 0xa1 <= ach <= 0xa9
				   IN_RANGE(0xb0, ach, 0xf7);		// 0xb0 <= ach <= 0xf7
	}
	else if (cpg >= 932)							// cpg <= 950
	{
		if (cpg == 950 || cpg == 949 || cpg == 936)	// Chinese (Taiwan, HK),
		{											//  Korean Ext Wansung,
			fRet = ach <= 0xfe;						//  PRC GBK: 0x81 - 0xfe
		}											  
		else if (cpg == 932)						// Japanese
JIS:		fRet = ach <= 0x9f || IN_RANGE(0xe0, ach, 0xfc);
	}

	#ifdef DEBUG
	TCHAR	ch;
	static	BYTE asz[2] = {0xe0, 0xe0};				// All code pages above

	// if cpg == 0, fRet will FALSE but IsDBCSLeadByteEx may succeed. 
	if ( cpg )
	{
		// If system supports cpg, then fRet should agree with system result
		AssertSz(MultiByteToWideChar(cpg, 0, (char *)asz, 2, &ch, 1) <= 0 ||
			fRet == IsDBCSLeadByteEx(cpg, ach),
			"IsLeadByte() differs from IsDBCSLeadByte()");
	}
	#endif

	return fRet;
}

/*
 *	IsTrailByte(aszBuff, cb, cpg)
 *
 *	@mfunc
 *		Returns TRUE iff the byte aszBuf[cb] is a trail byte for
 *		the code page cpg.
 *
 *	@rdesc
 *		TRUE if aszBuf[cb] is a trail byte for cpg
 *
 *	@comm
 *		The byte is a trail byte if it's preceeded by an odd number of
 *		contiguous lead bytes in aszBuff.
 */
BOOL CW32System::IsTrailByte(
	BYTE *	aszBuff,	//@parm Points to byte buffer
	LONG	cb,			//@parm Count of bytes preceeding possible trail byte
	UINT	cpg)		//@parm Code page to use
{
	LONG i;

	Assert(cb >= 0 && aszBuff);

	for (i = cb; i && IsLeadByte(aszBuff[i - 1], cpg); i--) ;

	return (cb - i) & 1;
}

⌨️ 快捷键说明

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