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

📄 clkspref.c

📁 vc环境下的pgp源码
💻 C
📖 第 1 页 / 共 3 页
字号:
			tlL.pszText = NULL;
		TreeList_SetListItem (hWndTree, &tlL, FALSE);

		// set listed state
		tlL.hItem = hTSelected;
		tlL.mask = TLIF_DATAVALUE;
		tlL.iSubItem = 2;
		if (pkss->bListed) tlL.lDataValue = IDX_CHECKED;
		else tlL.lDataValue = IDX_UNCHECKED;
		TreeList_SetListItem (hWndTree, &tlL, FALSE);
	}

	SetFocus (hWndTree);
}

//	_____________________________________________________
//
//  remove selected keyserver from treelist

VOID
CLRemoveKeyserver (HWND hWndParent, HWND hWndTree)
{
	CHAR sz0[256];
	CHAR sz1[256];
	CHAR sz2[256];
	TL_TREEITEM tlI;
	HTLITEM hTParent;

	if (sIsThisTheOnlyWorldServer (hWndTree)) {
		PGPclMessageBox (hWndParent, IDS_PROPCAPTION, 
				IDS_MUSTHAVEDEFAULTSERVER, MB_OK|MB_ICONEXCLAMATION);
		return;
	}

	tlI.hItem = hTSelected;
	tlI.mask = TLIF_TEXT | TLIF_PARAM;
	tlI.pszText = sz1;
	tlI.cchTextMax = sizeof(sz1);
	TreeList_GetItem (hWndTree, &tlI);
	hTParent = tlI.hItem;

	LoadString (g_hInst, IDS_DELKSPROMPT, sz0, sizeof(sz0));
	wsprintf (sz2, sz0, sz1);

	LoadString (g_hInst, IDS_PROPCAPTION, sz1, sizeof(sz1));
	if (MessageBox (hWndParent, sz2, sz1, 
			MB_YESNO|MB_ICONEXCLAMATION) == IDYES) {

		// free KEYSERVERSTRUCT
		clFree ((VOID*)(tlI.lParam));

		// delete selected item
		tlI.hItem = hTSelected;
		TreeList_DeleteItem (hWndTree, &tlI);

		hTSelected = NULL;
		iSelectedType = IDX_NONE;
		bSelectedRoot = FALSE;

		// finish up
		InvalidateRect (hWndTree, NULL, TRUE);
		EnableWindow (GetDlgItem (hWndParent, IDC_REMOVEKEYSERVER), 
							FALSE);
		EnableWindow (GetDlgItem (hWndParent, IDC_EDITKEYSERVER),
							FALSE);
		EnableWindow (GetDlgItem (hWndParent, IDC_SETASROOT),
							FALSE);
		--uNumberOfServers;
	}
	else 
		SetFocus (hWndTree);
}


//	_____________________________________________________
//
//  set selected server as root server

VOID
CLSetKeyserverAsRoot (HWND hWndParent, HWND hWndTree)
{
	TL_TREEITEM			tlI;
	PKEYSERVERSTRUCT	pkss;

	sRemoveAllRoots (hWndTree);

	tlI.hItem = hTSelected;
	tlI.mask = TLIF_PARAM;
	TreeList_GetItem (hWndTree, &tlI);
	pkss = (PKEYSERVERSTRUCT)tlI.lParam;

	pkss->bRoot = TRUE;

	tlI.hItem = hTSelected;
	tlI.stateMask = TLIS_BOLD;
	tlI.state = TLIS_BOLD;
	tlI.mask = TLIF_STATE;
	TreeList_SetItem (hWndTree, &tlI);

	EnableWindow (GetDlgItem (hWndParent, IDC_SETASROOT), FALSE);
	SetFocus (hWndTree);
}


//	_____________________________________________________
//
//  process treelist notification

static VOID
sUpdateSelectionFlags (HWND hWndTree)
{
	TL_TREEITEM			tlI;

	tlI.hItem = hTSelected;
	tlI.mask = TLIF_IMAGE | TLIF_STATE | TLIF_NEXTHANDLE;
	TreeList_GetItem (hWndTree, &tlI);
	iSelectedType = tlI.iImage;
	bSelectedRoot = tlI.state & TLIS_BOLD;
	bLastInList = !tlI.hItem;

	tlI.hItem = hTSelected;
	tlI.mask = TLIF_PREVHANDLE;
	TreeList_GetItem (hWndTree, &tlI);
	bFirstInList = !tlI.hItem;
}


//	_____________________________________________________
//
//  move selected keyserver up by reinserting item

VOID
CLMoveKeyserverUp (HWND hWndParent, HWND hWndTree)
{
	TL_TREEITEM			tlI;
	TL_INSERTSTRUCT		tlIns;

	tlI.hItem = hTSelected;
	tlI.mask = TLIF_PREVHANDLE;
	TreeList_GetItem (hWndTree, &tlI);

	if (tlI.hItem)
	{
		tlI.mask = TLIF_PREVHANDLE;
		TreeList_GetItem (hWndTree, &tlI);

		if (tlI.hItem)
			tlIns.hInsertAfter = tlI.hItem;
		else
			tlIns.hInsertAfter = TLI_FIRST;

		tlI.hItem = hTSelected;
		tlIns.item = tlI;
		tlIns.hParent = NULL;
		TreeList_ReInsertItem (hWndTree, &tlIns);

		InvalidateRect (hWndTree, NULL, FALSE);
		sUpdateSelectionFlags (hWndTree);
		EnableWindow (GetDlgItem (hWndParent, IDC_MOVEUP), !bFirstInList);
		EnableWindow (GetDlgItem (hWndParent, IDC_MOVEDOWN), !bLastInList);
	}
}


//	_____________________________________________________
//
//  move selected keyserver down by reinserting item

VOID
CLMoveKeyserverDown (HWND hWndParent, HWND hWndTree)
{
	TL_TREEITEM			tlI;
	TL_INSERTSTRUCT		tlIns;

	tlI.hItem = hTSelected;
	tlI.mask = TLIF_NEXTHANDLE;
	TreeList_GetItem (hWndTree, &tlI);

	if (tlI.hItem)
	{
		tlIns.hInsertAfter = tlI.hItem;
		tlI.hItem = hTSelected;
		tlIns.item = tlI;
		tlIns.hParent = NULL;
		TreeList_ReInsertItem (hWndTree, &tlIns);

		InvalidateRect (hWndTree, NULL, FALSE);
		sUpdateSelectionFlags (hWndTree);
		EnableWindow (GetDlgItem (hWndParent, IDC_MOVEUP), !bFirstInList);
		EnableWindow (GetDlgItem (hWndParent, IDC_MOVEDOWN), !bLastInList);
	}
}


//	_____________________________________________________
//
//  process treelist notification

static VOID
sServerContextMenu (HWND hwnd, INT iX, INT iY)
{
	HMENU	hMC;
	HMENU	hMenuTrackPopup;

	hMC = LoadMenu (g_hInst, MAKEINTRESOURCE (IDR_MENUEDITSERVER));
	if (iSelectedType == IDX_SERVER) 
	{
		EnableMenuItem (hMC, IDM_EDITSERVER, MF_BYCOMMAND|MF_ENABLED);

		if (uNumberOfServers > 1)
			EnableMenuItem (hMC, IDM_REMOVESERVER, MF_BYCOMMAND|MF_ENABLED);

		if (!bSelectedRoot)
			EnableMenuItem (hMC, IDM_SETASROOT, MF_BYCOMMAND|MF_ENABLED);

		if (!bFirstInList)
			EnableMenuItem (hMC, IDM_MOVEUP, MF_BYCOMMAND|MF_ENABLED);

		if (!bLastInList)
			EnableMenuItem (hMC, IDM_MOVEDOWN, MF_BYCOMMAND|MF_ENABLED);
	}

	hMenuTrackPopup = GetSubMenu (hMC, 0);

	TrackPopupMenu (hMenuTrackPopup, TPM_LEFTALIGN | TPM_RIGHTBUTTON,
					iX, iY, 0, hwnd, NULL);

	DestroyMenu (hMC);
}


//	_____________________________________________________
//
//  process treelist notification

INT
CLProcessKeyserverTreeList (HWND hWndParent, HWND hWndTree, 
							WPARAM wParam, LPARAM lParam)
{
	TL_TREEITEM			tlI;
	TL_LISTITEM			tlL;
	BOOL				bEnable;
	PKEYSERVERSTRUCT	pkss;

	switch (((LPNM_TREELIST)lParam)->hdr.code) {

	case TLN_SELCHANGED :
		hTSelected = ((LPNM_TREELIST)lParam)->itemNew.hItem;

		if (!hTSelected) {
			iSelectedType = IDX_NONE;
			bSelectedRoot = FALSE;
			EnableWindow (GetDlgItem (hWndParent, IDC_EDITKEYSERVER),
								FALSE);
			EnableWindow (GetDlgItem (hWndParent, IDC_REMOVEKEYSERVER), 
								FALSE);
			EnableWindow (GetDlgItem (hWndParent, IDC_SETASROOT), 
								FALSE);
			EnableWindow (GetDlgItem (hWndParent, IDC_MOVEUP), 
								FALSE);
			EnableWindow (GetDlgItem (hWndParent, IDC_MOVEDOWN), 
								FALSE);
			break;
		}

		sUpdateSelectionFlags (hWndTree);

		switch (iSelectedType) {
		case IDX_SERVER :
			EnableWindow (GetDlgItem (hWndParent, IDC_EDITKEYSERVER),
								TRUE);

			if (uNumberOfServers > 1)
				bEnable = TRUE;
			else 
				bEnable = FALSE;
			EnableWindow (GetDlgItem (hWndParent, IDC_REMOVEKEYSERVER), 
								bEnable);

			if (bSelectedRoot)
				bEnable = FALSE;
			else
				bEnable = TRUE;
			EnableWindow (GetDlgItem (hWndParent, IDC_SETASROOT), bEnable);

			EnableWindow (GetDlgItem (hWndParent, IDC_MOVEUP), !bFirstInList);
			EnableWindow (GetDlgItem (hWndParent, IDC_MOVEDOWN), !bLastInList);

			break;
		}
		break;

	case TLN_LISTITEMCLICKED : 
		tlI.hItem = hTSelected;
		tlI.mask = TLIF_PARAM;
		TreeList_GetItem (hWndTree, &tlI);

		pkss = (PKEYSERVERSTRUCT)(tlI.lParam);
		pkss->bListed = !pkss->bListed;

		tlL.hItem = hTSelected;
		tlL.iSubItem = 2;
		tlL.mask = TLIF_DATAVALUE;

		if (pkss->bListed) 
			tlL.lDataValue = IDX_CHECKED;
		else 
			tlL.lDataValue = IDX_UNCHECKED;

		TreeList_SetListItem (hWndTree, &tlL, FALSE);
		break;

	case TLN_ITEMDBLCLICKED :
		CLEditKeyserver (hWndParent, hWndTree);
		break;

	case TLN_CONTEXTMENU :
		sUpdateSelectionFlags (hWndTree);
		sServerContextMenu (hWndParent,
					((LPNM_TREELIST)lParam)->ptDrag.x,
					((LPNM_TREELIST)lParam)->ptDrag.y);
		break;

	}
	return 0;
}

//	_____________________________________________________
//
//  traverse treelist and save contents to preferences

INT
CLSaveKeyserverPrefs (PGPPrefRef PrefRef, HWND hWndParent, HWND hWndTree)
{
	TL_TREEITEM			tlI;
	HTLITEM				hTServer;
	PGPKeyServerEntry*	keyserverList;
	INT					iServer, iServerCount;
	PKEYSERVERSTRUCT	pkss;

	// count number of servers
	iServerCount = 0;
	hTServer = TreeList_GetFirstItem (hWndTree);
	while (hTServer) {
		++iServerCount;
		tlI.hItem = hTServer;
		tlI.mask = TLIF_NEXTHANDLE;
		TreeList_GetItem (hWndTree, &tlI);
		hTServer = tlI.hItem;
	}

	keyserverList = clAlloc (iServerCount * sizeof(PGPKeyServerEntry));
	if (!keyserverList) return kPGPError_OutOfMemory;

	iServer = 0;
	hTServer = TreeList_GetFirstItem (hWndTree);
	while (hTServer) {
		// get server structure
		tlI.hItem = hTServer;
		tlI.mask = TLIF_PARAM | TLIF_NEXTHANDLE;
		TreeList_GetItem (hWndTree, &tlI);

		pkss = (PKEYSERVERSTRUCT)(tlI.lParam);

		keyserverList[iServer].protocol = pkss->iType;
		lstrcpy (keyserverList[iServer].domain, pkss->szDomain);
		lstrcpy (keyserverList[iServer].serverDNS, pkss->szServer);
		keyserverList[iServer].serverPort = pkss->iPort;

		// authentication key
		if (pkss->authAlg != kPGPPublicKeyAlgorithm_Invalid) {
			keyserverList[iServer].authAlg = pkss->authAlg;
			lstrcpy (keyserverList[iServer].authKeyIDString, 
						pkss->szKeyIDAuth);
		}
		else {
			keyserverList[iServer].authAlg = kPGPPublicKeyAlgorithm_Invalid;
			keyserverList[iServer].authKeyIDString[0] = '\0';
		}

		// listed flag
		keyserverList[iServer].flags = 0;
		if (pkss->bListed) 
			keyserverList[iServer].flags |= kKeyServerListed;
		if (pkss->bRoot) 
			keyserverList[iServer].flags |= kKeyServerIsRoot;

		// step to next server
		++iServer;
		hTServer = tlI.hItem;
	}

	// done, set preferences
	PGPSetKeyServerPrefs (PrefRef, keyserverList, iServerCount);

	clFree (keyserverList);

	return 0;
}


⌨️ 快捷键说明

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