bump product version to 4.1.6.2
[LibreOffice.git] / svx / source / unodraw / unomod.cxx
blob3ae9b269b3369745318c5c51deb61a1e4bcf151b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/lang/ServiceNotRegisteredException.hpp>
21 #include <com/sun/star/lang/NoSupportException.hpp>
22 #include <com/sun/star/drawing/XShape.hpp>
23 #include <osl/mutex.hxx>
24 #include <vcl/svapp.hxx>
25 #include <svl/itemprop.hxx>
26 #include <svtools/unoevent.hxx>
27 #include <comphelper/sequence.hxx>
28 #include <comphelper/servicehelper.hxx>
29 #include <comphelper/serviceinfohelper.hxx>
31 #include <cppuhelper/implbase2.hxx>
32 #include <svx/unofill.hxx>
33 #include <editeng/unonrule.hxx>
34 #include <svtools/unoimap.hxx>
35 #include <svx/fmdpage.hxx>
36 #include <svx/fmmodel.hxx>
37 #include <svx/fmpage.hxx>
38 #include <sfx2/sfx.hrc>
39 #include <svx/unoapi.hxx>
41 #include <svx/svdmodel.hxx>
42 #include "svx/globl3d.hxx"
43 #include <svx/svdtypes.hxx>
44 #include <svx/unoprov.hxx>
45 #include <svx/unopage.hxx>
46 #include <editeng/unofield.hxx>
47 #include <svx/unomod.hxx>
48 #include <svx/unomodel.hxx>
49 #include <svx/svdobj.hxx>
50 #include <svx/svdpage.hxx>
51 #include <svx/unoshape.hxx>
52 #include <svx/xmlgrhlp.hxx>
54 #include <com/sun/star/text/textfield/Type.hpp>
56 //-////////////////////////////////////////////////////////////////////
58 using namespace ::rtl;
59 using namespace ::osl;
60 using namespace ::com::sun::star;
62 //-////////////////////////////////////////////////////////////////////
64 #define QUERYINT( xint ) \
65 if( rType == ::getCppuType((const uno::Reference< xint >*)0) ) \
66 aAny <<= uno::Reference< xint >(this)
68 #define ITYPE( xint ) \
69 ::getCppuType((const uno::Reference< xint >*)0)
71 //-////////////////////////////////////////////////////////////////////
73 class SvxUnoDrawPagesAccess : public ::cppu::WeakImplHelper2< ::com::sun::star::drawing::XDrawPages, ::com::sun::star::lang::XServiceInfo >
75 private:
76 SvxUnoDrawingModel& mrModel;
78 public:
79 SvxUnoDrawPagesAccess( SvxUnoDrawingModel& rMyModel ) throw();
80 virtual ~SvxUnoDrawPagesAccess() throw();
82 // XDrawPages
83 virtual ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage > SAL_CALL insertNewByIndex( sal_Int32 nIndex ) throw(::com::sun::star::uno::RuntimeException);
84 virtual void SAL_CALL remove( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >& xPage ) throw(::com::sun::star::uno::RuntimeException);
86 // XIndexAccess
87 virtual sal_Int32 SAL_CALL getCount() throw(::com::sun::star::uno::RuntimeException) ;
88 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);
90 // XElementAccess
91 virtual ::com::sun::star::uno::Type SAL_CALL getElementType() throw(::com::sun::star::uno::RuntimeException);
92 virtual sal_Bool SAL_CALL hasElements() throw(::com::sun::star::uno::RuntimeException);
94 // XServiceInfo
95 virtual OUString SAL_CALL getImplementationName( ) throw(::com::sun::star::uno::RuntimeException);
96 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException);
97 virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException);
99 //-////////////////////////////////////////////////////////////////////
101 static const SvEventDescription* ImplGetSupportedMacroItems()
103 static const SvEventDescription aMacroDescriptionsImpl[] =
105 { SFX_EVENT_MOUSEOVER_OBJECT, "OnMouseOver" },
106 { SFX_EVENT_MOUSEOUT_OBJECT, "OnMouseOut" },
107 { 0, NULL }
110 return aMacroDescriptionsImpl;
113 //-////////////////////////////////////////////////////////////////////
115 /** fills the given EventObject from the given SdrHint.
116 @returns
117 true if the SdrHint could be translated to an EventObject<br>
118 false if not
120 sal_Bool SvxUnoDrawMSFactory::createEvent( const SdrModel* pDoc, const SdrHint* pSdrHint, ::com::sun::star::document::EventObject& aEvent )
122 const SdrObject* pObj = NULL;
123 const SdrPage* pPage = NULL;
125 switch( pSdrHint->GetKind() )
127 // case HINT_LAYERCHG: // Layerdefinition geaendert
128 // case HINT_LAYERORDERCHG: // Layerreihenfolge geaendert (Insert/Remove/ChangePos)
129 // case HINT_LAYERSETCHG: // Layerset geaendert
130 // case HINT_LAYERSETORDERCHG: // Layersetreihenfolge geaendert (Insert/Remove/ChangePos)
132 // #115423#
133 // case HINT_PAGECHG: // Page geaendert
134 // aEvent.EventName = OUString( "PageModified" );
135 // pPage = pSdrHint->GetPage();
136 // break;
137 case HINT_PAGEORDERCHG: // Reihenfolge der Seiten (Zeichenseiten oder Masterpages) geaendert (Insert/Remove/ChangePos)
138 aEvent.EventName = OUString( "PageOrderModified" );
139 pPage = pSdrHint->GetPage();
140 break;
141 case HINT_OBJCHG: // Objekt geaendert
142 aEvent.EventName = OUString( "ShapeModified" );
143 pObj = pSdrHint->GetObject();
144 break;
145 case HINT_OBJINSERTED: // Neues Zeichenobjekt eingefuegt
146 aEvent.EventName = OUString( "ShapeInserted" );
147 pObj = pSdrHint->GetObject();
148 break;
149 case HINT_OBJREMOVED: // Zeichenobjekt aus Liste entfernt
150 aEvent.EventName = OUString( "ShapeRemoved" );
151 pObj = pSdrHint->GetObject();
152 break;
153 // HINT_DEFAULTTABCHG, // Default Tabulatorweite geaendert
154 // HINT_DEFFONTHGTCHG, // Default FontHeight geaendert
155 // HINT_SWITCHTOPAGE, // #94278# UNDO/REDO at an object evtl. on another page
156 // HINT_OBJLISTCLEAR // Is called before an SdrObjList will be cleared
157 default:
158 return sal_False;
161 if( pObj )
162 aEvent.Source = const_cast<SdrObject*>(pObj)->getUnoShape();
163 else if( pPage )
164 aEvent.Source = const_cast<SdrPage*>(pPage)->getUnoPage();
165 else
166 aEvent.Source = (const_cast<SdrModel*>(pDoc))->getUnoModel();
168 return sal_True;
171 uno::Reference< uno::XInterface > SAL_CALL SvxUnoDrawMSFactory::createInstance( const OUString& rServiceSpecifier )
172 throw( uno::Exception, uno::RuntimeException )
174 const OUString aDrawingPrefix("com.sun.star.drawing.");
176 if( rServiceSpecifier.startsWith( aDrawingPrefix ) )
178 sal_uInt32 nType = UHashMap::getId( rServiceSpecifier );
179 if( nType != UHASHMAP_NOTFOUND )
181 sal_uInt16 nT = (sal_uInt16)(nType & ~E3D_INVENTOR_FLAG);
182 sal_uInt32 nI = (nType & E3D_INVENTOR_FLAG)?E3dInventor:SdrInventor;
184 return uno::Reference< uno::XInterface >( (drawing::XShape*) SvxDrawPage::CreateShapeByTypeAndInventor( nT, nI ) );
187 else if ( rServiceSpecifier == "com.sun.star.document.ImportGraphicObjectResolver" )
189 SvXMLGraphicHelper* pGraphicHelper = SvXMLGraphicHelper::Create( GRAPHICHELPER_MODE_READ );
190 uno::Reference< uno::XInterface> xRet( static_cast< ::cppu::OWeakObject* >( pGraphicHelper ) );
191 pGraphicHelper->release();
192 return xRet;
195 uno::Reference< uno::XInterface > xRet( createTextField( rServiceSpecifier ) );
196 if( !xRet.is() )
197 throw lang::ServiceNotRegisteredException();
199 return xRet;
202 uno::Reference< uno::XInterface > SAL_CALL SvxUnoDrawMSFactory::createTextField( const OUString& ServiceSpecifier ) throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
204 return SvxUnoTextCreateTextField( ServiceSpecifier );
207 uno::Reference< uno::XInterface > SAL_CALL SvxUnoDrawMSFactory::createInstanceWithArguments( const OUString&, const uno::Sequence< ::com::sun::star::uno::Any >& )
208 throw( uno::Exception, uno::RuntimeException )
210 throw lang::NoSupportException();
213 uno::Sequence< OUString > SAL_CALL SvxUnoDrawMSFactory::getAvailableServiceNames()
214 throw( uno::RuntimeException )
216 return UHashMap::getServiceNames();
219 uno::Sequence< OUString > SvxUnoDrawMSFactory::concatServiceNames( uno::Sequence< OUString >& rServices1, uno::Sequence< OUString >& rServices2 ) throw()
221 const sal_Int32 nLen1 = rServices1.getLength();
222 const sal_Int32 nLen2 = rServices2.getLength();
224 uno::Sequence< OUString > aSeq( nLen1+nLen2 );
225 OUString* pStrings = aSeq.getArray();
227 sal_Int32 nIdx;
228 OUString* pStringDst = pStrings;
229 const OUString* pStringSrc = rServices1.getArray();
231 for( nIdx = 0; nIdx < nLen1; nIdx++ )
232 *pStringDst++ = *pStringSrc++;
234 pStringSrc = rServices2.getArray();
236 for( nIdx = 0; nIdx < nLen2; nIdx++ )
237 *pStringDst++ = *pStringSrc++;
239 return aSeq;
244 SvxUnoDrawingModel::SvxUnoDrawingModel( SdrModel* pDoc ) throw()
245 : mpDoc( pDoc )
249 SvxUnoDrawingModel::~SvxUnoDrawingModel() throw()
253 uno::Any SAL_CALL SvxUnoDrawingModel::queryInterface( const uno::Type & rType ) throw(uno::RuntimeException)
255 uno::Any aAny;
257 QUERYINT(lang::XServiceInfo);
258 else QUERYINT(lang::XMultiServiceFactory);
259 else QUERYINT(drawing::XDrawPagesSupplier);
260 else QUERYINT(com::sun::star::ucb::XAnyCompareFactory);
261 else
262 return SfxBaseModel::queryInterface( rType );
264 return aAny;
267 void SAL_CALL SvxUnoDrawingModel::acquire() throw ( )
269 SfxBaseModel::acquire();
272 void SAL_CALL SvxUnoDrawingModel::release() throw ( )
274 SfxBaseModel::release();
277 // XTypeProvider
278 uno::Sequence< uno::Type > SAL_CALL SvxUnoDrawingModel::getTypes( ) throw(uno::RuntimeException)
280 if( maTypeSequence.getLength() == 0 )
282 const uno::Sequence< uno::Type > aBaseTypes( SfxBaseModel::getTypes() );
283 const sal_Int32 nBaseTypes = aBaseTypes.getLength();
284 const uno::Type* pBaseTypes = aBaseTypes.getConstArray();
286 const sal_Int32 nOwnTypes = 4; // !DANGER! Keep this updated!
288 maTypeSequence.realloc( nBaseTypes + nOwnTypes );
289 uno::Type* pTypes = maTypeSequence.getArray();
291 *pTypes++ = ITYPE(lang::XServiceInfo);
292 *pTypes++ = ITYPE(lang::XMultiServiceFactory);
293 *pTypes++ = ITYPE(drawing::XDrawPagesSupplier);
294 *pTypes++ = ITYPE(com::sun::star::ucb::XAnyCompareFactory);
296 for( sal_Int32 nType = 0; nType < nBaseTypes; nType++ )
297 *pTypes++ = *pBaseTypes++;
300 return maTypeSequence;
303 namespace
305 class theSvxUnoDrawingModelImplementationId : public rtl::Static< UnoTunnelIdInit, theSvxUnoDrawingModelImplementationId > {};
308 uno::Sequence< sal_Int8 > SAL_CALL SvxUnoDrawingModel::getImplementationId( ) throw(uno::RuntimeException)
310 return theSvxUnoDrawingModelImplementationId::get().getSeq();
313 void SAL_CALL SvxUnoDrawingModel::lockControllers( )
314 throw(uno::RuntimeException)
316 if( mpDoc )
317 mpDoc->setLock(true);
320 void SAL_CALL SvxUnoDrawingModel::unlockControllers( )
321 throw(uno::RuntimeException)
323 if( mpDoc && mpDoc->isLocked() )
325 mpDoc->setLock(false);
329 sal_Bool SAL_CALL SvxUnoDrawingModel::hasControllersLocked( )
330 throw(uno::RuntimeException)
332 return mpDoc && mpDoc->isLocked();
335 // XDrawPagesSupplier
336 uno::Reference< drawing::XDrawPages > SAL_CALL SvxUnoDrawingModel::getDrawPages()
337 throw(uno::RuntimeException)
339 ::SolarMutexGuard aGuard;
341 uno::Reference< drawing::XDrawPages > xDrawPages( mxDrawPagesAccess );
343 if( !xDrawPages.is() )
344 mxDrawPagesAccess = xDrawPages = (drawing::XDrawPages*)new SvxUnoDrawPagesAccess(*this);
346 return xDrawPages;
349 // XMultiServiceFactory ( SvxFmMSFactory )
350 uno::Reference< uno::XInterface > SAL_CALL SvxUnoDrawingModel::createInstance( const OUString& aServiceSpecifier )
351 throw(uno::Exception, uno::RuntimeException)
353 ::SolarMutexGuard aGuard;
355 if( 0 == aServiceSpecifier.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.DashTable") ) )
357 if( !mxDashTable.is() )
358 mxDashTable = SvxUnoDashTable_createInstance( mpDoc );
359 return mxDashTable;
361 if( 0 == aServiceSpecifier.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.GradientTable") ) )
363 if( !mxGradientTable.is() )
364 mxGradientTable = SvxUnoGradientTable_createInstance( mpDoc );
365 return mxGradientTable;
367 if( 0 == aServiceSpecifier.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.HatchTable") ) )
369 if( !mxHatchTable.is() )
370 mxHatchTable = SvxUnoHatchTable_createInstance( mpDoc );
371 return mxHatchTable;
373 if( 0 == aServiceSpecifier.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.BitmapTable") ) )
375 if( !mxBitmapTable.is() )
376 mxBitmapTable = SvxUnoBitmapTable_createInstance( mpDoc );
377 return mxBitmapTable;
379 if( 0 == aServiceSpecifier.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.TransparencyGradientTable") ) )
381 if( !mxTransGradientTable.is() )
382 mxTransGradientTable = SvxUnoTransGradientTable_createInstance( mpDoc );
383 return mxTransGradientTable;
385 if( 0 == aServiceSpecifier.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.MarkerTable") ) )
387 if( !mxMarkerTable.is() )
388 mxMarkerTable = SvxUnoMarkerTable_createInstance( mpDoc );
389 return mxMarkerTable;
391 if( 0 == aServiceSpecifier.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.text.NumberingRules" ) ) )
393 return uno::Reference< uno::XInterface >( SvxCreateNumRule( mpDoc ), uno::UNO_QUERY );
396 if ( aServiceSpecifier == "com.sun.star.image.ImageMapRectangleObject" )
398 return SvUnoImageMapRectangleObject_createInstance( ImplGetSupportedMacroItems() );
401 if ( aServiceSpecifier == "com.sun.star.image.ImageMapCircleObject" )
403 return SvUnoImageMapCircleObject_createInstance( ImplGetSupportedMacroItems() );
406 if ( aServiceSpecifier == "com.sun.star.image.ImageMapPolygonObject" )
408 return SvUnoImageMapPolygonObject_createInstance( ImplGetSupportedMacroItems() );
411 if( 0 == aServiceSpecifier.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.text.TextField.DateTime") ) )
413 return (::cppu::OWeakObject * )new SvxUnoTextField(text::textfield::Type::DATE);
416 uno::Reference< uno::XInterface > xRet;
418 const String aType( aServiceSpecifier );
419 if( aType.EqualsAscii( "com.sun.star.presentation.", 0, 26 ) )
421 SvxShape* pShape = NULL;
423 sal_uInt16 nType = OBJ_TEXT;
424 // create a shape wrapper
425 if( aType.EqualsAscii( "TitleTextShape", 26, 14 ) )
427 nType = OBJ_TEXT;
429 else if( aType.EqualsAscii( "OutlinerShape", 26, 13 ) )
431 nType = OBJ_TEXT;
433 else if( aType.EqualsAscii( "SubtitleShape", 26, 13 ) )
435 nType = OBJ_TEXT;
437 else if( aType.EqualsAscii( "GraphicObjectShape", 26, 18 ) )
439 nType = OBJ_GRAF;
441 else if( aType.EqualsAscii( "PageShape", 26, 9 ) )
443 nType = OBJ_PAGE;
445 else if( aType.EqualsAscii( "OLE2Shape", 26, 9 ) )
447 nType = OBJ_OLE2;
449 else if( aType.EqualsAscii( "ChartShape", 26, 10 ) )
451 nType = OBJ_OLE2;
453 else if( aType.EqualsAscii( "TableShape", 26, 10 ) )
455 nType = OBJ_OLE2;
457 else if( aType.EqualsAscii( "OrgChartShape", 26, 13 ) )
459 nType = OBJ_OLE2;
461 else if( aType.EqualsAscii( "NotesShape", 26, 10 ) )
463 nType = OBJ_TEXT;
465 else if( aType.EqualsAscii( "HandoutShape", 26, 12 ) )
467 nType = OBJ_PAGE;
469 else if( aType.EqualsAscii( "FooterShape", 26, 12 ) )
471 nType = OBJ_TEXT;
473 else if( aType.EqualsAscii( "HeaderShape", 26, 12 ) )
475 nType = OBJ_TEXT;
477 else if( aType.EqualsAscii( "SlideNumberShape", 26, 17 ) )
479 nType = OBJ_TEXT;
481 else if( aType.EqualsAscii( "DateTimeShape", 26, 17 ) )
483 nType = OBJ_TEXT;
485 else if( aType.EqualsAscii( "TableShape", 26, 10 ) )
487 nType = OBJ_TABLE;
489 else
491 throw lang::ServiceNotRegisteredException();
494 // create the API wrapper
495 pShape = CreateSvxShapeByTypeAndInventor( nType, SdrInventor );
497 // set shape type
498 if( pShape )
499 pShape->SetShapeType(aServiceSpecifier);
501 xRet = (uno::XWeak*)pShape;
503 else
505 xRet = SvxFmMSFactory::createInstance( aServiceSpecifier );
508 return xRet;
511 uno::Sequence< OUString > SAL_CALL SvxUnoDrawingModel::getAvailableServiceNames()
512 throw(uno::RuntimeException)
514 const uno::Sequence< OUString > aSNS_ORG( SvxFmMSFactory::getAvailableServiceNames() );
516 uno::Sequence< OUString > aSNS( 21 );
518 sal_uInt16 i = 0;
520 aSNS[i++] = OUString("com.sun.star.drawing.DashTable");
521 aSNS[i++] = OUString("com.sun.star.drawing.GradientTable");
522 aSNS[i++] = OUString("com.sun.star.drawing.HatchTable");
523 aSNS[i++] = OUString("com.sun.star.drawing.BitmapTable");
524 aSNS[i++] = OUString("com.sun.star.drawing.TransparencyGradientTable");
525 aSNS[i++] = OUString("com.sun.star.drawing.MarkerTable");
526 aSNS[i++] = OUString("com.sun.star.text.NumberingRules");
527 aSNS[i++] = OUString("com.sun.star.image.ImageMapRectangleObject");
528 aSNS[i++] = OUString("com.sun.star.image.ImageMapCircleObject");
529 aSNS[i++] = OUString("com.sun.star.image.ImageMapPolygonObject");
531 aSNS[i++] = OUString("com.sun.star.presentation.TitleTextShape");
532 aSNS[i++] = OUString("com.sun.star.presentation.OutlinerShape");
533 aSNS[i++] = OUString("com.sun.star.presentation.SubtitleShape");
534 aSNS[i++] = OUString("com.sun.star.presentation.GraphicObjectShape");
535 aSNS[i++] = OUString("com.sun.star.presentation.ChartShape");
536 aSNS[i++] = OUString("com.sun.star.presentation.PageShape");
537 aSNS[i++] = OUString("com.sun.star.presentation.OLE2Shape");
538 aSNS[i++] = OUString("com.sun.star.presentation.TableShape");
539 aSNS[i++] = OUString("com.sun.star.presentation.OrgChartShape");
540 aSNS[i++] = OUString("com.sun.star.presentation.NotesShape");
541 aSNS[i++] = OUString("com.sun.star.presentation.HandoutShape");
543 DBG_ASSERT( i == aSNS.getLength(), "Sequence overrun!" );
545 return comphelper::concatSequences( aSNS_ORG, aSNS );
548 // lang::XServiceInfo
549 OUString SAL_CALL SvxUnoDrawingModel::getImplementationName()
550 throw(uno::RuntimeException)
552 return OUString("SvxUnoDrawingModel");
555 sal_Bool SAL_CALL SvxUnoDrawingModel::supportsService( const OUString& ServiceName )
556 throw(uno::RuntimeException)
558 return comphelper::ServiceInfoHelper::supportsService( ServiceName, getSupportedServiceNames() );
561 uno::Sequence< OUString > SAL_CALL SvxUnoDrawingModel::getSupportedServiceNames() throw(uno::RuntimeException)
563 OUString aSN("com.sun.star.drawing.DrawingDocument");
564 uno::Sequence< OUString > aSeq( &aSN, 1 );
565 return aSeq;
568 // XAnyCompareFactory
569 uno::Reference< com::sun::star::ucb::XAnyCompare > SAL_CALL SvxUnoDrawingModel::createAnyCompareByName( const OUString& )
570 throw(uno::RuntimeException)
572 return SvxCreateNumRuleCompare();
575 //=============================================================================
576 // class SvxUnoDrawPagesAccess
577 //=============================================================================
579 SvxUnoDrawPagesAccess::SvxUnoDrawPagesAccess( SvxUnoDrawingModel& rMyModel ) throw()
580 : mrModel(rMyModel)
584 SvxUnoDrawPagesAccess::~SvxUnoDrawPagesAccess() throw()
588 // XIndexAccess
589 sal_Int32 SAL_CALL SvxUnoDrawPagesAccess::getCount()
590 throw(uno::RuntimeException)
592 ::SolarMutexGuard aGuard;
594 sal_Int32 nCount = 0;
596 if( mrModel.mpDoc )
597 nCount = mrModel.mpDoc->GetPageCount();
599 return( nCount );
602 uno::Any SAL_CALL SvxUnoDrawPagesAccess::getByIndex( sal_Int32 Index )
603 throw(lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
605 ::SolarMutexGuard aGuard;
607 uno::Any aAny;
609 if( mrModel.mpDoc )
611 if( (Index < 0) || (Index >= mrModel.mpDoc->GetPageCount() ) )
612 throw lang::IndexOutOfBoundsException();
614 SdrPage* pPage = mrModel.mpDoc->GetPage( (sal_uInt16)Index );
615 if( pPage )
617 uno::Reference< uno::XInterface > xPage( pPage->mxUnoPage );
619 if( !xPage.is() )
621 if( PTR_CAST( FmFormModel, mrModel.mpDoc ) )
622 xPage = (drawing::XDrawPage*)new SvxFmDrawPage( pPage );
623 else
624 xPage = (drawing::XDrawPage*)new SvxDrawPage( pPage );
626 pPage->mxUnoPage = xPage;
629 aAny <<= xPage;
632 return aAny;
635 // XElementAccess
636 uno::Type SAL_CALL SvxUnoDrawPagesAccess::getElementType()
637 throw(uno::RuntimeException)
639 return ITYPE( drawing::XDrawPage );
642 sal_Bool SAL_CALL SvxUnoDrawPagesAccess::hasElements()
643 throw(uno::RuntimeException)
645 return getCount() > 0;
648 // XDrawPages
650 /******************************************************************************
651 * Erzeugt eine neue Seite mit Model an der angegebennen Position und gibt die *
652 * dazugehoerige SdDrawPage zurueck. *
653 ******************************************************************************/
654 uno::Reference< drawing::XDrawPage > SAL_CALL SvxUnoDrawPagesAccess::insertNewByIndex( sal_Int32 nIndex )
655 throw(uno::RuntimeException)
657 ::SolarMutexGuard aGuard;
659 uno::Reference< drawing::XDrawPage > xDrawPage;
661 if( mrModel.mpDoc )
663 SdrPage* pPage;
665 if( PTR_CAST( FmFormModel, mrModel.mpDoc ) )
666 pPage = new FmFormPage(*(FmFormModel*)mrModel.mpDoc, NULL);
667 else
668 pPage = new SdrPage(*mrModel.mpDoc);
670 mrModel.mpDoc->InsertPage( pPage, (sal_uInt16)nIndex );
671 xDrawPage = uno::Reference< drawing::XDrawPage >::query( pPage->getUnoPage() );
674 return xDrawPage;
677 void SAL_CALL SvxUnoDrawPagesAccess::remove( const uno::Reference< drawing::XDrawPage >& xPage )
678 throw(uno::RuntimeException)
680 ::SolarMutexGuard aGuard;
682 sal_uInt16 nPageCount = mrModel.mpDoc->GetPageCount();
683 if( nPageCount > 1 )
685 // pPage von xPage besorgen und dann die Id (nPos )ermitteln
686 SvxDrawPage* pSvxPage = SvxDrawPage::getImplementation( xPage );
687 if( pSvxPage )
689 SdrPage* pPage = pSvxPage->GetSdrPage();
690 if(pPage)
692 sal_uInt16 nPage = pPage->GetPageNum();
693 mrModel.mpDoc->DeletePage( nPage );
699 // XServiceInfo
700 const char pSvxUnoDrawPagesAccessService[] = "com.sun.star.drawing.DrawPages";
702 OUString SAL_CALL SvxUnoDrawPagesAccess::getImplementationName( ) throw(uno::RuntimeException)
704 return OUString( "SvxUnoDrawPagesAccess" );
707 sal_Bool SAL_CALL SvxUnoDrawPagesAccess::supportsService( const OUString& ServiceName ) throw(uno::RuntimeException)
709 return ServiceName == pSvxUnoDrawPagesAccessService;
712 uno::Sequence< OUString > SAL_CALL SvxUnoDrawPagesAccess::getSupportedServiceNames( ) throw(uno::RuntimeException)
714 OUString aService( RTL_CONSTASCII_USTRINGPARAM( pSvxUnoDrawPagesAccessService ) );
715 uno::Sequence< OUString > aSeq( &aService, 1 );
716 return aSeq;
719 com::sun::star::uno::Reference< com::sun::star::container::XIndexReplace > SvxCreateNumRule( SdrModel* pModel ) throw()
721 SvxNumRule* pDefaultRule = NULL;
722 if( pModel )
724 SvxNumBulletItem* pItem = (SvxNumBulletItem*) pModel->GetItemPool().GetSecondaryPool()->GetPoolDefaultItem(EE_PARA_NUMBULLET);
725 if( pItem )
727 pDefaultRule = pItem->GetNumRule();
731 if( pDefaultRule )
733 return SvxCreateNumRule( pDefaultRule );
735 else
737 SvxNumRule aTempRule( 0, 10, false );
738 return SvxCreateNumRule( &aTempRule );
742 ///////////////////////////////////////////////////////////////////////
744 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */