You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

625 lines
15 KiB
C++

//////////////////////////////////////////////////////////////////////////////
//文件: CItem类扩展
//主要功能:
// 操作各类元素或完成一定的功能
//
//程序编写: 2006-12-07
//
//
/////////////////////////////////////////////////////////////////////////////
#include "StdAfx.h"
//#include "DrawApp.h"
#include ".\itemprint.h"
//#include "DrawDoc.h"
//#include "DrawView.h"
//#include "DrawMainFrame.h"
//#include "DrawChildFrame.h"
//#include ".\PublicParam.h"
namespace NDrawView
{
CItemPrint::CItemPrint(CSigmaDoc * ppDoc)
: CItemBase(ppDoc)
{
this->SetType(ITEM_PRINT);
m_pPreviewDC=NULL;
m_bPrinting=FALSE;
m_szPageNum.SetSize(1,1);
m_bRestorePreviewDC=FALSE;
}
CItemPrint::~CItemPrint(void)
{
ClearPreviewDC();
}
void CItemPrint::ClearPreviewDC(void)
{
if(m_pPreviewDC)delete m_pPreviewDC;
m_pPreviewDC=NULL;
}
void CItemPrint::EnablePrinting(BOOL bEnable)
{
m_bPrinting=bEnable;
}
void CItemPrint::OnDraw(CXyDC* pDC)
{
}
void CItemPrint::OnFilePrintPreviewUIUpdate(CCmdUI* pCmdUI)
{
}
void CItemPrint::OnFilePrintPreview(void)
{
EnablePrinting(FALSE);
//m_bRestorePreviewDC=FALSE;
//if(m_pPreviewDC)
//{
// if(::AfxMessageBox(IDS_STRING_RESTORE_PREVIEW_DC, MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON1)==IDYES)
// m_bRestorePreviewDC=TRUE;
//}
//GetDrawDoc()->SetPreview(TRUE);
//m_bChildRulerBar=GetRulerBarState();
//CDrawMainFrame* pMainFrame = (CDrawMainFrame*)GetDrawDoc()->GetMainFrame();
//if(pMainFrame)
//{
// pMainFrame->EnablePaneBar(FALSE);
// //pMainFrame->CommandBarState(true);
// //pMainFrame->ShowCommandBar(false);
//}
}
void CItemPrint::OnEndPrintPreview(CDC* pDC, CPrintInfo* pInfo, POINT point, CPreviewView* pView)
{
// GetDrawDoc()->SetPreview(FALSE);
// SetRulerBarState(m_bChildRulerBar);
// CDrawMainFrame* pMainFrame = (CDrawMainFrame*)GetDrawDoc()->GetMainFrame();
// if(pMainFrame)
// {
// pMainFrame->EnablePaneBar(TRUE);
//// pMainFrame->CommandBarState(false);
// }
}
BOOL CItemPrint::OnPreparePrinting(CPrintInfo* pInfo)
{
return TRUE;
}
CRect CItemPrint::GetViewRect(CRect oldViewRect)
{
//CPrintPageSetup* pPageSetup = PARAM().GetPageSetup();
//if(pPageSetup->m_bMulline)
//{
// int mn=pPageSetup->m_nMullineNum;
// switch(pPageSetup->m_nMullineIdea)
// {
// case 0: //多列方式
// oldViewRect.SetRect(0,0,oldViewRect.Width()*m_szPageNum.cx, oldViewRect.Height()*m_szPageNum.cy*mn);
// break;
// case 1: //多行方式
// oldViewRect.SetRect(0,0,oldViewRect.Width()*m_szPageNum.cx*mn, oldViewRect.Height()*m_szPageNum.cy);
// break;
// }
//}
//else
// oldViewRect.SetRect(0,0,oldViewRect.Width()*m_szPageNum.cx,oldViewRect.Height()*m_szPageNum.cy);
return oldViewRect;
}
void CItemPrint::OnDrawSetDC(CXyDC* pDC) //设置分页打印时的浏览范围
{
if(pDC==NULL) return;
//设置显示范围
CRect rtView=pDC->GetViewRect();
rtView=GetViewRect(rtView);
pDC->SetViewRect(rtView);
}
void CItemPrint::SetSectionSize(long cx,long cy)
{
/*CDrawDoc* pDoc = GetDrawDoc();
COne *pOne;
CSection *od;
POSITION p = pDoc->GetDraw()->GetValueList()->GetHeadPosition();
while(p)
{
pOne=(COne *)(pDoc->GetDraw()->GetValueList()->GetNext(p));
if(pOne->GetType()!=DOUBLEFOX_SECTION)continue;
od=(CSection*)pOne->value;
od->SetViewSize(cx,cy);
}*/
}
void CItemPrint::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
//CPrintPageSetup* pPageSetup = PARAM().GetPageSetup();
//CDrawDoc* pDoc = GetDrawDoc();
////设置剖面显示高度,宽度
//CSize sz;
//sz.cx=pDC->GetDeviceCaps(HORZRES);//获得打印页上可打印区的宽度(单位:象素)
//sz.cy=pDC->GetDeviceCaps(VERTRES);//获得打印页上可打印区的高度(单位:象素)
//SetSectionSize(sz.cx,sz.cy);
////设置打印比例
//double xx,yy;
//pDoc->GetDC().GetScale(xx,yy);
//pDoc->SetDC(pDC);
//pDoc->GetDC().SetScale(xx,yy);
////当已经是预览状态时,(如在打印预览状态下设置纸张方向时,还得重新调用该函数)
////为了使退出预览状态后能保持之前的比例状态,需要判断是否是在预览状态设置打印参数造成的
//if(!pDoc->m_bSetPrinterInPreview)
//{
// BOOL br=pDoc->IsPreview();
// pDoc->SetPreview(FALSE);
// pDoc->PushDC();//备份显示参数
// pDoc->SetPreview(br);
//}
//m_szPageNum.SetSize(1,1);
//CRect rtView=pDoc->GetDC().GetViewRect();
//if(pPageSetup->m_bExtendScreen) //全屏显示
//{
// CRect rt=GetPrintArea(pDC); rt.OffsetRect(-rt.left,-rt.top);
// CRect8 rect(1e100,-1e100,-1e100,1e100);
// if(pDoc->GetDraw()->GetCount()>0) pDoc->GetDrawRange(rect);
// else *((CRect8*)&rect)=rt;
// if(pPageSetup->m_nScreenSel==0)pDoc->GetDC().Extend(rect,rt,EXTEND_MODE_CENTER); //居中显示
// else pDoc->GetDC().Extend(rect,rt,EXTEND_MODE_STRECH); //拉伸显示
//}
//else if(pPageSetup->m_bPartition) //分页显示
//{
// CSize sz=GetPartitionNum(pDC);
// pInfo->SetMinPage(1);
// pInfo->m_nNumPreviewPages = 1;
// switch(pPageSetup->m_nPartitionIdea)
// {
// case 0://全部
// pInfo->SetMaxPage(sz.cx*sz.cy);
// if(sz.cx*sz.cy>1) pInfo->m_nNumPreviewPages = 2;
// break;
// case 1://垂直
// pInfo->SetMaxPage(sz.cy);
// sz.cx=1;
// if(sz.cy>1) pInfo->m_nNumPreviewPages = 2;
// break;
// case 2://水平
// pInfo->SetMaxPage(sz.cx);
// sz.cy=1;
// if(sz.cx>1) pInfo->m_nNumPreviewPages = 2;
// break;
// }
// pInfo->m_nCurPage = 0;
// m_szPageNum=sz;
// //设置显示范围
// rtView=GetViewRect(rtView);
// pDoc->GetDC().SetViewRect(rtView);
//}
//else if(pPageSetup->m_bCenterDocument && pDoc->GetDraw()->GetCount()>0) //比例不变居中显示
//{
// //获得导出图件的大小
// CRect8 rect(1e100,-1e100,-1e100,1e100);
// pDoc->GetDrawRange(rect);
// //pDoc->GetDraw()->GetRange(rect);
// //rect.left=pDoc->GetDC().left;
// //rect.top=pDoc->GetDC().top;
// CRect rt=GetPrintArea(pDC);
// CRect mg=GetMarginRect();
// CPoint porg=pDC->GetViewportOrg();
// rt.OffsetRect(-mg.left,-mg.top);
// CRect8 rs=pDoc->GetDC().GetReal(rt);
// CPoint2D pt=rect.CenterPoint();
// CPoint2D ps=rs.CenterPoint();
// pDoc->GetDC().OffsetRect(pt.x0-ps.x0, pt.y0-ps.y0);
//}
////恢复上次预览时的参数
//if(m_pPreviewDC!=NULL)
//{
// if(m_bPrinting || m_bRestorePreviewDC)
// {
// pDoc->SetDC(*m_pPreviewDC);
// pDoc->SetDC(pDC);
// pDoc->GetDC().SetViewRect(rtView);
// return;
// }
//}
}
void CItemPrint::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
//CPrintPageSetup* pPageSetup = PARAM().GetPageSetup();
////画页边距
//if(GetDrawDoc()->IsPreview())
// DrawPageFrame(pDC, pInfo->m_rectDraw);
////输出页码
//CPoint pt=pDC->GetViewportOrg();
//pDC->SetViewportOrg(0,0);
//PrintPageNumber(pDC);
//pDC->SetViewportOrg(pt);
//if(!pPageSetup->m_bExtendScreen)
//{
// //pDC->SelectClipRgn(NULL);
// MarginRect(pInfo->m_rectDraw);
// pDC->IntersectClipRect(&pInfo->m_rectDraw);
//}
}
void CItemPrint::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)
{
//CDrawDoc* pDoc = GetDrawDoc();
//CDrawView* pView = GetDrawView();
////恢复剖面显示范围
//CRect rect;
//pView->GetClientRect(&rect);
//SetSectionSize(rect.Width()+5,rect.Height()+5);
////仅是为了保持与打印预览时的显示比例及位置相同
//CRect8 rt=*(CRect8*)&pDoc->GetDC();
//double sx,sy;
//BOOL bSetCurScale=::GetPreferences().OtherPrint.m_bSetScale;
//if(bSetCurScale)
//{
// pDoc->GetDC().GetScale(sx, sy);
// if(m_pPreviewDC)
// {
// delete m_pPreviewDC;
// m_pPreviewDC=NULL;
// }
//}
//else
//{
// if(m_pPreviewDC==NULL)
// m_pPreviewDC=new CXyDC;
// *m_pPreviewDC=pDoc->GetDC();
//}
///////////////////////////////////////////////////////
//BOOL br=pDoc->IsPreview();
//pDoc->SetPreview(FALSE);
//pDoc->PopDC();//恢复显示参数
//pDoc->SetPreview(br);
////恢复打印比例
//double xx,yy;
//pDoc->GetDC().GetScale(xx,yy);
//CClientDC dc(pView);
//pDoc->SetDC(&dc);
//pDoc->GetDC().SetScale(xx,yy);
////仅是为了保持与打印预览时的显示比例及位置相同
//if(bSetCurScale)
//{
// pDoc->GetDC()=rt;
// pDoc->GetDC().SetScale(sx,sy);
//}
//AfterEndPrinting(pDC, pInfo);
}
void CItemPrint::AfterEndPrinting(CDC* pDC, CPrintInfo* pInfo)
{
}
void CItemPrint::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
if(!pDC->IsPrinting()) return;
CRect rt = GetPrintArea(pDC);
CSize sz = m_szPageNum;
//CPrintPageSetup* pPageSetup = PARAM().GetPageSetup();
////TRACE("OnPrepareDC( %ld/(%ld,%ld) page )\n", pInfo->m_nCurPage, m_szPageNum.cx, m_szPageNum.cy);
//if(pInfo->m_nCurPage==1)
//{
// pDC->SetViewportOrg(rt.left,rt.top);
//}
//else if(pInfo->m_nCurPage>1)
//{
// CSize sw=GetSuperpositionWidth();//获得重叠区的像素值
// int pagew=rt.Width();
// int pageh=rt.Height();
//
// if(pPageSetup->m_bMulline)
// {
// int mn=pPageSetup->m_nMullineNum;
// if(pPageSetup->m_nMullineIdea==0) //多列
// pageh=pageh*mn-sw.cy*(mn-1);
// else //多行
// pagew=pagew*mn-sw.cx*(mn-1);
// }
// int x,y;
// switch(pPageSetup->m_nPartitionIdea)
// {
// case 0://全部
// {
// int row = pInfo->m_nCurPage / sz.cx + (pInfo->m_nCurPage % sz.cx > 0);
// int col = (pInfo->m_nCurPage - 1) % sz.cx + 1;
// //TRACE("OnPrepareDC( row=%d, col=%d)\n", row,col);
// x=-(pagew-sw.cx)*(col-1);
// y=-(pageh-sw.cy)*(row-1);
// }
// break;
// case 1://纵向
// x=-(pagew-sw.cx)*(pInfo->m_nCurPage-1);
// y=0;
// break;
// case 2://横向
// x=0;
// y=-(pageh-sw.cy)*(pInfo->m_nCurPage-1);
// break;
// }
// x+=rt.left;
// y+=rt.top;
// pDC->SetViewportOrg(x,y);
//}
}
CSize CItemPrint::GetPartitionNum(CDC* pDC)
{
//CDrawDoc* pDoc = GetDrawDoc();
//if(pDoc->GetDraw()->GetCount()==0) return CSize(1,1);
//CRect rt = GetPrintArea(pDC);
//CPrintPageSetup* pPageSetup = PARAM().GetPageSetup();
////获得一页可打印区的打印长度(单位:毫米)
//double sx=rt.Width ()*pDoc->GetDC().UnitX;
//double sy=rt.Height()*pDoc->GetDC().UnitY;
////当折行打印时,计算一页纸可打印的长度
//if(pPageSetup->m_bMulline)
//{
// int mn=pPageSetup->m_nMullineNum;
// if(pPageSetup->m_nMullineIdea==0) //多列
// sy=sy*mn-pPageSetup->m_nSuperpositionWidth*(mn-1);
// else //多行
// sx=sx*mn-pPageSetup->m_nSuperpositionWidth*(mn-1);
//}
////获得总图的毫米长度
//CRect8 rect(1e100,-1e100,-1e100,1e100);
//pDoc->GetDrawRange(rect);
//double mx=pDoc->GetDC().GetScreenWidth8 (rect.Width ()) * pDoc->GetDC().UnitX;
//double my=pDoc->GetDC().GetScreenHeight8(rect.Height()) * pDoc->GetDC().UnitY;
//my=fabs(my);
CSize sz(0,0);
//if(mx<=ZERO) sz.cx=1;
//else while(mx > ZERO)
//{
// sz.cx++;
// mx -= sx;
// if(mx <= ZERO) break;
// mx += pPageSetup->m_nSuperpositionWidth;
//}
//if(my<=ZERO) sz.cy=1;
//else while(my > ZERO)
//{
// sz.cy++;
// my -= sy;
// if(my <= ZERO) break;
// my += pPageSetup->m_nSuperpositionWidth;
//}
return sz;
}
void CItemPrint::PrintPageNumber(CDC *pDC)
{
//CPrintPageSetup* pPageSetup = PARAM().GetPageSetup();
//if(pPageSetup->m_nSideSel==0) return;
//if(pPageSetup->m_strLabel.IsEmpty()) return;
//CRect mg=GetMarginRect(0.5); //转换为像素之后的页边距
//int m_PageWidth=pDC->GetDeviceCaps(HORZRES);
//int m_PageHeight=pDC->GetDeviceCaps(VERTRES);
//
//int x = AfxGetPublicFunction()->FloatToLong(pPageSetup->m_nMarginX/GetDrawDoc()->GetDC().UnitX);
//int y = AfxGetPublicFunction()->FloatToLong(pPageSetup->m_nMarginY/GetDrawDoc()->GetDC().UnitY);
//CSize size=pDC->GetTextExtent(pPageSetup->m_strLabel);
//switch(pPageSetup->m_nSideSel)
//{
//case 1://纸的左边
// x+=mg.left;
// pPageSetup->m_lfPageNumberFont.lfEscapement=-900;//旋转-90度
// pPageSetup->m_lfPageNumberFont.lfOrientation=-900;//旋转-90度
// switch(pPageSetup->m_nAliginSel)
// {
// case 0://居右
// y=m_PageHeight-size.cx-y;
// y-=mg.bottom*2;
// break;
// case 1://居中
// y=m_PageHeight/2-size.cx/2+y;
// y=y+mg.top-mg.bottom;
// break;
// case 2://居左
// y+=mg.top*2;
// break;
// }
// x+=size.cy;
// break;
//case 3://纸的右边
// x+=mg.right;
// pPageSetup->m_lfPageNumberFont.lfEscapement=900;//旋转90度
// pPageSetup->m_lfPageNumberFont.lfOrientation=900;//旋转90度
// switch(pPageSetup->m_nAliginSel)
// {
// case 0://居右
// y+=size.cx;
// y+=mg.top*2;
// break;
// case 1://居中
// y=m_PageHeight/2+size.cx/2+y;
// y=y+mg.top-mg.bottom;
// break;
// case 2://居左
// y=m_PageHeight-y;
// y-=mg.bottom*2;
// break;
// }
// x=m_PageWidth-size.cy-x;
// break;
//case 2://纸的上边
// y+=mg.top;
// pPageSetup->m_lfPageNumberFont.lfEscapement=0;
// pPageSetup->m_lfPageNumberFont.lfOrientation=0;
// switch(pPageSetup->m_nAliginSel)
// {
// case 0://居右
// x=m_PageWidth-size.cx-x;
// x-=mg.right*2;
// break;
// case 1://居中
// x=m_PageWidth/2-size.cx/2+x;
// x=x-mg.right+mg.left;
// break;
// case 2://居左
// x+=mg.left*2;
// break;
// }
// break;
//case 4://纸的下边
// y+=mg.bottom;
// pPageSetup->m_lfPageNumberFont.lfEscapement=0;
// pPageSetup->m_lfPageNumberFont.lfOrientation=0;
// switch(pPageSetup->m_nAliginSel)
// {
// case 0://居右
// x=m_PageWidth-size.cx-x;
// x-=mg.right*2;
// break;
// case 1://居中
// x=(m_PageWidth)/2-size.cx/2+x;
// x=x-mg.right+mg.left;
// break;
// case 2://居左
// x+=mg.left*2;
// break;
// }
// y=m_PageHeight-size.cy-y;
// break;
//}
//CFont ft;
//if(ft.CreateFontIndirect(&pPageSetup->m_lfPageNumberFont))
//{
// CFont* pFont=pDC->SelectObject(&ft);
// pDC->TextOut(x,y,pPageSetup->m_strLabel);
// pDC->SelectObject(pFont);
//}
}
void CItemPrint::SetRulerBarState(BOOL bView)
{
//CDrawChildFrame *cf=(CDrawChildFrame*)GetDrawView()->GetParentChildFrame();
//if(cf) cf->ShowRuler(bView);
}
BOOL CItemPrint::GetRulerBarState(void)
{
BOOL vt=TRUE;
/*CDrawChildFrame *cf=(CDrawChildFrame*)GetDrawView()->GetParentChildFrame();
if(cf)
{
vt=cf->GetRulerState();
cf->ShowRuler(FALSE);
}*/
return vt;
}
CRect CItemPrint::GetPrintArea(CDC* pDC)
{
CRect rt(0, 0, pDC->GetDeviceCaps(HORZRES), pDC->GetDeviceCaps(VERTRES));
MarginRect(rt);
return rt;
}
void CItemPrint::MarginRect(CRect& rt)
{
CRect mg = GetMarginRect();
rt.left +=mg.left;
rt.top +=mg.top;
rt.right -=mg.right;
rt.bottom -=mg.bottom;
}
CRect CItemPrint::GetMarginRect(double sc)//转换为像素之后的页边距
{
/*CPrintPageSetup* pPageSetup = PARAM().GetPageSetup();
CRect rt;
rt.left =AfxGetPublicFunction()->FloatToLong(pPageSetup->m_nMarginLeft /GetDrawDoc()->GetDC().UnitX * sc);
rt.top =AfxGetPublicFunction()->FloatToLong(pPageSetup->m_nMarginTop /GetDrawDoc()->GetDC().UnitY * sc);
rt.right =AfxGetPublicFunction()->FloatToLong(pPageSetup->m_nMarginRight /GetDrawDoc()->GetDC().UnitX * sc);
rt.bottom =AfxGetPublicFunction()->FloatToLong(pPageSetup->m_nMarginBottom/GetDrawDoc()->GetDC().UnitY * sc);*/
CRect rt;
return rt;
}
CSize CItemPrint::GetSuperpositionWidth(void)//获得重叠区的像素值
{
//CPrintPageSetup* pPageSetup = PARAM().GetPageSetup();
CSize sz;
//sz.cx = AfxGetPublicFunction()->FloatToLong(pPageSetup->m_nSuperpositionWidth / GetDrawDoc()->GetDC().UnitX);
//sz.cy = AfxGetPublicFunction()->FloatToLong(pPageSetup->m_nSuperpositionWidth / GetDrawDoc()->GetDC().UnitY);
return sz;
}
void CItemPrint::DrawPageFrame(CDC* pDC, CRect rect)
{
//画页边距
CRect ro=rect;
CRect rn=rect;
MarginRect(rn);
CPen pen(PS_SOLID, 1, RGB(199,199,199));
CBrush* pBrush=(CBrush*)pDC->SelectStockObject(NULL_BRUSH);
CPen* pOldPen=(CPen*)pDC->SelectObject(&pen);
pDC->Rectangle(ro);
CRect mg = GetMarginRect();
if(!(mg.left==0 && mg.right==0 && mg.bottom==0 && mg.top==0))
{
pDC->MoveTo(ro.left, rn.top);
pDC->LineTo(ro.right, rn.top);
pDC->MoveTo(ro.left, rn.bottom);
pDC->LineTo(ro.right, rn.bottom);
pDC->MoveTo(rn.left, ro.top);
pDC->LineTo(rn.left, ro.bottom);
pDC->MoveTo(rn.right, ro.top);
pDC->LineTo(rn.right, ro.bottom);
//pDC->Rectangle(pInfo->m_rectDraw);
}
pDC->SelectObject(pOldPen);
pDC->SelectObject(pBrush);
}
}//namespace