http://www.amazon.cn/mn/detailApp?qid=1217206087&ref=SR&sr=13-1&uid=168-6620282-6711439&prodid=bkbk711576
posted @
2008-08-21 20:05 Horace 阅读(248) |
评论 (0) |
编辑 收藏
#ifndef LOGIX_CE
COleDataSource* CLadderView::OnGetClipboardData(CElementdef* pViewElement)
{
ASSERT_VALID(this);
// get document data element and stuff into OLE data source
CRungElem* datarungel = pViewElement->GetRungElem();
if(!datarungel)
return NULL;
COleDataSource* ClipLadDataSource = new COleDataSource(); //data source object used in clipbd exchange
if(!ClipLadDataSource)
return NULL;
TRY
{
// do native format
{
// Create a shared file and associate a CArchive with it
#ifndef LOGIX_CE
CSharedFile file;
#else
CMemFile file;
#endif //LOGIX_CE
CArchive ar(&file, CArchive::store);
//special case for copying rung to keep dbase strings
if(datarungel->IsKindOf(RUNTIME_CLASS(CRung)) )
{
CRung* pRung = ((CRung*)datarungel);
CRungElem* pTmpRung = pRung->CreateCopyWithDbase();
pTmpRung->SetAllModified();
ar.WriteObject(pTmpRung);
delete pTmpRung;
ar.Close();
ClipLadDataSource->CacheGlobalData(m_cfLadderRung, file.Detach());
}
else
{
// Make a copy of the rung element so don't SetAllModified() of the original rungelem
// SetAllModified is called so the string operands are copied over and not the edopnds
// delete must be called before returning because the rungelem is an allocated copy
CRungElem *pTmpElem = datarungel->CreateCopy();
// TRACE("Address of pTmpElem %08x \n", pTmpElem);
// TRACE("Address of datarungel %08x \n", datarungel);
if(!pTmpElem)
return NULL;
pTmpElem->SetAllModified();
ar.WriteObject(pTmpElem);//Serialize into fp
ar.Close();
// Made a copy so the original rung element isn't set to uncompiled be SetAllModified()
delete pTmpElem;
ClipLadDataSource->CacheGlobalData(m_cfLadderElement, file.Detach());
}
}
CRSLibProject RSLibProject;
//do database array of ID's
{
CRSLibDbase IDHolder;
if (m_pProgFile->GetDataHolder()->GetDbase())
{
RSLibProject.m_Database.AttachDbase(m_pProgFile->GetDataHolder()->GetDbase());
datarungel->GetDbaseIDs(&RSLibProject.m_Database);
if ( (RSLibProject.m_Database.GetAddrSymSize()>0) || (RSLibProject.m_Database.GetInstrSize()>0) )
{
CDataBaseClipboard pdataclp;
pdataclp.SetClipboardData(ClipLadDataSource, RSLibProject.m_Database); // array of Dbase ID's
}
}
#ifdef _FBOFFLINE
else
{
CDataBaseClipboard pdataclp;
datarungel->GetDbaseIDs(&RSLibProject.m_Database);
pdataclp.FBESetClipboardData(ClipLadDataSource, RSLibProject.m_Database,m_pInterfaceObj); // array of Dbase ID's
}
#endif
}
// Render neutral text put up right away
{
CString strAsciiString;
CLIPFORMAT cfFormat;
if (datarungel->IsKindOf(RUNTIME_CLASS(CRung)) )
{
CRSLibProgfile* pRSLibProgfile = new CRSLibProgfile;
RSLibProject.m_ProgfileArray.Add(pRSLibProgfile);
cfFormat = m_cfLadderNeutralTextRung;
CString strAscii, strComment, strTitle;
((CRung*)datarungel)->ToNeutralText(strAscii);
strAsciiString += strAscii;
CRSLibRung* pRSLibRung = new CRSLibRung;
pRSLibProgfile->m_RungArray.Add(pRSLibRung);
pRSLibRung->SetRung(strAscii);
((CRung*)datarungel)->GetRungComment(strComment);
pRSLibRung->SetRungComment(strComment);
((CRung*)datarungel)->GetRungTitle(strTitle);
pRSLibRung->SetPageTitle(strTitle);
// Put up RSLib data
CRSLibClipboard RSLibClipboard;
RSLibClipboard.SetClipboardData(ClipLadDataSource, RSLibProject);
}
else
{
((CRungElem*)datarungel)->ToNeutralText(strAsciiString);
cfFormat = m_cfLadderNeutralTextElement;
}
int nBytes = strAsciiString.GetLength();
HGLOBAL hGlobalMem = ::GlobalAlloc(GMEM_DDESHARE, nBytes+1);
if (hGlobalMem)
{
void* hgbl =(void*)::GlobalLock(hGlobalMem);
char* pIndex = (char*)hgbl;
memcpy(hgbl, (const void*)(const char*)strAsciiString, nBytes);
memset(&pIndex[nBytes],0,1); //terminate with null
ClipLadDataSource->CacheGlobalData(cfFormat, hgbl);
}
}
//do datatable array of addresses
{
CPtrArray AddrHolder;
CDataHolder* pDataHolder = m_pProgFile->GetDataHolder();
datarungel->GetXrefAddresses(&AddrHolder);
if(AddrHolder.GetSize()>0)
{
CDataFileClipboard pdataclp;
if(pDataHolder)
{
pdataclp.AttachDataHolder(pDataHolder);
pdataclp.AttachStructHolder(pDataHolder->GetStructHolder());
// If you want to put a m_cfDataFile on the clipboard then use one of the following two routines
pdataclp.SetClipboardData(ClipLadDataSource, AddrHolder); //array of pointers to edopnds
}
}
}
//do ascii text string
{
CString strAsciiString;
datarungel->ToAscii(strAsciiString);
int nBytes = strAsciiString.GetLength();
HGLOBAL hGlobalMem = ::GlobalAlloc(GMEM_DDESHARE, nBytes+1);
if (hGlobalMem)
{
void* hgbl =(void*)::GlobalLock(hGlobalMem);
char* pIndex = (char*)hgbl;
memcpy(hgbl,(const void*)(const char*)strAsciiString,nBytes);
memset(&pIndex[nBytes],0,1);//terminate with null
ClipLadDataSource->CacheGlobalData(CF_TEXT,hgbl);
}
}
//do metafile
{
CDC* dcScreen = GetDC();
CFont* pOldFont = dcScreen->SelectObject(&(m_Options.CVFont));
CRect rc;
pViewElement->GetRect(&rc);
CPoint Oldpos;
Oldpos.x = rc.left;
Oldpos.y = rc.top;
pViewElement->SetPosition(&m_Options,CPoint(0,0));
pViewElement->GetRect(&rc);
int x = rc.right+m_Options.GridUnit.cx*2;
x *= 2540; //2540 .01 mm == 1 inch
x += x/20; //adding 5% to width because rungs being cut off??
x /= dcScreen->GetDeviceCaps(LOGPIXELSX); // 2540/pixels per inch // ie. in 0.01mm
int y = rc.bottom+m_Options.GridUnit.cy;
y *= 2540;
y /= dcScreen->GetDeviceCaps(LOGPIXELSY); // ie. in 0.01mm
CRect modrc(0,0,x+x/10,y+y/10);
//rc is in .01 mm units
CMetaFileDC dc;
dc.CreateEnhanced(dcScreen,NULL,&modrc,"RSLogix\0Rung Object\0\0");
dc.m_hAttribDC = dcScreen->m_hAttribDC;
CFont* peOldFont = dc.SelectObject(&(m_Options.CVFont));
pViewElement->Draw(&dc,&m_Options,this);
pViewElement->SetPosition(&m_Options,Oldpos);
dc.SelectObject(peOldFont);
dcScreen->SelectObject(pOldFont);
HENHMETAFILE hmdc = dc.CloseEnhanced();
ReleaseDC(dcScreen);
if (hmdc)
{
STGMEDIUM MetaFileStg;
//DelEnhHMetafile(m_MetaFileStg.hEnhMetaFile);
MetaFileStg.tymed = TYMED_ENHMF;
MetaFileStg.hEnhMetaFile = hmdc;
MetaFileStg.pUnkForRelease = NULL;
ClipLadDataSource->CacheData(CF_ENHMETAFILE,&MetaFileStg);
}
}
//do bitmap
{
CDC* dcScreen = GetDC();
CBitmap RBmp;
CRect rc;
pViewElement->GetRect(&rc);
RBmp.CreateCompatibleBitmap(dcScreen, rc.Width(),rc.Height());
CDC memdc;
memdc.CreateCompatibleDC(dcScreen);
CBitmap* pOldBmap = memdc.SelectObject(&RBmp);
CFont* pOldFont = memdc.SelectObject(&(m_Options.CVFont));
CPoint Oldpos;
Oldpos.x = rc.left;
Oldpos.y = rc.top;
pViewElement->SetPosition(&m_Options,CPoint(0,0));
CBrush cbrback;
CBrush *hOldBrush=NULL;
cbrback.DeleteObject();
if(cbrback.CreateSolidBrush(m_Options.Color.cBackground))
hOldBrush = memdc.SelectObject(&cbrback);
memdc.FillRect(&rc,&cbrback);
pViewElement->Draw(&memdc,&m_Options,this);
if(hOldBrush)
memdc.SelectObject(hOldBrush);
pViewElement->SetPosition(&m_Options,Oldpos);
memdc.SelectObject(pOldFont);
memdc.SelectObject(pOldBmap);
ReleaseDC(dcScreen);
STGMEDIUM BitmapStg;
BitmapStg.tymed = TYMED_GDI;
BitmapStg.hBitmap = (HBITMAP)RBmp.Detach();
BitmapStg.pUnkForRelease = NULL;
ClipLadDataSource->CacheData(CF_BITMAP,&BitmapStg);
}
}
CATCH_ALL(e)
{
delete ClipLadDataSource;
THROW_LAST();
}
END_CATCH_ALL
ASSERT_VALID(ClipLadDataSource);
return ClipLadDataSource;
}
#endif //LOGIX_CE
posted @
2008-08-21 18:35 Horace 阅读(315) |
评论 (0) |
编辑 收藏