📄 cpage.cpp
字号:
}
////////////////////////////////////////////////////////////////////////////
// Desc: Creates a moveable print region
// params: location of region in 4 points
// Returns: Pointer to the new region or a NULL
///////////////////////////////////////////////////////////////////////////
CPrintRegion* CPage::CreateRegion(double ptop,double pleft,double pbottom, double pright,UINT Fill)
{
ConvertArea(ptop,pleft,pbottom,pright);
return CreateRegion((int) ptop,(int) pleft,(int) pbottom, (int) pright,Fill);
}
////////////////////////////////////////////////////////////////////////////
// Desc: Create a CprintRegion structure and maintain a list of created structures
// to free allocated memory when destructor runs
// params: bounding rectangle for the region
// Returns: pointer to the created structure
///////////////////////////////////////////////////////////////////////////
CPrintRegion* CPage::CreateRegion(int ptop,int pleft,int pbottom, int pright,UINT Fill)
{
CPrintRegion* pRegion= new CPrintRegion;
if(pRegion==NULL)
return pRegion;
pRegion->FillColor=Fill;
if( pRegion->Create(this,ptop,pleft,pright, pbottom,Fill)==FALSE)
{
delete pRegion;
return (CPrintRegion*)0;
}
m_RegionList.Add(pRegion);
return pRegion;
}
////////////////////////////////////////////////////////////////////////////
// Desc: Constructor for a table descriptor class
// params:
// Returns:
///////////////////////////////////////////////////////////////////////////
TABLEHEADER::TABLEHEADER()
{
SetSkip=0;
AutoSize=TRUE;
UseInches=FALSE;
PointSize=10;
LineSize=1;
NumColumns=2;
NumRows=2;
Border=TRUE;
VLines=TRUE;
HLines=TRUE;
NoHeader=HeaderOnly=FALSE;
HeaderLines=1;
NumPrintLines=1;
FillFlag=FILL_NONE;
StartRow=EndCol=StartCol=0;
pClsTable=NULL;
}
TABLEHEADER::~TABLEHEADER()
{
if(pClsTable != NULL)
delete pClsTable;
};
////////////////////////////////////////////////////////////////////////////
// Desc: Create and attach a table object to the print object. If the unit
// of measurment is in inches all conversions are done at this point.Once the
// table object is created it is displayed by the call to PrintTable.DO NOT CALL
// PRINTTABLE DIRECTLY ALWAYS USE THIS FUNCTION
// params: The table descriptor for the table
// Returns:
///////////////////////////////////////////////////////////////////////////
void CPage::Table(TABLEHEADER* TheTable)
{
PRTTYPE temp;
if(TheTable->NoHeader==TRUE)
TheTable->HeaderLines=0;
if(TheTable->UseInches)
{
TheTable->StartRow=ConvertToMappedUnits(TheTable->StartRow,VERTRES);
TheTable->StartCol=ConvertToMappedUnits(TheTable->StartCol,HORZRES);
TheTable->EndCol=ConvertToMappedUnits(TheTable->EndCol,HORZRES);
TheTable->EndRow=ConvertToMappedUnits(TheTable->EndRow,VERTRES);
for(int y=0;y < TheTable->NumColumns;++y)
TheTable->ColDesc[y].Width=ConvertToMappedUnits(TheTable->ColDesc[y].Width,HORZRES);
}
// check for horizontal margins
if(TheTable->EndCol > SetRightMargin(0))
return;
// create a table printing object and attach it to the table descriptor
CPrintTable* pTable=new CPrintTable(TheTable,this);
// pTable will be freed when the destructor for Thetable runs
// if you free it early there will be a system crash
TheTable->pClsTable=pTable;
temp=m_PrtDesc;
// print rhe table
pTable->PrintTable();
if(TheTable->UseInches)
TheTable->EndRow=ConvertToInches((int)TheTable->EndRow,VERTRES);
m_PrtDesc=temp;
}
////////////////////////////////////////////////////////////////////////////
// Desc: See CPage::Print () for details
// params: The table row and cloumn to print into, pointsixe textflags and variable arg list
// Returns:
///////////////////////////////////////////////////////////////////////////
void CPage::Print(TABLEHEADER* TheTable,int row,int col,int PointSize,UINT TextFlags,char* fmt,...)
{
CPrintTable* pTable=TheTable->pClsTable;
if(pTable==NULL)
return;
char* buff=new char[1000];
va_list t;
SaveState();
va_start(t,fmt);
vsprintf(buff,fmt,t);
if(TheTable->HeaderOnly==FALSE)
pTable->InsertItem(buff,row,col,PointSize,TextFlags);
else
pTable->InsertVirtualItem(buff,row,col,PointSize,TextFlags);
va_end(t);
delete[] buff;
m_nNextPos=m_PrtDesc.m_NextCharPos;
RestoreState();
}
////////////////////////////////////////////////////////////////////////////
// Desc: Print a disk based bitmapped imiage to the display
// params: The location in 4 points and full path to the imiage
// Returns:
///////////////////////////////////////////////////////////////////////////
void CPage::PrintBitMap(int top,int left,int bottom,int right,LPCSTR name)
{
extern BOOL WINAPI PrintTheBitMap(PRTTYPE *ps);
SaveState();
m_PrtDesc.rc.top=top;
m_PrtDesc.rc.bottom=bottom;
m_PrtDesc.rc.left=left;
m_PrtDesc.rc.right=right;
m_PrtDesc.Text=name;
PrintTheBitMap(&m_PrtDesc);
RestoreState();
}
////////////////////////////////////////////////////////////////////////////
// Desc: See above
// params:
// Returns:
///////////////////////////////////////////////////////////////////////////
void CPage::PrintBitMap(double top,double left,double bottom,double right,LPCSTR name)
{
extern BOOL WINAPI PrintTheBitMap(PRTTYPE *ps);
SaveState();
ConvertArea(top,left,bottom,right);
m_PrtDesc.rc.top=(int)top;
m_PrtDesc.rc.bottom=(int)bottom;
m_PrtDesc.rc.left=(int)left;
m_PrtDesc.rc.right=(int)right;
m_PrtDesc.Text=name;
PrintTheBitMap(&m_PrtDesc);
RestoreState();
}
////////////////////////////////////////////////////////////////////////////
// Helper class CPrintTable here
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
// Desc: places a value in a cell on the table defined as row,col. Do not call direct
// params:
// Returns:
///////////////////////////////////////////////////////////////////////////
void CPrintTable::InsertItem(LPCSTR Text,int row,int col,int PointSize,UINT TextFlags)
{
int y,SCol,ECol,Row,OldColor,OldMode;
int sz=GetVerticalSpacing();
if(row >= m_pTable->NumRows)
return;
if(PointSize < 1)
PointSize=m_pTable->PointSize;
// vertical displacement is determined by the font used by the column headers. If
// the font used to insert a item is larger it will look funny. So we adjust that
// here by assuring the font for the item is no larger than the column header
if(PointSize > m_pTable->PointSize)
{
if(m_pTable->HLines==TRUE && m_pTable->HeaderOnly==FALSE)
PointSize=m_pTable->PointSize;
}
// determine the bounds of the print rect
// row
Row=m_pTable->NoHeader==FALSE ? (int) (m_pTable->StartRow+(m_pTable->HeaderLines*(GetVerticalSpacing(FALSE)))+( (sz)*row)):
(int) (m_pTable->StartRow+( (sz)*row));
// col
SCol=(int) m_pTable->StartCol;
for(y=0;y < col;++y)
SCol+=(int) m_pTable->ColDesc[y].Width;
ECol=(int)(SCol+m_pTable->ColDesc[col].Width);
m_ps->rc.left=SCol+2;
m_ps->rc.right=ECol-2;
m_ps->rc.top=Row+2;
m_ps->rc.bottom=(Row+sz)-2;
m_ps->Text=Text;
m_ps->uFillFlags=m_pTable->ColDesc[col].FillFlag;
if(m_ps->uFillFlags > FILL_LTGRAY)
{
OldColor= p_Print->SetColor(COLOR_WHITE);
}
if(m_ps->uFillFlags > FILL_NONE)
{
OldMode=p_Print->m_PrtDesc.pDC->SetBkMode(TRANSPARENT);
}
if(m_pTable->NumPrintLines==1)
m_ps->uTextFlags=TextFlags|TEXT_VCENTER|TEXT_SINGLELINE;
else
m_ps->uTextFlags=TextFlags;
m_ps->PointSize=PointSize;
p_Print->ThePrinter.PrintText(m_ps,2);
p_Print->m_nNextPos=m_ps->m_NextCharPos;
if(m_ps->uFillFlags > FILL_NONE)
{
OldMode=p_Print->m_PrtDesc.pDC->SetBkMode(OldMode);
}
if(m_ps->uFillFlags > FILL_LTGRAY)
{
OldColor= p_Print->SetColor(OldColor);
}
}
////////////////////////////////////////////////////////////////////////////
// Desc: places a value in a cell on the table defined as row,col
// used only with tables that are header only type. This routine does no
// checking for valid rows only for columns
// params:
// Returns:
///////////////////////////////////////////////////////////////////////////
void CPrintTable::InsertVirtualItem(LPCSTR Text,int row,int col,int PointSize,UINT TextFlags)
{
int y,SCol,ECol,Row,OldColor,OldMode;
// not Noheader NoHeader means we have a grid with no column descriptors while
// HeaderOnly means we have a header with no table body. With header only we
// will still have the column descriptors to use to set margins for each field
// so we can add fields till we run out of room on the page
int sz=GetVerticalSpacing();
if(m_pTable->HeaderOnly==FALSE)
return;
if(PointSize < 1)
PointSize=m_pTable->PointSize;
// determine the bounds of the print rect
// row .
// The start pos + (the # Header lines * the size of line)+(row# * size)
Row=(int) (m_pTable->StartRow+(m_pTable->HeaderLines*(GetVerticalSpacing(FALSE)))+( (sz)*row));
// col
SCol=(int) m_pTable->StartCol;
for(y=0;y < col;++y)
SCol+=(int) m_pTable->ColDesc[y].Width;
ECol=(int) (SCol+m_pTable->ColDesc[col].Width);
m_ps->rc.left=SCol+1;
m_ps->rc.right=ECol-1;
m_ps->rc.top=Row+1;
m_ps->rc.bottom=Row+(sz)-1;
m_ps->Text=Text;
m_ps->uTextFlags=TextFlags;
m_ps->PointSize=PointSize;
m_ps->uFillFlags=m_pTable->ColDesc[col].FillFlag;
if(m_ps->uFillFlags > FILL_LTGRAY)
{
OldColor= p_Print->SetColor(COLOR_WHITE);
}
if(m_ps->uFillFlags > FILL_NONE)
{
OldMode=p_Print->m_PrtDesc.pDC->SetBkMode(TRANSPARENT);
}
p_Print->ThePrinter.PrintText(m_ps,2);
p_Print->m_nNextPos=m_ps->m_NextCharPos;
if(m_ps->uFillFlags > FILL_NONE)
{
OldMode=p_Print->m_PrtDesc.pDC->SetBkMode(OldMode);
}
if(m_ps->uFillFlags > FILL_LTGRAY)
{
OldColor= p_Print->SetColor(OldColor);
}
}
////////////////////////////////////////////////////////////////////////////
// Desc: Draw horizontal lines for esch item on table
// params:
// Returns:
///////////////////////////////////////////////////////////////////////////
void CPrintTable::PrintHLines()
{
int y,SCol,ECol,Row,SCount=0;
// get out if needed
int sz=GetVerticalSpacing();
if(m_pTable->HLines==FALSE||m_pTable->HeaderOnly==TRUE)
return;
// calc starting column and ending column
SCol=(int) m_pTable->StartCol;
ECol=(int) m_pTable->EndCol;
// if we have a header skip over it else start at start pos
Row=m_pTable->NoHeader==FALSE ? (int) m_pTable->StartRow+ (GetVerticalSpacing(FALSE)*m_pTable->HeaderLines):
(int) m_pTable->StartRow+sz;
// draw a line for each row from one side to the other
for(y=0;y < m_pTable->NumRows;++y)
{
if(m_pTable->SetSkip)
{
++SCount;
if(m_pTable->SetSkip==SCount)
{
p_Print->Line(Row,SCol,Row,ECol,m_pTable->LineSize,PEN_SOLID);
SCount=0;
}
}
else
p_Print->Line(Row,SCol,Row,ECol,m_pTable->LineSize,PEN_SOLID);
Row+=sz;
}
}
////////////////////////////////////////////////////////////////////////////
// Desc: Draws vertical line seperators for column entries
// params:
// Returns:
///////////////////////////////////////////////////////////////////////////
void CPrintTable::PrintVLines()
{
int y,start;
int sz=GetVerticalSpacing();
// get out if needed
if(m_pTable->VLines==FALSE||m_pTable->HeaderOnly==TRUE)
return;
// col to start drawing at
start=(int) m_pTable->StartCol;
int BRow,ERow;
// calc the beginning and ending rows to draw lines the correct length
if(m_pTable->NoHeader==FALSE)
{
// skip header area and calc area under header for x items
BRow=(int) m_pTable->StartRow+(m_pTable->HeaderLines*(GetVerticalSpacing(FALSE)));
ERow=(int) m_pTable->StartRow+(m_pTable->HeaderLines*(GetVerticalSpacing(FALSE))+(sz * m_pTable->NumRows));
}
else
{
// no header so calc only for x items
BRow=(int) m_pTable->StartRow;
ERow=(int) m_pTable->StartRow+( sz*m_pTable->NumRows);
}
// loop through drawing lines on the right margin except the last column
// the last column will have a line drawn by the border
for(y=0;y < m_pTable->NumColumns-1;++y)
{
start+=(int) m_pTable
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -