LCOV - code coverage report
Current view: top level - libreoffice/svx/source/svdraw - svdlayer.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 70 176 39.8 %
Date: 2012-12-27 Functions: 11 24 45.8 %
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/uno/Sequence.hxx>
      21             : 
      22             : #include <svx/svdlayer.hxx>
      23             : #include <svx/svdmodel.hxx> // for Broadcasting
      24             : #include "svx/svdglob.hxx"  // StringCache
      25             : #include "svx/svdstr.hrc"   // names taken from the resource
      26             : 
      27             : ////////////////////////////////////////////////////////////////////////////////////////////////////
      28             : // SetOfByte
      29             : ////////////////////////////////////////////////////////////////////////////////////////////////////
      30             : 
      31         816 : sal_Bool SetOfByte::IsEmpty() const
      32             : {
      33         816 :     for(sal_uInt16 i(0); i < 32; i++)
      34             :     {
      35         816 :         if(aData[i] != 0)
      36         816 :             return sal_False;
      37             :     }
      38             : 
      39           0 :     return sal_True;
      40             : }
      41             : 
      42           0 : void SetOfByte::operator&=(const SetOfByte& r2ndSet)
      43             : {
      44           0 :     for(sal_uInt16 i(0); i < 32; i++)
      45             :     {
      46           0 :         aData[i] &= r2ndSet.aData[i];
      47             :     }
      48           0 : }
      49             : 
      50           0 : void SetOfByte::operator|=(const SetOfByte& r2ndSet)
      51             : {
      52           0 :     for(sal_uInt16 i(0); i < 32; i++)
      53             :     {
      54           0 :         aData[i] |= r2ndSet.aData[i];
      55             :     }
      56           0 : }
      57             : 
      58             : /** initialize this set with a uno sequence of sal_Int8
      59             : */
      60           0 : void SetOfByte::PutValue( const com::sun::star::uno::Any & rAny )
      61             : {
      62           0 :     com::sun::star::uno::Sequence< sal_Int8 > aSeq;
      63           0 :     if( rAny >>= aSeq )
      64             :     {
      65           0 :         sal_Int16 nCount = (sal_Int16)aSeq.getLength();
      66           0 :         if( nCount > 32 )
      67           0 :             nCount = 32;
      68             : 
      69             :         sal_Int16 nIndex;
      70           0 :         for( nIndex = 0; nIndex < nCount; nIndex++ )
      71             :         {
      72           0 :             aData[nIndex] = static_cast<sal_uInt8>(aSeq[nIndex]);
      73             :         }
      74             : 
      75           0 :         for( ; nIndex < 32; nIndex++ )
      76             :         {
      77           0 :             aData[nIndex] = 0;
      78             :         }
      79           0 :     }
      80           0 : }
      81             : 
      82             : /** returns a uno sequence of sal_Int8
      83             : */
      84           0 : void SetOfByte::QueryValue( com::sun::star::uno::Any & rAny ) const
      85             : {
      86           0 :     sal_Int16 nNumBytesSet = 0;
      87             :     sal_Int16 nIndex;
      88           0 :     for( nIndex = 31; nIndex >= 00; nIndex-- )
      89             :     {
      90           0 :         if( 0 != aData[nIndex] )
      91             :         {
      92           0 :             nNumBytesSet = nIndex + 1;
      93           0 :             break;
      94             :         }
      95             :     }
      96             : 
      97           0 :     com::sun::star::uno::Sequence< sal_Int8 > aSeq( nNumBytesSet );
      98             : 
      99           0 :     for( nIndex = 0; nIndex < nNumBytesSet; nIndex++ )
     100             :     {
     101           0 :         aSeq[nIndex] = static_cast<sal_Int8>(aData[nIndex]);
     102             :     }
     103             : 
     104           0 :     rAny <<= aSeq;
     105           0 : }
     106             : 
     107             : ////////////////////////////////////////////////////////////////////////////////////////////////////
     108             : // SdrLayer
     109             : ////////////////////////////////////////////////////////////////////////////////////////////////////
     110             : 
     111           0 : void SdrLayer::SetStandardLayer(bool bStd)
     112             : {
     113           0 :     nType=(sal_uInt16)bStd;
     114           0 :     if (bStd) {
     115           0 :         aName=ImpGetResStr(STR_StandardLayerName);
     116             :     }
     117           0 :     if (pModel!=NULL) {
     118           0 :         SdrHint aHint(HINT_LAYERCHG);
     119           0 :         pModel->Broadcast(aHint);
     120           0 :         pModel->SetChanged();
     121             :     }
     122           0 : }
     123             : 
     124           0 : void SdrLayer::SetName(const XubString& rNewName)
     125             : {
     126           0 :     if(!rNewName.Equals(aName))
     127             :     {
     128           0 :         aName = rNewName;
     129           0 :         nType = 0; // user defined
     130             : 
     131           0 :         if(pModel)
     132             :         {
     133           0 :             SdrHint aHint(HINT_LAYERCHG);
     134             : 
     135           0 :             pModel->Broadcast(aHint);
     136           0 :             pModel->SetChanged();
     137             :         }
     138             :     }
     139           0 : }
     140             : 
     141           0 : bool SdrLayer::operator==(const SdrLayer& rCmpLayer) const
     142             : {
     143             :     return (nID == rCmpLayer.nID
     144             :         && nType == rCmpLayer.nType
     145           0 :         && aName.Equals(rCmpLayer.aName));
     146             : }
     147             : 
     148             : ////////////////////////////////////////////////////////////////////////////////////////////////////
     149             : // SdrLayerAdmin
     150             : ////////////////////////////////////////////////////////////////////////////////////////////////////
     151             : 
     152         914 : SdrLayerAdmin::SdrLayerAdmin(SdrLayerAdmin* pNewParent):
     153             :     aLayer(),
     154         914 :     pModel(NULL)
     155             : {
     156         914 :     aControlLayerName = String(RTL_CONSTASCII_USTRINGPARAM("Controls"));
     157         914 :     pParent=pNewParent;
     158         914 : }
     159             : 
     160           0 : SdrLayerAdmin::SdrLayerAdmin(const SdrLayerAdmin& rSrcLayerAdmin):
     161             :     aLayer(),
     162             :     pParent(NULL),
     163           0 :     pModel(NULL)
     164             : {
     165           0 :     aControlLayerName = String(RTL_CONSTASCII_USTRINGPARAM("Controls"));
     166           0 :     *this = rSrcLayerAdmin;
     167           0 : }
     168             : 
     169        1080 : SdrLayerAdmin::~SdrLayerAdmin()
     170             : {
     171         540 :     ClearLayer();
     172         540 : }
     173             : 
     174         892 : void SdrLayerAdmin::ClearLayer()
     175             : {
     176        1675 :     for( std::vector<SdrLayer*>::const_iterator it = aLayer.begin(); it != aLayer.end(); ++it )
     177         783 :         delete *it;
     178         892 :     aLayer.clear();
     179         892 : }
     180             : 
     181           0 : const SdrLayerAdmin& SdrLayerAdmin::operator=(const SdrLayerAdmin& rSrcLayerAdmin)
     182             : {
     183           0 :     ClearLayer();
     184           0 :     pParent=rSrcLayerAdmin.pParent;
     185             :     sal_uInt16 i;
     186           0 :     sal_uInt16 nAnz=rSrcLayerAdmin.GetLayerCount();
     187           0 :     for (i=0; i<nAnz; i++) {
     188           0 :         aLayer.push_back(new SdrLayer(*rSrcLayerAdmin.GetLayer(i)));
     189             :     }
     190           0 :     return *this;
     191             : }
     192             : 
     193           0 : bool SdrLayerAdmin::operator==(const SdrLayerAdmin& rCmpLayerAdmin) const
     194             : {
     195           0 :     if (pParent!=rCmpLayerAdmin.pParent ||
     196           0 :         aLayer.size()!=rCmpLayerAdmin.aLayer.size())
     197           0 :         return sal_False;
     198           0 :     bool bOk = true;
     199           0 :     sal_uInt16 nAnz=GetLayerCount();
     200           0 :     sal_uInt16 i=0;
     201           0 :     while (bOk && i<nAnz) {
     202           0 :         bOk=*GetLayer(i)==*rCmpLayerAdmin.GetLayer(i);
     203           0 :         i++;
     204             :     }
     205           0 :     return bOk;
     206             : }
     207             : 
     208         361 : void SdrLayerAdmin::SetModel(SdrModel* pNewModel)
     209             : {
     210         361 :     if (pNewModel!=pModel) {
     211         361 :         pModel=pNewModel;
     212         361 :         sal_uInt16 nAnz=GetLayerCount();
     213             :         sal_uInt16 i;
     214         361 :         for (i=0; i<nAnz; i++) {
     215           0 :             GetLayer(i)->SetModel(pNewModel);
     216             :         }
     217             :     }
     218         361 : }
     219             : 
     220        1862 : void SdrLayerAdmin::Broadcast() const
     221             : {
     222        1862 :     if (pModel!=NULL) {
     223        1862 :         SdrHint aHint(HINT_LAYERORDERCHG);
     224        1862 :         pModel->Broadcast(aHint);
     225        1862 :         pModel->SetChanged();
     226             :     }
     227        1862 : }
     228             : 
     229           0 : SdrLayer* SdrLayerAdmin::RemoveLayer(sal_uInt16 nPos)
     230             : {
     231           0 :     SdrLayer* pRetLayer=aLayer[nPos];
     232           0 :     aLayer.erase(aLayer.begin()+nPos);
     233           0 :     Broadcast();
     234           0 :     return pRetLayer;
     235             : }
     236             : 
     237        1862 : SdrLayer* SdrLayerAdmin::NewLayer(const XubString& rName, sal_uInt16 nPos)
     238             : {
     239        1862 :     SdrLayerID nID=GetUniqueLayerID();
     240        1862 :     SdrLayer* pLay=new SdrLayer(nID,rName);
     241        1862 :     pLay->SetModel(pModel);
     242        1862 :     if(nPos==0xFFFF)
     243        1672 :         aLayer.push_back(pLay);
     244             :     else
     245         190 :         aLayer.insert(aLayer.begin() + nPos, pLay);
     246        1862 :     Broadcast();
     247        1862 :     return pLay;
     248             : }
     249             : 
     250           0 : SdrLayer* SdrLayerAdmin::NewStandardLayer(sal_uInt16 nPos)
     251             : {
     252           0 :     SdrLayerID nID=GetUniqueLayerID();
     253           0 :     SdrLayer* pLay=new SdrLayer(nID,String());
     254           0 :     pLay->SetStandardLayer();
     255           0 :     pLay->SetModel(pModel);
     256           0 :     if(nPos==0xFFFF)
     257           0 :         aLayer.push_back(pLay);
     258             :     else
     259           0 :         aLayer.insert(aLayer.begin() + nPos, pLay);
     260           0 :     Broadcast();
     261           0 :     return pLay;
     262             : }
     263             : 
     264           0 : sal_uInt16 SdrLayerAdmin::GetLayerPos(SdrLayer* pLayer) const
     265             : {
     266           0 :     sal_uIntPtr nRet=SDRLAYER_NOTFOUND;
     267           0 :     if (pLayer!=NULL) {
     268           0 :         std::vector<SdrLayer*>::const_iterator it = std::find(aLayer.begin(), aLayer.end(), pLayer);
     269           0 :         if (it==aLayer.end()) {
     270           0 :             nRet=SDRLAYER_NOTFOUND;
     271             :         } else {
     272           0 :             nRet=it - aLayer.begin();
     273             :         }
     274             :     }
     275           0 :     return sal_uInt16(nRet);
     276             : }
     277             : 
     278        2943 : const SdrLayer* SdrLayerAdmin::GetLayer(const XubString& rName, bool /*bInherited*/) const
     279             : {
     280        2943 :     sal_uInt16 i(0);
     281        2943 :     const SdrLayer* pLay = NULL;
     282             : 
     283       13769 :     while(i < GetLayerCount() && !pLay)
     284             :     {
     285        7883 :         if(rName.Equals(GetLayer(i)->GetName()))
     286        2227 :             pLay = GetLayer(i);
     287             :         else
     288        5656 :             i++;
     289             :     }
     290             : 
     291        2943 :     if(!pLay && pParent)
     292             :     {
     293         716 :         pLay = pParent->GetLayer(rName, sal_True);
     294             :     }
     295             : 
     296        2943 :     return pLay;
     297             : }
     298             : 
     299        2082 : SdrLayerID SdrLayerAdmin::GetLayerID(const XubString& rName, bool bInherited) const
     300             : {
     301        2082 :     SdrLayerID nRet=SDRLAYER_NOTFOUND;
     302        2082 :     const SdrLayer* pLay=GetLayer(rName,bInherited);
     303        2082 :     if (pLay!=NULL) nRet=pLay->GetID();
     304        2082 :     return nRet;
     305             : }
     306             : 
     307          77 : const SdrLayer* SdrLayerAdmin::GetLayerPerID(sal_uInt16 nID) const
     308             : {
     309          77 :     sal_uInt16 i=0;
     310          77 :     const SdrLayer* pLay=NULL;
     311         231 :     while (i<GetLayerCount() && pLay==NULL) {
     312          77 :         if (nID==GetLayer(i)->GetID()) pLay=GetLayer(i);
     313           0 :         else i++;
     314             :     }
     315          77 :     return pLay;
     316             : }
     317             : 
     318             : // Global LayerIDs begin at 0 and increase,
     319             : // local LayerIDs begin at 254 and decrease;
     320             : // 255 is reserved for SDRLAYER_NOTFOUND.
     321             : 
     322        1862 : SdrLayerID SdrLayerAdmin::GetUniqueLayerID() const
     323             : {
     324        1862 :     SetOfByte aSet;
     325        1862 :     sal_Bool bDown = (pParent == NULL);
     326             :     sal_uInt16 j;
     327        6372 :     for (j=0; j<GetLayerCount(); j++)
     328             :     {
     329        4510 :         aSet.Set(GetLayer((sal_uInt16)j)->GetID());
     330             :     }
     331             :     SdrLayerID i;
     332        1862 :     if (!bDown)
     333             :     {
     334           0 :         i=254;
     335           0 :         while (i && aSet.IsSet(sal_uInt8(i)))
     336           0 :             --i;
     337           0 :         if (i == 0)
     338           0 :             i=254;
     339             :     }
     340             :     else
     341             :     {
     342        1862 :         i=0;
     343        8234 :         while (i<=254 && aSet.IsSet(sal_uInt8(i)))
     344        4510 :             i++;
     345        1862 :         if (i>254)
     346           0 :             i=0;
     347             :     }
     348        1862 :     return i;
     349             : }
     350             : 
     351             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10