xref: /aoo42x/main/svx/source/unodraw/unomod.cxx (revision f6e50924)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26 
27 #define _SVX_USE_UNOGLOBALS_
28 #include <com/sun/star/lang/ServiceNotRegisteredException.hpp>
29 #include <com/sun/star/lang/NoSupportException.hpp>
30 #include <com/sun/star/drawing/XShape.hpp>
31 #include <vos/mutex.hxx>
32 #include <vcl/svapp.hxx>
33 #include <tools/list.hxx>
34 #include <svl/itemprop.hxx>
35 #include <svtools/unoevent.hxx>
36 #include <comphelper/sequence.hxx>
37 #include <comphelper/serviceinfohelper.hxx>
38 
39 #include <cppuhelper/implbase2.hxx>
40 #include <svx/unofill.hxx>
41 #include <editeng/unonrule.hxx>
42 #include <svtools/unoimap.hxx>
43 #include <svx/fmdpage.hxx>
44 #include <svx/fmmodel.hxx>
45 #include <svx/fmpage.hxx>
46 #include <sfx2/sfx.hrc>
47 #include <svx/unoapi.hxx>
48 
49 #include <svx/svdmodel.hxx>
50 #include "svx/globl3d.hxx"
51 #include <svx/svdtypes.hxx>
52 #include <svx/unoprov.hxx>
53 #include <svx/unopage.hxx>
54 #include <editeng/unofield.hxx>
55 #include <svx/unomod.hxx>
56 #include <svx/unomodel.hxx>
57 #include <svx/svdobj.hxx>
58 #include <svx/svdpage.hxx>
59 #include <svx/unoshape.hxx>
60 
61 extern UHashMapEntry pSdrShapeIdentifierMap[];
62 
63 //-////////////////////////////////////////////////////////////////////
64 
65 using namespace ::rtl;
66 using namespace ::osl;
67 using namespace ::vos;
68 using namespace ::com::sun::star;
69 
70 //-////////////////////////////////////////////////////////////////////
71 
72 #define QUERYINT( xint ) \
73 	if( rType == ::getCppuType((const uno::Reference< xint >*)0) ) \
74 		aAny <<= uno::Reference< xint >(this)
75 
76 #define ITYPE( xint ) \
77 	::getCppuType((const uno::Reference< xint >*)0)
78 
79 //-////////////////////////////////////////////////////////////////////
80 
81 #ifndef SVX_LIGHT
82 
83 class SvxUnoDrawPagesAccess : public ::cppu::WeakImplHelper2< ::com::sun::star::drawing::XDrawPages, ::com::sun::star::lang::XServiceInfo >
84 {
85 private:
86 	SvxUnoDrawingModel&	mrModel;
87 
88 public:
89 	SvxUnoDrawPagesAccess( SvxUnoDrawingModel& rMyModel ) throw();
90 	virtual ~SvxUnoDrawPagesAccess() throw();
91 
92 	// XDrawPages
93     virtual ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage > SAL_CALL insertNewByIndex( sal_Int32 nIndex ) throw(::com::sun::star::uno::RuntimeException);
94     virtual void SAL_CALL remove( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >& xPage ) throw(::com::sun::star::uno::RuntimeException);
95 
96 	// XIndexAccess
97     virtual sal_Int32 SAL_CALL getCount() throw(::com::sun::star::uno::RuntimeException) ;
98     virtual ::com::sun::star::uno::Any SAL_CALL getByIndex( sal_Int32 Index ) throw(::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
99 
100 	// XElementAccess
101     virtual ::com::sun::star::uno::Type SAL_CALL getElementType() throw(::com::sun::star::uno::RuntimeException);
102     virtual sal_Bool SAL_CALL hasElements() throw(::com::sun::star::uno::RuntimeException);
103 
104     // XServiceInfo
105     virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw(::com::sun::star::uno::RuntimeException);
106     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException);
107     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw(::com::sun::star::uno::RuntimeException);
108 };
109 #endif
110 //-////////////////////////////////////////////////////////////////////
111 
112 #ifndef SVX_LIGHT
ImplGetSupportedMacroItems()113 const SvEventDescription* ImplGetSupportedMacroItems()
114 {
115 	static const SvEventDescription aMacroDescriptionsImpl[] =
116 	{
117 		{ SFX_EVENT_MOUSEOVER_OBJECT, "OnMouseOver" },
118 		{ SFX_EVENT_MOUSEOUT_OBJECT, "OnMouseOut" },
119 		{ 0, NULL }
120 	};
121 
122 	return aMacroDescriptionsImpl;
123 }
124 #endif
125 
126 //-////////////////////////////////////////////////////////////////////
127 
128 /** fills the given EventObject from the given SdrHint.
129 	@returns
130 		true	if the SdrHint could be translated to an EventObject<br>
131 		false	if not
132 */
createEvent(const SdrModel * pDoc,const SdrHint * pSdrHint,::com::sun::star::document::EventObject & aEvent)133 sal_Bool SvxUnoDrawMSFactory::createEvent( const SdrModel* pDoc, const SdrHint* pSdrHint, ::com::sun::star::document::EventObject& aEvent )
134 {
135 	const SdrObject* pObj = NULL;
136 	const SdrPage* pPage = NULL;
137 
138 	switch( pSdrHint->GetKind() )
139 	{
140 //				case HINT_LAYERCHG:				// Layerdefinition geaendert
141 //				case HINT_LAYERORDERCHG:		// Layerreihenfolge geaendert (Insert/Remove/ChangePos)
142 //				case HINT_LAYERSETCHG:			// Layerset geaendert
143 //				case HINT_LAYERSETORDERCHG:		// Layersetreihenfolge geaendert (Insert/Remove/ChangePos)
144 
145 // #115423#
146 //		case HINT_PAGECHG:				// Page geaendert
147 //			aEvent.EventName = OUString( RTL_CONSTASCII_USTRINGPARAM( "PageModified" ) );
148 //			pPage = pSdrHint->GetPage();
149 //			break;
150 		case HINT_PAGEORDERCHG:			// Reihenfolge der Seiten (Zeichenseiten oder Masterpages) geaendert (Insert/Remove/ChangePos)
151 			aEvent.EventName = OUString( RTL_CONSTASCII_USTRINGPARAM( "PageOrderModified" ) );
152 			pPage = pSdrHint->GetPage();
153 			break;
154 		case HINT_OBJCHG:				// Objekt geaendert
155 			aEvent.EventName = OUString( RTL_CONSTASCII_USTRINGPARAM( "ShapeModified" ) );
156 			pObj = pSdrHint->GetObject();
157 			break;
158 		case HINT_OBJINSERTED:			// Neues Zeichenobjekt eingefuegt
159 			aEvent.EventName = OUString( RTL_CONSTASCII_USTRINGPARAM( "ShapeInserted" ) );
160 			pObj = pSdrHint->GetObject();
161 			break;
162 		case HINT_OBJREMOVED:			// Zeichenobjekt aus Liste entfernt
163 			aEvent.EventName = OUString( RTL_CONSTASCII_USTRINGPARAM( "ShapeRemoved" ) );
164 			pObj = pSdrHint->GetObject();
165 			break;
166 //				  HINT_DEFAULTTABCHG,   // Default Tabulatorweite geaendert
167 //				  HINT_DEFFONTHGTCHG,   // Default FontHeight geaendert
168 //				  HINT_SWITCHTOPAGE,    // #94278# UNDO/REDO at an object evtl. on another page
169 //				  HINT_OBJLISTCLEAR		// Is called before an SdrObjList will be cleared
170 		default:
171 			return sal_False;
172 	}
173 
174 	if( pObj )
175 		aEvent.Source = const_cast<SdrObject*>(pObj)->getUnoShape();
176 	else if( pPage )
177 		aEvent.Source = const_cast<SdrPage*>(pPage)->getUnoPage();
178 	else
179 		aEvent.Source = (const_cast<SdrModel*>(pDoc))->getUnoModel();
180 
181 	return sal_True;
182 }
183 
createInstance(const OUString & ServiceSpecifier)184 uno::Reference< uno::XInterface > SAL_CALL SvxUnoDrawMSFactory::createInstance( const OUString& ServiceSpecifier )
185 	throw( uno::Exception, uno::RuntimeException )
186 {
187 	const OUString aDrawingPrefix( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.") );
188 
189 	if( ServiceSpecifier.compareTo( aDrawingPrefix, aDrawingPrefix.getLength() ) == 0 )
190 	{
191 		sal_uInt32 nType = aSdrShapeIdentifierMap.getId( ServiceSpecifier );
192 		if( nType != UHASHMAP_NOTFOUND )
193 		{
194 			sal_uInt16 nT = (sal_uInt16)(nType & ~E3D_INVENTOR_FLAG);
195 			sal_uInt32 nI = (nType & E3D_INVENTOR_FLAG)?E3dInventor:SdrInventor;
196 
197 			return uno::Reference< uno::XInterface >( (drawing::XShape*) SvxDrawPage::CreateShapeByTypeAndInventor( nT, nI ) );
198 		}
199 	}
200 
201 	uno::Reference< uno::XInterface > xRet( createTextField( ServiceSpecifier ) );
202 	if( !xRet.is() )
203 		throw lang::ServiceNotRegisteredException();
204 
205 	return xRet;
206 }
207 
createTextField(const::rtl::OUString & ServiceSpecifier)208 uno::Reference< uno::XInterface > SAL_CALL SvxUnoDrawMSFactory::createTextField( const ::rtl::OUString& ServiceSpecifier ) throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
209 {
210 	return SvxUnoTextCreateTextField( ServiceSpecifier );
211 }
212 
createInstanceWithArguments(const OUString &,const uno::Sequence<::com::sun::star::uno::Any> &)213 uno::Reference< uno::XInterface > SAL_CALL SvxUnoDrawMSFactory::createInstanceWithArguments( const OUString&, const uno::Sequence< ::com::sun::star::uno::Any >& )
214 	throw( uno::Exception, uno::RuntimeException )
215 {
216 	throw lang::NoSupportException();
217 }
218 
getAvailableServiceNames()219 uno::Sequence< OUString > SAL_CALL SvxUnoDrawMSFactory::getAvailableServiceNames()
220 	throw( uno::RuntimeException )
221 {
222 	UHashMapEntry* pMap = pSdrShapeIdentifierMap;
223 
224 	sal_uInt32 nCount = 0;
225 	while (pMap->aIdentifier.getLength())
226 	{
227 		pMap++;
228 		nCount++;
229 	}
230 
231 	uno::Sequence< OUString > aSeq( nCount );
232 	OUString* pStrings = aSeq.getArray();
233 
234 	pMap = pSdrShapeIdentifierMap;
235 	sal_uInt32 nIdx = 0;
236 	while(pMap->aIdentifier.getLength())
237 	{
238 		pStrings[nIdx] = pMap->aIdentifier;
239 		pMap++;
240 		nIdx++;
241 	}
242 
243 	return aSeq;
244 }
245 
concatServiceNames(uno::Sequence<OUString> & rServices1,uno::Sequence<OUString> & rServices2)246 uno::Sequence< OUString > SvxUnoDrawMSFactory::concatServiceNames( uno::Sequence< OUString >& rServices1, uno::Sequence< OUString >& rServices2 ) throw()
247 {
248 	const sal_Int32 nLen1 = rServices1.getLength();
249 	const sal_Int32 nLen2 = rServices2.getLength();
250 
251 	uno::Sequence< OUString > aSeq( nLen1+nLen2 );
252 	OUString* pStrings = aSeq.getArray();
253 
254 	sal_Int32 nIdx;
255 	OUString* pStringDst = pStrings;
256 	const OUString* pStringSrc = rServices1.getArray();
257 
258 	for( nIdx = 0; nIdx < nLen1; nIdx++ )
259 		*pStringDst++ = *pStringSrc++;
260 
261 	pStringSrc = rServices2.getArray();
262 
263 	for( nIdx = 0; nIdx < nLen2; nIdx++ )
264 		*pStringDst++ = *pStringSrc++;
265 
266 	return aSeq;
267 }
268 
269 
270 #ifndef SVX_LIGHT
271 
272 ///
SvxUnoDrawingModel(SdrModel * pDoc)273 SvxUnoDrawingModel::SvxUnoDrawingModel( SdrModel* pDoc ) throw()
274 : mpDoc( pDoc )
275 {
276 }
277 
~SvxUnoDrawingModel()278 SvxUnoDrawingModel::~SvxUnoDrawingModel() throw()
279 {
280 }
281 
queryInterface(const uno::Type & rType)282 uno::Any SAL_CALL SvxUnoDrawingModel::queryInterface( const uno::Type & rType ) throw(uno::RuntimeException)
283 {
284 	uno::Any aAny;
285 
286 	QUERYINT(lang::XServiceInfo);
287 	else QUERYINT(lang::XMultiServiceFactory);
288 	else QUERYINT(drawing::XDrawPagesSupplier);
289 	else QUERYINT(com::sun::star::ucb::XAnyCompareFactory);
290 	else
291 		return SfxBaseModel::queryInterface( rType );
292 
293 	return aAny;
294 }
295 
acquire()296 void SAL_CALL SvxUnoDrawingModel::acquire() throw ( )
297 {
298 	SfxBaseModel::acquire();
299 }
300 
release()301 void SAL_CALL SvxUnoDrawingModel::release() throw ( )
302 {
303 	SfxBaseModel::release();
304 }
305 
306 // XTypeProvider
getTypes()307 uno::Sequence< uno::Type > SAL_CALL SvxUnoDrawingModel::getTypes(  ) throw(uno::RuntimeException)
308 {
309 	if( maTypeSequence.getLength() == 0 )
310 	{
311 		const uno::Sequence< uno::Type > aBaseTypes( SfxBaseModel::getTypes() );
312 		const sal_Int32 nBaseTypes = aBaseTypes.getLength();
313 		const uno::Type* pBaseTypes = aBaseTypes.getConstArray();
314 
315 		const sal_Int32 nOwnTypes = 4;		// !DANGER! Keep this updated!
316 
317 		maTypeSequence.realloc(  nBaseTypes + nOwnTypes );
318 		uno::Type* pTypes = maTypeSequence.getArray();
319 
320 		*pTypes++ = ITYPE(lang::XServiceInfo);
321 		*pTypes++ = ITYPE(lang::XMultiServiceFactory);
322 		*pTypes++ = ITYPE(drawing::XDrawPagesSupplier);
323 		*pTypes++ = ITYPE(com::sun::star::ucb::XAnyCompareFactory);
324 
325 		for( sal_Int32 nType = 0; nType < nBaseTypes; nType++ )
326 			*pTypes++ = *pBaseTypes++;
327 	}
328 
329 	return maTypeSequence;
330 }
331 
getImplementationId()332 uno::Sequence< sal_Int8 > SAL_CALL SvxUnoDrawingModel::getImplementationId(  ) throw(uno::RuntimeException)
333 {
334 	static uno::Sequence< sal_Int8 > aId;
335 	if( aId.getLength() == 0 )
336 	{
337 		aId.realloc( 16 );
338 		rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True );
339 	}
340 	return aId;
341 }
342 
lockControllers()343 void SAL_CALL SvxUnoDrawingModel::lockControllers(  )
344 	throw(uno::RuntimeException)
345 {
346 	if( mpDoc )
347 		mpDoc->setLock( sal_True );
348 }
349 
unlockControllers()350 void SAL_CALL SvxUnoDrawingModel::unlockControllers(  )
351 	throw(uno::RuntimeException)
352 {
353 	if( mpDoc && mpDoc->isLocked() )
354 	{
355 		mpDoc->setLock( sal_False );
356 	}
357 }
358 
hasControllersLocked()359 sal_Bool SAL_CALL SvxUnoDrawingModel::hasControllersLocked(  )
360 	throw(uno::RuntimeException)
361 {
362 	return mpDoc && mpDoc->isLocked();
363 }
364 
365 // XDrawPagesSupplier
getDrawPages()366 uno::Reference< drawing::XDrawPages > SAL_CALL SvxUnoDrawingModel::getDrawPages()
367 	throw(uno::RuntimeException)
368 {
369 	OGuard aGuard( Application::GetSolarMutex() );
370 
371 	uno::Reference< drawing::XDrawPages >  xDrawPages( mxDrawPagesAccess );
372 
373 	if( !xDrawPages.is() )
374 		mxDrawPagesAccess = xDrawPages = (drawing::XDrawPages*)new SvxUnoDrawPagesAccess(*this);
375 
376 	return xDrawPages;
377 }
378 
379 // XMultiServiceFactory ( SvxFmMSFactory )
createInstance(const OUString & aServiceSpecifier)380 uno::Reference< uno::XInterface > SAL_CALL SvxUnoDrawingModel::createInstance( const OUString& aServiceSpecifier )
381 	throw(uno::Exception, uno::RuntimeException)
382 {
383 	OGuard aGuard( Application::GetSolarMutex() );
384 
385 	if( 0 == aServiceSpecifier.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.DashTable") ) )
386 	{
387 		if( !mxDashTable.is() )
388 			mxDashTable = SvxUnoDashTable_createInstance( mpDoc );
389 		return mxDashTable;
390 	}
391 	if( 0 == aServiceSpecifier.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.GradientTable") ) )
392 	{
393 		if( !mxGradientTable.is() )
394 			mxGradientTable = SvxUnoGradientTable_createInstance( mpDoc );
395 		return mxGradientTable;
396 	}
397 	if( 0 == aServiceSpecifier.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.HatchTable") ) )
398 	{
399 		if( !mxHatchTable.is() )
400 			mxHatchTable = SvxUnoHatchTable_createInstance( mpDoc );
401 		return mxHatchTable;
402 	}
403 	if( 0 == aServiceSpecifier.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.BitmapTable") ) )
404 	{
405 		if( !mxBitmapTable.is() )
406 			mxBitmapTable = SvxUnoBitmapTable_createInstance( mpDoc );
407 		return mxBitmapTable;
408 	}
409 	if( 0 == aServiceSpecifier.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.TransparencyGradientTable") ) )
410 	{
411 		if( !mxTransGradientTable.is() )
412 			mxTransGradientTable = SvxUnoTransGradientTable_createInstance( mpDoc );
413 		return mxTransGradientTable;
414 	}
415 	if( 0 == aServiceSpecifier.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.MarkerTable") ) )
416 	{
417 		if( !mxMarkerTable.is() )
418 			mxMarkerTable = SvxUnoMarkerTable_createInstance( mpDoc );
419 		return mxMarkerTable;
420 	}
421 	if( 0 == aServiceSpecifier.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.text.NumberingRules" ) ) )
422 	{
423 		return uno::Reference< uno::XInterface >( SvxCreateNumRule( mpDoc ), uno::UNO_QUERY );
424 	}
425 
426 	if( aServiceSpecifier.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.image.ImageMapRectangleObject") ) )
427 	{
428 		return SvUnoImageMapRectangleObject_createInstance( ImplGetSupportedMacroItems() );
429 	}
430 
431 	if( aServiceSpecifier.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.image.ImageMapCircleObject") ) )
432 	{
433 		return SvUnoImageMapCircleObject_createInstance( ImplGetSupportedMacroItems() );
434 	}
435 
436 	if( aServiceSpecifier.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.image.ImageMapPolygonObject") ) )
437 	{
438 		return SvUnoImageMapPolygonObject_createInstance( ImplGetSupportedMacroItems() );
439 	}
440 
441 	if( 0 == aServiceSpecifier.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.text.TextField.DateTime") ) )
442 	{
443 		return (::cppu::OWeakObject * )new SvxUnoTextField( ID_EXT_DATEFIELD );
444 	}
445 
446 	uno::Reference< uno::XInterface > xRet;
447 
448 	const String aType( aServiceSpecifier );
449 	if( aType.EqualsAscii( "com.sun.star.presentation.", 0, 26 ) )
450 	{
451 		SvxShape* pShape = NULL;
452 
453 		sal_uInt16 nType = OBJ_TEXT;
454 		// create a shape wrapper
455 		if( aType.EqualsAscii( "TitleTextShape", 26, 14 ) )
456 		{
457 			nType = OBJ_TEXT;
458 		}
459 		else if( aType.EqualsAscii( "OutlinerShape", 26, 13 ) )
460 		{
461 			nType = OBJ_TEXT;
462 		}
463 		else if( aType.EqualsAscii( "SubtitleShape", 26, 13 ) )
464 		{
465 			nType = OBJ_TEXT;
466 		}
467 		else if( aType.EqualsAscii( "GraphicObjectShape", 26, 18 ) )
468 		{
469 			nType = OBJ_GRAF;
470 		}
471 		else if( aType.EqualsAscii( "PageShape", 26, 9 ) )
472 		{
473 			nType = OBJ_PAGE;
474 		}
475 		else if( aType.EqualsAscii( "OLE2Shape", 26, 9 ) )
476 		{
477 			nType = OBJ_OLE2;
478 		}
479 		else if( aType.EqualsAscii( "ChartShape", 26, 10 ) )
480 		{
481 			nType = OBJ_OLE2;
482 		}
483 		else if( aType.EqualsAscii( "TableShape", 26, 10 ) )
484 		{
485 			nType = OBJ_OLE2;
486 		}
487 		else if( aType.EqualsAscii( "OrgChartShape", 26, 13 ) )
488 		{
489 			nType = OBJ_OLE2;
490 		}
491 		else if( aType.EqualsAscii( "NotesShape", 26, 10 ) )
492 		{
493 			nType = OBJ_TEXT;
494 		}
495 		else if( aType.EqualsAscii( "HandoutShape", 26, 12 ) )
496 		{
497 			nType = OBJ_PAGE;
498 		}
499 		else if( aType.EqualsAscii( "FooterShape", 26, 12 ) )
500 		{
501 			nType = OBJ_TEXT;
502 		}
503 		else if( aType.EqualsAscii( "HeaderShape", 26, 12 ) )
504 		{
505 			nType = OBJ_TEXT;
506 		}
507 		else if( aType.EqualsAscii( "SlideNumberShape", 26, 17 ) )
508 		{
509 			nType = OBJ_TEXT;
510 		}
511 		else if( aType.EqualsAscii( "DateTimeShape", 26, 17 ) )
512 		{
513 			nType = OBJ_TEXT;
514 		}
515 		else if( aType.EqualsAscii( "TableShape", 26, 10 ) )
516 		{
517 			nType = OBJ_TABLE;
518 		}
519 		else
520 		{
521 			throw lang::ServiceNotRegisteredException();
522 		}
523 
524 		// create the API wrapper
525 		pShape = CreateSvxShapeByTypeAndInventor( nType, SdrInventor );
526 
527 		// set shape type
528 		if( pShape )
529 			pShape->SetShapeType(aServiceSpecifier);
530 
531 		xRet = (uno::XWeak*)pShape;
532 	}
533 	else
534 	{
535 		xRet = SvxFmMSFactory::createInstance( aServiceSpecifier );
536 	}
537 
538 	return xRet;
539 }
540 
getAvailableServiceNames()541 uno::Sequence< OUString > SAL_CALL SvxUnoDrawingModel::getAvailableServiceNames()
542 	throw(uno::RuntimeException)
543 {
544 	const uno::Sequence< OUString > aSNS_ORG( SvxFmMSFactory::getAvailableServiceNames() );
545 
546 	uno::Sequence< OUString > aSNS( 21 );
547 
548 	sal_uInt16 i = 0;
549 
550 	aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.DashTable"));
551 	aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.GradientTable"));
552 	aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.HatchTable"));
553 	aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.BitmapTable"));
554 	aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.TransparencyGradientTable"));
555 	aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.MarkerTable"));
556 	aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.NumberingRules"));
557 	aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.image.ImageMapRectangleObject"));
558 	aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.image.ImageMapCircleObject"));
559 	aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.image.ImageMapPolygonObject"));
560 
561 	aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.TitleTextShape"));
562 	aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.OutlinerShape"));
563 	aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.SubtitleShape"));
564 	aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.GraphicObjectShape"));
565 	aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.ChartShape"));
566 	aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.PageShape"));
567 	aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.OLE2Shape"));
568 	aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.TableShape"));
569 	aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.OrgChartShape"));
570 	aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.NotesShape"));
571 	aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.HandoutShape"));
572 
573 	DBG_ASSERT( i == aSNS.getLength(), "Sequence overrun!" );
574 
575 	return comphelper::concatSequences( aSNS_ORG, aSNS );
576 }
577 
578 // lang::XServiceInfo
getImplementationName()579 OUString SAL_CALL SvxUnoDrawingModel::getImplementationName()
580 	throw(uno::RuntimeException)
581 {
582 	return OUString( RTL_CONSTASCII_USTRINGPARAM("SvxUnoDrawingModel"));
583 }
584 
supportsService(const OUString & ServiceName)585 sal_Bool SAL_CALL SvxUnoDrawingModel::supportsService( const OUString& ServiceName )
586 	throw(uno::RuntimeException)
587 {
588 	return comphelper::ServiceInfoHelper::supportsService( ServiceName, getSupportedServiceNames() );
589 }
590 
getSupportedServiceNames()591 uno::Sequence< OUString > SAL_CALL SvxUnoDrawingModel::getSupportedServiceNames() throw(uno::RuntimeException)
592 {
593 	OUString aSN( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.DrawingDocument"));
594 	uno::Sequence< OUString > aSeq( &aSN, 1 );
595 	return aSeq;
596 }
597 
598 // XAnyCompareFactory
createAnyCompareByName(const OUString &)599 uno::Reference< com::sun::star::ucb::XAnyCompare > SAL_CALL SvxUnoDrawingModel::createAnyCompareByName( const OUString& )
600 	throw(uno::RuntimeException)
601 {
602 	return SvxCreateNumRuleCompare();
603 }
604 
605 //=============================================================================
606 // class SvxUnoDrawPagesAccess
607 //=============================================================================
608 
SvxUnoDrawPagesAccess(SvxUnoDrawingModel & rMyModel)609 SvxUnoDrawPagesAccess::SvxUnoDrawPagesAccess( SvxUnoDrawingModel& rMyModel )  throw()
610 :	mrModel(rMyModel)
611 {
612 }
613 
~SvxUnoDrawPagesAccess()614 SvxUnoDrawPagesAccess::~SvxUnoDrawPagesAccess() throw()
615 {
616 }
617 
618 // XIndexAccess
getCount()619 sal_Int32 SAL_CALL SvxUnoDrawPagesAccess::getCount()
620 	throw(uno::RuntimeException)
621 {
622 	OGuard aGuard( Application::GetSolarMutex() );
623 
624 	sal_Int32 nCount = 0;
625 
626 	if( mrModel.mpDoc )
627 		nCount = mrModel.mpDoc->GetPageCount();
628 
629 	return( nCount );
630 }
631 
getByIndex(sal_Int32 Index)632 uno::Any SAL_CALL SvxUnoDrawPagesAccess::getByIndex( sal_Int32 Index )
633 	throw(lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
634 {
635 	OGuard aGuard( Application::GetSolarMutex() );
636 
637 	uno::Any aAny;
638 
639 	if( mrModel.mpDoc )
640 	{
641 		if( (Index < 0) || (Index >= mrModel.mpDoc->GetPageCount() ) )
642 			throw lang::IndexOutOfBoundsException();
643 
644 		SdrPage* pPage = mrModel.mpDoc->GetPage( (sal_uInt16)Index );
645 		if( pPage )
646 		{
647 			uno::Reference< uno::XInterface > xPage( pPage->mxUnoPage );
648 
649 			if( !xPage.is() )
650 			{
651 				if( PTR_CAST( FmFormModel, mrModel.mpDoc ) )
652 					xPage = (drawing::XDrawPage*)new SvxFmDrawPage( pPage );
653 				else
654 					xPage = (drawing::XDrawPage*)new SvxDrawPage( pPage );
655 
656 				pPage->mxUnoPage = xPage;
657 			}
658 
659 			aAny <<= xPage;
660 		}
661 	}
662 	return aAny;
663 }
664 
665 // XElementAccess
getElementType()666 uno::Type SAL_CALL SvxUnoDrawPagesAccess::getElementType()
667 	throw(uno::RuntimeException)
668 {
669 	return ITYPE( drawing::XDrawPage );
670 }
671 
hasElements()672 sal_Bool SAL_CALL SvxUnoDrawPagesAccess::hasElements()
673 	throw(uno::RuntimeException)
674 {
675 	return getCount() > 0;
676 }
677 
678 // XDrawPages
679 
680 /******************************************************************************
681 * Erzeugt eine neue Seite mit Model an der angegebennen Position und gibt die *
682 * dazugehoerige SdDrawPage zurueck.                                           *
683 ******************************************************************************/
insertNewByIndex(sal_Int32 nIndex)684 uno::Reference< drawing::XDrawPage > SAL_CALL SvxUnoDrawPagesAccess::insertNewByIndex( sal_Int32 nIndex )
685 	throw(uno::RuntimeException)
686 {
687 	OGuard aGuard( Application::GetSolarMutex() );
688 
689 	uno::Reference< drawing::XDrawPage > xDrawPage;
690 
691 	if( mrModel.mpDoc )
692 	{
693 		SdrPage* pPage;
694 
695 		if( PTR_CAST( FmFormModel, mrModel.mpDoc ) )
696 			pPage = new FmFormPage(*(FmFormModel*)mrModel.mpDoc, NULL);
697 		else
698 			pPage = new SdrPage(*mrModel.mpDoc);
699 
700 		mrModel.mpDoc->InsertPage( pPage, (sal_uInt16)nIndex );
701 		xDrawPage = uno::Reference< drawing::XDrawPage >::query( pPage->getUnoPage() );
702 	}
703 
704 	return xDrawPage;
705 }
706 
remove(const uno::Reference<drawing::XDrawPage> & xPage)707 void SAL_CALL SvxUnoDrawPagesAccess::remove( const uno::Reference< drawing::XDrawPage >& xPage )
708 		throw(uno::RuntimeException)
709 {
710 	OGuard aGuard( Application::GetSolarMutex() );
711 
712 	sal_uInt16 nPageCount = mrModel.mpDoc->GetPageCount();
713 	if( nPageCount > 1 )
714 	{
715 		// pPage von xPage besorgen und dann die Id (nPos )ermitteln
716 		SvxDrawPage* pSvxPage = SvxDrawPage::getImplementation( xPage );
717 		if( pSvxPage )
718 		{
719 			SdrPage* pPage = pSvxPage->GetSdrPage();
720 			if(pPage)
721 			{
722 				sal_uInt16 nPage = pPage->GetPageNum();
723 				mrModel.mpDoc->DeletePage( nPage );
724 			}
725 		}
726 	}
727 }
728 
729 // XServiceInfo
730 sal_Char pSvxUnoDrawPagesAccessService[sizeof("com.sun.star.drawing.DrawPages")] = "com.sun.star.drawing.DrawPages";
731 
getImplementationName()732 OUString SAL_CALL SvxUnoDrawPagesAccess::getImplementationName(  ) throw(uno::RuntimeException)
733 {
734 	return OUString( RTL_CONSTASCII_USTRINGPARAM( "SvxUnoDrawPagesAccess" ) );
735 }
736 
supportsService(const OUString & ServiceName)737 sal_Bool SAL_CALL SvxUnoDrawPagesAccess::supportsService( const OUString& ServiceName ) throw(uno::RuntimeException)
738 {
739 	return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( pSvxUnoDrawPagesAccessService ) );
740 }
741 
getSupportedServiceNames()742 uno::Sequence< OUString > SAL_CALL SvxUnoDrawPagesAccess::getSupportedServiceNames(  ) throw(uno::RuntimeException)
743 {
744 	OUString aService( RTL_CONSTASCII_USTRINGPARAM( pSvxUnoDrawPagesAccessService ) );
745 	uno::Sequence< OUString > aSeq( &aService, 1 );
746 	return aSeq;
747 }
748 #include <editeng/unonrule.hxx>
SvxCreateNumRule(SdrModel * pModel)749 com::sun::star::uno::Reference< com::sun::star::container::XIndexReplace > SvxCreateNumRule( SdrModel* pModel ) throw()
750 {
751 	SvxNumRule* pDefaultRule = NULL;
752 	if( pModel )
753 	{
754 		SvxNumBulletItem* pItem = (SvxNumBulletItem*) pModel->GetItemPool().GetSecondaryPool()->GetPoolDefaultItem(EE_PARA_NUMBULLET);
755 		if( pItem )
756 		{
757 			pDefaultRule = pItem->GetNumRule();
758 		}
759 	}
760 
761 	if( pDefaultRule )
762 	{
763 		return SvxCreateNumRule( pDefaultRule );
764 	}
765 	else
766 	{
767 		SvxNumRule aTempRule( 0, 10, false );
768 		return SvxCreateNumRule( &aTempRule );
769 	}
770 }
771 
772 ///////////////////////////////////////////////////////////////////////
773 
774 #endif
775