merge the formfield patch from ooo-build
[ooovba.git] / svx / source / unodraw / unopage.cxx
blob5bfeb3a3bf9de768a26021fda57bdbfd746ee989
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unopage.cxx,v $
10 * $Revision: 1.50.18.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #define _SVX_USE_UNOGLOBALS_
35 #include <com/sun/star/document/EventObject.hpp>
36 #include <com/sun/star/lang/DisposedException.hpp>
37 #include <vos/mutex.hxx>
38 #include <osl/mutex.hxx>
39 #include <sfx2/dispatch.hxx>
40 #include <sot/clsids.hxx>
42 #include <rtl/uuid.h>
43 #include <rtl/memory.h>
44 #include <sfx2/objsh.hxx>
46 #include <svx/svdobj.hxx>
47 #include <svx/svdoole2.hxx>
48 #include <svx/svdpage.hxx>
49 #include <svx/svdmodel.hxx>
50 #include <svx/svdview.hxx>
51 #include <svx/svdpagv.hxx>
52 #include <svx/unopage.hxx>
53 #include "shapeimpl.hxx"
54 #include "globl3d.hxx"
55 #include <svx/polysc3d.hxx>
56 #include <svx/unoprov.hxx>
57 #include <svx/svdopath.hxx>
58 #include "unoapi.hxx"
59 #include <svx/svdomeas.hxx>
60 #include <svx/extrud3d.hxx>
61 #include <svx/lathe3d.hxx>
62 #include <vcl/svapp.hxx>
64 using ::rtl::OUString;
65 using namespace ::vos;
66 using namespace ::cppu;
67 using namespace ::com::sun::star;
68 using namespace ::com::sun::star::uno;
69 using namespace ::com::sun::star::lang;
70 using namespace ::com::sun::star::container;
71 using namespace ::com::sun::star::drawing;
73 #define INTERFACE_TYPE( xint ) \
74 ::getCppuType((const Reference< xint >*)0)
76 #define QUERYINT( xint ) \
77 if( rType == ::getCppuType((const Reference< xint >*)0) ) \
78 aAny <<= Reference< xint >(this)
80 DECLARE_LIST( SvxDrawPageList, SvxDrawPage * )
83 /**********************************************************************
84 * class SvxDrawPage *
85 **********************************************************************/
87 UNO3_GETIMPLEMENTATION_IMPL( SvxDrawPage );
88 DBG_NAME(SvxDrawPage)
89 SvxDrawPage::SvxDrawPage( SdrPage* pInPage ) throw()
90 : mrBHelper( getMutex() )
91 , mpPage( pInPage )
92 , mpModel( 0 )
94 DBG_CTOR(SvxDrawPage,NULL);
95 // Am Broadcaster anmelden
96 if( mpPage )
97 mpModel = mpPage->GetModel();
98 if( mpModel )
99 StartListening( *mpModel );
102 // Erzeugen der (hidden) ::com::sun::star::sdbcx::View
103 mpView = new SdrView( mpModel );
104 if( mpView )
105 mpView->SetDesignMode(sal_True);
108 //----------------------------------------------------------------------
109 // Ctor fuer SvxDrawPage_NewInstance()
110 //----------------------------------------------------------------------
111 SvxDrawPage::SvxDrawPage() throw()
112 : mrBHelper( getMutex() )
113 , mpPage( NULL )
114 , mpModel( NULL )
115 , mpView( NULL )
117 DBG_CTOR(SvxDrawPage,NULL);
120 //----------------------------------------------------------------------
121 SvxDrawPage::~SvxDrawPage() throw()
123 DBG_ASSERT( mrBHelper.bDisposed, "SvxDrawPage must be disposed!" );
124 if( !mrBHelper.bDisposed )
126 acquire();
127 dispose();
129 DBG_DTOR(SvxDrawPage,NULL);
132 //----------------------------------------------------------------------
134 // XInterface
135 void SvxDrawPage::release() throw()
138 uno::Reference< uno::XInterface > x( xDelegator );
139 if (! x.is())
141 if (osl_decrementInterlockedCount( &m_refCount ) == 0)
143 if (! mrBHelper.bDisposed)
145 uno::Reference< uno::XInterface > xHoldAlive( (uno::XWeak*)this );
146 // First dispose
149 dispose();
151 catch(::com::sun::star::uno::Exception&)
153 // release should not throw exceptions
156 // only the alive ref holds the object
157 OSL_ASSERT( m_refCount == 1 );
158 // destroy the object if xHoldAlive decrement the refcount to 0
159 return;
162 // restore the reference count
163 osl_incrementInterlockedCount( &m_refCount );
166 OWeakAggObject::release();
169 //----------------------------------------------------------------------
171 SvxDrawPage* SvxDrawPage::GetPageForSdrPage( SdrPage* mpPage ) throw()
173 return getImplementation( mpPage->getUnoPage() );
176 // XComponent
177 void SvxDrawPage::disposing() throw()
179 if( mpModel )
181 EndListening( *mpModel );
182 mpModel = NULL;
185 if( mpView )
187 delete mpView;
188 mpView = NULL;
190 mpPage = 0;
193 //----------------------------------------------------------------------
194 // XComponent
195 //----------------------------------------------------------------------
197 void SvxDrawPage::dispose()
198 throw(::com::sun::star::uno::RuntimeException)
200 OGuard aSolarGuard( Application::GetSolarMutex() );
202 // An frequently programming error is to release the last
203 // reference to this object in the disposing message.
204 // Make it rubust, hold a self Reference.
205 uno::Reference< lang::XComponent > xSelf( this );
207 // Guard dispose against multible threading
208 // Remark: It is an error to call dispose more than once
209 sal_Bool bDoDispose = sal_False;
211 osl::MutexGuard aGuard( mrBHelper.rMutex );
212 if( !mrBHelper.bDisposed && !mrBHelper.bInDispose )
214 // only one call go into this section
215 mrBHelper.bInDispose = sal_True;
216 bDoDispose = sal_True;
220 // Do not hold the mutex because we are broadcasting
221 if( bDoDispose )
223 // Create an event with this as sender
226 uno::Reference< uno::XInterface > xSource( uno::Reference< uno::XInterface >::query( (lang::XComponent *)this ) );
227 ::com::sun::star::document::EventObject aEvt;
228 aEvt.Source = xSource;
229 // inform all listeners to release this object
230 // The listener container are automaticly cleared
231 mrBHelper.aLC.disposeAndClear( aEvt );
232 // notify subclasses to do their dispose
233 disposing();
235 catch(::com::sun::star::uno::Exception& e)
237 // catch exception and throw again but signal that
238 // the object was disposed. Dispose should be called
239 // only once.
240 mrBHelper.bDisposed = sal_True;
241 mrBHelper.bInDispose = sal_False;
242 throw e;
245 // the values bDispose and bInDisposing must set in this order.
246 // No multithread call overcome the "!rBHelper.bDisposed && !rBHelper.bInDispose" guard.
247 mrBHelper.bDisposed = sal_True;
248 mrBHelper.bInDispose = sal_False;
253 //----------------------------------------------------------------------
255 void SAL_CALL SvxDrawPage::addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw(::com::sun::star::uno::RuntimeException)
257 OGuard aGuard( Application::GetSolarMutex() );
259 if( mpModel == 0 )
260 throw lang::DisposedException();
262 mrBHelper.addListener( ::getCppuType( &aListener ) , aListener );
265 //----------------------------------------------------------------------
267 void SAL_CALL SvxDrawPage::removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw(::com::sun::star::uno::RuntimeException)
269 OGuard aGuard( Application::GetSolarMutex() );
271 if( mpModel == 0 )
272 throw lang::DisposedException();
274 mrBHelper.removeListener( ::getCppuType( &aListener ) , aListener );
277 //----------------------------------------------------------------------
278 // SfxListener
279 //----------------------------------------------------------------------
281 void SvxDrawPage::Notify( SfxBroadcaster&, const SfxHint& /*rHint*/ )
284 if( mpModel )
286 const SdrHint* pSdrHint = PTR_CAST( SdrHint, &rHint );
287 if( pSdrHint )
289 switch( pSdrHint->GetKind() )
291 case HINT_MODELCLEARED:
292 dispose();
293 break;
294 default:
295 break;
302 //----------------------------------------------------------------------
303 // ::com::sun::star::drawing::XShapes
304 //----------------------------------------------------------------------
306 void SAL_CALL SvxDrawPage::add( const uno::Reference< drawing::XShape >& xShape )
307 throw( uno::RuntimeException )
309 OGuard aGuard( Application::GetSolarMutex() );
311 if( (mpModel == 0) || (mpPage == 0) )
312 throw lang::DisposedException();
314 SvxShape* pShape = SvxShape::getImplementation( xShape );
316 if( NULL == pShape )
317 return;
319 SdrObject *pObj = pShape->GetSdrObject();
321 if(!pObj)
323 pObj = CreateSdrObject( xShape );
325 else if ( !pObj->IsInserted() )
327 pObj->SetModel(mpModel);
328 mpPage->InsertObject( pObj );
331 if(pObj == NULL)
332 return;
334 if(pShape)
335 pShape->Create( pObj, this );
337 if( mpModel )
338 mpModel->SetChanged();
341 //----------------------------------------------------------------------
342 void SAL_CALL SvxDrawPage::remove( const Reference< drawing::XShape >& xShape )
343 throw( uno::RuntimeException )
345 OGuard aGuard( Application::GetSolarMutex() );
347 if( (mpModel == 0) || (mpPage == 0) )
348 throw lang::DisposedException();
350 SvxShape* pShape = SvxShape::getImplementation( xShape );
352 if(pShape)
354 SdrObject* pObj = pShape->GetSdrObject();
355 if(pObj)
357 // SdrObject aus der Page loeschen
358 sal_uInt32 nCount = mpPage->GetObjCount();
359 for( sal_uInt32 nNum = 0; nNum < nCount; nNum++ )
361 if(mpPage->GetObj(nNum) == pObj)
363 OSL_VERIFY( mpPage->RemoveObject( nNum ) == pObj );
364 SdrObject::Free( pObj );
365 break;
371 if( mpModel )
372 mpModel->SetChanged();
375 //----------------------------------------------------------------------
376 // ::com::sun::star::container::XIndexAccess
377 //----------------------------------------------------------------------
379 sal_Int32 SAL_CALL SvxDrawPage::getCount()
380 throw( uno::RuntimeException )
382 OGuard aGuard( Application::GetSolarMutex() );
384 if( (mpModel == 0) || (mpPage == 0) )
385 throw lang::DisposedException();
387 return( (sal_Int32) mpPage->GetObjCount() );
390 //----------------------------------------------------------------------
391 uno::Any SAL_CALL SvxDrawPage::getByIndex( sal_Int32 Index )
392 throw( lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
394 OGuard aGuard( Application::GetSolarMutex() );
396 if( (mpModel == 0) || (mpPage == 0) )
397 throw lang::DisposedException();
399 if ( Index < 0 || Index >= (sal_Int32)mpPage->GetObjCount() )
400 throw lang::IndexOutOfBoundsException();
402 SdrObject* pObj = mpPage->GetObj( Index );
403 if( pObj == NULL )
404 throw uno::RuntimeException();
407 return makeAny(Reference< drawing::XShape >( pObj->getUnoShape(), uno::UNO_QUERY ));
411 //----------------------------------------------------------------------
412 // ::com::sun::star::container::XElementAccess
413 //----------------------------------------------------------------------
415 uno::Type SAL_CALL SvxDrawPage::getElementType()
416 throw( uno::RuntimeException )
418 return INTERFACE_TYPE( drawing::XShape );
421 //----------------------------------------------------------------------
422 sal_Bool SAL_CALL SvxDrawPage::hasElements()
423 throw( uno::RuntimeException )
425 OGuard aGuard( Application::GetSolarMutex() );
427 if( (mpModel == 0) || (mpPage == 0) )
428 throw lang::DisposedException();
430 return mpPage && mpPage->GetObjCount()>0;
433 namespace
435 void lcl_markSdrObjectOfShape( const Reference< drawing::XShape >& _rxShape, SdrView& _rView, SdrPageView& _rPageView )
437 SvxShape* pShape = SvxShape::getImplementation( _rxShape );
438 if ( !pShape )
439 return;
441 SdrObject* pObj = pShape->GetSdrObject();
442 if ( !pObj )
443 return;
445 _rView.MarkObj( pObj, &_rPageView );
449 //----------------------------------------------------------------------
450 // ACHTUNG: _SelectObjectsInView selektiert die ::com::sun::star::drawing::Shapes nur in der angegebennen
451 // SdrPageView. Dies muß nicht die sichtbare SdrPageView sein.
452 //----------------------------------------------------------------------
453 void SvxDrawPage::_SelectObjectsInView( const Reference< drawing::XShapes > & aShapes, SdrPageView* pPageView ) throw ()
455 DBG_ASSERT(pPageView,"SdrPageView ist NULL! [CL]");
456 DBG_ASSERT(mpView, "SdrView ist NULL! [CL]");
458 if(pPageView!=NULL && mpView!=NULL)
460 mpView->UnmarkAllObj( pPageView );
462 long nCount = aShapes->getCount();
463 for( long i = 0; i < nCount; i++ )
465 uno::Any aAny( aShapes->getByIndex(i) );
466 Reference< drawing::XShape > xShape;
467 if( aAny >>= xShape )
468 lcl_markSdrObjectOfShape( xShape, *mpView, *pPageView );
473 //----------------------------------------------------------------------
474 // ACHTUNG: _SelectObjectInView selektiert das Shape *nur* in der angegebennen
475 // SdrPageView. Dies muß nicht die sichtbare SdrPageView sein.
476 //----------------------------------------------------------------------
477 void SvxDrawPage::_SelectObjectInView( const Reference< drawing::XShape > & xShape, SdrPageView* pPageView ) throw()
479 DBG_ASSERT(pPageView,"SdrPageView ist NULL! [CL]");
480 DBG_ASSERT(mpView, "SdrView ist NULL! [CL]");
482 if(pPageView!=NULL && mpView != NULL)
484 mpView->UnmarkAllObj( pPageView );
485 lcl_markSdrObjectOfShape( xShape, *mpView, *pPageView );
489 //----------------------------------------------------------------------
490 Reference< drawing::XShapeGroup > SAL_CALL SvxDrawPage::group( const Reference< drawing::XShapes >& xShapes )
491 throw( uno::RuntimeException )
493 OGuard aGuard( Application::GetSolarMutex() );
495 if( (mpModel == 0) || (mpPage == 0) )
496 throw lang::DisposedException();
498 DBG_ASSERT(mpPage,"SdrPage ist NULL! [CL]");
499 DBG_ASSERT(mpView, "SdrView ist NULL! [CL]");
501 Reference< ::com::sun::star::drawing::XShapeGroup > xShapeGroup;
502 if(mpPage==NULL||mpView==NULL||!xShapes.is())
503 return xShapeGroup;
505 SdrPageView* pPageView = mpView->ShowSdrPage( mpPage );
507 _SelectObjectsInView( xShapes, pPageView );
509 mpView->GroupMarked();
511 mpView->AdjustMarkHdl();
512 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
513 if( rMarkList.GetMarkCount() == 1 )
515 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
516 if( pObj )
517 xShapeGroup = Reference< drawing::XShapeGroup >::query( pObj->getUnoShape() );
520 mpView->HideSdrPage();
522 if( mpModel )
523 mpModel->SetChanged();
525 return xShapeGroup;
528 //----------------------------------------------------------------------
529 void SAL_CALL SvxDrawPage::ungroup( const Reference< drawing::XShapeGroup >& aGroup )
530 throw( uno::RuntimeException )
532 OGuard aGuard( Application::GetSolarMutex() );
534 if( (mpModel == 0) || (mpPage == 0) )
535 throw lang::DisposedException();
537 DBG_ASSERT(mpPage,"SdrPage ist NULL! [CL]");
538 DBG_ASSERT(mpView, "SdrView ist NULL! [CL]");
540 if(mpPage==NULL||mpView==NULL||!aGroup.is())
541 return;
543 SdrPageView* pPageView = mpView->ShowSdrPage( mpPage );
545 Reference< drawing::XShape > xShape( aGroup, UNO_QUERY );
546 _SelectObjectInView( xShape, pPageView );
547 mpView->UnGroupMarked();
549 mpView->HideSdrPage();
551 if( mpModel )
552 mpModel->SetChanged();
555 //----------------------------------------------------------------------
556 SdrObject *SvxDrawPage::_CreateSdrObject( const Reference< drawing::XShape > & xShape ) throw()
558 sal_uInt16 nType;
559 sal_uInt32 nInventor;
561 GetTypeAndInventor( nType, nInventor, xShape->getShapeType() );
562 SdrObject* pNewObj = 0;
564 if( nType != 0 )
566 awt::Size aSize = xShape->getSize();
567 aSize.Width += 1;
568 aSize.Height += 1;
569 awt::Point aPos = xShape->getPosition();
570 Rectangle aRect( Point( aPos.X, aPos.Y ), Size( aSize.Width, aSize.Height ) );
572 // special cases
573 if( nInventor == SdrInventor )
575 switch( nType )
577 case OBJ_MEASURE:
579 pNewObj = new SdrMeasureObj( aRect.TopLeft(), aRect.BottomRight() );
580 break;
582 case OBJ_LINE:
584 basegfx::B2DPolygon aPoly;
585 aPoly.append(basegfx::B2DPoint(aRect.Left(), aRect.Top()));
586 aPoly.append(basegfx::B2DPoint(aRect.Right(), aRect.Bottom()));
587 pNewObj = new SdrPathObj(OBJ_LINE, basegfx::B2DPolyPolygon(aPoly));
588 break;
593 if( pNewObj == NULL )
594 pNewObj = SdrObjFactory::MakeNewObject( nInventor, nType, mpPage );
596 if(pNewObj)
598 pNewObj->SetSnapRect(aRect);
600 if( pNewObj->ISA(E3dPolyScene))
602 // Szene initialisieren
603 E3dScene* pScene = (E3dScene*)pNewObj;
605 double fW = (double)aSize.Width;
606 double fH = (double)aSize.Height;
608 Camera3D aCam(pScene->GetCamera());
609 aCam.SetAutoAdjustProjection(sal_False);
610 aCam.SetViewWindow(- fW / 2, - fH / 2, fW, fH);
611 basegfx::B3DPoint aLookAt;
612 basegfx::B3DPoint aCamPos(0.0, 0.0, 10000.0);
613 aCam.SetPosAndLookAt(aCamPos, aLookAt);
614 aCam.SetFocalLength(100.0);
615 aCam.SetDefaults(aCamPos, aLookAt, 10000.0);
616 pScene->SetCamera(aCam);
618 pScene->SetRectsDirty();
620 else if(pNewObj->ISA(E3dExtrudeObj))
622 E3dExtrudeObj* pObj = (E3dExtrudeObj*)pNewObj;
623 basegfx::B2DPolygon aNewPolygon;
624 aNewPolygon.append(basegfx::B2DPoint(0.0, 0.0));
625 aNewPolygon.append(basegfx::B2DPoint(0.0, 1.0));
626 aNewPolygon.append(basegfx::B2DPoint(1.0, 0.0));
627 aNewPolygon.setClosed(true);
628 pObj->SetExtrudePolygon(basegfx::B2DPolyPolygon(aNewPolygon));
630 // #107245# pObj->SetExtrudeCharacterMode(TRUE);
631 pObj->SetMergedItem(Svx3DCharacterModeItem(sal_True));
633 else if(pNewObj->ISA(E3dLatheObj))
635 E3dLatheObj* pObj = (E3dLatheObj*)pNewObj;
636 basegfx::B2DPolygon aNewPolygon;
637 aNewPolygon.append(basegfx::B2DPoint(0.0, 0.0));
638 aNewPolygon.append(basegfx::B2DPoint(0.0, 1.0));
639 aNewPolygon.append(basegfx::B2DPoint(1.0, 0.0));
640 aNewPolygon.setClosed(true);
641 pObj->SetPolyPoly2D(basegfx::B2DPolyPolygon(aNewPolygon));
643 // #107245# pObj->SetLatheCharacterMode(TRUE);
644 pObj->SetMergedItem(Svx3DCharacterModeItem(sal_True));
649 return pNewObj;
652 //----------------------------------------------------------------------
653 void SvxDrawPage::GetTypeAndInventor( sal_uInt16& rType, sal_uInt32& rInventor, const OUString& aName ) const throw()
655 sal_uInt32 nTempType = aSdrShapeIdentifierMap.getId( aName );
657 if( nTempType == UHASHMAP_NOTFOUND )
659 if( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.TableShape")) )
661 rInventor = SdrInventor;
662 rType = OBJ_TABLE;
665 else if(nTempType & E3D_INVENTOR_FLAG)
667 rInventor = E3dInventor;
668 rType = (sal_uInt16)(nTempType & ~E3D_INVENTOR_FLAG);
670 else
672 rInventor = SdrInventor;
673 rType = (sal_uInt16)nTempType;
675 switch( rType )
677 case OBJ_FRAME:
678 case OBJ_OLE2_PLUGIN:
679 case OBJ_OLE2_APPLET:
680 rType = OBJ_OLE2;
681 break;
686 //----------------------------------------------------------------------
687 SvxShape* SvxDrawPage::CreateShapeByTypeAndInventor( sal_uInt16 nType, sal_uInt32 nInventor, SdrObject *pObj, SvxDrawPage *mpPage ) throw()
689 SvxShape* pRet = NULL;
690 switch( nInventor )
692 case E3dInventor:
694 switch( nType )
696 case E3D_SCENE_ID :
697 case E3D_POLYSCENE_ID :
698 pRet = new Svx3DSceneObject( pObj, mpPage );
699 break;
700 case E3D_CUBEOBJ_ID :
701 pRet = new Svx3DCubeObject( pObj );
702 break;
703 case E3D_SPHEREOBJ_ID :
704 pRet = new Svx3DSphereObject( pObj );
705 break;
706 case E3D_LATHEOBJ_ID :
707 pRet = new Svx3DLatheObject( pObj );
708 break;
709 case E3D_EXTRUDEOBJ_ID :
710 pRet = new Svx3DExtrudeObject( pObj );
711 break;
712 case E3D_POLYGONOBJ_ID :
713 pRet = new Svx3DPolygonObject( pObj );
714 break;
715 default: // unbekanntes 3D-Objekt auf der Page
716 pRet = new SvxShape( pObj );
717 break;
719 break;
721 case SdrInventor:
723 switch( nType )
725 // case OBJ_NONE:
726 // break;
727 case OBJ_GRUP:
728 pRet = new SvxShapeGroup( pObj, mpPage );
729 break;
730 case OBJ_LINE:
731 pRet = new SvxShapePolyPolygon( pObj , PolygonKind_LINE );
732 break;
733 case OBJ_RECT:
734 pRet = new SvxShapeRect( pObj );
735 break;
736 case OBJ_CIRC:
737 case OBJ_SECT:
738 case OBJ_CARC:
739 case OBJ_CCUT:
740 pRet = new SvxShapeCircle( pObj );
741 break;
742 case OBJ_POLY:
743 pRet = new SvxShapePolyPolygon( pObj , PolygonKind_POLY );
744 break;
745 case OBJ_PLIN:
746 pRet = new SvxShapePolyPolygon( pObj , PolygonKind_PLIN );
747 break;
748 case OBJ_SPLNLINE:
749 case OBJ_PATHLINE:
750 pRet = new SvxShapePolyPolygonBezier( pObj , PolygonKind_PATHLINE );
751 break;
752 case OBJ_SPLNFILL:
753 case OBJ_PATHFILL:
754 pRet = new SvxShapePolyPolygonBezier( pObj , PolygonKind_PATHFILL );
755 break;
756 case OBJ_FREELINE:
757 pRet = new SvxShapePolyPolygonBezier( pObj , PolygonKind_FREELINE );
758 break;
759 case OBJ_FREEFILL:
760 pRet = new SvxShapePolyPolygonBezier( pObj , PolygonKind_FREEFILL );
761 break;
762 case OBJ_CAPTION:
763 pRet = new SvxShapeCaption( pObj );
764 break;
765 case OBJ_TITLETEXT:
766 case OBJ_OUTLINETEXT:
767 case OBJ_TEXT:
768 pRet = new SvxShapeText( pObj );
769 break;
770 case OBJ_GRAF:
771 pRet = new SvxGraphicObject( pObj );
772 break;
773 case OBJ_FRAME:
774 pRet = new SvxFrameShape( pObj );
775 break;
776 case OBJ_OLE2_APPLET:
777 pRet = new SvxAppletShape( pObj );
778 break;
779 case OBJ_OLE2_PLUGIN:
780 pRet = new SvxPluginShape( pObj );
781 break;
782 case OBJ_OLE2:
784 if( pObj && !pObj->IsEmptyPresObj() && mpPage )
786 SdrPage* pSdrPage = mpPage->GetSdrPage();
787 if( pSdrPage )
789 SdrModel* pSdrModel = pSdrPage->GetModel();
790 if( pSdrModel )
792 ::comphelper::IEmbeddedHelper *pPersist = pSdrModel->GetPersist();
793 if( pPersist )
795 uno::Reference < embed::XEmbeddedObject > xObject = pPersist->getEmbeddedObjectContainer().
796 GetEmbeddedObject( static_cast< SdrOle2Obj* >( pObj )->GetPersistName() );
798 // TODO CL->KA: Why is this not working anymore?
799 if( xObject.is() )
801 SvGlobalName aClassId( xObject->getClassID() );
803 const SvGlobalName aAppletClassId( SO3_APPLET_CLASSID );
804 const SvGlobalName aPluginClassId( SO3_PLUGIN_CLASSID );
805 const SvGlobalName aIFrameClassId( SO3_IFRAME_CLASSID );
807 if( aPluginClassId == aClassId )
809 pRet = new SvxPluginShape( pObj );
810 nType = OBJ_OLE2_PLUGIN;
812 else if( aAppletClassId == aClassId )
814 pRet = new SvxAppletShape( pObj );
815 nType = OBJ_OLE2_APPLET;
817 else if( aIFrameClassId == aClassId )
819 pRet = new SvxFrameShape( pObj );
820 nType = OBJ_FRAME;
827 if( pRet == NULL )
829 pRet = new SvxOle2Shape( pObj, aSvxMapProvider.GetMap(SVXMAP_OLE2), aSvxMapProvider.GetPropertySet(SVXMAP_OLE2) );
832 break;
833 case OBJ_EDGE:
834 pRet = new SvxShapeConnector( pObj );
835 break;
836 case OBJ_PATHPOLY:
837 pRet = new SvxShapePolyPolygon( pObj , PolygonKind_PATHPOLY );
838 break;
839 case OBJ_PATHPLIN:
840 pRet = new SvxShapePolyPolygon( pObj , PolygonKind_PATHPLIN );
841 break;
842 case OBJ_PAGE:
843 pRet = new SvxShape( pObj, aSvxMapProvider.GetMap(SVXMAP_PAGE), aSvxMapProvider.GetPropertySet(SVXMAP_PAGE) );
844 break;
845 case OBJ_MEASURE:
846 pRet = new SvxShapeDimensioning( pObj );
847 break;
848 // case OBJ_DUMMY:
849 // break;
850 case OBJ_UNO:
851 pRet = new SvxShapeControl( pObj );
852 break;
853 case OBJ_CUSTOMSHAPE:
854 pRet = new SvxCustomShape( pObj );
855 break;
856 case OBJ_MEDIA:
857 pRet = new SvxMediaShape( pObj );
858 break;
859 case OBJ_TABLE:
860 pRet = new SvxTableShape( pObj );
861 break;
862 default: // unbekanntes 2D-Objekt auf der Page
863 DBG_ERROR("Nicht implementierter Starone-Shape erzeugt! [CL]");
864 pRet = new SvxShapeText( pObj );
865 break;
867 break;
869 default: // Unbekannter Inventor
871 DBG_ERROR("AW: Unknown Inventor in SvxDrawPage::_CreateShape()");
872 break;
876 if(pRet)
878 sal_uInt32 nObjId = nType;
880 if( nInventor == E3dInventor )
881 nObjId |= E3D_INVENTOR_FLAG;
883 switch(nObjId)
885 case OBJ_CCUT: // Kreisabschnitt
886 case OBJ_CARC: // Kreisbogen
887 case OBJ_SECT: // Kreissektor
888 nObjId = OBJ_CIRC;
889 break;
891 case E3D_SCENE_ID | E3D_INVENTOR_FLAG:
892 nObjId = E3D_POLYSCENE_ID | E3D_INVENTOR_FLAG;
893 break;
895 case OBJ_TITLETEXT:
896 case OBJ_OUTLINETEXT:
897 nObjId = OBJ_TEXT;
898 break;
901 pRet->setShapeKind(nObjId);
904 return pRet;
907 //----------------------------------------------------------------------
908 Reference< drawing::XShape > SvxDrawPage::_CreateShape( SdrObject *pObj ) const throw()
910 Reference< drawing::XShape > xShape( CreateShapeByTypeAndInventor(pObj->GetObjIdentifier(),
911 pObj->GetObjInventor(),
912 pObj,
913 (SvxDrawPage*)this));
914 return xShape;
917 //----------------------------------------------------------------------
918 SdrObject *SvxDrawPage::CreateSdrObject( const Reference< drawing::XShape > & xShape ) throw()
920 SdrObject* pObj = _CreateSdrObject( xShape );
921 if( pObj && !pObj->IsInserted() )
922 mpPage->InsertObject( pObj );
924 return pObj;
927 //----------------------------------------------------------------------
928 // ::com::sun::star::lang::XServiceInfo
929 //----------------------------------------------------------------------
930 OUString SAL_CALL SvxDrawPage::getImplementationName() throw( uno::RuntimeException )
932 return OUString( RTL_CONSTASCII_USTRINGPARAM("SvxDrawPage"));
935 sal_Bool SAL_CALL SvxDrawPage::supportsService( const OUString& ServiceName )
936 throw(::com::sun::star::uno::RuntimeException)
938 return SvxServiceInfoHelper::supportsService( ServiceName, getSupportedServiceNames() );
941 uno::Sequence< OUString > SAL_CALL SvxDrawPage::getSupportedServiceNames() throw( uno::RuntimeException )
943 uno::Sequence< OUString > aSeq( 1 );
944 aSeq.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.ShapeCollection" ));
945 return aSeq;
948 SvxShape* CreateSvxShapeByTypeAndInventor( sal_uInt16 nType, sal_uInt32 nInventor ) throw()
950 return SvxDrawPage::CreateShapeByTypeAndInventor( nType, nInventor );
953 void SvxDrawPage::ChangeModel( SdrModel* pNewModel )
955 if( pNewModel != mpModel )
957 if( mpModel )
958 EndListening( *mpModel );
960 if( pNewModel )
961 StartListening( *pNewModel );
963 mpModel = pNewModel;
965 if( mpView )
967 delete mpView;
968 mpView = new SdrView( mpModel );
969 if( mpView )
970 mpView->SetDesignMode(sal_True);
975 /** returns a StarOffice API wrapper for the given SdrPage */
976 uno::Reference< drawing::XDrawPage > GetXDrawPageForSdrPage( SdrPage* pPage ) throw ()
978 if(pPage)
980 uno::Reference< drawing::XDrawPage > xDrawPage( pPage->getUnoPage(), uno::UNO_QUERY );
982 return xDrawPage;
985 return uno::Reference< drawing::XDrawPage >();
988 /** returns the SdrObject from the given StarOffice API wrapper */
989 SdrPage* GetSdrPageFromXDrawPage( uno::Reference< drawing::XDrawPage > xDrawPage ) throw()
991 if(xDrawPage.is())
993 SvxDrawPage* pDrawPage = SvxDrawPage::getImplementation( xDrawPage );
995 if(pDrawPage)
997 return pDrawPage->GetSdrPage();
1001 return NULL;
1004 // eof