2006-01-10 13:27:15 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
|
|
|
*
|
|
|
|
* $RCSfile: shapelist.cxx,v $
|
|
|
|
*
|
2006-11-01 13:14:58 +00:00
|
|
|
* $Revision: 1.4 $
|
2006-01-10 13:27:15 +00:00
|
|
|
*
|
2006-11-01 13:14:58 +00:00
|
|
|
* last change: $Author: vg $ $Date: 2006-11-01 14:14:58 $
|
2006-01-10 13:27:15 +00:00
|
|
|
*
|
|
|
|
* The Contents of this file are made available subject to
|
|
|
|
* the terms of GNU Lesser General Public License Version 2.1.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* GNU Lesser General Public License Version 2.1
|
|
|
|
* =============================================
|
|
|
|
* Copyright 2005 by Sun Microsystems, Inc.
|
|
|
|
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License version 2.1, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2006-09-16 17:16:55 +00:00
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_sd.hxx"
|
|
|
|
|
2006-01-10 13:27:15 +00:00
|
|
|
#ifndef _TOOLS_DEBUG_HXX
|
|
|
|
#include <tools/debug.hxx>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _SVDOBJ_HXX //autogen
|
|
|
|
#include <svx/svdobj.hxx>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _SHAPELIST_HXX
|
|
|
|
#include "shapelist.hxx"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
using namespace sd;
|
|
|
|
|
2006-11-01 13:14:58 +00:00
|
|
|
ShapeList::ShapeList()
|
|
|
|
{
|
|
|
|
maIter = maShapeList.end();
|
|
|
|
}
|
|
|
|
|
2006-01-10 13:27:15 +00:00
|
|
|
ShapeList::~ShapeList()
|
|
|
|
{
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** adds the given shape to this list */
|
|
|
|
void ShapeList::addShape( SdrObject& rObject )
|
|
|
|
{
|
|
|
|
ListImpl::iterator aIter( std::find( maShapeList.begin(), maShapeList.end(), &rObject ) );
|
|
|
|
if( aIter == maShapeList.end() )
|
|
|
|
{
|
|
|
|
maShapeList.push_back(&rObject);
|
|
|
|
rObject.AddObjectUser( *this );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DBG_ERROR("sd::ShapeList::addShape(), given shape already part of list!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** removes the given shape from this list */
|
|
|
|
SdrObject* ShapeList::removeShape( SdrObject& rObject )
|
|
|
|
{
|
|
|
|
ListImpl::iterator aIter( std::find( maShapeList.begin(), maShapeList.end(), &rObject ) );
|
|
|
|
if( aIter != maShapeList.end() )
|
|
|
|
{
|
2006-11-01 13:14:58 +00:00
|
|
|
bool bIterErased = aIter == maIter;
|
|
|
|
|
2006-01-10 13:27:15 +00:00
|
|
|
(*aIter)->RemoveObjectUser(*this);
|
|
|
|
aIter = maShapeList.erase( aIter );
|
2006-11-01 13:14:58 +00:00
|
|
|
|
|
|
|
if( bIterErased )
|
|
|
|
maIter = aIter;
|
|
|
|
|
2006-01-10 13:27:15 +00:00
|
|
|
if( aIter != maShapeList.end() )
|
|
|
|
return (*aIter);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DBG_ERROR("sd::ShapeList::removeShape(), given shape not part of list!");
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** removes all shapes from this list
|
|
|
|
NOTE: iterators will become invalid */
|
|
|
|
void ShapeList::clear()
|
|
|
|
{
|
|
|
|
ListImpl aShapeList;
|
|
|
|
aShapeList.swap( maShapeList );
|
|
|
|
|
|
|
|
ListImpl::iterator aIter( aShapeList.begin() );
|
|
|
|
while( aIter != aShapeList.end() )
|
|
|
|
(*aIter++)->RemoveObjectUser(*this);
|
2006-11-01 13:14:58 +00:00
|
|
|
|
|
|
|
maIter = aShapeList.end();
|
2006-01-10 13:27:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** returns true if this list is empty */
|
|
|
|
bool ShapeList::isEmpty() const
|
|
|
|
{
|
|
|
|
return maShapeList.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** returns true if given shape is part of this list */
|
|
|
|
bool ShapeList::hasShape( SdrObject& rObject ) const
|
|
|
|
{
|
|
|
|
return std::find( maShapeList.begin(), maShapeList.end(), &rObject ) != maShapeList.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
SdrObject* ShapeList::getNextShape(SdrObject* pObj) const
|
|
|
|
{
|
|
|
|
if( pObj )
|
|
|
|
{
|
|
|
|
ListImpl::const_iterator aIter( std::find( maShapeList.begin(), maShapeList.end(), pObj ) );
|
|
|
|
if( aIter != maShapeList.end() )
|
|
|
|
{
|
|
|
|
aIter++;
|
|
|
|
if( aIter != maShapeList.end() )
|
|
|
|
{
|
|
|
|
return (*aIter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( !maShapeList.empty() )
|
|
|
|
{
|
|
|
|
return (*maShapeList.begin());
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
SdrObject* ShapeList::getPreviousShape( SdrObject* pObj ) const
|
|
|
|
{
|
|
|
|
if( pObj )
|
|
|
|
{
|
|
|
|
ListImpl::const_iterator aIter( std::find( maShapeList.begin(), maShapeList.end(), pObj ) );
|
|
|
|
if( (aIter != maShapeList.end()) && (aIter != maShapeList.begin()) )
|
|
|
|
{
|
|
|
|
aIter--;
|
|
|
|
return (*aIter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( !maShapeList.empty() )
|
|
|
|
{
|
|
|
|
return (*--maShapeList.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShapeList::ObjectInDestruction(const SdrObject& rObject)
|
|
|
|
{
|
|
|
|
ListImpl::iterator aIter( std::find( maShapeList.begin(), maShapeList.end(), &rObject ) );
|
|
|
|
if( aIter != maShapeList.end() )
|
|
|
|
{
|
2006-11-01 13:14:58 +00:00
|
|
|
bool bIterErased = aIter == maIter;
|
|
|
|
|
|
|
|
aIter = maShapeList.erase( aIter );
|
|
|
|
|
|
|
|
if( bIterErased )
|
|
|
|
maIter = aIter;
|
2006-01-10 13:27:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DBG_ERROR("sd::ShapeList::ObjectInDestruction(), got a call from an unknown friend!");
|
|
|
|
}
|
|
|
|
}
|
2006-11-01 13:14:58 +00:00
|
|
|
|
|
|
|
SdrObject* ShapeList::getNextShape()
|
|
|
|
{
|
|
|
|
if( maIter != maShapeList.end() )
|
|
|
|
{
|
|
|
|
return (*maIter++);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShapeList::seekShape( sal_uInt32 nIndex )
|
|
|
|
{
|
|
|
|
maIter = maShapeList.begin();
|
|
|
|
while( nIndex-- && (maIter != maShapeList.end()) )
|
|
|
|
maIter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ShapeList::hasMore() const
|
|
|
|
{
|
|
|
|
return maIter != maShapeList.end();
|
|
|
|
}
|