clprefshotkeys.c

来自「PGP8.0源码 请认真阅读您的文件包然后写出其具体功能」· C语言 代码 · 共 616 行 · 第 1/2 页

C
616
字号
/*____________________________________________________________________________
	Copyright (C) 2002 PGP Corporation
	All rights reserved.
	
	CLprefsHotkeys.c - handle PGP hotkeys preferences dialogs

	$Id: CLprefsHotkeys.c,v 1.15 2002/11/12 18:55:25 pbj Exp $
____________________________________________________________________________*/
#include "pgpPFLConfig.h"

// project header files
#include "PGPclx.h"
#include "CLprefs.h"
#include "pgpHotKeys.h"

// external globals
extern HINSTANCE	g_hInst;


static DWORD aHotkeyIds[] = {			// Help IDs
	IDC_ENABLEPURGECACHE,	IDH_PGPCLPREF_ENABLEPURGEHOTKEY,
	IDC_PURGEHOTKEY,		IDH_PGPCLPREF_PURGEHOTKEY,
	IDC_ENABLEENCRYPT,		IDH_PGPCLPREF_ENABLEENCRYPTHOTKEY,
	IDC_ENCRYPTHOTKEY,		IDH_PGPCLPREF_ENCRYPTHOTKEY,
	IDC_ENABLESIGN,			IDH_PGPCLPREF_ENABLESIGNHOTKEY,
	IDC_SIGNHOTKEY,			IDH_PGPCLPREF_SIGNHOTKEY,
	IDC_ENABLEENCRYPTSIGN,	IDH_PGPCLPREF_ENABLEESHOTKEY,
	IDC_ENCRYPTSIGNHOTKEY,	IDH_PGPCLPREF_ENCRYPTSIGNHOTKEY,
	IDC_ENABLEDECRYPT,		IDH_PGPCLPREF_ENABLEDECRYPTHOTKEY,
	IDC_DECRYPTHOTKEY,		IDH_PGPCLPREF_DECRYPTHOTKEY,
	IDC_ENABLEUNMOUNT,		IDH_PGPCLPREF_ENABLEUNMOUNTHOTKEY,
	IDC_UNMOUNTHOTKEY,		IDH_PGPCLPREF_UNMOUNTHOTKEY,
	0,0
};


//	_____________________________________________________
//
//  Message processing function for property sheet dialog

static VOID
sSetHotKeyControl (
		HWND		hwnd,
		PGPUInt32	u)
{
	UINT	uKey	= LOWORD (u);
	UINT	uMod	= 0;

	if (u & kPGPHotKeyAltModifier)
		uMod |= HOTKEYF_ALT;

	if (u & kPGPHotKeyCtrlModifier)
		uMod |= HOTKEYF_CONTROL;

	if (u & kPGPHotKeyExtModifier)
		uMod |= HOTKEYF_EXT;

	if (u & kPGPHotKeyShiftModifier)
		uMod |= HOTKEYF_SHIFT;

	SendMessage (hwnd, HKM_SETHOTKEY, MAKEWORD (LOBYTE (uKey), uMod), 0);

	if (u & kPGPHotKeyEnabled)
		EnableWindow (hwnd, TRUE);
	else
		EnableWindow (hwnd, FALSE);
}


//	_____________________________________________________
//
//  Message processing function for property sheet dialog

static PGPUInt32
sGetHotKeyControl (
		HWND		hwnd)
{
	UINT	uKey;
	WORD	wMod;

	uKey = SendMessage (hwnd, HKM_GETHOTKEY, 0, 0);

	wMod = HIBYTE (LOWORD (uKey));
	uKey &= 0xFF;

	if (wMod & HOTKEYF_ALT)
		uKey |= kPGPHotKeyAltModifier;

	if (wMod & HOTKEYF_CONTROL)
		uKey |= kPGPHotKeyCtrlModifier;

	if (wMod & HOTKEYF_EXT)
		uKey |= kPGPHotKeyExtModifier;

	if (wMod & HOTKEYF_SHIFT)
		uKey |= kPGPHotKeyShiftModifier;

	return uKey;
}


//	_____________________________________________________
//
//  Message processing function for property sheet dialog

static BOOL
sDoHotKeysOverlap (
		PGPHotKeys* photkeys)
{
	PGPUInt32* pStart	= &(photkeys->hotkeyPurgePassphraseCache);
	PGPUInt32* pEnd		= &(photkeys->hotkeyDiskUnmount);
	PGPUInt32* p;

	do
	{
		p = pStart+1;
		while (p <= pEnd)
		{
			if ((*p & kPGPHotKeyEnabled) &&
				(*p == *pStart))
				return TRUE;
			p++;
		}
		pStart++;
	}
	while (pStart < pEnd);

	return FALSE;
}


//	_____________________________________________________
//
//  determine if hotkey is already in use -- this works because
//	we have already disabled all PGP hotkeys (except PGPdisk)

static BOOL
sIsHotKeyInUse (
		PGPUInt32 uHotKey)
{
	UINT	uMod		= 0;
	BOOL	bInUse		= TRUE;

	if (uHotKey & kPGPHotKeyAltModifier)
		uMod |= MOD_ALT;
	if (uHotKey & kPGPHotKeyCtrlModifier)
		uMod |= MOD_CONTROL;
	if (uHotKey & kPGPHotKeyShiftModifier)
		uMod |= MOD_SHIFT;

	if (RegisterHotKey (NULL, 0xC000, uMod, (uHotKey & 0xFF)))
	{
		UnregisterHotKey (NULL, 0xC000);
		bInUse = FALSE;
	}

	return bInUse;
}


//	_____________________________________________________
//
//  Message processing function for property sheet dialog

LRESULT WINAPI
CLHotkeyPropDlgProc (
		HWND	hwnd,
		UINT	uMsg,
		WPARAM	wParam,
		LPARAM	lParam)
{
	PPREFSDLGSTRUCT			ppds;

	switch (uMsg) {

	case WM_INITDIALOG:
	{
		PGPHotKeys*		phks		= NULL;
		PGPSize			size;
		PGPHotKeys		hotkeys;
		PGPError		err;
		PGPPrefRef		prefref;

		SetWindowLong (hwnd, GWL_USERDATA, ((PROPSHEETPAGE*)lParam)->lParam);
		ppds = (PPREFSDLGSTRUCT)GetWindowLong (hwnd, GWL_USERDATA);

		if (ppds->bNeedsCentering) 
		{
			PGPclCenterWindowOnMonitor (GetParent (hwnd), kPGPclWindowMonitor);
			ppds->bNeedsCentering = FALSE;
		}

		prefref = CLGetPrefRef (ppds);

		pgpCopyMemory (&sDefaultHotKeys, &hotkeys, sizeof(hotkeys));
		err = PGPGetPrefData (prefref, kPGPPrefHotKeyData, &size, &phks);

		if ((IsntPGPError (err)) &&
			(size == sizeof (hotkeys)))
				pgpCopyMemory (phks, &hotkeys, size);

		// initialize purge passphrase hotkey
		sSetHotKeyControl (GetDlgItem (hwnd, IDC_PURGEHOTKEY),
				hotkeys.hotkeyPurgePassphraseCache);

		if (hotkeys.hotkeyPurgePassphraseCache & kPGPHotKeyEnabled)
			CheckDlgButton (hwnd, IDC_ENABLEPURGECACHE, BST_CHECKED);
		else
			CheckDlgButton (hwnd, IDC_ENABLEPURGECACHE, BST_UNCHECKED);

		if (ppds->bToolsPrefsEnabled)
		{
			// initialize encrypt hotkey
			sSetHotKeyControl (GetDlgItem (hwnd, IDC_ENCRYPTHOTKEY),
					hotkeys.hotkeyEncrypt);

			if (hotkeys.hotkeyEncrypt & kPGPHotKeyEnabled)
				CheckDlgButton (hwnd, IDC_ENABLEENCRYPT, BST_CHECKED);
			else
				CheckDlgButton (hwnd, IDC_ENABLEENCRYPT, BST_UNCHECKED);

			// initialize sign hotkey
			sSetHotKeyControl (GetDlgItem (hwnd, IDC_SIGNHOTKEY),
					hotkeys.hotkeySign);

			if (hotkeys.hotkeySign & kPGPHotKeyEnabled)
				CheckDlgButton (hwnd, IDC_ENABLESIGN, BST_CHECKED);
			else
				CheckDlgButton (hwnd, IDC_ENABLESIGN, BST_UNCHECKED);

			// initialize encrypt & sign hotkey
			sSetHotKeyControl (GetDlgItem (hwnd, IDC_ENCRYPTSIGNHOTKEY),
					hotkeys.hotkeyEncryptSign);

			if (hotkeys.hotkeyEncryptSign & kPGPHotKeyEnabled)
				CheckDlgButton (hwnd, IDC_ENABLEENCRYPTSIGN, BST_CHECKED);
			else
				CheckDlgButton (hwnd, IDC_ENABLEENCRYPTSIGN, BST_UNCHECKED);

			// initialize decrypt & verify hotkey
			sSetHotKeyControl (GetDlgItem (hwnd, IDC_DECRYPTHOTKEY),
					hotkeys.hotkeyDecrypt);

			if (hotkeys.hotkeyDecrypt & kPGPHotKeyEnabled)
				CheckDlgButton (hwnd, IDC_ENABLEDECRYPT, BST_CHECKED);
			else
				CheckDlgButton (hwnd, IDC_ENABLEDECRYPT, BST_UNCHECKED);
		}
		else
		{
			CheckDlgButton (hwnd, IDC_ENABLEENCRYPT, BST_UNCHECKED);
			CheckDlgButton (hwnd, IDC_ENABLESIGN, BST_UNCHECKED);
			CheckDlgButton (hwnd, IDC_ENABLEENCRYPTSIGN, BST_UNCHECKED);
			CheckDlgButton (hwnd, IDC_ENABLEDECRYPT, BST_UNCHECKED);

			EnableWindow (GetDlgItem (hwnd, IDC_ENABLEENCRYPT), FALSE);
			EnableWindow (GetDlgItem (hwnd, IDC_ENABLESIGN), FALSE);
			EnableWindow (GetDlgItem (hwnd, IDC_ENABLEENCRYPTSIGN), FALSE);
			EnableWindow (GetDlgItem (hwnd, IDC_ENABLEDECRYPT), FALSE);

			EnableWindow (GetDlgItem (hwnd, IDC_ENCRYPTHOTKEY), FALSE);
			EnableWindow (GetDlgItem (hwnd, IDC_SIGNHOTKEY), FALSE);
			EnableWindow (GetDlgItem (hwnd, IDC_ENCRYPTSIGNHOTKEY), FALSE);
			EnableWindow (GetDlgItem (hwnd, IDC_DECRYPTHOTKEY), FALSE);

			ShowWindow (GetDlgItem (hwnd, IDC_ENABLEENCRYPT), SW_HIDE);
			ShowWindow (GetDlgItem (hwnd, IDC_ENABLESIGN), SW_HIDE);
			ShowWindow (GetDlgItem (hwnd, IDC_ENABLEENCRYPTSIGN), SW_HIDE);
			ShowWindow (GetDlgItem (hwnd, IDC_ENABLEDECRYPT), SW_HIDE);

			ShowWindow (GetDlgItem (hwnd, IDC_ENCRYPTHOTKEY), SW_HIDE);
			ShowWindow (GetDlgItem (hwnd, IDC_SIGNHOTKEY), SW_HIDE);
			ShowWindow (GetDlgItem (hwnd, IDC_ENCRYPTSIGNHOTKEY), SW_HIDE);
			ShowWindow (GetDlgItem (hwnd, IDC_DECRYPTHOTKEY), SW_HIDE);
		}

		// initialize unmount hotkey
		if(PGPlnIsAuthorized() && PGPlnPGPdiskEnabled ())
		{
			if (ppds->disk.bPrefsEnabled)
			{
				sSetHotKeyControl (GetDlgItem (hwnd, IDC_UNMOUNTHOTKEY),
						hotkeys.hotkeyDiskUnmount);

				if (hotkeys.hotkeyDiskUnmount & kPGPHotKeyEnabled)
					CheckDlgButton (hwnd, IDC_ENABLEUNMOUNT, BST_CHECKED);
				else
					CheckDlgButton (hwnd, IDC_ENABLEUNMOUNT, BST_UNCHECKED);
			}
			else
			{
				CheckDlgButton (hwnd, IDC_ENABLEUNMOUNT, BST_UNCHECKED);

				EnableWindow (GetDlgItem (hwnd, IDC_ENABLEUNMOUNT), FALSE);
				EnableWindow (GetDlgItem (hwnd, IDC_UNMOUNTHOTKEY), FALSE);

				ShowWindow (GetDlgItem (hwnd, IDC_ENABLEUNMOUNT), SW_HIDE);
				ShowWindow (GetDlgItem (hwnd, IDC_UNMOUNTHOTKEY), SW_HIDE);
			}
		}
		else
		{
			CheckDlgButton (hwnd, IDC_ENABLEUNMOUNT, BST_UNCHECKED);

			EnableWindow (GetDlgItem (hwnd, IDC_ENABLEUNMOUNT), FALSE);
			EnableWindow (GetDlgItem (hwnd, IDC_UNMOUNTHOTKEY), FALSE);

			ShowWindow (GetDlgItem (hwnd, IDC_ENABLEUNMOUNT), SW_HIDE);

⌨️ 快捷键说明

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