📄 searchproc.c
字号:
GetClientRect(hwnd, &rect);
GetClientRect(GetParent(hwnd), &rectParent);
if(rect.right != rectParent.right)
{
MapWindowPoints(hwnd, GetParent(hwnd), (LPPOINT)&rect, 2);
rect.left = rectParent.left;
rect.top = rectParent.top;
rect.right = rectParent.right;
MoveWindow( hwnd,
rect.left,
rect.top,
rect.right - rect.left,
rect.bottom - rect.top,
TRUE);
}
break;
}
case WM_COMMAND:
{
WORD wNotifyCode = HIWORD(wParam); // notification code
WORD wID = LOWORD(wParam); // item, control id
HWND hwndCtl = (HWND) lParam; // handle of control
switch( wID )
{
case IDC_MORE:
{
PCHOICE choice;
RECT rectChoice;
RECT rect;
int height;
if(wNotifyCode)
{
break;
}
choice = NewChoice(hwnd);
if(choice)
{
SIZEREQUEST request;
HWND hwndCtrl = NULL;
GetClientRect(hwnd, &rect);
GetClientRect(choice->hwnd, &rectChoice);
height = rectChoice.bottom - rectChoice.top + 1;
memset(&request, 0x00, sizeof(request));
request.nmhdr.hwndFrom = hwnd;
request.nmhdr.idFrom = IDD_SEARCH;
request.nmhdr.code = SEARCH_REQUEST_SIZING;
request.delta = height;
if(SendMessage( GetParent(hwnd),
WM_NOTIFY,
(WPARAM)hwnd,
(LPARAM)&request))
{
NMHDR nmhdr;
height += rect.bottom - rect.top;
MapWindowPoints(hwnd,
GetParent(hwnd),
(LPPOINT)&rect,
2);
rect.bottom = rect.top + height;
MoveWindow( hwnd,
rect.left,
rect.top,
rect.right - rect.left,
rect.bottom - rect.top,
TRUE);
ShowWindow(choice->hwnd, SW_SHOW);
EnableWindow(GetDlgItem(hwnd, IDC_FEWER), TRUE);
memset(&nmhdr, 0x00, sizeof(nmhdr));
nmhdr.hwndFrom = hwnd;
nmhdr.idFrom = IDD_SEARCH;
nmhdr.code = SEARCH_SIZING;
SendMessage(GetParent(hwnd),
WM_NOTIFY,
(WPARAM)hwnd,
(LPARAM)&nmhdr);
hwndCtrl = GetDlgItem(hwnd, IDC_MORE);
InvalidateRect(hwndCtrl, NULL, FALSE);
hwndCtrl = GetDlgItem(hwnd, IDC_FEWER);
InvalidateRect(hwndCtrl, NULL, FALSE);
}
else
{
HWND hwndChoice;
RemoveLastChoice(hwnd, &hwndChoice);
DestroyWindow(hwndChoice);
}
}
break;
}
case IDC_FEWER:
{
PCHOICE choice;
HWND hwndChoice;
RECT rectChoice;
RECT rect;
int height;
NMHDR nmhdr;
if(wNotifyCode)
{
break;
}
choice = RemoveLastChoice(hwnd, &hwndChoice);
GetClientRect(hwnd, &rect);
GetClientRect(hwndChoice, &rectChoice);
height = rect.bottom - rect.top;
height -= rectChoice.bottom - rectChoice.top + 1;
MapWindowPoints(hwnd, GetParent(hwnd), (LPPOINT)&rect, 2);
rect.bottom = rect.top + height;
MoveWindow( hwnd,
rect.left,
rect.top,
rect.right - rect.left,
rect.bottom - rect.top,
TRUE);
if(!choice)
{
EnableWindow(GetDlgItem(hwnd, IDC_FEWER), FALSE);
}
DestroyWindow(hwndChoice);
memset(&nmhdr, 0x00, sizeof(nmhdr));
nmhdr.hwndFrom = hwnd;
nmhdr.idFrom = IDD_SEARCH;
nmhdr.code = SEARCH_SIZING;
SendMessage(GetParent(hwnd),
WM_NOTIFY,
(WPARAM)hwnd,
(LPARAM)&nmhdr);
break;
}
case IDC_CLEAR:
{
HWND hwndItem = NULL;
int count = ChoiceCount(hwnd);
if(wNotifyCode)
{
break;
}
// delete extra choices
for(count; count > 0; count--)
{
SendMessage(hwnd,
WM_COMMAND,
MAKEWPARAM(IDC_FEWER, 0),
0);
}
// reset default choice
hwndItem = GetDlgItem(hwnd, IDC_ATTRIBUTE);
ComboBox_SetCurSel(hwndItem, 0);
ChangeAttributeSelection(hwndItem);
hwndItem = GetDlgItem(hwnd, IDC_SPECIFIER_EDIT);
Edit_SetText(hwndItem, "");
break;
}
case IDC_SEARCH:
{
PGPFilterRef filter = NULL;
PGPFilterRef SearchFilter = NULL;
PCHOICE choice = NULL;
PGPError error;
int action = 0;
HWND hwndStop = NULL;
if(wNotifyCode)
{
break;
}
hwndStop = GetDlgItem(hwnd, IDC_STOP);
// Take Care of the Default Search Item in ourself
error = CreateFilter(hwnd, &filter, &action);
SearchFilter = filter;
if( IsntPGPError (error ) )
{
// now iterate the children if there are any
choice = FirstChoice(hwnd);
while( choice && IsntPGPError (error ) )
{
error = CreateFilter( choice->hwnd,
&filter,
&action);
if( IsntPGPError (error ) )
{
PGPFilterRef CombinedFilter = NULL;
// | the filters
if( action == ACTION_UNION )
{
error = PGPUnionFilters(
filter,
SearchFilter,
&CombinedFilter);
}
// & the filters
else if( action == ACTION_INTERSECT )
{
error = PGPIntersectFilters(
filter,
SearchFilter,
&CombinedFilter);
}
SearchFilter = CombinedFilter;
}
choice = NextChoice(hwnd, choice);
}
}
if( IsPGPError(error) )
{
PGPclErrorBox (NULL, error);
}
if( IsntPGPError(error) )
{
PSEARCHTHREADSTRUCT psts = NULL;
psts = (PSEARCHTHREADSTRUCT)
GetProp( hwnd, "SearchInfo");
if( psts )
{
if (!psts->threadHandle)
{
memset(psts, 0x00,
sizeof(SEARCHTHREADSTRUCT));
psts->hwnd = hwnd;
psts->filter = SearchFilter;
psts->bCancel = FALSE;
psts->bAlreadyAsked = FALSE;
SetProp( hwnd, "SearchInfo",(HANDLE) psts);
EnableWindow (hwndStop, TRUE);
ShowWindow(hwndStop, SW_SHOW);
EnableWindow(hwndCtl, FALSE);
ShowWindow(hwndCtl, SW_HIDE);
psts->threadHandle = CreateThread( NULL,
0,
SearchThreadRoutine,
(void*)psts,
0,
&psts->threadID);
}
}
}
if( IsPGPError(error) )
{
SEARCHABORT abort;
if (filter) PGPFreeFilter (filter);
abort.nmhdr.hwndFrom = hwnd;
abort.nmhdr.idFrom = IDD_SEARCH;
abort.nmhdr.code = SEARCH_ABORT;
abort.error = kPGPError_UserAbort;
SendMessage(GetParent(hwnd),
WM_NOTIFY,
(WPARAM)hwnd,
(LPARAM)&abort);
}
break;
}
case IDC_STOP:
{
HWND hwndSearch, hwndStop;
PSEARCHTHREADSTRUCT psts;
if(wNotifyCode)
{
break;
}
hwndSearch = GetDlgItem(hwnd, IDC_SEARCH);
hwndStop = GetDlgItem(hwnd, IDC_STOP);
if(!IsWindowEnabled (hwndStop))
{
break;
}
psts = (PSEARCHTHREADSTRUCT) GetProp(hwnd, "SearchInfo");
EnableWindow(hwndStop, FALSE);
if(psts)
{
PGPEvent event;
PGPEventErrorData data;
PGPError err;
if (PGPKeyServerRefIsValid (psts->server))
{
err = PGPCancelKeyServerCall (psts->server);
PGPclErrorBox (hwnd, err);
}
data.error = kPGPError_UserAbort;
memset(&event, 0x00, sizeof(PGPEvent));
event.type = kPGPEvent_ErrorEvent;
event.data.errorData = data;
SearchEventHandler( NULL,
&event,
psts);
}
if(psts)
{
SEARCHABORT abort;
memset(&abort, 0x00, sizeof(abort));
abort.nmhdr.hwndFrom = psts->hwnd;
abort.nmhdr.idFrom = IDD_SEARCH;
abort.nmhdr.code = SEARCH_ABORT;
abort.error = kPGPError_UserAbort;
SendMessage(GetParent(psts->hwnd),
WM_NOTIFY,
(WPARAM)psts->hwnd,
(LPARAM)&abort);
}
break;
}
case IDHELP:
{
if(wNotifyCode)
{
break;
}
WinHelp (hwnd, g_szHelpFile, HELP_CONTEXT,
IDH_PGPPK_SEARCH_DIALOG);
break;
}
case IDC_ATTRIBUTE:
{
HANDLE_IDC_ATTRIBUTE(hwnd, msg, wParam, lParam);
break;
}
case IDC_LOCATION:
{
INT i;
if (wNotifyCode == CBN_DROPDOWN)
{
RECT rc;
GetWindowRect (hwndCtl, &rc);
i = rc.top;
}
if (wNotifyCode == CBN_SELCHANGE)
{
RECT rc;
GetWindowRect (hwndCtl, &rc);
i = rc.top;
}
break;
}
}
return TRUE;
}
}
return FALSE;
}
PGPError PerformSearch(HWND hwndLocation,
PSEARCHTHREADSTRUCT psts,
BOOL bPending,
long* flags,
PGPKeySetRef* pKeySetOut)
{
HINSTANCE hinst = GetModuleHandle(NULL);
PGPError error = kPGPError_NoErr;
PGPKeySetRef localKeySet = kPGPInvalidRef;
int locationSelection = 0;
int lastSearchIndex = 0;
int localSearchIndex = 0;
int searchPathIndex = 0;
char* locationBuffer = NULL;
int locationLength = 0;
LPARAM lParam = 0;
int lastSearchType = 0;
char szString[256] = {0x00};
PGPKeyServerAccessType accessType = kPGPKeyServerAccessType_Normal;
CRITICAL_SECTION* keyserverLock =
(CRITICAL_SECTION*) GetProp(GetParent(hwndLocation),
"KeyserverLock");
PGPKeyServerThreadStorageRef previousStorage;
#if PGP_BUSINESS_SECURITY
if (PGPclIsAdminInstall ())
accessType = kPGPKeyServerAccessType_Administrator;
#endif // PGP_BUSINESS_SECURITY
PGPKeyServerInit();
PGPKeyServerCreateThreadStorage(&previousStorage);
EnterCriticalSection(keyserverLock);
lastSearchType = (int)GetProp(hwndLocation, "LastSearchType");
LoadString(hinst, IDS_DEFAULT_PATH, szString, sizeof(szString));
searchPathIndex = ComboBox_FindString(hwndLocation, -1, szString);
LoadString(hinst, IDS_LOCAL_KEYRING, szString, sizeof(szString));
localSearchIndex = ComboBox_FindString(hwndLocation, -1, szString);
LoadString(hinst, IDS_CURRENT_SEARCH, szString, sizeof(szString));
lastSearchIndex = ComboBox_FindString(hwndLocation, -1, szString);
locationSelection = ComboBox_GetCurSel(hwndLocation);
lParam = ComboBox_GetItemData(hwndLocation, locationSelection);
psts->keySet =
(PGPKeySetRef) ComboBox_GetItemData(hwndLocation, localSearchIndex);
LeaveCriticalSection(keyserverLock);
if (lParam == 0L ) // NULL: Invalid Selection
{
*pKeySetOut = kPGPInvalidRef;
}
// Default Path
else if( locationSelection == searchPathIndex )
{
PGPPrefRef prefs;
PGPtlsSessionRef tls = kInvalidPGPtlsSessionRef;
PGPKeyServerEntry* keyserverList = NULL;
PGPUInt32 keyserverCount = 0;
char* searchString = NULL;
int searchStringLength = 0;
char emailDomain[512] = {0x00};
*flags = FLAG_SEARCH_MEMORY;
SetProp( hwndLocation, "LastSearchType",(HANDLE) *flags);
// retrieve search string from control
GrabUserIdStrings( GetParent(hwndLocation),
&searchString,
&searchStringLength);
if(searchString)
{
PGPFindEmailDomain(searchString, emailDomain);
}
error = PGPclOpenClientPrefs(
PGPGetContextMemoryMgr (g_Context),
&prefs);
if( IsntPGPError( error ) )
{
DWORD index = 0;
error = PGPCreateKeyServerPath( prefs,
emailDomain,
&keyserverList,
&keyserverCount);
if( IsntPGPError( error ) )
{
for(index = 0; index < keyserverCount; index++)
{
SEARCHPROGRESS progress;
char templateString[256];
memset(&progress, 0x00, sizeof(progress));
progress.nmhdr.hwndFrom = GetParent(hwndLocation);
progress.nmhdr.idFrom = IDD_SEARCH;
progress.nmhdr.code = SEARCH_PROGRESS;
progress.step = SEARCH_PROGRESS_INFINITE;
progress.total = SEARCH_PROGRESS_INFINITE;
LoadString( g_hInst,
IDS_SEARCH_MESSAGE_SERVER_NAME,
templateString,
sizeof(templateString));
wsprintf( progress.message,
templateString,
keyserverList[index].serverDNS);
SendMessage(GetParent(GetParent(hwndLocation)),
WM_NOTIFY,
(WPARAM)GetParent(hwndLocation),
(LPARAM)&progress);
error = PGPNewKeyServerFromHostName(
g_Context,
keyserverList[index].serverDNS,
keyserverList[index].serverPort,
keyserverList[index].protocol,
accessType,
(bPending ? kPGPKeyServerKeySpace_Pending :
kPGPKeyServerKeySpace_Default),
&psts->server );
if( IsntPGPError( error ) )
{
memcpy(&(psts->keyserverEntry),
&(keyserverList[index]),
sizeof(PGPKeyServerEntry));
error = PGPSetKeyServerEventHandler( psts->server,
SearchEventHandler, psts );
if ( IsntPGPError( error ) )
{
if( (kPGPKeyServerType_LDAPS ==
keyserverList[index].protocol) ||
(kPGPKeyServerType_HTTPS ==
keyserverList[index].protocol))
{
error = PGPNewTLSSession( g_TLSContext,
&tls );
if( IsPGPError(error) )
{
// warn beyond the icon?
tls = kInvalidPGPtlsSessionRef;
}
}
error = PGPKeyServerOpen( psts->server, tls );
if ( IsntPGPError(error) )
{
error = PGPQueryKeyServer( psts->server,
psts->filter,
pKeySetOut);
PGPKeyServerClose ( psts->server );
}
}
PGPFreeKeyServer( psts->server );
psts->server = kInvalidPGPKeyServerRef;
if( PGPtlsSessionRefIsValid(tls) )
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -