📄 pgpdialogoptions.c
字号:
/*____________________________________________________________________________
Copyright (C) 1997 Network Associates Inc. and affiliated companies.
All rights reserved.
$Id: pgpDialogOptions.c,v 1.29.8.1 1999/06/04 01:12:05 heller Exp $
____________________________________________________________________________*/
#include <string.h>
#include "pgpKeys.h"
#include "pgpKeyServer.h"
#include "pgpMem.h"
#include "pgpUserInterface.h"
#include "pgpOptionListPriv.h"
#define elemsof(x) ((unsigned)(sizeof(x)/sizeof(*x)))
PGPOptionListRef
PGPOUIDialogPrompt(
PGPContextRef context,
const char *prompt)
{
PGPOptionListRef optionList;
pgpValidateOptionContext( context );
pgpValidateOptionParam( IsntNull( prompt ) );
optionList = pgpCreateBufferOptionList( context,
kPGPOptionType_DialogPrompt,
prompt, strlen( prompt ) + 1 );
return( optionList );
}
PGPOptionListRef
PGPOUIWindowTitle(
PGPContextRef context,
const char *title)
{
PGPOptionListRef optionList;
pgpValidateOptionContext( context );
pgpValidateOptionParam( IsntNull( title ) );
optionList = pgpCreateBufferOptionList( context,
kPGPOptionType_WindowTitle,
title, strlen( title ) + 1 );
return( optionList );
}
PGPOptionListRef
PGPOUIOutputPassphrase(
PGPContextRef context,
char **passphrase)
{
PGPOptionListRef optionList;
PGPOptionValue value;
pgpValidateOptionParam( IsntNull( passphrase ) );
*passphrase = NULL;
pgpValidateOptionContext( context );
/* buffer size may be 0 */
value.asPtr = passphrase;
optionList = pgpCreateStandardValueOptionList( context,
kPGPOptionType_OutputPassphrase,
&value, sizeof( passphrase), NULL );
return( optionList );
}
/* MS Windows only.*/
/* Option takes parent's HWND and uses for child windows */
#if PGP_WIN32
PGPOptionListRef
PGPOUIParentWindowHandle(
PGPContextRef context,
HWND hwndParent)
{
PGPOptionListRef optionList;
PGPOptionValue value;
pgpValidateOptionContext( context );
/* buffer size may be 0 */
value.asUInt = (UINT)hwndParent;
optionList = pgpCreateStandardValueOptionList( context,
kPGPOptionType_ParentWindowHandle,
&value, sizeof( PGPUInt32 ), NULL );
return( optionList );
}
#endif
static void
FreePGPOUICheckboxDesc(
PGPContextRef context,
PGPOUICheckboxDesc *desc)
{
pgpAssertAddrValid( desc, PGPOUICheckboxDesc );
if( IsntNull( desc->title ) )
{
pgpContextMemFree( context, (void *) desc->title );
desc->title = NULL;
}
if( IsntNull( desc->description ) )
{
pgpContextMemFree( context, (void *) desc->description );
desc->description = NULL;
}
pgpContextMemFree( context, desc );
}
static PGPError
CopyPGPOUICheckboxDesc(
PGPContextRef context,
const PGPOUICheckboxDesc *srcDesc,
PGPOUICheckboxDesc **destDesc)
{
PGPError err = kPGPError_OutOfMemory;
PGPOUICheckboxDesc *outDesc;
pgpAssertAddrValid( srcDesc, PGPOUICheckboxDesc );
pgpAssertAddrValid( destDesc, PGPOUICheckboxDesc * );
*destDesc = NULL;
outDesc = (PGPOUICheckboxDesc *) pgpContextMemAlloc( context,
sizeof( *outDesc ), kPGPMemoryMgrFlags_Clear );
if( IsntNull( outDesc ) )
{
*outDesc = *srcDesc;
pgpAssertAddrValid( srcDesc->title, char );
pgpAssertAddrValid( srcDesc->description, char );
outDesc->title = pgpAllocCString( context, srcDesc->title );
outDesc->description = pgpAllocCString( context,
srcDesc->description );
if( IsntNull( outDesc->title ) &&
IsntNull( outDesc->description ) )
{
err = kPGPError_NoErr;
}
else
{
FreePGPOUICheckboxDesc( context, outDesc );
outDesc = NULL;
}
}
*destDesc = outDesc;
return( err );
}
static PGPError
CheckboxOptionHandlerProc(
PGPContextRef context,
PGPOptionHandlerOperation operation,
PGPOptionType type,
PGPOptionValue inputValue,
PGPSize inputValueSize,
PGPOptionValue *outputValue,
PGPSize *outputValueSize)
{
PGPError err = kPGPError_NoErr;
PGPOUICheckboxDesc *inputDesc;
pgpAssert( inputValueSize == sizeof( *inputDesc ) );
(void) type;
(void) inputValueSize;
inputDesc = (PGPOUICheckboxDesc *) inputValue.asPtr;
pgpAssertAddrValid( inputDesc, PGPOUICheckboxDesc );
switch( operation )
{
case kPGPOptionHandler_FreeDataOperation:
{
FreePGPOUICheckboxDesc( context, inputDesc );
break;
}
case kPGPOptionHandler_CopyDataOperation:
{
PGPOUICheckboxDesc *outputDesc;
pgpAssertAddrValid( outputValue, PGPOptionValue );
pgpAssertAddrValid( outputValueSize, PGPSize );
err = CopyPGPOUICheckboxDesc( context, inputDesc, &outputDesc );
if( IsntPGPError( err ) )
{
outputValue->asPtr = outputDesc;
*outputValueSize = sizeof( *outputDesc );
}
break;
}
default:
{
err = kPGPError_UnknownRequest;
break;
}
}
return( err );
}
static const PGPOptionType sCheckboxOptionSet[] =
{
kPGPOptionType_Checkbox,
kPGPOptionType_PopupList
};
PGPOptionListRef
PGPOUICheckbox(
PGPContextRef context,
PGPUInt32 itemID,
const char *title,
const char *description, /* Can be NULL */
PGPUInt32 initialValue,
PGPUInt32 *resultPtr,
PGPOptionListRef firstOption, ...)
{
PGPOptionListRef optionList = kInvalidPGPOptionListRef;
PGPBoolean disposeOptionParams = FALSE;
pgpAssert( pgpContextIsValid( context ) );
pgpAssert( IsntNull( title ) );
pgpAssert( IsntNull( resultPtr ) );
/* Booleanize value */
if( initialValue != 0 )
initialValue = 1;
if( IsntNull( resultPtr ) )
*resultPtr = initialValue;
if( pgpContextIsValid( context ) &&
IsntNull( title ) &&
IsntNull( resultPtr ) )
{
PGPOUICheckboxDesc descriptor;
PGPOUICheckboxDesc *allocatedDesc;
char emptyString[] = "";
pgpClearMemory( &descriptor, sizeof( descriptor ) );
descriptor.itemID = itemID;
descriptor.valuePtr = resultPtr;
descriptor.title = title;
if( IsntNull( description ) )
{
descriptor.description = description;
}
else
{
descriptor.description = emptyString;
}
if( IsntPGPError( CopyPGPOUICheckboxDesc( context, &descriptor,
&allocatedDesc ) ) )
{
PGPOptionValue value;
PGPOptionListRef subOptions;
va_list args;
value.asPtr = allocatedDesc;
va_start( args, firstOption );
subOptions = pgpBuildOptionListArgs( context, FALSE, firstOption,
args );
va_end( args );
optionList = pgpCreateCustomValueOptionList( context,
kPGPOptionType_Checkbox,
kPGPOptionFlag_Default,
&value, sizeof( *allocatedDesc ),
subOptions, CheckboxOptionHandlerProc );
if( pgpGetOptionListError( optionList ) == kPGPError_NoErr &&
pgpOptionListIsReal( subOptions ) )
{
PGPError err;
err = pgpCheckOptionsInSet( subOptions, sCheckboxOptionSet,
elemsof( sCheckboxOptionSet ) );
if( IsPGPError( err ) )
{
pgpSetOptionListError( optionList, err );
}
}
}
else
{
optionList = kPGPOutOfMemoryOptionListRef;
disposeOptionParams = TRUE;
}
}
else
{
disposeOptionParams = TRUE;
}
if( disposeOptionParams )
{
va_list args;
va_start( args, firstOption );
pgpFreeVarArgOptionList( firstOption, args);
va_end( args );
optionList = kPGPBadParamsOptionListRef;
}
return( optionList );
}
static void
FreePGPOUIPopupListDesc(
PGPContextRef context,
PGPOUIPopupListDesc *desc)
{
pgpAssertAddrValid( desc, PGPOUIPopupListDesc );
if( IsntNull( desc->title ) )
{
pgpContextMemFree( context, (void *) desc->title );
desc->title = NULL;
}
if( IsntNull( desc->description ) )
{
pgpContextMemFree( context, (void *) desc->description );
desc->description = NULL;
}
if( IsntNull( desc->listItems ) )
{
PGPUInt32 listIndex;
for( listIndex = 0; listIndex < desc->numListItems; listIndex++ )
{
if( IsntNull( desc->listItems[listIndex] ) )
{
pgpContextMemFree( context,
(void *) desc->listItems[listIndex] );
desc->listItems[listIndex] = NULL;
}
}
pgpContextMemFree( context, (void *) desc->listItems );
desc->listItems = NULL;
}
pgpContextMemFree( context, desc );
}
static char **
CopyPopupListItems(
PGPContextRef context,
const PGPOUIPopupListDesc *srcDesc)
{
char **listItems;
PGPError err = kPGPError_NoErr;
pgpAssertAddrValid( srcDesc, PGPOUIPopupListDesc );
pgpAssert( srcDesc->numListItems > 0 );
pgpAssertAddrValid( srcDesc->listItems, char * );
listItems = (char **) pgpContextMemAlloc( context, srcDesc->numListItems *
sizeof( srcDesc->listItems[0] ),
kPGPMemoryMgrFlags_Clear );
if( IsntNull( listItems ) )
{
PGPUInt32 listIndex;
for( listIndex = 0; listIndex < srcDesc->numListItems; listIndex++ )
{
if( IsntNull( srcDesc->listItems[listIndex] ) )
{
listItems[listIndex] = pgpAllocCString( context,
srcDesc->listItems[listIndex] );
if( IsNull( listItems[listIndex] ) )
{
err = kPGPError_OutOfMemory;
break;
}
}
}
if( IsPGPError( err ) )
{
for( listIndex = 0; listIndex < srcDesc->numListItems; listIndex++ )
{
if( IsntNull( listItems[listIndex] ) )
pgpContextMemFree( context, listItems[listIndex] );
}
pgpContextMemFree( context, listItems );
listItems = NULL;
}
}
return( listItems );
}
static PGPError
CopyPGPOUIPopupListDesc(
PGPContextRef context,
const PGPOUIPopupListDesc *srcDesc,
PGPOUIPopupListDesc **destDesc)
{
PGPError err = kPGPError_OutOfMemory;
PGPOUIPopupListDesc *outDesc;
pgpAssertAddrValid( srcDesc, PGPOUIPopupListDesc );
pgpAssertAddrValid( destDesc, PGPOUIPopupListDesc * );
*destDesc = NULL;
outDesc = (PGPOUIPopupListDesc *) pgpContextMemAlloc( context,
sizeof( *outDesc ), kPGPMemoryMgrFlags_Clear );
if( IsntNull( outDesc ) )
{
*outDesc = *srcDesc;
pgpAssertAddrValid( srcDesc->title, char );
pgpAssertAddrValid( srcDesc->description, char );
outDesc->title = pgpAllocCString( context, srcDesc->title );
outDesc->description = pgpAllocCString( context,
srcDesc->description );
outDesc->listItems = (const char **) CopyPopupListItems( context, srcDesc );
if( IsntNull( outDesc->title ) &&
IsntNull( outDesc->description ) &&
IsntNull( outDesc->listItems ) )
{
err = kPGPError_NoErr;
}
else
{
FreePGPOUIPopupListDesc( context, outDesc );
outDesc = NULL;
}
}
*destDesc = outDesc;
return( err );
}
static PGPError
PopupListOptionHandlerProc(
PGPContextRef context,
PGPOptionHandlerOperation operation,
PGPOptionType type,
PGPOptionValue inputValue,
PGPSize inputValueSize,
PGPOptionValue *outputValue,
PGPSize *outputValueSize)
{
PGPError err = kPGPError_NoErr;
PGPOUIPopupListDesc *inputDesc;
pgpAssert( inputValueSize == sizeof( *inputDesc ) );
(void) type;
(void) inputValueSize;
inputDesc = (PGPOUIPopupListDesc *) inputValue.asPtr;
pgpAssertAddrValid( inputDesc, PGPOUIPopupListDesc );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -