📄 tempest.c
字号:
/*____________________________________________________________________________
Copyright (C) 1997 Network Associates Inc. and affiliated companies.
All rights reserved.
$Id: Tempest.c,v 1.16 1999/03/30 17:24:50 wjb Exp $
____________________________________________________________________________*/
#include "precomp.h"
#include "pgpIO.h"
#include "pgpMemoryIO.h"
#include "pgpWordWrap.h"
#define DEACTIVATETIMERID 100
#define DEACTIVATETIME 50
#define MINDLGX 300
#define MINDLGY 200
#define MODX 16
#define XMARGIN 2
#define YMARGIN 1
#define TABWIDTH 4
// This is our global tempest viewer variable structure
// used in case we ever need to make this reentrant. Globals
// are Very Bad (tm).
typedef struct _GTV {
HWND hdlg;
HWND hwndLB;
char *pInput;
HBITMAP hAlphaBmp;
HBITMAP hTempABmp;
HBITMAP hTempBBmp;
HBITMAP hTempCBmp;
HBITMAP hTempDBmp;
HFONT hFixedWidthFont;
HBRUSH hBackBrush;
int LtrX;
int LtrY;
COLORREF BackColor;
COLORREF TextColor;
BOOL bDoTempest;
} GTV;
PGPError
PGPtempestWrapBuffer (
PGPContextRef context,
LPSTR szInText,
PGPUInt16 wrapColumn,
LPSTR* pszOutText)
{
PGPError err = kPGPError_NoErr;
PGPIORef inRef, outRef;
PGPMemoryMgrRef memMgr;
PGPFileOffset outSize;
PGPSize outRead;
INT InSize;
PGPMemoryMgrRef memmgr;
memmgr = PGPGetContextMemoryMgr (context);
outRead = 0;
err = PGPNewMemoryMgr ( 0, &memMgr);
if (IsntPGPError (err))
{
PGPNewMemoryIO (
memMgr,
(PGPMemoryIORef *)(&inRef));
InSize = strlen (szInText);
PGPIOWrite (inRef,
InSize,
szInText);
PGPIOFlush (inRef);
PGPIOSetPos (inRef,0);
PGPNewMemoryIO (
memMgr,
(PGPMemoryIORef *)(&outRef));
err = pgpWordWrapIO(
inRef,outRef,
wrapColumn,
"\r\n");
if (IsntPGPError (err))
{
INT memamt;
PGPIOGetPos (outRef, &outSize);
memamt = (INT)outSize+1;
*pszOutText = (CHAR *)PGPNewSecureData (memmgr, memamt, 0);
if (*pszOutText)
{
memset (*pszOutText, 0x00, memamt);
PGPIOSetPos (outRef,0);
PGPIORead (outRef,
(INT)outSize,
*pszOutText,
&outRead);
PGPIOFlush (outRef);
}
else err = kPGPError_OutOfMemory;
}
PGPFreeIO (inRef);
PGPFreeIO (outRef);
}
PGPFreeMemoryMgr (memMgr);
return err;
}
void SizeTempest(HWND hdlg,int Width,int Height)
{
InvalidateRect(GetDlgItem(hdlg, IDC_TEMPESTLIST),NULL,TRUE);
MoveWindow(GetDlgItem(hdlg, IDC_TEMPESTLIST),
10,10,
Width-20,Height-45,
TRUE);
InvalidateRect(GetDlgItem(hdlg, IDC_TEMPESTFONT),NULL,TRUE);
MoveWindow(GetDlgItem(hdlg, IDC_TEMPESTFONT),
10,Height-25,
300,15,
TRUE);
}
//
// DrawListViewItem
//
// This routine, given a standard Windows LPDRAWITEMSTRUCT, draws the
// elements of our custom listview.
void DrawListBoxItem(GTV *gtv,LPDRAWITEMSTRUCT lpDrawItem)
{
HDC mDC;
UINT i;
unsigned char *szString;
unsigned char StringIndex;
int xCoord,yCoord;
int pos;
srand( (unsigned)time( NULL ) );
// Create a memory DC for bitmap work
mDC = CreateCompatibleDC( lpDrawItem->hDC );
if(!gtv->bDoTempest)
{
SelectObject( mDC, gtv->hAlphaBmp);
}
FillRect(lpDrawItem->hDC,&(lpDrawItem->rcItem),gtv->hBackBrush);
szString=(char *)lpDrawItem->itemData;
if(szString==NULL)
return;
pos=0;
i=0;
while((szString[i]!=0)&&(szString[i]!='\n'))
{
StringIndex=(unsigned char)szString[i];
if(StringIndex=='\t')
{
pos=((pos/TABWIDTH)+1)*TABWIDTH;
}
else
{
// Avoid the characters outside the range of our font
if(((StringIndex>=32)&&(StringIndex<=127))||
((StringIndex>=160)&&(StringIndex<=255)))
{
if(StringIndex<=127)
{
StringIndex=StringIndex-32;
}
else
{
StringIndex=StringIndex-160+6*MODX;
}
// Randomly select through jittered fonts to
// confuse snoopers further
if(gtv->bDoTempest)
{
switch((4*rand())/RAND_MAX)
{
case 0:
SelectObject( mDC, gtv->hTempABmp);
break;
case 1:
SelectObject( mDC, gtv->hTempBBmp);
break;
case 2:
SelectObject( mDC, gtv->hTempCBmp);
break;
default:
SelectObject( mDC, gtv->hTempDBmp);
break;
}
}
xCoord=(StringIndex)%MODX;
yCoord=(StringIndex)/MODX;
BitBlt(lpDrawItem->hDC,// handle to destination device context
lpDrawItem->rcItem.left + XMARGIN + pos * gtv->LtrX,
// x-coordinate of destination rectangle's upper-left
lpDrawItem->rcItem.top + YMARGIN,
// x-coordinate of destination rectangle's upper-left
gtv->LtrX, // width of destination rectangle
gtv->LtrY, // height of destination rectangle
mDC, // handle to source device context
xCoord*gtv->LtrX,
// x-coordinate of source rectangle's upper-left
yCoord*gtv->LtrY,
// y-coordinate of source rectangle's upper-left
SRCCOPY);
}
pos++;
}
i++;
}
// Kill off the memory DC, unlocking passed BMP
DeleteDC( mDC );
return;
}
// Main_OnDrawItem
//
// Entry function for the message handler. Basically, we want to draw
// the whole thing no matter what.
BOOL Main_OnDrawItem(GTV *gtv, const DRAWITEMSTRUCT * lpDrawItem)
{
// Make sure the control is the listview control
if (lpDrawItem->CtlType != ODT_LISTBOX)
return FALSE;
switch (lpDrawItem->itemAction)
{
case ODA_DRAWENTIRE:
case ODA_FOCUS:
case ODA_SELECT:
DrawListBoxItem(gtv,(LPDRAWITEMSTRUCT)lpDrawItem);
break;
}
return TRUE;
}
// Main_OnMeasureItem
//
// Entry function for the message handler. We need to get the width and
// height of the font we're using.
void Main_OnMeasureItem(GTV *gtv, MEASUREITEMSTRUCT * lpMeasureItem)
{
// Make sure the control is the listview control
if (lpMeasureItem->CtlType != ODT_LISTBOX)
return;
// Add a little extra space between items
lpMeasureItem->itemHeight = gtv->LtrY + YMARGIN;
}
UINT TempestStringWidth(char *szString)
{
UINT pos,i;
pos=0;
i=0;
while((szString[i]!=0)&&(szString[i]!='\n'))
{
// Handle Tabs
if(szString[i]=='\t')
{
pos=((pos/TABWIDTH)+1)*TABWIDTH;
}
else
{
pos++;
}
i++;
}
return pos;
}
void AddListBoxLines(GTV *gtv)
{
int width,maxwidth;
char *szNew,*szOld;
maxwidth=0;
szNew=gtv->pInput;
while(szNew!=0)
{
szOld=szNew;
szNew=strstr(szOld,"\n");
if(szNew!=0)
{
szNew++;
}
width=TempestStringWidth(szOld)*gtv->LtrX+2*XMARGIN;
if(width>maxwidth)
{
maxwidth=width;
}
SendMessage(gtv->hwndLB,
LB_ADDSTRING,0,(LPARAM)szOld);
}
SendMessage(gtv->hwndLB,
LB_SETHORIZONTALEXTENT,(WPARAM)maxwidth,0);
}
void RedoTempestList(GTV *gtv)
{
RECT rc;
if(gtv->hwndLB!=NULL)
DestroyWindow(gtv->hwndLB);
gtv->hwndLB=CreateWindowEx (WS_EX_CLIENTEDGE,"listbox", NULL,
WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL |
LBS_OWNERDRAWFIXED | LBS_NOINTEGRALHEIGHT | WS_TABSTOP,
0,0,0,0,
gtv->hdlg, (HMENU)IDC_TEMPESTLIST,
(HINSTANCE) g_hinst,
NULL) ;
// Size the viewer
GetClientRect(gtv->hdlg,&rc);
SizeTempest(gtv->hdlg,rc.right-rc.left,rc.bottom-rc.top);
AddListBoxLines(gtv);
}
// Get rid of all drawing elements to clean up
void UninitFontBitmap(GTV *gtv)
{
if(gtv->hFixedWidthFont!=NULL)
DeleteObject(gtv->hFixedWidthFont);
gtv->hFixedWidthFont=NULL;
if(gtv->hBackBrush!=NULL)
DeleteObject(gtv->hBackBrush);
gtv->hBackBrush=NULL;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -