void CEMapView::OnEditCopy()
{
ASSERT_VALID(this);
ASSERT(m_cfDraw != NULL); // Create a shared file and associate a CArchive with it
CSharedFile file;
CArchive ar(&file, CArchive::store); // Serialize selected objects to the archive
m_selection.Serialize(ar);
ar.Close(); COleDataSource* pDataSource = NULL;
TRY
{
pDataSource = new COleDataSource;
// put on local format instead of or in addation to
pDataSource->CacheGlobalData(m_cfDraw, file.Detach());
pDataSource->SetClipboard();
}
CATCH_ALL(e)
{
delete pDataSource;
THROW_LAST();
}
END_CATCH_ALL
}
void CEMapView::OnEditPaste()
{
COleDataObject dataObject;
dataObject.AttachClipboard(); // invalidate current selection since it will be deselected
OnUpdate(NULL, CEMapDoc::HINT_UPDATE_SELECTION, NULL);
m_selection.RemoveAll();
m_pEMapDrawItemHit=NULL;
if (dataObject.IsDataAvailable(m_cfDraw))
{
PasteNative(dataObject); // now add all items in m_selection to document
POSITION pos = m_selection.GetHeadPosition();
while (pos != NULL)
GetDocument()->Add(m_selection.GetNext(pos));
} // invalidate new pasted stuff
GetDocument()->UpdateAllViews(this, CEMapDoc::HINT_UPDATE_SELECTION, &m_selection);
m_pDocument->UpdateAllViews(this,CEMapDoc::HINT_UPDATE_ALL_ITEMS,NULL);//notify itemview
}
void CEMapView::PasteNative(COleDataObject& dataObject)
{
// get file refering to clipboard data
CFile* pFile = dataObject.GetFileData(m_cfDraw);
if (pFile == NULL)
return; // connect the file to the archive
CArchive ar(pFile, CArchive::load);
TRY
{
ar.m_pDocument = GetDocument(); // set back-pointer in archive // read the selection
m_selection.Serialize(ar);
POSITION pos=m_selection.GetHeadPosition();
while(pos){
CEMapDrawItem* pItem=m_selection.GetNext(pos);
pItem->m_item.m_nMapID=GetDocument()->m_EMapCurrent.m_nID;
}
}
CATCH_ALL(e)
{
ar.Close();
delete pFile;
THROW_LAST();
}
END_CATCH_ALL ar.Close();
delete pFile;
}