bump product version to 7.2.5.1
[LibreOffice.git] / svx / source / unodraw / unopage.cxx
blob0cc4f7d954e5a371502d9e9928876d6930ae360f
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 <config_features.h>
22 #include <com/sun/star/document/EventObject.hpp>
23 #include <com/sun/star/embed/XEmbeddedObject.hpp>
24 #include <com/sun/star/lang/DisposedException.hpp>
25 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
26 #include <o3tl/safeint.hxx>
27 #include <osl/mutex.hxx>
28 #include <comphelper/classids.hxx>
29 #include <comphelper/embeddedobjectcontainer.hxx>
30 #include <comphelper/sequence.hxx>
31 #include <cppuhelper/supportsservice.hxx>
33 #include <svx/svdpool.hxx>
34 #include <svx/svdobj.hxx>
35 #include <svx/svdoole2.hxx>
36 #include <svx/svdpage.hxx>
37 #include <svx/svdmodel.hxx>
38 #include <svx/strings.hrc>
39 #include <svx/svdview.hxx>
40 #include <svx/svdpagv.hxx>
41 #include <svx/svdundo.hxx>
42 #include <svx/unopage.hxx>
43 #include "shapeimpl.hxx"
44 #include <svx/dialmgr.hxx>
45 #include <svx/svdobjkind.hxx>
46 #include <svx/unoprov.hxx>
47 #include <svx/unoapi.hxx>
48 #include <extrud3d.hxx>
49 #include <svx/lathe3d.hxx>
50 #include <svx/scene3d.hxx>
51 #include <vcl/svapp.hxx>
52 #include <tools/diagnose_ex.h>
53 #include <tools/globname.hxx>
54 #include <sal/log.hxx>
56 using namespace ::cppu;
57 using namespace ::com::sun::star;
58 using namespace ::com::sun::star::uno;
59 using namespace ::com::sun::star::lang;
60 using namespace ::com::sun::star::container;
61 using namespace ::com::sun::star::drawing;
63 UNO3_GETIMPLEMENTATION_IMPL( SvxDrawPage );
65 SvxDrawPage::SvxDrawPage(SdrPage* pInPage) // TTTT should be reference
66 : mrBHelper(m_aMutex)
67 ,mpPage(pInPage)
68 ,mpModel(&pInPage->getSdrModelFromSdrPage()) // register at broadcaster
69 ,mpView(new SdrView(pInPage->getSdrModelFromSdrPage())) // create (hidden) view
71 mpView->SetDesignMode();
74 SvxDrawPage::~SvxDrawPage() noexcept
76 if( !mrBHelper.bDisposed )
78 assert(!"SvxDrawPage must be disposed!");
79 acquire();
80 dispose();
84 // XInterface
85 void SvxDrawPage::release() noexcept
87 OWeakAggObject::release();
90 // XComponent
91 void SvxDrawPage::disposing() noexcept
93 if( mpModel )
95 mpModel = nullptr;
98 mpView.reset();
99 mpPage = nullptr;
102 // XComponent
103 void SvxDrawPage::dispose()
105 SolarMutexGuard aSolarGuard;
107 // An frequently programming error is to release the last
108 // reference to this object in the disposing message.
109 // Make it robust, hold a self Reference.
110 uno::Reference< lang::XComponent > xSelf( this );
112 // Guard dispose against multiple threading
113 // Remark: It is an error to call dispose more than once
114 bool bDoDispose = false;
116 osl::MutexGuard aGuard( mrBHelper.rMutex );
117 if( !mrBHelper.bDisposed && !mrBHelper.bInDispose )
119 // only one call go into this section
120 mrBHelper.bInDispose = true;
121 bDoDispose = true;
125 // Do not hold the mutex because we are broadcasting
126 if( !bDoDispose )
127 return;
129 // Create an event with this as sender
132 uno::Reference< uno::XInterface > xSource( uno::Reference< uno::XInterface >::query( static_cast<lang::XComponent *>(this) ) );
133 css::document::EventObject aEvt;
134 aEvt.Source = xSource;
135 // inform all listeners to release this object
136 // The listener container are automatically cleared
137 mrBHelper.aLC.disposeAndClear( aEvt );
138 // notify subclasses to do their dispose
139 disposing();
141 catch(const css::uno::Exception&)
143 // catch exception and throw again but signal that
144 // the object was disposed. Dispose should be called
145 // only once.
146 osl::MutexGuard aGuard( mrBHelper.rMutex );
147 mrBHelper.bDisposed = true;
148 mrBHelper.bInDispose = false;
149 throw;
152 osl::MutexGuard aGuard( mrBHelper.rMutex );
153 mrBHelper.bDisposed = true;
154 mrBHelper.bInDispose = false;
158 void SAL_CALL SvxDrawPage::addEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener )
160 SolarMutexGuard aGuard;
162 if( mpModel == nullptr )
163 throw lang::DisposedException();
165 mrBHelper.addListener( cppu::UnoType<decltype(aListener)>::get() , aListener );
168 void SAL_CALL SvxDrawPage::removeEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener )
170 SolarMutexGuard aGuard;
172 if( mpModel == nullptr )
173 throw lang::DisposedException();
175 mrBHelper.removeListener( cppu::UnoType<decltype(aListener)>::get() , aListener );
178 void SAL_CALL SvxDrawPage::add( const uno::Reference< drawing::XShape >& xShape )
180 SolarMutexGuard aGuard;
182 if ( ( mpModel == nullptr ) || ( mpPage == nullptr ) )
183 throw lang::DisposedException();
185 SvxShape* pShape = comphelper::getUnoTunnelImplementation<SvxShape>( xShape );
187 if( nullptr == pShape )
188 return;
190 SdrObject *pObj = pShape->GetSdrObject();
191 bool bNeededToClone(false);
193 if(nullptr != pObj && &pObj->getSdrModelFromSdrObject() != &mpPage->getSdrModelFromSdrPage())
195 // TTTT UNO API tries to add an existing SvxShape to this SvxDrawPage,
196 // but these use different SdrModels. It was possible before to completely
197 // 'change' a SdrObject to another SdrModel (including dangerous MigrateItemPool
198 // stuff), but is no longer. We need to Clone the SdrObject to the target model
199 // and ::Create a new SvxShape (set SdrObject there, take obver values, ...)
200 SdrObject* pClonedSdrShape(pObj->CloneSdrObject(mpPage->getSdrModelFromSdrPage()));
201 pObj->setUnoShape(nullptr);
202 pClonedSdrShape->setUnoShape(xShape);
203 // pShape->InvalidateSdrObject();
204 // pShape->Create(pClonedSdrShape, this);
205 SdrObject::Free(pObj);
206 pObj = pClonedSdrShape;
207 bNeededToClone = true;
210 if(!pObj)
212 pObj = CreateSdrObject( xShape );
213 ENSURE_OR_RETURN_VOID( pObj != nullptr, "SvxDrawPage::add: no SdrObject was created!" );
215 else if ( !pObj->IsInserted() )
217 mpPage->InsertObject( pObj );
219 if(bNeededToClone)
221 // TTTT Unfortunately in SdrObject::SetPage (see there) the
222 // xShape/UnoShape at the newly cloned SDrObject is *removed* again,
223 // so re-set it here, the caller *may need it* (e.g. Writer)
224 uno::Reference< uno::XInterface > xShapeCheck(pObj->getWeakUnoShape());
226 if( !xShapeCheck.is() )
228 pObj->setUnoShape(xShape);
233 pShape->Create( pObj, this );
234 OSL_ENSURE( pShape->GetSdrObject() == pObj, "SvxDrawPage::add: shape does not know about its newly created SdrObject!" );
236 if ( !pObj->IsInserted() )
238 mpPage->InsertObject( pObj );
241 mpModel->SetChanged();
244 void SAL_CALL SvxDrawPage::addTop( const uno::Reference< drawing::XShape >& xShape )
246 add(xShape);
249 void SAL_CALL SvxDrawPage::addBottom( const uno::Reference< drawing::XShape >& xShape )
251 SolarMutexGuard aGuard;
253 if ( ( mpModel == nullptr ) || ( mpPage == nullptr ) )
254 throw lang::DisposedException();
256 SvxShape* pShape = comphelper::getUnoTunnelImplementation<SvxShape>( xShape );
258 if( nullptr == pShape )
259 return;
261 SdrObject *pObj = pShape->GetSdrObject();
263 if(!pObj)
265 pObj = CreateSdrObject( xShape, true );
266 ENSURE_OR_RETURN_VOID( pObj != nullptr, "SvxDrawPage::add: no SdrObject was created!" );
268 else if ( !pObj->IsInserted() )
270 mpPage->InsertObject( pObj, 0 );
273 pShape->Create( pObj, this );
274 OSL_ENSURE( pShape->GetSdrObject() == pObj, "SvxDrawPage::add: shape does not know about its newly created SdrObject!" );
276 if ( !pObj->IsInserted() )
278 mpPage->InsertObject( pObj, 0 );
281 mpModel->SetChanged();
284 void SAL_CALL SvxDrawPage::remove( const Reference< drawing::XShape >& xShape )
286 SolarMutexGuard aGuard;
288 if( (mpModel == nullptr) || (mpPage == nullptr) )
289 throw lang::DisposedException();
291 SdrObject* pObj = SdrObject::getSdrObjectFromXShape( xShape );
292 if (!pObj)
293 return;
295 // remove SdrObject from page
296 const size_t nCount = mpPage->GetObjCount();
297 for( size_t nNum = 0; nNum < nCount; ++nNum )
299 if(mpPage->GetObj(nNum) == pObj)
301 const bool bUndoEnabled = mpModel->IsUndoEnabled();
303 if (bUndoEnabled)
305 mpModel->BegUndo(SvxResId(STR_EditDelete),
306 pObj->TakeObjNameSingul(), SdrRepeatFunc::Delete);
308 mpModel->AddUndo(mpModel->GetSdrUndoFactory().CreateUndoDeleteObject(*pObj));
311 OSL_VERIFY( mpPage->RemoveObject( nNum ) == pObj );
313 if (!bUndoEnabled)
314 SdrObject::Free(pObj);
316 if (bUndoEnabled)
317 mpModel->EndUndo();
319 break;
323 mpModel->SetChanged();
326 void SvxDrawPage::sort( const css::uno::Sequence< sal_Int32 >& sortOrder )
328 SolarMutexGuard aGuard;
330 if ((mpModel == nullptr) || (mpPage == nullptr))
331 throw lang::DisposedException();
333 auto newOrder = comphelper::sequenceToContainer<std::vector<sal_Int32>>(sortOrder);
334 mpPage->sort(newOrder);
337 // css::container::XIndexAccess
338 sal_Int32 SAL_CALL SvxDrawPage::getCount()
340 SolarMutexGuard aGuard;
342 if( (mpModel == nullptr) || (mpPage == nullptr) )
343 throw lang::DisposedException();
345 return static_cast<sal_Int32>( mpPage->GetObjCount() );
348 uno::Any SAL_CALL SvxDrawPage::getByIndex( sal_Int32 Index )
350 SolarMutexGuard aGuard;
352 if( (mpModel == nullptr) || (mpPage == nullptr) )
353 throw lang::DisposedException("Model or Page was already disposed!");
355 if ( Index < 0 || o3tl::make_unsigned(Index) >= mpPage->GetObjCount() )
356 throw lang::IndexOutOfBoundsException("Index (" + OUString::number(Index)
357 + ") needs to be a positive integer smaller than the shape count ("
358 + OUString::number(mpPage->GetObjCount()) + ")!");
360 SdrObject* pObj = mpPage->GetObj( Index );
361 if( pObj == nullptr )
362 throw uno::RuntimeException("Runtime exception thrown while getting a ref to the SdrObject at index: "
363 + OUString::number(Index));
366 return makeAny(Reference< drawing::XShape >( pObj->getUnoShape(), uno::UNO_QUERY ));
369 // css::container::XElementAccess
370 uno::Type SAL_CALL SvxDrawPage::getElementType()
372 return cppu::UnoType<drawing::XShape>::get();
375 sal_Bool SAL_CALL SvxDrawPage::hasElements()
377 SolarMutexGuard aGuard;
379 if( (mpModel == nullptr) || (mpPage == nullptr) )
380 throw lang::DisposedException();
382 return mpPage && mpPage->GetObjCount()>0;
385 namespace
387 void lcl_markSdrObjectOfShape( const Reference< drawing::XShape >& _rxShape, SdrView& _rView, SdrPageView& _rPageView )
389 SdrObject* pObj = SdrObject::getSdrObjectFromXShape( _rxShape );
390 if ( !pObj )
391 return;
393 _rView.MarkObj( pObj, &_rPageView );
397 // ATTENTION: SelectObjectsInView selects the css::drawing::Shapes
398 // only in the given SdrPageView. It hasn't to be the visible SdrPageView.
399 void SvxDrawPage::SelectObjectsInView( const Reference< drawing::XShapes > & aShapes, SdrPageView* pPageView ) noexcept
401 SAL_WARN_IF(!pPageView, "svx", "SdrPageView is NULL!");
402 SAL_WARN_IF(!mpView, "svx", "SdrView is NULL!");
404 if(pPageView==nullptr || mpView==nullptr)
405 return;
407 mpView->UnmarkAllObj( pPageView );
409 tools::Long nCount = aShapes->getCount();
410 for( tools::Long i = 0; i < nCount; i++ )
412 uno::Any aAny( aShapes->getByIndex(i) );
413 Reference< drawing::XShape > xShape;
414 if( aAny >>= xShape )
415 lcl_markSdrObjectOfShape( xShape, *mpView, *pPageView );
419 // ATTENTION: SelectObjectInView selects the shape only in the given SdrPageView.
420 // It hasn't to be the visible SdrPageView.
421 void SvxDrawPage::SelectObjectInView( const Reference< drawing::XShape > & xShape, SdrPageView* pPageView ) noexcept
423 SAL_WARN_IF(!pPageView, "svx", "SdrPageView is NULL!");
424 SAL_WARN_IF(!mpView, "svx", "SdrView is NULL!");
426 if(pPageView!=nullptr && mpView != nullptr)
428 mpView->UnmarkAllObj( pPageView );
429 lcl_markSdrObjectOfShape( xShape, *mpView, *pPageView );
433 Reference< drawing::XShapeGroup > SAL_CALL SvxDrawPage::group( const Reference< drawing::XShapes >& xShapes )
435 SolarMutexGuard aGuard;
437 if( (mpModel == nullptr) || (mpPage == nullptr) )
438 throw lang::DisposedException();
440 SAL_WARN_IF(!mpPage , "svx", "SdrPage is NULL!");
441 SAL_WARN_IF(!mpView, "svx", "SdrView is NULL!");
443 Reference< css::drawing::XShapeGroup > xShapeGroup;
444 if(mpPage==nullptr||mpView==nullptr||!xShapes.is())
445 return xShapeGroup;
447 SdrPageView* pPageView = mpView->ShowSdrPage( mpPage );
449 SelectObjectsInView( xShapes, pPageView );
451 mpView->GroupMarked();
453 mpView->AdjustMarkHdl();
454 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
455 if( rMarkList.GetMarkCount() == 1 )
457 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
458 if( pObj )
459 xShapeGroup.set( pObj->getUnoShape(), UNO_QUERY );
462 mpView->HideSdrPage();
464 if( mpModel )
465 mpModel->SetChanged();
467 return xShapeGroup;
470 void SAL_CALL SvxDrawPage::ungroup( const Reference< drawing::XShapeGroup >& aGroup )
472 SolarMutexGuard aGuard;
474 if( (mpModel == nullptr) || (mpPage == nullptr) )
475 throw lang::DisposedException();
477 SAL_WARN_IF(!mpPage, "svx", "SdrPage is NULL!");
478 SAL_WARN_IF(!mpView, "svx", "SdrView is NULL!");
480 if(mpPage==nullptr||mpView==nullptr||!aGroup.is())
481 return;
483 SdrPageView* pPageView = mpView->ShowSdrPage( mpPage );
485 SelectObjectInView( aGroup, pPageView );
486 mpView->UnGroupMarked();
488 mpView->HideSdrPage();
490 if( mpModel )
491 mpModel->SetChanged();
494 SdrObject* SvxDrawPage::CreateSdrObject_(const Reference< drawing::XShape > & xShape)
496 SdrObjKind nType = OBJ_NONE;
497 SdrInventor nInventor;
499 GetTypeAndInventor( nType, nInventor, xShape->getShapeType() );
500 if (!nType)
501 return nullptr;
503 awt::Size aSize = xShape->getSize();
504 aSize.Width += 1;
505 aSize.Height += 1;
506 awt::Point aPos = xShape->getPosition();
507 tools::Rectangle aRect( Point( aPos.X, aPos.Y ), Size( aSize.Width, aSize.Height ) );
509 SdrObject* pNewObj = SdrObjFactory::MakeNewObject(
510 *mpModel,
511 nInventor,
512 nType,
513 &aRect);
515 if (!pNewObj)
516 return nullptr;
518 if( auto pScene = dynamic_cast<E3dScene* >(pNewObj) )
520 // initialise scene
522 double fW = static_cast<double>(aSize.Width);
523 double fH = static_cast<double>(aSize.Height);
525 Camera3D aCam(pScene->GetCamera());
526 aCam.SetAutoAdjustProjection(false);
527 aCam.SetViewWindow(- fW / 2, - fH / 2, fW, fH);
528 basegfx::B3DPoint aLookAt;
529 basegfx::B3DPoint aCamPos(0.0, 0.0, 10000.0);
530 aCam.SetPosAndLookAt(aCamPos, aLookAt);
531 aCam.SetFocalLength(100.0);
532 pScene->SetCamera(aCam);
534 pScene->SetRectsDirty();
536 else if(auto pObj = dynamic_cast<E3dExtrudeObj* >(pNewObj))
538 basegfx::B2DPolygon aNewPolygon;
539 aNewPolygon.append(basegfx::B2DPoint(0.0, 0.0));
540 aNewPolygon.append(basegfx::B2DPoint(0.0, 1.0));
541 aNewPolygon.append(basegfx::B2DPoint(1.0, 0.0));
542 aNewPolygon.setClosed(true);
543 pObj->SetExtrudePolygon(basegfx::B2DPolyPolygon(aNewPolygon));
545 // #107245# pObj->SetExtrudeCharacterMode(sal_True);
546 pObj->SetMergedItem(Svx3DCharacterModeItem(true));
548 else if(auto pLatheObj = dynamic_cast<E3dLatheObj* >(pNewObj))
550 basegfx::B2DPolygon aNewPolygon;
551 aNewPolygon.append(basegfx::B2DPoint(0.0, 0.0));
552 aNewPolygon.append(basegfx::B2DPoint(0.0, 1.0));
553 aNewPolygon.append(basegfx::B2DPoint(1.0, 0.0));
554 aNewPolygon.setClosed(true);
555 pLatheObj->SetPolyPoly2D(basegfx::B2DPolyPolygon(aNewPolygon));
557 // #107245# pObj->SetLatheCharacterMode(sal_True);
558 pLatheObj->SetMergedItem(Svx3DCharacterModeItem(true));
561 return pNewObj;
564 void SvxDrawPage::GetTypeAndInventor( SdrObjKind& rType, SdrInventor& rInventor, const OUString& aName ) noexcept
566 sal_uInt32 nTempType = UHashMap::getId( aName );
568 if( nTempType == UHASHMAP_NOTFOUND )
570 if( aName == "com.sun.star.drawing.TableShape" ||
571 aName == "com.sun.star.presentation.TableShape" )
573 rInventor = SdrInventor::Default;
574 rType = OBJ_TABLE;
576 #if HAVE_FEATURE_AVMEDIA
577 else if ( aName == "com.sun.star.presentation.MediaShape" )
579 rInventor = SdrInventor::Default;
580 rType = OBJ_MEDIA;
582 #endif
584 else if(nTempType & E3D_INVENTOR_FLAG)
586 rInventor = SdrInventor::E3d;
587 rType = static_cast<SdrObjKind>(nTempType & ~E3D_INVENTOR_FLAG);
589 else
591 rInventor = SdrInventor::Default;
592 rType = static_cast<SdrObjKind>(nTempType);
594 switch( rType )
596 case OBJ_FRAME:
597 case OBJ_OLE2_PLUGIN:
598 case OBJ_OLE2_APPLET:
599 rType = OBJ_OLE2;
600 break;
601 default:
602 break;
607 rtl::Reference<SvxShape> SvxDrawPage::CreateShapeByTypeAndInventor( sal_uInt16 nType, SdrInventor nInventor, SdrObject *pObj, SvxDrawPage *mpPage, OUString const & referer )
609 rtl::Reference<SvxShape> pRet;
611 switch( nInventor )
613 case SdrInventor::E3d:
615 switch( nType )
617 case E3D_SCENE_ID :
618 pRet = new Svx3DSceneObject( pObj, mpPage );
619 break;
620 case E3D_CUBEOBJ_ID :
621 pRet = new Svx3DCubeObject( pObj );
622 break;
623 case E3D_SPHEREOBJ_ID :
624 pRet = new Svx3DSphereObject( pObj );
625 break;
626 case E3D_LATHEOBJ_ID :
627 pRet = new Svx3DLatheObject( pObj );
628 break;
629 case E3D_EXTRUDEOBJ_ID :
630 pRet = new Svx3DExtrudeObject( pObj );
631 break;
632 case E3D_POLYGONOBJ_ID :
633 pRet = new Svx3DPolygonObject( pObj );
634 break;
635 default: // unknown 3D-object on page
636 pRet = new SvxShape( pObj );
637 break;
639 break;
641 case SdrInventor::Default:
643 switch( nType )
645 case OBJ_GRUP:
646 pRet = new SvxShapeGroup( pObj, mpPage );
647 break;
648 case OBJ_LINE:
649 pRet = new SvxShapePolyPolygon( pObj );
650 break;
651 case OBJ_RECT:
652 pRet = new SvxShapeRect( pObj );
653 break;
654 case OBJ_CIRC:
655 case OBJ_SECT:
656 case OBJ_CARC:
657 case OBJ_CCUT:
658 pRet = new SvxShapeCircle( pObj );
659 break;
660 case OBJ_POLY:
661 pRet = new SvxShapePolyPolygon( pObj );
662 break;
663 case OBJ_PLIN:
664 pRet = new SvxShapePolyPolygon( pObj );
665 break;
666 case OBJ_SPLNLINE:
667 case OBJ_PATHLINE:
668 pRet = new SvxShapePolyPolygon( pObj );
669 break;
670 case OBJ_SPLNFILL:
671 case OBJ_PATHFILL:
672 pRet = new SvxShapePolyPolygon( pObj );
673 break;
674 case OBJ_FREELINE:
675 pRet = new SvxShapePolyPolygon( pObj );
676 break;
677 case OBJ_FREEFILL:
678 pRet = new SvxShapePolyPolygon( pObj );
679 break;
680 case OBJ_CAPTION:
681 pRet = new SvxShapeCaption( pObj );
682 break;
683 case OBJ_TITLETEXT:
684 case OBJ_OUTLINETEXT:
685 case OBJ_TEXT:
686 pRet = new SvxShapeText( pObj );
687 break;
688 case OBJ_GRAF:
689 pRet = new SvxGraphicObject( pObj );
690 break;
691 case OBJ_FRAME:
692 pRet = new SvxFrameShape( pObj );
693 break;
694 case OBJ_OLE2_APPLET:
695 pRet = new SvxAppletShape( pObj );
696 break;
697 case OBJ_OLE2_PLUGIN:
698 pRet = new SvxPluginShape( pObj );
699 break;
700 case OBJ_OLE2:
702 if( pObj && !pObj->IsEmptyPresObj() && mpPage )
704 SdrPage* pSdrPage = mpPage->GetSdrPage();
705 if( pSdrPage )
707 SdrModel& rSdrModel(pSdrPage->getSdrModelFromSdrPage());
708 ::comphelper::IEmbeddedHelper *pPersist = rSdrModel.GetPersist();
710 if( pPersist )
712 uno::Reference < embed::XEmbeddedObject > xObject = pPersist->getEmbeddedObjectContainer().
713 GetEmbeddedObject( static_cast< SdrOle2Obj* >( pObj )->GetPersistName() );
715 // TODO CL->KA: Why is this not working anymore?
716 if( xObject.is() )
718 SvGlobalName aClassId( xObject->getClassID() );
720 const SvGlobalName aAppletClassId( SO3_APPLET_CLASSID );
721 const SvGlobalName aPluginClassId( SO3_PLUGIN_CLASSID );
722 const SvGlobalName aIFrameClassId( SO3_IFRAME_CLASSID );
724 if( aPluginClassId == aClassId )
726 pRet = new SvxPluginShape( pObj );
727 nType = OBJ_OLE2_PLUGIN;
729 else if( aAppletClassId == aClassId )
731 pRet = new SvxAppletShape( pObj );
732 nType = OBJ_OLE2_APPLET;
734 else if( aIFrameClassId == aClassId )
736 pRet = new SvxFrameShape( pObj );
737 nType = OBJ_FRAME;
743 if( pRet == nullptr )
745 SvxUnoPropertyMapProvider& rSvxMapProvider = getSvxMapProvider();
746 pRet = new SvxOle2Shape( pObj, rSvxMapProvider.GetMap(SVXMAP_OLE2), rSvxMapProvider.GetPropertySet(SVXMAP_OLE2, SdrObject::GetGlobalDrawObjectItemPool()) );
749 break;
750 case OBJ_EDGE:
751 pRet = new SvxShapeConnector( pObj );
752 break;
753 case OBJ_PATHPOLY:
754 pRet = new SvxShapePolyPolygon( pObj );
755 break;
756 case OBJ_PATHPLIN:
757 pRet = new SvxShapePolyPolygon( pObj );
758 break;
759 case OBJ_PAGE:
761 SvxUnoPropertyMapProvider& rSvxMapProvider = getSvxMapProvider();
762 pRet = new SvxShape( pObj, rSvxMapProvider.GetMap(SVXMAP_PAGE), rSvxMapProvider.GetPropertySet(SVXMAP_PAGE, SdrObject::GetGlobalDrawObjectItemPool()) );
764 break;
765 case OBJ_MEASURE:
766 pRet = new SvxShapeDimensioning( pObj );
767 break;
768 case OBJ_UNO:
769 pRet = new SvxShapeControl( pObj );
770 break;
771 case OBJ_CUSTOMSHAPE:
772 pRet = new SvxCustomShape( pObj );
773 break;
774 case OBJ_MEDIA:
775 pRet = new SvxMediaShape( pObj, referer );
776 break;
777 case OBJ_TABLE:
778 pRet = new SvxTableShape( pObj );
779 break;
780 default: // unknown 2D-object on page
781 assert(false && "Not implemented Starone-Shape created");
782 pRet = new SvxShapeText( pObj );
783 break;
785 break;
787 default: // unknown inventor
789 assert(false && "Unknown Inventor in SvxDrawPage::CreateShape()");
790 break;
794 if(pRet)
796 sal_uInt32 nObjId = nType;
798 if( nInventor == SdrInventor::E3d )
799 nObjId |= E3D_INVENTOR_FLAG;
801 switch(nObjId)
803 case OBJ_CCUT: // segment of circle
804 case OBJ_CARC: // arc of circle
805 case OBJ_SECT: // sector
806 nObjId = OBJ_CIRC;
807 break;
809 case OBJ_TITLETEXT:
810 case OBJ_OUTLINETEXT:
811 nObjId = OBJ_TEXT;
812 break;
815 pRet->setShapeKind(nObjId);
818 return pRet;
821 Reference< drawing::XShape > SvxDrawPage::CreateShape( SdrObject *pObj ) const
823 Reference< drawing::XShape > xShape( CreateShapeByTypeAndInventor(pObj->GetObjIdentifier(),
824 pObj->GetObjInventor(),
825 pObj,
826 const_cast<SvxDrawPage*>(this)));
827 return xShape;
830 SdrObject *SvxDrawPage::CreateSdrObject( const Reference< drawing::XShape > & xShape, bool bBeginning ) noexcept
832 SdrObject* pObj = CreateSdrObject_( xShape );
833 if( pObj)
835 if ( !pObj->IsInserted() && !pObj->IsDoNotInsertIntoPageAutomatically() )
837 if(bBeginning)
838 mpPage->InsertObject( pObj, 0 );
839 else
840 mpPage->InsertObject( pObj );
844 return pObj;
847 // css::lang::XServiceInfo
848 OUString SAL_CALL SvxDrawPage::getImplementationName()
850 return "SvxDrawPage";
853 sal_Bool SAL_CALL SvxDrawPage::supportsService( const OUString& ServiceName )
855 return cppu::supportsService( this, ServiceName );
858 uno::Sequence< OUString > SAL_CALL SvxDrawPage::getSupportedServiceNames()
860 uno::Sequence<OUString> aSeq { "com.sun.star.drawing.ShapeCollection" };
861 return aSeq;
864 rtl::Reference<SvxShape> CreateSvxShapeByTypeAndInventor(sal_uInt16 nType, SdrInventor nInventor, OUString const & referer)
866 return SvxDrawPage::CreateShapeByTypeAndInventor( nType, nInventor, nullptr, nullptr, referer );
869 /** returns a StarOffice API wrapper for the given SdrPage */
870 uno::Reference< drawing::XDrawPage > GetXDrawPageForSdrPage( SdrPage* pPage ) noexcept
872 if(pPage)
874 uno::Reference< drawing::XDrawPage > xDrawPage( pPage->getUnoPage(), uno::UNO_QUERY );
876 return xDrawPage;
879 return uno::Reference< drawing::XDrawPage >();
882 /** returns the SdrObject from the given StarOffice API wrapper */
883 SdrPage* GetSdrPageFromXDrawPage( const uno::Reference< drawing::XDrawPage >& xDrawPage ) noexcept
885 if(xDrawPage.is())
887 SvxDrawPage* pDrawPage = comphelper::getUnoTunnelImplementation<SvxDrawPage>( xDrawPage );
889 if(pDrawPage)
891 return pDrawPage->GetSdrPage();
895 return nullptr;
898 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */