📄 creport.cpp
字号:
#include "CReport.h"
#include "str.h"
#include "utilcpp.h"
#include "error.h"
#include "utilcpp.h"
#include "str.h"
#include "def.h"
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <fcntl.h>
#include <unix.h>
#define MEM_SIZESTART 10000
#define MEM_SIZEEXPAND 5000
#define MAX_CHAR_LINE 255
CReport::CReport()
{
}
CReport::~CReport()
{
long l;
delete pMem;
for (l = lLine; l > 0; l--)
pLineArray->DeleteItem(l);
delete pLineArray;
}
CReport::CReport(CView *pView, CBureaucrat *pBureau)
: CPanorama(pView, pBureau)
{
int nHeight;
int nWidth;
pMem = new CMemory();
pMem->Allocate(MEM_SIZESTART);
lReportLen = 0;
lLine = 0;
pText = NULL;
pLineArray = new CArray(sizeof(long), 10);
pLineArray->Add(new long(0));
nWidth = GetCharWidth();
nHeight = GetCharHeight();
GetSteps((short*)&nWidth, (short*)&nHeight);
}
void CReport::AppendMsg(char *str)
{
LongRect lr, lr2;
LongPt lp;
int nWidth, nHeight;
CWindow *pWnd;
while (lReportLen + strlen(str) >= pMem->GetSize())
{ /*Need to reallocate memory*/
pMem->Reallocate(lReportLen + MEM_SIZEEXPAND);
}
pText = (char *)pMem->GetPtr();
strcpy(pText + lReportLen, str);
pMem->ReleasePtr();
lLine++;
pLineArray->Add(new long(lReportLen + strlen(str)));
nWidth = GetCharWidth();
nHeight = GetCharHeight();
lr.left = 0;
lr.top = 0;
lr.bottom = lLine * nHeight + 10L;
lr.right = MAX_CHAR_LINE * nWidth;
SetBounds(&lr);
pWnd = GetWindow();
pWnd->GetInterior(&lr2);
if (lr.bottom > lr2.bottom)
{
SetLongPt(&lp, 0, lr.bottom);
Scroll/*To*/(/*&lp, TRUE*/0, nHeight, TRUE);
}
lr.top = (lLine-1L) * nHeight;
lr.bottom = lLine * nHeight;
RefreshLongRect(&lr);
lReportLen += strlen(str);
}
int CReport::GetCharHeight()
{
return 13;
}
int CReport::GetCharWidth()
{
return 8;
}
void CReport::DrawCharLine(long lPos)
{
long lCurLine;
lCurLine = GetLineNumber(lPos);
DrawLine(lCurLine);
}
void CReport::DrawLine(long lCurLine)
{
char str_line[MAX_CHAR_LINE], *str_end;
long length, lPos;
pText = (char*)pMem->GetPtr();
pLineArray->GetArrayItem(&lPos, lCurLine);
str_end = strchr(pText + lPos, chr_RT2);
if (str_end != NULL)
{
length = str_end - pText - lPos;
if (length >= MAX_CHAR_LINE)
length = MAX_CHAR_LINE - 1;
}
else
length = strlen(pText) - lPos;
strncpy(str_line, pText + lPos, length);
str_line[length] = 0;
c2pstr(str_line);
pMem->ReleasePtr();
MoveTo(0, lCurLine*GetCharHeight());
DrawString((unsigned char const *)str_line);
}
void CReport::Draw(Rect *area)
{
int nHeight, nWidth;
long l, lstart, lend;
nHeight = GetCharHeight();
nWidth = GetCharWidth();
lstart = area->top / GetCharHeight();
lend = area->bottom / GetCharHeight() + 1L;
if (lstart < 1)
lstart = 1;
if (lend > lLine)
lend = lLine;
for (l = lstart; l <= lend; l++)
{
DrawLine(l);
}
}
long CReport::GetLineNumber(long lPos)
{
long l, *pItem;
l = 0L;
do
{
l++;
pLineArray->GetArrayItem(pItem, l);
}
while (l <= lLine && *pItem > lPos);
return l;
}
int CReport::Save(char *filename)
{
FILE* nf;
long lwritten;
nf = fopen(filename, "w");
/*Create the file in binary mode, overwites it if it doesn't exist*/
if (nf == NULL)
{
Msg(-1, str_ERR_FILE_OPEN, errno);
return ERR_FILE_OPEN;
}
pText = (char *)pMem->GetPtr();
lwritten = fwrite(pText, sizeof(char), lReportLen, nf);
pMem->ReleasePtr();
if (lwritten != lReportLen)
{
Msg(0, str_ERR_FILE_WRITE, lwritten, lReportLen);
}
if (fclose(nf) == -1)
{
Msg(0, str_ERR_FILE_CLOSE);
}
Msg(0, str_SAVE_NUM, lwritten);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -