Version 24.2.2.2, tag libreoffice-24.2.2.2
[LibreOffice.git] / svx / source / unodraw / unopage.cxx
blob960212ef6cdc84d26a3c91552aa4c5c0cadbce04
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 <com/sun/star/form/XForms.hpp>
27 #include <o3tl/safeint.hxx>
28 #include <osl/mutex.hxx>
29 #include <comphelper/classids.hxx>
30 #include <comphelper/embeddedobjectcontainer.hxx>
31 #include <comphelper/sequence.hxx>
32 #include <cppuhelper/supportsservice.hxx>
34 #include <svx/fmpage.hxx>
35 #include <svx/svdpool.hxx>
36 #include <svx/svdobj.hxx>
37 #include <svx/svdoole2.hxx>
38 #include <svx/svdpage.hxx>
39 #include <svx/svdmodel.hxx>
40 #include <svx/strings.hrc>
41 #include <svx/svdview.hxx>
42 #include <svx/svdpagv.hxx>
43 #include <svx/svdundo.hxx>
44 #include <svx/unopage.hxx>
45 #include "shapeimpl.hxx"
46 #include <svx/unodraw/SvxTableShape.hxx>
47 #include <svx/dialmgr.hxx>
48 #include <svx/svdobjkind.hxx>
49 #include <svx/unoprov.hxx>
50 #include <svx/unoapi.hxx>
51 #include <extrud3d.hxx>
52 #include <svx/lathe3d.hxx>
53 #include <svx/scene3d.hxx>
54 #include <vcl/svapp.hxx>
55 #include <comphelper/diagnose_ex.hxx>
56 #include <tools/globname.hxx>
57 #include <sal/log.hxx>
58 #include <fmobj.hxx>
60 using namespace ::cppu;
61 using namespace ::com::sun::star;
62 using namespace ::com::sun::star::uno;
63 using namespace ::com::sun::star::lang;
64 using namespace ::com::sun::star::container;
65 using namespace ::com::sun::star::drawing;
67 UNO3_GETIMPLEMENTATION_IMPL( SvxDrawPage );
69 SvxDrawPage::SvxDrawPage(SdrPage* pInPage) // TTTT should be reference
70 : mrBHelper(m_aMutex)
71 ,mpPage(pInPage)
72 ,mpModel(&pInPage->getSdrModelFromSdrPage()) // register at broadcaster
73 ,mpView(new SdrView(pInPage->getSdrModelFromSdrPage())) // create (hidden) view
75 mpView->SetDesignMode();
78 SvxDrawPage::~SvxDrawPage() noexcept
80 if( !mrBHelper.bDisposed )
82 assert(!"SvxDrawPage must be disposed!");
83 acquire();
84 dispose();
88 // XComponent
89 void SvxDrawPage::disposing() noexcept
91 if( mpModel )
93 mpModel = nullptr;
96 mpView.reset();
97 mpPage = nullptr;
100 // XComponent
101 void SvxDrawPage::dispose()
103 SolarMutexGuard aSolarGuard;
105 // An frequently programming error is to release the last
106 // reference to this object in the disposing message.
107 // Make it robust, hold a self Reference.
108 uno::Reference< lang::XComponent > xSelf( this );
110 // Guard dispose against multiple threading
111 // Remark: It is an error to call dispose more than once
112 bool bDoDispose = false;
114 osl::MutexGuard aGuard( mrBHelper.rMutex );
115 if( !mrBHelper.bDisposed && !mrBHelper.bInDispose )
117 // only one call go into this section
118 mrBHelper.bInDispose = true;
119 bDoDispose = true;
123 // Do not hold the mutex because we are broadcasting
124 if( !bDoDispose )
125 return;
127 // Create an event with this as sender
130 uno::Reference< uno::XInterface > xSource( uno::Reference< uno::XInterface >::query( static_cast<lang::XComponent *>(this) ) );
131 css::document::EventObject aEvt;
132 aEvt.Source = xSource;
133 // inform all listeners to release this object
134 // The listener container are automatically cleared
135 mrBHelper.aLC.disposeAndClear( aEvt );
136 // notify subclasses to do their dispose
137 disposing();
139 catch(const css::uno::Exception&)
141 // catch exception and throw again but signal that
142 // the object was disposed. Dispose should be called
143 // only once.
144 osl::MutexGuard aGuard( mrBHelper.rMutex );
145 mrBHelper.bDisposed = true;
146 mrBHelper.bInDispose = false;
147 throw;
150 osl::MutexGuard aGuard( mrBHelper.rMutex );
151 mrBHelper.bDisposed = true;
152 mrBHelper.bInDispose = false;
156 void SAL_CALL SvxDrawPage::addEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener )
158 SolarMutexGuard aGuard;
160 if( mpModel == nullptr )
161 throw lang::DisposedException();
163 mrBHelper.addListener( cppu::UnoType<decltype(aListener)>::get() , aListener );
166 void SAL_CALL SvxDrawPage::removeEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener )
168 SolarMutexGuard aGuard;
170 if( mpModel == nullptr )
171 throw lang::DisposedException();
173 mrBHelper.removeListener( cppu::UnoType<decltype(aListener)>::get() , aListener );
176 void SAL_CALL SvxDrawPage::add( const uno::Reference< drawing::XShape >& xShape )
178 SolarMutexGuard aGuard;
180 if ( ( mpModel == nullptr ) || ( mpPage == nullptr ) )
181 throw lang::DisposedException();
183 SvxShape* pShape = comphelper::getFromUnoTunnel<SvxShape>( xShape );
185 if( nullptr == pShape )
187 assert(false && "adding a non-SvxShape to a page?");
188 return;
191 rtl::Reference<SdrObject> pObj = pShape->GetSdrObject();
192 bool bNeededToClone(false);
194 if(pObj && &pObj->getSdrModelFromSdrObject() != &mpPage->getSdrModelFromSdrPage())
196 // TTTT UNO API tries to add an existing SvxShape to this SvxDrawPage,
197 // but these use different SdrModels. It was possible before to completely
198 // 'change' a SdrObject to another SdrModel (including dangerous MigrateItemPool
199 // stuff), but is no longer. We need to Clone the SdrObject to the target model
200 // and ::Create a new SvxShape (set SdrObject there, take over values, ...)
201 rtl::Reference<SdrObject> pClonedSdrShape(pObj->CloneSdrObject(mpPage->getSdrModelFromSdrPage()));
202 pObj->setUnoShape(nullptr);
203 pClonedSdrShape->setUnoShape(pShape);
204 // pShape->InvalidateSdrObject();
205 // pShape->Create(pClonedSdrShape, this);
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.get() );
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< drawing::XShape > xShapeCheck(pObj->getWeakUnoShape());
226 if( !xShapeCheck.is() )
228 pObj->setUnoShape(pShape);
233 pShape->Create( pObj.get(), this );
234 OSL_ENSURE( pShape->GetSdrObject() == pObj.get(), "SvxDrawPage::add: shape does not know about its newly created SdrObject!" );
236 if ( !pObj->IsInserted() )
238 mpPage->InsertObject( pObj.get() );
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::getFromUnoTunnel<SvxShape>( xShape );
258 if( nullptr == pShape )
260 assert(false && "adding a non-SvxShape to a page?");
261 return;
264 rtl::Reference<SdrObject> pObj = pShape->GetSdrObject();
266 if(!pObj)
268 pObj = CreateSdrObject( xShape, true );
269 ENSURE_OR_RETURN_VOID( pObj != nullptr, "SvxDrawPage::add: no SdrObject was created!" );
271 else if ( !pObj->IsInserted() )
273 mpPage->InsertObject( pObj.get(), 0 );
276 pShape->Create( pObj.get(), this );
277 OSL_ENSURE( pShape->GetSdrObject() == pObj.get(), "SvxDrawPage::add: shape does not know about its newly created SdrObject!" );
279 if ( !pObj->IsInserted() )
281 mpPage->InsertObject( pObj.get(), 0 );
284 mpModel->SetChanged();
287 void SAL_CALL SvxDrawPage::remove( const Reference< drawing::XShape >& xShape )
289 SolarMutexGuard aGuard;
291 if( (mpModel == nullptr) || (mpPage == nullptr) )
292 throw lang::DisposedException();
294 SdrObject* pObj = SdrObject::getSdrObjectFromXShape( xShape );
295 if (!pObj)
296 return;
298 // remove SdrObject from page
299 const size_t nCount = mpPage->GetObjCount();
300 for( size_t nNum = 0; nNum < nCount; ++nNum )
302 if(mpPage->GetObj(nNum) == pObj)
304 const bool bUndoEnabled = mpModel->IsUndoEnabled();
306 if (bUndoEnabled)
308 mpModel->BegUndo(SvxResId(STR_EditDelete),
309 pObj->TakeObjNameSingul(), SdrRepeatFunc::Delete);
311 mpModel->AddUndo(mpModel->GetSdrUndoFactory().CreateUndoDeleteObject(*pObj));
314 OSL_VERIFY( mpPage->RemoveObject( nNum ) == 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 Any(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 rtl::Reference<SdrObject> SvxDrawPage::CreateSdrObject_(const Reference< drawing::XShape > & xShape)
496 OUString aShapeType( xShape->getShapeType() );
498 if ( aShapeType == "com.sun.star.drawing.ShapeControl" // compatibility
499 || aShapeType == "com.sun.star.drawing.ControlShape"
502 return new FmFormObj(GetSdrPage()->getSdrModelFromSdrPage());
505 SdrObjKind nType = SdrObjKind::NONE;
506 SdrInventor nInventor;
508 GetTypeAndInventor( nType, nInventor, xShape->getShapeType() );
509 if (nType == SdrObjKind::NONE)
510 return nullptr;
512 awt::Size aSize = xShape->getSize();
513 aSize.Width += 1;
514 aSize.Height += 1;
515 awt::Point aPos = xShape->getPosition();
516 tools::Rectangle aRect( Point( aPos.X, aPos.Y ), Size( aSize.Width, aSize.Height ) );
518 rtl::Reference<SdrObject> pNewObj = SdrObjFactory::MakeNewObject(
519 *mpModel,
520 nInventor,
521 nType,
522 &aRect);
524 if (!pNewObj)
525 return nullptr;
527 if( nType == SdrObjKind::E3D_Scene )
529 auto pScene = static_cast<E3dScene* >(pNewObj.get());
530 // initialise scene
532 double fW = static_cast<double>(aSize.Width);
533 double fH = static_cast<double>(aSize.Height);
535 Camera3D aCam(pScene->GetCamera());
536 aCam.SetAutoAdjustProjection(false);
537 aCam.SetViewWindow(- fW / 2, - fH / 2, fW, fH);
538 basegfx::B3DPoint aLookAt;
539 basegfx::B3DPoint aCamPos(0.0, 0.0, 10000.0);
540 aCam.SetPosAndLookAt(aCamPos, aLookAt);
541 aCam.SetFocalLength(100.0);
542 pScene->SetCamera(aCam);
544 pScene->SetBoundAndSnapRectsDirty();
546 else if(nType == SdrObjKind::E3D_Extrusion)
548 auto pObj = static_cast<E3dExtrudeObj* >(pNewObj.get());
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->SetExtrudePolygon(basegfx::B2DPolyPolygon(aNewPolygon));
556 // #107245# pObj->SetExtrudeCharacterMode(sal_True);
557 pObj->SetMergedItem(Svx3DCharacterModeItem(true));
559 else if(nType == SdrObjKind::E3D_Lathe)
561 auto pLatheObj = static_cast<E3dLatheObj* >(pNewObj.get());
562 basegfx::B2DPolygon aNewPolygon;
563 aNewPolygon.append(basegfx::B2DPoint(0.0, 0.0));
564 aNewPolygon.append(basegfx::B2DPoint(0.0, 1.0));
565 aNewPolygon.append(basegfx::B2DPoint(1.0, 0.0));
566 aNewPolygon.setClosed(true);
567 pLatheObj->SetPolyPoly2D(basegfx::B2DPolyPolygon(aNewPolygon));
569 // #107245# pObj->SetLatheCharacterMode(sal_True);
570 pLatheObj->SetMergedItem(Svx3DCharacterModeItem(true));
573 return pNewObj;
576 void SvxDrawPage::GetTypeAndInventor( SdrObjKind& rType, SdrInventor& rInventor, const OUString& aName ) noexcept
578 std::optional<SdrObjKind> nTempType = UHashMap::getId( aName );
580 if( !nTempType )
582 if( aName == "com.sun.star.drawing.TableShape" ||
583 aName == "com.sun.star.presentation.TableShape" )
585 rInventor = SdrInventor::Default;
586 rType = SdrObjKind::Table;
588 #if HAVE_FEATURE_AVMEDIA
589 else if ( aName == "com.sun.star.presentation.MediaShape" )
591 rInventor = SdrInventor::Default;
592 rType = SdrObjKind::Media;
594 #endif
596 else if( IsInventorE3D(*nTempType) )
598 rInventor = SdrInventor::E3d;
599 rType = *nTempType;
601 else
603 rInventor = SdrInventor::Default;
604 rType = *nTempType;
606 switch( rType )
608 case SdrObjKind::OLEPluginFrame:
609 case SdrObjKind::OLE2Plugin:
610 case SdrObjKind::OLE2Applet:
611 rType = SdrObjKind::OLE2;
612 break;
613 default:
614 break;
619 rtl::Reference<SvxShape> SvxDrawPage::CreateShapeByTypeAndInventor( SdrObjKind nType, SdrInventor nInventor, SdrObject *pObj, SvxDrawPage *mpPage, OUString const & referer )
621 rtl::Reference<SvxShape> pRet;
623 switch( nInventor )
625 case SdrInventor::FmForm:
627 return new SvxShapeControl( pObj );
629 case SdrInventor::E3d:
631 switch( nType )
633 case SdrObjKind::E3D_Scene :
634 pRet = new Svx3DSceneObject( pObj, mpPage );
635 break;
636 case SdrObjKind::E3D_Cube :
637 pRet = new Svx3DCubeObject( pObj );
638 break;
639 case SdrObjKind::E3D_Sphere :
640 pRet = new Svx3DSphereObject( pObj );
641 break;
642 case SdrObjKind::E3D_Lathe :
643 pRet = new Svx3DLatheObject( pObj );
644 break;
645 case SdrObjKind::E3D_Extrusion :
646 pRet = new Svx3DExtrudeObject( pObj );
647 break;
648 case SdrObjKind::E3D_Polygon :
649 pRet = new Svx3DPolygonObject( pObj );
650 break;
651 default: // unknown 3D-object on page
652 assert(false && "the IsInventor3D function must be wrong");
653 pRet = new SvxShape( pObj );
654 break;
656 break;
658 case SdrInventor::Default:
660 switch( nType )
662 case SdrObjKind::Group:
663 pRet = new SvxShapeGroup( pObj, mpPage );
664 break;
665 case SdrObjKind::Line:
666 pRet = new SvxShapePolyPolygon( pObj );
667 break;
668 case SdrObjKind::Rectangle:
669 pRet = new SvxShapeRect( pObj );
670 break;
671 case SdrObjKind::CircleOrEllipse:
672 case SdrObjKind::CircleSection:
673 case SdrObjKind::CircleArc:
674 case SdrObjKind::CircleCut:
675 pRet = new SvxShapeCircle( pObj );
676 break;
677 case SdrObjKind::Polygon:
678 pRet = new SvxShapePolyPolygon( pObj );
679 break;
680 case SdrObjKind::PolyLine:
681 pRet = new SvxShapePolyPolygon( pObj );
682 break;
683 case SdrObjKind::PathLine:
684 pRet = new SvxShapePolyPolygon( pObj );
685 break;
686 case SdrObjKind::PathFill:
687 pRet = new SvxShapePolyPolygon( pObj );
688 break;
689 case SdrObjKind::FreehandLine:
690 pRet = new SvxShapePolyPolygon( pObj );
691 break;
692 case SdrObjKind::FreehandFill:
693 pRet = new SvxShapePolyPolygon( pObj );
694 break;
695 case SdrObjKind::Caption:
696 pRet = new SvxShapeCaption( pObj );
697 break;
698 case SdrObjKind::TitleText:
699 case SdrObjKind::OutlineText:
700 case SdrObjKind::Text:
701 pRet = new SvxShapeText( pObj );
702 break;
703 case SdrObjKind::Graphic:
704 pRet = new SvxGraphicObject( pObj );
705 break;
706 case SdrObjKind::OLEPluginFrame:
707 pRet = new SvxFrameShape( pObj, referer );
708 break;
709 case SdrObjKind::OLE2Applet:
710 pRet = new SvxAppletShape( pObj, referer );
711 break;
712 case SdrObjKind::OLE2Plugin:
713 pRet = new SvxPluginShape( pObj, referer );
714 break;
715 case SdrObjKind::OLE2:
717 if( pObj && !pObj->IsEmptyPresObj() && mpPage )
719 SdrPage* pSdrPage = mpPage->GetSdrPage();
720 if( pSdrPage )
722 SdrModel& rSdrModel(pSdrPage->getSdrModelFromSdrPage());
723 ::comphelper::IEmbeddedHelper *pPersist = rSdrModel.GetPersist();
725 if( pPersist )
727 uno::Reference < embed::XEmbeddedObject > xObject = pPersist->getEmbeddedObjectContainer().
728 GetEmbeddedObject( static_cast< SdrOle2Obj* >( pObj )->GetPersistName() );
730 // TODO CL->KA: Why is this not working anymore?
731 if( xObject.is() )
733 SvGlobalName aClassId( xObject->getClassID() );
735 const SvGlobalName aAppletClassId( SO3_APPLET_CLASSID );
736 const SvGlobalName aPluginClassId( SO3_PLUGIN_CLASSID );
737 const SvGlobalName aIFrameClassId( SO3_IFRAME_CLASSID );
739 if( aPluginClassId == aClassId )
741 pRet = new SvxPluginShape( pObj, referer );
742 nType = SdrObjKind::OLE2Plugin;
744 else if( aAppletClassId == aClassId )
746 pRet = new SvxAppletShape( pObj, referer );
747 nType = SdrObjKind::OLE2Applet;
749 else if( aIFrameClassId == aClassId )
751 pRet = new SvxFrameShape( pObj, referer );
752 nType = SdrObjKind::OLEPluginFrame;
758 if( pRet == nullptr )
760 SvxUnoPropertyMapProvider& rSvxMapProvider = getSvxMapProvider();
761 pRet = new SvxOle2Shape( pObj, referer, rSvxMapProvider.GetMap(SVXMAP_OLE2), rSvxMapProvider.GetPropertySet(SVXMAP_OLE2, SdrObject::GetGlobalDrawObjectItemPool()) );
764 break;
765 case SdrObjKind::Edge:
766 pRet = new SvxShapeConnector( pObj );
767 break;
768 case SdrObjKind::PathPoly:
769 pRet = new SvxShapePolyPolygon( pObj );
770 break;
771 case SdrObjKind::PathPolyLine:
772 pRet = new SvxShapePolyPolygon( pObj );
773 break;
774 case SdrObjKind::Page:
776 SvxUnoPropertyMapProvider& rSvxMapProvider = getSvxMapProvider();
777 pRet = new SvxShape( pObj, rSvxMapProvider.GetMap(SVXMAP_PAGE), rSvxMapProvider.GetPropertySet(SVXMAP_PAGE, SdrObject::GetGlobalDrawObjectItemPool()) );
779 break;
780 case SdrObjKind::Measure:
781 pRet = new SvxShapeDimensioning( pObj );
782 break;
783 case SdrObjKind::UNO:
784 pRet = new SvxShapeControl( pObj );
785 break;
786 case SdrObjKind::CustomShape:
787 pRet = new SvxCustomShape( pObj );
788 break;
789 case SdrObjKind::Media:
790 pRet = new SvxMediaShape( pObj, referer );
791 break;
792 case SdrObjKind::Table:
793 pRet = new SvxTableShape( pObj );
794 break;
795 default: // unknown 2D-object on page
796 assert(false && "Not implemented Starone-Shape created");
797 pRet = new SvxShapeText( pObj );
798 break;
800 break;
802 default: // unknown inventor
804 assert(false && "Unknown Inventor in SvxDrawPage::CreateShape()");
805 break;
809 if(pRet)
811 SdrObjKind nObjId = nType;
813 switch(nObjId)
815 case SdrObjKind::CircleCut: // segment of circle
816 case SdrObjKind::CircleArc: // arc of circle
817 case SdrObjKind::CircleSection: // sector
818 nObjId = SdrObjKind::CircleOrEllipse;
819 break;
821 case SdrObjKind::TitleText:
822 case SdrObjKind::OutlineText:
823 nObjId = SdrObjKind::Text;
824 break;
825 default: ;
828 pRet->setShapeKind(nObjId);
831 return pRet;
834 Reference< drawing::XShape > SvxDrawPage::CreateShape( SdrObject *pObj ) const
836 Reference< drawing::XShape > xShape( CreateShapeByTypeAndInventor(pObj->GetObjIdentifier(),
837 pObj->GetObjInventor(),
838 pObj,
839 const_cast<SvxDrawPage*>(this)));
840 return xShape;
843 rtl::Reference<SdrObject> SvxDrawPage::CreateSdrObject( const Reference< drawing::XShape > & xShape, bool bBeginning ) noexcept
845 rtl::Reference<SdrObject> pObj = CreateSdrObject_( xShape );
846 if( pObj)
848 if ( !pObj->IsInserted() && !pObj->IsDoNotInsertIntoPageAutomatically() )
850 if(bBeginning)
851 mpPage->InsertObject( pObj.get(), 0 );
852 else
853 mpPage->InsertObject( pObj.get() );
857 return pObj;
860 // css::lang::XServiceInfo
861 OUString SAL_CALL SvxDrawPage::getImplementationName()
863 return "SvxDrawPage";
866 sal_Bool SAL_CALL SvxDrawPage::supportsService( const OUString& ServiceName )
868 return cppu::supportsService( this, ServiceName );
871 uno::Sequence< OUString > SAL_CALL SvxDrawPage::getSupportedServiceNames()
873 uno::Sequence<OUString> aSeq { "com.sun.star.drawing.ShapeCollection" };
874 return aSeq;
877 rtl::Reference<SvxShape> CreateSvxShapeByTypeAndInventor(SdrObjKind nType, SdrInventor nInventor, OUString const & referer)
879 return SvxDrawPage::CreateShapeByTypeAndInventor( nType, nInventor, nullptr, nullptr, referer );
882 /** returns a StarOffice API wrapper for the given SdrPage */
883 uno::Reference< drawing::XDrawPage > GetXDrawPageForSdrPage( SdrPage* pPage ) noexcept
885 if(pPage)
887 uno::Reference< drawing::XDrawPage > xDrawPage( pPage->getUnoPage(), uno::UNO_QUERY );
889 return xDrawPage;
892 return uno::Reference< drawing::XDrawPage >();
895 /** returns the SdrObject from the given StarOffice API wrapper */
896 SdrPage* GetSdrPageFromXDrawPage( const uno::Reference< drawing::XDrawPage >& xDrawPage ) noexcept
898 if(xDrawPage.is())
900 SvxDrawPage* pDrawPage = comphelper::getFromUnoTunnel<SvxDrawPage>( xDrawPage );
902 if(pDrawPage)
904 return pDrawPage->GetSdrPage();
906 assert(false && "non-SvxDrawPage?");
909 return nullptr;
912 // XFormsSupplier
913 css::uno::Reference< css::container::XNameContainer > SAL_CALL SvxDrawPage::getForms()
915 SolarMutexGuard g;
917 css::uno::Reference< css::container::XNameContainer > xForms;
919 FmFormPage *pFmPage = dynamic_cast<FmFormPage*>( GetSdrPage() );
920 if( pFmPage )
921 xForms.set( pFmPage->GetForms(), css::uno::UNO_QUERY_THROW );
923 return xForms;
926 // XFormsSupplier2
927 sal_Bool SAL_CALL SvxDrawPage::hasForms()
929 SolarMutexGuard g;
931 bool bHas = false;
932 FmFormPage* pFormPage = dynamic_cast<FmFormPage*>( GetSdrPage() );
933 if ( pFormPage )
934 bHas = pFormPage->GetForms( false ).is();
935 return bHas;
938 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */