xref: /trunk/main/svx/source/unodraw/unomtabl.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_svx.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <set>
32*cdf0e10cSrcweir #include <comphelper/stl_types.hxx>
33*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/drawing/PointSequence.hpp>
36*cdf0e10cSrcweir #include <svl/style.hxx>
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx>
39*cdf0e10cSrcweir #include <svl/itempool.hxx>
40*cdf0e10cSrcweir #include <svl/itemset.hxx>
41*cdf0e10cSrcweir #include <svl/lstner.hxx>
42*cdf0e10cSrcweir #include <svx/xlnedit.hxx>
43*cdf0e10cSrcweir #include <svx/xlnstit.hxx>
44*cdf0e10cSrcweir #include <svx/svdmodel.hxx>
45*cdf0e10cSrcweir #include <svx/xdef.hxx>
46*cdf0e10cSrcweir #include <svx/xflhtit.hxx>
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir #include <vector>
49*cdf0e10cSrcweir #include <vos/mutex.hxx>
50*cdf0e10cSrcweir #include <vcl/svapp.hxx>
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir #include "svx/unofill.hxx"
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir #include "svx/unoapi.hxx"
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir using namespace ::com::sun::star;
58*cdf0e10cSrcweir using namespace ::rtl;
59*cdf0e10cSrcweir using namespace ::cppu;
60*cdf0e10cSrcweir using namespace ::vos;
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir typedef std::vector< SfxItemSet* > ItemPoolVector;
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir class SvxUnoMarkerTable : public WeakImplHelper2< container::XNameContainer, lang::XServiceInfo >,
65*cdf0e10cSrcweir 						  public SfxListener
66*cdf0e10cSrcweir {
67*cdf0e10cSrcweir private:
68*cdf0e10cSrcweir 	SdrModel*		mpModel;
69*cdf0e10cSrcweir 	SfxItemPool*	mpModelPool;
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir 	ItemPoolVector maItemSetVector;
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir public:
74*cdf0e10cSrcweir 	SvxUnoMarkerTable( SdrModel* pModel ) throw();
75*cdf0e10cSrcweir 	virtual	~SvxUnoMarkerTable() throw();
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir 	void dispose();
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir 	// SfxListener
80*cdf0e10cSrcweir 	virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) throw ();
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir 	void SAL_CALL ImplInsertByName( const OUString& aName, const uno::Any& aElement );
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir     // XServiceInfo
85*cdf0e10cSrcweir     virtual OUString SAL_CALL getImplementationName(  ) throw( uno::RuntimeException );
86*cdf0e10cSrcweir     virtual sal_Bool SAL_CALL supportsService( const  OUString& ServiceName ) throw( uno::RuntimeException);
87*cdf0e10cSrcweir     virtual uno::Sequence<  OUString > SAL_CALL getSupportedServiceNames(  ) throw( uno::RuntimeException);
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir 	// XNameContainer
90*cdf0e10cSrcweir 	virtual void SAL_CALL insertByName( const  OUString& aName, const  uno::Any& aElement ) throw( lang::IllegalArgumentException, container::ElementExistException, lang::WrappedTargetException, uno::RuntimeException);
91*cdf0e10cSrcweir 	virtual void SAL_CALL removeByName( const  OUString& Name ) throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException);
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir 	// XNameReplace
94*cdf0e10cSrcweir     virtual void SAL_CALL replaceByName( const  OUString& aName, const  uno::Any& aElement ) throw( lang::IllegalArgumentException, container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException);
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir 	// XNameAccess
97*cdf0e10cSrcweir     virtual uno::Any SAL_CALL getByName( const  OUString& aName ) throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException);
98*cdf0e10cSrcweir     virtual uno::Sequence<  OUString > SAL_CALL getElementNames(  ) throw( uno::RuntimeException);
99*cdf0e10cSrcweir     virtual sal_Bool SAL_CALL hasByName( const  OUString& aName ) throw( uno::RuntimeException);
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir 	// XElementAccess
102*cdf0e10cSrcweir     virtual uno::Type SAL_CALL getElementType(  ) throw( uno::RuntimeException);
103*cdf0e10cSrcweir     virtual sal_Bool SAL_CALL hasElements(  ) throw( uno::RuntimeException);
104*cdf0e10cSrcweir };
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir SvxUnoMarkerTable::SvxUnoMarkerTable( SdrModel* pModel ) throw()
107*cdf0e10cSrcweir : mpModel( pModel ),
108*cdf0e10cSrcweir   mpModelPool( pModel ? &pModel->GetItemPool() : (SfxItemPool*)NULL )
109*cdf0e10cSrcweir {
110*cdf0e10cSrcweir 	if( pModel )
111*cdf0e10cSrcweir 		StartListening( *pModel );
112*cdf0e10cSrcweir }
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir SvxUnoMarkerTable::~SvxUnoMarkerTable() throw()
115*cdf0e10cSrcweir {
116*cdf0e10cSrcweir 	if( mpModel )
117*cdf0e10cSrcweir 		EndListening( *mpModel );
118*cdf0e10cSrcweir 	dispose();
119*cdf0e10cSrcweir }
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir void SvxUnoMarkerTable::dispose()
122*cdf0e10cSrcweir {
123*cdf0e10cSrcweir 	ItemPoolVector::iterator aIter = maItemSetVector.begin();
124*cdf0e10cSrcweir 	const ItemPoolVector::iterator aEnd = maItemSetVector.end();
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir 	while( aIter != aEnd )
127*cdf0e10cSrcweir 	{
128*cdf0e10cSrcweir 		delete (*aIter++);
129*cdf0e10cSrcweir 	}
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir 	maItemSetVector.clear();
132*cdf0e10cSrcweir }
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir // SfxListener
135*cdf0e10cSrcweir void SvxUnoMarkerTable::Notify( SfxBroadcaster&, const SfxHint& rHint ) throw()
136*cdf0e10cSrcweir {
137*cdf0e10cSrcweir 	const SdrHint* pSdrHint = PTR_CAST( SdrHint, &rHint );
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir 	if( pSdrHint && HINT_MODELCLEARED == pSdrHint->GetKind() )
140*cdf0e10cSrcweir 		dispose();
141*cdf0e10cSrcweir }
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir sal_Bool SAL_CALL SvxUnoMarkerTable::supportsService( const  OUString& ServiceName ) throw(uno::RuntimeException)
144*cdf0e10cSrcweir {
145*cdf0e10cSrcweir     uno::Sequence< OUString > aSNL( getSupportedServiceNames() );
146*cdf0e10cSrcweir     const OUString * pArray = aSNL.getConstArray();
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir     for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
149*cdf0e10cSrcweir         if( pArray[i] == ServiceName )
150*cdf0e10cSrcweir             return sal_True;
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir     return sal_False;
153*cdf0e10cSrcweir }
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir OUString SAL_CALL SvxUnoMarkerTable::getImplementationName() throw( uno::RuntimeException )
156*cdf0e10cSrcweir {
157*cdf0e10cSrcweir 	return OUString( RTL_CONSTASCII_USTRINGPARAM("SvxUnoMarkerTable") );
158*cdf0e10cSrcweir }
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir uno::Sequence< OUString > SAL_CALL SvxUnoMarkerTable::getSupportedServiceNames(  )
161*cdf0e10cSrcweir 	throw( uno::RuntimeException )
162*cdf0e10cSrcweir {
163*cdf0e10cSrcweir     uno::Sequence< OUString > aSNS( 1 );
164*cdf0e10cSrcweir     aSNS.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.MarkerTable" ));
165*cdf0e10cSrcweir     return aSNS;
166*cdf0e10cSrcweir }
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir void SAL_CALL SvxUnoMarkerTable::ImplInsertByName( const OUString& aName, const uno::Any& aElement )
169*cdf0e10cSrcweir {
170*cdf0e10cSrcweir 	SfxItemSet* mpInSet = new SfxItemSet( *mpModelPool, XATTR_LINESTART, XATTR_LINEEND );
171*cdf0e10cSrcweir 	maItemSetVector.push_back( mpInSet );
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir 	XLineEndItem aEndMarker;
174*cdf0e10cSrcweir 	aEndMarker.SetName( String( aName ) );
175*cdf0e10cSrcweir 	aEndMarker.PutValue( aElement );
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir 	mpInSet->Put( aEndMarker, XATTR_LINEEND );
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir 	XLineStartItem aStartMarker;
180*cdf0e10cSrcweir 	aStartMarker.SetName( String( aName ) );
181*cdf0e10cSrcweir 	aStartMarker.PutValue( aElement );
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir 	mpInSet->Put( aStartMarker, XATTR_LINESTART );
184*cdf0e10cSrcweir }
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir // XNameContainer
187*cdf0e10cSrcweir void SAL_CALL SvxUnoMarkerTable::insertByName( const OUString& aApiName, const uno::Any& aElement )
188*cdf0e10cSrcweir 	throw( lang::IllegalArgumentException, container::ElementExistException, lang::WrappedTargetException, uno::RuntimeException )
189*cdf0e10cSrcweir {
190*cdf0e10cSrcweir 	OGuard aGuard( Application::GetSolarMutex() );
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir 	if( hasByName( aApiName ) )
193*cdf0e10cSrcweir 		throw container::ElementExistException();
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir 	String aName;
196*cdf0e10cSrcweir 	SvxUnogetInternalNameForItem( XATTR_LINEEND, aApiName, aName );
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir 	ImplInsertByName( aName, aElement );
199*cdf0e10cSrcweir }
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir void SAL_CALL SvxUnoMarkerTable::removeByName( const OUString& aApiName )
202*cdf0e10cSrcweir 	throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
203*cdf0e10cSrcweir {
204*cdf0e10cSrcweir 	OGuard aGuard( Application::GetSolarMutex() );
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir 	// a little quickfix for 2.0 to let applications clear api
207*cdf0e10cSrcweir 	// created items that are not used
208*cdf0e10cSrcweir 	if( aApiName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("~clear~") ) )
209*cdf0e10cSrcweir 	{
210*cdf0e10cSrcweir 		dispose();
211*cdf0e10cSrcweir 		return;
212*cdf0e10cSrcweir 	}
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir 	String Name;
215*cdf0e10cSrcweir 	SvxUnogetInternalNameForItem( XATTR_LINEEND, aApiName, Name );
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir 	ItemPoolVector::iterator aIter = maItemSetVector.begin();
218*cdf0e10cSrcweir 	const ItemPoolVector::iterator aEnd = maItemSetVector.end();
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir 	NameOrIndex *pItem;
221*cdf0e10cSrcweir 	const String aSearchName( Name );
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir 	while( aIter != aEnd )
224*cdf0e10cSrcweir 	{
225*cdf0e10cSrcweir 		pItem = (NameOrIndex *)&((*aIter)->Get( XATTR_LINEEND ) );
226*cdf0e10cSrcweir 		if( pItem->GetName() == aSearchName )
227*cdf0e10cSrcweir 		{
228*cdf0e10cSrcweir 			delete (*aIter);
229*cdf0e10cSrcweir 			maItemSetVector.erase( aIter );
230*cdf0e10cSrcweir 			return;
231*cdf0e10cSrcweir 		}
232*cdf0e10cSrcweir 		aIter++;
233*cdf0e10cSrcweir 	}
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir 	if( !hasByName( Name ) )
236*cdf0e10cSrcweir 		throw container::NoSuchElementException();
237*cdf0e10cSrcweir }
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir // XNameReplace
240*cdf0e10cSrcweir void SAL_CALL SvxUnoMarkerTable::replaceByName( const OUString& aApiName, const uno::Any& aElement )
241*cdf0e10cSrcweir 	throw( lang::IllegalArgumentException, container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException )
242*cdf0e10cSrcweir {
243*cdf0e10cSrcweir 	OGuard aGuard( Application::GetSolarMutex() );
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir 	String aName;
246*cdf0e10cSrcweir 	SvxUnogetInternalNameForItem( XATTR_LINEEND, aApiName, aName );
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir 	ItemPoolVector::iterator aIter = maItemSetVector.begin();
249*cdf0e10cSrcweir 	const ItemPoolVector::iterator aEnd = maItemSetVector.end();
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir 	NameOrIndex *pItem;
252*cdf0e10cSrcweir 	const String aSearchName( aName );
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir 	while( aIter != aEnd )
255*cdf0e10cSrcweir 	{
256*cdf0e10cSrcweir 		pItem = (NameOrIndex *)&((*aIter)->Get( XATTR_LINEEND ) );
257*cdf0e10cSrcweir 		if( pItem->GetName() == aSearchName )
258*cdf0e10cSrcweir 		{
259*cdf0e10cSrcweir 			XLineEndItem aEndMarker;
260*cdf0e10cSrcweir 			aEndMarker.SetName( aSearchName );
261*cdf0e10cSrcweir 			if( !aEndMarker.PutValue( aElement ) )
262*cdf0e10cSrcweir 				throw lang::IllegalArgumentException();
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir 			(*aIter)->Put( aEndMarker, XATTR_LINEEND );
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir 			XLineStartItem aStartMarker;
267*cdf0e10cSrcweir 			aStartMarker.SetName( aSearchName );
268*cdf0e10cSrcweir 			aStartMarker.PutValue( aElement );
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir 			(*aIter)->Put( aStartMarker, XATTR_LINESTART );
271*cdf0e10cSrcweir 			return;
272*cdf0e10cSrcweir 		}
273*cdf0e10cSrcweir 		aIter++;
274*cdf0e10cSrcweir 	}
275*cdf0e10cSrcweir 
276*cdf0e10cSrcweir 	// if it is not in our own sets, modify the pool!
277*cdf0e10cSrcweir 	sal_Bool bFound = sal_False;
278*cdf0e10cSrcweir 
279*cdf0e10cSrcweir 	sal_uInt32 nSurrogate;
280*cdf0e10cSrcweir 	const sal_uInt32 nStartCount = mpModelPool ? mpModelPool->GetItemCount2( XATTR_LINESTART ) : 0;
281*cdf0e10cSrcweir 	for( nSurrogate = 0; nSurrogate < nStartCount; nSurrogate++ )
282*cdf0e10cSrcweir 	{
283*cdf0e10cSrcweir 		pItem = (NameOrIndex*)mpModelPool->GetItem2( XATTR_LINESTART, nSurrogate);
284*cdf0e10cSrcweir 		if( pItem && pItem->GetName() == aSearchName )
285*cdf0e10cSrcweir 		{
286*cdf0e10cSrcweir 			pItem->PutValue( aElement );
287*cdf0e10cSrcweir 			bFound = sal_True;
288*cdf0e10cSrcweir 			break;
289*cdf0e10cSrcweir 		}
290*cdf0e10cSrcweir 	}
291*cdf0e10cSrcweir 
292*cdf0e10cSrcweir 	const sal_uInt32 nEndCount = mpModelPool ? mpModelPool->GetItemCount2( XATTR_LINEEND ) : 0;
293*cdf0e10cSrcweir 	for( nSurrogate = 0; nSurrogate < nEndCount; nSurrogate++ )
294*cdf0e10cSrcweir 	{
295*cdf0e10cSrcweir 		pItem = (NameOrIndex*)mpModelPool->GetItem2( XATTR_LINEEND, nSurrogate);
296*cdf0e10cSrcweir 		if( pItem && pItem->GetName() == aSearchName )
297*cdf0e10cSrcweir 		{
298*cdf0e10cSrcweir 			pItem->PutValue( aElement );
299*cdf0e10cSrcweir 			bFound = sal_True;
300*cdf0e10cSrcweir 			break;
301*cdf0e10cSrcweir 		}
302*cdf0e10cSrcweir 	}
303*cdf0e10cSrcweir 
304*cdf0e10cSrcweir 	if( bFound )
305*cdf0e10cSrcweir 		ImplInsertByName( aName, aElement );
306*cdf0e10cSrcweir 	else
307*cdf0e10cSrcweir 		throw container::NoSuchElementException();
308*cdf0e10cSrcweir }
309*cdf0e10cSrcweir 
310*cdf0e10cSrcweir static sal_Bool getByNameFromPool( const String& rSearchName, SfxItemPool* pPool, sal_uInt16 nWhich, uno::Any& rAny )
311*cdf0e10cSrcweir {
312*cdf0e10cSrcweir 	NameOrIndex *pItem;
313*cdf0e10cSrcweir 	const sal_uInt32 nSurrogateCount = pPool ? pPool->GetItemCount2( nWhich ) : 0;
314*cdf0e10cSrcweir 	for( sal_uInt32 nSurrogate = 0; nSurrogate < nSurrogateCount; nSurrogate++ )
315*cdf0e10cSrcweir 	{
316*cdf0e10cSrcweir 		pItem = (NameOrIndex*)pPool->GetItem2( nWhich, nSurrogate );
317*cdf0e10cSrcweir 
318*cdf0e10cSrcweir 		if( pItem && pItem->GetName() == rSearchName )
319*cdf0e10cSrcweir 		{
320*cdf0e10cSrcweir 			pItem->QueryValue( rAny, 0 );
321*cdf0e10cSrcweir 			return sal_True;
322*cdf0e10cSrcweir 		}
323*cdf0e10cSrcweir 	}
324*cdf0e10cSrcweir 
325*cdf0e10cSrcweir 	return sal_False;
326*cdf0e10cSrcweir }
327*cdf0e10cSrcweir 
328*cdf0e10cSrcweir // XNameAccess
329*cdf0e10cSrcweir uno::Any SAL_CALL SvxUnoMarkerTable::getByName( const OUString& aApiName )
330*cdf0e10cSrcweir 	throw( container::NoSuchElementException,  lang::WrappedTargetException, uno::RuntimeException)
331*cdf0e10cSrcweir {
332*cdf0e10cSrcweir 	OGuard aGuard( Application::GetSolarMutex() );
333*cdf0e10cSrcweir 
334*cdf0e10cSrcweir 	String aName;
335*cdf0e10cSrcweir 	SvxUnogetInternalNameForItem( XATTR_LINEEND, aApiName, aName );
336*cdf0e10cSrcweir 
337*cdf0e10cSrcweir 	uno::Any aAny;
338*cdf0e10cSrcweir 
339*cdf0e10cSrcweir 	if( mpModelPool && aName.Len() != 0 )
340*cdf0e10cSrcweir 	{
341*cdf0e10cSrcweir 		do
342*cdf0e10cSrcweir 		{
343*cdf0e10cSrcweir 			const String aSearchName( aName );
344*cdf0e10cSrcweir 			if( getByNameFromPool( aSearchName, mpModelPool, XATTR_LINESTART, aAny ) )
345*cdf0e10cSrcweir 				break;
346*cdf0e10cSrcweir 
347*cdf0e10cSrcweir 			if( getByNameFromPool( aSearchName, mpModelPool, XATTR_LINEEND, aAny ) )
348*cdf0e10cSrcweir 				break;
349*cdf0e10cSrcweir 
350*cdf0e10cSrcweir 			throw container::NoSuchElementException();
351*cdf0e10cSrcweir 		}
352*cdf0e10cSrcweir 		while(0);
353*cdf0e10cSrcweir 	}
354*cdf0e10cSrcweir 
355*cdf0e10cSrcweir 	return aAny;
356*cdf0e10cSrcweir }
357*cdf0e10cSrcweir 
358*cdf0e10cSrcweir static void createNamesForPool( SfxItemPool* pPool, sal_uInt16 nWhich, std::set< OUString, comphelper::UStringLess >& rNameSet )
359*cdf0e10cSrcweir {
360*cdf0e10cSrcweir 	const sal_uInt32 nSuroCount = pPool->GetItemCount2( nWhich );
361*cdf0e10cSrcweir 	sal_uInt32 nSurrogate;
362*cdf0e10cSrcweir 
363*cdf0e10cSrcweir 	NameOrIndex* pItem;
364*cdf0e10cSrcweir 	OUString aName;
365*cdf0e10cSrcweir 
366*cdf0e10cSrcweir 	for( nSurrogate = 0; nSurrogate < nSuroCount; nSurrogate++ )
367*cdf0e10cSrcweir 	{
368*cdf0e10cSrcweir 		pItem = (NameOrIndex*)pPool->GetItem2( nWhich, nSurrogate );
369*cdf0e10cSrcweir 
370*cdf0e10cSrcweir 		if( pItem == NULL || pItem->GetName().Len() == 0 )
371*cdf0e10cSrcweir 			continue;
372*cdf0e10cSrcweir 
373*cdf0e10cSrcweir 		SvxUnogetApiNameForItem( XATTR_LINEEND, pItem->GetName(), aName );
374*cdf0e10cSrcweir 		rNameSet.insert( aName );
375*cdf0e10cSrcweir 	}
376*cdf0e10cSrcweir }
377*cdf0e10cSrcweir 
378*cdf0e10cSrcweir uno::Sequence< OUString > SAL_CALL SvxUnoMarkerTable::getElementNames()
379*cdf0e10cSrcweir 	throw( uno::RuntimeException )
380*cdf0e10cSrcweir {
381*cdf0e10cSrcweir 	OGuard aGuard( Application::GetSolarMutex() );
382*cdf0e10cSrcweir 
383*cdf0e10cSrcweir 	std::set< OUString, comphelper::UStringLess > aNameSet;
384*cdf0e10cSrcweir 
385*cdf0e10cSrcweir 	// search model pool for line starts
386*cdf0e10cSrcweir 	createNamesForPool( mpModelPool, XATTR_LINESTART, aNameSet );
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir 	// search model pool for line ends
389*cdf0e10cSrcweir 	createNamesForPool( mpModelPool, XATTR_LINEEND, aNameSet );
390*cdf0e10cSrcweir 
391*cdf0e10cSrcweir 	uno::Sequence< OUString > aSeq( aNameSet.size() );
392*cdf0e10cSrcweir 	OUString* pNames = aSeq.getArray();
393*cdf0e10cSrcweir 
394*cdf0e10cSrcweir 	std::set< OUString, comphelper::UStringLess >::iterator aIter( aNameSet.begin() );
395*cdf0e10cSrcweir 	const std::set< OUString, comphelper::UStringLess >::iterator aEnd( aNameSet.end() );
396*cdf0e10cSrcweir 
397*cdf0e10cSrcweir 	while( aIter != aEnd )
398*cdf0e10cSrcweir 	{
399*cdf0e10cSrcweir 		*pNames++ = *aIter++;
400*cdf0e10cSrcweir 	}
401*cdf0e10cSrcweir 
402*cdf0e10cSrcweir 	return aSeq;
403*cdf0e10cSrcweir }
404*cdf0e10cSrcweir 
405*cdf0e10cSrcweir sal_Bool SAL_CALL SvxUnoMarkerTable::hasByName( const OUString& aName )
406*cdf0e10cSrcweir 	throw( uno::RuntimeException )
407*cdf0e10cSrcweir {
408*cdf0e10cSrcweir 	OGuard aGuard( Application::GetSolarMutex() );
409*cdf0e10cSrcweir 
410*cdf0e10cSrcweir 	if( aName.getLength() == 0 )
411*cdf0e10cSrcweir 		return sal_False;
412*cdf0e10cSrcweir 
413*cdf0e10cSrcweir 	String aSearchName;
414*cdf0e10cSrcweir 
415*cdf0e10cSrcweir 	NameOrIndex *pItem;
416*cdf0e10cSrcweir 
417*cdf0e10cSrcweir 	SvxUnogetInternalNameForItem( XATTR_LINESTART, aName, aSearchName );
418*cdf0e10cSrcweir 	sal_uInt32 nStartCount = mpModelPool ? mpModelPool->GetItemCount2( XATTR_LINESTART ) : 0;
419*cdf0e10cSrcweir 	sal_uInt32 nSurrogate;
420*cdf0e10cSrcweir 	for( nSurrogate = 0; nSurrogate < nStartCount; nSurrogate++ )
421*cdf0e10cSrcweir 	{
422*cdf0e10cSrcweir 		pItem = (NameOrIndex*)mpModelPool->GetItem2( XATTR_LINESTART, nSurrogate);
423*cdf0e10cSrcweir 		if( pItem && pItem->GetName() == aSearchName )
424*cdf0e10cSrcweir 			return sal_True;
425*cdf0e10cSrcweir 	}
426*cdf0e10cSrcweir 
427*cdf0e10cSrcweir 	SvxUnogetInternalNameForItem( XATTR_LINEEND, aName, aSearchName );
428*cdf0e10cSrcweir 	sal_uInt32 nEndCount = mpModelPool ? mpModelPool->GetItemCount2( XATTR_LINEEND ) : 0;
429*cdf0e10cSrcweir 	for( nSurrogate = 0; nSurrogate < nEndCount; nSurrogate++ )
430*cdf0e10cSrcweir 	{
431*cdf0e10cSrcweir 		pItem = (NameOrIndex*)mpModelPool->GetItem2( XATTR_LINEEND, nSurrogate);
432*cdf0e10cSrcweir 		if( pItem && pItem->GetName() == aSearchName )
433*cdf0e10cSrcweir 			return sal_True;
434*cdf0e10cSrcweir 	}
435*cdf0e10cSrcweir 
436*cdf0e10cSrcweir 	return sal_False;
437*cdf0e10cSrcweir }
438*cdf0e10cSrcweir 
439*cdf0e10cSrcweir // XElementAccess
440*cdf0e10cSrcweir uno::Type SAL_CALL SvxUnoMarkerTable::getElementType(  )
441*cdf0e10cSrcweir 	throw( uno::RuntimeException )
442*cdf0e10cSrcweir {
443*cdf0e10cSrcweir 	return ::getCppuType((const drawing::PointSequence*)0);
444*cdf0e10cSrcweir }
445*cdf0e10cSrcweir 
446*cdf0e10cSrcweir sal_Bool SAL_CALL SvxUnoMarkerTable::hasElements(  )
447*cdf0e10cSrcweir 	throw( uno::RuntimeException )
448*cdf0e10cSrcweir {
449*cdf0e10cSrcweir 	OGuard aGuard( Application::GetSolarMutex() );
450*cdf0e10cSrcweir 
451*cdf0e10cSrcweir 	NameOrIndex *pItem;
452*cdf0e10cSrcweir 
453*cdf0e10cSrcweir 	const sal_uInt32 nStartCount = mpModelPool ? mpModelPool->GetItemCount2( XATTR_LINESTART ) : 0;
454*cdf0e10cSrcweir 	sal_uInt32 nSurrogate;
455*cdf0e10cSrcweir 	for( nSurrogate = 0; nSurrogate < nStartCount; nSurrogate++ )
456*cdf0e10cSrcweir 	{
457*cdf0e10cSrcweir 		pItem = (NameOrIndex*)mpModelPool->GetItem2( XATTR_LINESTART, nSurrogate);
458*cdf0e10cSrcweir 		if( pItem && pItem->GetName().Len() != 0 )
459*cdf0e10cSrcweir 			return sal_True;
460*cdf0e10cSrcweir 	}
461*cdf0e10cSrcweir 
462*cdf0e10cSrcweir 	const sal_uInt32 nEndCount = mpModelPool ? mpModelPool->GetItemCount2( XATTR_LINEEND ) : 0;
463*cdf0e10cSrcweir 	for( nSurrogate = 0; nSurrogate < nEndCount; nSurrogate++ )
464*cdf0e10cSrcweir 	{
465*cdf0e10cSrcweir 		pItem = (NameOrIndex*)mpModelPool->GetItem2( XATTR_LINEEND, nSurrogate);
466*cdf0e10cSrcweir 		if( pItem && pItem->GetName().Len() != 0 )
467*cdf0e10cSrcweir 			return sal_True;
468*cdf0e10cSrcweir 	}
469*cdf0e10cSrcweir 
470*cdf0e10cSrcweir 	return sal_False;
471*cdf0e10cSrcweir }
472*cdf0e10cSrcweir 
473*cdf0e10cSrcweir /**
474*cdf0e10cSrcweir  * Create a hatchtable
475*cdf0e10cSrcweir  */
476*cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL SvxUnoMarkerTable_createInstance( SdrModel* pModel )
477*cdf0e10cSrcweir {
478*cdf0e10cSrcweir 	return *new SvxUnoMarkerTable(pModel);
479*cdf0e10cSrcweir }
480*cdf0e10cSrcweir 
481*cdf0e10cSrcweir 
482*cdf0e10cSrcweir 
483