⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pgpoptionsdialog.cpp

📁 pgp soucecode pgp soucecode
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*____________________________________________________________________________
	Copyright (C) 1997 Network Associates Inc. and affiliated companies.
	All rights reserved.
	
	$Id: PGPOptionsDialog.cpp,v 1.32 1999/03/31 23:22:46 wjb Exp $
____________________________________________________________________________*/

// Public includes:

#include "PGPui32.h"
#include "pgpDialogs.h"
#include "pgpSDKUILibPriv.h"

#define CHECKWIDTH 19
#define INDENT 19
#define LINESPERCONTROL 1.60
#define COMBOSPACER 5
#define COMBOYADJ 3

extern HHOOK hhookKeyboard;
extern HHOOK hhookMouse;

WNDPROC origCheckBoxProc;
WNDPROC origComboBoxProc;

#define OI_CHECKBOX 1
#define OI_COMBOBOX 2

#define MINDLGX 200
#define MINDLGY 200

typedef struct _OPTIONINFO
{
	DWORD dwType;
	HWND hwndOption;
	BOOL bDisableListBoxesIfChecked;
	BOOL bDisableChildrenIfUnchecked;
	struct _OPTIONINFO *poiParent;
	struct _OPTIONINFO *nextSibling;
	struct _OPTIONINFO *nextChild;
	DWORD dwTempValue;
	DWORD *pdwFinalValue;
} OPTIONINFO, *POPTIONINFO;

typedef struct _OPTDLG
{
	PGPOptionListRef options;
	POPTIONINFO headpoi;
	int cxChar;
	int cxCaps;
	int cyChar;
	int MaxWidth;
	int NumLines;
	int cxClient;
	int cyClient;
	int iVscrollPos;
	int iVscrollMax;
	int iHscrollPos;
	int iHscrollMax;
	int iVscrollInc;
	int iHscrollInc;
} OPTDLG, *POPTDLG;

typedef struct _DLGDATA
{
	CPGPOptionsDialogOptions * options;
	HWND hwndOptions;
} DLGDATA, *PDLGDATA;

void EnableOrDisableChildren(POPTIONINFO poi,BOOL bEnable)
{
	POPTIONINFO poiParent;
	POPTIONINFO poiChild;

	if(poi==NULL)
		return;

	// If we check the box, the parent must also be checked
	poiParent=poi->poiParent;

	while(poiParent!=NULL)
	{
		if(bEnable)
		{
			poiParent->dwTempValue=TRUE;
			Button_SetCheck(poiParent->hwndOption,poiParent->dwTempValue);
		}

		if(poiParent->bDisableListBoxesIfChecked)
		{
			HWND hDlg;

			hDlg=GetParent(GetParent(poiParent->hwndOption));

			EnableWindow(GetDlgItem(hDlg,IDC_USER_ID_LIST),!poiParent->dwTempValue);
						
			EnableWindow(GetDlgItem(hDlg,IDC_RECIPIENT_LIST),!poiParent->dwTempValue);
		}

		poiParent=poiParent->poiParent;
	}

	poiChild=poi->nextChild;

	// If we uncheck the box, the siblings must be unchecked
	while(poiChild!=NULL)
	{
		// Loop through the siblings

//		We no longer do the enable disable thing, but keep this
//		code here just in case...
//		EnableWindow(poiChild->hwndOption,bEnable);

		if(!bEnable)
		{
			poiChild->dwTempValue=*(poiChild->pdwFinalValue);
			Button_SetCheck(poiChild->hwndOption,poiChild->dwTempValue);
		}

		// Go through the children
		EnableOrDisableChildren(poiChild->nextChild,bEnable);

		poiChild=poiChild->nextSibling;
	}
}

// Clean up copy of Option Data for CheckBoxes
LRESULT WINAPI MyCheckBoxWndProc(HWND hwnd, UINT msg, 
                                 WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
		case WM_DESTROY:
		{
			POPTIONINFO poi;

			poi=(POPTIONINFO)GetWindowLong(hwnd,GWL_USERDATA);
			free(poi);
			break;
		}
	}

    //  Pass all non-custom messages to old window proc
    return CallWindowProc(origCheckBoxProc, hwnd, 
                           msg, wParam, lParam ) ;
}

// Clean up copy of Option Data for ComboBoxes
LRESULT WINAPI MyComboBoxWndProc(HWND hwnd, UINT msg, 
                                 WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
		case WM_DESTROY:
		{
			POPTIONINFO poi;

			poi=(POPTIONINFO)GetWindowLong(hwnd,GWL_USERDATA);
			free(poi);
			break;
		}
	}

    //  Pass all non-custom messages to old window proc
    return CallWindowProc(origComboBoxProc, hwnd, 
                           msg, wParam, lParam ) ;
}

int NumLines (HDC hdc, char *pText, int Width)
{
	int  iBreakCount ;
	PSTR pBegin, pEnd ;
	SIZE size ;
	int numrows;

	numrows = 0;
	do                               // for each text line
	{
		iBreakCount = 0 ;
	
		pBegin = pText ;

		do                           // until the line is known
		{
			pEnd = pText ;

			while (*pText != '\0' && *pText++ != ' ') ;
			if (*pText == '\0')
				break ;
                                     // for each space, calculate extents
			iBreakCount++ ;
			SetTextJustification (hdc, 0, 0) ;
			GetTextExtentPoint32 (hdc, pBegin, pText - pBegin - 1, &size) ;
		}
		while ((int) size.cx < Width) ;

		iBreakCount-- ;
		while (*(pEnd - 1) == ' ')   // eliminate trailing blanks
		{
			pEnd-- ;
			iBreakCount-- ;
		}

		if (*pText == '\0' || iBreakCount <= 0)
			pEnd = pText;

		SetTextJustification (hdc, 0, 0) ;
		GetTextExtentPoint32 (hdc, pBegin, pEnd - pBegin, &size) ;

		numrows++;
		pText = pEnd ;
	} while (*pText);

	return numrows;
}

int GetClientWidth(HWND hwnd)
{
	RECT rc;

	GetClientRect(hwnd,&rc);
	return(rc.right-rc.left-GetSystemMetrics(SM_CXVSCROLL));
}

HWND MakeDescription(HWND hwndParent,
				 HDC hdc,
				 HFONT hFont,
				 int ID,
				 const char *String,
				 int x,int *y,
				 int MaxWidth)
{
	int NumberOfLines;
	HWND hwndDesc;
	SIZE size;

	if(*String==0)
		return NULL;

	GetTextExtentPoint32(hdc,String,strlen(String),&size);

	NumberOfLines=NumLines(hdc,(char *)String,MaxWidth-INDENT-x);

	hwndDesc = CreateWindow ("static", String,
                              WS_CHILDWINDOW | WS_VISIBLE | SS_LEFT,
                              size.cy+INDENT+x,*y,
                              MaxWidth-INDENT-x,size.cy*NumberOfLines,
                              hwndParent, (HMENU) ID,
                              gPGPsdkUILibInst, NULL) ;

	*y=(int)((double)(*y)+
		((double)LINESPERCONTROL + (double)NumberOfLines - (double)1) * (double)size.cy);

	SendMessage(hwndDesc, WM_SETFONT,(WPARAM)hFont, MAKELPARAM(TRUE, 0));

	return hwndDesc;
}

POPTIONINFO MakeCheckBox(HWND hwndParent,
				 POPTIONINFO poiParent,
				 HDC hdc,
				 HFONT hFont,
				 PGPOption *optionData,
				 int x,int *y,
				 int MaxWidth)
{
	HWND hwndCheckBox;
	SIZE size;
	PGPOUICheckboxDesc *Descriptor;
	POPTIONINFO poi;

	poi=(POPTIONINFO)malloc(sizeof(OPTIONINFO));
	memset(poi,0x00,sizeof(OPTIONINFO));
	poi->dwType=OI_CHECKBOX;
	poi->poiParent=poiParent;

	Descriptor = (PGPOUICheckboxDesc *) optionData->value.asPtr;
	poi->pdwFinalValue=(DWORD *)Descriptor->valuePtr;
	poi->dwTempValue=*(poi->pdwFinalValue);

	GetTextExtentPoint32(hdc,Descriptor->title,strlen(Descriptor->title),&size);

	hwndCheckBox = CreateWindow ("button", Descriptor->title,
		WS_CHILD | WS_VISIBLE | BS_CHECKBOX | WS_TABSTOP,
        size.cy+x,*y,
        size.cx+CHECKWIDTH,size.cy,
        hwndParent, (HMENU) Descriptor->itemID,
        gPGPsdkUILibInst, NULL) ;

	*y=(int)((double)*y + (double)size.cy * (double)LINESPERCONTROL);

	SendMessage(hwndCheckBox, WM_SETFONT,
		(WPARAM)hFont, MAKELPARAM(TRUE, 0));

	Button_SetCheck (hwndCheckBox,poi->dwTempValue);

	if(Descriptor->description!=NULL)
		MakeDescription(hwndParent,hdc,hFont,
			5000+Descriptor->itemID,Descriptor->description,x,y,MaxWidth);

	SetWindowLong(hwndCheckBox, GWL_USERDATA, (DWORD)poi);    
	origCheckBoxProc=SubclassWindow(hwndCheckBox,MyCheckBoxWndProc);  

	// Hardcode in the conventional encryption disabling
	// (Ugly I know, but there is no API for this)
	if(!strcmp(Descriptor->title,"Conventional &Encryption"))
	{
		HWND hDlg;

		hDlg=GetParent(hwndParent);

		EnableWindow(GetDlgItem(hDlg,IDC_USER_ID_LIST),!poi->dwTempValue);
						
		EnableWindow(GetDlgItem(hDlg,IDC_RECIPIENT_LIST),!poi->dwTempValue);

		poi->bDisableListBoxesIfChecked=TRUE;
	}
	
	poi->bDisableChildrenIfUnchecked=TRUE;

	poi->hwndOption=hwndCheckBox;

	return poi;
}

int MeasureComboBox(HDC hdc,PGPOUIPopupListDesc *Descriptor)
{
	SIZE size;
	unsigned int itemIndex;
	int ComboWidth;

	ComboWidth=0;

	// Find the longest text element
	for(itemIndex = 0; itemIndex < Descriptor->numListItems; itemIndex++)
	{
		if( IsntNull( Descriptor->listItems[itemIndex] ) )
		{
			GetTextExtentPoint32(hdc,Descriptor->listItems[itemIndex],
				strlen(Descriptor->listItems[itemIndex]),&size);
			if(size.cx>ComboWidth)ComboWidth=size.cx;
		}
	}

	ComboWidth=ComboWidth+2*GetSystemMetrics(SM_CXVSCROLL);

	return ComboWidth;
}

POPTIONINFO MakeComboBox(HWND hwndParent,
				 POPTIONINFO poiParent,
				 HDC hdc,
				 HFONT hFont,
				 PGPOption *optionData,				 
				 int x,int *y,
				 int MaxWidth)
{
	HWND hwndText,hwndComboBox;
	SIZE size;
	unsigned int itemIndex;
	PGPOUIPopupListDesc *Descriptor;
	POPTIONINFO poi;

	poi=(POPTIONINFO)malloc(sizeof(OPTIONINFO));
	memset(poi,0x00,sizeof(OPTIONINFO));
	poi->dwType=OI_COMBOBOX;
	poi->poiParent=poiParent;

	Descriptor = (PGPOUIPopupListDesc *) optionData->value.asPtr;
	poi->pdwFinalValue=(DWORD *)Descriptor->valuePtr;
	poi->dwTempValue=*(poi->pdwFinalValue);

	GetTextExtentPoint32(hdc,Descriptor->title,strlen(Descriptor->title),&size);

	hwndText = CreateWindow ("static", Descriptor->title,
		WS_CHILDWINDOW | WS_VISIBLE | SS_LEFT ,
		size.cy+x,*y,
		size.cx,size.cy,
		hwndParent, (HMENU) (1000+Descriptor->itemID),
		gPGPsdkUILibInst, NULL) ;

	SendMessage(hwndText, WM_SETFONT,
		(WPARAM)hFont, MAKELPARAM(TRUE, 0));

	hwndComboBox = CreateWindow ("combobox",NULL,
		WS_CHILD | WS_VISIBLE | CBS_DROPDOWN | WS_TABSTOP,
		size.cy+size.cx+COMBOSPACER+x,*y-COMBOYADJ,
		MeasureComboBox(hdc,Descriptor),size.cy*6,
        hwndParent, (HMENU)Descriptor->itemID,
		gPGPsdkUILibInst, NULL) ;

		*y=(int)((double)*y + (double)size.cy * (double)(LINESPERCONTROL));

	for(itemIndex = 0; itemIndex < Descriptor->numListItems; itemIndex++)
	{
		if( IsntNull( Descriptor->listItems[itemIndex] ) )
		{
			SendMessage (hwndComboBox, CB_ADDSTRING, 0, 
				(LPARAM)Descriptor->listItems[itemIndex]);
		}
	}

	SendMessage(hwndComboBox,CB_SETCURSEL,
		(WPARAM)(poi->dwTempValue-1),0);

	SendMessage(hwndComboBox, WM_SETFONT,
		(WPARAM)hFont, MAKELPARAM(TRUE, 0));

	if(Descriptor->description!=NULL)
		MakeDescription(hwndParent,hdc,hFont,
			5000+Descriptor->itemID,Descriptor->description,x,y,MaxWidth);

	SetWindowLong(hwndComboBox, GWL_USERDATA, (DWORD)poi);    
	origComboBoxProc=SubclassWindow(hwndComboBox,MyComboBoxWndProc);  

	poi->hwndOption=hwndComboBox;

	return poi;
}

int MeasureOptionsControls(HDC hdc,int xindent,PGPOptionListRef options)
{
	PGPUInt32	optionIndex	= 0;
	PGPOption	optionData;
	int MaxWidth;
	int ChildWidth;
	SIZE size;

	if(options==NULL)
		return(0);

	MaxWidth=0;

	/* Build list of checkboxes and/or popups */
	
	while( IsntPGPError( pgpGetIndexedOption( options,
					optionIndex, FALSE, &optionData ) ) )
	{
		if( optionData.type == kPGPOptionType_Checkbox )
		{
			PGPOUICheckboxDesc		*descriptor;
			
			descriptor = (PGPOUICheckboxDesc *) optionData.value.asPtr;

			GetTextExtentPoint32(hdc,descriptor->title,strlen(descriptor->title),&size);
			size.cx=size.cx+xindent;

			if(size.cx>MaxWidth)MaxWidth=size.cx;
		}
		else if( optionData.type == kPGPOptionType_PopupList )
		{
			PGPOUIPopupListDesc		*descriptor;
			
			descriptor = (PGPOUIPopupListDesc *) optionData.value.asPtr;

			GetTextExtentPoint32(hdc,descriptor->title,strlen(descriptor->title),&size);
			size.cx=size.cx+xindent;
			size.cx=size.cx+COMBOSPACER;
			size.cx=size.cx+MeasureComboBox(hdc,descriptor);

			if(size.cx>MaxWidth)MaxWidth=size.cx;
		}		

		// Get the max width of the indented children
		ChildWidth=MeasureOptionsControls(hdc,xindent+INDENT,optionData.subOptions);

		if(ChildWidth>MaxWidth)
			MaxWidth=ChildWidth;

		++optionIndex;
	}

	return MaxWidth;
}

	POPTIONINFO
CreateOptionsControls(HWND hwndOptionsControl,
					  POPTIONINFO poiParent,
					  HDC hdc,HFONT hFont,
					  int xpos,int *ypos,int MaxWidth,
					  PGPOptionListRef options)
{
	PGPError	err 		= kPGPError_NoErr;
	PGPUInt32	optionIndex	= 0;
	PGPOption	optionData;
	POPTIONINFO FirstOption;
	POPTIONINFO OldOption;
	POPTIONINFO poi;

	if(options==NULL)
		return(NULL);

	FirstOption=OldOption=NULL;

	/* Build list of checkboxes and/or popups */
	
	while( IsntPGPError( pgpGetIndexedOption( options,
					optionIndex, FALSE, &optionData ) ) )
	{
		if( optionData.type == kPGPOptionType_Checkbox )
		{
			poi = MakeCheckBox(
				hwndOptionsControl,
				poiParent,
				hdc,hFont,
				&optionData,
				xpos,ypos,MaxWidth);
		}
		else if( optionData.type == kPGPOptionType_PopupList )
		{
			poi = MakeComboBox(

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -