tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / svx / source / unodraw / unopage.cxx
blob149058d02c8607eca378965badb2a7e82c4c80fd
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/fmpage.hxx>
34 #include <svx/svdpool.hxx>
35 #include <svx/svdobj.hxx>
36 #include <svx/svdoole2.hxx>
37 #include <svx/svdpage.hxx>
38 #include <svx/svdmodel.hxx>
39 #include <svx/strings.hrc>
40 #include <svx/svdview.hxx>
41 #include <svx/svdpagv.hxx>
42 #include <svx/svdundo.hxx>
43 #include <svx/unopage.hxx>
44 #include "shapeimpl.hxx"
45 #include <svx/unodraw/SvxTableShape.hxx>
46 #include <svx/dialmgr.hxx>
47 #include <svx/svdobjkind.hxx>
48 #include <svx/unoprov.hxx>
49 #include <svx/unoapi.hxx>
50 #include <extrud3d.hxx>
51 #include <svx/lathe3d.hxx>
52 #include <svx/scene3d.hxx>
53 #include <vcl/svapp.hxx>
54 #include <comphelper/diagnose_ex.hxx>
55 #include <tools/globname.hxx>
56 #include <sal/log.hxx>
57 #include <fmobj.hxx>
59 using namespace ::cppu;
60 using namespace ::com::sun::star;
61 using namespace ::com::sun::star::uno;
62 using namespace ::com::sun::star::lang;
63 using namespace ::com::sun::star::container;
64 using namespace ::com::sun::star::drawing;
66 UNO3_GETIMPLEMENTATION_IMPL( SvxDrawPage );
68 SvxDrawPage::SvxDrawPage(SdrPage* pInPage) // TTTT should be reference
69 : mpPage(pInPage)
70 ,mpModel(&pInPage->getSdrModelFromSdrPage()) // register at broadcaster
71 ,mpView(new SdrView(pInPage->getSdrModelFromSdrPage())) // create (hidden) view
73 mpView->SetDesignMode();
76 SvxDrawPage::~SvxDrawPage() noexcept
78 if( !m_bDisposed )
80 assert(!"SvxDrawPage must be disposed!");
81 acquire();
82 dispose();
86 // XComponent
87 void SvxDrawPage::disposing() noexcept
89 if( mpModel )
91 mpModel = nullptr;
94 mpView.reset();
95 mpPage = nullptr;
98 // XComponent
99 void SvxDrawPage::dispose()
101 SolarMutexGuard aSolarGuard;
103 // An frequently programming error is to release the last
104 // reference to this object in the disposing message.
105 // Make it robust, hold a self Reference.
106 uno::Reference< lang::XComponent > xSelf( this );
108 // Guard dispose against multiple threading
109 // Remark: It is an error to call dispose more than once
111 std::unique_lock aGuard( m_aMutex );
112 if( m_bDisposed )
113 return;
114 m_bDisposed = true;
117 // Create an event with this as sender
118 css::document::EventObject aEvt;
119 aEvt.Source.set(uno::Reference<uno::XInterface>::query( static_cast<lang::XComponent *>(this) ));
120 // inform all listeners to release this object
121 // The listener container are automatically cleared
123 std::unique_lock aGuard( m_aMutex );
124 maEventListeners.disposeAndClear( aGuard, aEvt );
126 // notify subclasses to do their dispose
127 disposing();
130 void SAL_CALL SvxDrawPage::addEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener )
132 std::unique_lock aGuard( m_aMutex );
134 if( mpModel == nullptr )
135 throw lang::DisposedException();
137 maEventListeners.addInterface( aGuard, aListener );
140 void SAL_CALL SvxDrawPage::removeEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener )
142 std::unique_lock aGuard( m_aMutex );
144 if( mpModel == nullptr )
145 throw lang::DisposedException();
147 maEventListeners.removeInterface( aGuard, aListener );
150 void SAL_CALL SvxDrawPage::add( const uno::Reference< drawing::XShape >& xShape )
152 SolarMutexGuard aGuard;
154 if ( ( mpModel == nullptr ) || ( mpPage == nullptr ) )
155 throw lang::DisposedException();
157 SvxShape* pShape = comphelper::getFromUnoTunnel<SvxShape>( xShape );
159 if( nullptr == pShape )
161 assert(false && "adding a non-SvxShape to a page?");
162 return;
165 rtl::Reference<SdrObject> pObj = pShape->GetSdrObject();
166 bool bNeededToClone(false);
168 if(pObj && &pObj->getSdrModelFromSdrObject() != &mpPage->getSdrModelFromSdrPage())
170 // TTTT UNO API tries to add an existing SvxShape to this SvxDrawPage,
171 // but these use different SdrModels. It was possible before to completely
172 // 'change' a SdrObject to another SdrModel (including dangerous MigrateItemPool
173 // stuff), but is no longer. We need to Clone the SdrObject to the target model
174 // and ::Create a new SvxShape (set SdrObject there, take over values, ...)
175 rtl::Reference<SdrObject> pClonedSdrShape(pObj->CloneSdrObject(mpPage->getSdrModelFromSdrPage()));
176 pObj->setUnoShape(nullptr);
177 pClonedSdrShape->setUnoShape(pShape);
178 // pShape->InvalidateSdrObject();
179 // pShape->Create(pClonedSdrShape, this);
180 pObj = std::move(pClonedSdrShape);
181 bNeededToClone = true;
184 if(!pObj)
186 pObj = CreateSdrObject( xShape );
187 ENSURE_OR_RETURN_VOID( pObj != nullptr, "SvxDrawPage::add: no SdrObject was created!" );
189 else if ( !pObj->IsInserted() )
191 mpPage->InsertObject( pObj.get() );
193 if(bNeededToClone)
195 // TTTT Unfortunately in SdrObject::SetPage (see there) the
196 // xShape/UnoShape at the newly cloned SDrObject is *removed* again,
197 // so re-set it here, the caller *may need it* (e.g. Writer)
198 uno::Reference< drawing::XShape > xShapeCheck(pObj->getWeakUnoShape());
200 if( !xShapeCheck.is() )
202 pObj->setUnoShape(pShape);
207 pShape->Create( pObj.get(), this );
208 OSL_ENSURE( pShape->GetSdrObject() == pObj.get(), "SvxDrawPage::add: shape does not know about its newly created SdrObject!" );
210 if ( !pObj->IsInserted() )
212 mpPage->InsertObject( pObj.get() );
215 mpModel->SetChanged();
218 void SAL_CALL SvxDrawPage::addTop( const uno::Reference< drawing::XShape >& xShape )
220 add(xShape);
223 void SAL_CALL SvxDrawPage::addBottom( const uno::Reference< drawing::XShape >& xShape )
225 SolarMutexGuard aGuard;
227 if ( ( mpModel == nullptr ) || ( mpPage == nullptr ) )
228 throw lang::DisposedException();
230 SvxShape* pShape = comphelper::getFromUnoTunnel<SvxShape>( xShape );
232 if( nullptr == pShape )
234 assert(false && "adding a non-SvxShape to a page?");
235 return;
238 rtl::Reference<SdrObject> pObj = pShape->GetSdrObject();
240 if(!pObj)
242 pObj = CreateSdrObject( xShape, true );
243 ENSURE_OR_RETURN_VOID( pObj != nullptr, "SvxDrawPage::add: no SdrObject was created!" );
245 else if ( !pObj->IsInserted() )
247 mpPage->InsertObject( pObj.get(), 0 );
250 pShape->Create( pObj.get(), this );
251 OSL_ENSURE( pShape->GetSdrObject() == pObj.get(), "SvxDrawPage::add: shape does not know about its newly created SdrObject!" );
253 if ( !pObj->IsInserted() )
255 mpPage->InsertObject( pObj.get(), 0 );
258 mpModel->SetChanged();
261 void SAL_CALL SvxDrawPage::remove( const Reference< drawing::XShape >& xShape )
263 SolarMutexGuard aGuard;
265 if( (mpModel == nullptr) || (mpPage == nullptr) )
266 throw lang::DisposedException();
268 SdrObject* pObj = SdrObject::getSdrObjectFromXShape( xShape );
269 if (!pObj)
270 return;
272 // remove SdrObject from page
273 const size_t nCount = mpPage->GetObjCount();
274 for( size_t nNum = 0; nNum < nCount; ++nNum )
276 if(mpPage->GetObj(nNum) == pObj)
278 const bool bUndoEnabled = mpModel->IsUndoEnabled();
280 if (bUndoEnabled)
282 mpModel->BegUndo(SvxResId(STR_EditDelete),
283 pObj->TakeObjNameSingul(), SdrRepeatFunc::Delete);
285 mpModel->AddUndo(mpModel->GetSdrUndoFactory().CreateUndoDeleteObject(*pObj));
288 OSL_VERIFY( mpPage->RemoveObject( nNum ) == pObj );
290 if (bUndoEnabled)
291 mpModel->EndUndo();
293 break;
297 mpModel->SetChanged();
300 void SvxDrawPage::sort( const css::uno::Sequence< sal_Int32 >& sortOrder )
302 SolarMutexGuard aGuard;
304 if ((mpModel == nullptr) || (mpPage == nullptr))
305 throw lang::DisposedException();
307 auto newOrder = comphelper::sequenceToContainer<std::vector<sal_Int32>>(sortOrder);
308 mpPage->sort(newOrder);
311 // css::container::XIndexAccess
312 sal_Int32 SAL_CALL SvxDrawPage::getCount()
314 SolarMutexGuard aGuard;
316 if( (mpModel == nullptr) || (mpPage == nullptr) )
317 throw lang::DisposedException();
319 return static_cast<sal_Int32>( mpPage->GetObjCount() );
322 uno::Any SAL_CALL SvxDrawPage::getByIndex( sal_Int32 Index )
324 SolarMutexGuard aGuard;
326 if( (mpModel == nullptr) || (mpPage == nullptr) )
327 throw lang::DisposedException(u"Model or Page was already disposed!"_ustr);
329 if ( Index < 0 || o3tl::make_unsigned(Index) >= mpPage->GetObjCount() )
330 throw lang::IndexOutOfBoundsException("Index (" + OUString::number(Index)
331 + ") needs to be a positive integer smaller than the shape count ("
332 + OUString::number(mpPage->GetObjCount()) + ")!");
334 SdrObject* pObj = mpPage->GetObj( Index );
335 if( pObj == nullptr )
336 throw uno::RuntimeException("Runtime exception thrown while getting a ref to the SdrObject at index: "
337 + OUString::number(Index));
340 return Any(Reference< drawing::XShape >( pObj->getUnoShape(), uno::UNO_QUERY ));
343 // css::container::XElementAccess
344 uno::Type SAL_CALL SvxDrawPage::getElementType()
346 return cppu::UnoType<drawing::XShape>::get();
349 sal_Bool SAL_CALL SvxDrawPage::hasElements()
351 SolarMutexGuard aGuard;
353 if( (mpModel == nullptr) || (mpPage == nullptr) )
354 throw lang::DisposedException();
356 return mpPage->GetObjCount()>0;
359 namespace
361 void lcl_markSdrObjectOfShape( const Reference< drawing::XShape >& _rxShape, SdrView& _rView, SdrPageView& _rPageView )
363 SdrObject* pObj = SdrObject::getSdrObjectFromXShape( _rxShape );
364 if ( !pObj )
365 return;
367 _rView.MarkObj( pObj, &_rPageView );
371 // ATTENTION: SelectObjectsInView selects the css::drawing::Shapes
372 // only in the given SdrPageView. It hasn't to be the visible SdrPageView.
373 void SvxDrawPage::SelectObjectsInView( const Reference< drawing::XShapes > & aShapes, SdrPageView* pPageView ) noexcept
375 SAL_WARN_IF(!pPageView, "svx", "SdrPageView is NULL!");
376 SAL_WARN_IF(!mpView, "svx", "SdrView is NULL!");
378 if(pPageView==nullptr || mpView==nullptr)
379 return;
381 mpView->UnmarkAllObj( pPageView );
383 tools::Long nCount = aShapes->getCount();
384 for( tools::Long i = 0; i < nCount; i++ )
386 uno::Any aAny( aShapes->getByIndex(i) );
387 Reference< drawing::XShape > xShape;
388 if( aAny >>= xShape )
389 lcl_markSdrObjectOfShape( xShape, *mpView, *pPageView );
393 // ATTENTION: SelectObjectInView selects the shape only in the given SdrPageView.
394 // It hasn't to be the visible SdrPageView.
395 void SvxDrawPage::SelectObjectInView( const Reference< drawing::XShape > & xShape, SdrPageView* pPageView ) noexcept
397 SAL_WARN_IF(!pPageView, "svx", "SdrPageView is NULL!");
398 SAL_WARN_IF(!mpView, "svx", "SdrView is NULL!");
400 if(pPageView!=nullptr && mpView != nullptr)
402 mpView->UnmarkAllObj( pPageView );
403 lcl_markSdrObjectOfShape( xShape, *mpView, *pPageView );
407 Reference< drawing::XShapeGroup > SAL_CALL SvxDrawPage::group( const Reference< drawing::XShapes >& xShapes )
409 SolarMutexGuard aGuard;
411 if( (mpModel == nullptr) || (mpPage == nullptr) )
412 throw lang::DisposedException();
414 SAL_WARN_IF(!mpPage , "svx", "SdrPage is NULL!");
415 SAL_WARN_IF(!mpView, "svx", "SdrView is NULL!");
417 Reference< css::drawing::XShapeGroup > xShapeGroup;
418 if(mpPage==nullptr||mpView==nullptr||!xShapes.is())
419 return xShapeGroup;
421 SdrPageView* pPageView = mpView->ShowSdrPage( mpPage );
423 SelectObjectsInView( xShapes, pPageView );
425 mpView->GroupMarked();
427 mpView->AdjustMarkHdl();
428 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
429 if( rMarkList.GetMarkCount() == 1 )
431 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
432 if( pObj )
433 xShapeGroup.set( pObj->getUnoShape(), UNO_QUERY );
436 mpView->HideSdrPage();
438 if( mpModel )
439 mpModel->SetChanged();
441 return xShapeGroup;
444 void SAL_CALL SvxDrawPage::ungroup( const Reference< drawing::XShapeGroup >& aGroup )
446 SolarMutexGuard aGuard;
448 if( (mpModel == nullptr) || (mpPage == nullptr) )
449 throw lang::DisposedException();
451 SAL_WARN_IF(!mpPage, "svx", "SdrPage is NULL!");
452 SAL_WARN_IF(!mpView, "svx", "SdrView is NULL!");
454 if(mpPage==nullptr||mpView==nullptr||!aGroup.is())
455 return;
457 SdrPageView* pPageView = mpView->ShowSdrPage( mpPage );
459 SelectObjectInView( aGroup, pPageView );
460 mpView->UnGroupMarked();
462 mpView->HideSdrPage();
464 if( mpModel )
465 mpModel->SetChanged();
468 rtl::Reference<SdrObject> SvxDrawPage::CreateSdrObject_(const Reference< drawing::XShape > & xShape)
470 OUString aShapeType( xShape->getShapeType() );
472 if ( aShapeType == "com.sun.star.drawing.ShapeControl" // compatibility
473 || aShapeType == "com.sun.star.drawing.ControlShape"
476 return new FmFormObj(GetSdrPage()->getSdrModelFromSdrPage());
479 SdrObjKind nType = SdrObjKind::NONE;
480 SdrInventor nInventor;
482 GetTypeAndInventor( nType, nInventor, xShape->getShapeType() );
483 if (nType == SdrObjKind::NONE)
484 return nullptr;
486 awt::Size aSize = xShape->getSize();
487 aSize.Width += 1;
488 aSize.Height += 1;
489 awt::Point aPos = xShape->getPosition();
490 tools::Rectangle aRect( Point( aPos.X, aPos.Y ), Size( aSize.Width, aSize.Height ) );
492 rtl::Reference<SdrObject> pNewObj = SdrObjFactory::MakeNewObject(
493 *mpModel,
494 nInventor,
495 nType,
496 &aRect);
498 if (!pNewObj)
499 return nullptr;
501 if( nType == SdrObjKind::E3D_Scene )
503 auto pScene = static_cast<E3dScene* >(pNewObj.get());
504 // initialise scene
506 double fW = static_cast<double>(aSize.Width);
507 double fH = static_cast<double>(aSize.Height);
509 Camera3D aCam(pScene->GetCamera());
510 aCam.SetAutoAdjustProjection(false);
511 aCam.SetViewWindow(- fW / 2, - fH / 2, fW, fH);
512 basegfx::B3DPoint aLookAt;
513 basegfx::B3DPoint aCamPos(0.0, 0.0, 10000.0);
514 aCam.SetPosAndLookAt(aCamPos, aLookAt);
515 aCam.SetFocalLength(100.0);
516 pScene->SetCamera(aCam);
518 pScene->SetBoundAndSnapRectsDirty();
520 else if(nType == SdrObjKind::E3D_Extrusion)
522 auto pObj = static_cast<E3dExtrudeObj* >(pNewObj.get());
523 basegfx::B2DPolygon aNewPolygon;
524 aNewPolygon.append(basegfx::B2DPoint(0.0, 0.0));
525 aNewPolygon.append(basegfx::B2DPoint(0.0, 1.0));
526 aNewPolygon.append(basegfx::B2DPoint(1.0, 0.0));
527 aNewPolygon.setClosed(true);
528 pObj->SetExtrudePolygon(basegfx::B2DPolyPolygon(aNewPolygon));
530 // #107245# pObj->SetExtrudeCharacterMode(sal_True);
531 pObj->SetMergedItem(Svx3DCharacterModeItem(true));
533 else if(nType == SdrObjKind::E3D_Lathe)
535 auto pLatheObj = static_cast<E3dLatheObj* >(pNewObj.get());
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 pLatheObj->SetPolyPoly2D(basegfx::B2DPolyPolygon(aNewPolygon));
543 // #107245# pObj->SetLatheCharacterMode(sal_True);
544 pLatheObj->SetMergedItem(Svx3DCharacterModeItem(true));
547 return pNewObj;
550 void SvxDrawPage::GetTypeAndInventor( SdrObjKind& rType, SdrInventor& rInventor, const OUString& aName ) noexcept
552 std::optional<SdrObjKind> nTempType = UHashMap::getId( aName );
554 if( !nTempType )
556 if( aName == "com.sun.star.drawing.TableShape" ||
557 aName == "com.sun.star.presentation.TableShape" )
559 rInventor = SdrInventor::Default;
560 rType = SdrObjKind::Table;
562 #if HAVE_FEATURE_AVMEDIA
563 else if ( aName == "com.sun.star.presentation.MediaShape" )
565 rInventor = SdrInventor::Default;
566 rType = SdrObjKind::Media;
568 #endif
570 else if( IsInventorE3D(*nTempType) )
572 rInventor = SdrInventor::E3d;
573 rType = *nTempType;
575 else
577 rInventor = SdrInventor::Default;
578 rType = *nTempType;
580 switch( rType )
582 case SdrObjKind::OLEPluginFrame:
583 case SdrObjKind::OLE2Plugin:
584 case SdrObjKind::OLE2Applet:
585 rType = SdrObjKind::OLE2;
586 break;
587 default:
588 break;
593 rtl::Reference<SvxShape> SvxDrawPage::CreateShapeByTypeAndInventor( SdrObjKind nType, SdrInventor nInventor, SdrObject *pObj, SvxDrawPage *mpPage, OUString const & referer )
595 rtl::Reference<SvxShape> pRet;
597 switch( nInventor )
599 case SdrInventor::FmForm:
601 return new SvxShapeControl( pObj );
603 case SdrInventor::E3d:
605 switch( nType )
607 case SdrObjKind::E3D_Scene :
608 pRet = new Svx3DSceneObject( pObj, mpPage );
609 break;
610 case SdrObjKind::E3D_Cube :
611 pRet = new Svx3DCubeObject( pObj );
612 break;
613 case SdrObjKind::E3D_Sphere :
614 pRet = new Svx3DSphereObject( pObj );
615 break;
616 case SdrObjKind::E3D_Lathe :
617 pRet = new Svx3DLatheObject( pObj );
618 break;
619 case SdrObjKind::E3D_Extrusion :
620 pRet = new Svx3DExtrudeObject( pObj );
621 break;
622 case SdrObjKind::E3D_Polygon :
623 pRet = new Svx3DPolygonObject( pObj );
624 break;
625 default: // unknown 3D-object on page
626 assert(false && "the IsInventor3D function must be wrong");
627 pRet = new SvxShape( pObj );
628 break;
630 break;
632 case SdrInventor::Default:
634 switch( nType )
636 case SdrObjKind::Group:
637 pRet = new SvxShapeGroup( pObj, mpPage );
638 break;
639 case SdrObjKind::Line:
640 pRet = new SvxShapePolyPolygon( pObj );
641 break;
642 case SdrObjKind::Rectangle:
643 case SdrObjKind::Annotation:
644 pRet = new SvxShapeRect( pObj );
645 break;
646 case SdrObjKind::CircleOrEllipse:
647 case SdrObjKind::CircleSection:
648 case SdrObjKind::CircleArc:
649 case SdrObjKind::CircleCut:
650 pRet = new SvxShapeCircle( pObj );
651 break;
652 case SdrObjKind::Polygon:
653 pRet = new SvxShapePolyPolygon( pObj );
654 break;
655 case SdrObjKind::PolyLine:
656 pRet = new SvxShapePolyPolygon( pObj );
657 break;
658 case SdrObjKind::PathLine:
659 pRet = new SvxShapePolyPolygon( pObj );
660 break;
661 case SdrObjKind::PathFill:
662 pRet = new SvxShapePolyPolygon( pObj );
663 break;
664 case SdrObjKind::FreehandLine:
665 pRet = new SvxShapePolyPolygon( pObj );
666 break;
667 case SdrObjKind::FreehandFill:
668 pRet = new SvxShapePolyPolygon( pObj );
669 break;
670 case SdrObjKind::Caption:
671 pRet = new SvxShapeCaption( pObj );
672 break;
673 case SdrObjKind::TitleText:
674 case SdrObjKind::OutlineText:
675 case SdrObjKind::Text:
676 pRet = new SvxShapeText( pObj );
677 break;
678 case SdrObjKind::Graphic:
679 pRet = new SvxGraphicObject( pObj );
680 break;
681 case SdrObjKind::OLEPluginFrame:
682 pRet = new SvxFrameShape( pObj, referer );
683 break;
684 case SdrObjKind::OLE2Applet:
685 pRet = new SvxAppletShape( pObj, referer );
686 break;
687 case SdrObjKind::OLE2Plugin:
688 pRet = new SvxPluginShape( pObj, referer );
689 break;
690 case SdrObjKind::OLE2:
692 if( pObj && !pObj->IsEmptyPresObj() && mpPage )
694 SdrPage* pSdrPage = mpPage->GetSdrPage();
695 if( pSdrPage )
697 SdrModel& rSdrModel(pSdrPage->getSdrModelFromSdrPage());
698 ::comphelper::IEmbeddedHelper *pPersist = rSdrModel.GetPersist();
700 if( pPersist )
702 uno::Reference < embed::XEmbeddedObject > xObject = pPersist->getEmbeddedObjectContainer().
703 GetEmbeddedObject( static_cast< SdrOle2Obj* >( pObj )->GetPersistName() );
705 // TODO CL->KA: Why is this not working anymore?
706 if( xObject.is() )
708 SvGlobalName aClassId( xObject->getClassID() );
710 const SvGlobalName aAppletClassId( SO3_APPLET_CLASSID );
711 const SvGlobalName aPluginClassId( SO3_PLUGIN_CLASSID );
712 const SvGlobalName aIFrameClassId( SO3_IFRAME_CLASSID );
714 if( aPluginClassId == aClassId )
716 pRet = new SvxPluginShape( pObj, referer );
717 nType = SdrObjKind::OLE2Plugin;
719 else if( aAppletClassId == aClassId )
721 pRet = new SvxAppletShape( pObj, referer );
722 nType = SdrObjKind::OLE2Applet;
724 else if( aIFrameClassId == aClassId )
726 pRet = new SvxFrameShape( pObj, referer );
727 nType = SdrObjKind::OLEPluginFrame;
733 if( pRet == nullptr )
735 SvxUnoPropertyMapProvider& rSvxMapProvider = getSvxMapProvider();
736 pRet = new SvxOle2Shape( pObj, referer, rSvxMapProvider.GetMap(SVXMAP_OLE2), rSvxMapProvider.GetPropertySet(SVXMAP_OLE2, SdrObject::GetGlobalDrawObjectItemPool()) );
739 break;
740 case SdrObjKind::Edge:
741 pRet = new SvxShapeConnector( pObj );
742 break;
743 case SdrObjKind::PathPoly:
744 pRet = new SvxShapePolyPolygon( pObj );
745 break;
746 case SdrObjKind::PathPolyLine:
747 pRet = new SvxShapePolyPolygon( pObj );
748 break;
749 case SdrObjKind::Page:
751 SvxUnoPropertyMapProvider& rSvxMapProvider = getSvxMapProvider();
752 pRet = new SvxShape( pObj, rSvxMapProvider.GetMap(SVXMAP_PAGE), rSvxMapProvider.GetPropertySet(SVXMAP_PAGE, SdrObject::GetGlobalDrawObjectItemPool()) );
754 break;
755 case SdrObjKind::Measure:
756 pRet = new SvxShapeDimensioning( pObj );
757 break;
758 case SdrObjKind::UNO:
759 pRet = new SvxShapeControl( pObj );
760 break;
761 case SdrObjKind::CustomShape:
762 pRet = new SvxCustomShape( pObj );
763 break;
764 case SdrObjKind::Media:
765 pRet = new SvxMediaShape( pObj, referer );
766 break;
767 case SdrObjKind::Table:
768 pRet = new SvxTableShape( pObj );
769 break;
770 default: // unknown 2D-object on page
771 assert(false && "Not implemented Starone-Shape created");
772 pRet = new SvxShapeText( pObj );
773 break;
775 break;
777 default: // unknown inventor
779 assert(false && "Unknown Inventor in SvxDrawPage::CreateShape()");
780 break;
784 if(pRet)
786 SdrObjKind nObjId = nType;
788 switch(nObjId)
790 case SdrObjKind::CircleCut: // segment of circle
791 case SdrObjKind::CircleArc: // arc of circle
792 case SdrObjKind::CircleSection: // sector
793 nObjId = SdrObjKind::CircleOrEllipse;
794 break;
796 case SdrObjKind::TitleText:
797 case SdrObjKind::OutlineText:
798 nObjId = SdrObjKind::Text;
799 break;
800 default: ;
803 pRet->setShapeKind(nObjId);
806 return pRet;
809 Reference< drawing::XShape > SvxDrawPage::CreateShape( SdrObject *pObj ) const
811 Reference< drawing::XShape > xShape( CreateShapeByTypeAndInventor(pObj->GetObjIdentifier(),
812 pObj->GetObjInventor(),
813 pObj,
814 const_cast<SvxDrawPage*>(this)));
815 return xShape;
818 rtl::Reference<SdrObject> SvxDrawPage::CreateSdrObject( const Reference< drawing::XShape > & xShape, bool bBeginning ) noexcept
820 rtl::Reference<SdrObject> pObj = CreateSdrObject_( xShape );
821 if( pObj)
823 if ( !pObj->IsInserted() && !pObj->IsDoNotInsertIntoPageAutomatically() )
825 if(bBeginning)
826 mpPage->InsertObject( pObj.get(), 0 );
827 else
828 mpPage->InsertObject( pObj.get() );
832 return pObj;
835 // css::lang::XServiceInfo
836 OUString SAL_CALL SvxDrawPage::getImplementationName()
838 return u"SvxDrawPage"_ustr;
841 sal_Bool SAL_CALL SvxDrawPage::supportsService( const OUString& ServiceName )
843 return cppu::supportsService( this, ServiceName );
846 uno::Sequence< OUString > SAL_CALL SvxDrawPage::getSupportedServiceNames()
848 uno::Sequence<OUString> aSeq { u"com.sun.star.drawing.ShapeCollection"_ustr };
849 return aSeq;
852 rtl::Reference<SvxShape> CreateSvxShapeByTypeAndInventor(SdrObjKind nType, SdrInventor nInventor, OUString const & referer)
854 return SvxDrawPage::CreateShapeByTypeAndInventor( nType, nInventor, nullptr, nullptr, referer );
857 /** returns a StarOffice API wrapper for the given SdrPage */
858 uno::Reference< drawing::XDrawPage > GetXDrawPageForSdrPage( SdrPage* pPage ) noexcept
860 if(pPage)
862 uno::Reference< drawing::XDrawPage > xDrawPage( pPage->getUnoPage(), uno::UNO_QUERY );
864 return xDrawPage;
867 return uno::Reference< drawing::XDrawPage >();
870 /** returns the SdrObject from the given StarOffice API wrapper */
871 SdrPage* GetSdrPageFromXDrawPage( const uno::Reference< drawing::XDrawPage >& xDrawPage ) noexcept
873 if(xDrawPage.is())
875 SvxDrawPage* pDrawPage = comphelper::getFromUnoTunnel<SvxDrawPage>( xDrawPage );
877 if(pDrawPage)
879 return pDrawPage->GetSdrPage();
881 assert(false && "non-SvxDrawPage?");
884 return nullptr;
887 // helper that returns true if the given XShape is member of the given
888 // XDrawPage or it's MasterPage (aka associated)
889 bool IsXShapeAssociatedWithXDrawPage(
890 const css::uno::Reference<css::drawing::XShape>& rxShape,
891 const css::uno::Reference< css::drawing::XDrawPage >& rxDrawPage) noexcept
893 if (!rxShape)
894 return false;
896 if (!rxDrawPage)
897 return false;
899 const SdrObject* pSdrObject(SdrObject::getSdrObjectFromXShape(rxShape));
900 if (nullptr == pSdrObject)
901 return false;
903 SdrPage* pSdrPage(GetSdrPageFromXDrawPage(rxDrawPage));
904 if (nullptr == pSdrPage)
905 return false;
907 const SdrPage* pPageFromObj(pSdrObject->getSdrPageFromSdrObject());
908 if (nullptr == pPageFromObj)
909 return false;
911 if (pSdrPage == pPageFromObj)
912 // given XShape is member of given XDrawPage
913 return true;
915 if (pSdrPage->TRG_HasMasterPage())
916 if (&pSdrPage->TRG_GetMasterPage() == pPageFromObj)
917 // given XShape is member of MasterPage of given XDrawPage
918 return true;
920 return false;
923 // XFormsSupplier
924 css::uno::Reference< css::container::XNameContainer > SAL_CALL SvxDrawPage::getForms()
926 SolarMutexGuard g;
928 css::uno::Reference< css::container::XNameContainer > xForms;
930 FmFormPage *pFmPage = dynamic_cast<FmFormPage*>( GetSdrPage() );
931 if( pFmPage )
932 xForms.set( pFmPage->GetForms(), css::uno::UNO_QUERY_THROW );
934 return xForms;
937 // XFormsSupplier2
938 sal_Bool SAL_CALL SvxDrawPage::hasForms()
940 SolarMutexGuard g;
942 bool bHas = false;
943 FmFormPage* pFormPage = dynamic_cast<FmFormPage*>( GetSdrPage() );
944 if ( pFormPage )
945 bHas = pFormPage->GetForms( false ).is();
946 return bHas;
949 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */