fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / svx / source / unodraw / unopage.cxx
blob97e93817f94bfe1442fc75738f657c749993e6c8
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/lang/DisposedException.hpp>
24 #include <osl/mutex.hxx>
25 #include <sfx2/dispatch.hxx>
26 #include <comphelper/classids.hxx>
27 #include <cppuhelper/supportsservice.hxx>
29 #include <sfx2/objsh.hxx>
30 #include <svx/svdpool.hxx>
31 #include <svx/svdobj.hxx>
32 #include <svx/svdoole2.hxx>
33 #include <svx/svdpage.hxx>
34 #include <svx/svdmodel.hxx>
35 #include <svx/svdstr.hrc>
36 #include <svx/svdview.hxx>
37 #include <svx/svdpagv.hxx>
38 #include <svx/svdundo.hxx>
39 #include <svx/unopage.hxx>
40 #include "shapeimpl.hxx"
41 #include "svdglob.hxx"
42 #include "svx/globl3d.hxx"
43 #include <svx/polysc3d.hxx>
44 #include <svx/unoprov.hxx>
45 #include <svx/svdopath.hxx>
46 #include "svx/unoapi.hxx"
47 #include <svx/svdomeas.hxx>
48 #include <svx/extrud3d.hxx>
49 #include <svx/lathe3d.hxx>
50 #include <vcl/svapp.hxx>
51 #include <tools/diagnose_ex.h>
53 using namespace ::cppu;
54 using namespace ::com::sun::star;
55 using namespace ::com::sun::star::uno;
56 using namespace ::com::sun::star::lang;
57 using namespace ::com::sun::star::container;
58 using namespace ::com::sun::star::drawing;
60 #define INTERFACE_TYPE( xint ) \
61 cppu::UnoType<xint>::get()
63 UNO3_GETIMPLEMENTATION_IMPL( SvxDrawPage );
64 SvxDrawPage::SvxDrawPage( SdrPage* pInPage ) throw()
65 : mrBHelper( getMutex() )
66 , mpPage( pInPage )
67 , mpModel( 0 )
69 // register at broadcaster
70 if( mpPage )
71 mpModel = mpPage->GetModel();
72 if( mpModel )
73 StartListening( *mpModel );
76 // create (hidden) view
77 mpView = new SdrView( mpModel );
78 mpView->SetDesignMode(true);
81 SvxDrawPage::~SvxDrawPage() throw()
83 if( !mrBHelper.bDisposed )
85 SAL_WARN("svx", "SvxDrawPage must be disposed!");
86 acquire();
87 dispose();
91 // XInterface
92 void SvxDrawPage::release() throw()
94 OWeakAggObject::release();
97 // XComponent
98 void SvxDrawPage::disposing() throw()
100 if( mpModel )
102 EndListening( *mpModel );
103 mpModel = NULL;
106 if( mpView )
108 delete mpView;
109 mpView = NULL;
111 mpPage = 0;
114 // XComponent
115 void SvxDrawPage::dispose()
116 throw(::com::sun::star::uno::RuntimeException, std::exception)
118 SolarMutexGuard aSolarGuard;
120 // An frequently programming error is to release the last
121 // reference to this object in the disposing message.
122 // Make it rubust, hold a self Reference.
123 uno::Reference< lang::XComponent > xSelf( this );
125 // Guard dispose against multible threading
126 // Remark: It is an error to call dispose more than once
127 bool bDoDispose = false;
129 osl::MutexGuard aGuard( mrBHelper.rMutex );
130 if( !mrBHelper.bDisposed && !mrBHelper.bInDispose )
132 // only one call go into this section
133 mrBHelper.bInDispose = sal_True;
134 bDoDispose = true;
138 // Do not hold the mutex because we are broadcasting
139 if( bDoDispose )
141 // Create an event with this as sender
144 uno::Reference< uno::XInterface > xSource( uno::Reference< uno::XInterface >::query( (lang::XComponent *)this ) );
145 ::com::sun::star::document::EventObject aEvt;
146 aEvt.Source = xSource;
147 // inform all listeners to release this object
148 // The listener container are automatically cleared
149 mrBHelper.aLC.disposeAndClear( aEvt );
150 // notify subclasses to do their dispose
151 disposing();
153 catch(const ::com::sun::star::uno::Exception&)
155 // catch exception and throw again but signal that
156 // the object was disposed. Dispose should be called
157 // only once.
158 mrBHelper.bDisposed = sal_True;
159 mrBHelper.bInDispose = sal_False;
160 throw;
163 // the values bDispose and bInDisposing must set in this order.
164 // No multithread call overcome the "!rBHelper.bDisposed && !rBHelper.bInDispose" guard.
165 mrBHelper.bDisposed = sal_True;
166 mrBHelper.bInDispose = sal_False;
171 void SAL_CALL SvxDrawPage::addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw(::com::sun::star::uno::RuntimeException, std::exception)
173 SolarMutexGuard aGuard;
175 if( mpModel == 0 )
176 throw lang::DisposedException();
178 mrBHelper.addListener( cppu::UnoType<decltype(aListener)>::get() , aListener );
181 void SAL_CALL SvxDrawPage::removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw(::com::sun::star::uno::RuntimeException, std::exception)
183 SolarMutexGuard aGuard;
185 if( mpModel == 0 )
186 throw lang::DisposedException();
188 mrBHelper.removeListener( cppu::UnoType<decltype(aListener)>::get() , aListener );
191 // SfxListener
192 void SvxDrawPage::Notify( SfxBroadcaster&, const SfxHint& /*rHint*/ )
196 void SAL_CALL SvxDrawPage::add( const uno::Reference< drawing::XShape >& xShape )
197 throw( uno::RuntimeException, std::exception )
199 SolarMutexGuard aGuard;
201 if ( ( mpModel == NULL ) || ( mpPage == NULL ) )
202 throw lang::DisposedException();
204 SvxShape* pShape = SvxShape::getImplementation( xShape );
206 if( NULL == pShape )
207 return;
209 SdrObject *pObj = pShape->GetSdrObject();
211 if(!pObj)
213 pObj = CreateSdrObject( xShape );
214 ENSURE_OR_RETURN_VOID( pObj != NULL, "SvxDrawPage::add: no SdrObject was created!" );
216 else if ( !pObj->IsInserted() )
218 pObj->SetModel(mpModel);
219 mpPage->InsertObject( pObj );
222 pShape->Create( pObj, this );
223 OSL_ENSURE( pShape->GetSdrObject() == pObj, "SvxDrawPage::add: shape does not know about its newly created SdrObject!" );
225 if ( !pObj->IsInserted() )
227 pObj->SetModel(mpModel);
228 mpPage->InsertObject( pObj );
231 mpModel->SetChanged();
234 void SAL_CALL SvxDrawPage::addTop( const uno::Reference< drawing::XShape >& xShape )
235 throw( uno::RuntimeException, std::exception )
237 add(xShape);
240 void SAL_CALL SvxDrawPage::addBottom( const uno::Reference< drawing::XShape >& xShape )
241 throw( uno::RuntimeException, std::exception )
243 SolarMutexGuard aGuard;
245 if ( ( mpModel == NULL ) || ( mpPage == NULL ) )
246 throw lang::DisposedException();
248 SvxShape* pShape = SvxShape::getImplementation( xShape );
250 if( NULL == pShape )
251 return;
253 SdrObject *pObj = pShape->GetSdrObject();
255 if(!pObj)
257 pObj = CreateSdrObject( xShape, true );
258 ENSURE_OR_RETURN_VOID( pObj != NULL, "SvxDrawPage::add: no SdrObject was created!" );
260 else if ( !pObj->IsInserted() )
262 pObj->SetModel(mpModel);
263 mpPage->InsertObject( pObj, 0 );
266 pShape->Create( pObj, this );
267 OSL_ENSURE( pShape->GetSdrObject() == pObj, "SvxDrawPage::add: shape does not know about its newly created SdrObject!" );
269 if ( !pObj->IsInserted() )
271 pObj->SetModel(mpModel);
272 mpPage->InsertObject( pObj, 0 );
275 mpModel->SetChanged();
278 void SAL_CALL SvxDrawPage::remove( const Reference< drawing::XShape >& xShape )
279 throw (uno::RuntimeException, std::exception)
281 SolarMutexGuard aGuard;
283 if( (mpModel == 0) || (mpPage == 0) )
284 throw lang::DisposedException();
286 SvxShape* pShape = SvxShape::getImplementation( xShape );
288 if (pShape)
290 SdrObject* pObj = pShape->GetSdrObject();
291 if (pObj)
293 // remove SdrObject from page
294 const size_t nCount = mpPage->GetObjCount();
295 for( size_t nNum = 0; nNum < nCount; ++nNum )
297 if(mpPage->GetObj(nNum) == pObj)
299 const bool bUndoEnabled = mpModel->IsUndoEnabled();
301 if (bUndoEnabled)
303 mpModel->BegUndo(ImpGetResStr(STR_EditDelete),
304 pObj->TakeObjNameSingul(), SDRREPFUNC_OBJ_DELETE);
306 SdrUndoAction * pAction = mpModel->GetSdrUndoFactory().CreateUndoDeleteObject(*pObj);
307 mpModel->AddUndo(pAction);
310 OSL_VERIFY( mpPage->RemoveObject( nNum ) == pObj );
312 if (!bUndoEnabled)
313 SdrObject::Free(pObj);
315 if (bUndoEnabled)
316 mpModel->EndUndo();
318 break;
324 mpModel->SetChanged();
327 // ::com::sun::star::container::XIndexAccess
328 sal_Int32 SAL_CALL SvxDrawPage::getCount()
329 throw( uno::RuntimeException, std::exception )
331 SolarMutexGuard aGuard;
333 if( (mpModel == 0) || (mpPage == 0) )
334 throw lang::DisposedException();
336 return static_cast<sal_Int32>( mpPage->GetObjCount() );
339 uno::Any SAL_CALL SvxDrawPage::getByIndex( sal_Int32 Index )
340 throw( lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
342 SolarMutexGuard aGuard;
344 if( (mpModel == 0) || (mpPage == 0) )
345 throw lang::DisposedException();
347 if ( Index < 0 || static_cast<size_t>(Index) >= mpPage->GetObjCount() )
348 throw lang::IndexOutOfBoundsException();
350 SdrObject* pObj = mpPage->GetObj( Index );
351 if( pObj == NULL )
352 throw uno::RuntimeException();
355 return makeAny(Reference< drawing::XShape >( pObj->getUnoShape(), uno::UNO_QUERY ));
358 // ::com::sun::star::container::XElementAccess
359 uno::Type SAL_CALL SvxDrawPage::getElementType()
360 throw( uno::RuntimeException, std::exception )
362 return INTERFACE_TYPE( drawing::XShape );
365 sal_Bool SAL_CALL SvxDrawPage::hasElements()
366 throw( uno::RuntimeException, std::exception )
368 SolarMutexGuard aGuard;
370 if( (mpModel == 0) || (mpPage == 0) )
371 throw lang::DisposedException();
373 return mpPage && mpPage->GetObjCount()>0;
376 namespace
378 void lcl_markSdrObjectOfShape( const Reference< drawing::XShape >& _rxShape, SdrView& _rView, SdrPageView& _rPageView )
380 SvxShape* pShape = SvxShape::getImplementation( _rxShape );
381 if ( !pShape )
382 return;
384 SdrObject* pObj = pShape->GetSdrObject();
385 if ( !pObj )
386 return;
388 _rView.MarkObj( pObj, &_rPageView );
392 // ATTENTION: _SelectObjectsInView selects the ::com::sun::star::drawing::Shapes
393 // only in the given SdrPageView. It hasn't to be the visible SdrPageView.
394 void SvxDrawPage::_SelectObjectsInView( const Reference< drawing::XShapes > & aShapes, SdrPageView* pPageView ) throw ()
396 SAL_WARN_IF(!pPageView, "svx", "SdrPageView is NULL!");
397 SAL_WARN_IF(!mpView, "svx", "SdrView is NULL!");
399 if(pPageView!=NULL && mpView!=NULL)
401 mpView->UnmarkAllObj( pPageView );
403 long nCount = aShapes->getCount();
404 for( long i = 0; i < nCount; i++ )
406 uno::Any aAny( aShapes->getByIndex(i) );
407 Reference< drawing::XShape > xShape;
408 if( aAny >>= xShape )
409 lcl_markSdrObjectOfShape( xShape, *mpView, *pPageView );
414 // ATTENTION: _SelectObjectInView selects the shape only in the given SdrPageView.
415 // It hasn't to be the visible SdrPageView.
416 void SvxDrawPage::_SelectObjectInView( const Reference< drawing::XShape > & xShape, SdrPageView* pPageView ) throw()
418 SAL_WARN_IF(!pPageView, "svx", "SdrPageView is NULL!");
419 SAL_WARN_IF(!mpView, "svx", "SdrView is NULL!");
421 if(pPageView!=NULL && mpView != NULL)
423 mpView->UnmarkAllObj( pPageView );
424 lcl_markSdrObjectOfShape( xShape, *mpView, *pPageView );
428 Reference< drawing::XShapeGroup > SAL_CALL SvxDrawPage::group( const Reference< drawing::XShapes >& xShapes )
429 throw( uno::RuntimeException, std::exception )
431 SolarMutexGuard aGuard;
433 if( (mpModel == 0) || (mpPage == 0) )
434 throw lang::DisposedException();
436 SAL_WARN_IF(!mpPage , "svx", "SdrPage is NULL!");
437 SAL_WARN_IF(!mpView, "svx", "SdrView is NULL!");
439 Reference< ::com::sun::star::drawing::XShapeGroup > xShapeGroup;
440 if(mpPage==NULL||mpView==NULL||!xShapes.is())
441 return xShapeGroup;
443 SdrPageView* pPageView = mpView->ShowSdrPage( mpPage );
445 _SelectObjectsInView( xShapes, pPageView );
447 mpView->GroupMarked();
449 mpView->AdjustMarkHdl();
450 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
451 if( rMarkList.GetMarkCount() == 1 )
453 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
454 if( pObj )
455 xShapeGroup = Reference< drawing::XShapeGroup >::query( pObj->getUnoShape() );
458 mpView->HideSdrPage();
460 if( mpModel )
461 mpModel->SetChanged();
463 return xShapeGroup;
466 void SAL_CALL SvxDrawPage::ungroup( const Reference< drawing::XShapeGroup >& aGroup )
467 throw( uno::RuntimeException, std::exception )
469 SolarMutexGuard aGuard;
471 if( (mpModel == 0) || (mpPage == 0) )
472 throw lang::DisposedException();
474 SAL_WARN_IF(!mpPage, "svx", "SdrPage is NULL!");
475 SAL_WARN_IF(!mpView, "svx", "SdrView is NULL!");
477 if(mpPage==NULL||mpView==NULL||!aGroup.is())
478 return;
480 SdrPageView* pPageView = mpView->ShowSdrPage( mpPage );
482 Reference< drawing::XShape > xShape( aGroup, UNO_QUERY );
483 _SelectObjectInView( xShape, pPageView );
484 mpView->UnGroupMarked();
486 mpView->HideSdrPage();
488 if( mpModel )
489 mpModel->SetChanged();
492 SdrObject *SvxDrawPage::_CreateSdrObject(const Reference< drawing::XShape > & xShape)
493 throw (css::uno::RuntimeException, std::exception)
495 sal_uInt16 nType = 0;
496 sal_uInt32 nInventor = 0;
498 GetTypeAndInventor( nType, nInventor, xShape->getShapeType() );
499 if (!nType)
500 return NULL;
502 awt::Size aSize = xShape->getSize();
503 aSize.Width += 1;
504 aSize.Height += 1;
505 awt::Point aPos = xShape->getPosition();
506 Rectangle aRect( Point( aPos.X, aPos.Y ), Size( aSize.Width, aSize.Height ) );
508 SdrObject* pNewObj = SdrObjFactory::MakeNewObject(nInventor, nType, aRect, mpPage);
509 if (!pNewObj)
510 return NULL;
512 if( pNewObj->ISA(E3dPolyScene))
514 // initialise scene
515 E3dScene* pScene = static_cast<E3dScene*>(pNewObj);
517 double fW = (double)aSize.Width;
518 double fH = (double)aSize.Height;
520 Camera3D aCam(pScene->GetCamera());
521 aCam.SetAutoAdjustProjection(false);
522 aCam.SetViewWindow(- fW / 2, - fH / 2, fW, fH);
523 basegfx::B3DPoint aLookAt;
524 basegfx::B3DPoint aCamPos(0.0, 0.0, 10000.0);
525 aCam.SetPosAndLookAt(aCamPos, aLookAt);
526 aCam.SetFocalLength(100.0);
527 aCam.SetDefaults(aCamPos, aLookAt, 10000.0);
528 pScene->SetCamera(aCam);
530 pScene->SetRectsDirty();
532 else if(pNewObj->ISA(E3dExtrudeObj))
534 E3dExtrudeObj* pObj = static_cast<E3dExtrudeObj*>(pNewObj);
535 basegfx::B2DPolygon aNewPolygon;
536 aNewPolygon.append(basegfx::B2DPoint(0.0, 0.0));
537 aNewPolygon.append(basegfx::B2DPoint(0.0, 1.0));
538 aNewPolygon.append(basegfx::B2DPoint(1.0, 0.0));
539 aNewPolygon.setClosed(true);
540 pObj->SetExtrudePolygon(basegfx::B2DPolyPolygon(aNewPolygon));
542 // #107245# pObj->SetExtrudeCharacterMode(sal_True);
543 pObj->SetMergedItem(Svx3DCharacterModeItem(true));
545 else if(pNewObj->ISA(E3dLatheObj))
547 E3dLatheObj* pObj = static_cast<E3dLatheObj*>(pNewObj);
548 basegfx::B2DPolygon aNewPolygon;
549 aNewPolygon.append(basegfx::B2DPoint(0.0, 0.0));
550 aNewPolygon.append(basegfx::B2DPoint(0.0, 1.0));
551 aNewPolygon.append(basegfx::B2DPoint(1.0, 0.0));
552 aNewPolygon.setClosed(true);
553 pObj->SetPolyPoly2D(basegfx::B2DPolyPolygon(aNewPolygon));
555 // #107245# pObj->SetLatheCharacterMode(sal_True);
556 pObj->SetMergedItem(Svx3DCharacterModeItem(true));
559 return pNewObj;
562 void SvxDrawPage::GetTypeAndInventor( sal_uInt16& rType, sal_uInt32& rInventor, const OUString& aName ) throw()
564 sal_uInt32 nTempType = UHashMap::getId( aName );
566 if( nTempType == UHASHMAP_NOTFOUND )
568 if( aName == "com.sun.star.drawing.TableShape" ||
569 aName == "com.sun.star.presentation.TableShape" )
571 rInventor = SdrInventor;
572 rType = OBJ_TABLE;
574 #if HAVE_FEATURE_AVMEDIA
575 else if ( aName == "com.sun.star.presentation.MediaShape" )
577 rInventor = SdrInventor;
578 rType = OBJ_MEDIA;
580 #endif
582 else if(nTempType & E3D_INVENTOR_FLAG)
584 rInventor = E3dInventor;
585 rType = (sal_uInt16)(nTempType & ~E3D_INVENTOR_FLAG);
587 else
589 rInventor = SdrInventor;
590 rType = (sal_uInt16)nTempType;
592 switch( rType )
594 case OBJ_FRAME:
595 case OBJ_OLE2_PLUGIN:
596 case OBJ_OLE2_APPLET:
597 rType = OBJ_OLE2;
598 break;
603 SvxShape* SvxDrawPage::CreateShapeByTypeAndInventor( sal_uInt16 nType, sal_uInt32 nInventor, SdrObject *pObj, SvxDrawPage *mpPage, OUString const & referer )
604 throw (css::uno::RuntimeException)
606 SvxShape* pRet = NULL;
607 switch( nInventor )
609 case E3dInventor:
611 switch( nType )
613 case E3D_SCENE_ID :
614 case E3D_POLYSCENE_ID :
615 pRet = new Svx3DSceneObject( pObj, mpPage );
616 break;
617 case E3D_CUBEOBJ_ID :
618 pRet = new Svx3DCubeObject( pObj );
619 break;
620 case E3D_SPHEREOBJ_ID :
621 pRet = new Svx3DSphereObject( pObj );
622 break;
623 case E3D_LATHEOBJ_ID :
624 pRet = new Svx3DLatheObject( pObj );
625 break;
626 case E3D_EXTRUDEOBJ_ID :
627 pRet = new Svx3DExtrudeObject( pObj );
628 break;
629 case E3D_POLYGONOBJ_ID :
630 pRet = new Svx3DPolygonObject( pObj );
631 break;
632 default: // unknown 3D-object on page
633 pRet = new SvxShape( pObj );
634 break;
636 break;
638 case SdrInventor:
640 switch( nType )
642 case OBJ_GRUP:
643 pRet = new SvxShapeGroup( pObj, mpPage );
644 break;
645 case OBJ_LINE:
646 pRet = new SvxShapePolyPolygon( pObj , PolygonKind_LINE );
647 break;
648 case OBJ_RECT:
649 pRet = new SvxShapeRect( pObj );
650 break;
651 case OBJ_CIRC:
652 case OBJ_SECT:
653 case OBJ_CARC:
654 case OBJ_CCUT:
655 pRet = new SvxShapeCircle( pObj );
656 break;
657 case OBJ_POLY:
658 pRet = new SvxShapePolyPolygon( pObj , PolygonKind_POLY );
659 break;
660 case OBJ_PLIN:
661 pRet = new SvxShapePolyPolygon( pObj , PolygonKind_PLIN );
662 break;
663 case OBJ_SPLNLINE:
664 case OBJ_PATHLINE:
665 pRet = new SvxShapePolyPolygonBezier( pObj , PolygonKind_PATHLINE );
666 break;
667 case OBJ_SPLNFILL:
668 case OBJ_PATHFILL:
669 pRet = new SvxShapePolyPolygonBezier( pObj , PolygonKind_PATHFILL );
670 break;
671 case OBJ_FREELINE:
672 pRet = new SvxShapePolyPolygonBezier( pObj , PolygonKind_FREELINE );
673 break;
674 case OBJ_FREEFILL:
675 pRet = new SvxShapePolyPolygonBezier( pObj , PolygonKind_FREEFILL );
676 break;
677 case OBJ_CAPTION:
678 pRet = new SvxShapeCaption( pObj );
679 break;
680 case OBJ_TITLETEXT:
681 case OBJ_OUTLINETEXT:
682 case OBJ_TEXT:
683 pRet = new SvxShapeText( pObj );
684 break;
685 case OBJ_GRAF:
686 pRet = new SvxGraphicObject( pObj, referer );
687 break;
688 case OBJ_FRAME:
689 pRet = new SvxFrameShape( pObj );
690 break;
691 case OBJ_OLE2_APPLET:
692 pRet = new SvxAppletShape( pObj );
693 break;
694 case OBJ_OLE2_PLUGIN:
695 pRet = new SvxPluginShape( pObj );
696 break;
697 case OBJ_OLE2:
699 if( pObj && !pObj->IsEmptyPresObj() && mpPage )
701 SdrPage* pSdrPage = mpPage->GetSdrPage();
702 if( pSdrPage )
704 SdrModel* pSdrModel = pSdrPage->GetModel();
705 if( pSdrModel )
707 ::comphelper::IEmbeddedHelper *pPersist = pSdrModel->GetPersist();
708 if( pPersist )
710 uno::Reference < embed::XEmbeddedObject > xObject = pPersist->getEmbeddedObjectContainer().
711 GetEmbeddedObject( static_cast< SdrOle2Obj* >( pObj )->GetPersistName() );
713 // TODO CL->KA: Why is this not working anymore?
714 if( xObject.is() )
716 SvGlobalName aClassId( xObject->getClassID() );
718 const SvGlobalName aAppletClassId( SO3_APPLET_CLASSID );
719 const SvGlobalName aPluginClassId( SO3_PLUGIN_CLASSID );
720 const SvGlobalName aIFrameClassId( SO3_IFRAME_CLASSID );
722 if( aPluginClassId == aClassId )
724 pRet = new SvxPluginShape( pObj );
725 nType = OBJ_OLE2_PLUGIN;
727 else if( aAppletClassId == aClassId )
729 pRet = new SvxAppletShape( pObj );
730 nType = OBJ_OLE2_APPLET;
732 else if( aIFrameClassId == aClassId )
734 pRet = new SvxFrameShape( pObj );
735 nType = OBJ_FRAME;
742 if( pRet == NULL )
744 SvxUnoPropertyMapProvider& rSvxMapProvider = getSvxMapProvider();
745 pRet = new SvxOle2Shape( pObj, rSvxMapProvider.GetMap(SVXMAP_OLE2), rSvxMapProvider.GetPropertySet(SVXMAP_OLE2, SdrObject::GetGlobalDrawObjectItemPool()) );
748 break;
749 case OBJ_EDGE:
750 pRet = new SvxShapeConnector( pObj );
751 break;
752 case OBJ_PATHPOLY:
753 pRet = new SvxShapePolyPolygon( pObj , PolygonKind_PATHPOLY );
754 break;
755 case OBJ_PATHPLIN:
756 pRet = new SvxShapePolyPolygon( pObj , PolygonKind_PATHPLIN );
757 break;
758 case OBJ_PAGE:
760 SvxUnoPropertyMapProvider& rSvxMapProvider = getSvxMapProvider();
761 pRet = new SvxShape( pObj, rSvxMapProvider.GetMap(SVXMAP_PAGE), rSvxMapProvider.GetPropertySet(SVXMAP_PAGE, SdrObject::GetGlobalDrawObjectItemPool()) );
763 break;
764 case OBJ_MEASURE:
765 pRet = new SvxShapeDimensioning( pObj );
766 break;
767 case OBJ_UNO:
768 pRet = new SvxShapeControl( pObj );
769 break;
770 case OBJ_CUSTOMSHAPE:
771 pRet = new SvxCustomShape( pObj );
772 break;
773 #if HAVE_FEATURE_DESKTOP
774 case OBJ_MEDIA:
775 pRet = new SvxMediaShape( pObj, referer );
776 break;
777 #endif
778 case OBJ_TABLE:
779 pRet = new SvxTableShape( pObj );
780 break;
781 case OBJ_OPENGL:
782 pRet = new SvxOpenGLObject( pObj );
783 break;
784 default: // unknown 2D-object on page
785 OSL_FAIL("Not implemented Starone-Shape created! [CL]");
786 pRet = new SvxShapeText( pObj );
787 break;
789 break;
791 default: // unknown inventor
793 OSL_FAIL("AW: Unknown Inventor in SvxDrawPage::_CreateShape()");
794 break;
798 if(pRet)
800 sal_uInt32 nObjId = nType;
802 if( nInventor == E3dInventor )
803 nObjId |= E3D_INVENTOR_FLAG;
805 switch(nObjId)
807 case OBJ_CCUT: // segment of circle
808 case OBJ_CARC: // arc of circle
809 case OBJ_SECT: // sector
810 nObjId = OBJ_CIRC;
811 break;
813 case E3D_SCENE_ID | E3D_INVENTOR_FLAG:
814 nObjId = E3D_POLYSCENE_ID | E3D_INVENTOR_FLAG;
815 break;
817 case OBJ_TITLETEXT:
818 case OBJ_OUTLINETEXT:
819 nObjId = OBJ_TEXT;
820 break;
823 pRet->setShapeKind(nObjId);
826 return pRet;
829 Reference< drawing::XShape > SvxDrawPage::_CreateShape( SdrObject *pObj ) const
830 throw (css::uno::RuntimeException, std::exception)
832 Reference< drawing::XShape > xShape( CreateShapeByTypeAndInventor(pObj->GetObjIdentifier(),
833 pObj->GetObjInventor(),
834 pObj,
835 const_cast<SvxDrawPage*>(this)));
836 return xShape;
839 SdrObject *SvxDrawPage::CreateSdrObject( const Reference< drawing::XShape > & xShape, bool bBeginning ) throw()
841 SdrObject* pObj = _CreateSdrObject( xShape );
842 if( pObj)
844 pObj->SetModel(mpModel);
845 if ( !pObj->IsInserted() && !pObj->IsDoNotInsertIntoPageAutomatically() )
847 if(bBeginning)
848 mpPage->InsertObject( pObj, 0 );
849 else
850 mpPage->InsertObject( pObj );
854 return pObj;
857 // ::com::sun::star::lang::XServiceInfo
858 OUString SAL_CALL SvxDrawPage::getImplementationName() throw( uno::RuntimeException, std::exception )
860 return OUString("SvxDrawPage");
863 sal_Bool SAL_CALL SvxDrawPage::supportsService( const OUString& ServiceName )
864 throw(::com::sun::star::uno::RuntimeException, std::exception)
866 return cppu::supportsService( this, ServiceName );
869 uno::Sequence< OUString > SAL_CALL SvxDrawPage::getSupportedServiceNames() throw( uno::RuntimeException, std::exception )
871 uno::Sequence< OUString > aSeq( 1 );
872 aSeq.getArray()[0] = "com.sun.star.drawing.ShapeCollection";
873 return aSeq;
876 SvxShape* CreateSvxShapeByTypeAndInventor(sal_uInt16 nType, sal_uInt32 nInventor, OUString const & referer)
877 throw (css::uno::RuntimeException, std::exception)
879 return SvxDrawPage::CreateShapeByTypeAndInventor( nType, nInventor, 0, 0, referer );
882 void SvxDrawPage::ChangeModel( SdrModel* pNewModel )
884 if( pNewModel != mpModel )
886 if( mpModel )
887 EndListening( *mpModel );
889 if( pNewModel )
890 StartListening( *pNewModel );
892 mpModel = pNewModel;
894 if( mpView )
896 delete mpView;
897 mpView = new SdrView( mpModel );
898 mpView->SetDesignMode(true);
903 /** returns a StarOffice API wrapper for the given SdrPage */
904 uno::Reference< drawing::XDrawPage > GetXDrawPageForSdrPage( SdrPage* pPage ) throw ()
906 if(pPage)
908 uno::Reference< drawing::XDrawPage > xDrawPage( pPage->getUnoPage(), uno::UNO_QUERY );
910 return xDrawPage;
913 return uno::Reference< drawing::XDrawPage >();
916 /** returns the SdrObject from the given StarOffice API wrapper */
917 SdrPage* GetSdrPageFromXDrawPage( uno::Reference< drawing::XDrawPage > xDrawPage ) throw()
919 if(xDrawPage.is())
921 SvxDrawPage* pDrawPage = SvxDrawPage::getImplementation( xDrawPage );
923 if(pDrawPage)
925 return pDrawPage->GetSdrPage();
929 return NULL;
932 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */