📄 kmtree.c
字号:
/*____________________________________________________________________________
Copyright (C) 1998 Network Associates, Inc.
All rights reserved.
KMTree.c - handle creating and filling TreeList control
$Id: KMTree.c,v 1.37 1999/04/01 03:36:50 pbj Exp $
____________________________________________________________________________*/
#include "pgpPFLConfig.h"
// project header files
#include "pgpkmx.h"
// constant defitions
#define BITMAP_WIDTH 16
#define BITMAP_HEIGHT 16
typedef struct {
FARPROC lpfnCallback;
HWND hWndTree;
} EXPANDCOLLAPSESTRUCT;
typedef struct {
FARPROC lpfnCallback;
HWND hWndTree;
PGPKeySetRef keysetSelected;
} SELECTEDSTRUCT;
typedef struct _USERVALSTRUCT {
struct _USERVALSTRUCT* next;
PKEYMAN pKM;
LONG lValue;
} USERVALSTRUCT;
// external globals
extern HINSTANCE g_hInst;
// _______________________________________________
//
// get key user value list item
PGPError
KMGetKeyUserVal (PKEYMAN pKM, PGPKeyRef Key, LONG* lValue)
{
USERVALSTRUCT* puvs;
PGPError err;
err = PGPGetKeyUserVal (Key, &puvs);
if (err) return err;
// there is an existing linked list
if (puvs) {
// search for the element inserted by this KM
do {
if (puvs->pKM == pKM) {
*lValue = puvs->lValue;
return kPGPError_NoErr;
}
puvs = puvs->next;
} while (puvs);
// no element in list inserted by this KM
*lValue = 0;
}
// no user value
else
*lValue = 0;
return kPGPError_NoErr;
}
// _______________________________________________
//
// get userid user value list item
PGPError
KMGetUserIDUserVal (PKEYMAN pKM, PGPUserIDRef UID, LONG* lValue)
{
USERVALSTRUCT* puvs;
PGPError err;
err = PGPGetUserIDUserVal (UID, &puvs);
if (err) return err;
// there is an existing linked list
if (puvs) {
// search for the element inserted by this KM
do {
if (puvs->pKM == pKM) {
*lValue = puvs->lValue;
return kPGPError_NoErr;
}
puvs = puvs->next;
} while (puvs);
// no element in list inserted by this KM
*lValue = 0;
}
// no user value
else
*lValue = 0;
return kPGPError_NoErr;
}
// _______________________________________________
//
// get cert user value list item
PGPError
KMGetCertUserVal (PKEYMAN pKM, PGPSigRef Cert, LONG* lValue)
{
USERVALSTRUCT* puvs;
PGPError err;
err = PGPGetSigUserVal (Cert, &puvs);
if (err) return err;
// there is an existing linked list
if (puvs) {
// search for the element inserted by this KM
do {
if (puvs->pKM == pKM) {
*lValue = puvs->lValue;
return kPGPError_NoErr;
}
puvs = puvs->next;
} while (puvs);
// no element in list inserted by this KM
*lValue = 0;
}
// no user value
else
*lValue = 0;
return kPGPError_NoErr;
}
// _______________________________________________
//
// set key user value list item
PGPError
KMSetKeyUserVal (PKEYMAN pKM, PGPKeyRef Key, LONG lValue)
{
USERVALSTRUCT* puvs;
USERVALSTRUCT* puvsPrev;
PGPError err;
err = PGPGetKeyUserVal (Key, &puvs);
if (err) return err;
// there is an existing linked list
if (puvs) {
puvsPrev = NULL;
// search for the element inserted by this KM
do {
if (puvs->pKM == pKM) {
// if value is zero, remove item from list
if (!lValue) {
if (!puvsPrev)
PGPSetKeyUserVal (Key, puvs->next);
else
puvsPrev->next = puvs->next;
KMFree (puvs);
}
// otherwise set the list element to the desired value
else
puvs->lValue = lValue;
return kPGPError_NoErr;
}
puvsPrev = puvs;
puvs = puvs->next;
} while (puvs);
// no element in list inserted by this KM, create and append one
if (!lValue) return kPGPError_NoErr;
puvs = KMAlloc (sizeof(USERVALSTRUCT));
puvsPrev->next = puvs;
}
// no user value, create one
else {
if (!lValue) return kPGPError_NoErr;
puvs = KMAlloc (sizeof(USERVALSTRUCT));
PGPSetKeyUserVal (Key, puvs);
}
// set contents of linked list element
puvs->pKM = pKM;
puvs->next = NULL;
puvs->lValue = lValue;
return kPGPError_NoErr;
}
// _______________________________________________
//
// set userid user value list item
PGPError
KMSetUserIDUserVal (PKEYMAN pKM, PGPUserIDRef UID, LONG lValue)
{
USERVALSTRUCT* puvs;
USERVALSTRUCT* puvsPrev;
PGPError err;
err = PGPGetUserIDUserVal (UID, &puvs);
if (err) return err;
// there is an existing linked list
if (puvs) {
puvsPrev = NULL;
// search for the element inserted by this KM
do {
if (puvs->pKM == pKM) {
// if value is zero, remove item from list
if (!lValue) {
if (!puvsPrev)
PGPSetUserIDUserVal (UID, puvs->next);
else
puvsPrev->next = puvs->next;
KMFree (puvs);
}
// otherwise set the list element to the desired value
else
puvs->lValue = lValue;
return kPGPError_NoErr;
}
puvsPrev = puvs;
puvs = puvs->next;
} while (puvs);
// no element in list inserted by this KM, create and append one
if (!lValue) return kPGPError_NoErr;
puvs = KMAlloc (sizeof(USERVALSTRUCT));
puvsPrev->next = puvs;
}
// no user value, create one
else {
if (!lValue) return kPGPError_NoErr;
puvs = KMAlloc (sizeof(USERVALSTRUCT));
PGPSetUserIDUserVal (UID, puvs);
}
// set contents of linked list element
puvs->pKM = pKM;
puvs->next = NULL;
puvs->lValue = lValue;
return kPGPError_NoErr;
}
// _______________________________________________
//
// set cert user value list item
PGPError
KMSetCertUserVal (PKEYMAN pKM, PGPSigRef Cert, LONG lValue)
{
USERVALSTRUCT* puvs;
USERVALSTRUCT* puvsPrev;
PGPError err;
err = PGPGetSigUserVal (Cert, &puvs);
if (err) return err;
// there is an existing linked list
if (puvs) {
puvsPrev = NULL;
// search for the element inserted by this KM
do {
if (puvs->pKM == pKM) {
// if value is zero, remove item from list
if (!lValue) {
if (!puvsPrev)
PGPSetSigUserVal (Cert, puvs->next);
else
puvsPrev->next = puvs->next;
KMFree (puvs);
}
// otherwise set the list element to the desired value
else
puvs->lValue = lValue;
return kPGPError_NoErr;
}
puvsPrev = puvs;
puvs = puvs->next;
} while (puvs);
// no element in list inserted by this KM, create and append one
if (!lValue) return kPGPError_NoErr;
puvs = KMAlloc (sizeof(USERVALSTRUCT));
puvsPrev->next = puvs;
}
// no user value, create one
else {
if (!lValue) return kPGPError_NoErr;
puvs = KMAlloc (sizeof(USERVALSTRUCT));
PGPSetSigUserVal (Cert, puvs);
}
// set contents of linked list element
puvs->pKM = pKM;
puvs->next = NULL;
puvs->lValue = lValue;
return kPGPError_NoErr;
}
// _______________________________________________
//
// Create TreeList Window
HKEYMAN PGPkmExport
PGPkmCreateKeyManagerEx (
PGPContextRef Context,
PGPtlsContextRef tlsContext,
HWND hWndParent,
INT iID,
HWNDLISTPROC lpfnHwndListFunc,
INT x,
INT y,
INT nWidth,
INT nHeight,
UINT uFlags)
{
HBITMAP hBmp; // handle to a bitmap
PKEYMAN pKM;
HDC hDC;
INT iNumBits;
DWORD dwStyle;
pKM = KMAlloc (sizeof (KEYMAN));
if (!pKM) return NULL;
memset (pKM, 0x00, sizeof (KEYMAN));
pKM->hWndParent = hWndParent;
pKM->hWndTree = NULL;
pKM->lpfnHwndListFunc = lpfnHwndListFunc;
pKM->iID = iID;
pKM->hRequestMutex = CreateMutex (NULL, FALSE, NULL);
pKM->hAccessMutex = CreateMutex (NULL, TRUE, NULL);
pKM->hIml = NULL;
pKM->pDropTarget = NULL; //pointer to DropTarget object
lstrcpy (pKM->szHelpFile, ""); //string containing name of help file
ZeroMemory (&pKM->keyserver, sizeof(PGPKeyServerEntry));
pKM->Context = Context; //PGP context
pKM->tlsContext = tlsContext; //TLS context
pKM->KeySetDisp = NULL; //displayed keyset
pKM->KeySetMain = NULL; //main keyset
pKM->bMainKeySet = FALSE;
pKM->ulOptionFlags = 0;
pKM->ulDisableActions = 0;
pKM->ulHideColumns = 0;
pKM->ulShowColumns = 0;
pKM->bMultipleSelected = FALSE;
pKM->uSelectedFlags = 0;
pKM->iFocusedItemType = 0;
pKM->iFocusedObjectType = 0;
pKM->hFocusedItem = NULL;
pKM->pFocusedObject = NULL;
pKM->iValidityThreshold = KM_VALIDITY_MARGINAL;
pKM->iNumberSheets = 0;
pKM->pSplitKeyDialogList = NULL;
KMGetColumnPreferences (pKM);
// Create the tree view window.
dwStyle = WS_VISIBLE | WS_CHILD | WS_BORDER | WS_TABSTOP | WS_GROUP |
TLS_HASBUTTONS | TLS_HASLINES | TLS_AUTOSCROLL |
TLS_PROMISCUOUS | TLS_DRAGABLEHEADERS;
if (uFlags & PGPKM_SINGLESELECT)
dwStyle |= TLS_SINGLESELECT;
if (uFlags & PGPKM_SHOWSELECTION)
dwStyle |= TLS_SHOWSELECTIONALWAYS;
pKM->hWndTree = CreateWindowEx (WS_EX_CLIENTEDGE, WC_TREELIST, "",
dwStyle, x, y, nWidth, nHeight,
hWndParent, (HMENU)iID, g_hInst, NULL);
if (pKM->hWndTree == NULL) return NULL;
// Initialize the tree view window.
// First create imagelist and load the appropriate bitmaps
// based on current display capabilities.
hDC = GetDC (NULL); // DC for desktop
iNumBits = GetDeviceCaps (hDC, BITSPIXEL) * GetDeviceCaps (hDC, PLANES);
ReleaseDC (NULL, hDC);
if (iNumBits <= 8) {
pKM->hIml = ImageList_Create (16, 16, ILC_COLOR|ILC_MASK,
NUM_BITMAPS, 0);
hBmp = LoadBitmap (g_hInst, MAKEINTRESOURCE (IDB_IMAGES4BIT));
ImageList_AddMasked (pKM->hIml, hBmp, RGB(255, 0, 255));
DeleteObject (hBmp);
}
else {
pKM->hIml = ImageList_Create (16, 16, ILC_COLOR24|ILC_MASK,
NUM_BITMAPS, 0);
hBmp = LoadBitmap (g_hInst, MAKEINTRESOURCE (IDB_IMAGES24BIT));
ImageList_AddMasked (pKM->hIml, hBmp, RGB(255, 0, 255));
DeleteObject (hBmp);
}
// Associate the image list with the tree view control.
TreeList_SetImageList (pKM->hWndTree, pKM->hIml);
KMSetFocus (pKM, NULL, FALSE);
pKM->pDropTarget = KMCreateDropTarget (pKM->hWndTree, (VOID*)pKM, FALSE);
CoLockObjectExternal ((IUnknown*)pKM->pDropTarget, TRUE, TRUE);
RegisterDragDrop (pKM->hWndTree, pKM->pDropTarget);
KMEnableDropTarget (pKM->pDropTarget, FALSE);
return (HKEYMAN)pKM;
}
// _______________________________________________
//
// Create TreeList Window - old version
HKEYMAN PGPkmExport
PGPkmCreateKeyManager (
PGPContextRef Context,
PGPtlsContextRef tlsContext,
HWND hWndParent,
INT iID,
HWNDLISTPROC lpfnHwndListFunc,
INT x,
INT y,
INT nWidth,
INT nHeight)
{
return (PGPkmCreateKeyManagerEx (Context, tlsContext, hWndParent, iID,
lpfnHwndListFunc, x, y, nWidth, nHeight, 0));
}
// _______________________________________________
//
// Insert column information into control
BOOL
KMAddColumns (PKEYMAN pKM)
{
TL_COLUMN tlc;
CHAR sz[64];
INT iField, iCol, ids;
TreeList_DeleteAllColumns (pKM->hWndTree);
tlc.mask = TLCF_FMT | TLCF_WIDTH | TLCF_TEXT |
TLCF_SUBITEM | TLCF_DATATYPE | TLCF_DATAMAX |
TLCF_MOUSENOTIFY;
tlc.pszText = sz;
tlc.iSubItem = 0;
tlc.fmt = TLCFMT_LEFT;
tlc.iDataType = TLC_DATASTRING;
tlc.cx = pKM->wFieldWidth[0];
tlc.bMouseNotify = FALSE;
LoadString (g_hInst, IDS_NAMEFIELD, sz, sizeof(sz));
TreeList_InsertColumn (pKM->hWndTree, 0, &tlc);
for (iCol=1; iCol<NUMBERFIELDS; iCol++) {
iField = pKM->wColumnField[iCol];
if (iField) {
switch (iField) {
case KMI_VALIDITY :
ids = IDS_VALIDITYFIELD;
if (pKM->ulOptionFlags & KMF_NOVICEMODE)
tlc.fmt = TLCFMT_IMAGE;
else
tlc.fmt = TLCFMT_LINBAR;
tlc.cchTextMax =
KMConvertFromPGPValidity (kPGPValidity_Complete);
tlc.iDataType = TLC_DATALONG;
tlc.bMouseNotify = TRUE;
break;
case KMI_SIZE :
ids = IDS_SIZEFIELD;
tlc.fmt = TLCFMT_LEFT;
tlc.iDataType = TLC_DATASTRING;
tlc.bMouseNotify = FALSE;
break;
case KMI_DESCRIPTION :
ids = IDS_DESCRIPTIONFIELD;
tlc.fmt = TLCFMT_LEFT;
tlc.iDataType = TLC_DATASTRING;
tlc.bMouseNotify = FALSE;
break;
case KMI_KEYID :
ids = IDS_KEYIDFIELD;
tlc.fmt = TLCFMT_LEFT;
tlc.iDataType = TLC_DATASTRING;
tlc.bMouseNotify = FALSE;
break;
case KMI_TRUST :
ids = IDS_TRUSTFIELD;
tlc.fmt = TLCFMT_LINBAR;
tlc.cchTextMax =
KMConvertFromPGPTrust (kPGPKeyTrust_Complete);
tlc.iDataType = TLC_DATALONG;
tlc.bMouseNotify = FALSE;
break;
case KMI_CREATION :
ids = IDS_CREATIONFIELD;
tlc.fmt = TLCFMT_LEFT;
tlc.iDataType = TLC_DATASTRING;
tlc.bMouseNotify = FALSE;
break;
case KMI_EXPIRATION :
ids = IDS_EXPIRATIONFIELD;
tlc.fmt = TLCFMT_LEFT;
tlc.iDataType = TLC_DATASTRING;
tlc.bMouseNotify = FALSE;
break;
case KMI_ADK :
ids = IDS_ADKFIELD;
tlc.fmt = TLCFMT_IMAGE;
tlc.iDataType = TLC_DATALONG;
tlc.bMouseNotify = FALSE;
break;
}
LoadString (g_hInst, ids, sz, sizeof(sz));
tlc.cx = pKM->wFieldWidth[iField];
TreeList_InsertColumn (pKM->hWndTree, iCol, &tlc);
}
}
return TRUE;
}
// _______________________________________________
//
// Set (or add) a tree item to the tree
static HTLITEM
sSetOneItem (
PKEYMAN pKM,
BOOL bReInsertExisting,
HTLITEM hItem,
HTLITEM hParent,
LPSTR szText,
HTLITEM hInsAfter,
INT iImage,
UINT uState,
LPARAM lParam)
{
TL_TREEITEM tlI;
TL_INSERTSTRUCT tlIns;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -