📄 searchproc.c
字号:
/*____________________________________________________________________________
Copyright (C) 2002 PGP Corporation
All rights reserved.
$Id: SearchProc.c,v 1.24 2002/11/19 21:07:11 pbj Exp $
____________________________________________________________________________*/
// System Headers
#include <windows.h>
#include <windowsx.h>
#include <winsock.h>
#include <commctrl.h>
// PGPsdk Headers
#include "pgpKeys.h"
#include "pgpErrors.h"
#include "pgpKeyServer.h"
#include "pgpKeyServerPrefs.h"
#include "pgpBuild.h"
#include "pgpUtilities.h"
#include "pgpClientPrefs.h"
// Shared Headers
#include "PGPclientLib.h"
#include "PGPkeysx.h"
// Project Headers
#include "Search.h"
#include "Choice.h"
#include "SearchFilter.h"
#include "SearchCommon.h"
#include "resource.h"
#include "UTF8Edit.h"
// set this flag to TRUE in order to hide the "pending" checkbox
// on non-Admin installs of PGP Enterprise
#define HIDE_PENDING_CHECKBOX TRUE
typedef struct _SEARCHTHREADSTRUCT
{
HWND hwnd;
HANDLE threadHandle;
DWORD threadID;
PGPFilterRef filter;
PGPKeyServerEntry keyserverEntry;
PGPKeyDBRef keydbMain;
PGPKeyServerRef server;
BOOL bCancel;
BOOL bHidePending;
}SEARCHTHREADSTRUCT,*PSEARCHTHREADSTRUCT;
extern PGPContextRef g_context;
extern PGPtlsContextRef g_tlscontext;
extern HINSTANCE g_hinst;
static DWORD aSearchIds[] = { // Help IDs
IDC_SEARCH, IDH_PGPPKSEARCH_SEARCH,
IDC_STOP, IDH_PGPPKSEARCH_STOP,
IDC_CLEAR, IDH_PGPPKSEARCH_CLEAR,
IDC_LOCATION, IDH_PGPPKSEARCH_LOCATION,
IDC_ATTRIBUTE, IDH_PGPPKSEARCH_ATTRIBUTE,
IDC_VERB, IDH_PGPPKSEARCH_VERB,
IDC_MORE, IDH_PGPPKSEARCH_MORE,
IDC_FEWER, IDH_PGPPKSEARCH_FEWER,
IDC_PENDING, IDH_PGPPKSEARCH_PENDING,
0,0
};
PGPError PerformSearch(HWND hwndLocation,
PSEARCHTHREADSTRUCT psts,
BOOL bPending,
long* flags,
PGPKeySetRef* pKeySetOut);
PGPError SearchEventHandler(PGPContextRef context,
PGPEvent *event,
PGPUserValue userValue);
DWORD WINAPI SearchThreadRoutine( LPVOID lpvoid);
void GrabUserIdStrings(HWND hwnd,
char** string,
int* length);
BOOL
CALLBACK
SearchProc( HWND hwnd,
UINT msg,
WPARAM wParam,
LPARAM lParam )
{
static int offsetButtons = 0;
static int offsetBoxes = 0;
static int originalWidth = 0;
int oldWidth = (int)GetProp(hwnd, "oldWidth");
int oldHeight = (int)GetProp(hwnd, "oldHeight");
switch(msg)
{
case WM_INITDIALOG:
{
RECT rectWindow, rectButton, rectBox;
HWND hwndBox = GetDlgItem(hwnd, IDC_SPECIFIER_COMBO);
HWND hwndButton = GetDlgItem(hwnd, IDC_SEARCH);
HWND hwndPending = GetDlgItem(hwnd, IDC_PENDING);
HWND hwndTime = NULL;
RECT rect;
PSEARCHTHREADSTRUCT psts;
CRITICAL_SECTION* keyserverLock;
UTF8EditInit(GetDlgItem (hwnd, IDC_SPECIFIER_EDIT));
GetClientRect(hwndBox, &rect);
MapWindowPoints(hwndBox, hwnd, (LPPOINT)&rect, 2);
hwndTime = CreateWindowEx (0, DATETIMEPICK_CLASS,
"DateTime",
WS_BORDER|WS_CHILD|WS_VISIBLE|WS_TABSTOP,
rect.left, rect.top-1,
rect.right-rect.left, rect.bottom-rect.top+2,
hwnd, NULL, g_hinst, NULL);
SetWindowPos (hwndTime, GetDlgItem (hwnd, IDC_VERB),
0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
SendMessage (hwndTime, DTM_SETMCCOLOR,
MCSC_MONTHBK, (LPARAM)GetSysColor (COLOR_3DFACE));
ShowWindow(hwndTime, SW_HIDE);
SetProp( hwnd, "hwndTime", hwndTime);
GetWindowRect(hwnd, &rectWindow);
GetWindowRect(hwndButton, &rectButton);
GetWindowRect(hwndBox, &rectBox);
offsetButtons = rectWindow.right - rectButton.right;
offsetBoxes = rectButton.left - rectBox.right;
oldWidth = rectWindow.right - rectWindow.left;
SetProp( hwnd, "oldWidth",(HANDLE) oldWidth);
oldHeight = rectWindow.bottom - rectWindow.top;
SetProp( hwnd, "oldHeight",(HANDLE) oldHeight);
originalWidth = oldWidth;
SetProp( hwnd, "ChoiceList",(HANDLE) 0);
psts = (PSEARCHTHREADSTRUCT) malloc( sizeof(SEARCHTHREADSTRUCT));
if(psts)
{
memset(psts, 0x00, sizeof(SEARCHTHREADSTRUCT));
SetProp(hwnd,"SearchInfo", (HANDLE) psts );
#if HIDE_PENDING_CHECKBOX
if(PGPlnEnterprise())
{
psts->bHidePending = PGPclIsClientInstall();
}
#endif // HIDE_PENDING_CHECKBOX
if(!psts->bHidePending)
ShowWindow(hwndPending, SW_SHOW);
}
keyserverLock =
(CRITICAL_SECTION*)malloc(sizeof(CRITICAL_SECTION));
if(keyserverLock)
{
InitializeCriticalSection(keyserverLock);
SetProp(hwnd,"KeyserverLock", (HANDLE) keyserverLock );
}
EnterCriticalSection(keyserverLock);
InitializeControlValues(hwnd, 0);
LeaveCriticalSection(keyserverLock);
// subclass datetime control
SetProp(hwndTime,"hwnd", hwnd );
SetProp (hwndTime, "oldproc",
(HANDLE)GetWindowLong( hwndTime, GWL_WNDPROC ) );
SetWindowLong( hwndTime,
GWL_WNDPROC,
(DWORD)SearchSubclassWndProc );
// subclass combo box
hwndBox = GetDlgItem(hwnd, IDC_SPECIFIER_COMBO);
SetProp(hwndBox,"hwnd", hwnd );
SetProp (hwndBox, "oldproc",
(HANDLE)GetWindowLong( hwndBox, GWL_WNDPROC ) );
SetWindowLong( hwndBox,
GWL_WNDPROC,
(DWORD)SearchSubclassWndProc );
// subclass combo box
hwndBox = GetDlgItem(hwnd, IDC_SPECIFIER_COMBO_LIST);
SetProp(hwndBox,"hwnd", hwnd );
SetProp (hwndBox, "oldproc",
(HANDLE)GetWindowLong( hwndBox, GWL_WNDPROC ) );
SetWindowLong( hwndBox,
GWL_WNDPROC,
(DWORD)SearchSubclassWndProc );
// subclass edit box
hwndBox = UTF8EditGetHandle (GetDlgItem(hwnd, IDC_SPECIFIER_EDIT));
SetProp(hwndBox,"hwnd", hwnd );
SetProp (hwndBox, "oldproc",
(HANDLE)GetWindowLong( hwndBox, GWL_WNDPROC ) );
SetWindowLong( hwndBox,
GWL_WNDPROC,
(DWORD)SearchSubclassWndProc );
SetFocus(hwndBox);
return FALSE;
}
case WM_DESTROY:
{
HINSTANCE hinst = GetModuleHandle(NULL);
PCHOICE choice = NULL;
HWND hwndChoice = NULL;
HWND hwndLocation = NULL;
LPARAM itemData = 0;
int searchPathIndex = 0;
int locationSelection = 0;
char szString[256] = {0x00};
PSEARCHTHREADSTRUCT psts = NULL;
CRITICAL_SECTION* keyserverLock = NULL;
PSEARCHPATH path = NULL;
psts = (PSEARCHTHREADSTRUCT) GetProp(hwnd, "SearchInfo");
if(psts)
{
if(psts->threadHandle)
TerminateThread(psts->threadHandle, 0);
free(psts);
}
RemoveProp (hwnd, "SearchInfo");
keyserverLock = (CRITICAL_SECTION*) GetProp(hwnd,
"KeyserverLock");
if(keyserverLock)
{
EnterCriticalSection(keyserverLock);
DeleteCriticalSection( keyserverLock );
free(keyserverLock);
}
RemoveProp (hwnd, "KeyserverLock");
// remove all the choice windows
do
{
choice = RemoveLastChoice(hwnd, &hwndChoice);
UTF8EditDestroy(GetDlgItem (hwndChoice, IDC_SPECIFIER_EDIT));
DestroyWindow( hwndChoice );
}while( choice );
RemoveProp (hwnd, "ChoiceList");
// free the prefs struct I am using
hwndLocation = GetDlgItem(hwnd, IDC_LOCATION);
locationSelection = ComboBox_GetCurSel(hwndLocation);
path = (PSEARCHPATH) GetProp(hwnd, "SearchPath");
if(path)
{
PGPFreeData(path->keyserverList);
PGPclPeekClientLibPrefRefs (&path->prefRef, NULL);
PGPSetPrefNumber (path->prefRef,
kPGPPrefLastSearchWindowSelection,
(PGPUInt32)locationSelection);
PGPclFlushClientLibPrefs (path->prefRef, NULL);
free(path);
}
RemoveProp (hwnd, "SearchPath");
RemoveProp (hwnd, "hwndTime");
RemoveProp (hwnd, "oldWidth");
RemoveProp (hwnd, "oldHeight");
RemoveProp (hwnd, "LastSearchType");
CloseSearch ();
return TRUE;
}
#define DividerItem 1
case WM_MEASUREITEM:
{
LPMEASUREITEMSTRUCT lpmis = (LPMEASUREITEMSTRUCT) lParam;
if (lpmis->itemID != -1)
{
lpmis->itemHeight += 2;
}
return TRUE;
}
// Draw the listbox
case WM_DRAWITEM:
{
LPDRAWITEMSTRUCT lpDs = (LPDRAWITEMSTRUCT)lParam;
int iTextVOff = 2;
RECT Rect, EtchRect;
HBRUSH hBrush;
char szText[ 256 ];
// If nothing to draw, exit now
if( lpDs->itemID == CB_ERR )
{
return( FALSE );
}
Rect.left = lpDs->rcItem.left;
Rect.top = lpDs->rcItem.top;
Rect.right = lpDs->rcItem.right;
Rect.bottom = lpDs->rcItem.bottom;
// Create a brush using the item's background color
hBrush = CreateSolidBrush( GetSysColor(COLOR_WINDOW ));
// Fill entire item area
FillRect( lpDs->hDC, &Rect, hBrush );
// Delete the brush when done
DeleteObject( hBrush );
// Highlight if selected
if( lpDs->itemState & ODS_FOCUS )
{
if (!(lpDs->itemState & ODS_COMBOBOXEDIT)) {
if (lpDs->itemID == DividerItem) {
iTextVOff = 1;
Rect.bottom -= 2;
}
else if (lpDs->itemID == DividerItem+1)
Rect.top += 1;
}
// Create a brush using the item's background color
hBrush = CreateSolidBrush( GetSysColor(COLOR_HIGHLIGHT ));
// Fill entire item area
FillRect( lpDs->hDC, &Rect, hBrush );
// Delete the brush when done
DeleteObject( hBrush );
}
// Get the item string
SendMessage(lpDs->hwndItem,
CB_GETLBTEXT ,
lpDs->itemID,
(LPARAM)szText );
SetBkMode( lpDs->hDC, TRANSPARENT );
SetTextColor( lpDs->hDC,
GetSysColor(( (lpDs->itemState & ODS_FOCUS) ?
COLOR_HIGHLIGHTTEXT : COLOR_BTNTEXT) ));
// and display the text
TextOut(lpDs->hDC,
4,
lpDs->rcItem.top + iTextVOff,
szText,
strlen( szText ) );
EtchRect = lpDs->rcItem;
if (!(lpDs->itemState & ODS_COMBOBOXEDIT) &&
(lpDs->itemID == DividerItem))
{
EtchRect.top = EtchRect.bottom-1;
DrawEdge( lpDs->hDC,
&EtchRect,
EDGE_ETCHED,
BF_TOP );
}
return TRUE;
} // End of WM_DRAWITEM
case WM_GETDLGCODE:
{
return DLGC_WANTMESSAGE;
}
case WM_CONTEXTMENU :
{
return PGPclHtmlHelp (hwnd, msg, wParam, lParam,
(char*)kPGPclHelpFile, aSearchIds);
}
case SEARCH_SET_LOCAL_KEYSET:
{
HINSTANCE hinst = GetModuleHandle(NULL);
HWND hwndBox = NULL;
char szString[256] = {0x00};
int i = 0;
hwndBox = GetDlgItem(hwnd, IDC_LOCATION);
LoadString(hinst, IDS_LOCAL_KEYRING, szString, sizeof(szString));
i = ComboBox_FindString(hwndBox, -1, szString);
ComboBox_SetItemData(hwndBox, i, lParam);
break;
}
case SEARCH_SET_CURRENT_SEARCH:
{
HINSTANCE hinst = GetModuleHandle(NULL);
HWND hwndBox = NULL;
char szString[256] = {0x00};
int i = 0;
hwndBox = GetDlgItem(hwnd, IDC_LOCATION);
LoadString(hinst, IDS_CURRENT_SEARCH, szString, sizeof(szString));
i = ComboBox_FindString(hwndBox, -1, szString);
ComboBox_SetItemData(hwndBox, i, lParam);
break;
}
case SEARCH_SET_FOCUS:
{
SetFocus (GetDlgItem (hwnd, IDC_SEARCH));
break;
}
case SEARCH_SET_MAIN_KEYDB:
{
PSEARCHTHREADSTRUCT psts = NULL;
psts = (PSEARCHTHREADSTRUCT) GetProp(hwnd, "SearchInfo");
if (psts)
psts->keydbMain = (PGPKeyDBRef)lParam;
break;
}
case WM_NOTIFY:
{
LPNMHDR pnmh = (LPNMHDR) lParam;
switch(pnmh->code)
{
case REFRESH_KEYSERVER_LIST:
{
CRITICAL_SECTION* keyserverLock =
(CRITICAL_SECTION*) GetProp(hwnd, "KeyserverLock");
EnterCriticalSection(keyserverLock);
ReloadKeyserverList(hwnd);
LeaveCriticalSection(keyserverLock);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -