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

Generated by: LCOV version 1.11