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.
207 lines
4.1 KiB
C++
207 lines
4.1 KiB
C++
//////////////////////////////////////////////////////////////////////////////
|
|
//类: CActionSortItem
|
|
//主要功能:
|
|
//
|
|
//程序编写: 2006-12-07
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
#include "StdAfx.h"
|
|
#include ".\actionsortitem.h"
|
|
#include "SigmaDoc.h"
|
|
#include "SigmaView.h"
|
|
#include "Visitor.h"
|
|
|
|
NAction::CActionSortItem::CActionSortItem()
|
|
: CActionItem(nullptr, 0)
|
|
{
|
|
}
|
|
|
|
CActionSortItem::CActionSortItem(CSigmaDoc * ppDoc, UINT actionType, const CPositionList& list, int nModeSel)
|
|
: CActionItem(ppDoc, actionType)
|
|
, m_nModeSel(nModeSel)
|
|
{
|
|
if(!list.IsEmpty())
|
|
{
|
|
POSITION pos,pt;
|
|
pt=list.GetHeadPosition();
|
|
while(pt)
|
|
{
|
|
pos=list.GetNext(pt);
|
|
m_eleList.AddTail(pos);
|
|
}
|
|
|
|
long num=(long)list.GetCount();
|
|
m_oldPos.resize(num);
|
|
switch(nModeSel)
|
|
{
|
|
case 0://最上显示
|
|
Movetofront(m_eleList);
|
|
break;
|
|
case 1://最下显示
|
|
Movetoback(m_eleList);
|
|
break;
|
|
case 2://上移一层
|
|
Moveforward(m_eleList);
|
|
break;
|
|
case 3://下移一层
|
|
Moveback(m_eleList);
|
|
break;
|
|
}
|
|
|
|
GetDoc()->Modified();
|
|
GetDoc()->InvalidateSelection(m_eleList);
|
|
}
|
|
}
|
|
|
|
CActionSortItem::~CActionSortItem(void)
|
|
{
|
|
}
|
|
|
|
void NAction::CActionSortItem::Movetofront(CPositionList& list)//最上显示
|
|
{
|
|
int i=0;
|
|
POSITION p,pos;
|
|
p=list.GetHeadPosition();
|
|
while(p)
|
|
{
|
|
pos=list.GetAt(p);
|
|
m_oldPos[i]=GetDoc()->GetDraw()->GetElementIndex(pos);
|
|
pos=GetDoc()->GetDraw()->MoveToFront(pos);
|
|
if(pos) list.SetAt(p,pos);
|
|
list.GetNext(p);
|
|
i++;
|
|
}
|
|
}
|
|
|
|
void NAction::CActionSortItem::Movetoback(CPositionList& list)//最下显示
|
|
{
|
|
int i=(int)list.GetCount();
|
|
POSITION p,pos;
|
|
p=list.GetTailPosition();
|
|
while(p)
|
|
{
|
|
i--;
|
|
pos=list.GetAt(p);
|
|
m_oldPos[i]=GetDoc()->GetDraw()->GetElementIndex(pos);
|
|
pos=GetDoc()->GetDraw()->MoveToBack(pos);
|
|
if(pos) list.SetAt(p,pos);
|
|
list.GetPrev(p);
|
|
}
|
|
}
|
|
|
|
void NAction::CActionSortItem::Moveforward(CPositionList& list)//上移一层
|
|
{
|
|
int i=(int)list.GetCount();
|
|
POSITION p,pos;
|
|
p=list.GetTailPosition();
|
|
while(p)
|
|
{
|
|
i--;
|
|
pos=list.GetAt(p);
|
|
m_oldPos[i]=GetDoc()->GetDraw()->GetElementIndex(pos);
|
|
pos=GetDoc()->GetDraw()->MoveForward(pos);
|
|
if(pos) list.SetAt(p,pos);
|
|
list.GetPrev(p);
|
|
}
|
|
}
|
|
|
|
void NAction::CActionSortItem::Moveback(CPositionList& list)//下移一层
|
|
{
|
|
int i=0;
|
|
POSITION p,pos;
|
|
p=list.GetHeadPosition();
|
|
while(p)
|
|
{
|
|
pos=list.GetAt(p);
|
|
m_oldPos[i]=GetDoc()->GetDraw()->GetElementIndex(pos);
|
|
pos=GetDoc()->GetDraw()->MoveBackward(pos);
|
|
if(pos) list.SetAt(p,pos);
|
|
list.GetNext(p);
|
|
i++;
|
|
}
|
|
}
|
|
|
|
void CActionSortItem::Undo(void)
|
|
{
|
|
CActionItem::Undo();
|
|
|
|
int i;
|
|
COne *pOne;
|
|
POSITION p,pos;
|
|
switch(m_nModeSel)
|
|
{
|
|
case 0://最上显示
|
|
case 3://下移一层
|
|
i=(int)m_eleList.GetCount();
|
|
p=m_eleList.GetTailPosition();
|
|
while(p)
|
|
{
|
|
i--;
|
|
pos=m_eleList.GetAt(p);
|
|
pOne=GetDoc()->GetDraw()->RemoveAtNoClear(pos);
|
|
pos=GetDoc()->GetDraw()->FindIndex(m_oldPos[i]);
|
|
if(pos==NULL) pos=GetDoc()->GetDraw()->AddTailOne(pOne);
|
|
else pos=GetDoc()->GetDraw()->InsertElementBefore(pos,pOne);
|
|
m_eleList.SetAt(p, pos);
|
|
m_eleList.GetPrev(p);
|
|
}
|
|
break;
|
|
case 1://最下显示
|
|
case 2://上移一层
|
|
i=0;
|
|
p=m_eleList.GetHeadPosition();
|
|
while(p)
|
|
{
|
|
pos=m_eleList.GetAt(p);
|
|
pOne=GetDoc()->GetDraw()->RemoveAtNoClear(pos);
|
|
pos=GetDoc()->GetDraw()->FindIndex(m_oldPos[i]);
|
|
if(pos==NULL) pos=GetDoc()->GetDraw()->AddTailOne(pOne);
|
|
else pos=GetDoc()->GetDraw()->InsertElementBefore(pos,pOne);
|
|
m_eleList.SetAt(p, pos);
|
|
m_eleList.GetNext(p);
|
|
i++;
|
|
}
|
|
break;
|
|
}
|
|
GetDoc()->InvalidateSelection(m_eleList);
|
|
//GetDoc()->SetSelection(m_eleList);
|
|
}
|
|
|
|
void CActionSortItem::Redo(void)
|
|
{
|
|
CActionItem::Redo();
|
|
|
|
switch(m_nModeSel)
|
|
{
|
|
case 0://最上显示
|
|
Movetofront(m_eleList);
|
|
break;
|
|
case 1://最下显示
|
|
Movetoback(m_eleList);
|
|
break;
|
|
case 2://上移一层
|
|
Moveforward(m_eleList);
|
|
break;
|
|
case 3://下移一层
|
|
Moveback(m_eleList);
|
|
break;
|
|
}
|
|
GetDoc()->InvalidateSelection(m_eleList);
|
|
}
|
|
|
|
void NAction::CActionSortItem::accept(CActionVisitor& visitor)
|
|
{
|
|
visitor.visit(*this);
|
|
}
|
|
|
|
void NAction::CActionSortItem::GetElementList(CPositionList& list)
|
|
{
|
|
POSITION pos,pt;
|
|
pt=m_eleList.GetHeadPosition();
|
|
while(pt)
|
|
{
|
|
pos=m_eleList.GetNext(pt);
|
|
list.AddTail(pos);
|
|
}
|
|
}
|