LCOV - code coverage report
Current view: top level - svx/source/unodraw - unopage.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 388 456 85.1 %
Date: 2014-11-03 Functions: 34 39 87.2 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #include <config_features.h>
      21             : 
      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>
      28             : 
      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>
      52             : 
      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;
      59             : 
      60             : #define INTERFACE_TYPE( xint ) \
      61             :     ::getCppuType((const Reference< xint >*)0)
      62             : 
      63      240438 : UNO3_GETIMPLEMENTATION_IMPL( SvxDrawPage );
      64        8593 : SvxDrawPage::SvxDrawPage( SdrPage* pInPage ) throw()
      65        8593 : : mrBHelper( getMutex() )
      66             : , mpPage( pInPage )
      67       17186 : , mpModel( 0 )
      68             : {
      69             :     // Am Broadcaster anmelden
      70        8593 :     if( mpPage )
      71        8593 :         mpModel = mpPage->GetModel();
      72        8593 :     if( mpModel )
      73        8593 :         StartListening( *mpModel );
      74             : 
      75             : 
      76             :     // Erzeugen der (hidden) View
      77        8593 :     mpView = new SdrView( mpModel );
      78        8593 :     if( mpView )
      79        8593 :         mpView->SetDesignMode(true);
      80        8593 : }
      81             : 
      82       17110 : SvxDrawPage::~SvxDrawPage() throw()
      83             : {
      84             :     DBG_ASSERT( mrBHelper.bDisposed, "SvxDrawPage must be disposed!" );
      85        8555 :     if( !mrBHelper.bDisposed )
      86             :     {
      87         386 :         acquire();
      88         386 :         dispose();
      89             :     }
      90        8555 : }
      91             : 
      92             : // XInterface
      93      456278 : void SvxDrawPage::release() throw()
      94             : {
      95      456278 :     OWeakAggObject::release();
      96      456278 : }
      97             : 
      98             : // XComponent
      99        8557 : void SvxDrawPage::disposing() throw()
     100             : {
     101        8557 :     if( mpModel )
     102             :     {
     103        8557 :         EndListening( *mpModel );
     104        8557 :         mpModel = NULL;
     105             :     }
     106             : 
     107        8557 :     if( mpView )
     108             :     {
     109        8557 :         delete mpView;
     110        8557 :         mpView = NULL;
     111             :     }
     112        8557 :     mpPage = 0;
     113        8557 : }
     114             : 
     115             : // XComponent
     116       11350 : void SvxDrawPage::dispose()
     117             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     118             : {
     119       11350 :     SolarMutexGuard aSolarGuard;
     120             : 
     121             :     // An frequently programming error is to release the last
     122             :     // reference to this object in the disposing message.
     123             :     // Make it rubust, hold a self Reference.
     124       22700 :     uno::Reference< lang::XComponent > xSelf( this );
     125             : 
     126             :     // Guard dispose against multible threading
     127             :     // Remark: It is an error to call dispose more than once
     128       11350 :     bool bDoDispose = false;
     129             :     {
     130       11350 :     osl::MutexGuard aGuard( mrBHelper.rMutex );
     131       11350 :     if( !mrBHelper.bDisposed && !mrBHelper.bInDispose )
     132             :     {
     133             :         // only one call go into this section
     134        8557 :         mrBHelper.bInDispose = sal_True;
     135        8557 :         bDoDispose = true;
     136       11350 :     }
     137             :     }
     138             : 
     139             :     // Do not hold the mutex because we are broadcasting
     140       11350 :     if( bDoDispose )
     141             :     {
     142             :         // Create an event with this as sender
     143             :         try
     144             :         {
     145        8557 :             uno::Reference< uno::XInterface > xSource( uno::Reference< uno::XInterface >::query( (lang::XComponent *)this ) );
     146       17114 :             ::com::sun::star::document::EventObject aEvt;
     147        8557 :             aEvt.Source = xSource;
     148             :             // inform all listeners to release this object
     149             :             // The listener container are automatically cleared
     150        8557 :             mrBHelper.aLC.disposeAndClear( aEvt );
     151             :             // notify subclasses to do their dispose
     152       17114 :             disposing();
     153             :         }
     154           0 :         catch(const ::com::sun::star::uno::Exception&)
     155             :         {
     156             :             // catch exception and throw again but signal that
     157             :             // the object was disposed. Dispose should be called
     158             :             // only once.
     159           0 :             mrBHelper.bDisposed = sal_True;
     160           0 :             mrBHelper.bInDispose = sal_False;
     161           0 :             throw;
     162             :         }
     163             : 
     164             :         // the values bDispose and bInDisposing must set in this order.
     165             :         // No multithread call overcome the "!rBHelper.bDisposed && !rBHelper.bInDispose" guard.
     166        8557 :         mrBHelper.bDisposed = sal_True;
     167        8557 :         mrBHelper.bInDispose = sal_False;
     168       11350 :     }
     169             : 
     170       11350 : }
     171             : 
     172          70 : 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             : {
     174          70 :     SolarMutexGuard aGuard;
     175             : 
     176          70 :     if( mpModel == 0 )
     177           0 :         throw lang::DisposedException();
     178             : 
     179          70 :     mrBHelper.addListener( ::getCppuType( &aListener ) , aListener );
     180          70 : }
     181             : 
     182          70 : 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             : {
     184          70 :     SolarMutexGuard aGuard;
     185             : 
     186          70 :     if( mpModel == 0 )
     187           0 :         throw lang::DisposedException();
     188             : 
     189          70 :     mrBHelper.removeListener( ::getCppuType( &aListener ) , aListener );
     190          70 : }
     191             : 
     192             : // SfxListener
     193      425287 : void SvxDrawPage::Notify( SfxBroadcaster&, const SfxHint& /*rHint*/ )
     194             : {
     195      425287 : }
     196             : 
     197        7970 : void SAL_CALL SvxDrawPage::add( const uno::Reference< drawing::XShape >& xShape )
     198             :     throw( uno::RuntimeException, std::exception )
     199             : {
     200        7970 :     SolarMutexGuard aGuard;
     201             : 
     202        7970 :     if ( ( mpModel == NULL ) || ( mpPage == NULL ) )
     203           0 :         throw lang::DisposedException();
     204             : 
     205        7970 :     SvxShape* pShape = SvxShape::getImplementation( xShape );
     206             : 
     207        7970 :     if( NULL == pShape )
     208           0 :         return;
     209             : 
     210        7970 :     SdrObject *pObj = pShape->GetSdrObject();
     211             : 
     212        7970 :     if(!pObj)
     213             :     {
     214        7382 :         pObj = CreateSdrObject( xShape );
     215        7382 :         ENSURE_OR_RETURN_VOID( pObj != NULL, "SvxDrawPage::add: no SdrObject was created!" );
     216             :     }
     217         588 :     else if ( !pObj->IsInserted() )
     218             :     {
     219         588 :         pObj->SetModel(mpModel);
     220         588 :         mpPage->InsertObject( pObj );
     221             :     }
     222             : 
     223        7970 :     pShape->Create( pObj, this );
     224             :     OSL_ENSURE( pShape->GetSdrObject() == pObj, "SvxDrawPage::add: shape does not know about its newly created SdrObject!" );
     225             : 
     226        7970 :     if ( !pObj->IsInserted() )
     227             :     {
     228           0 :         pObj->SetModel(mpModel);
     229           0 :         mpPage->InsertObject( pObj );
     230             :     }
     231             : 
     232        7970 :     mpModel->SetChanged();
     233             : }
     234             : 
     235           0 : void SAL_CALL SvxDrawPage::addTop( const uno::Reference< drawing::XShape >& xShape )
     236             :     throw( uno::RuntimeException, std::exception )
     237             : {
     238           0 :     add(xShape);
     239           0 : }
     240             : 
     241         436 : void SAL_CALL SvxDrawPage::addBottom( const uno::Reference< drawing::XShape >& xShape )
     242             :     throw( uno::RuntimeException, std::exception )
     243             : {
     244         436 :     SolarMutexGuard aGuard;
     245             : 
     246         436 :     if ( ( mpModel == NULL ) || ( mpPage == NULL ) )
     247           0 :         throw lang::DisposedException();
     248             : 
     249         436 :     SvxShape* pShape = SvxShape::getImplementation( xShape );
     250             : 
     251         436 :     if( NULL == pShape )
     252           0 :         return;
     253             : 
     254         436 :     SdrObject *pObj = pShape->GetSdrObject();
     255             : 
     256         436 :     if(!pObj)
     257             :     {
     258         436 :         pObj = CreateSdrObject( xShape, true );
     259         436 :         ENSURE_OR_RETURN_VOID( pObj != NULL, "SvxDrawPage::add: no SdrObject was created!" );
     260             :     }
     261           0 :     else if ( !pObj->IsInserted() )
     262             :     {
     263           0 :         pObj->SetModel(mpModel);
     264           0 :         mpPage->InsertObject( pObj, 0 );
     265             :     }
     266             : 
     267         436 :     pShape->Create( pObj, this );
     268             :     OSL_ENSURE( pShape->GetSdrObject() == pObj, "SvxDrawPage::add: shape does not know about its newly created SdrObject!" );
     269             : 
     270         436 :     if ( !pObj->IsInserted() )
     271             :     {
     272           0 :         pObj->SetModel(mpModel);
     273           0 :         mpPage->InsertObject( pObj, 0 );
     274             :     }
     275             : 
     276         436 :     mpModel->SetChanged();
     277             : }
     278             : 
     279        1870 : void SAL_CALL SvxDrawPage::remove( const Reference< drawing::XShape >& xShape )
     280             :     throw (uno::RuntimeException, std::exception)
     281             : {
     282        1870 :     SolarMutexGuard aGuard;
     283             : 
     284        1870 :     if( (mpModel == 0) || (mpPage == 0) )
     285           0 :         throw lang::DisposedException();
     286             : 
     287        1870 :     SvxShape* pShape = SvxShape::getImplementation( xShape );
     288             : 
     289        1870 :     if (pShape)
     290             :     {
     291        1870 :         SdrObject* pObj = pShape->GetSdrObject();
     292        1870 :         if (pObj)
     293             :         {
     294             :             // remove SdrObject from page
     295        1870 :             const size_t nCount = mpPage->GetObjCount();
     296        2422 :             for( size_t nNum = 0; nNum < nCount; ++nNum )
     297             :             {
     298        2422 :                 if(mpPage->GetObj(nNum) == pObj)
     299             :                 {
     300        1870 :                     const bool bUndoEnabled = mpModel->IsUndoEnabled();
     301             : 
     302        1870 :                     if (bUndoEnabled)
     303             :                     {
     304             :                         mpModel->BegUndo(ImpGetResStr(STR_EditDelete),
     305         906 :                             pObj->TakeObjNameSingul(), SDRREPFUNC_OBJ_DELETE);
     306             : 
     307         906 :                         SdrUndoAction * pAction = mpModel->GetSdrUndoFactory().CreateUndoDeleteObject(*pObj);
     308         906 :                         mpModel->AddUndo(pAction);
     309             :                     }
     310             : 
     311        1870 :                     OSL_VERIFY( mpPage->RemoveObject( nNum ) == pObj );
     312             : 
     313        1870 :                     if (!bUndoEnabled)
     314         964 :                         SdrObject::Free(pObj);
     315             : 
     316        1870 :                     if (bUndoEnabled)
     317         906 :                         mpModel->EndUndo();
     318             : 
     319        1870 :                     break;
     320             :                 }
     321             :             }
     322             :         }
     323             :     }
     324             : 
     325        1870 :     mpModel->SetChanged();
     326        1870 : }
     327             : 
     328             : // ::com::sun::star::container::XIndexAccess
     329       10012 : sal_Int32 SAL_CALL SvxDrawPage::getCount()
     330             :     throw( uno::RuntimeException, std::exception )
     331             : {
     332       10012 :     SolarMutexGuard aGuard;
     333             : 
     334       10012 :     if( (mpModel == 0) || (mpPage == 0) )
     335           0 :         throw lang::DisposedException();
     336             : 
     337       10012 :     return static_cast<sal_Int32>( mpPage->GetObjCount() );
     338             : }
     339             : 
     340        7813 : uno::Any SAL_CALL SvxDrawPage::getByIndex( sal_Int32 Index )
     341             :     throw( lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
     342             : {
     343        7813 :     SolarMutexGuard aGuard;
     344             : 
     345        7813 :     if( (mpModel == 0) || (mpPage == 0) )
     346           0 :         throw lang::DisposedException();
     347             : 
     348        7813 :     if ( Index < 0 || static_cast<size_t>(Index) >= mpPage->GetObjCount() )
     349          18 :         throw lang::IndexOutOfBoundsException();
     350             : 
     351        7795 :     SdrObject* pObj = mpPage->GetObj( Index );
     352        7795 :     if( pObj == NULL )
     353           0 :         throw uno::RuntimeException();
     354             : 
     355             : 
     356        7795 :     return makeAny(Reference< drawing::XShape >( pObj->getUnoShape(), uno::UNO_QUERY ));
     357             : }
     358             : 
     359             : // ::com::sun::star::container::XElementAccess
     360          10 : uno::Type SAL_CALL SvxDrawPage::getElementType()
     361             :     throw( uno::RuntimeException, std::exception )
     362             : {
     363          10 :     return INTERFACE_TYPE( drawing::XShape );
     364             : }
     365             : 
     366          12 : sal_Bool SAL_CALL SvxDrawPage::hasElements()
     367             :     throw( uno::RuntimeException, std::exception )
     368             : {
     369          12 :     SolarMutexGuard aGuard;
     370             : 
     371          12 :     if( (mpModel == 0) || (mpPage == 0) )
     372           0 :         throw lang::DisposedException();
     373             : 
     374          12 :     return mpPage && mpPage->GetObjCount()>0;
     375             : }
     376             : 
     377             : namespace
     378             : {
     379         324 :     void lcl_markSdrObjectOfShape( const Reference< drawing::XShape >& _rxShape, SdrView& _rView, SdrPageView& _rPageView )
     380             :     {
     381         324 :         SvxShape* pShape = SvxShape::getImplementation( _rxShape );
     382         324 :         if ( !pShape )
     383           0 :             return;
     384             : 
     385         324 :         SdrObject* pObj = pShape->GetSdrObject();
     386         324 :         if ( !pObj )
     387           0 :             return;
     388             : 
     389         324 :         _rView.MarkObj( pObj, &_rPageView );
     390             :     }
     391             : }
     392             : 
     393             : // ACHTUNG: _SelectObjectsInView selektiert die ::com::sun::star::drawing::Shapes nur in der angegebennen
     394             : //         SdrPageView. Dies muss nicht die sichtbare SdrPageView sein.
     395          78 : void SvxDrawPage::_SelectObjectsInView( const Reference< drawing::XShapes > & aShapes, SdrPageView* pPageView ) throw ()
     396             : {
     397             :     DBG_ASSERT(pPageView,"SdrPageView ist NULL! [CL]");
     398             :     DBG_ASSERT(mpView, "SdrView ist NULL! [CL]");
     399             : 
     400          78 :     if(pPageView!=NULL && mpView!=NULL)
     401             :     {
     402          78 :         mpView->UnmarkAllObj( pPageView );
     403             : 
     404          78 :         long nCount = aShapes->getCount();
     405         380 :         for( long i = 0; i < nCount; i++ )
     406             :         {
     407         302 :             uno::Any aAny( aShapes->getByIndex(i) );
     408         604 :             Reference< drawing::XShape > xShape;
     409         302 :             if( aAny >>= xShape )
     410         302 :                 lcl_markSdrObjectOfShape( xShape, *mpView, *pPageView );
     411         302 :         }
     412             :     }
     413          78 : }
     414             : 
     415             : // ACHTUNG: _SelectObjectInView selektiert das Shape *nur* in der angegebennen
     416             : //         SdrPageView. Dies muss nicht die sichtbare SdrPageView sein.
     417          22 : void SvxDrawPage::_SelectObjectInView( const Reference< drawing::XShape > & xShape, SdrPageView* pPageView ) throw()
     418             : {
     419             :     DBG_ASSERT(pPageView,"SdrPageView ist NULL! [CL]");
     420             :     DBG_ASSERT(mpView, "SdrView ist NULL! [CL]");
     421             : 
     422          22 :     if(pPageView!=NULL && mpView != NULL)
     423             :     {
     424          22 :         mpView->UnmarkAllObj( pPageView );
     425          22 :         lcl_markSdrObjectOfShape( xShape, *mpView, *pPageView );
     426             :     }
     427          22 : }
     428             : 
     429          66 : Reference< drawing::XShapeGroup > SAL_CALL SvxDrawPage::group( const Reference< drawing::XShapes >& xShapes )
     430             :     throw( uno::RuntimeException, std::exception )
     431             : {
     432          66 :     SolarMutexGuard aGuard;
     433             : 
     434          66 :     if( (mpModel == 0) || (mpPage == 0) )
     435           0 :         throw lang::DisposedException();
     436             : 
     437             :     DBG_ASSERT(mpPage,"SdrPage ist NULL! [CL]");
     438             :     DBG_ASSERT(mpView, "SdrView ist NULL! [CL]");
     439             : 
     440          66 :     Reference< ::com::sun::star::drawing::XShapeGroup >  xShapeGroup;
     441          66 :     if(mpPage==NULL||mpView==NULL||!xShapes.is())
     442           0 :         return xShapeGroup;
     443             : 
     444          66 :     SdrPageView* pPageView = mpView->ShowSdrPage( mpPage );
     445             : 
     446          66 :     _SelectObjectsInView( xShapes, pPageView );
     447             : 
     448          66 :     mpView->GroupMarked();
     449             : 
     450          66 :     mpView->AdjustMarkHdl();
     451          66 :     const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
     452          66 :     if( rMarkList.GetMarkCount() == 1 )
     453             :     {
     454          66 :         SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
     455          66 :         if( pObj )
     456          66 :              xShapeGroup = Reference< drawing::XShapeGroup >::query( pObj->getUnoShape() );
     457             :     }
     458             : 
     459          66 :     mpView->HideSdrPage();
     460             : 
     461          66 :     if( mpModel )
     462          66 :         mpModel->SetChanged();
     463             : 
     464          66 :     return xShapeGroup;
     465             : }
     466             : 
     467          10 : void SAL_CALL SvxDrawPage::ungroup( const Reference< drawing::XShapeGroup >& aGroup )
     468             :     throw( uno::RuntimeException, std::exception )
     469             : {
     470          10 :     SolarMutexGuard aGuard;
     471             : 
     472          10 :     if( (mpModel == 0) || (mpPage == 0) )
     473           0 :         throw lang::DisposedException();
     474             : 
     475             :     DBG_ASSERT(mpPage,"SdrPage ist NULL! [CL]");
     476             :     DBG_ASSERT(mpView, "SdrView ist NULL! [CL]");
     477             : 
     478          10 :     if(mpPage==NULL||mpView==NULL||!aGroup.is())
     479          10 :         return;
     480             : 
     481          10 :     SdrPageView* pPageView = mpView->ShowSdrPage( mpPage );
     482             : 
     483          20 :     Reference< drawing::XShape > xShape( aGroup, UNO_QUERY );
     484          10 :     _SelectObjectInView( xShape, pPageView );
     485          10 :     mpView->UnGroupMarked();
     486             : 
     487          10 :     mpView->HideSdrPage();
     488             : 
     489          10 :     if( mpModel )
     490          20 :         mpModel->SetChanged();
     491             : }
     492             : 
     493       65380 : SdrObject *SvxDrawPage::_CreateSdrObject(const Reference< drawing::XShape > & xShape)
     494             :     throw (css::uno::RuntimeException, std::exception)
     495             : {
     496       65380 :     sal_uInt16 nType = 0;
     497       65380 :     sal_uInt32 nInventor = 0;
     498             : 
     499       65380 :     GetTypeAndInventor( nType, nInventor, xShape->getShapeType() );
     500       65380 :     if (!nType)
     501           0 :         return NULL;
     502             : 
     503       65380 :     SdrObject* pNewObj = 0;
     504             : 
     505       65380 :     awt::Size aSize = xShape->getSize();
     506       65380 :     aSize.Width += 1;
     507       65380 :     aSize.Height += 1;
     508       65380 :     awt::Point aPos = xShape->getPosition();
     509       65380 :     Rectangle aRect( Point( aPos.X, aPos.Y ), Size( aSize.Width, aSize.Height ) );
     510             : 
     511             :     // special cases
     512       65380 :     if( nInventor == SdrInventor )
     513             :     {
     514       59876 :         switch( nType )
     515             :         {
     516             :         case OBJ_MEASURE:
     517             :             {
     518           2 :                 pNewObj = new SdrMeasureObj( aRect.TopLeft(), aRect.BottomRight() );
     519           2 :                 break;
     520             :             }
     521             :         case OBJ_LINE:
     522             :             {
     523         256 :                 basegfx::B2DPolygon aPoly;
     524         256 :                 aPoly.append(basegfx::B2DPoint(aRect.Left(), aRect.Top()));
     525         256 :                 aPoly.append(basegfx::B2DPoint(aRect.Right(), aRect.Bottom()));
     526         256 :                 pNewObj = new SdrPathObj(OBJ_LINE, basegfx::B2DPolyPolygon(aPoly));
     527         256 :                 break;
     528             :             }
     529             :         }
     530             :     }
     531             : 
     532       65380 :     if( pNewObj == NULL )
     533       65122 :         pNewObj = SdrObjFactory::MakeNewObject( nInventor, nType, mpPage );
     534             : 
     535       65380 :     if (!pNewObj)
     536           0 :         return NULL;
     537             : 
     538       65380 :     pNewObj->SetSnapRect(aRect);
     539             : 
     540       65380 :     if( pNewObj->ISA(E3dPolyScene))
     541             :     {
     542             :         // Szene initialisieren
     543        1406 :         E3dScene* pScene = static_cast<E3dScene*>(pNewObj);
     544             : 
     545        1406 :         double fW = (double)aSize.Width;
     546        1406 :         double fH = (double)aSize.Height;
     547             : 
     548        1406 :         Camera3D aCam(pScene->GetCamera());
     549        1406 :         aCam.SetAutoAdjustProjection(false);
     550        1406 :         aCam.SetViewWindow(- fW / 2, - fH / 2, fW, fH);
     551        2812 :         basegfx::B3DPoint aLookAt;
     552        2812 :         basegfx::B3DPoint aCamPos(0.0, 0.0, 10000.0);
     553        1406 :         aCam.SetPosAndLookAt(aCamPos, aLookAt);
     554        1406 :         aCam.SetFocalLength(100.0);
     555        1406 :         aCam.SetDefaults(aCamPos, aLookAt, 10000.0);
     556        1406 :         pScene->SetCamera(aCam);
     557             : 
     558        2812 :         pScene->SetRectsDirty();
     559             :     }
     560       63974 :     else if(pNewObj->ISA(E3dExtrudeObj))
     561             :     {
     562        3257 :         E3dExtrudeObj* pObj = static_cast<E3dExtrudeObj*>(pNewObj);
     563        3257 :         basegfx::B2DPolygon aNewPolygon;
     564        3257 :         aNewPolygon.append(basegfx::B2DPoint(0.0, 0.0));
     565        3257 :         aNewPolygon.append(basegfx::B2DPoint(0.0, 1.0));
     566        3257 :         aNewPolygon.append(basegfx::B2DPoint(1.0, 0.0));
     567        3257 :         aNewPolygon.setClosed(true);
     568        3257 :         pObj->SetExtrudePolygon(basegfx::B2DPolyPolygon(aNewPolygon));
     569             : 
     570             :         // #107245# pObj->SetExtrudeCharacterMode(sal_True);
     571        3257 :         pObj->SetMergedItem(Svx3DCharacterModeItem(true));
     572             :     }
     573       60717 :     else if(pNewObj->ISA(E3dLatheObj))
     574             :     {
     575          96 :         E3dLatheObj* pObj = static_cast<E3dLatheObj*>(pNewObj);
     576          96 :         basegfx::B2DPolygon aNewPolygon;
     577          96 :         aNewPolygon.append(basegfx::B2DPoint(0.0, 0.0));
     578          96 :         aNewPolygon.append(basegfx::B2DPoint(0.0, 1.0));
     579          96 :         aNewPolygon.append(basegfx::B2DPoint(1.0, 0.0));
     580          96 :         aNewPolygon.setClosed(true);
     581          96 :         pObj->SetPolyPoly2D(basegfx::B2DPolyPolygon(aNewPolygon));
     582             : 
     583             :         // #107245# pObj->SetLatheCharacterMode(sal_True);
     584          96 :         pObj->SetMergedItem(Svx3DCharacterModeItem(true));
     585             :     }
     586             : 
     587       65380 :     return pNewObj;
     588             : }
     589             : 
     590       65380 : void SvxDrawPage::GetTypeAndInventor( sal_uInt16& rType, sal_uInt32& rInventor, const OUString& aName ) const throw()
     591             : {
     592       65380 :     sal_uInt32 nTempType = UHashMap::getId( aName );
     593             : 
     594       65380 :     if( nTempType == UHASHMAP_NOTFOUND )
     595             :     {
     596          22 :         if( aName == "com.sun.star.drawing.TableShape" ||
     597           6 :             aName == "com.sun.star.presentation.TableShape" )
     598             :         {
     599          12 :             rInventor = SdrInventor;
     600          12 :             rType = OBJ_TABLE;
     601             :         }
     602             : #if HAVE_FEATURE_AVMEDIA
     603           4 :         else if ( aName == "com.sun.star.presentation.MediaShape" )
     604             :         {
     605           4 :             rInventor = SdrInventor;
     606           4 :             rType = OBJ_MEDIA;
     607             :         }
     608             : #endif
     609             :     }
     610       65364 :     else if(nTempType & E3D_INVENTOR_FLAG)
     611             :     {
     612        5504 :         rInventor = E3dInventor;
     613        5504 :         rType = (sal_uInt16)(nTempType & ~E3D_INVENTOR_FLAG);
     614             :     }
     615             :     else
     616             :     {
     617       59860 :         rInventor = SdrInventor;
     618       59860 :         rType = (sal_uInt16)nTempType;
     619             : 
     620       59860 :         switch( rType )
     621             :         {
     622             :             case OBJ_FRAME:
     623             :             case OBJ_OLE2_PLUGIN:
     624             :             case OBJ_OLE2_APPLET:
     625           0 :                 rType = OBJ_OLE2;
     626           0 :                 break;
     627             :         }
     628             :     }
     629       65380 : }
     630             : 
     631      125134 : SvxShape* SvxDrawPage::CreateShapeByTypeAndInventor( sal_uInt16 nType, sal_uInt32 nInventor, SdrObject *pObj, SvxDrawPage *mpPage, OUString const & referer )
     632             :     throw (css::uno::RuntimeException)
     633             : {
     634      125134 :     SvxShape* pRet = NULL;
     635      125134 :     switch( nInventor )
     636             :     {
     637             :         case E3dInventor:
     638             :         {
     639        5555 :             switch( nType )
     640             :             {
     641             :                 case E3D_SCENE_ID :
     642             :                 case E3D_POLYSCENE_ID :
     643        1447 :                     pRet = new Svx3DSceneObject( pObj, mpPage );
     644        1447 :                     break;
     645             :                 case E3D_CUBEOBJ_ID :
     646           2 :                     pRet = new Svx3DCubeObject( pObj );
     647           2 :                     break;
     648             :                 case E3D_SPHEREOBJ_ID :
     649           2 :                     pRet = new Svx3DSphereObject( pObj );
     650           2 :                     break;
     651             :                 case E3D_LATHEOBJ_ID :
     652          98 :                     pRet = new Svx3DLatheObject( pObj );
     653          98 :                     break;
     654             :                 case E3D_EXTRUDEOBJ_ID :
     655        3259 :                     pRet = new Svx3DExtrudeObject( pObj );
     656        3259 :                     break;
     657             :                 case E3D_POLYGONOBJ_ID :
     658         747 :                     pRet = new Svx3DPolygonObject( pObj );
     659         747 :                     break;
     660             :                 default: // unbekanntes 3D-Objekt auf der Page
     661           0 :                     pRet = new SvxShape( pObj );
     662           0 :                     break;
     663             :             }
     664        5555 :             break;
     665             :         }
     666             :         case SdrInventor:
     667             :         {
     668      119579 :             switch( nType )
     669             :             {
     670             :                 case OBJ_GRUP:
     671       34427 :                     pRet = new SvxShapeGroup( pObj, mpPage );
     672       34427 :                     break;
     673             :                 case OBJ_LINE:
     674        1867 :                     pRet = new SvxShapePolyPolygon( pObj , PolygonKind_LINE );
     675        1867 :                     break;
     676             :                 case OBJ_RECT:
     677       14716 :                     pRet = new SvxShapeRect( pObj );
     678       14716 :                     break;
     679             :                 case OBJ_CIRC:
     680             :                 case OBJ_SECT:
     681             :                 case OBJ_CARC:
     682             :                 case OBJ_CCUT:
     683         350 :                     pRet = new SvxShapeCircle( pObj );
     684         350 :                     break;
     685             :                 case OBJ_POLY:
     686       13074 :                     pRet = new SvxShapePolyPolygon( pObj , PolygonKind_POLY );
     687       13074 :                     break;
     688             :                 case OBJ_PLIN:
     689        7585 :                     pRet = new SvxShapePolyPolygon( pObj , PolygonKind_PLIN );
     690        7585 :                     break;
     691             :                 case OBJ_SPLNLINE:
     692             :                 case OBJ_PATHLINE:
     693         296 :                     pRet = new SvxShapePolyPolygonBezier( pObj , PolygonKind_PATHLINE );
     694         296 :                     break;
     695             :                 case OBJ_SPLNFILL:
     696             :                 case OBJ_PATHFILL:
     697        2290 :                     pRet = new SvxShapePolyPolygonBezier( pObj , PolygonKind_PATHFILL );
     698        2290 :                     break;
     699             :                 case OBJ_FREELINE:
     700           2 :                     pRet = new SvxShapePolyPolygonBezier( pObj , PolygonKind_FREELINE );
     701           2 :                     break;
     702             :                 case OBJ_FREEFILL:
     703           2 :                     pRet = new SvxShapePolyPolygonBezier( pObj , PolygonKind_FREEFILL );
     704           2 :                     break;
     705             :                 case OBJ_CAPTION:
     706          58 :                     pRet = new SvxShapeCaption( pObj );
     707          58 :                     break;
     708             :                 case OBJ_TITLETEXT:
     709             :                 case OBJ_OUTLINETEXT:
     710             :                 case OBJ_TEXT:
     711       25706 :                     pRet = new SvxShapeText( pObj );
     712       25706 :                     break;
     713             :                 case OBJ_GRAF:
     714        1342 :                     pRet = new SvxGraphicObject( pObj, referer );
     715        1342 :                     break;
     716             :                 case OBJ_FRAME:
     717           2 :                     pRet = new SvxFrameShape( pObj );
     718           2 :                     break;
     719             :                 case OBJ_OLE2_APPLET:
     720           2 :                     pRet = new SvxAppletShape( pObj );
     721           2 :                     break;
     722             :                 case OBJ_OLE2_PLUGIN:
     723           2 :                     pRet = new SvxPluginShape( pObj );
     724           2 :                     break;
     725             :                  case OBJ_OLE2:
     726             :                      {
     727         384 :                         if( pObj && !pObj->IsEmptyPresObj() && mpPage )
     728             :                         {
     729          60 :                             SdrPage* pSdrPage = mpPage->GetSdrPage();
     730          60 :                             if( pSdrPage )
     731             :                             {
     732          60 :                                 SdrModel* pSdrModel = pSdrPage->GetModel();
     733          60 :                                 if( pSdrModel )
     734             :                                 {
     735          60 :                                     ::comphelper::IEmbeddedHelper *pPersist = pSdrModel->GetPersist();
     736          60 :                                     if( pPersist )
     737             :                                     {
     738          60 :                                         uno::Reference < embed::XEmbeddedObject > xObject = pPersist->getEmbeddedObjectContainer().
     739         120 :                                                 GetEmbeddedObject( static_cast< SdrOle2Obj* >( pObj )->GetPersistName() );
     740             : 
     741             :                                         // TODO CL->KA: Why is this not working anymore?
     742          60 :                                         if( xObject.is() )
     743             :                                         {
     744          58 :                                             SvGlobalName aClassId( xObject->getClassID() );
     745             : 
     746         116 :                                             const SvGlobalName aAppletClassId( SO3_APPLET_CLASSID );
     747         116 :                                             const SvGlobalName aPluginClassId( SO3_PLUGIN_CLASSID );
     748         116 :                                             const SvGlobalName aIFrameClassId( SO3_IFRAME_CLASSID );
     749             : 
     750          58 :                                             if( aPluginClassId == aClassId )
     751             :                                             {
     752           0 :                                                 pRet = new SvxPluginShape( pObj );
     753           0 :                                                 nType = OBJ_OLE2_PLUGIN;
     754             :                                             }
     755          58 :                                             else if( aAppletClassId == aClassId )
     756             :                                             {
     757           0 :                                                 pRet = new SvxAppletShape( pObj );
     758           0 :                                                 nType = OBJ_OLE2_APPLET;
     759             :                                             }
     760          58 :                                             else if( aIFrameClassId == aClassId )
     761             :                                             {
     762           0 :                                                 pRet = new SvxFrameShape( pObj );
     763           0 :                                                 nType = OBJ_FRAME;
     764          58 :                                             }
     765          60 :                                         }
     766             :                                     }
     767             :                                 }
     768             :                             }
     769             :                         }
     770         384 :                         if( pRet == NULL )
     771             :                         {
     772         384 :                             SvxUnoPropertyMapProvider& rSvxMapProvider = getSvxMapProvider();
     773         384 :                             pRet = new SvxOle2Shape( pObj, rSvxMapProvider.GetMap(SVXMAP_OLE2),  rSvxMapProvider.GetPropertySet(SVXMAP_OLE2, SdrObject::GetGlobalDrawObjectItemPool()) );
     774             :                         }
     775             :                      }
     776         384 :                     break;
     777             :                 case OBJ_EDGE:
     778         122 :                     pRet = new SvxShapeConnector( pObj );
     779         122 :                     break;
     780             :                 case OBJ_PATHPOLY:
     781           2 :                     pRet = new SvxShapePolyPolygon( pObj , PolygonKind_PATHPOLY );
     782           2 :                     break;
     783             :                 case OBJ_PATHPLIN:
     784           2 :                     pRet = new SvxShapePolyPolygon( pObj , PolygonKind_PATHPLIN );
     785           2 :                     break;
     786             :                 case OBJ_PAGE:
     787             :                 {
     788        1970 :                     SvxUnoPropertyMapProvider& rSvxMapProvider = getSvxMapProvider();
     789        1970 :                     pRet = new SvxShape( pObj, rSvxMapProvider.GetMap(SVXMAP_PAGE),  rSvxMapProvider.GetPropertySet(SVXMAP_PAGE, SdrObject::GetGlobalDrawObjectItemPool()) );
     790             :                 }
     791        1970 :                     break;
     792             :                 case OBJ_MEASURE:
     793           6 :                     pRet = new SvxShapeDimensioning( pObj );
     794           6 :                     break;
     795             :                 case OBJ_UNO:
     796           0 :                     pRet = new SvxShapeControl( pObj );
     797           0 :                     break;
     798             :                 case OBJ_CUSTOMSHAPE:
     799       15304 :                     pRet = new SvxCustomShape( pObj );
     800       15304 :                     break;
     801             : #if HAVE_FEATURE_DESKTOP
     802             :                 case OBJ_MEDIA:
     803          38 :                     pRet = new SvxMediaShape( pObj, referer );
     804          38 :                     break;
     805             : #endif
     806             :                 case OBJ_TABLE:
     807          28 :                     pRet = new SvxTableShape( pObj );
     808          28 :                     break;
     809             :                 case OBJ_OPENGL:
     810           2 :                     pRet = new SvxOpenGLObject( pObj );
     811           2 :                     break;
     812             :                 default: // unbekanntes 2D-Objekt auf der Page
     813             :                     OSL_FAIL("Nicht implementierter Starone-Shape erzeugt! [CL]");
     814           0 :                     pRet = new SvxShapeText( pObj );
     815           0 :                     break;
     816             :             }
     817      119579 :             break;
     818             :         }
     819             :         default: // Unbekannter Inventor
     820             :         {
     821             :             OSL_FAIL("AW: Unknown Inventor in SvxDrawPage::_CreateShape()");
     822           0 :             break;
     823             :         }
     824             :     }
     825             : 
     826      125134 :     if(pRet)
     827             :     {
     828      125134 :         sal_uInt32 nObjId = nType;
     829             : 
     830      125134 :         if( nInventor == E3dInventor )
     831        5555 :             nObjId |= E3D_INVENTOR_FLAG;
     832             : 
     833      125134 :         switch(nObjId)
     834             :         {
     835             :         case OBJ_CCUT:          // Kreisabschnitt
     836             :         case OBJ_CARC:          // Kreisbogen
     837             :         case OBJ_SECT:          // Kreissektor
     838          70 :             nObjId = OBJ_CIRC;
     839          70 :             break;
     840             : 
     841             :         case E3D_SCENE_ID | E3D_INVENTOR_FLAG:
     842           0 :             nObjId = E3D_POLYSCENE_ID | E3D_INVENTOR_FLAG;
     843           0 :             break;
     844             : 
     845             :         case OBJ_TITLETEXT:
     846             :         case OBJ_OUTLINETEXT:
     847           0 :             nObjId = OBJ_TEXT;
     848           0 :             break;
     849             :         }
     850             : 
     851      125134 :         pRet->setShapeKind(nObjId);
     852             :     }
     853             : 
     854      125134 :     return pRet;
     855             : }
     856             : 
     857       50226 : Reference< drawing::XShape >  SvxDrawPage::_CreateShape( SdrObject *pObj ) const
     858             :     throw (css::uno::RuntimeException, std::exception)
     859             : {
     860       50226 :     Reference< drawing::XShape > xShape( CreateShapeByTypeAndInventor(pObj->GetObjIdentifier(),
     861       50226 :                                               pObj->GetObjInventor(),
     862             :                                               pObj,
     863      150678 :                                               (SvxDrawPage*)this));
     864       50226 :     return xShape;
     865             : }
     866             : 
     867        7818 : SdrObject *SvxDrawPage::CreateSdrObject( const Reference< drawing::XShape > & xShape, bool bBeginning ) throw()
     868             : {
     869        7818 :     SdrObject* pObj = _CreateSdrObject( xShape );
     870        7818 :     if( pObj)
     871             :     {
     872        7818 :         pObj->SetModel(mpModel);
     873        7818 :         if ( !pObj->IsInserted() && !pObj->IsDoNotInsertIntoPageAutomatically() )
     874             :         {
     875        6518 :             if(bBeginning)
     876         436 :                 mpPage->InsertObject( pObj, 0 );
     877             :             else
     878        6082 :                 mpPage->InsertObject( pObj );
     879             :         }
     880             :     }
     881             : 
     882        7818 :     return pObj;
     883             : }
     884             : 
     885             : // ::com::sun::star::lang::XServiceInfo
     886           0 : OUString SAL_CALL SvxDrawPage::getImplementationName() throw( uno::RuntimeException, std::exception )
     887             : {
     888           0 :     return OUString("SvxDrawPage");
     889             : }
     890             : 
     891           0 : sal_Bool SAL_CALL SvxDrawPage::supportsService( const OUString& ServiceName )
     892             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     893             : {
     894           0 :     return cppu::supportsService( this, ServiceName );
     895             : }
     896             : 
     897         316 : uno::Sequence< OUString > SAL_CALL SvxDrawPage::getSupportedServiceNames() throw( uno::RuntimeException, std::exception )
     898             : {
     899         316 :     uno::Sequence< OUString > aSeq( 1 );
     900         316 :     aSeq.getArray()[0] = "com.sun.star.drawing.ShapeCollection";
     901         316 :     return aSeq;
     902             : }
     903             : 
     904        1316 : SvxShape* CreateSvxShapeByTypeAndInventor(sal_uInt16 nType, sal_uInt32 nInventor, OUString const & referer)
     905             :     throw (css::uno::RuntimeException, std::exception)
     906             : {
     907        1316 :     return SvxDrawPage::CreateShapeByTypeAndInventor( nType, nInventor, 0, 0, referer );
     908             : }
     909             : 
     910           0 : void SvxDrawPage::ChangeModel( SdrModel* pNewModel )
     911             : {
     912           0 :     if( pNewModel != mpModel )
     913             :     {
     914           0 :         if( mpModel )
     915           0 :             EndListening( *mpModel );
     916             : 
     917           0 :         if( pNewModel )
     918           0 :             StartListening( *pNewModel );
     919             : 
     920           0 :         mpModel = pNewModel;
     921             : 
     922           0 :         if( mpView )
     923             :         {
     924           0 :             delete mpView;
     925           0 :             mpView = new SdrView( mpModel );
     926           0 :             if( mpView )
     927           0 :                 mpView->SetDesignMode(true);
     928             :         }
     929             :     }
     930           0 : }
     931             : 
     932             : /** returns a StarOffice API wrapper for the given SdrPage */
     933       85776 : uno::Reference< drawing::XDrawPage > GetXDrawPageForSdrPage( SdrPage* pPage ) throw ()
     934             : {
     935       85776 :     if(pPage)
     936             :     {
     937       85722 :         uno::Reference< drawing::XDrawPage > xDrawPage( pPage->getUnoPage(), uno::UNO_QUERY );
     938             : 
     939       85722 :         return xDrawPage;
     940             :     }
     941             : 
     942          54 :     return uno::Reference< drawing::XDrawPage >();
     943             : }
     944             : 
     945             : /** returns the SdrObject from the given StarOffice API wrapper */
     946       15448 : SdrPage* GetSdrPageFromXDrawPage( uno::Reference< drawing::XDrawPage > xDrawPage ) throw()
     947             : {
     948       15448 :     if(xDrawPage.is())
     949             :     {
     950        2908 :         SvxDrawPage* pDrawPage = SvxDrawPage::getImplementation( xDrawPage );
     951             : 
     952        2908 :         if(pDrawPage)
     953             :         {
     954        2908 :             return pDrawPage->GetSdrPage();
     955             :         }
     956             :     }
     957             : 
     958       12540 :     return NULL;
     959         651 : }
     960             : 
     961             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10