📄 gmtree.c
字号:
BOOL bForceNewAlloc,
BOOL bExpandNew,
BOOL bFirstCall,
HTLITEM hTParent,
HTLITEM hTPrev)
{
HTLITEM hTGroup, hTItem, hTItemPrev;
TL_TREEITEM tli;
INT i, iNumKeys, iNumTotal, idx;
UINT u, uState, uVal;
PGPBoolean bNew, bItalics;
PGPGroupInfo groupinfo;
PGPGroupItem groupitem;
PGPGroupID groupidThis, groupidParent;
PGPKeyDBObjRef key;
PGPError err;
CHAR sz[kPGPMaxUserIDSize];
CHAR szID[kPGPMaxKeyIDStringSize];
static BOOL bNewKeyExpanded;
uState = 0;
bNew = FALSE;
hTItem = NULL;
hTItemPrev = TLI_FIRST;
if (bFirstCall)
bNewKeyExpanded = FALSE;
if (hTParent)
{
groupidParent = groupid;
PGPGetIndGroupItem (pGM->groupsetMain, groupidParent,
iIndex, &groupitem);
groupidThis = groupitem.u.groupID;
PGPGetGroupInfo (pGM->groupsetMain, groupidThis, &groupinfo);
hTGroup = groupitem.userValue;
}
else
{
groupidThis = groupid;
PGPGetGroupInfo (pGM->groupsetMain, groupidThis, &groupinfo);
hTGroup = groupinfo.userValue;
}
if (!hTGroup)
bNew = TRUE;
// determine icon and italics
idx = IDX_GROUP;
// insert group item into tree and save pointer to tree item
if (bNew && bExpandNew)
uState |= TLIS_SELECTED;
if (bForceNewAlloc)
hTGroup = NULL;
if (hTParent)
{
uVal = MAKELONG (iIndex, groupidParent);
hTGroup = sSetOneGroupItem (pGM, bReInsert, hTGroup, hTParent,
groupinfo.name, hTPrev, idx, uState, uVal);
PGPSetIndGroupItemUserValue (pGM->groupsetMain, groupidParent,
iIndex, (PGPUserValue)hTGroup);
}
else
{
uVal = MAKELONG (groupidThis, 0);
hTGroup = sSetOneGroupItem (pGM, bReInsert, hTGroup, hTParent,
groupinfo.name, hTPrev, idx, uState, uVal);
PGPSetGroupUserValue (pGM->groupsetMain,
groupidThis, (PGPUserValue)hTGroup);
}
sSetGroupData (pGM, hTGroup, groupidThis, groupinfo.description);
// if a reinsertion, then we're done
if (bReInsert)
return hTGroup;
// if not at root, then we don't draw items in group
if (hTParent)
return hTGroup;
// iterate through items in group
PGPCountGroupItems (pGM->groupsetMain,
groupidThis, FALSE, &iNumKeys, &iNumTotal);
for (i=0; i<iNumTotal; i++)
{
PGPGetIndGroupItem (pGM->groupsetMain, groupidThis, i, &groupitem);
if (groupitem.type == kPGPGroupItem_KeyID)
{
err = PGPFindKeyByKeyID (pGM->keydbMain,
&groupitem.u.keyID, &key);
if (IsntPGPError (err) && PGPKeyDBObjRefIsValid (key))
{
uState = 0;
hTItem = (HTLITEM)groupitem.userValue;
if (!hTItem) bNew = TRUE;
// get and set treelist tree data for this key
PGPclGetPrimaryUserIDNameUTF8 (key, sz, sizeof(sz), &u);
if (bForceNewAlloc)
hTItem = NULL;
idx = PGPclDetermineKeyIcon (key, &bItalics);
if (bItalics)
uState |= TLIS_ITALICS;
uVal = MAKELONG (i, groupidThis);
hTItem = sSetOneGroupItem (pGM, bReInsert, hTItem, hTGroup,
sz, hTItemPrev, idx, uState, uVal);
PGPSetIndGroupItemUserValue (pGM->groupsetMain,
groupidThis, i, (PGPUserValue)hTItem);
sSetKeyData (pGM, hTItem, key, "");
}
else
{
hTItem = (HTLITEM)groupitem.userValue;
if (!hTItem) bNew = TRUE;
// get and set treelist tree data for this key
if (bForceNewAlloc)
hTItem = NULL;
idx = IDX_DSAPUBDISKEY;
uState = TLIS_ITALICS;
LoadString (g_hinst, IDS_UNAVAILABLE, sz, sizeof(sz));
PGPGetKeyIDString (&groupitem.u.keyID,
kPGPKeyIDString_Abbreviated, szID);
lstrcat (sz, szID);
uVal = MAKELONG (i, groupidThis);
hTItem = sSetOneGroupItem (pGM, bReInsert, hTItem, hTGroup,
sz, hTItemPrev, idx, uState, uVal);
PGPSetIndGroupItemUserValue (pGM->groupsetMain,
groupidThis, i, (PGPUserValue)hTItem);
}
}
// this is a group within a group
else
{
hTItem = sReloadGroup (pGM, groupidThis, i, bReInsert,
bForceNewAlloc, bExpandNew, FALSE, hTGroup, hTItemPrev);
}
hTItemPrev = hTItem;
}
// select and expand key, if appropriate
if (bExpandNew && bNew)
{
tli.hItem = hTGroup;
if (!bNewKeyExpanded)
{
TreeList_Select (pGM->hwndTree, &tli, TRUE);
TreeList_Expand (pGM->hwndTree, &tli, TLE_EXPANDALL);
bNewKeyExpanded = TRUE;
}
else
{
GMSetFocus (pGM, GMFocusedItem (pGM), TRUE, FALSE);
TreeList_Expand (pGM->hwndTree, &tli, TLE_EXPANDALL);
}
}
return hTGroup;
}
// ___________________________________________________
//
// Scan entire groupset loading in any new data
BOOL
GMLoadGroupsIntoTree (
PGROUPMAN pGM,
BOOL bReInsert,
BOOL bExpandNew,
BOOL bForceRealloc)
{
HCURSOR hCursorOld;
TL_TREEITEM tli;
HTLITEM hTPrevKey;
BOOL bFirst;
PGPGroupID groupid;
INT i, iNumGroups;
hTPrevKey = (HTLITEM)TLI_FIRST;
bFirst = TRUE;
if (pGM->groupsetMain)
{
hCursorOld = SetCursor (LoadCursor (NULL, IDC_WAIT));
PGPCountGroupsInSet (pGM->groupsetMain, &iNumGroups);
for (i=0; i<iNumGroups; i++)
{
PGPGetIndGroupID (pGM->groupsetMain, i, &groupid);
hTPrevKey = sReloadGroup (pGM, groupid, 0, bReInsert,
bForceRealloc, bExpandNew, bFirst, NULL, hTPrevKey);
bFirst = FALSE;
}
SetCursor (hCursorOld);
if (bExpandNew)
{
tli.hItem = GMFocusedItem (pGM);
if (tli.hItem)
TreeList_EnsureVisible (pGM->hwndTree, &tli);
}
return TRUE;
}
return FALSE;
}
// ___________________________________________________
//
// Cleanup group manager
PGPError
PGPgmDestroyGroupManager (HGROUPMAN hGM)
{
PGROUPMAN pGM = (PGROUPMAN)hGM;
if (!hGM)
return kPGPError_BadParams;
RevokeDragDrop (pGM->hwndTree);
PKReleaseDropTarget (pGM->pDropTarget);
CoLockObjectExternal ((IUnknown*)pGM->pDropTarget, FALSE, TRUE);
PGPclCloseGroupFile (pGM->pGroupFile);
GMSetColumnPreferences (pGM);
SendMessage (pGM->hwndTree, WM_CLOSE, 0, 0);
gmFree (pGM);
return kPGPError_NoErr;
}
// ___________________________________________________
//
// Map dragover screen coordinates to window coords
BOOL
GMSelectGroup (PGROUPMAN pGM, POINTL ptl)
{
POINT pt;
pt.x = ptl.x;
pt.y = ptl.y;
MapWindowPoints (NULL, pGM->hwndTree, &pt, 1);
return (TreeList_DragOver (pGM->hwndTree, MAKELONG (pt.x, pt.y)));
}
// ___________________________________________________
//
// Load keyset into treelist
PGPError
PGPgmLoadGroups (HGROUPMAN hGroupMan)
{
PGROUPMAN pGM = (PGROUPMAN)hGroupMan;
if (!pGM)
return kPGPError_BadParams;
if (pGM->groupsetMain)
{
GMSetFocus (pGM, NULL, FALSE, FALSE);
TreeList_DeleteTree (pGM->hwndTree, TRUE);
PGPclCloseGroupFile (pGM->pGroupFile);
pGM->groupsetMain = NULL;
}
if (PGPKeyDBRefIsValid (pGM->keydbMain))
{
PGPclOpenGroupFile (pGM->context, &(pGM->pGroupFile));
pGM->groupsetMain = pGM->pGroupFile->groupset;
GMAddColumns (pGM);
GMSortGroupSet (pGM);
GMLoadGroupsIntoTree (pGM, FALSE, FALSE, TRUE);
PKEnableDropTarget (pGM->pDropTarget, TRUE);
}
InvalidateRect (pGM->hwndTree, NULL, TRUE);
UpdateWindow (pGM->hwndTree);
return kPGPError_NoErr;
}
// ___________________________________________________
//
// Load keyset into treelist
PGPError PGPgmExport
PGPgmReLoadGroups (HGROUPMAN hGroupMan)
{
PGROUPMAN pGM = (PGROUPMAN)hGroupMan;
if (!pGM)
return kPGPError_BadParams;
if (!pGM->groupsetMain)
return kPGPError_BadParams;
if (!PGPKeyDBRefIsValid (pGM->keydbMain))
return kPGPError_BadParams;
GMSortGroupSet (pGM);
GMLoadGroupsIntoTree (pGM, FALSE, TRUE, FALSE);
InvalidateRect (pGM->hwndTree, NULL, TRUE);
UpdateWindow (pGM->hwndTree);
return kPGPError_NoErr;
}
// ___________________________________________________
//
// Set configuration
PGPError PGPgmExport
PGPgmConfigure (
HGROUPMAN hGroupMan,
PGMCONFIG pGMConfig)
{
PGROUPMAN pGM = (PGROUPMAN)hGroupMan;
if (!pGM)
return kPGPError_BadParams;
if (pGM)
{
pGM->ppks = pGMConfig->ppks;
pGM->hKL = pGMConfig->hKL;
pGM->keydbMain = pGMConfig->keydbMain;
pGM->uOptions = pGMConfig->uOptions;
pGM->hwndStatusBar = pGMConfig->hwndStatusBar;
if (pGM->uOptions & GMF_MARGASINVALID)
pGM->iValidityThreshold = GM_VALIDITY_COMPLETE;
else
pGM->iValidityThreshold = GM_VALIDITY_MARGINAL;
return kPGPError_NoErr;
}
else
return kPGPError_BadParams;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -