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

📄 pkmenu.c

📁 PGP8.0源码 请认真阅读您的文件包然后写出其具体功能
💻 C
📖 第 1 页 / 共 4 页
字号:
/*____________________________________________________________________________
	Copyright (C) 2002 PGP Corporation
	All rights reserved.

	PKMenu.c - handle menu enabling/disabling chores

	$Id: PKMenu.c,v 1.56 2002/10/31 04:13:36 pbj Exp $
____________________________________________________________________________*/
#include "pgpPFLConfig.h"

// project header files
#include "PGPkeysx.h"
#include "pgpImageList.h"
#include "PGPpda.h"

// pgp header files
#include "pgpKeyServerPrefs.h"

// constant definitions
#define	SENDTOSERVERPOS	0

#define MENU_FILE		0
#define MENU_EDIT		1
#define MENU_VIEW		2
#define MENU_KEYS		3
#define MENU_SERVER		4
#define MENU_GROUPS		5
#define MENU_HELP		6

#define SUBMENU_ADD		2


// External globals
extern HINSTANCE		g_hinst;
extern PGPBoolean		g_bKeyGenEnabled;
extern PGPBoolean		g_bX509CertRequestEnabled;
extern PGPBoolean		g_bKeyReconstructionEnabled;
extern PGPUInt32		g_uNumTokens;
extern PGPContextRef	g_context;
extern PGPPDASTRUCT*	g_pPDA;


//	____________________________________
//
//  Enable/Disable menu items

static VOID
sSetItem (
		HMENU	hMenu,
		INT		iId,
		BOOL	bEnable)
{
	if (bEnable)
		EnableMenuItem (hMenu, iId, MF_BYCOMMAND|MF_ENABLED);
	else
		EnableMenuItem (hMenu, iId, MF_BYCOMMAND|MF_GRAYED);
}


//	___________________________________________________
//
//	create popup menu which is list of keyservers

static HMENU
sCreateKeyserverMenu (
		PGPKEYSSTRUCT*	ppks)
{
	PGPPrefRef			prefref			= kInvalidPGPPrefRef;
	PGPUInt32			uNumServers		= 0;
	HMENU				hmenu			= NULL;

	PGPKeyServerEntry*	keyserverList;
	PGPUInt32			u, uID;
	PGPError			err;
	CHAR				sz[256];

	if (IsPGPError (PGPclPeekClientLibPrefRefs (&prefref, NULL)))
		return NULL;

	hmenu = CreatePopupMenu ();
	err = PGPGetKeyServerPrefs (prefref, &keyserverList, &uNumServers);

	if (IsntPGPError (err))
	{
		LoadString (g_hinst, IDS_DOMAINSERVER, sz, sizeof(sz));
		AppendMenu (hmenu, MF_STRING, IDM_DOMAINKEYSERVERX, sz);

		if(PGPlnEnterprise())
		{
			if (g_bKeyReconstructionEnabled)
			{
				LoadString (g_hinst, IDS_RECONSTRUCTIONSERVER, sz, sizeof(sz));
				AppendMenu (hmenu, MF_STRING, IDM_DOMAINKEYSERVERX +1, sz);
				sSetItem (hmenu, IDM_DOMAINKEYSERVERX +1, 
						PKIsActionEnabled (ppks, KM_SENDTORECONSERVER));
			}
		}

		LoadString (g_hinst, IDS_TOKEN, sz, sizeof(sz));
		AppendMenu (hmenu, MF_STRING, IDM_SENDTOTOKEN, sz);
		sSetItem (hmenu, IDM_SENDTOTOKEN, 
				PKIsActionEnabled (ppks, KM_SENDTOTOKEN));

		LoadString (g_hinst, IDS_EMAILRECIPIENT, sz, sizeof(sz));
		AppendMenu (hmenu, MF_STRING, IDM_SENDVIAEMAIL, sz);

		AppendMenu (hmenu, MF_SEPARATOR, 0, NULL);

		uID = 2;
		for (u=0; u<uNumServers; u++)
		{
			if (IsKeyServerListed (keyserverList[u].flags))
			{
				PGPGetKeyServerURL (&(keyserverList[u]), sz);
				AppendMenu (hmenu, MF_STRING, IDM_DOMAINKEYSERVERX +uID, sz);
				++uID;
			}
		}

		if (keyserverList)
			PGPFreeKeyServerList (keyserverList);
	}

	return hmenu;
}


//	___________________________________________________
//
//	initialize the main window menu based on build flags

VOID
PKInitMenuKeyMan (
		HMENU	hmenuMain,
		UINT	uFlags)
{
	HMENU	hmenu;

	// get "File" menu
	hmenu = GetSubMenu (hmenuMain, MENU_FILE);

	if ((uFlags & (PK_MAINWINDOW|PK_PDAWINDOW)) &&
		IsntNull (g_pPDA))
	{
		PGPError (*pGetPdaString)(PGPpdaStringStruct*);

		PGPPDASTRUCT*		pPDA			= g_pPDA;
		UINT				uIndex			= 0;
		BOOL				bItemAdded		= FALSE;

		PGPpdaStringStruct	pss;
		MENUITEMINFO		mii;
		HMODULE				hmod;

		while (pPDA->hmod)
		{
			if (pPDA->uPlatform == 0)
			{
				pPDA++;
				uIndex++;
				continue;
			}

			hmod = pPDA->hmod;

			pGetPdaString = (PGPError (*)(PGPpdaStringStruct*))
					GetProcAddress (hmod, "PGPpdaGetString");

			if (pGetPdaString)
			{
				if (pPDA->bKeyring)
				{
					if (uFlags & PK_MAINWINDOW)
					{
						mii.cbSize = sizeof(mii);

						pss.uStringIndex = kPGPpdaString_OpenKeyringMenuText;
						if ((*pGetPdaString)(&pss) == kPGPError_NoErr)
						{
							mii.fMask = MIIM_TYPE | MIIM_ID;
							mii.fType = MFT_STRING;
							mii.wID = IDM_PDAOPERATION + uIndex;
							mii.dwTypeData = pss.szString;
							mii.cch = lstrlen (pss.szString);

							if (InsertMenuItem (hmenu, IDM_CLOSE, FALSE, &mii))
								bItemAdded = TRUE;
						}
					}
				}
				else
				{
					if (((pPDA->uFlags & PK_PDAWINDOWOP) && 
							(uFlags & PK_PDAWINDOW)) ||
						(!(pPDA->uFlags & PK_PDAWINDOWOP) && 
							(uFlags & PK_MAINWINDOW)))
					{
						mii.cbSize = sizeof(mii);

						pss.uStringIndex = 
								kPGPpdaString_OperationMenuText + pPDA->uOp;
						if ((*pGetPdaString)(&pss) == kPGPError_NoErr)
						{
							mii.fMask = MIIM_TYPE | MIIM_ID;
							mii.fType = MFT_STRING;
							mii.wID = IDM_PDAOPERATION + uIndex;
							mii.dwTypeData = pss.szString;
							mii.cch = lstrlen (pss.szString);

							if (InsertMenuItem (hmenu, IDM_CLOSE, FALSE, &mii))
								bItemAdded = TRUE;
						}
					}
				}
			}

			pPDA++;
			uIndex++;

			if (pPDA->hmod != hmod)
			{
				if (bItemAdded)
				{
					mii.fMask = MIIM_TYPE;
					mii.fType = MFT_SEPARATOR;
					InsertMenuItem (hmenu, IDM_CLOSE, FALSE, &mii);
				}
			}
		}
	}

	if(PGPlnEnterprise())
	{
		if (PGPclIsClientInstall ())
		{
			// get "Servers" menu
			hmenu = GetSubMenu (hmenuMain, MENU_SERVER);

			// delete "Send Group Lists" item
			DeleteMenu (hmenu, IDM_SENDGROUPLISTS, MF_BYCOMMAND);
		}
	}
	else
	{
		// get "Servers" menu
		hmenu = GetSubMenu (hmenuMain, MENU_SERVER);

		// delete "Update" items
		DeleteMenu (hmenu, IDM_SENDGROUPLISTS, MF_BYCOMMAND);
		DeleteMenu (hmenu, IDM_UPDATEGROUPLISTS, MF_BYCOMMAND);
		DeleteMenu (hmenu, IDM_UPDATECONFIGURATION, MF_BYCOMMAND);
		DeleteMenu (hmenu, IDM_UPDATEINTRODUCERS, MF_BYCOMMAND);

		// get "Keys" menu
		hmenu = GetSubMenu (hmenuMain, MENU_KEYS);

		// delete "Reconstruct" item
		DeleteMenu (hmenu, IDM_RECONSTRUCTKEY, MF_BYCOMMAND);
	}

	hmenu = GetSubMenu (hmenuMain, MENU_FILE);
	if (uFlags & PK_MAINWINDOW)
		DeleteMenu (hmenu, IDM_CLOSE, MF_BYCOMMAND);
	else
	{
		DeleteMenu (hmenu, IDM_FILEEXIT, MF_BYCOMMAND);

		// now delete entire "Groups" menu
		DeleteMenu (hmenuMain, MENU_GROUPS, MF_BYPOSITION);
	}
}


//	___________________________________________________
//
//	derive the keyserver string name from the menu ID

VOID
PKGetServerActionFromID (
		UINT				uID,
		PGPKeyServerEntry*	pkeyserver,
		UINT*				puAction)
{
	PGPUInt32			uNumServers		= 0;
	HMENU				hmenu			= NULL;
	PGPKeyServerEntry*	keyserverList	= NULL;
	PGPPrefRef			prefref			= kInvalidPGPPrefRef;

	PGPUInt32			u1, u2;
	PGPError			err;

	*puAction = KM_NOACTION;

	if (IsPGPError (PGPclPeekClientLibPrefRefs (&prefref, NULL)))
		return;

	// domain server
	if (uID == IDM_DOMAINKEYSERVERX)
	{
		err = PGPCreateKeyServerPath (prefref, "",
				&keyserverList, &uNumServers);
		if (IsntPGPError (err))
		{
			*puAction = KM_SENDTOSERVER;
			CopyMemory (pkeyserver, &(keyserverList[0]),
					sizeof(PGPKeyServerEntry));
			PGPDisposeKeyServerPath (keyserverList);
		}
	}

	// reconstruction server
	else if (uID == IDM_DOMAINKEYSERVERX +1)
	{
		*puAction = KM_SENDTORECONSERVER;
		ZeroMemory (pkeyserver, sizeof(PGPKeyServerEntry));
	}

	// other servers
	else
	{
		PGPGetKeyServerPrefs (prefref, &keyserverList, &uNumServers);

		u1 = IDM_DOMAINKEYSERVERX+2;
		if ((uID - u1) < uNumServers)
		{
			for (u2=0; u2<uNumServers; u2++)
			{
				if (IsKeyServerListed (keyserverList[u2].flags))
				{
					if (uID == u1)
					{
						*puAction = KM_SENDTOSERVER;
						CopyMemory (pkeyserver, &(keyserverList[u2]),
								sizeof(PGPKeyServerEntry));
						break;
					}
					u1++;
				}
			}
		}
		if (keyserverList)
			PGPFreeKeyServerList (keyserverList);
	}

	return;
}


//	_____________________________________________________
//
//  Set the Expand/Collapse items to "All" or "Selection"

static VOID
sSetMenuAllOrSelected (
		HMENU	hMenu,
		BOOL	bAll)
{
	MENUITEMINFO	mii;
	CHAR			sz[64];

	mii.cbSize = sizeof (MENUITEMINFO);
	mii.fMask = MIIM_TYPE;
	mii.fType = MFT_STRING;
	if (bAll)
	{
		LoadString (g_hinst, IDS_COLLAPSEALL, sz, sizeof(sz));
		mii.dwTypeData = sz;
		mii.cch = lstrlen (sz);
		SetMenuItemInfo (hMenu, IDM_COLLAPSESEL, FALSE, &mii);
		LoadString (g_hinst, IDS_EXPANDALL, sz, sizeof(sz));
		mii.dwTypeData = sz;
		mii.cch = lstrlen (sz);
		SetMenuItemInfo (hMenu, IDM_EXPANDSEL, FALSE, &mii);
	}
	else
	{
		LoadString (g_hinst, IDS_COLLAPSESEL, sz, sizeof(sz));
		mii.dwTypeData = sz;
		mii.cch = lstrlen (sz);
		SetMenuItemInfo (hMenu, IDM_COLLAPSESEL, FALSE, &mii);
		LoadString (g_hinst, IDS_EXPANDSEL, sz, sizeof(sz));
		mii.dwTypeData = sz;
		mii.cch = lstrlen (sz);
		SetMenuItemInfo (hMenu, IDM_EXPANDSEL, FALSE, &mii);
	}
}

//	______________________________________________
//
//  Set the "Set As ..." to "Default" or "Primary"

static VOID
sSetMenuDefaultOrPrimary (
		HMENU	hMenu,
		BOOL	bDefault)
{
	MENUITEMINFO	mii;
	CHAR			sz[64];

	mii.cbSize = sizeof (MENUITEMINFO);
	mii.fMask = MIIM_TYPE;
	mii.fType = MFT_STRING;
	if (bDefault)
	{
		LoadString (g_hinst, IDS_SETASDEFAULT, sz, sizeof(sz));
		mii.dwTypeData = sz;
		mii.cch = lstrlen (sz);
		SetMenuItemInfo (hMenu, IDM_SETASDEFAULT, FALSE, &mii);
	}
	else
	{
		LoadString (g_hinst, IDS_SETASPRIMARY, sz, sizeof(sz));
		mii.dwTypeData = sz;
		mii.cch = lstrlen (sz);
		SetMenuItemInfo (hMenu, IDM_SETASDEFAULT, FALSE, &mii);
	}
}


//	____________________________________
//
//  returns TRUE if multiple types of objects are selected

static BOOL
sPromiscuousSelected (
		PGPUInt32	uSel)
{
	switch (uSel) {
	case kPGPclKeyList_None :
	case kPGPclKeyList_Key :
	case kPGPclKeyList_UserID :
	case kPGPclKeyList_Signature :
		return FALSE;

	default :
		return TRUE;
	}
}


//	________________________________________
//
//	Return TRUE if signing operations allowed

static BOOL
sSigningAllowed (PGPUInt32 uSel)
{
	if ((uSel == kPGPclKeyList_None) ||
		(uSel & kPGPclKeyList_Signature))
	{
		return FALSE;
	}
	else
		return TRUE;
}


//	___________________________________________________
//
//	determine if each action is enabled or not

//	copy
static BOOL
sIsCopyEnabled (PPGPKEYSSTRUCT ppks)
{
	PGPUInt32		uSel, uFocus;

⌨️ 快捷键说明

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