Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / unodraw / unopage.cxx
blob7c8ab3dde951463dee497f549c774caf8e0a0ec3
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/unodraw/SvxTableShape.hxx>
45 #include <svx/dialmgr.hxx>
46 #include <svx/svdobjkind.hxx>
47 #include <svx/unoprov.hxx>
48 #include <svx/unoapi.hxx>
49 #include <extrud3d.hxx>
50 #include <svx/lathe3d.hxx>
51 #include <svx/scene3d.hxx>
52 #include <vcl/svapp.hxx>
53 #include <comphelper/diagnose_ex.hxx>
54 #include <tools/globname.hxx>
55 #include <sal/log.hxx>
57 using namespace ::cppu;
58 using namespace ::com::sun::star;
59 using namespace ::com::sun::star::uno;
60 using namespace ::com::sun::star::lang;
61 using namespace ::com::sun::star::container;
62 using namespace ::com::sun::star::drawing;
64 UNO3_GETIMPLEMENTATION_IMPL( SvxDrawPage );
66 SvxDrawPage::SvxDrawPage(SdrPage* pInPage) // TTTT should be reference
67 : mrBHelper(m_aMutex)
68 ,mpPage(pInPage)
69 ,mpModel(&pInPage->getSdrModelFromSdrPage()) // register at broadcaster
70 ,mpView(new SdrView(pInPage->getSdrModelFromSdrPage())) // create (hidden) view
72 mpView->SetDesignMode();
75 SvxDrawPage::~SvxDrawPage() noexcept
77 if( !mrBHelper.bDisposed )
79 assert(!"SvxDrawPage must be disposed!");
80 acquire();
81 dispose();
85 // XInterface
86 void SvxDrawPage::release() noexcept
88 OWeakAggObject::release();
91 // XComponent
92 void SvxDrawPage::disposing() noexcept
94 if( mpModel )
96 mpModel = nullptr;
99 mpView.reset();
100 mpPage = nullptr;
103 // XComponent
104 void SvxDrawPage::dispose()
106 SolarMutexGuard aSolarGuard;
108 // An frequently programming error is to release the last
109 // reference to this object in the disposing message.
110 // Make it robust, hold a self Reference.
111 uno::Reference< lang::XComponent > xSelf( this );
113 // Guard dispose against multiple threading
114 // Remark: It is an error to call dispose more than once
115 bool bDoDispose = false;
117 osl::MutexGuard aGuard( mrBHelper.rMutex );
118 if( !mrBHelper.bDisposed && !mrBHelper.bInDispose )
120 // only one call go into this section
121 mrBHelper.bInDispose = true;
122 bDoDispose = true;
126 // Do not hold the mutex because we are broadcasting
127 if( !bDoDispose )
128 return;
130 // Create an event with this as sender
133 uno::Reference< uno::XInterface > xSource( uno::Reference< uno::XInterface >::query( static_cast<lang::XComponent *>(this) ) );
134 css::document::EventObject aEvt;
135 aEvt.Source = xSource;
136 // inform all listeners to release this object
137 // The listener container are automatically cleared
138 mrBHelper.aLC.disposeAndClear( aEvt );
139 // notify subclasses to do their dispose
140 disposing();
142 catch(const css::uno::Exception&)
144 // catch exception and throw again but signal that
145 // the object was disposed. Dispose should be called
146 // only once.
147 osl::MutexGuard aGuard( mrBHelper.rMutex );
148 mrBHelper.bDisposed = true;
149 mrBHelper.bInDispose = false;
150 throw;
153 osl::MutexGuard aGuard( mrBHelper.rMutex );
154 mrBHelper.bDisposed = true;
155 mrBHelper.bInDispose = false;
159 void SAL_CALL SvxDrawPage::addEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener )
161 SolarMutexGuard aGuard;
163 if( mpModel == nullptr )
164 throw lang::DisposedException();
166 mrBHelper.addListener( cppu::UnoType<decltype(aListener)>::get() , aListener );
169 void SAL_CALL SvxDrawPage::removeEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener )
171 SolarMutexGuard aGuard;
173 if( mpModel == nullptr )
174 throw lang::DisposedException();
176 mrBHelper.removeListener( cppu::UnoType<decltype(aListener)>::get() , aListener );
179 void SAL_CALL SvxDrawPage::add( const uno::Reference< drawing::XShape >& xShape )
181 SolarMutexGuard aGuard;
183 if ( ( mpModel == nullptr ) || ( mpPage == nullptr ) )
184 throw lang::DisposedException();
186 SvxShape* pShape = comphelper::getFromUnoTunnel<SvxShape>( xShape );
188 if( nullptr == pShape )
190 assert(false && "adding a non-SvxShape to a page?");
191 return;
194 rtl::Reference<SdrObject> pObj = pShape->GetSdrObject();
195 bool bNeededToClone(false);
197 if(pObj && &pObj->getSdrModelFromSdrObject() != &mpPage->getSdrModelFromSdrPage())
199 // TTTT UNO API tries to add an existing SvxShape to this SvxDrawPage,
200 // but these use different SdrModels. It was possible before to completely
201 // 'change' a SdrObject to another SdrModel (including dangerous MigrateItemPool
202 // stuff), but is no longer. We need to Clone the SdrObject to the target model
203 // and ::Create a new SvxShape (set SdrObject there, take over values, ...)
204 rtl::Reference<SdrObject> pClonedSdrShape(pObj->CloneSdrObject(mpPage->getSdrModelFromSdrPage()));
205 pObj->setUnoShape(nullptr);
206 pClonedSdrShape->setUnoShape(pShape);
207 // pShape->InvalidateSdrObject();
208 // pShape->Create(pClonedSdrShape, this);
209 pObj = pClonedSdrShape;
210 bNeededToClone = true;
213 if(!pObj)
215 pObj = CreateSdrObject( xShape );
216 ENSURE_OR_RETURN_VOID( pObj != nullptr, "SvxDrawPage::add: no SdrObject was created!" );
218 else if ( !pObj->IsInserted() )
220 mpPage->InsertObject( pObj.get() );
222 if(bNeededToClone)
224 // TTTT Unfortunately in SdrObject::SetPage (see there) the
225 // xShape/UnoShape at the newly cloned SDrObject is *removed* again,
226 // so re-set it here, the caller *may need it* (e.g. Writer)
227 uno::Reference< drawing::XShape > xShapeCheck(pObj->getWeakUnoShape());
229 if( !xShapeCheck.is() )
231 pObj->setUnoShape(pShape);
236 pShape->Create( pObj.get(), this );
237 OSL_ENSURE( pShape->GetSdrObject() == pObj.get(), "SvxDrawPage::add: shape does not know about its newly created SdrObject!" );
239 if ( !pObj->IsInserted() )
241 mpPage->InsertObject( pObj.get() );
244 mpModel->SetChanged();
247 void SAL_CALL SvxDrawPage::addTop( const uno::Reference< drawing::XShape >& xShape )
249 add(xShape);
252 void SAL_CALL SvxDrawPage::addBottom( const uno::Reference< drawing::XShape >& xShape )
254 SolarMutexGuard aGuard;
256 if ( ( mpModel == nullptr ) || ( mpPage == nullptr ) )
257 throw lang::DisposedException();
259 SvxShape* pShape = comphelper::getFromUnoTunnel<SvxShape>( xShape );
261 if( nullptr == pShape )
263 assert(false && "adding a non-SvxShape to a page?");
264 return;
267 rtl::Reference<SdrObject> pObj = pShape->GetSdrObject();
269 if(!pObj)
271 pObj = CreateSdrObject( xShape, true );
272 ENSURE_OR_RETURN_VOID( pObj != nullptr, "SvxDrawPage::add: no SdrObject was created!" );
274 else if ( !pObj->IsInserted() )
276 mpPage->InsertObject( pObj.get(), 0 );
279 pShape->Create( pObj.get(), this );
280 OSL_ENSURE( pShape->GetSdrObject() == pObj.get(), "SvxDrawPage::add: shape does not know about its newly created SdrObject!" );
282 if ( !pObj->IsInserted() )
284 mpPage->InsertObject( pObj.get(), 0 );
287 mpModel->SetChanged();
290 void SAL_CALL SvxDrawPage::remove( const Reference< drawing::XShape >& xShape )
292 SolarMutexGuard aGuard;
294 if( (mpModel == nullptr) || (mpPage == nullptr) )
295 throw lang::DisposedException();
297 SdrObject* pObj = SdrObject::getSdrObjectFromXShape( xShape );
298 if (!pObj)
299 return;
301 // remove SdrObject from page
302 const size_t nCount = mpPage->GetObjCount();
303 for( size_t nNum = 0; nNum < nCount; ++nNum )
305 if(mpPage->GetObj(nNum) == pObj)
307 const bool bUndoEnabled = mpModel->IsUndoEnabled();
309 if (bUndoEnabled)
311 mpModel->BegUndo(SvxResId(STR_EditDelete),
312 pObj->TakeObjNameSingul(), SdrRepeatFunc::Delete);
314 mpModel->AddUndo(mpModel->GetSdrUndoFactory().CreateUndoDeleteObject(*pObj));
317 OSL_VERIFY( mpPage->RemoveObject( nNum ) == pObj );
319 if (bUndoEnabled)
320 mpModel->EndUndo();
322 break;
326 mpModel->SetChanged();
329 void SvxDrawPage::sort( const css::uno::Sequence< sal_Int32 >& sortOrder )
331 SolarMutexGuard aGuard;
333 if ((mpModel == nullptr) || (mpPage == nullptr))
334 throw lang::DisposedException();
336 auto newOrder = comphelper::sequenceToContainer<std::vector<sal_Int32>>(sortOrder);
337 mpPage->sort(newOrder);
340 // css::container::XIndexAccess
341 sal_Int32 SAL_CALL SvxDrawPage::getCount()
343 SolarMutexGuard aGuard;
345 if( (mpModel == nullptr) || (mpPage == nullptr) )
346 throw lang::DisposedException();
348 return static_cast<sal_Int32>( mpPage->GetObjCount() );
351 uno::Any SAL_CALL SvxDrawPage::getByIndex( sal_Int32 Index )
353 SolarMutexGuard aGuard;
355 if( (mpModel == nullptr) || (mpPage == nullptr) )
356 throw lang::DisposedException("Model or Page was already disposed!");
358 if ( Index < 0 || o3tl::make_unsigned(Index) >= mpPage->GetObjCount() )
359 throw lang::IndexOutOfBoundsException("Index (" + OUString::number(Index)
360 + ") needs to be a positive integer smaller than the shape count ("
361 + OUString::number(mpPage->GetObjCount()) + ")!");
363 SdrObject* pObj = mpPage->GetObj( Index );
364 if( pObj == nullptr )
365 throw uno::RuntimeException("Runtime exception thrown while getting a ref to the SdrObject at index: "
366 + OUString::number(Index));
369 return Any(Reference< drawing::XShape >( pObj->getUnoShape(), uno::UNO_QUERY ));
372 // css::container::XElementAccess
373 uno::Type SAL_CALL SvxDrawPage::getElementType()
375 return cppu::UnoType<drawing::XShape>::get();
378 sal_Bool SAL_CALL SvxDrawPage::hasElements()
380 SolarMutexGuard aGuard;
382 if( (mpModel == nullptr) || (mpPage == nullptr) )
383 throw lang::DisposedException();
385 return mpPage && mpPage->GetObjCount()>0;
388 namespace
390 void lcl_markSdrObjectOfShape( const Reference< drawing::XShape >& _rxShape, SdrView& _rView, SdrPageView& _rPageView )
392 SdrObject* pObj = SdrObject::getSdrObjectFromXShape( _rxShape );
393 if ( !pObj )
394 return;
396 _rView.MarkObj( pObj, &_rPageView );
400 // ATTENTION: SelectObjectsInView selects the css::drawing::Shapes
401 // only in the given SdrPageView. It hasn't to be the visible SdrPageView.
402 void SvxDrawPage::SelectObjectsInView( const Reference< drawing::XShapes > & aShapes, SdrPageView* pPageView ) noexcept
404 SAL_WARN_IF(!pPageView, "svx", "SdrPageView is NULL!");
405 SAL_WARN_IF(!mpView, "svx", "SdrView is NULL!");
407 if(pPageView==nullptr || mpView==nullptr)
408 return;
410 mpView->UnmarkAllObj( pPageView );
412 tools::Long nCount = aShapes->getCount();
413 for( tools::Long i = 0; i < nCount; i++ )
415 uno::Any aAny( aShapes->getByIndex(i) );
416 Reference< drawing::XShape > xShape;
417 if( aAny >>= xShape )
418 lcl_markSdrObjectOfShape( xShape, *mpView, *pPageView );
422 // ATTENTION: SelectObjectInView selects the shape only in the given SdrPageView.
423 // It hasn't to be the visible SdrPageView.
424 void SvxDrawPage::SelectObjectInView( const Reference< drawing::XShape > & xShape, SdrPageView* pPageView ) noexcept
426 SAL_WARN_IF(!pPageView, "svx", "SdrPageView is NULL!");
427 SAL_WARN_IF(!mpView, "svx", "SdrView is NULL!");
429 if(pPageView!=nullptr && mpView != nullptr)
431 mpView->UnmarkAllObj( pPageView );
432 lcl_markSdrObjectOfShape( xShape, *mpView, *pPageView );
436 Reference< drawing::XShapeGroup > SAL_CALL SvxDrawPage::group( const Reference< drawing::XShapes >& xShapes )
438 SolarMutexGuard aGuard;
440 if( (mpModel == nullptr) || (mpPage == nullptr) )
441 throw lang::DisposedException();
443 SAL_WARN_IF(!mpPage , "svx", "SdrPage is NULL!");
444 SAL_WARN_IF(!mpView, "svx", "SdrView is NULL!");
446 Reference< css::drawing::XShapeGroup > xShapeGroup;
447 if(mpPage==nullptr||mpView==nullptr||!xShapes.is())
448 return xShapeGroup;
450 SdrPageView* pPageView = mpView->ShowSdrPage( mpPage );
452 SelectObjectsInView( xShapes, pPageView );
454 mpView->GroupMarked();
456 mpView->AdjustMarkHdl();
457 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
458 if( rMarkList.GetMarkCount() == 1 )
460 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
461 if( pObj )
462 xShapeGroup.set( pObj->getUnoShape(), UNO_QUERY );
465 mpView->HideSdrPage();
467 if( mpModel )
468 mpModel->SetChanged();
470 return xShapeGroup;
473 void SAL_CALL SvxDrawPage::ungroup( const Reference< drawing::XShapeGroup >& aGroup )
475 SolarMutexGuard aGuard;
477 if( (mpModel == nullptr) || (mpPage == nullptr) )
478 throw lang::DisposedException();
480 SAL_WARN_IF(!mpPage, "svx", "SdrPage is NULL!");
481 SAL_WARN_IF(!mpView, "svx", "SdrView is NULL!");
483 if(mpPage==nullptr||mpView==nullptr||!aGroup.is())
484 return;
486 SdrPageView* pPageView = mpView->ShowSdrPage( mpPage );
488 SelectObjectInView( aGroup, pPageView );
489 mpView->UnGroupMarked();
491 mpView->HideSdrPage();
493 if( mpModel )
494 mpModel->SetChanged();
497 rtl::Reference<SdrObject> SvxDrawPage::CreateSdrObject_(const Reference< drawing::XShape > & xShape)
499 SdrObjKind nType = SdrObjKind::NONE;
500 SdrInventor nInventor;
502 GetTypeAndInventor( nType, nInventor, xShape->getShapeType() );
503 if (nType == SdrObjKind::NONE)
504 return nullptr;
506 awt::Size aSize = xShape->getSize();
507 aSize.Width += 1;
508 aSize.Height += 1;
509 awt::Point aPos = xShape->getPosition();
510 tools::Rectangle aRect( Point( aPos.X, aPos.Y ), Size( aSize.Width, aSize.Height ) );
512 rtl::Reference<SdrObject> pNewObj = SdrObjFactory::MakeNewObject(
513 *mpModel,
514 nInventor,
515 nType,
516 &aRect);
518 if (!pNewObj)
519 return nullptr;
521 if( nType == SdrObjKind::E3D_Scene )
523 auto pScene = static_cast<E3dScene* >(pNewObj.get());
524 // initialise scene
526 double fW = static_cast<double>(aSize.Width);
527 double fH = static_cast<double>(aSize.Height);
529 Camera3D aCam(pScene->GetCamera());
530 aCam.SetAutoAdjustProjection(false);
531 aCam.SetViewWindow(- fW / 2, - fH / 2, fW, fH);
532 basegfx::B3DPoint aLookAt;
533 basegfx::B3DPoint aCamPos(0.0, 0.0, 10000.0);
534 aCam.SetPosAndLookAt(aCamPos, aLookAt);
535 aCam.SetFocalLength(100.0);
536 pScene->SetCamera(aCam);
538 pScene->SetBoundAndSnapRectsDirty();
540 else if(nType == SdrObjKind::E3D_Extrusion)
542 auto pObj = static_cast<E3dExtrudeObj* >(pNewObj.get());
543 basegfx::B2DPolygon aNewPolygon;
544 aNewPolygon.append(basegfx::B2DPoint(0.0, 0.0));
545 aNewPolygon.append(basegfx::B2DPoint(0.0, 1.0));
546 aNewPolygon.append(basegfx::B2DPoint(1.0, 0.0));
547 aNewPolygon.setClosed(true);
548 pObj->SetExtrudePolygon(basegfx::B2DPolyPolygon(aNewPolygon));
550 // #107245# pObj->SetExtrudeCharacterMode(sal_True);
551 pObj->SetMergedItem(Svx3DCharacterModeItem(true));
553 else if(nType == SdrObjKind::E3D_Lathe)
555 auto pLatheObj = static_cast<E3dLatheObj* >(pNewObj.get());
556 basegfx::B2DPolygon aNewPolygon;
557 aNewPolygon.append(basegfx::B2DPoint(0.0, 0.0));
558 aNewPolygon.append(basegfx::B2DPoint(0.0, 1.0));
559 aNewPolygon.append(basegfx::B2DPoint(1.0, 0.0));
560 aNewPolygon.setClosed(true);
561 pLatheObj->SetPolyPoly2D(basegfx::B2DPolyPolygon(aNewPolygon));
563 // #107245# pObj->SetLatheCharacterMode(sal_True);
564 pLatheObj->SetMergedItem(Svx3DCharacterModeItem(true));
567 return pNewObj;
570 void SvxDrawPage::GetTypeAndInventor( SdrObjKind& rType, SdrInventor& rInventor, const OUString& aName ) noexcept
572 std::optional<SdrObjKind> nTempType = UHashMap::getId( aName );
574 if( !nTempType )
576 if( aName == "com.sun.star.drawing.TableShape" ||
577 aName == "com.sun.star.presentation.TableShape" )
579 rInventor = SdrInventor::Default;
580 rType = SdrObjKind::Table;
582 #if HAVE_FEATURE_AVMEDIA
583 else if ( aName == "com.sun.star.presentation.MediaShape" )
585 rInventor = SdrInventor::Default;
586 rType = SdrObjKind::Media;
588 #endif
590 else if( IsInventorE3D(*nTempType) )
592 rInventor = SdrInventor::E3d;
593 rType = *nTempType;
595 else
597 rInventor = SdrInventor::Default;
598 rType = *nTempType;
600 switch( rType )
602 case SdrObjKind::OLEPluginFrame:
603 case SdrObjKind::OLE2Plugin:
604 case SdrObjKind::OLE2Applet:
605 rType = SdrObjKind::OLE2;
606 break;
607 default:
608 break;
613 rtl::Reference<SvxShape> SvxDrawPage::CreateShapeByTypeAndInventor( SdrObjKind nType, SdrInventor nInventor, SdrObject *pObj, SvxDrawPage *mpPage, OUString const & referer )
615 rtl::Reference<SvxShape> pRet;
617 switch( nInventor )
619 case SdrInventor::E3d:
621 switch( nType )
623 case SdrObjKind::E3D_Scene :
624 pRet = new Svx3DSceneObject( pObj, mpPage );
625 break;
626 case SdrObjKind::E3D_Cube :
627 pRet = new Svx3DCubeObject( pObj );
628 break;
629 case SdrObjKind::E3D_Sphere :
630 pRet = new Svx3DSphereObject( pObj );
631 break;
632 case SdrObjKind::E3D_Lathe :
633 pRet = new Svx3DLatheObject( pObj );
634 break;
635 case SdrObjKind::E3D_Extrusion :
636 pRet = new Svx3DExtrudeObject( pObj );
637 break;
638 case SdrObjKind::E3D_Polygon :
639 pRet = new Svx3DPolygonObject( pObj );
640 break;
641 default: // unknown 3D-object on page
642 assert(false && "the IsInventor3D function must be wrong");
643 pRet = new SvxShape( pObj );
644 break;
646 break;
648 case SdrInventor::Default:
650 switch( nType )
652 case SdrObjKind::Group:
653 pRet = new SvxShapeGroup( pObj, mpPage );
654 break;
655 case SdrObjKind::Line:
656 pRet = new SvxShapePolyPolygon( pObj );
657 break;
658 case SdrObjKind::Rectangle:
659 pRet = new SvxShapeRect( pObj );
660 break;
661 case SdrObjKind::CircleOrEllipse:
662 case SdrObjKind::CircleSection:
663 case SdrObjKind::CircleArc:
664 case SdrObjKind::CircleCut:
665 pRet = new SvxShapeCircle( pObj );
666 break;
667 case SdrObjKind::Polygon:
668 pRet = new SvxShapePolyPolygon( pObj );
669 break;
670 case SdrObjKind::PolyLine:
671 pRet = new SvxShapePolyPolygon( pObj );
672 break;
673 case SdrObjKind::PathLine:
674 pRet = new SvxShapePolyPolygon( pObj );
675 break;
676 case SdrObjKind::PathFill:
677 pRet = new SvxShapePolyPolygon( pObj );
678 break;
679 case SdrObjKind::FreehandLine:
680 pRet = new SvxShapePolyPolygon( pObj );
681 break;
682 case SdrObjKind::FreehandFill:
683 pRet = new SvxShapePolyPolygon( pObj );
684 break;
685 case SdrObjKind::Caption:
686 pRet = new SvxShapeCaption( pObj );
687 break;
688 case SdrObjKind::TitleText:
689 case SdrObjKind::OutlineText:
690 case SdrObjKind::Text:
691 pRet = new SvxShapeText( pObj );
692 break;
693 case SdrObjKind::Graphic:
694 pRet = new SvxGraphicObject( pObj );
695 break;
696 case SdrObjKind::OLEPluginFrame:
697 pRet = new SvxFrameShape( pObj, referer );
698 break;
699 case SdrObjKind::OLE2Applet:
700 pRet = new SvxAppletShape( pObj, referer );
701 break;
702 case SdrObjKind::OLE2Plugin:
703 pRet = new SvxPluginShape( pObj, referer );
704 break;
705 case SdrObjKind::OLE2:
707 if( pObj && !pObj->IsEmptyPresObj() && mpPage )
709 SdrPage* pSdrPage = mpPage->GetSdrPage();
710 if( pSdrPage )
712 SdrModel& rSdrModel(pSdrPage->getSdrModelFromSdrPage());
713 ::comphelper::IEmbeddedHelper *pPersist = rSdrModel.GetPersist();
715 if( pPersist )
717 uno::Reference < embed::XEmbeddedObject > xObject = pPersist->getEmbeddedObjectContainer().
718 GetEmbeddedObject( static_cast< SdrOle2Obj* >( pObj )->GetPersistName() );
720 // TODO CL->KA: Why is this not working anymore?
721 if( xObject.is() )
723 SvGlobalName aClassId( xObject->getClassID() );
725 const SvGlobalName aAppletClassId( SO3_APPLET_CLASSID );
726 const SvGlobalName aPluginClassId( SO3_PLUGIN_CLASSID );
727 const SvGlobalName aIFrameClassId( SO3_IFRAME_CLASSID );
729 if( aPluginClassId == aClassId )
731 pRet = new SvxPluginShape( pObj, referer );
732 nType = SdrObjKind::OLE2Plugin;
734 else if( aAppletClassId == aClassId )
736 pRet = new SvxAppletShape( pObj, referer );
737 nType = SdrObjKind::OLE2Applet;
739 else if( aIFrameClassId == aClassId )
741 pRet = new SvxFrameShape( pObj, referer );
742 nType = SdrObjKind::OLEPluginFrame;
748 if( pRet == nullptr )
750 SvxUnoPropertyMapProvider& rSvxMapProvider = getSvxMapProvider();
751 pRet = new SvxOle2Shape( pObj, referer, rSvxMapProvider.GetMap(SVXMAP_OLE2), rSvxMapProvider.GetPropertySet(SVXMAP_OLE2, SdrObject::GetGlobalDrawObjectItemPool()) );
754 break;
755 case SdrObjKind::Edge:
756 pRet = new SvxShapeConnector( pObj );
757 break;
758 case SdrObjKind::PathPoly:
759 pRet = new SvxShapePolyPolygon( pObj );
760 break;
761 case SdrObjKind::PathPolyLine:
762 pRet = new SvxShapePolyPolygon( pObj );
763 break;
764 case SdrObjKind::Page:
766 SvxUnoPropertyMapProvider& rSvxMapProvider = getSvxMapProvider();
767 pRet = new SvxShape( pObj, rSvxMapProvider.GetMap(SVXMAP_PAGE), rSvxMapProvider.GetPropertySet(SVXMAP_PAGE, SdrObject::GetGlobalDrawObjectItemPool()) );
769 break;
770 case SdrObjKind::Measure:
771 pRet = new SvxShapeDimensioning( pObj );
772 break;
773 case SdrObjKind::UNO:
774 pRet = new SvxShapeControl( pObj );
775 break;
776 case SdrObjKind::CustomShape:
777 pRet = new SvxCustomShape( pObj );
778 break;
779 case SdrObjKind::Media:
780 pRet = new SvxMediaShape( pObj, referer );
781 break;
782 case SdrObjKind::Table:
783 pRet = new SvxTableShape( pObj );
784 break;
785 default: // unknown 2D-object on page
786 assert(false && "Not implemented Starone-Shape created");
787 pRet = new SvxShapeText( pObj );
788 break;
790 break;
792 default: // unknown inventor
794 assert(false && "Unknown Inventor in SvxDrawPage::CreateShape()");
795 break;
799 if(pRet)
801 SdrObjKind nObjId = nType;
803 switch(nObjId)
805 case SdrObjKind::CircleCut: // segment of circle
806 case SdrObjKind::CircleArc: // arc of circle
807 case SdrObjKind::CircleSection: // sector
808 nObjId = SdrObjKind::CircleOrEllipse;
809 break;
811 case SdrObjKind::TitleText:
812 case SdrObjKind::OutlineText:
813 nObjId = SdrObjKind::Text;
814 break;
815 default: ;
818 pRet->setShapeKind(nObjId);
821 return pRet;
824 Reference< drawing::XShape > SvxDrawPage::CreateShape( SdrObject *pObj ) const
826 Reference< drawing::XShape > xShape( CreateShapeByTypeAndInventor(pObj->GetObjIdentifier(),
827 pObj->GetObjInventor(),
828 pObj,
829 const_cast<SvxDrawPage*>(this)));
830 return xShape;
833 rtl::Reference<SdrObject> SvxDrawPage::CreateSdrObject( const Reference< drawing::XShape > & xShape, bool bBeginning ) noexcept
835 rtl::Reference<SdrObject> pObj = CreateSdrObject_( xShape );
836 if( pObj)
838 if ( !pObj->IsInserted() && !pObj->IsDoNotInsertIntoPageAutomatically() )
840 if(bBeginning)
841 mpPage->InsertObject( pObj.get(), 0 );
842 else
843 mpPage->InsertObject( pObj.get() );
847 return pObj;
850 // css::lang::XServiceInfo
851 OUString SAL_CALL SvxDrawPage::getImplementationName()
853 return "SvxDrawPage";
856 sal_Bool SAL_CALL SvxDrawPage::supportsService( const OUString& ServiceName )
858 return cppu::supportsService( this, ServiceName );
861 uno::Sequence< OUString > SAL_CALL SvxDrawPage::getSupportedServiceNames()
863 uno::Sequence<OUString> aSeq { "com.sun.star.drawing.ShapeCollection" };
864 return aSeq;
867 rtl::Reference<SvxShape> CreateSvxShapeByTypeAndInventor(SdrObjKind nType, SdrInventor nInventor, OUString const & referer)
869 return SvxDrawPage::CreateShapeByTypeAndInventor( nType, nInventor, nullptr, nullptr, referer );
872 /** returns a StarOffice API wrapper for the given SdrPage */
873 uno::Reference< drawing::XDrawPage > GetXDrawPageForSdrPage( SdrPage* pPage ) noexcept
875 if(pPage)
877 uno::Reference< drawing::XDrawPage > xDrawPage( pPage->getUnoPage(), uno::UNO_QUERY );
879 return xDrawPage;
882 return uno::Reference< drawing::XDrawPage >();
885 /** returns the SdrObject from the given StarOffice API wrapper */
886 SdrPage* GetSdrPageFromXDrawPage( const uno::Reference< drawing::XDrawPage >& xDrawPage ) noexcept
888 if(xDrawPage.is())
890 SvxDrawPage* pDrawPage = comphelper::getFromUnoTunnel<SvxDrawPage>( xDrawPage );
892 if(pDrawPage)
894 return pDrawPage->GetSdrPage();
896 assert(false && "non-SvxDrawPage?");
899 return nullptr;
902 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */