LCOV - code coverage report
Current view: top level - sd/source/ui/unoidl - unolayer.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 222 362 61.3 %
Date: 2014-04-11 Functions: 32 54 59.3 %
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         185 : const SvxItemPropertySet* ImplGetSdLayerPropertySet()
      66             : {
      67             :     static const SfxItemPropertyMapEntry aSdLayerPropertyMap_Impl[] =
      68             :     {
      69           7 :         { OUString(UNO_NAME_LAYER_LOCKED),      WID_LAYER_LOCKED,   ::getBooleanCppuType(),            0, 0 },
      70           7 :         { OUString(UNO_NAME_LAYER_PRINTABLE),   WID_LAYER_PRINTABLE,::getBooleanCppuType(),            0, 0 },
      71           7 :         { OUString(UNO_NAME_LAYER_VISIBLE),     WID_LAYER_VISIBLE,  ::getBooleanCppuType(),            0, 0 },
      72           7 :         { OUString(UNO_NAME_LAYER_NAME),        WID_LAYER_NAME,     ::getCppuType((const OUString*)0), 0, 0 },
      73           7 :         { OUString("Title"),                    WID_LAYER_TITLE,    ::getCppuType((const OUString*)0), 0, 0 },
      74           7 :         { OUString("Description"),              WID_LAYER_DESC,     ::getCppuType((const OUString*)0), 0, 0 },
      75             :         { OUString(), 0, css::uno::Type(), 0, 0 }
      76         234 :     };
      77         185 :     static SvxItemPropertySet aSDLayerPropertySet_Impl( aSdLayerPropertyMap_Impl, SdrObject::GetGlobalDrawObjectItemPool() );
      78         185 :     return &aSDLayerPropertySet_Impl;
      79             : }
      80             : 
      81         567 : OUString SdLayer::convertToInternalName( const OUString& rName )
      82             : {
      83         567 :     if ( rName == sUNO_LayerName_background )
      84             :     {
      85          28 :         return SD_RESSTR( STR_LAYER_BCKGRND );
      86             :     }
      87         539 :     else if ( rName == sUNO_LayerName_background_objects )
      88             :     {
      89         279 :         return  SD_RESSTR( STR_LAYER_BCKGRNDOBJ );
      90             :     }
      91         260 :     else if ( rName == sUNO_LayerName_layout )
      92             :     {
      93         201 :         return  SD_RESSTR( STR_LAYER_LAYOUT );
      94             :     }
      95          59 :     else if ( rName == sUNO_LayerName_controls )
      96             :     {
      97          28 :         return  SD_RESSTR( STR_LAYER_CONTROLS );
      98             :     }
      99          31 :     else if ( rName == sUNO_LayerName_measurelines )
     100             :     {
     101          29 :         return  SD_RESSTR( STR_LAYER_MEASURELINES );
     102             :     }
     103             :     else
     104             :     {
     105           2 :         return rName;
     106             :     }
     107             : }
     108             : 
     109         450 : OUString SdLayer::convertToExternalName( const OUString& rName )
     110             : {
     111         450 :     if( rName == SD_RESSTR( STR_LAYER_BCKGRND ) )
     112             :     {
     113          23 :         return OUString( sUNO_LayerName_background );
     114             :     }
     115         427 :     else if( rName == SD_RESSTR( STR_LAYER_BCKGRNDOBJ ) )
     116             :     {
     117          86 :         return OUString( sUNO_LayerName_background_objects );
     118             :     }
     119         341 :     else if( rName == SD_RESSTR( STR_LAYER_LAYOUT ) )
     120             :     {
     121         293 :         return OUString( sUNO_LayerName_layout );
     122             :     }
     123          48 :     else if( rName == SD_RESSTR( STR_LAYER_CONTROLS ) )
     124             :     {
     125          23 :         return OUString( sUNO_LayerName_controls );
     126             :     }
     127          25 :     else if( rName == SD_RESSTR( STR_LAYER_MEASURELINES ) )
     128             :     {
     129          23 :         return OUString( sUNO_LayerName_measurelines );
     130             :     }
     131             :     else
     132             :     {
     133           2 :         return rName;
     134             :     }
     135             : }
     136             : 
     137         185 : SdLayer::SdLayer( SdLayerManager* pLayerManager_, SdrLayer* pSdrLayer_ ) throw()
     138             : : pLayerManager(pLayerManager_)
     139             : , mxLayerManager(pLayerManager_)
     140             : , pLayer(pSdrLayer_)
     141         185 : , pPropSet(ImplGetSdLayerPropertySet())
     142             : {
     143         185 : }
     144             : 
     145         370 : SdLayer::~SdLayer() throw()
     146             : {
     147         370 : }
     148             : 
     149             : // uno helper
     150          52 : 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         140 : 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         140 :     SolarMutexGuard aGuard;
     185             : 
     186         140 :     if(pLayer == NULL || pLayerManager == NULL)
     187           0 :         throw lang::DisposedException();
     188             : 
     189         140 :     const SfxItemPropertySimpleEntry* pEntry = pPropSet->getPropertyMapEntry(aPropertyName);
     190             : 
     191         140 :     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          70 :         OUString sTitle;
     231          70 :         if(!(aValue >>= sTitle))
     232           0 :             throw lang::IllegalArgumentException();
     233             : 
     234          70 :         pLayer->SetTitle(sTitle);
     235          70 :         break;
     236             :     }
     237             : 
     238             :     case WID_LAYER_DESC:
     239             :     {
     240          70 :         OUString sDescription;
     241          70 :         if(!(aValue >>= sDescription))
     242           0 :             throw lang::IllegalArgumentException();
     243             : 
     244          70 :         pLayer->SetDescription(sDescription);
     245          70 :         break;
     246             :     }
     247             : 
     248             :     default:
     249           0 :         throw beans::UnknownPropertyException();
     250             :     }
     251             : 
     252         140 :     if( pLayerManager->GetDocShell() )
     253         140 :         pLayerManager->GetDocShell()->SetModified();
     254         140 : }
     255             : 
     256         332 : uno::Any SAL_CALL SdLayer::getPropertyValue( const OUString& PropertyName )
     257             :     throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
     258             : {
     259         332 :     SolarMutexGuard aGuard;
     260             : 
     261         332 :     if(pLayer == NULL || pLayerManager == NULL)
     262           0 :         throw lang::DisposedException();
     263             : 
     264         332 :     const SfxItemPropertySimpleEntry* pEntry = pPropSet->getPropertyMapEntry(PropertyName);
     265             : 
     266         332 :     uno::Any aValue;
     267             : 
     268         332 :     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         112 :         OUString aRet( SdLayer::convertToExternalName( pLayer->GetName() ) );
     282         112 :         aValue <<= aRet;
     283         112 :         break;
     284             :     }
     285             :     case WID_LAYER_TITLE:
     286         110 :         aValue <<= OUString( pLayer->GetTitle() );
     287         110 :         break;
     288             :     case WID_LAYER_DESC:
     289         110 :         aValue <<= OUString( pLayer->GetDescription() );
     290         110 :         break;
     291             :     default:
     292           0 :         throw beans::UnknownPropertyException();
     293             :     }
     294             : 
     295         332 :     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           5 : void SAL_CALL SdLayer::dispose(  ) throw (uno::RuntimeException, std::exception)
     422             : {
     423           5 :     pLayerManager = 0;
     424           5 :     mxLayerManager = 0;
     425           5 :     pLayer = 0;
     426           5 : }
     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          38 : SdLayerManager::SdLayerManager( SdXImpressDocument& rMyModel ) throw()
     442          38 : :mpModel( &rMyModel)
     443             : {
     444          38 :     mpLayers = new SvUnoWeakContainer;
     445          38 : }
     446             : 
     447         114 : SdLayerManager::~SdLayerManager() throw()
     448             : {
     449          38 :     dispose();
     450          76 : }
     451             : 
     452             : // uno helper
     453           0 : UNO3_GETIMPLEMENTATION_IMPL( SdLayerManager );
     454             : 
     455             : // XComponent
     456          40 : void SAL_CALL SdLayerManager::dispose(  ) throw (uno::RuntimeException, std::exception)
     457             : {
     458          40 :     mpModel = 0;
     459          40 :     if( mpLayers )
     460             :     {
     461          38 :         mpLayers->dispose();
     462             : 
     463          38 :         delete mpLayers;
     464          38 :         mpLayers = 0;
     465             :     }
     466          40 : }
     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           1 : uno::Reference< drawing::XLayer > SAL_CALL SdLayerManager::insertNewByIndex( sal_Int32 nIndex )
     501             :     throw(uno::RuntimeException, std::exception)
     502             : {
     503           1 :     SolarMutexGuard aGuard;
     504             : 
     505           1 :     if( mpModel == 0 )
     506           0 :         throw lang::DisposedException();
     507             : 
     508           1 :     uno::Reference< drawing::XLayer > xLayer;
     509             : 
     510           1 :     if( mpModel->mpDoc )
     511             :     {
     512           1 :         SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin();
     513           1 :         sal_uInt16 nLayerCnt = rLayerAdmin.GetLayerCount();
     514           1 :         sal_Int32 nLayer = nLayerCnt - 2 + 1;
     515           1 :         OUString aLayerName;
     516             : 
     517             :         // Test for existing names
     518           3 :         while( aLayerName.isEmpty() || rLayerAdmin.GetLayer( aLayerName, false) )
     519             :         {
     520           1 :             aLayerName = SD_RESSTR(STR_LAYER);
     521           1 :             aLayerName += OUString::number(nLayer);
     522           1 :             ++nLayer;
     523             :         }
     524             : 
     525           1 :         SdrLayerAdmin& rLA=mpModel->mpDoc->GetLayerAdmin();
     526           1 :         const sal_Int32 nMax=rLA.GetLayerCount();
     527           1 :         if (nIndex>nMax) nIndex=nMax;
     528           1 :         xLayer = GetLayer (rLA.NewLayer(aLayerName,(sal_uInt16)nIndex));
     529           1 :         mpModel->SetModified();
     530             :     }
     531           1 :     return xLayer;
     532             : }
     533             : 
     534           1 : void SAL_CALL SdLayerManager::remove( const uno::Reference< drawing::XLayer >& xLayer )
     535             :     throw(container::NoSuchElementException, uno::RuntimeException, std::exception)
     536             : {
     537           1 :     SolarMutexGuard aGuard;
     538             : 
     539           1 :     if( mpModel == 0 )
     540           0 :         throw lang::DisposedException();
     541             : 
     542           1 :     SdLayer* pSdLayer = SdLayer::getImplementation(xLayer);
     543             : 
     544           1 :     if(pSdLayer && GetView())
     545             :     {
     546           1 :         const SdrLayer* pSdrLayer = pSdLayer->GetSdrLayer();
     547           1 :         GetView()->DeleteLayer( pSdrLayer->GetName() );
     548             : 
     549           1 :         UpdateLayerView();
     550             :     }
     551             : 
     552           1 :     mpModel->SetModified();
     553           1 : }
     554             : 
     555           1 : 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           1 :     SolarMutexGuard aGuard;
     559             : 
     560           1 :     if( mpModel == 0 )
     561           0 :         throw lang::DisposedException();
     562             : 
     563           1 :     SdLayer* pSdLayer = SdLayer::getImplementation(xLayer);
     564           1 :     SdrLayer* pSdrLayer = pSdLayer?pSdLayer->GetSdrLayer():NULL;
     565           1 :     if(pSdrLayer==NULL)
     566           1 :         return;
     567             : 
     568           1 :     SvxShape* pShape = SvxShape::getImplementation( xShape );
     569           1 :     SdrObject* pSdrObject = pShape?pShape->GetSdrObject():NULL;
     570             : 
     571           1 :     if(pSdrObject && pSdrLayer )
     572           1 :         pSdrObject->SetLayer(pSdrLayer->GetID());
     573             : 
     574           1 :     mpModel->SetModified();
     575             : }
     576             : 
     577           1 : uno::Reference< drawing::XLayer > SAL_CALL SdLayerManager::getLayerForShape( const uno::Reference< drawing::XShape >& xShape ) throw(uno::RuntimeException, std::exception)
     578             : {
     579           1 :     SolarMutexGuard aGuard;
     580             : 
     581           1 :     if( mpModel == 0 )
     582           0 :         throw lang::DisposedException();
     583             : 
     584           1 :     uno::Reference< drawing::XLayer >  xLayer;
     585             : 
     586           1 :     if(mpModel->mpDoc)
     587             :     {
     588           1 :         SvxShape* pShape = SvxShape::getImplementation( xShape );
     589           1 :         SdrObject* pObj = pShape?pShape->GetSdrObject():NULL;
     590           1 :         if(pObj)
     591             :         {
     592           1 :             SdrLayerID aId = pObj->GetLayer();
     593           1 :             SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin();
     594           1 :             xLayer = GetLayer (rLayerAdmin.GetLayerPerID(aId));
     595             :         }
     596             :     }
     597           1 :     return xLayer;
     598             : }
     599             : 
     600             : // XIndexAccess
     601         141 : sal_Int32 SAL_CALL SdLayerManager::getCount()
     602             :     throw(uno::RuntimeException, std::exception)
     603             : {
     604         141 :     SolarMutexGuard aGuard;
     605             : 
     606         141 :     if( mpModel == 0 )
     607           0 :         throw lang::DisposedException();
     608             : 
     609         141 :     if( mpModel->mpDoc )
     610             :     {
     611         141 :         SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin();
     612         141 :         return rLayerAdmin.GetLayerCount();
     613             :     }
     614             : 
     615           0 :     return 0;
     616             : }
     617             : 
     618         115 : uno::Any SAL_CALL SdLayerManager::getByIndex( sal_Int32 nLayer )
     619             :     throw(lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
     620             : {
     621         115 :     SolarMutexGuard aGuard;
     622             : 
     623         115 :     if( mpModel == 0 )
     624           0 :         throw lang::DisposedException();
     625             : 
     626         115 :     if( nLayer >= getCount() || nLayer < 0 )
     627           1 :         throw lang::IndexOutOfBoundsException();
     628             : 
     629         114 :     uno::Any aAny;
     630             : 
     631         114 :     if( mpModel->mpDoc )
     632             :     {
     633         114 :         SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin();
     634         114 :         uno::Reference<drawing::XLayer> xLayer (GetLayer (rLayerAdmin.GetLayer((sal_uInt16)nLayer)));
     635         114 :         aAny <<= xLayer;
     636             :     }
     637         115 :     return aAny;
     638             : }
     639             : 
     640             : // XNameAccess
     641          72 : uno::Any SAL_CALL SdLayerManager::getByName( const OUString& aName )
     642             :     throw(container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
     643             : {
     644          72 :     SolarMutexGuard aGuard;
     645             : 
     646          72 :     if( (mpModel == 0) || (mpModel->mpDoc == 0 ) )
     647           0 :         throw lang::DisposedException();
     648             : 
     649          72 :     SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin();
     650          72 :     SdrLayer* pLayer = rLayerAdmin.GetLayer( SdLayer::convertToInternalName( aName ), false );
     651          72 :     if( pLayer == NULL )
     652           1 :         throw container::NoSuchElementException();
     653             : 
     654          71 :     return uno::Any( GetLayer (pLayer) );
     655             : }
     656             : 
     657           1 : uno::Sequence< OUString > SAL_CALL SdLayerManager::getElementNames()
     658             :     throw(uno::RuntimeException, std::exception)
     659             : {
     660           1 :     SolarMutexGuard aGuard;
     661             : 
     662           1 :     if( mpModel == 0 )
     663           0 :         throw lang::DisposedException();
     664             : 
     665           1 :     SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin();
     666           1 :     const sal_uInt16 nLayerCount = rLayerAdmin.GetLayerCount();
     667             : 
     668           1 :     uno::Sequence< OUString > aSeq( nLayerCount );
     669             : 
     670           1 :     OUString* pStrings = aSeq.getArray();
     671             :     SdrLayer* pLayer;
     672             : 
     673           6 :     for( sal_uInt16 nLayer = 0; nLayer < nLayerCount; nLayer++ )
     674             :     {
     675           5 :         pLayer = rLayerAdmin.GetLayer( nLayer );
     676           5 :         if( pLayer )
     677           5 :             *pStrings++ = SdLayer::convertToExternalName( pLayer->GetName() );
     678             :     }
     679             : 
     680           1 :     return aSeq;
     681             : }
     682             : 
     683          72 : sal_Bool SAL_CALL SdLayerManager::hasByName( const OUString& aName ) throw(uno::RuntimeException, std::exception)
     684             : {
     685          72 :     SolarMutexGuard aGuard;
     686             : 
     687          72 :     if( mpModel == 0 )
     688           0 :         throw lang::DisposedException();
     689             : 
     690          72 :     SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin();
     691             : 
     692          72 :     return NULL != rLayerAdmin.GetLayer( SdLayer::convertToInternalName( aName ), false );
     693             : }
     694             : 
     695             : // XElementAccess
     696           1 : uno::Type SAL_CALL SdLayerManager::getElementType()
     697             :     throw(uno::RuntimeException, std::exception)
     698             : {
     699           1 :     return cppu::UnoType<drawing::XLayer>::get();
     700             : }
     701             : 
     702           1 : sal_Bool SAL_CALL SdLayerManager::hasElements() throw(uno::RuntimeException, std::exception)
     703             : {
     704           1 :     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           1 : void SdLayerManager::UpdateLayerView( sal_Bool modify ) const throw()
     712             : {
     713           1 :     if(mpModel->mpDocShell)
     714             :     {
     715             :         ::sd::DrawViewShell* pDrViewSh =
     716           1 :             PTR_CAST(::sd::DrawViewShell, mpModel->mpDocShell->GetViewShell());
     717             : 
     718           1 :         if(pDrViewSh)
     719             :         {
     720           1 :             sal_Bool bLayerMode = pDrViewSh->IsLayerModeActive();
     721           1 :             pDrViewSh->ChangeEditMode(pDrViewSh->GetEditMode(), !bLayerMode);
     722           1 :             pDrViewSh->ChangeEditMode(pDrViewSh->GetEditMode(), bLayerMode);
     723             :         }
     724             : 
     725           1 :         if(modify)
     726           1 :             mpModel->mpDoc->SetChanged(true);
     727             :     }
     728           1 : }
     729             : 
     730             : /** */
     731           2 : ::sd::View* SdLayerManager::GetView() const throw()
     732             : {
     733           2 :     if( mpModel->mpDocShell )
     734             :     {
     735           2 :         ::sd::ViewShell* pViewSh = mpModel->mpDocShell->GetViewShell();
     736           2 :         if(pViewSh)
     737           2 :             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          11 : sal_Bool compare_layers (uno::WeakReference<uno::XInterface> xRef, void* pSearchData)
     757             : {
     758          11 :     uno::Reference<uno::XInterface> xLayer (xRef);
     759          11 :     if (xLayer.is())
     760             :     {
     761          11 :         SdLayer* pSdLayer = SdLayer::getImplementation (xRef);
     762          11 :         if (pSdLayer != NULL)
     763             :         {
     764          11 :             SdrLayer* pSdrLayer = pSdLayer->GetSdrLayer ();
     765          11 :             if (pSdrLayer == static_cast<SdrLayer*>(pSearchData))
     766           2 :                 return sal_True;
     767             :         }
     768             :     }
     769           9 :     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         187 : uno::Reference<drawing::XLayer> SdLayerManager::GetLayer (SdrLayer* pLayer)
     778             : {
     779         187 :     uno::WeakReference<uno::XInterface> xRef;
     780         187 :     uno::Reference<drawing::XLayer>  xLayer;
     781             : 
     782             :     // Search existing xLayer for the given pLayer.
     783         187 :     if (mpLayers->findRef (xRef, (void*)pLayer, compare_layers))
     784           2 :         xLayer = uno::Reference<drawing::XLayer> (xRef, uno::UNO_QUERY);
     785             : 
     786             :     // Create the xLayer if necessary.
     787         187 :     if ( ! xLayer.is())
     788             :     {
     789         185 :         xLayer = new SdLayer (this, pLayer);
     790             : 
     791             :         // Remember the new xLayer for future calls.
     792         185 :         uno::WeakReference<uno::XInterface> wRef(xLayer);
     793         185 :         mpLayers->insert(wRef);
     794             :     }
     795             : 
     796         187 :     return xLayer;
     797             : }
     798             : 
     799             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10