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

📄 cpgpkeypicker.cpp

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

        $Id: CPGPKeyPicker.cpp,v 1.8 2002/08/06 20:09:23 dallen Exp $
____________________________________________________________________________*/

#include "pgpClassesConfig.h"

#include "CMessageBox.h"
#include "CPGPclPrefs.h"
#include "CPGPdiskEngine.h"
#include "CPGPKeyDB.h"
#include "UCommonStrings.h"

#include "CHelpShower.h"
#include "CPGPKeyPicker.h"
#include "PGPdiskHelp.h"
#include "Resource.h"

_USING_PGP

// Constants

_UNNAMED_BEGIN

DWORD	PGPKeyPickerDlgHelpIDs[]	= 
{
	IDC_PICK_TEXT,		IDH_PGPDISKUI_PICKKEYDLG_PUBKEYSVIEW, 
	IDC_KEYS_VIEW,		IDH_PGPDISKUI_PICKKEYDLG_PUBKEYSVIEW, 
	IDOK,				IDH_PGPDISKUI_PICKKEYDLG_OK, 
	IDCANCEL,			IDH_PGPDISKUI_PICKKEYDLG_CANCEL, 
	0,					0
};

_UNNAMED_END


// Class CPGPKeyPicker public member functions

CPGPKeyPicker::CPGPKeyPicker() : 
	mPContext(NULL), mPInKeys(NULL), mPPickedKeys(NULL)
{
}

CPGPKeyPicker::~CPGPKeyPicker()
{
}

PGPUInt16 
CPGPKeyPicker::GetDialogId() const
{
	return IDD_PICKKEY_DLG;
}

void 
CPGPKeyPicker::Display(
	const CPGPdiskContext&	context, 
	HWND					parent, 
	const char				*title, 
	const char				*message, 
	const CPGPKeySet&		inKeys, 
	CPGPKeySet&				pickedKeys, 
	PGPBoolean				singleSelect)
{
	pgpAssert(IsWindow(parent));
	pgpAssertStrValid(title);
	pgpAssertStrValid(message);

	mPContext		= &context;
	mPInKeys		= &inKeys;
	mPPickedKeys	= &pickedKeys;

	mTitle = title;
	mMessage = message;

	mSingleSelect = singleSelect;

	CreateModal(parent);
}

void 
CPGPKeyPicker::InitControls()
{
	// Initialize keys view.
	CPGPclPrefs	clPrefs(mPContext->PGPclPrefs());

	mKeysView.Initialize(mPContext, mSingleSelect, 
		clPrefs.GetBoolean(kPGPPrefMarginalIsInvalid), 
		clPrefs.GetBoolean(kPGPPrefDisplayMarginalValidity));

	// Fill keys view.
	CPGPKeyList	keyList(*mPInKeys, kPGPKeyOrdering_Any);
	CPGPKeyIter	keyIter(keyList);
	CPGPKey		key;

	while (keyIter.Next(key))
	{
		try
		{
			CPGPKey	subKey;
			keyIter.NextSubKey(subKey);

			mKeysView.AddKey(key, subKey);
		}
		catch (CComboError&)
		{
			pgpAssert(FALSE);
		}
	}
}

void 
CPGPKeyPicker::InitDialogText()
{
	SetWindowText(mTitle);
	mPickText.SetWindowText(mMessage);
}

void 
CPGPKeyPicker::OnOk()
{
	// Get the key(s) the user selected.
	CArray<CPublicKeysView::PubKeyItem>	items;
	PGPUInt32							numItems;

	mKeysView.GetSelectedItems(items, numItems);

	if (numItems == 0)
	{
		using namespace UCommonStrings;

		CMessageBox	messageBox;
		messageBox.Display(Get(kTellNoPubKeySelected), 
			Get(kPGPKeyPickerMsgBoxTitle), Handle());

		return;
	}

	pgpAssert(!mSingleSelect || (numItems == 1));

	for (PGPUInt32 i = 0; i < numItems; i++)
	{
		mPPickedKeys->Add(items[i].key);
	}

	mKeysView.SortOnColumn(0);

	CDialog::OnOk();
}

void 
CPGPKeyPicker::OnContextMenu(HWND menuWnd, CPoint coords)
{
	CHelpShower::ShowContextMenu(menuWnd, PGPKeyPickerDlgHelpIDs);
}

void 
CPGPKeyPicker::OnHelp(HELPINFO *pInfo)
{
	CHelpShower::ShowForControl(static_cast<HWND>(pInfo->hItemHandle), 
		PGPKeyPickerDlgHelpIDs);
}

BOOL 
CPGPKeyPicker::OnInitDialog(HWND focusCtrl)
{
	CDialog::OnInitDialog(focusCtrl);

	mKeysView.Subclass(GetDlgItem(IDC_KEYS_VIEW));
	mPickText.Subclass(GetDlgItem(IDC_PICK_TEXT));

	InitControls();
	InitDialogText();

	mKeysView.SetFocus();

	Center();
	SetForegroundWindow();

	return FALSE;
}

PGPUInt32 
CPGPKeyPicker::OnNotify(PGPUInt16 ctrlId, LPNMHDR pNMHDR)
{
	switch (pNMHDR->code)
	{
	case NM_DBLCLK:
	{
		NMITEMACTIVATE	*pNMIA	= reinterpret_cast<NMITEMACTIVATE *>(pNMHDR);

		if (mKeysView.GetSelectedCount() > 0)
			OnOk();
	}
	break;

	default:
		return CWindow::OnNotify(ctrlId, pNMHDR);
	}

	return 0;
}

⌨️ 快捷键说明

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