update credits
[LibreOffice.git] / svx / source / unodraw / unopage.cxx
blob4cd98006ff1eb541be0b1ef53b571d56adfc17b3
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/document/EventObject.hpp>
21 #include <com/sun/star/lang/DisposedException.hpp>
22 #include <osl/mutex.hxx>
23 #include <sfx2/dispatch.hxx>
24 #include <comphelper/classids.hxx>
25 #include <comphelper/serviceinfohelper.hxx>
27 #include <sfx2/objsh.hxx>
28 #include <svx/svdpool.hxx>
29 #include <svx/svdobj.hxx>
30 #include <svx/svdoole2.hxx>
31 #include <svx/svdpage.hxx>
32 #include <svx/svdmodel.hxx>
33 #include <svx/svdview.hxx>
34 #include <svx/svdpagv.hxx>
35 #include <svx/unopage.hxx>
36 #include "shapeimpl.hxx"
37 #include "svx/globl3d.hxx"
38 #include <svx/polysc3d.hxx>
39 #include <svx/unoprov.hxx>
40 #include <svx/svdopath.hxx>
41 #include "svx/unoapi.hxx"
42 #include <svx/svdomeas.hxx>
43 #include <svx/extrud3d.hxx>
44 #include <svx/lathe3d.hxx>
45 #include <vcl/svapp.hxx>
46 #include <tools/diagnose_ex.h>
48 using namespace ::cppu;
49 using namespace ::com::sun::star;
50 using namespace ::com::sun::star::uno;
51 using namespace ::com::sun::star::lang;
52 using namespace ::com::sun::star::container;
53 using namespace ::com::sun::star::drawing;
55 #define INTERFACE_TYPE( xint ) \
56 ::getCppuType((const Reference< xint >*)0)
58 /**********************************************************************
59 * class SvxDrawPage *
60 **********************************************************************/
62 UNO3_GETIMPLEMENTATION_IMPL( SvxDrawPage );
63 DBG_NAME(SvxDrawPage)
64 SvxDrawPage::SvxDrawPage( SdrPage* pInPage ) throw()
65 : mrBHelper( getMutex() )
66 , mpPage( pInPage )
67 , mpModel( 0 )
69 DBG_CTOR(SvxDrawPage,NULL);
70 // Am Broadcaster anmelden
71 if( mpPage )
72 mpModel = mpPage->GetModel();
73 if( mpModel )
74 StartListening( *mpModel );
77 // Erzeugen der (hidden) ::com::sun::star::sdbcx::View
78 mpView = new SdrView( mpModel );
79 if( mpView )
80 mpView->SetDesignMode(sal_True);
83 //----------------------------------------------------------------------
84 SvxDrawPage::~SvxDrawPage() throw()
86 DBG_ASSERT( mrBHelper.bDisposed, "SvxDrawPage must be disposed!" );
87 if( !mrBHelper.bDisposed )
89 acquire();
90 dispose();
92 DBG_DTOR(SvxDrawPage,NULL);
95 //----------------------------------------------------------------------
97 // XInterface
98 void SvxDrawPage::release() throw()
100 OWeakAggObject::release();
103 // XComponent
104 void SvxDrawPage::disposing() throw()
106 if( mpModel )
108 EndListening( *mpModel );
109 mpModel = NULL;
112 if( mpView )
114 delete mpView;
115 mpView = NULL;
117 mpPage = 0;
120 //----------------------------------------------------------------------
121 // XComponent
122 //----------------------------------------------------------------------
124 void SvxDrawPage::dispose()
125 throw(::com::sun::star::uno::RuntimeException)
127 SolarMutexGuard aSolarGuard;
129 // An frequently programming error is to release the last
130 // reference to this object in the disposing message.
131 // Make it rubust, hold a self Reference.
132 uno::Reference< lang::XComponent > xSelf( this );
134 // Guard dispose against multible threading
135 // Remark: It is an error to call dispose more than once
136 bool bDoDispose = false;
138 osl::MutexGuard aGuard( mrBHelper.rMutex );
139 if( !mrBHelper.bDisposed && !mrBHelper.bInDispose )
141 // only one call go into this section
142 mrBHelper.bInDispose = sal_True;
143 bDoDispose = true;
147 // Do not hold the mutex because we are broadcasting
148 if( bDoDispose )
150 // Create an event with this as sender
153 uno::Reference< uno::XInterface > xSource( uno::Reference< uno::XInterface >::query( (lang::XComponent *)this ) );
154 ::com::sun::star::document::EventObject aEvt;
155 aEvt.Source = xSource;
156 // inform all listeners to release this object
157 // The listener container are automaticly cleared
158 mrBHelper.aLC.disposeAndClear( aEvt );
159 // notify subclasses to do their dispose
160 disposing();
162 catch(const ::com::sun::star::uno::Exception&)
164 // catch exception and throw again but signal that
165 // the object was disposed. Dispose should be called
166 // only once.
167 mrBHelper.bDisposed = sal_True;
168 mrBHelper.bInDispose = sal_False;
169 throw;
172 // the values bDispose and bInDisposing must set in this order.
173 // No multithread call overcome the "!rBHelper.bDisposed && !rBHelper.bInDispose" guard.
174 mrBHelper.bDisposed = sal_True;
175 mrBHelper.bInDispose = sal_False;
180 //----------------------------------------------------------------------
182 void SAL_CALL SvxDrawPage::addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw(::com::sun::star::uno::RuntimeException)
184 SolarMutexGuard aGuard;
186 if( mpModel == 0 )
187 throw lang::DisposedException();
189 mrBHelper.addListener( ::getCppuType( &aListener ) , aListener );
192 //----------------------------------------------------------------------
194 void SAL_CALL SvxDrawPage::removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw(::com::sun::star::uno::RuntimeException)
196 SolarMutexGuard aGuard;
198 if( mpModel == 0 )
199 throw lang::DisposedException();
201 mrBHelper.removeListener( ::getCppuType( &aListener ) , aListener );
204 //----------------------------------------------------------------------
205 // SfxListener
206 //----------------------------------------------------------------------
208 void SvxDrawPage::Notify( SfxBroadcaster&, const SfxHint& /*rHint*/ )
212 //----------------------------------------------------------------------
213 // ::com::sun::star::drawing::XShapes
214 //----------------------------------------------------------------------
216 void SAL_CALL SvxDrawPage::add( const uno::Reference< drawing::XShape >& xShape )
217 throw( uno::RuntimeException )
219 SolarMutexGuard aGuard;
221 if ( ( mpModel == NULL ) || ( mpPage == NULL ) )
222 throw lang::DisposedException();
224 SvxShape* pShape = SvxShape::getImplementation( xShape );
226 if( NULL == pShape )
227 return;
229 SdrObject *pObj = pShape->GetSdrObject();
231 if(!pObj)
233 pObj = CreateSdrObject( xShape );
234 ENSURE_OR_RETURN_VOID( pObj != NULL, "SvxDrawPage::add: no SdrObject was created!" );
236 else if ( !pObj->IsInserted() )
238 pObj->SetModel(mpModel);
239 mpPage->InsertObject( pObj );
242 pShape->Create( pObj, this );
243 OSL_ENSURE( pShape->GetSdrObject() == pObj, "SvxDrawPage::add: shape does not know about its newly created SdrObject!" );
245 if ( !pObj->IsInserted() )
247 pObj->SetModel(mpModel);
248 mpPage->InsertObject( pObj );
251 mpModel->SetChanged();
254 //----------------------------------------------------------------------
255 void SAL_CALL SvxDrawPage::remove( const Reference< drawing::XShape >& xShape )
256 throw( uno::RuntimeException )
258 SolarMutexGuard aGuard;
260 if( (mpModel == 0) || (mpPage == 0) )
261 throw lang::DisposedException();
263 SvxShape* pShape = SvxShape::getImplementation( xShape );
265 if(pShape)
267 SdrObject* pObj = pShape->GetSdrObject();
268 if(pObj)
270 // SdrObject aus der Page loeschen
271 sal_uInt32 nCount = mpPage->GetObjCount();
272 for( sal_uInt32 nNum = 0; nNum < nCount; nNum++ )
274 if(mpPage->GetObj(nNum) == pObj)
276 OSL_VERIFY( mpPage->RemoveObject( nNum ) == pObj );
277 SdrObject::Free( pObj );
278 break;
284 if( mpModel )
285 mpModel->SetChanged();
288 //----------------------------------------------------------------------
289 // ::com::sun::star::container::XIndexAccess
290 //----------------------------------------------------------------------
292 sal_Int32 SAL_CALL SvxDrawPage::getCount()
293 throw( uno::RuntimeException )
295 SolarMutexGuard aGuard;
297 if( (mpModel == 0) || (mpPage == 0) )
298 throw lang::DisposedException();
300 return( (sal_Int32) mpPage->GetObjCount() );
303 //----------------------------------------------------------------------
304 uno::Any SAL_CALL SvxDrawPage::getByIndex( sal_Int32 Index )
305 throw( lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
307 SolarMutexGuard aGuard;
309 if( (mpModel == 0) || (mpPage == 0) )
310 throw lang::DisposedException();
312 if ( Index < 0 || Index >= (sal_Int32)mpPage->GetObjCount() )
313 throw lang::IndexOutOfBoundsException();
315 SdrObject* pObj = mpPage->GetObj( Index );
316 if( pObj == NULL )
317 throw uno::RuntimeException();
320 return makeAny(Reference< drawing::XShape >( pObj->getUnoShape(), uno::UNO_QUERY ));
324 //----------------------------------------------------------------------
325 // ::com::sun::star::container::XElementAccess
326 //----------------------------------------------------------------------
328 uno::Type SAL_CALL SvxDrawPage::getElementType()
329 throw( uno::RuntimeException )
331 return INTERFACE_TYPE( drawing::XShape );
334 //----------------------------------------------------------------------
335 sal_Bool SAL_CALL SvxDrawPage::hasElements()
336 throw( uno::RuntimeException )
338 SolarMutexGuard aGuard;
340 if( (mpModel == 0) || (mpPage == 0) )
341 throw lang::DisposedException();
343 return mpPage && mpPage->GetObjCount()>0;
346 namespace
348 void lcl_markSdrObjectOfShape( const Reference< drawing::XShape >& _rxShape, SdrView& _rView, SdrPageView& _rPageView )
350 SvxShape* pShape = SvxShape::getImplementation( _rxShape );
351 if ( !pShape )
352 return;
354 SdrObject* pObj = pShape->GetSdrObject();
355 if ( !pObj )
356 return;
358 _rView.MarkObj( pObj, &_rPageView );
362 //----------------------------------------------------------------------
363 // ACHTUNG: _SelectObjectsInView selektiert die ::com::sun::star::drawing::Shapes nur in der angegebennen
364 // SdrPageView. Dies mu� nicht die sichtbare SdrPageView sein.
365 //----------------------------------------------------------------------
366 void SvxDrawPage::_SelectObjectsInView( const Reference< drawing::XShapes > & aShapes, SdrPageView* pPageView ) throw ()
368 DBG_ASSERT(pPageView,"SdrPageView ist NULL! [CL]");
369 DBG_ASSERT(mpView, "SdrView ist NULL! [CL]");
371 if(pPageView!=NULL && mpView!=NULL)
373 mpView->UnmarkAllObj( pPageView );
375 long nCount = aShapes->getCount();
376 for( long i = 0; i < nCount; i++ )
378 uno::Any aAny( aShapes->getByIndex(i) );
379 Reference< drawing::XShape > xShape;
380 if( aAny >>= xShape )
381 lcl_markSdrObjectOfShape( xShape, *mpView, *pPageView );
386 //----------------------------------------------------------------------
387 // ACHTUNG: _SelectObjectInView selektiert das Shape *nur* in der angegebennen
388 // SdrPageView. Dies mu� nicht die sichtbare SdrPageView sein.
389 //----------------------------------------------------------------------
390 void SvxDrawPage::_SelectObjectInView( const Reference< drawing::XShape > & xShape, SdrPageView* pPageView ) throw()
392 DBG_ASSERT(pPageView,"SdrPageView ist NULL! [CL]");
393 DBG_ASSERT(mpView, "SdrView ist NULL! [CL]");
395 if(pPageView!=NULL && mpView != NULL)
397 mpView->UnmarkAllObj( pPageView );
398 lcl_markSdrObjectOfShape( xShape, *mpView, *pPageView );
402 //----------------------------------------------------------------------
403 Reference< drawing::XShapeGroup > SAL_CALL SvxDrawPage::group( const Reference< drawing::XShapes >& xShapes )
404 throw( uno::RuntimeException )
406 SolarMutexGuard aGuard;
408 if( (mpModel == 0) || (mpPage == 0) )
409 throw lang::DisposedException();
411 DBG_ASSERT(mpPage,"SdrPage ist NULL! [CL]");
412 DBG_ASSERT(mpView, "SdrView ist NULL! [CL]");
414 Reference< ::com::sun::star::drawing::XShapeGroup > xShapeGroup;
415 if(mpPage==NULL||mpView==NULL||!xShapes.is())
416 return xShapeGroup;
418 SdrPageView* pPageView = mpView->ShowSdrPage( mpPage );
420 _SelectObjectsInView( xShapes, pPageView );
422 mpView->GroupMarked();
424 mpView->AdjustMarkHdl();
425 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
426 if( rMarkList.GetMarkCount() == 1 )
428 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
429 if( pObj )
430 xShapeGroup = Reference< drawing::XShapeGroup >::query( pObj->getUnoShape() );
433 mpView->HideSdrPage();
435 if( mpModel )
436 mpModel->SetChanged();
438 return xShapeGroup;
441 //----------------------------------------------------------------------
442 void SAL_CALL SvxDrawPage::ungroup( const Reference< drawing::XShapeGroup >& aGroup )
443 throw( uno::RuntimeException )
445 SolarMutexGuard aGuard;
447 if( (mpModel == 0) || (mpPage == 0) )
448 throw lang::DisposedException();
450 DBG_ASSERT(mpPage,"SdrPage ist NULL! [CL]");
451 DBG_ASSERT(mpView, "SdrView ist NULL! [CL]");
453 if(mpPage==NULL||mpView==NULL||!aGroup.is())
454 return;
456 SdrPageView* pPageView = mpView->ShowSdrPage( mpPage );
458 Reference< drawing::XShape > xShape( aGroup, UNO_QUERY );
459 _SelectObjectInView( xShape, pPageView );
460 mpView->UnGroupMarked();
462 mpView->HideSdrPage();
464 if( mpModel )
465 mpModel->SetChanged();
468 //----------------------------------------------------------------------
469 SdrObject *SvxDrawPage::_CreateSdrObject( const Reference< drawing::XShape > & xShape ) throw()
471 sal_uInt16 nType;
472 sal_uInt32 nInventor;
474 GetTypeAndInventor( nType, nInventor, xShape->getShapeType() );
475 SdrObject* pNewObj = 0;
477 if( nType != 0 )
479 awt::Size aSize = xShape->getSize();
480 aSize.Width += 1;
481 aSize.Height += 1;
482 awt::Point aPos = xShape->getPosition();
483 Rectangle aRect( Point( aPos.X, aPos.Y ), Size( aSize.Width, aSize.Height ) );
485 // special cases
486 if( nInventor == SdrInventor )
488 switch( nType )
490 case OBJ_MEASURE:
492 pNewObj = new SdrMeasureObj( aRect.TopLeft(), aRect.BottomRight() );
493 break;
495 case OBJ_LINE:
497 basegfx::B2DPolygon aPoly;
498 aPoly.append(basegfx::B2DPoint(aRect.Left(), aRect.Top()));
499 aPoly.append(basegfx::B2DPoint(aRect.Right(), aRect.Bottom()));
500 pNewObj = new SdrPathObj(OBJ_LINE, basegfx::B2DPolyPolygon(aPoly));
501 break;
506 if( pNewObj == NULL )
507 pNewObj = SdrObjFactory::MakeNewObject( nInventor, nType, mpPage );
509 if(pNewObj)
511 pNewObj->SetSnapRect(aRect);
513 if( pNewObj->ISA(E3dPolyScene))
515 // Szene initialisieren
516 E3dScene* pScene = (E3dScene*)pNewObj;
518 double fW = (double)aSize.Width;
519 double fH = (double)aSize.Height;
521 Camera3D aCam(pScene->GetCamera());
522 aCam.SetAutoAdjustProjection(sal_False);
523 aCam.SetViewWindow(- fW / 2, - fH / 2, fW, fH);
524 basegfx::B3DPoint aLookAt;
525 basegfx::B3DPoint aCamPos(0.0, 0.0, 10000.0);
526 aCam.SetPosAndLookAt(aCamPos, aLookAt);
527 aCam.SetFocalLength(100.0);
528 aCam.SetDefaults(aCamPos, aLookAt, 10000.0);
529 pScene->SetCamera(aCam);
531 pScene->SetRectsDirty();
533 else if(pNewObj->ISA(E3dExtrudeObj))
535 E3dExtrudeObj* pObj = (E3dExtrudeObj*)pNewObj;
536 basegfx::B2DPolygon aNewPolygon;
537 aNewPolygon.append(basegfx::B2DPoint(0.0, 0.0));
538 aNewPolygon.append(basegfx::B2DPoint(0.0, 1.0));
539 aNewPolygon.append(basegfx::B2DPoint(1.0, 0.0));
540 aNewPolygon.setClosed(true);
541 pObj->SetExtrudePolygon(basegfx::B2DPolyPolygon(aNewPolygon));
543 // #107245# pObj->SetExtrudeCharacterMode(sal_True);
544 pObj->SetMergedItem(Svx3DCharacterModeItem(sal_True));
546 else if(pNewObj->ISA(E3dLatheObj))
548 E3dLatheObj* pObj = (E3dLatheObj*)pNewObj;
549 basegfx::B2DPolygon aNewPolygon;
550 aNewPolygon.append(basegfx::B2DPoint(0.0, 0.0));
551 aNewPolygon.append(basegfx::B2DPoint(0.0, 1.0));
552 aNewPolygon.append(basegfx::B2DPoint(1.0, 0.0));
553 aNewPolygon.setClosed(true);
554 pObj->SetPolyPoly2D(basegfx::B2DPolyPolygon(aNewPolygon));
556 // #107245# pObj->SetLatheCharacterMode(sal_True);
557 pObj->SetMergedItem(Svx3DCharacterModeItem(sal_True));
562 return pNewObj;
565 //----------------------------------------------------------------------
566 void SvxDrawPage::GetTypeAndInventor( sal_uInt16& rType, sal_uInt32& rInventor, const OUString& aName ) const throw()
568 sal_uInt32 nTempType = UHashMap::getId( aName );
570 if( nTempType == UHASHMAP_NOTFOUND )
572 if( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.TableShape")) ||
573 aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("com.sun.star.presentation.TableShape")) )
575 rInventor = SdrInventor;
576 rType = OBJ_TABLE;
578 else if ( aName == "com.sun.star.presentation.MediaShape" )
580 rInventor = SdrInventor;
581 rType = OBJ_MEDIA;
584 else if(nTempType & E3D_INVENTOR_FLAG)
586 rInventor = E3dInventor;
587 rType = (sal_uInt16)(nTempType & ~E3D_INVENTOR_FLAG);
589 else
591 rInventor = SdrInventor;
592 rType = (sal_uInt16)nTempType;
594 switch( rType )
596 case OBJ_FRAME:
597 case OBJ_OLE2_PLUGIN:
598 case OBJ_OLE2_APPLET:
599 rType = OBJ_OLE2;
600 break;
605 //----------------------------------------------------------------------
606 SvxShape* SvxDrawPage::CreateShapeByTypeAndInventor( sal_uInt16 nType, sal_uInt32 nInventor, SdrObject *pObj, SvxDrawPage *mpPage ) throw()
608 SvxShape* pRet = NULL;
609 switch( nInventor )
611 case E3dInventor:
613 switch( nType )
615 case E3D_SCENE_ID :
616 case E3D_POLYSCENE_ID :
617 pRet = new Svx3DSceneObject( pObj, mpPage );
618 break;
619 case E3D_CUBEOBJ_ID :
620 pRet = new Svx3DCubeObject( pObj );
621 break;
622 case E3D_SPHEREOBJ_ID :
623 pRet = new Svx3DSphereObject( pObj );
624 break;
625 case E3D_LATHEOBJ_ID :
626 pRet = new Svx3DLatheObject( pObj );
627 break;
628 case E3D_EXTRUDEOBJ_ID :
629 pRet = new Svx3DExtrudeObject( pObj );
630 break;
631 case E3D_POLYGONOBJ_ID :
632 pRet = new Svx3DPolygonObject( pObj );
633 break;
634 default: // unbekanntes 3D-Objekt auf der Page
635 pRet = new SvxShape( pObj );
636 break;
638 break;
640 case SdrInventor:
642 switch( nType )
644 // case OBJ_NONE:
645 // break;
646 case OBJ_GRUP:
647 pRet = new SvxShapeGroup( pObj, mpPage );
648 break;
649 case OBJ_LINE:
650 pRet = new SvxShapePolyPolygon( pObj , PolygonKind_LINE );
651 break;
652 case OBJ_RECT:
653 pRet = new SvxShapeRect( pObj );
654 break;
655 case OBJ_CIRC:
656 case OBJ_SECT:
657 case OBJ_CARC:
658 case OBJ_CCUT:
659 pRet = new SvxShapeCircle( pObj );
660 break;
661 case OBJ_POLY:
662 pRet = new SvxShapePolyPolygon( pObj , PolygonKind_POLY );
663 break;
664 case OBJ_PLIN:
665 pRet = new SvxShapePolyPolygon( pObj , PolygonKind_PLIN );
666 break;
667 case OBJ_SPLNLINE:
668 case OBJ_PATHLINE:
669 pRet = new SvxShapePolyPolygonBezier( pObj , PolygonKind_PATHLINE );
670 break;
671 case OBJ_SPLNFILL:
672 case OBJ_PATHFILL:
673 pRet = new SvxShapePolyPolygonBezier( pObj , PolygonKind_PATHFILL );
674 break;
675 case OBJ_FREELINE:
676 pRet = new SvxShapePolyPolygonBezier( pObj , PolygonKind_FREELINE );
677 break;
678 case OBJ_FREEFILL:
679 pRet = new SvxShapePolyPolygonBezier( pObj , PolygonKind_FREEFILL );
680 break;
681 case OBJ_CAPTION:
682 pRet = new SvxShapeCaption( pObj );
683 break;
684 case OBJ_TITLETEXT:
685 case OBJ_OUTLINETEXT:
686 case OBJ_TEXT:
687 pRet = new SvxShapeText( pObj );
688 break;
689 case OBJ_GRAF:
690 pRet = new SvxGraphicObject( pObj );
691 break;
692 case OBJ_FRAME:
693 pRet = new SvxFrameShape( pObj );
694 break;
695 case OBJ_OLE2_APPLET:
696 pRet = new SvxAppletShape( pObj );
697 break;
698 case OBJ_OLE2_PLUGIN:
699 pRet = new SvxPluginShape( pObj );
700 break;
701 case OBJ_OLE2:
703 if( pObj && !pObj->IsEmptyPresObj() && mpPage )
705 SdrPage* pSdrPage = mpPage->GetSdrPage();
706 if( pSdrPage )
708 SdrModel* pSdrModel = pSdrPage->GetModel();
709 if( pSdrModel )
711 ::comphelper::IEmbeddedHelper *pPersist = pSdrModel->GetPersist();
712 if( pPersist )
714 uno::Reference < embed::XEmbeddedObject > xObject = pPersist->getEmbeddedObjectContainer().
715 GetEmbeddedObject( static_cast< SdrOle2Obj* >( pObj )->GetPersistName() );
717 // TODO CL->KA: Why is this not working anymore?
718 if( xObject.is() )
720 SvGlobalName aClassId( xObject->getClassID() );
722 const SvGlobalName aAppletClassId( SO3_APPLET_CLASSID );
723 const SvGlobalName aPluginClassId( SO3_PLUGIN_CLASSID );
724 const SvGlobalName aIFrameClassId( SO3_IFRAME_CLASSID );
726 if( aPluginClassId == aClassId )
728 pRet = new SvxPluginShape( pObj );
729 nType = OBJ_OLE2_PLUGIN;
731 else if( aAppletClassId == aClassId )
733 pRet = new SvxAppletShape( pObj );
734 nType = OBJ_OLE2_APPLET;
736 else if( aIFrameClassId == aClassId )
738 pRet = new SvxFrameShape( pObj );
739 nType = OBJ_FRAME;
746 if( pRet == NULL )
748 SvxUnoPropertyMapProvider& rSvxMapProvider = getSvxMapProvider();
749 pRet = new SvxOle2Shape( pObj, rSvxMapProvider.GetMap(SVXMAP_OLE2), rSvxMapProvider.GetPropertySet(SVXMAP_OLE2, SdrObject::GetGlobalDrawObjectItemPool()) );
752 break;
753 case OBJ_EDGE:
754 pRet = new SvxShapeConnector( pObj );
755 break;
756 case OBJ_PATHPOLY:
757 pRet = new SvxShapePolyPolygon( pObj , PolygonKind_PATHPOLY );
758 break;
759 case OBJ_PATHPLIN:
760 pRet = new SvxShapePolyPolygon( pObj , PolygonKind_PATHPLIN );
761 break;
762 case OBJ_PAGE:
764 SvxUnoPropertyMapProvider& rSvxMapProvider = getSvxMapProvider();
765 pRet = new SvxShape( pObj, rSvxMapProvider.GetMap(SVXMAP_PAGE), rSvxMapProvider.GetPropertySet(SVXMAP_PAGE, SdrObject::GetGlobalDrawObjectItemPool()) );
767 break;
768 case OBJ_MEASURE:
769 pRet = new SvxShapeDimensioning( pObj );
770 break;
771 // case OBJ_DUMMY:
772 // break;
773 case OBJ_UNO:
774 pRet = new SvxShapeControl( pObj );
775 break;
776 case OBJ_CUSTOMSHAPE:
777 pRet = new SvxCustomShape( pObj );
778 break;
779 case OBJ_MEDIA:
780 pRet = new SvxMediaShape( pObj );
781 break;
782 case OBJ_TABLE:
783 pRet = new SvxTableShape( pObj );
784 break;
785 default: // unbekanntes 2D-Objekt auf der Page
786 OSL_FAIL("Nicht implementierter Starone-Shape erzeugt! [CL]");
787 pRet = new SvxShapeText( pObj );
788 break;
790 break;
792 default: // Unbekannter Inventor
794 OSL_FAIL("AW: Unknown Inventor in SvxDrawPage::_CreateShape()");
795 break;
799 if(pRet)
801 sal_uInt32 nObjId = nType;
803 if( nInventor == E3dInventor )
804 nObjId |= E3D_INVENTOR_FLAG;
806 switch(nObjId)
808 case OBJ_CCUT: // Kreisabschnitt
809 case OBJ_CARC: // Kreisbogen
810 case OBJ_SECT: // Kreissektor
811 nObjId = OBJ_CIRC;
812 break;
814 case E3D_SCENE_ID | E3D_INVENTOR_FLAG:
815 nObjId = E3D_POLYSCENE_ID | E3D_INVENTOR_FLAG;
816 break;
818 case OBJ_TITLETEXT:
819 case OBJ_OUTLINETEXT:
820 nObjId = OBJ_TEXT;
821 break;
824 pRet->setShapeKind(nObjId);
827 return pRet;
830 //----------------------------------------------------------------------
831 Reference< drawing::XShape > SvxDrawPage::_CreateShape( SdrObject *pObj ) const throw()
833 Reference< drawing::XShape > xShape( CreateShapeByTypeAndInventor(pObj->GetObjIdentifier(),
834 pObj->GetObjInventor(),
835 pObj,
836 (SvxDrawPage*)this));
837 return xShape;
840 //----------------------------------------------------------------------
841 SdrObject *SvxDrawPage::CreateSdrObject( const Reference< drawing::XShape > & xShape ) throw()
843 SdrObject* pObj = _CreateSdrObject( xShape );
844 if( pObj)
846 pObj->SetModel(mpModel);
847 if ( !pObj->IsInserted() && !pObj->IsDoNotInsertIntoPageAutomatically() )
848 mpPage->InsertObject( pObj );
851 return pObj;
854 //----------------------------------------------------------------------
855 // ::com::sun::star::lang::XServiceInfo
856 //----------------------------------------------------------------------
857 OUString SAL_CALL SvxDrawPage::getImplementationName() throw( uno::RuntimeException )
859 return OUString("SvxDrawPage");
862 sal_Bool SAL_CALL SvxDrawPage::supportsService( const OUString& ServiceName )
863 throw(::com::sun::star::uno::RuntimeException)
865 return comphelper::ServiceInfoHelper::supportsService( ServiceName, getSupportedServiceNames() );
868 uno::Sequence< OUString > SAL_CALL SvxDrawPage::getSupportedServiceNames() throw( uno::RuntimeException )
870 uno::Sequence< OUString > aSeq( 1 );
871 aSeq.getArray()[0] = OUString("com.sun.star.drawing.ShapeCollection" );
872 return aSeq;
875 SvxShape* CreateSvxShapeByTypeAndInventor( sal_uInt16 nType, sal_uInt32 nInventor ) throw()
877 return SvxDrawPage::CreateShapeByTypeAndInventor( nType, nInventor );
880 void SvxDrawPage::ChangeModel( SdrModel* pNewModel )
882 if( pNewModel != mpModel )
884 if( mpModel )
885 EndListening( *mpModel );
887 if( pNewModel )
888 StartListening( *pNewModel );
890 mpModel = pNewModel;
892 if( mpView )
894 delete mpView;
895 mpView = new SdrView( mpModel );
896 if( mpView )
897 mpView->SetDesignMode(sal_True);
902 /** returns a StarOffice API wrapper for the given SdrPage */
903 uno::Reference< drawing::XDrawPage > GetXDrawPageForSdrPage( SdrPage* pPage ) throw ()
905 if(pPage)
907 uno::Reference< drawing::XDrawPage > xDrawPage( pPage->getUnoPage(), uno::UNO_QUERY );
909 return xDrawPage;
912 return uno::Reference< drawing::XDrawPage >();
915 /** returns the SdrObject from the given StarOffice API wrapper */
916 SdrPage* GetSdrPageFromXDrawPage( uno::Reference< drawing::XDrawPage > xDrawPage ) throw()
918 if(xDrawPage.is())
920 SvxDrawPage* pDrawPage = SvxDrawPage::getImplementation( xDrawPage );
922 if(pDrawPage)
924 return pDrawPage->GetSdrPage();
928 return NULL;
931 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */