LCOV - code coverage report
Current view: top level - sd/source/ui/unoidl - unolayer.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 362 0.0 %
Date: 2014-04-14 Functions: 0 54 0.0 %
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 <com/sun/star/lang/DisposedException.hpp>
      21             : 
      22             : #include "unolayer.hxx"
      23             : #include <osl/mutex.hxx>
      24             : 
      25             : #include <svx/svdpagv.hxx>
      26             : #include <svx/unoshape.hxx>
      27             : #include <svx/svdobj.hxx>
      28             : #include <cppuhelper/supportsservice.hxx>
      29             : 
      30             : // following ones for InsertSdPage()
      31             : #include <svx/svdlayer.hxx>
      32             : 
      33             : #include "DrawDocShell.hxx"
      34             : #include <drawdoc.hxx>
      35             : #include <unomodel.hxx>
      36             : #include "unoprnms.hxx"
      37             : #include <com/sun/star/lang/NoSupportException.hpp>
      38             : #include <svx/svdpool.hxx>
      39             : #include "unohelp.hxx"
      40             : #include "FrameView.hxx"
      41             : #include "DrawViewShell.hxx"
      42             : #include "View.hxx"
      43             : #include "ViewShell.hxx"
      44             : #include "app.hrc"
      45             : #include "strings.hrc"
      46             : #include "sdresid.hxx"
      47             : #include "glob.hrc"
      48             : 
      49             : #include "unokywds.hxx"
      50             : #include "unowcntr.hxx"
      51             : #include <vcl/svapp.hxx>
      52             : 
      53             : using namespace ::rtl;
      54             : using namespace ::com::sun::star;
      55             : 
      56             : 
      57             : // class SdLayer
      58             : #define WID_LAYER_LOCKED    1
      59             : #define WID_LAYER_PRINTABLE 2
      60             : #define WID_LAYER_VISIBLE   3
      61             : #define WID_LAYER_NAME      4
      62             : #define WID_LAYER_TITLE     5
      63             : #define WID_LAYER_DESC      6
      64             : 
      65           0 : const SvxItemPropertySet* ImplGetSdLayerPropertySet()
      66             : {
      67             :     static const SfxItemPropertyMapEntry aSdLayerPropertyMap_Impl[] =
      68             :     {
      69           0 :         { OUString(UNO_NAME_LAYER_LOCKED),      WID_LAYER_LOCKED,   ::getBooleanCppuType(),            0, 0 },
      70           0 :         { OUString(UNO_NAME_LAYER_PRINTABLE),   WID_LAYER_PRINTABLE,::getBooleanCppuType(),            0, 0 },
      71           0 :         { OUString(UNO_NAME_LAYER_VISIBLE),     WID_LAYER_VISIBLE,  ::getBooleanCppuType(),            0, 0 },
      72           0 :         { OUString(UNO_NAME_LAYER_NAME),        WID_LAYER_NAME,     ::getCppuType((const OUString*)0), 0, 0 },
      73           0 :         { OUString("Title"),                    WID_LAYER_TITLE,    ::getCppuType((const OUString*)0), 0, 0 },
      74           0 :         { OUString("Description"),              WID_LAYER_DESC,     ::getCppuType((const OUString*)0), 0, 0 },
      75             :         { OUString(), 0, css::uno::Type(), 0, 0 }
      76           0 :     };
      77           0 :     static SvxItemPropertySet aSDLayerPropertySet_Impl( aSdLayerPropertyMap_Impl, SdrObject::GetGlobalDrawObjectItemPool() );
      78           0 :     return &aSDLayerPropertySet_Impl;
      79             : }
      80             : 
      81           0 : OUString SdLayer::convertToInternalName( const OUString& rName )
      82             : {
      83           0 :     if ( rName == sUNO_LayerName_background )
      84             :     {
      85           0 :         return SD_RESSTR( STR_LAYER_BCKGRND );
      86             :     }
      87           0 :     else if ( rName == sUNO_LayerName_background_objects )
      88             :     {
      89           0 :         return  SD_RESSTR( STR_LAYER_BCKGRNDOBJ );
      90             :     }
      91           0 :     else if ( rName == sUNO_LayerName_layout )
      92             :     {
      93           0 :         return  SD_RESSTR( STR_LAYER_LAYOUT );
      94             :     }
      95           0 :     else if ( rName == sUNO_LayerName_controls )
      96             :     {
      97           0 :         return  SD_RESSTR( STR_LAYER_CONTROLS );
      98             :     }
      99           0 :     else if ( rName == sUNO_LayerName_measurelines )
     100             :     {
     101           0 :         return  SD_RESSTR( STR_LAYER_MEASURELINES );
     102             :     }
     103             :     else
     104             :     {
     105           0 :         return rName;
     106             :     }
     107             : }
     108             : 
     109           0 : OUString SdLayer::convertToExternalName( const OUString& rName )
     110             : {
     111           0 :     if( rName == SD_RESSTR( STR_LAYER_BCKGRND ) )
     112             :     {
     113           0 :         return OUString( sUNO_LayerName_background );
     114             :     }
     115           0 :     else if( rName == SD_RESSTR( STR_LAYER_BCKGRNDOBJ ) )
     116             :     {
     117           0 :         return OUString( sUNO_LayerName_background_objects );
     118             :     }
     119           0 :     else if( rName == SD_RESSTR( STR_LAYER_LAYOUT ) )
     120             :     {
     121           0 :         return OUString( sUNO_LayerName_layout );
     122             :     }
     123           0 :     else if( rName == SD_RESSTR( STR_LAYER_CONTROLS ) )
     124             :     {
     125           0 :         return OUString( sUNO_LayerName_controls );
     126             :     }
     127           0 :     else if( rName == SD_RESSTR( STR_LAYER_MEASURELINES ) )
     128             :     {
     129           0 :         return OUString( sUNO_LayerName_measurelines );
     130             :     }
     131             :     else
     132             :     {
     133           0 :         return rName;
     134             :     }
     135             : }
     136             : 
     137           0 : SdLayer::SdLayer( SdLayerManager* pLayerManager_, SdrLayer* pSdrLayer_ ) throw()
     138             : : pLayerManager(pLayerManager_)
     139             : , mxLayerManager(pLayerManager_)
     140             : , pLayer(pSdrLayer_)
     141           0 : , pPropSet(ImplGetSdLayerPropertySet())
     142             : {
     143           0 : }
     144             : 
     145           0 : SdLayer::~SdLayer() throw()
     146             : {
     147           0 : }
     148             : 
     149             : // uno helper
     150           0 : UNO3_GETIMPLEMENTATION_IMPL( SdLayer );
     151             : 
     152             : // XServiceInfo
     153           0 : OUString SAL_CALL SdLayer::getImplementationName()
     154             :     throw(uno::RuntimeException, std::exception)
     155             : {
     156           0 :     return OUString( OUString::createFromAscii(sUNO_SdLayer) );
     157             : }
     158             : 
     159           0 : sal_Bool SAL_CALL SdLayer::supportsService( const OUString& ServiceName )
     160             :     throw(uno::RuntimeException, std::exception)
     161             : {
     162           0 :     return cppu::supportsService( this, ServiceName );
     163             : }
     164             : 
     165           0 : uno::Sequence< OUString > SAL_CALL SdLayer::getSupportedServiceNames()
     166             :     throw(uno::RuntimeException, std::exception)
     167             : {
     168           0 :     OUString aServiceName( OUString::createFromAscii(sUNO_Service_DrawingLayer) );
     169           0 :     uno::Sequence< OUString > aSeq( &aServiceName, 1 );
     170           0 :     return aSeq;
     171             : }
     172             : 
     173             : // beans::XPropertySet
     174           0 : uno::Reference< beans::XPropertySetInfo > SAL_CALL SdLayer::getPropertySetInfo(  )
     175             :     throw(uno::RuntimeException, std::exception)
     176             : {
     177           0 :     SolarMutexGuard aGuard;
     178           0 :     return pPropSet->getPropertySetInfo();
     179             : }
     180             : 
     181           0 : void SAL_CALL SdLayer::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue )
     182             :     throw(beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
     183             : {
     184           0 :     SolarMutexGuard aGuard;
     185             : 
     186           0 :     if(pLayer == NULL || pLayerManager == NULL)
     187           0 :         throw lang::DisposedException();
     188             : 
     189           0 :     const SfxItemPropertySimpleEntry* pEntry = pPropSet->getPropertyMapEntry(aPropertyName);
     190             : 
     191           0 :     switch( pEntry ? pEntry->nWID : -1 )
     192             :     {
     193             :     case WID_LAYER_LOCKED:
     194             :     {
     195           0 :         sal_Bool bValue = sal_False;
     196           0 :         if(!sd::any2bool( aValue, bValue ))
     197           0 :             throw lang::IllegalArgumentException();
     198           0 :         set( LOCKED, bValue );
     199           0 :         break;
     200             :     }
     201             :     case WID_LAYER_PRINTABLE:
     202             :     {
     203           0 :         sal_Bool bValue = sal_False;
     204           0 :         if(!sd::any2bool( aValue, bValue ))
     205           0 :             throw lang::IllegalArgumentException();
     206           0 :         set( PRINTABLE, bValue );
     207           0 :         break;
     208             :     }
     209             :     case WID_LAYER_VISIBLE:
     210             :     {
     211           0 :         sal_Bool bValue = sal_False;
     212           0 :         if(!sd::any2bool( aValue, bValue ))
     213           0 :             throw lang::IllegalArgumentException();
     214           0 :         set( VISIBLE, bValue );
     215           0 :         break;
     216             :     }
     217             :     case WID_LAYER_NAME:
     218             :     {
     219           0 :         OUString aName;
     220           0 :         if(!(aValue >>= aName))
     221           0 :             throw lang::IllegalArgumentException();
     222             : 
     223           0 :         pLayer->SetName(SdLayer::convertToInternalName( aName ) );
     224           0 :         pLayerManager->UpdateLayerView();
     225           0 :         break;
     226             :     }
     227             : 
     228             :     case WID_LAYER_TITLE:
     229             :     {
     230           0 :         OUString sTitle;
     231           0 :         if(!(aValue >>= sTitle))
     232           0 :             throw lang::IllegalArgumentException();
     233             : 
     234           0 :         pLayer->SetTitle(sTitle);
     235           0 :         break;
     236             :     }
     237             : 
     238             :     case WID_LAYER_DESC:
     239             :     {
     240           0 :         OUString sDescription;
     241           0 :         if(!(aValue >>= sDescription))
     242           0 :             throw lang::IllegalArgumentException();
     243             : 
     244           0 :         pLayer->SetDescription(sDescription);
     245           0 :         break;
     246             :     }
     247             : 
     248             :     default:
     249           0 :         throw beans::UnknownPropertyException();
     250             :     }
     251             : 
     252           0 :     if( pLayerManager->GetDocShell() )
     253           0 :         pLayerManager->GetDocShell()->SetModified();
     254           0 : }
     255             : 
     256           0 : uno::Any SAL_CALL SdLayer::getPropertyValue( const OUString& PropertyName )
     257             :     throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
     258             : {
     259           0 :     SolarMutexGuard aGuard;
     260             : 
     261           0 :     if(pLayer == NULL || pLayerManager == NULL)
     262           0 :         throw lang::DisposedException();
     263             : 
     264           0 :     const SfxItemPropertySimpleEntry* pEntry = pPropSet->getPropertyMapEntry(PropertyName);
     265             : 
     266           0 :     uno::Any aValue;
     267             : 
     268           0 :     switch( pEntry ? pEntry->nWID : -1 )
     269             :     {
     270             :     case WID_LAYER_LOCKED:
     271           0 :         sd::bool2any( get( LOCKED ), aValue );
     272           0 :         break;
     273             :     case WID_LAYER_PRINTABLE:
     274           0 :         sd::bool2any( get( PRINTABLE ), aValue );
     275           0 :         break;
     276             :     case WID_LAYER_VISIBLE:
     277           0 :         sd::bool2any( get( VISIBLE ), aValue );
     278           0 :         break;
     279             :     case WID_LAYER_NAME:
     280             :     {
     281           0 :         OUString aRet( SdLayer::convertToExternalName( pLayer->GetName() ) );
     282           0 :         aValue <<= aRet;
     283           0 :         break;
     284             :     }
     285             :     case WID_LAYER_TITLE:
     286           0 :         aValue <<= OUString( pLayer->GetTitle() );
     287           0 :         break;
     288             :     case WID_LAYER_DESC:
     289           0 :         aValue <<= OUString( pLayer->GetDescription() );
     290           0 :         break;
     291             :     default:
     292           0 :         throw beans::UnknownPropertyException();
     293             :     }
     294             : 
     295           0 :     return aValue;
     296             : }
     297             : 
     298           0 : void SAL_CALL SdLayer::addPropertyChangeListener( const OUString& , const uno::Reference< beans::XPropertyChangeListener >& ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception) {}
     299           0 : void SAL_CALL SdLayer::removePropertyChangeListener( const OUString& , const uno::Reference< beans::XPropertyChangeListener >& ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception) {}
     300           0 : void SAL_CALL SdLayer::addVetoableChangeListener( const OUString& , const uno::Reference< beans::XVetoableChangeListener >& ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception) {}
     301           0 : void SAL_CALL SdLayer::removeVetoableChangeListener( const OUString& , const uno::Reference< beans::XVetoableChangeListener >& ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception) {}
     302             : 
     303           0 : sal_Bool SdLayer::get( LayerAttribute what ) throw()
     304             : {
     305           0 :     if(pLayer&&pLayerManager)
     306             :     {
     307             :         // Try 1. is an arbitrary page open?
     308           0 :         ::sd::View *pView = pLayerManager->GetView();
     309           0 :         SdrPageView* pSdrPageView = NULL;
     310           0 :         if(pView)
     311           0 :             pSdrPageView = pView->GetSdrPageView();
     312             : 
     313           0 :         if(pSdrPageView)
     314             :         {
     315           0 :             OUString aLayerName = pLayer->GetName();
     316           0 :             switch(what)
     317             :             {
     318           0 :             case VISIBLE:   return pSdrPageView->IsLayerVisible(aLayerName);
     319           0 :             case PRINTABLE: return pSdrPageView->IsLayerPrintable(aLayerName);
     320           0 :             case LOCKED:    return pSdrPageView->IsLayerLocked(aLayerName);
     321           0 :             }
     322             :         }
     323             : 
     324             :         // Try 2. get info from FrameView
     325           0 :         if(pLayerManager->GetDocShell())
     326             :         {
     327           0 :             ::sd::FrameView *pFrameView = pLayerManager->GetDocShell()->GetFrameView();
     328           0 :             if(pFrameView)
     329           0 :                 switch(what)
     330             :                 {
     331           0 :                 case VISIBLE:   return pFrameView->GetVisibleLayers().IsSet(pLayer->GetID());
     332           0 :                 case PRINTABLE: return pFrameView->GetPrintableLayers().IsSet(pLayer->GetID());
     333           0 :                 case LOCKED:    return pFrameView->GetLockedLayers().IsSet(pLayer->GetID());
     334             :                 }
     335             :         }
     336             :     }
     337           0 :     return sal_False; //TODO: uno::Exception?
     338             : }
     339             : 
     340           0 : void SdLayer::set( LayerAttribute what, sal_Bool flag ) throw()
     341             : {
     342           0 :     if(pLayer&&pLayerManager)
     343             :     {
     344             :         // Try 1. is an arbitrary page open?
     345           0 :         ::sd::View *pView = pLayerManager->GetView();
     346           0 :         SdrPageView* pSdrPageView = NULL;
     347           0 :         if(pView)
     348           0 :             pSdrPageView = pView->GetSdrPageView();
     349             : 
     350           0 :         if(pSdrPageView)
     351             :         {
     352           0 :             OUString aLayerName(pLayer->GetName());
     353           0 :             switch(what)
     354             :             {
     355           0 :             case VISIBLE:   pSdrPageView->SetLayerVisible(aLayerName,flag);
     356           0 :                             break;
     357           0 :             case PRINTABLE: pSdrPageView->SetLayerPrintable(aLayerName,flag);
     358           0 :                             break;
     359           0 :             case LOCKED:    pSdrPageView->SetLayerLocked(aLayerName,flag);
     360           0 :                             break;
     361           0 :             }
     362             :         }
     363             : 
     364             :         // Try 2. get info from FrameView
     365           0 :         if(pLayerManager->GetDocShell())
     366             :         {
     367           0 :             ::sd::FrameView *pFrameView = pLayerManager->GetDocShell()->GetFrameView();
     368             : 
     369           0 :             if(pFrameView)
     370             :             {
     371           0 :                 SetOfByte aNewLayers;
     372           0 :                 switch(what)
     373             :                 {
     374           0 :                 case VISIBLE:   aNewLayers = pFrameView->GetVisibleLayers();
     375           0 :                                 break;
     376           0 :                 case PRINTABLE: aNewLayers = pFrameView->GetPrintableLayers();
     377           0 :                                 break;
     378           0 :                 case LOCKED:    aNewLayers = pFrameView->GetLockedLayers();
     379           0 :                                 break;
     380             :                 }
     381             : 
     382           0 :                 aNewLayers.Set(pLayer->GetID(),flag);
     383             : 
     384           0 :                 switch(what)
     385             :                 {
     386           0 :                 case VISIBLE:   pFrameView->SetVisibleLayers(aNewLayers);
     387           0 :                                 break;
     388           0 :                 case PRINTABLE: pFrameView->SetPrintableLayers(aNewLayers);
     389           0 :                                 break;
     390           0 :                 case LOCKED:    pFrameView->SetLockedLayers(aNewLayers);
     391           0 :                                 break;
     392             :                 }
     393           0 :                 return;
     394             :             }
     395             :         }
     396             :     }
     397             :     //TODO: uno::Exception?
     398             : }
     399             : 
     400             : // ::com::sun::star::container::XChild
     401           0 : uno::Reference<uno::XInterface> SAL_CALL SdLayer::getParent (void)
     402             :     throw (::com::sun::star::uno::RuntimeException, std::exception)
     403             : {
     404           0 :     SolarMutexGuard aGuard;
     405             : 
     406           0 :     if( pLayerManager == NULL )
     407           0 :         throw lang::DisposedException();
     408             : 
     409           0 :     return uno::Reference<uno::XInterface> (mxLayerManager, uno::UNO_QUERY);
     410             : }
     411             : 
     412             : 
     413           0 : void SAL_CALL SdLayer::setParent (const uno::Reference<uno::XInterface >& )
     414             :     throw (::com::sun::star::lang::NoSupportException,
     415             :         ::com::sun::star::uno::RuntimeException, std::exception)
     416             : {
     417           0 :     throw lang::NoSupportException ();
     418             : }
     419             : 
     420             : // XComponent
     421           0 : void SAL_CALL SdLayer::dispose(  ) throw (uno::RuntimeException, std::exception)
     422             : {
     423           0 :     pLayerManager = 0;
     424           0 :     mxLayerManager = 0;
     425           0 :     pLayer = 0;
     426           0 : }
     427             : 
     428           0 : void SAL_CALL SdLayer::addEventListener( const uno::Reference< lang::XEventListener >& ) throw (uno::RuntimeException, std::exception)
     429             : {
     430             :     OSL_FAIL("not implemented!");
     431           0 : }
     432             : 
     433           0 : void SAL_CALL SdLayer::removeEventListener( const uno::Reference< lang::XEventListener >& ) throw (uno::RuntimeException, std::exception)
     434             : {
     435             :     OSL_FAIL("not implemented!");
     436           0 : }
     437             : 
     438             : 
     439             : 
     440             : // class SdLayerManager
     441           0 : SdLayerManager::SdLayerManager( SdXImpressDocument& rMyModel ) throw()
     442           0 : :mpModel( &rMyModel)
     443             : {
     444           0 :     mpLayers = new SvUnoWeakContainer;
     445           0 : }
     446             : 
     447           0 : SdLayerManager::~SdLayerManager() throw()
     448             : {
     449           0 :     dispose();
     450           0 : }
     451             : 
     452             : // uno helper
     453           0 : UNO3_GETIMPLEMENTATION_IMPL( SdLayerManager );
     454             : 
     455             : // XComponent
     456           0 : void SAL_CALL SdLayerManager::dispose(  ) throw (uno::RuntimeException, std::exception)
     457             : {
     458           0 :     mpModel = 0;
     459           0 :     if( mpLayers )
     460             :     {
     461           0 :         mpLayers->dispose();
     462             : 
     463           0 :         delete mpLayers;
     464           0 :         mpLayers = 0;
     465             :     }
     466           0 : }
     467             : 
     468           0 : void SAL_CALL SdLayerManager::addEventListener( const uno::Reference< lang::XEventListener >& ) throw (uno::RuntimeException, std::exception)
     469             : {
     470             :     OSL_FAIL("not implemented!");
     471           0 : }
     472             : 
     473           0 : void SAL_CALL SdLayerManager::removeEventListener( const uno::Reference< lang::XEventListener >& ) throw (uno::RuntimeException, std::exception)
     474             : {
     475             :     OSL_FAIL("not implemented!");
     476           0 : }
     477             : 
     478             : // XServiceInfo
     479           0 : OUString SAL_CALL SdLayerManager::getImplementationName()
     480             :     throw(uno::RuntimeException, std::exception)
     481             : {
     482           0 :     return OUString( OUString::createFromAscii(sUNO_SdLayerManager) );
     483             : }
     484             : 
     485           0 : sal_Bool SAL_CALL SdLayerManager::supportsService( const OUString& ServiceName )
     486             :     throw(uno::RuntimeException, std::exception)
     487             : {
     488           0 :     return cppu::supportsService( this, ServiceName );
     489             : }
     490             : 
     491           0 : uno::Sequence< OUString > SAL_CALL SdLayerManager::getSupportedServiceNames()
     492             :     throw(uno::RuntimeException, std::exception)
     493             : {
     494           0 :     OUString aServiceName( OUString::createFromAscii(sUNO_Service_DrawingLayerManager) );
     495           0 :     uno::Sequence< OUString > aSeq( &aServiceName, 1 );
     496           0 :     return aSeq;
     497             : }
     498             : 
     499             : // XLayerManager
     500           0 : uno::Reference< drawing::XLayer > SAL_CALL SdLayerManager::insertNewByIndex( sal_Int32 nIndex )
     501             :     throw(uno::RuntimeException, std::exception)
     502             : {
     503           0 :     SolarMutexGuard aGuard;
     504             : 
     505           0 :     if( mpModel == 0 )
     506           0 :         throw lang::DisposedException();
     507             : 
     508           0 :     uno::Reference< drawing::XLayer > xLayer;
     509             : 
     510           0 :     if( mpModel->mpDoc )
     511             :     {
     512           0 :         SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin();
     513           0 :         sal_uInt16 nLayerCnt = rLayerAdmin.GetLayerCount();
     514           0 :         sal_Int32 nLayer = nLayerCnt - 2 + 1;
     515           0 :         OUString aLayerName;
     516             : 
     517             :         // Test for existing names
     518           0 :         while( aLayerName.isEmpty() || rLayerAdmin.GetLayer( aLayerName, false) )
     519             :         {
     520           0 :             aLayerName = SD_RESSTR(STR_LAYER);
     521           0 :             aLayerName += OUString::number(nLayer);
     522           0 :             ++nLayer;
     523             :         }
     524             : 
     525           0 :         SdrLayerAdmin& rLA=mpModel->mpDoc->GetLayerAdmin();
     526           0 :         const sal_Int32 nMax=rLA.GetLayerCount();
     527           0 :         if (nIndex>nMax) nIndex=nMax;
     528           0 :         xLayer = GetLayer (rLA.NewLayer(aLayerName,(sal_uInt16)nIndex));
     529           0 :         mpModel->SetModified();
     530             :     }
     531           0 :     return xLayer;
     532             : }
     533             : 
     534           0 : void SAL_CALL SdLayerManager::remove( const uno::Reference< drawing::XLayer >& xLayer )
     535             :     throw(container::NoSuchElementException, uno::RuntimeException, std::exception)
     536             : {
     537           0 :     SolarMutexGuard aGuard;
     538             : 
     539           0 :     if( mpModel == 0 )
     540           0 :         throw lang::DisposedException();
     541             : 
     542           0 :     SdLayer* pSdLayer = SdLayer::getImplementation(xLayer);
     543             : 
     544           0 :     if(pSdLayer && GetView())
     545             :     {
     546           0 :         const SdrLayer* pSdrLayer = pSdLayer->GetSdrLayer();
     547           0 :         GetView()->DeleteLayer( pSdrLayer->GetName() );
     548             : 
     549           0 :         UpdateLayerView();
     550             :     }
     551             : 
     552           0 :     mpModel->SetModified();
     553           0 : }
     554             : 
     555           0 : void SAL_CALL SdLayerManager::attachShapeToLayer( const uno::Reference< drawing::XShape >& xShape, const uno::Reference< drawing::XLayer >& xLayer )
     556             :     throw(uno::RuntimeException, std::exception)
     557             : {
     558           0 :     SolarMutexGuard aGuard;
     559             : 
     560           0 :     if( mpModel == 0 )
     561           0 :         throw lang::DisposedException();
     562             : 
     563           0 :     SdLayer* pSdLayer = SdLayer::getImplementation(xLayer);
     564           0 :     SdrLayer* pSdrLayer = pSdLayer?pSdLayer->GetSdrLayer():NULL;
     565           0 :     if(pSdrLayer==NULL)
     566           0 :         return;
     567             : 
     568           0 :     SvxShape* pShape = SvxShape::getImplementation( xShape );
     569           0 :     SdrObject* pSdrObject = pShape?pShape->GetSdrObject():NULL;
     570             : 
     571           0 :     if(pSdrObject && pSdrLayer )
     572           0 :         pSdrObject->SetLayer(pSdrLayer->GetID());
     573             : 
     574           0 :     mpModel->SetModified();
     575             : }
     576             : 
     577           0 : uno::Reference< drawing::XLayer > SAL_CALL SdLayerManager::getLayerForShape( const uno::Reference< drawing::XShape >& xShape ) throw(uno::RuntimeException, std::exception)
     578             : {
     579           0 :     SolarMutexGuard aGuard;
     580             : 
     581           0 :     if( mpModel == 0 )
     582           0 :         throw lang::DisposedException();
     583             : 
     584           0 :     uno::Reference< drawing::XLayer >  xLayer;
     585             : 
     586           0 :     if(mpModel->mpDoc)
     587             :     {
     588           0 :         SvxShape* pShape = SvxShape::getImplementation( xShape );
     589           0 :         SdrObject* pObj = pShape?pShape->GetSdrObject():NULL;
     590           0 :         if(pObj)
     591             :         {
     592           0 :             SdrLayerID aId = pObj->GetLayer();
     593           0 :             SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin();
     594           0 :             xLayer = GetLayer (rLayerAdmin.GetLayerPerID(aId));
     595             :         }
     596             :     }
     597           0 :     return xLayer;
     598             : }
     599             : 
     600             : // XIndexAccess
     601           0 : sal_Int32 SAL_CALL SdLayerManager::getCount()
     602             :     throw(uno::RuntimeException, std::exception)
     603             : {
     604           0 :     SolarMutexGuard aGuard;
     605             : 
     606           0 :     if( mpModel == 0 )
     607           0 :         throw lang::DisposedException();
     608             : 
     609           0 :     if( mpModel->mpDoc )
     610             :     {
     611           0 :         SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin();
     612           0 :         return rLayerAdmin.GetLayerCount();
     613             :     }
     614             : 
     615           0 :     return 0;
     616             : }
     617             : 
     618           0 : uno::Any SAL_CALL SdLayerManager::getByIndex( sal_Int32 nLayer )
     619             :     throw(lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
     620             : {
     621           0 :     SolarMutexGuard aGuard;
     622             : 
     623           0 :     if( mpModel == 0 )
     624           0 :         throw lang::DisposedException();
     625             : 
     626           0 :     if( nLayer >= getCount() || nLayer < 0 )
     627           0 :         throw lang::IndexOutOfBoundsException();
     628             : 
     629           0 :     uno::Any aAny;
     630             : 
     631           0 :     if( mpModel->mpDoc )
     632             :     {
     633           0 :         SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin();
     634           0 :         uno::Reference<drawing::XLayer> xLayer (GetLayer (rLayerAdmin.GetLayer((sal_uInt16)nLayer)));
     635           0 :         aAny <<= xLayer;
     636             :     }
     637           0 :     return aAny;
     638             : }
     639             : 
     640             : // XNameAccess
     641           0 : uno::Any SAL_CALL SdLayerManager::getByName( const OUString& aName )
     642             :     throw(container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
     643             : {
     644           0 :     SolarMutexGuard aGuard;
     645             : 
     646           0 :     if( (mpModel == 0) || (mpModel->mpDoc == 0 ) )
     647           0 :         throw lang::DisposedException();
     648             : 
     649           0 :     SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin();
     650           0 :     SdrLayer* pLayer = rLayerAdmin.GetLayer( SdLayer::convertToInternalName( aName ), false );
     651           0 :     if( pLayer == NULL )
     652           0 :         throw container::NoSuchElementException();
     653             : 
     654           0 :     return uno::Any( GetLayer (pLayer) );
     655             : }
     656             : 
     657           0 : uno::Sequence< OUString > SAL_CALL SdLayerManager::getElementNames()
     658             :     throw(uno::RuntimeException, std::exception)
     659             : {
     660           0 :     SolarMutexGuard aGuard;
     661             : 
     662           0 :     if( mpModel == 0 )
     663           0 :         throw lang::DisposedException();
     664             : 
     665           0 :     SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin();
     666           0 :     const sal_uInt16 nLayerCount = rLayerAdmin.GetLayerCount();
     667             : 
     668           0 :     uno::Sequence< OUString > aSeq( nLayerCount );
     669             : 
     670           0 :     OUString* pStrings = aSeq.getArray();
     671             :     SdrLayer* pLayer;
     672             : 
     673           0 :     for( sal_uInt16 nLayer = 0; nLayer < nLayerCount; nLayer++ )
     674             :     {
     675           0 :         pLayer = rLayerAdmin.GetLayer( nLayer );
     676           0 :         if( pLayer )
     677           0 :             *pStrings++ = SdLayer::convertToExternalName( pLayer->GetName() );
     678             :     }
     679             : 
     680           0 :     return aSeq;
     681             : }
     682             : 
     683           0 : sal_Bool SAL_CALL SdLayerManager::hasByName( const OUString& aName ) throw(uno::RuntimeException, std::exception)
     684             : {
     685           0 :     SolarMutexGuard aGuard;
     686             : 
     687           0 :     if( mpModel == 0 )
     688           0 :         throw lang::DisposedException();
     689             : 
     690           0 :     SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin();
     691             : 
     692           0 :     return NULL != rLayerAdmin.GetLayer( SdLayer::convertToInternalName( aName ), false );
     693             : }
     694             : 
     695             : // XElementAccess
     696           0 : uno::Type SAL_CALL SdLayerManager::getElementType()
     697             :     throw(uno::RuntimeException, std::exception)
     698             : {
     699           0 :     return cppu::UnoType<drawing::XLayer>::get();
     700             : }
     701             : 
     702           0 : sal_Bool SAL_CALL SdLayerManager::hasElements() throw(uno::RuntimeException, std::exception)
     703             : {
     704           0 :     return getCount() > 0;
     705             : }
     706             : 
     707             : /**
     708             :  * If something was changed at the layers, this methods takes care that the
     709             :  * changes are made visible in sdbcx::View.
     710             :  */
     711           0 : void SdLayerManager::UpdateLayerView( sal_Bool modify ) const throw()
     712             : {
     713           0 :     if(mpModel->mpDocShell)
     714             :     {
     715             :         ::sd::DrawViewShell* pDrViewSh =
     716           0 :             PTR_CAST(::sd::DrawViewShell, mpModel->mpDocShell->GetViewShell());
     717             : 
     718           0 :         if(pDrViewSh)
     719             :         {
     720           0 :             sal_Bool bLayerMode = pDrViewSh->IsLayerModeActive();
     721           0 :             pDrViewSh->ChangeEditMode(pDrViewSh->GetEditMode(), !bLayerMode);
     722           0 :             pDrViewSh->ChangeEditMode(pDrViewSh->GetEditMode(), bLayerMode);
     723             :         }
     724             : 
     725           0 :         if(modify)
     726           0 :             mpModel->mpDoc->SetChanged(true);
     727             :     }
     728           0 : }
     729             : 
     730             : /** */
     731           0 : ::sd::View* SdLayerManager::GetView() const throw()
     732             : {
     733           0 :     if( mpModel->mpDocShell )
     734             :     {
     735           0 :         ::sd::ViewShell* pViewSh = mpModel->mpDocShell->GetViewShell();
     736           0 :         if(pViewSh)
     737           0 :             return pViewSh->GetView();
     738             :     }
     739           0 :     return NULL;
     740             : }
     741             : 
     742             : 
     743             : 
     744             : namespace
     745             : {
     746             : /** Compare two pointers to <type>SdrLayer</type> objects.
     747             :     @param xRef
     748             :         The implementing SdLayer class provides the first pointer by the
     749             :         <member>SdLayer::GetSdrLayer</member> method.
     750             :     @param pSearchData
     751             :         This void pointer is the second pointer to an <type>SdrLayer</type>
     752             :         object.
     753             :     @return
     754             :         Return </True> if both pointers point to the same object.
     755             : */
     756           0 : sal_Bool compare_layers (uno::WeakReference<uno::XInterface> xRef, void* pSearchData)
     757             : {
     758           0 :     uno::Reference<uno::XInterface> xLayer (xRef);
     759           0 :     if (xLayer.is())
     760             :     {
     761           0 :         SdLayer* pSdLayer = SdLayer::getImplementation (xRef);
     762           0 :         if (pSdLayer != NULL)
     763             :         {
     764           0 :             SdrLayer* pSdrLayer = pSdLayer->GetSdrLayer ();
     765           0 :             if (pSdrLayer == static_cast<SdrLayer*>(pSearchData))
     766           0 :                 return sal_True;
     767             :         }
     768             :     }
     769           0 :     return sal_False;
     770             : }
     771             : }
     772             : 
     773             : /** Use the <member>mpLayers</member> container of weak references to either
     774             :     retrieve and return a previously created <type>XLayer</type> object for
     775             :     the given <type>SdrLayer</type> object or create and remember a new one.
     776             : */
     777           0 : uno::Reference<drawing::XLayer> SdLayerManager::GetLayer (SdrLayer* pLayer)
     778             : {
     779           0 :     uno::WeakReference<uno::XInterface> xRef;
     780           0 :     uno::Reference<drawing::XLayer>  xLayer;
     781             : 
     782             :     // Search existing xLayer for the given pLayer.
     783           0 :     if (mpLayers->findRef (xRef, (void*)pLayer, compare_layers))
     784           0 :         xLayer = uno::Reference<drawing::XLayer> (xRef, uno::UNO_QUERY);
     785             : 
     786             :     // Create the xLayer if necessary.
     787           0 :     if ( ! xLayer.is())
     788             :     {
     789           0 :         xLayer = new SdLayer (this, pLayer);
     790             : 
     791             :         // Remember the new xLayer for future calls.
     792           0 :         uno::WeakReference<uno::XInterface> wRef(xLayer);
     793           0 :         mpLayers->insert(wRef);
     794             :     }
     795             : 
     796           0 :     return xLayer;
     797             : }
     798             : 
     799             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10