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

📄 spaceedit.c

📁 PGP8.0源码 请认真阅读您的文件包然后写出其具体功能
💻 C
📖 第 1 页 / 共 2 页
字号:
					SetCaretPos (sep->ptCaret.x+1, sep->ptCaret.y+1);
			}

			return TRUE;
		}
	}

	return FALSE;
}


//	______________________________________
//
//  Passphrase edit box subclass procedure

LRESULT APIENTRY 
SESubclassProc (
		HWND	hWnd, 
		UINT	uMsg, 
		WPARAM	wParam, 
		LPARAM	lParam) 
{
	LRESULT		lResult;
	SEP			sep;

	if (sCommonMsgProc (hWnd, uMsg, wParam, lParam, &lResult))
		return lResult;

	sep=(SEP)GetWindowLong (hWnd, GWL_USERDATA);

	switch (uMsg) 
	{

#if !PGP_SDA	// disable Global IME support in SDAs -- 
				//   thems the breaks for Win95 support for now
		case WM_IME_COMPOSITION :
		{
			if (lParam & GCS_RESULTSTR) 
			{
				HIMC	hIMC = ImmGetContext (hWnd);
				int		i;

				if (hIMC) 
				{
					// ImmGetCompositionStringW returns bytes
					i = ImmGetCompositionStringW (
							hIMC, GCS_RESULTSTR, NULL, 0);
					i = min (i>>1, SE_BUFSIZE-sep->iLen);

					// get the actual string
					ImmGetCompositionStringW (
							hIMC, GCS_RESULTSTR, 
							&(sep->wszRealText[sep->iLen]), i<<1);

					// obfuscate
					while (i > 0)
					{
						sep->wszRealText[sep->iLen] ^= 
								sep->iNumSpaces[sep->iLen];
						sep->iLen++;
						i--;
					}

					ImmReleaseContext (hWnd, hIMC);
				}

				InvalidateRect (hWnd, NULL, FALSE);

				sCalculateEstimatedQuality (sep);

				if (sep->UserCallback)
					(sep->UserCallback)(hWnd,sep->pUserValue);

				return 0;
            }
   			break;
		}
#endif // !PGP_SDA

		case WM_CHAR :
		{
			WCHAR wchCharCode;
			int strsize;

			strsize = sep->iLen;
			wchCharCode = (WCHAR)wParam;

			if ((wchCharCode == VK_ESCAPE) || (wchCharCode == VK_RETURN))
			{
				sep->dwSpecialKey = wchCharCode;
				return 0;
			}

			// look for backspace characters
			if (wchCharCode == 0x08)
			{
				strsize--;

				// Backspace it for us
				if (strsize >= 0)
				{
					sep->wszRealText[strsize] = 0;
					sep->iLen--;

					InvalidateRect (hWnd, NULL, FALSE);

					sCalculateEstimatedQuality (sep);

					if (sep->UserCallback)
						(sep->UserCallback)(hWnd,sep->pUserValue);
				}

				return 0;
			}

			if (strsize == SE_BUFSIZE)
				return 0;

			if (strsize >= sep->iMaxLen)
				return 0;

			if (iscntrl (wchCharCode))
				return 0;

			// if character is in local code page, convert to Unicode
			if (wchCharCode > 127)
			{
				if (!sep->bUnicodeOS)
				{
					unsigned char chCharCode = LOBYTE (wchCharCode);
					PGPUInt32	u;
					CHARSETINFO	cs;

					if (!sep->bGotLanguageNotification)
						sep->iCharSet = sGetCharset ();

					TranslateCharsetInfo (
							(DWORD*)(sep->iCharSet), &cs, TCI_SRCCHARSET);

					pgpLocalStringToUCS2 (kPGPUnicodeFlag_Secure, 
							cs.ciACP, &chCharCode, 1, 
							&wchCharCode, 1, &u);
				}
			}

			// This is XOR'ed to obsfucate, just in case something
			// "really bad" happens. The memory should be locked,
			// cleared and freed on exit however.
			sep->wszRealText[strsize]=wchCharCode^sep->iNumSpaces[strsize];
			sep->iLen++;

			InvalidateRect (hWnd, NULL, FALSE);

			sCalculateEstimatedQuality (sep);

			if (sep->UserCallback)
				(sep->UserCallback)(hWnd,sep->pUserValue);

			return 0;
		}
	}

	if (sep->bUnicodeOS)
	{
		return CallWindowProcW (sep->wpOrigProc, 
				hWnd, uMsg, wParam, lParam);
	}
	else
	{
		return CallWindowProcA (sep->wpOrigProc, 
				hWnd, uMsg, wParam, lParam);
	}
} 


//	______________________________________
//
//  initialize the subclassing

VOID
SEInit(
#if PGP_SDK_AVAILABLE
	   PGPContextRef	context,
#endif
	   HWND				hwndEdit,
	   BOOL				bHideTyping,
	   USERCALLBACK		UserCallback,
	   void*			pUserValue)
{
	OSVERSIONINFO	osvi;
	SEP				sep;
	int				index;
	TEXTMETRIC		tm;
	HDC				hdc;

#if PGP_SDK_AVAILABLE
	sep=SEsecAlloc(context,sizeof(SE));
#else
	sep=malloc(sizeof(SE));
#endif
	memset(sep,0x00,sizeof(SE));
	sep->hwndEdit=hwndEdit;
	sep->iMaxLen=0x7fffffff; // No maximum

	osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
	GetVersionEx (&osvi);
	sep->bUnicodeOS = (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT);

	GetClientRect (hwndEdit, &sep->rcClient);

	hdc = GetDC (hwndEdit);
	GetTextMetrics (hdc, &tm);
	sep->iCaretHeight = tm.tmAscent;
	sep->iRowHeight = tm.tmHeight;
	if (!sep->bUnicodeOS)
		sep->iCharSet = sGetCharset ();

	sep->hdcMem = CreateCompatibleDC (hdc);
	sep->hbmMem = CreateCompatibleBitmap (hdc, 
			sep->rcClient.right-sep->rcClient.left, 
			sep->rcClient.bottom-sep->rcClient.top);
	SelectObject (sep->hdcMem, sep->hbmMem);
	ReleaseDC (hwndEdit, hdc);

	SetWindowLong (hwndEdit,GWL_USERDATA,(LONG)sep);

	if (sep->bUnicodeOS)
	{
		sep->wpOrigProc = (WNDPROC) 
			SetWindowLongW(hwndEdit,GWL_WNDPROC,(LONG)SESubclassProc);
	}
	else
	{
		SendMessage (hwndEdit, EM_SETEDITSTYLE, SES_USEAIMM, SES_USEAIMM);
		sep->wpOrigProc = (WNDPROC) 
			SetWindowLong(hwndEdit,GWL_WNDPROC,(LONG)SESubclassProc);
	}

	sep->bHideTyping=bHideTyping;
	sep->iLen=0;
	sep->UserCallback=UserCallback;
	sep->pUserValue=pUserValue;

	sCheckCaps (sep);

	srand( (unsigned)time( NULL ) );
	for (index=0; index<SE_BUFSIZE+1; index++)
		sep->iNumSpaces[index]=rand();

	// initialize the caret
	if (GetFocus () == hwndEdit)
	{
		sep->bFocused = TRUE;
		CreateCaret (hwndEdit, NULL, 0, sep->iCaretHeight);
		ShowCaret (hwndEdit);
	}
}

VOID 
SEDestroy(HWND hwndEdit)
{
	SEP sep;

	sep=(SEP)GetWindowLong (hwndEdit, GWL_USERDATA);

	if(sep!=0)
	{
		if (sep->bFocused)
			DestroyCaret ();

		DeleteObject (sep->hbmMem);
		DeleteDC (sep->hdcMem);

		if (sep->bUnicodeOS)
			SetWindowLongW(hwndEdit,GWL_WNDPROC,(LONG)sep->wpOrigProc);
		else
			SetWindowLong(hwndEdit,GWL_WNDPROC,(LONG)sep->wpOrigProc);

		SetWindowLong(hwndEdit,GWL_USERDATA,(LONG)0);

#if PGP_SDK_AVAILABLE
		SEsecFree(sep,sizeof(SE));
#else
		memset(sep,0x00,sizeof(SE));
		free(sep);
#endif
	}
}


//	__________________
//
//	Wipe edit box clean

VOID 
SEWipeEditBox (HWND hwndEdit)
{
	SEP sep;
	char szNull[1];
	int index;

	sep=(SEP)GetWindowLong (hwndEdit, GWL_USERDATA);

	if(sep!=0)
	{
		sep->dwQuality=0;
		sep->iLen=0;
		memset(sep->wszRealText,0x00,sizeof(sep->wszRealText));
		for(index=0;index<SE_BUFSIZE+1;index++)
		{
			sep->iNumSpaces[index]=rand();
		}

		szNull[0]=0;
		SendMessage(hwndEdit,WM_SETTEXT,0,(LPARAM)szNull);

		InvalidateRect(hwndEdit,NULL,TRUE);
		UpdateWindow(hwndEdit);
	}
}

VOID 
SESetMaxLength (HWND hwndEdit, int iMaxLen)
{
	SEP sep;

	sep=(SEP)GetWindowLong (hwndEdit, GWL_USERDATA);

	sep->iMaxLen=iMaxLen;
}

VOID 
SEGetText(HWND hwndEdit,char *copyto,int ilen)
{
	SEP sep;
	int index;
	PGPUInt32 ucopied;

	sep=(SEP)GetWindowLong (hwndEdit, GWL_USERDATA);

	for(index=0;index<sep->iLen;index++)
		sep->wszRealText[index]^=sep->iNumSpaces[index];

	pgpUCS2StringToUTF8 (sep->wszRealText, sep->iLen, copyto, ilen, &ucopied);

	for(index=0;index<sep->iLen;index++)
		sep->wszRealText[index]^=sep->iNumSpaces[index];

	copyto[ucopied]=0;
}

DWORD
SEGetTextLength(HWND hwndEdit)
{
	SEP sep;
	int index;
	UINT ulen;

	sep=(SEP)GetWindowLong (hwndEdit, GWL_USERDATA);

	for(index=0;index<sep->iLen;index++)
		sep->wszRealText[index]^=sep->iNumSpaces[index];

	pgpUCS2StringToUTF8 (sep->wszRealText, sep->iLen, NULL, 0, &ulen);

	for(index=0;index<sep->iLen;index++)
		sep->wszRealText[index]^=sep->iNumSpaces[index];

	return ulen;
}

BOOL
SEGetShowWarning(HWND hwndEdit)
{
	SEP sep;

	sep=(SEP)GetWindowLong (hwndEdit, GWL_USERDATA);

	return sep->bShowWarning;
}

VOID 
SEChangeHideTyping (HWND hwndEdit, BOOL bHideTyping)
{
	SEP sep;

	sep=(SEP)GetWindowLong (hwndEdit, GWL_USERDATA);

	if(bHideTyping==sep->bHideTyping)
		return;

	sep->bHideTyping=bHideTyping;

	InvalidateRect (hwndEdit, NULL, FALSE);
}

DWORD
SEGetSpecialKey(HWND hwndEdit)
{
	SEP	sep;
	DWORD dwSpecialKey;

	sep=(SEP)GetWindowLong (hwndEdit, GWL_USERDATA);

	dwSpecialKey = sep->dwSpecialKey;
	sep->dwSpecialKey = 0;

	return dwSpecialKey;
}

#if PGP_SDK_AVAILABLE
DWORD
SEGetTextQuality(HWND hwndEdit)
{
	SEP sep;

	sep=(SEP)GetWindowLong (hwndEdit, GWL_USERDATA);

	return sep->dwQuality;
}
#endif

/*__Editor_settings____

	Local Variables:
	tab-width: 4
	End:
	vi: ts=4 sw=4
	vim: si
_____________________*/

⌨️ 快捷键说明

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