LCOV - code coverage report
Current view: top level - sd/source/ui/unoidl - unolayer.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 228 354 64.4 %
Date: 2015-06-13 12:38:46 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         313 : const SvxItemPropertySet* ImplGetSdLayerPropertySet()
      65             : {
      66             :     static const SfxItemPropertyMapEntry aSdLayerPropertyMap_Impl[] =
      67             :     {
      68          12 :         { OUString(UNO_NAME_LAYER_LOCKED),      WID_LAYER_LOCKED,   cppu::UnoType<bool>::get(),            0, 0 },
      69          12 :         { OUString(UNO_NAME_LAYER_PRINTABLE),   WID_LAYER_PRINTABLE,cppu::UnoType<bool>::get(),            0, 0 },
      70          12 :         { OUString(UNO_NAME_LAYER_VISIBLE),     WID_LAYER_VISIBLE,  cppu::UnoType<bool>::get(),            0, 0 },
      71          12 :         { OUString(UNO_NAME_LAYER_NAME),        WID_LAYER_NAME,     ::cppu::UnoType<OUString>::get(), 0, 0 },
      72          12 :         { OUString("Title"),                    WID_LAYER_TITLE,    ::cppu::UnoType<OUString>::get(), 0, 0 },
      73          12 :         { OUString("Description"),              WID_LAYER_DESC,     ::cppu::UnoType<OUString>::get(), 0, 0 },
      74             :         { OUString(), 0, css::uno::Type(), 0, 0 }
      75         397 :     };
      76         313 :     static SvxItemPropertySet aSDLayerPropertySet_Impl( aSdLayerPropertyMap_Impl, SdrObject::GetGlobalDrawObjectItemPool() );
      77         313 :     return &aSDLayerPropertySet_Impl;
      78             : }
      79             : 
      80        2824 : OUString SdLayer::convertToInternalName( const OUString& rName )
      81             : {
      82        2824 :     if ( rName == sUNO_LayerName_background )
      83             :     {
      84          92 :         return SD_RESSTR( STR_LAYER_BCKGRND );
      85             :     }
      86        2732 :     else if ( rName == sUNO_LayerName_background_objects )
      87             :     {
      88         960 :         return  SD_RESSTR( STR_LAYER_BCKGRNDOBJ );
      89             :     }
      90        1772 :     else if ( rName == sUNO_LayerName_layout )
      91             :     {
      92        1564 :         return  SD_RESSTR( STR_LAYER_LAYOUT );
      93             :     }
      94         208 :     else if ( rName == sUNO_LayerName_controls )
      95             :     {
      96          92 :         return  SD_RESSTR( STR_LAYER_CONTROLS );
      97             :     }
      98         116 :     else if ( rName == sUNO_LayerName_measurelines )
      99             :     {
     100          93 :         return  SD_RESSTR( STR_LAYER_MEASURELINES );
     101             :     }
     102             :     else
     103             :     {
     104          23 :         return rName;
     105             :     }
     106             : }
     107             : 
     108         528 : OUString SdLayer::convertToExternalName( const OUString& rName )
     109             : {
     110         528 :     if( rName == SD_RESSTR( STR_LAYER_BCKGRND ) )
     111             :     {
     112          16 :         return OUString( sUNO_LayerName_background );
     113             :     }
     114         512 :     else if( rName == SD_RESSTR( STR_LAYER_BCKGRNDOBJ ) )
     115             :     {
     116         160 :         return OUString( sUNO_LayerName_background_objects );
     117             :     }
     118         352 :     else if( rName == SD_RESSTR( STR_LAYER_LAYOUT ) )
     119             :     {
     120         318 :         return OUString( sUNO_LayerName_layout );
     121             :     }
     122          34 :     else if( rName == SD_RESSTR( STR_LAYER_CONTROLS ) )
     123             :     {
     124          16 :         return OUString( sUNO_LayerName_controls );
     125             :     }
     126          18 :     else if( rName == SD_RESSTR( STR_LAYER_MEASURELINES ) )
     127             :     {
     128          16 :         return OUString( sUNO_LayerName_measurelines );
     129             :     }
     130             :     else
     131             :     {
     132           2 :         return rName;
     133             :     }
     134             : }
     135             : 
     136         313 : SdLayer::SdLayer( SdLayerManager* pLayerManager_, SdrLayer* pSdrLayer_ ) throw()
     137             : : pLayerManager(pLayerManager_)
     138             : , mxLayerManager(pLayerManager_)
     139             : , pLayer(pSdrLayer_)
     140         313 : , pPropSet(ImplGetSdLayerPropertySet())
     141             : {
     142         313 : }
     143             : 
     144         626 : SdLayer::~SdLayer() throw()
     145             : {
     146         626 : }
     147             : 
     148             : // uno helper
     149          52 : 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("SdUnoLayer");
     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(UNO_PREFIX "drawing.Layer");
     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         469 : 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         469 :     SolarMutexGuard aGuard;
     184             : 
     185         469 :     if(pLayer == NULL || pLayerManager == NULL)
     186           0 :         throw lang::DisposedException();
     187             : 
     188         469 :     const SfxItemPropertySimpleEntry* pEntry = pPropSet->getPropertyMapEntry(aPropertyName);
     189             : 
     190         469 :     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           3 :         OUString aName;
     210           3 :         if(!(aValue >>= aName))
     211           0 :             throw lang::IllegalArgumentException();
     212             : 
     213           3 :         pLayer->SetName(SdLayer::convertToInternalName( aName ) );
     214           3 :         pLayerManager->UpdateLayerView();
     215           3 :         break;
     216             :     }
     217             : 
     218             :     case WID_LAYER_TITLE:
     219             :     {
     220         233 :         OUString sTitle;
     221         233 :         if(!(aValue >>= sTitle))
     222           0 :             throw lang::IllegalArgumentException();
     223             : 
     224         233 :         pLayer->SetTitle(sTitle);
     225         233 :         break;
     226             :     }
     227             : 
     228             :     case WID_LAYER_DESC:
     229             :     {
     230         233 :         OUString sDescription;
     231         233 :         if(!(aValue >>= sDescription))
     232           0 :             throw lang::IllegalArgumentException();
     233             : 
     234         233 :         pLayer->SetDescription(sDescription);
     235         233 :         break;
     236             :     }
     237             : 
     238             :     default:
     239           0 :         throw beans::UnknownPropertyException();
     240             :     }
     241             : 
     242         469 :     if( pLayerManager->GetDocShell() )
     243         469 :         pLayerManager->GetDocShell()->SetModified();
     244         469 : }
     245             : 
     246         227 : uno::Any SAL_CALL SdLayer::getPropertyValue( const OUString& PropertyName )
     247             :     throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
     248             : {
     249         227 :     SolarMutexGuard aGuard;
     250             : 
     251         227 :     if(pLayer == NULL || pLayerManager == NULL)
     252           0 :         throw lang::DisposedException();
     253             : 
     254         227 :     const SfxItemPropertySimpleEntry* pEntry = pPropSet->getPropertyMapEntry(PropertyName);
     255             : 
     256         227 :     uno::Any aValue;
     257             : 
     258         227 :     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          77 :         OUString aRet( SdLayer::convertToExternalName( pLayer->GetName() ) );
     272          77 :         aValue <<= aRet;
     273          77 :         break;
     274             :     }
     275             :     case WID_LAYER_TITLE:
     276          75 :         aValue <<= OUString( pLayer->GetTitle() );
     277          75 :         break;
     278             :     case WID_LAYER_DESC:
     279          75 :         aValue <<= OUString( pLayer->GetDescription() );
     280          75 :         break;
     281             :     default:
     282           0 :         throw beans::UnknownPropertyException();
     283             :     }
     284             : 
     285         227 :     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()
     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           5 : void SAL_CALL SdLayer::dispose(  ) throw (uno::RuntimeException, std::exception)
     411             : {
     412           5 :     pLayerManager = 0;
     413           5 :     mxLayerManager = 0;
     414           5 :     pLayer = 0;
     415           5 : }
     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          63 : SdLayerManager::SdLayerManager( SdXImpressDocument& rMyModel ) throw()
     429          63 : :mpModel( &rMyModel)
     430             : {
     431          63 :     mpLayers = new SvUnoWeakContainer;
     432          63 : }
     433             : 
     434         189 : SdLayerManager::~SdLayerManager() throw()
     435             : {
     436          63 :     dispose();
     437         126 : }
     438             : 
     439             : // uno helper
     440           0 : UNO3_GETIMPLEMENTATION_IMPL( SdLayerManager );
     441             : 
     442             : // XComponent
     443          65 : void SAL_CALL SdLayerManager::dispose(  ) throw (uno::RuntimeException, std::exception)
     444             : {
     445          65 :     mpModel = 0;
     446          65 :     if( mpLayers )
     447             :     {
     448          63 :         mpLayers->dispose();
     449             : 
     450          63 :         delete mpLayers;
     451          63 :         mpLayers = 0;
     452             :     }
     453          65 : }
     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("SdUnoLayerManager");
     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(UNO_PREFIX "drawing.LayerManager");
     482           0 :     uno::Sequence< OUString > aSeq( &aServiceName, 1 );
     483           0 :     return aSeq;
     484             : }
     485             : 
     486             : // XLayerManager
     487           4 : uno::Reference< drawing::XLayer > SAL_CALL SdLayerManager::insertNewByIndex( sal_Int32 nIndex )
     488             :     throw(uno::RuntimeException, std::exception)
     489             : {
     490           4 :     SolarMutexGuard aGuard;
     491             : 
     492           4 :     if( mpModel == 0 )
     493           0 :         throw lang::DisposedException();
     494             : 
     495           4 :     uno::Reference< drawing::XLayer > xLayer;
     496             : 
     497           4 :     if( mpModel->mpDoc )
     498             :     {
     499           4 :         SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin();
     500           4 :         sal_uInt16 nLayerCnt = rLayerAdmin.GetLayerCount();
     501           4 :         sal_Int32 nLayer = nLayerCnt - 2 + 1;
     502           4 :         OUString aLayerName;
     503             : 
     504             :         // Test for existing names
     505          12 :         while( aLayerName.isEmpty() || rLayerAdmin.GetLayer( aLayerName, false) )
     506             :         {
     507           4 :             aLayerName = SD_RESSTR(STR_LAYER);
     508           4 :             aLayerName += OUString::number(nLayer);
     509           4 :             ++nLayer;
     510             :         }
     511             : 
     512           4 :         SdrLayerAdmin& rLA=mpModel->mpDoc->GetLayerAdmin();
     513           4 :         const sal_Int32 nMax=rLA.GetLayerCount();
     514           4 :         if (nIndex>nMax) nIndex=nMax;
     515           4 :         xLayer = GetLayer (rLA.NewLayer(aLayerName,(sal_uInt16)nIndex));
     516           4 :         mpModel->SetModified();
     517             :     }
     518           4 :     return xLayer;
     519             : }
     520             : 
     521           1 : void SAL_CALL SdLayerManager::remove( const uno::Reference< drawing::XLayer >& xLayer )
     522             :     throw(container::NoSuchElementException, uno::RuntimeException, std::exception)
     523             : {
     524           1 :     SolarMutexGuard aGuard;
     525             : 
     526           1 :     if( mpModel == 0 )
     527           0 :         throw lang::DisposedException();
     528             : 
     529           1 :     SdLayer* pSdLayer = SdLayer::getImplementation(xLayer);
     530             : 
     531           1 :     if(pSdLayer && GetView())
     532             :     {
     533           1 :         const SdrLayer* pSdrLayer = pSdLayer->GetSdrLayer();
     534           1 :         GetView()->DeleteLayer( pSdrLayer->GetName() );
     535             : 
     536           1 :         UpdateLayerView();
     537             :     }
     538             : 
     539           1 :     mpModel->SetModified();
     540           1 : }
     541             : 
     542           1 : 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           1 :     SolarMutexGuard aGuard;
     546             : 
     547           1 :     if( mpModel == 0 )
     548           0 :         throw lang::DisposedException();
     549             : 
     550           1 :     SdLayer* pSdLayer = SdLayer::getImplementation(xLayer);
     551           1 :     SdrLayer* pSdrLayer = pSdLayer?pSdLayer->GetSdrLayer():NULL;
     552           1 :     if(pSdrLayer==NULL)
     553           1 :         return;
     554             : 
     555           1 :     SvxShape* pShape = SvxShape::getImplementation( xShape );
     556           1 :     SdrObject* pSdrObject = pShape?pShape->GetSdrObject():NULL;
     557             : 
     558           1 :     if(pSdrObject && pSdrLayer )
     559           1 :         pSdrObject->SetLayer(pSdrLayer->GetID());
     560             : 
     561           1 :     mpModel->SetModified();
     562             : }
     563             : 
     564           1 : uno::Reference< drawing::XLayer > SAL_CALL SdLayerManager::getLayerForShape( const uno::Reference< drawing::XShape >& xShape ) throw(uno::RuntimeException, std::exception)
     565             : {
     566           1 :     SolarMutexGuard aGuard;
     567             : 
     568           1 :     if( mpModel == 0 )
     569           0 :         throw lang::DisposedException();
     570             : 
     571           1 :     uno::Reference< drawing::XLayer >  xLayer;
     572             : 
     573           1 :     if(mpModel->mpDoc)
     574             :     {
     575           1 :         SvxShape* pShape = SvxShape::getImplementation( xShape );
     576           1 :         SdrObject* pObj = pShape?pShape->GetSdrObject():NULL;
     577           1 :         if(pObj)
     578             :         {
     579           1 :             SdrLayerID aId = pObj->GetLayer();
     580           1 :             SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin();
     581           1 :             xLayer = GetLayer (rLayerAdmin.GetLayerPerID(aId));
     582             :         }
     583             :     }
     584           1 :     return xLayer;
     585             : }
     586             : 
     587             : // XIndexAccess
     588         102 : sal_Int32 SAL_CALL SdLayerManager::getCount()
     589             :     throw(uno::RuntimeException, std::exception)
     590             : {
     591         102 :     SolarMutexGuard aGuard;
     592             : 
     593         102 :     if( mpModel == 0 )
     594           0 :         throw lang::DisposedException();
     595             : 
     596         102 :     if( mpModel->mpDoc )
     597             :     {
     598         102 :         SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin();
     599         102 :         return rLayerAdmin.GetLayerCount();
     600             :     }
     601             : 
     602           0 :     return 0;
     603             : }
     604             : 
     605          80 : uno::Any SAL_CALL SdLayerManager::getByIndex( sal_Int32 nLayer )
     606             :     throw(lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
     607             : {
     608          80 :     SolarMutexGuard aGuard;
     609             : 
     610          80 :     if( mpModel == 0 )
     611           0 :         throw lang::DisposedException();
     612             : 
     613          80 :     if( nLayer >= getCount() || nLayer < 0 )
     614           1 :         throw lang::IndexOutOfBoundsException();
     615             : 
     616          79 :     uno::Any aAny;
     617             : 
     618          79 :     if( mpModel->mpDoc )
     619             :     {
     620          79 :         SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin();
     621          79 :         uno::Reference<drawing::XLayer> xLayer (GetLayer (rLayerAdmin.GetLayer((sal_uInt16)nLayer)));
     622          79 :         aAny <<= xLayer;
     623             :     }
     624          80 :     return aAny;
     625             : }
     626             : 
     627             : // XNameAccess
     628         232 : uno::Any SAL_CALL SdLayerManager::getByName( const OUString& aName )
     629             :     throw(container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
     630             : {
     631         232 :     SolarMutexGuard aGuard;
     632             : 
     633         232 :     if( (mpModel == 0) || (mpModel->mpDoc == 0 ) )
     634           0 :         throw lang::DisposedException();
     635             : 
     636         232 :     SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin();
     637         232 :     SdrLayer* pLayer = rLayerAdmin.GetLayer( SdLayer::convertToInternalName( aName ), false );
     638         232 :     if( pLayer == NULL )
     639           1 :         throw container::NoSuchElementException();
     640             : 
     641         231 :     return uno::Any( GetLayer (pLayer) );
     642             : }
     643             : 
     644           1 : uno::Sequence< OUString > SAL_CALL SdLayerManager::getElementNames()
     645             :     throw(uno::RuntimeException, std::exception)
     646             : {
     647           1 :     SolarMutexGuard aGuard;
     648             : 
     649           1 :     if( mpModel == 0 )
     650           0 :         throw lang::DisposedException();
     651             : 
     652           1 :     SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin();
     653           1 :     const sal_uInt16 nLayerCount = rLayerAdmin.GetLayerCount();
     654             : 
     655           1 :     uno::Sequence< OUString > aSeq( nLayerCount );
     656             : 
     657           1 :     OUString* pStrings = aSeq.getArray();
     658             : 
     659           6 :     for( sal_uInt16 nLayer = 0; nLayer < nLayerCount; nLayer++ )
     660             :     {
     661           5 :         SdrLayer* pLayer = rLayerAdmin.GetLayer( nLayer );
     662           5 :         if( pLayer )
     663           5 :             *pStrings++ = SdLayer::convertToExternalName( pLayer->GetName() );
     664             :     }
     665             : 
     666           1 :     return aSeq;
     667             : }
     668             : 
     669         235 : sal_Bool SAL_CALL SdLayerManager::hasByName( const OUString& aName ) throw(uno::RuntimeException, std::exception)
     670             : {
     671         235 :     SolarMutexGuard aGuard;
     672             : 
     673         235 :     if( mpModel == 0 )
     674           0 :         throw lang::DisposedException();
     675             : 
     676         235 :     SdrLayerAdmin& rLayerAdmin = mpModel->mpDoc->GetLayerAdmin();
     677             : 
     678         235 :     return NULL != rLayerAdmin.GetLayer( SdLayer::convertToInternalName( aName ), false );
     679             : }
     680             : 
     681             : // XElementAccess
     682           1 : uno::Type SAL_CALL SdLayerManager::getElementType()
     683             :     throw(uno::RuntimeException, std::exception)
     684             : {
     685           1 :     return cppu::UnoType<drawing::XLayer>::get();
     686             : }
     687             : 
     688           1 : sal_Bool SAL_CALL SdLayerManager::hasElements() throw(uno::RuntimeException, std::exception)
     689             : {
     690           1 :     return getCount() > 0;
     691             : }
     692             : 
     693             : /**
     694             :  * If something was changed at the layers, this methods takes care that the
     695             :  * changes are made visible in sdbcx::View.
     696             :  */
     697           4 : void SdLayerManager::UpdateLayerView( bool modify ) const throw()
     698             : {
     699           4 :     if(mpModel->mpDocShell)
     700             :     {
     701             :         ::sd::DrawViewShell* pDrViewSh =
     702           4 :             PTR_CAST(::sd::DrawViewShell, mpModel->mpDocShell->GetViewShell());
     703             : 
     704           4 :         if(pDrViewSh)
     705             :         {
     706           4 :             bool bLayerMode = pDrViewSh->IsLayerModeActive();
     707           4 :             pDrViewSh->ChangeEditMode(pDrViewSh->GetEditMode(), !bLayerMode);
     708           4 :             pDrViewSh->ChangeEditMode(pDrViewSh->GetEditMode(), bLayerMode);
     709             :         }
     710             : 
     711           4 :         if(modify)
     712           4 :             mpModel->mpDoc->SetChanged(true);
     713             :     }
     714           4 : }
     715             : 
     716             : /** */
     717           2 : ::sd::View* SdLayerManager::GetView() const throw()
     718             : {
     719           2 :     if( mpModel->mpDocShell )
     720             :     {
     721           2 :         ::sd::ViewShell* pViewSh = mpModel->mpDocShell->GetViewShell();
     722           2 :         if(pViewSh)
     723           2 :             return pViewSh->GetView();
     724             :     }
     725           0 :     return NULL;
     726             : }
     727             : 
     728             : namespace
     729             : {
     730             : /** Compare two pointers to <type>SdrLayer</type> objects.
     731             :     @param xRef
     732             :         The implementing SdLayer class provides the first pointer by the
     733             :         <member>SdLayer::GetSdrLayer</member> method.
     734             :     @param pSearchData
     735             :         This void pointer is the second pointer to an <type>SdrLayer</type>
     736             :         object.
     737             :     @return
     738             :         Return </True> if both pointers point to the same object.
     739             : */
     740          11 : bool compare_layers (uno::WeakReference<uno::XInterface> xRef, void* pSearchData)
     741             : {
     742          11 :     uno::Reference<uno::XInterface> xLayer (xRef);
     743          11 :     if (xLayer.is())
     744             :     {
     745          11 :         SdLayer* pSdLayer = SdLayer::getImplementation (xRef);
     746          11 :         if (pSdLayer != NULL)
     747             :         {
     748          11 :             SdrLayer* pSdrLayer = pSdLayer->GetSdrLayer ();
     749          11 :             if (pSdrLayer == static_cast<SdrLayer*>(pSearchData))
     750           2 :                 return true;
     751             :         }
     752             :     }
     753           9 :     return false;
     754             : }
     755             : }
     756             : 
     757             : /** Use the <member>mpLayers</member> container of weak references to either
     758             :     retrieve and return a previously created <type>XLayer</type> object for
     759             :     the given <type>SdrLayer</type> object or create and remember a new one.
     760             : */
     761         315 : uno::Reference<drawing::XLayer> SdLayerManager::GetLayer (SdrLayer* pLayer)
     762             : {
     763         315 :     uno::WeakReference<uno::XInterface> xRef;
     764         315 :     uno::Reference<drawing::XLayer>  xLayer;
     765             : 
     766             :     // Search existing xLayer for the given pLayer.
     767         315 :     if (mpLayers->findRef (xRef, static_cast<void*>(pLayer), compare_layers))
     768           2 :         xLayer = uno::Reference<drawing::XLayer> (xRef, uno::UNO_QUERY);
     769             : 
     770             :     // Create the xLayer if necessary.
     771         315 :     if ( ! xLayer.is())
     772             :     {
     773         313 :         xLayer = new SdLayer (this, pLayer);
     774             : 
     775             :         // Remember the new xLayer for future calls.
     776         313 :         uno::WeakReference<uno::XInterface> wRef(xLayer);
     777         313 :         mpLayers->insert(wRef);
     778             :     }
     779             : 
     780         315 :     return xLayer;
     781          66 : }
     782             : 
     783             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11