climport.c
来自「PGP8.0源码 请认真阅读您的文件包然后写出其具体功能」· C语言 代码 · 共 627 行 · 第 1/2 页
C
627 行
/*____________________________________________________________________________
Copyright (C) 2002 PGP Corporation
All rights reserved.
CLimport.c - selective import dialog
$Id: CLimport.c,v 1.17 2002/08/06 20:09:19 dallen Exp $
____________________________________________________________________________*/
#include "pgpPFLConfig.h"
// project header files
#include "PGPclx.h"
#include "PGPklx.h"
// system header files
#include <zmouse.h>
// External globals
extern HINSTANCE g_hInst;
extern UINT g_uMouseWheelMessage;
typedef struct {
PGPContextRef context;
PGPtlsContextRef tlscontext;
LPSTR pszPrompt;
PGPKeySetRef keysetToDisplay;
PGPKeyDBRef keydbToAddTo;
PGPKeySetRef keysetSelected;
PGPKeySetRef keysetAdded;
HKEYLIST hKL;
PGPclKeyListConfig klConfig;
UINT uFlags;
HWND hwndTree;
INT iyOffset;
INT iyTop;
} QUERYSTRUCT;
#define IDC_QUERYTREELIST 0x0101
#define BUTTONOFFSETY 10
#define DIALOGMINWIDTH 400
#define BOTTOM_BUTTON_OFFSET 10
#define BUTTON_SPACING 8
#define HOR_OFFSET 4
// local globals
static DWORD aIds[] = { // Help IDs
IDOK, IDH_PGPCL_IMPORT,
IDC_SELECTALL, IDH_PGPCL_IMPORTSELALL,
IDC_UNSELECTALL, IDH_PGPCL_IMPORTUNSELALL,
IDC_QUERYTREELIST, IDH_PGPCL_IMPORTLIST,
0,0
};
// ___________________________________________________
//
// Put up appropriate context menu on basis of selection flags.
// Called in response to right mouse click.
//
// hWnd = handle of parent window
// uSelFlags = bits indicate what types of objects are selected
// x, y = mouse position when right button clicked (screen coords)
static VOID
sQueryContextMenu (
HWND hWnd,
HKEYLIST hKL,
UINT uSelFlags,
INT x,
INT y)
{
PKEYLIST pKL = (PKEYLIST)hKL;
HMENU hMC;
HMENU hMenuTrackPopup;
switch (uSelFlags) {
case kPGPclKeyList_Key :
hMC = LoadMenu (g_hInst, MAKEINTRESOURCE (IDR_MENUIMPORT));
break;
default :
hMC = NULL;
break;
}
if (!hMC)
return;
hMenuTrackPopup = GetSubMenu (hMC, 0);
if (KLMultipleSelected (pKL))
{
EnableMenuItem (hMenuTrackPopup, IDM_KEYPROPERTIES,
MF_BYCOMMAND|MF_GRAYED);
}
TrackPopupMenu (hMenuTrackPopup, TPM_LEFTALIGN|TPM_RIGHTBUTTON,
x, y, 0, hWnd, NULL);
DestroyMenu (hMC);
}
// ____________________________________
//
// get number of wheel scroll lines and pass to treelist controls
static VOID
sUpdateWheelScrollLines (QUERYSTRUCT* pqs)
{
UINT uLines;
if (!SystemParametersInfo (SPI_GETWHEELSCROLLLINES, 0, &uLines, 0))
{
HWND hwnd = NULL;
UINT umsg = 0;
umsg = RegisterWindowMessage (MSH_SCROLL_LINES);
hwnd = FindWindow (MSH_WHEELMODULE_CLASS, MSH_WHEELMODULE_TITLE);
if (hwnd && umsg)
uLines = (UINT)SendMessage (hwnd, umsg, 0, 0);
}
TreeList_SetWheelScrollLines (pqs->hwndTree, uLines);
}
// ____________________________________
//
// we're resizing -- move all the buttons
static VOID
sMoveButtons (
HWND hwnd,
WORD wXsize,
WORD wYsize)
{
HDWP hdwp;
INT iButtonWidth, iButtonHeight;
RECT rc;
GetWindowRect (GetDlgItem (hwnd, IDOK), &rc);
iButtonWidth = rc.right - rc.left;
iButtonHeight = rc.bottom - rc.top;
hdwp = BeginDeferWindowPos (4);
// position the "cancel" button
DeferWindowPos (hdwp,
GetDlgItem (hwnd, IDCANCEL), NULL,
wXsize - HOR_OFFSET - iButtonWidth,
wYsize - BOTTOM_BUTTON_OFFSET - iButtonHeight,
0, 0, SWP_NOSIZE|SWP_NOZORDER);
// position the "OK" button
DeferWindowPos (hdwp,
GetDlgItem (hwnd, IDOK), NULL,
wXsize - HOR_OFFSET - BUTTON_SPACING - 2*iButtonWidth,
wYsize - BOTTOM_BUTTON_OFFSET - iButtonHeight,
0, 0, SWP_NOSIZE|SWP_NOZORDER);
// position the "unselectall" button
DeferWindowPos (hdwp,
GetDlgItem (hwnd, IDC_UNSELECTALL), NULL,
wXsize - HOR_OFFSET - 2*BUTTON_SPACING - 3*iButtonWidth,
wYsize - BOTTOM_BUTTON_OFFSET - iButtonHeight,
0, 0, SWP_NOSIZE|SWP_NOZORDER);
// position the "selectall" button
DeferWindowPos (hdwp,
GetDlgItem (hwnd, IDC_SELECTALL), NULL,
wXsize - HOR_OFFSET - 3*BUTTON_SPACING - 4*iButtonWidth,
wYsize - BOTTOM_BUTTON_OFFSET - iButtonHeight,
0, 0, SWP_NOSIZE|SWP_NOZORDER);
EndDeferWindowPos(hdwp);
}
// ___________________________________________________
//
// Selective import dialog message procedure
static BOOL CALLBACK
sImportDlgProc (
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
QUERYSTRUCT* pqs;
switch (uMsg) {
case WM_INITDIALOG :
{
PGPPrefRef prefref = kInvalidPGPPrefRef;
RECT rc;
INT iy;
POINT pt;
HWND hwndControl;
PGPBoolean b;
CHAR sz[16];
SetWindowLong (hwnd, GWL_USERDATA, lParam);
pqs = (QUERYSTRUCT*)lParam;
// change "OK" button to "Import"
LoadString (g_hInst, IDS_IMPORT, sz, sizeof(sz));
SetDlgItemText (hwnd, IDOK, sz);
// set prompt text
hwndControl = GetDlgItem (hwnd, IDC_PROMPT);
SetWindowText (hwndControl, pqs->pszPrompt);
// create keymanager window
GetWindowRect (hwndControl, &rc);
pt.x = rc.left;
pt.y = rc.bottom;
ScreenToClient (hwnd, &pt);
pqs->iyTop = pt.y;
hwndControl = GetDlgItem (hwnd, IDC_SELECTALL);
GetWindowRect (hwndControl, &rc);
pt.x = rc.left;
pt.y = rc.top;
ScreenToClient (hwnd, &pt);
iy = pt.y;
GetClientRect (hwnd, &rc);
pqs->iyOffset = rc.bottom - (iy - BUTTONOFFSETY) + pqs->iyTop;
pqs->hKL = PGPclKeyListCreate (pqs->context, pqs->tlscontext,
hwnd, IDC_QUERYTREELIST, 0, pqs->iyTop,
rc.right-rc.left, rc.bottom-pqs->iyOffset,
kPGPclKeyList_ShowSelection, &pqs->hwndTree);
// configure key manager window
pqs->klConfig.keyserver.protocol = kPGPKeyServerProtocol_Invalid;
pqs->klConfig.hwndStatusBar = NULL;
pqs->klConfig.uShowColumns = 0;
pqs->klConfig.uOptions =
kPGPclKeyList_SelectKeysOnly|kPGPclKeyList_ReadOnly;
// get those options which are based on prefs
if (IsPGPError (PGPclPeekClientLibPrefRefs (&prefref, NULL)))
EndDialog (hwnd, 0);
PGPGetPrefBoolean (prefref, kPGPPrefDisplayMarginalValidity, &b);
if (!b)
pqs->klConfig.uOptions |= kPGPclKeyList_GreenDotMode;
PGPGetPrefBoolean (prefref, kPGPPrefMarginalIsInvalid, &b);
if (b)
pqs->klConfig.uOptions |= kPGPclKeyList_MarginalIsInvalid;
pqs->klConfig.uMask = kPGPclKeyList_ConfigureAll;
PGPclKeyListConfigure (pqs->hKL, &pqs->klConfig);
// initialize keymanager
PGPclKeyListLoadKeys (pqs->hKL,
pqs->keydbToAddTo,
pqs->keysetToDisplay);
PGPclKeyListSetTree (pqs->hKL,
kPGPclSelectAll, kInvalidPGPKeyDBObjRef);
// initialize wheel scrolling
sUpdateWheelScrollLines (pqs);
// position buttons
GetClientRect (hwnd, &rc);
sMoveButtons (hwnd, (WORD)rc.right, (WORD)rc.bottom);
// post message to sync keysets
PostMessage (hwnd, WM_APP, 0, 0);
return FALSE;
}
case WM_APP :
{
HCURSOR hCursorOld;
// this syncs the import keyset with the main one
pqs = (QUERYSTRUCT*)GetWindowLong (hwnd, GWL_USERDATA);
hCursorOld = SetCursor (LoadCursor (NULL, IDC_WAIT));
PGPCheckKeyRingSigs (pqs->keysetToDisplay,
pqs->keydbToAddTo, TRUE, NULL, NULL);
PGPclKeyListReloadKeys (pqs->hKL, FALSE);
PGPclKeyListSetTree (pqs->hKL,
kPGPclSelectAll, kInvalidPGPKeyDBObjRef);
SetCursor (hCursorOld);
SetForegroundWindow (hwnd);
EnableWindow (GetDlgItem (hwnd, IDOK), TRUE);
SetFocus (pqs->hwndTree);
break;
}
case WM_ACTIVATE :
pqs = (QUERYSTRUCT*)GetWindowLong (hwnd, GWL_USERDATA);
SetFocus (pqs->hwndTree);
break;
case WM_SIZING :
{
LPRECT prc = (LPRECT)lParam;
switch (wParam) {
case WMSZ_TOPLEFT :
case WMSZ_LEFT :
case WMSZ_BOTTOMLEFT :
if ((prc->right - prc->left) < DIALOGMINWIDTH)
prc->left = prc->right - DIALOGMINWIDTH;
break;
case WMSZ_TOPRIGHT :
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?