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.
134 lines
2.9 KiB
C++
134 lines
2.9 KiB
C++
#include "StdAfx.h"
|
|
#include ".\actionadditem.h"
|
|
#include "SigmaDoc.h"
|
|
#include "SigmaView.h"
|
|
#include "Visitor.h"
|
|
|
|
|
|
NAction::CActionAddItem::CActionAddItem()
|
|
: CActionItem(nullptr, 0)
|
|
{
|
|
}
|
|
|
|
CActionAddItem::CActionAddItem(CSigmaDoc * ppDoc, UINT actionType, const CPositionList& list)
|
|
: CActionItem(ppDoc, actionType)
|
|
, m_bAdded(false)
|
|
{
|
|
Remember(list);
|
|
CreatePos();
|
|
}
|
|
|
|
CActionAddItem::CActionAddItem(CSigmaDoc * ppDoc, UINT actionType, COne* pOne)
|
|
: CActionItem(ppDoc, actionType)
|
|
, m_bAdded(false)
|
|
, m_pos(NULL)
|
|
{
|
|
value.AddTail(pOne);
|
|
CreatePos();
|
|
}
|
|
|
|
CActionAddItem::~CActionAddItem(void)
|
|
{
|
|
if (!m_bAdded)
|
|
Clear(value); //this COne associated with addAction is deleted when the action is deleted.
|
|
//only if the object is not added in the document;
|
|
}
|
|
|
|
void CActionAddItem::Finish(void)
|
|
{
|
|
PerformOperation();
|
|
CActionItem::Finish();
|
|
}
|
|
|
|
void NAction::CActionAddItem::accept(CActionVisitor& visitor)
|
|
{
|
|
visitor.visit(*this);
|
|
}
|
|
|
|
// Actually perform the operation, or tell the view to do it. Subclasses
|
|
// should override to provide custom edit-like operations such as insert
|
|
// date/time.
|
|
|
|
void CActionAddItem::PerformOperation()
|
|
{
|
|
m_bAdded = true;
|
|
}
|
|
|
|
//Selection of object is not restored in the Undo. Because i don't think it is a state of CDocument,
|
|
//though it is a state of CView. The real reason behind this is, it is not important
|
|
//for users to retrieve what have been seleted after doing something.
|
|
void CActionAddItem::Undo()
|
|
{
|
|
CActionItem::Undo();
|
|
//delete the new added obj;
|
|
RemoveOperation();
|
|
m_bAdded = false;
|
|
}
|
|
|
|
void CActionAddItem::Redo()
|
|
{
|
|
CActionItem::Redo();
|
|
AddOperation();
|
|
// this is a one-shot action
|
|
m_bAdded = true;
|
|
}
|
|
|
|
void CActionAddItem::AddOperation(void)
|
|
{
|
|
//add back all the objects according its position in the CDrawDoc::m_objects.
|
|
int i=0;
|
|
COne *pOne;
|
|
POSITION p,pos=NULL;
|
|
//CPositionList list;
|
|
p=value.GetHeadPosition();
|
|
while(p)
|
|
{
|
|
pOne=(COne *)(value.GetNext(p));
|
|
if(!m_pos.empty()) pos=GetDoc()->GetDraw()->FindIndex(m_pos[i]);
|
|
if(pos==NULL)
|
|
pos=GetDoc()->GetDraw()->AddTailOne(pOne);
|
|
else
|
|
pos=GetDoc()->GetDraw()->InsertElementBefore(pos,pOne);
|
|
|
|
//list.AddTail(pos);
|
|
i++;
|
|
}
|
|
//GetDoc()->InvalidateSelection(list);
|
|
//GetDoc()->SetSelection(list);
|
|
}
|
|
|
|
void CActionAddItem::RemoveOperation(void)
|
|
{
|
|
GetDoc()->ClearSelection();
|
|
COne* pOne;
|
|
int n=0;
|
|
CRect8 range(1e100,-1e100,-1e100,1e100);
|
|
//delete all the regulation fist;
|
|
POSITION pos = value.GetTailPosition();
|
|
while (pos != NULL)
|
|
{
|
|
pOne = (COne*)value.GetPrev(pos);
|
|
pOne->GetRange(range);
|
|
this->RemoveAt(pOne);
|
|
}
|
|
Invalidate(range);
|
|
}
|
|
|
|
int NAction::CActionAddItem::CreatePos(void)
|
|
{
|
|
if(value.IsEmpty()) return 0;
|
|
m_pos.resize(value.GetCount());
|
|
|
|
long i=0;
|
|
COne* pOne;
|
|
POSITION pos, pt;
|
|
pos=value.GetHeadPosition();
|
|
while(pos)
|
|
{
|
|
pOne=(COne*)value.GetNext(pos);
|
|
pt=GetDoc()->GetDraw()->Find(pOne);
|
|
m_pos[i++]=GetDoc()->GetDraw()->GetElementIndex(pt);
|
|
}
|
|
return (int)value.GetCount();
|
|
}
|