📄 gmops.c
字号:
/*____________________________________________________________________________
Copyright (C) 1998 Network Associates, Inc.
All rights reserved.
GMTree.h - create and fill group manager control
$Id: GMOps.c,v 1.27 1999/04/01 03:46:43 pbj Exp $
____________________________________________________________________________*/
#include "pgpPFLConfig.h"
// project header files
#include "pgpgmx.h"
// system header files
#include <commdlg.h>
// constant definitions
#define BITMAP_WIDTH 16
#define BITMAP_HEIGHT 16
#define VALIDITYTHRESHOLD 2
#define AXIOMATICTHRESHOLD 3
// typedefs
typedef struct {
FARPROC lpfnCallback;
PGPContextRef Context;
PGROUPMAN pGM;
LPSTR pszPrompt;
BOOL bItemModified;
BOOL bRootGroupDeleted;
BOOL bItemNotDeleted;
BOOL bDeleteAll;
HTLITEM hPostDeleteFocusItem;
} DELETESTRUCT;
typedef struct {
FARPROC lpfnCallback;
PGROUPMAN pGM;
BOOL bFirst;
} LOCATESTRUCT;
typedef struct {
FARPROC lpfnCallback;
PGROUPMAN pGM;
PGPGroupID groupidDest;
BOOL bAdded;
} ADDSTRUCT;
// local globals
static DWORD aDeleteAllIds[] = { // Help IDs
IDOK, IDH_PGPPKGRP_DELETEONE,
IDC_YESTOALL, IDH_PGPPKGRP_DELETEALL,
IDNO, IDH_PGPPKGRP_DELETENO,
IDCANCEL, IDH_PGPPKGRP_DELETECANCEL,
0,0
};
// external globals
extern HINSTANCE g_hInst;
//----------------------------------------------------|
// Delete All dialog message procedure
static BOOL CALLBACK
sDeleteAllDlgProc (
HWND hWndDlg,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
DELETESTRUCT* pds;
switch (uMsg) {
case WM_INITDIALOG :
SetWindowLong (hWndDlg, GWL_USERDATA, lParam);
pds = (DELETESTRUCT*)lParam;
SetDlgItemText (hWndDlg, IDC_STRING, pds->pszPrompt);
break;
case WM_HELP:
pds = (DELETESTRUCT*)GetWindowLong (hWndDlg, GWL_USERDATA);
WinHelp (((LPHELPINFO) lParam)->hItemHandle, pds->pGM->szHelpFile,
HELP_WM_HELP, (DWORD) (LPSTR) aDeleteAllIds);
break;
case WM_CONTEXTMENU:
pds = (DELETESTRUCT*)GetWindowLong (hWndDlg, GWL_USERDATA);
WinHelp ((HWND) wParam, pds->pGM->szHelpFile, HELP_CONTEXTMENU,
(DWORD) (LPVOID) aDeleteAllIds);
break;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDCANCEL:
pds = (DELETESTRUCT*)GetWindowLong (hWndDlg, GWL_USERDATA);
pds->bItemNotDeleted = TRUE;
EndDialog (hWndDlg, IDCANCEL);
break;
case IDOK:
case IDYES:
EndDialog (hWndDlg, IDYES);
break;
case IDNO:
EndDialog (hWndDlg, IDNO);
break;
case IDC_YESTOALL :
pds = (DELETESTRUCT*)GetWindowLong (hWndDlg, GWL_USERDATA);
pds->bDeleteAll = TRUE;
EndDialog (hWndDlg, IDYES);
break;
}
return TRUE;
}
return FALSE;
}
//----------------------------------------------------|
// Ask user for delete confirmation
static INT
sDeleteConfirm (
TL_TREEITEM* lptli,
INT iPromptID,
DELETESTRUCT* pds)
{
CHAR sz256[256];
CHAR sz512[512];
INT iRetVal;
if (pds->bDeleteAll) return IDYES;
LoadString (g_hInst, iPromptID, sz256, 256);
wsprintf (sz512, sz256, lptli->pszText);
if (GMMultipleSelected (pds->pGM)) {
pds->pszPrompt = sz512;
iRetVal = DialogBoxParam (g_hInst, MAKEINTRESOURCE (IDD_DELETEALL),
pds->pGM->hWndParent, sDeleteAllDlgProc, (LPARAM)pds);
if (!pds->bItemNotDeleted && (iRetVal == IDNO)) {
pds->bItemNotDeleted = TRUE;
pds->hPostDeleteFocusItem = lptli->hItem;
}
}
else {
LoadString (g_hInst, IDS_DELCONFCAPTION, sz256, 256);
iRetVal = MessageBox (pds->pGM->hWndParent, sz512, sz256,
MB_YESNO|MB_TASKMODAL|MB_DEFBUTTON2|MB_ICONWARNING);
}
return iRetVal;
}
//----------------------------------------------------|
// Get handle of nearby item
//
// lptli = pointer to TreeList item
static HTLITEM
sGetAdjacentItem (
HWND hWndTree,
TL_TREEITEM* lptli)
{
TL_TREEITEM tli;
tli.hItem = lptli->hItem;
tli.mask = TLIF_NEXTHANDLE;
TreeList_GetItem (hWndTree, &tli);
if (!tli.hItem) {
tli.hItem = lptli->hItem;
tli.mask = TLIF_PREVHANDLE;
TreeList_GetItem (hWndTree, &tli);
if (!tli.hItem) {
tli.hItem = lptli->hItem;
tli.mask = TLIF_PARENTHANDLE;
TreeList_GetItem (hWndTree, &tli);
}
}
return tli.hItem;
}
//----------------------------------------------------|
// Delete a single object
// routine called as a callback function from the TreeList control to
// delete a single item.
//
// lptli = pointer to TreeList item to delete
static BOOL CALLBACK
sDeleteSingleObject (
TL_TREEITEM* lptli,
LPARAM lParam)
{
DELETESTRUCT* pds = (DELETESTRUCT*)lParam;
INT iConfirm;
PGPUInt32 index;
PGPGroupID id;
switch (lptli->iImage) {
// is it a group ?
case IDX_GROUP :
iConfirm = sDeleteConfirm (lptli, IDS_DELCONFGROUP, pds);
if (iConfirm == IDYES) {
id = HIWORD(lptli->lParam);
index = LOWORD(lptli->lParam);
// if hiword is non-zero, then it's a copy of a group
if (id) {
PGPDeleteIndItemFromGroup (pds->pGM->groupsetMain,
id, index);
}
// if hiword is zero, then it's a root group
else {
id = LOWORD(lptli->lParam);
PGPDeleteGroup (pds->pGM->groupsetMain, id);
pds->bRootGroupDeleted = TRUE;
}
pds->bItemModified = TRUE;
if (!pds->bItemNotDeleted)
pds->hPostDeleteFocusItem =
sGetAdjacentItem (pds->pGM->hWndTree, lptli);
TreeList_DeleteItem (pds->pGM->hWndTree, lptli);
}
if (iConfirm == IDCANCEL) return FALSE;
else return TRUE;
// otherwise it's a key
default:
iConfirm = sDeleteConfirm (lptli, IDS_DELCONFKEY, pds);
if (iConfirm == IDYES) {
id = HIWORD(lptli->lParam);
index = LOWORD(lptli->lParam);
if (id) {
PGPDeleteIndItemFromGroup (pds->pGM->groupsetMain, id, index);
pds->bItemModified = TRUE;
if (!pds->bItemNotDeleted)
pds->hPostDeleteFocusItem =
sGetAdjacentItem (pds->pGM->hWndTree, lptli);
TreeList_DeleteItem (pds->pGM->hWndTree, lptli);
}
}
if (iConfirm == IDCANCEL) return FALSE;
else return TRUE;
}
}
// ___________________________________________________
//
// delete group or keys
BOOL
GMDeleteObject (PGROUPMAN pGM)
{
TL_TREEITEM tli;
DELETESTRUCT ds;
ds.lpfnCallback = sDeleteSingleObject;
ds.Context = pGM->context;
ds.pGM = pGM;
ds.bItemModified = FALSE;
ds.bRootGroupDeleted = FALSE;
ds.bDeleteAll = FALSE;
ds.bItemNotDeleted = FALSE;
ds.hPostDeleteFocusItem = NULL;
TreeList_IterateSelected (pGM->hWndTree, &ds);
if (ds.bItemModified) {
GMCommitGroupChanges (pGM, TRUE);
if (ds.bRootGroupDeleted) {
TreeList_DeleteTree (pGM->hWndTree, TRUE);
GMAddColumns (pGM);
GMSortGroupSet (pGM);
GMLoadGroupsIntoTree (pGM, FALSE, FALSE, TRUE);
}
else
GMLoadGroupsIntoTree (pGM, FALSE, FALSE, FALSE);
if (ds.bItemNotDeleted) {
if (ds.hPostDeleteFocusItem) {
tli.hItem = ds.hPostDeleteFocusItem;
TreeList_Select (pGM->hWndTree, &tli, FALSE);
}
else GMSetFocus (pGM, NULL, FALSE);
}
else {
if (ds.hPostDeleteFocusItem) {
tli.hItem = ds.hPostDeleteFocusItem;
TreeList_Select (pGM->hWndTree, &tli, TRUE);
tli.stateMask = TLIS_SELECTED;
tli.state = 0;
tli.mask = TLIF_STATE;
TreeList_SetItem (pGM->hWndTree, &tli);
}
else GMSetFocus (pGM, NULL, FALSE);
}
InvalidateRect (pGM->hWndTree, NULL, TRUE);
}
return (ds.bItemModified);
}
//----------------------------------------------------|
// Add a single object
// routine called as a callback function from the TreeList control to
// add a single item.
//
// lptli = pointer to TreeList item to delete
static BOOL CALLBACK
sAddSingleObject (
TL_TREEITEM* lptli,
LPARAM lParam)
{
ADDSTRUCT* pas = (ADDSTRUCT*)lParam;
PGPUInt32 index;
PGPGroupID id;
PGPGroupItem groupitem;
PGPError err;
switch (lptli->iImage) {
// is it a group ?
case IDX_GROUP :
id = HIWORD(lptli->lParam);
if (!id) id = LOWORD(lptli->lParam);
if (id) {
if (id != pas->groupidDest) {
groupitem.type = kPGPGroupItem_Group;
groupitem.userValue = 0;
groupitem.u.group.id = id;
err = PGPAddItemToGroup (pas->pGM->groupsetMain,
&groupitem, pas->groupidDest);
if (IsntPGPError (err)) pas->bAdded = TRUE;
}
}
return TRUE;
// otherwise it's a key
default:
id = HIWORD(lptli->lParam);
index = LOWORD(lptli->lParam);
if (id) {
PGPGetIndGroupItem (pas->pGM->groupsetMain,
id, index, &groupitem);
groupitem.userValue = 0;
err = PGPAddItemToGroup (pas->pGM->groupsetMain, &groupitem,
pas->groupidDest);
if (IsntPGPError (err)) pas->bAdded = TRUE;
}
return TRUE;
}
}
// _______________________________________________
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -