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

Generated by: LCOV version 1.10