LCOV - code coverage report
Current view: top level - svx/source/svdraw - svdlayer.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 110 176 62.5 %
Date: 2012-08-25 Functions: 16 24 66.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 94 234 40.2 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <com/sun/star/uno/Sequence.hxx>
      30                 :            : 
      31                 :            : #include <svx/svdlayer.hxx>
      32                 :            : #include <svx/svdmodel.hxx> // for Broadcasting
      33                 :            : #include "svx/svdglob.hxx"  // StringCache
      34                 :            : #include "svx/svdstr.hrc"   // names taken from the resource
      35                 :            : 
      36                 :            : ////////////////////////////////////////////////////////////////////////////////////////////////////
      37                 :            : // SetOfByte
      38                 :            : ////////////////////////////////////////////////////////////////////////////////////////////////////
      39                 :            : 
      40                 :      49800 : sal_Bool SetOfByte::IsEmpty() const
      41                 :            : {
      42         [ +  + ]:     109436 :     for(sal_uInt16 i(0); i < 32; i++)
      43                 :            :     {
      44         [ +  + ]:     108514 :         if(aData[i] != 0)
      45                 :      48878 :             return sal_False;
      46                 :            :     }
      47                 :            : 
      48                 :      49800 :     return sal_True;
      49                 :            : }
      50                 :            : 
      51                 :       4326 : void SetOfByte::operator&=(const SetOfByte& r2ndSet)
      52                 :            : {
      53         [ +  + ]:     142758 :     for(sal_uInt16 i(0); i < 32; i++)
      54                 :            :     {
      55                 :     138432 :         aData[i] &= r2ndSet.aData[i];
      56                 :            :     }
      57                 :       4326 : }
      58                 :            : 
      59                 :          0 : void SetOfByte::operator|=(const SetOfByte& r2ndSet)
      60                 :            : {
      61         [ #  # ]:          0 :     for(sal_uInt16 i(0); i < 32; i++)
      62                 :            :     {
      63                 :          0 :         aData[i] |= r2ndSet.aData[i];
      64                 :            :     }
      65                 :          0 : }
      66                 :            : 
      67                 :            : /** initialize this set with a uno sequence of sal_Int8
      68                 :            : */
      69                 :        312 : void SetOfByte::PutValue( const com::sun::star::uno::Any & rAny )
      70                 :            : {
      71         [ +  - ]:        312 :     com::sun::star::uno::Sequence< sal_Int8 > aSeq;
      72 [ +  - ][ +  - ]:        312 :     if( rAny >>= aSeq )
      73                 :            :     {
      74                 :        312 :         sal_Int16 nCount = (sal_Int16)aSeq.getLength();
      75         [ -  + ]:        312 :         if( nCount > 32 )
      76                 :          0 :             nCount = 32;
      77                 :            : 
      78                 :            :         sal_Int16 nIndex;
      79         [ +  + ]:       6968 :         for( nIndex = 0; nIndex < nCount; nIndex++ )
      80                 :            :         {
      81         [ +  - ]:       6656 :             aData[nIndex] = static_cast<sal_uInt8>(aSeq[nIndex]);
      82                 :            :         }
      83                 :            : 
      84         [ +  + ]:       3640 :         for( ; nIndex < 32; nIndex++ )
      85                 :            :         {
      86                 :       3328 :             aData[nIndex] = 0;
      87                 :            :         }
      88         [ +  - ]:        312 :     }
      89                 :        312 : }
      90                 :            : 
      91                 :            : /** returns a uno sequence of sal_Int8
      92                 :            : */
      93                 :        402 : void SetOfByte::QueryValue( com::sun::star::uno::Any & rAny ) const
      94                 :            : {
      95                 :        402 :     sal_Int16 nNumBytesSet = 0;
      96                 :            :     sal_Int16 nIndex;
      97         [ +  + ]:       4690 :     for( nIndex = 31; nIndex >= 00; nIndex-- )
      98                 :            :     {
      99         [ +  + ]:       4556 :         if( 0 != aData[nIndex] )
     100                 :            :         {
     101                 :        268 :             nNumBytesSet = nIndex + 1;
     102                 :        268 :             break;
     103                 :            :         }
     104                 :            :     }
     105                 :            : 
     106         [ +  - ]:        402 :     com::sun::star::uno::Sequence< sal_Int8 > aSeq( nNumBytesSet );
     107                 :            : 
     108         [ +  + ]:       8978 :     for( nIndex = 0; nIndex < nNumBytesSet; nIndex++ )
     109                 :            :     {
     110         [ +  - ]:       8576 :         aSeq[nIndex] = static_cast<sal_Int8>(aData[nIndex]);
     111                 :            :     }
     112                 :            : 
     113 [ +  - ][ +  - ]:        402 :     rAny <<= aSeq;
     114                 :        402 : }
     115                 :            : 
     116                 :            : ////////////////////////////////////////////////////////////////////////////////////////////////////
     117                 :            : // SdrLayer
     118                 :            : ////////////////////////////////////////////////////////////////////////////////////////////////////
     119                 :            : 
     120                 :          0 : void SdrLayer::SetStandardLayer(bool bStd)
     121                 :            : {
     122                 :          0 :     nType=(sal_uInt16)bStd;
     123         [ #  # ]:          0 :     if (bStd) {
     124         [ #  # ]:          0 :         aName=ImpGetResStr(STR_StandardLayerName);
     125                 :            :     }
     126         [ #  # ]:          0 :     if (pModel!=NULL) {
     127         [ #  # ]:          0 :         SdrHint aHint(HINT_LAYERCHG);
     128         [ #  # ]:          0 :         pModel->Broadcast(aHint);
     129 [ #  # ][ #  # ]:          0 :         pModel->SetChanged();
     130                 :            :     }
     131                 :          0 : }
     132                 :            : 
     133                 :          0 : void SdrLayer::SetName(const XubString& rNewName)
     134                 :            : {
     135         [ #  # ]:          0 :     if(!rNewName.Equals(aName))
     136                 :            :     {
     137                 :          0 :         aName = rNewName;
     138                 :          0 :         nType = 0; // user defined
     139                 :            : 
     140         [ #  # ]:          0 :         if(pModel)
     141                 :            :         {
     142         [ #  # ]:          0 :             SdrHint aHint(HINT_LAYERCHG);
     143                 :            : 
     144         [ #  # ]:          0 :             pModel->Broadcast(aHint);
     145 [ #  # ][ #  # ]:          0 :             pModel->SetChanged();
     146                 :            :         }
     147                 :            :     }
     148                 :          0 : }
     149                 :            : 
     150                 :          0 : bool SdrLayer::operator==(const SdrLayer& rCmpLayer) const
     151                 :            : {
     152                 :            :     return (nID == rCmpLayer.nID
     153                 :            :         && nType == rCmpLayer.nType
     154 [ #  # ][ #  # ]:          0 :         && aName.Equals(rCmpLayer.aName));
                 [ #  # ]
     155                 :            : }
     156                 :            : 
     157                 :            : ////////////////////////////////////////////////////////////////////////////////////////////////////
     158                 :            : // SdrLayerAdmin
     159                 :            : ////////////////////////////////////////////////////////////////////////////////////////////////////
     160                 :            : 
     161                 :       6378 : SdrLayerAdmin::SdrLayerAdmin(SdrLayerAdmin* pNewParent):
     162                 :            :     aLayer(),
     163         [ +  - ]:       6378 :     pModel(NULL)
     164                 :            : {
     165 [ +  - ][ +  - ]:       6378 :     aControlLayerName = String(RTL_CONSTASCII_USTRINGPARAM("Controls"));
                 [ +  - ]
     166                 :       6378 :     pParent=pNewParent;
     167                 :       6378 : }
     168                 :            : 
     169                 :          0 : SdrLayerAdmin::SdrLayerAdmin(const SdrLayerAdmin& rSrcLayerAdmin):
     170                 :            :     aLayer(),
     171                 :            :     pParent(NULL),
     172         [ #  # ]:          0 :     pModel(NULL)
     173                 :            : {
     174 [ #  # ][ #  # ]:          0 :     aControlLayerName = String(RTL_CONSTASCII_USTRINGPARAM("Controls"));
                 [ #  # ]
     175         [ #  # ]:          0 :     *this = rSrcLayerAdmin;
     176                 :          0 : }
     177                 :            : 
     178         [ +  - ]:       6139 : SdrLayerAdmin::~SdrLayerAdmin()
     179                 :            : {
     180         [ +  - ]:       6139 :     ClearLayer();
     181                 :       6139 : }
     182                 :            : 
     183                 :      11452 : void SdrLayerAdmin::ClearLayer()
     184                 :            : {
     185 [ +  - ][ +  - ]:      21654 :     for( std::vector<SdrLayer*>::const_iterator it = aLayer.begin(); it != aLayer.end(); ++it )
         [ +  - ][ +  + ]
     186 [ +  - ][ +  - ]:      10202 :         delete *it;
                 [ +  - ]
     187                 :      11452 :     aLayer.clear();
     188                 :      11452 : }
     189                 :            : 
     190                 :          0 : const SdrLayerAdmin& SdrLayerAdmin::operator=(const SdrLayerAdmin& rSrcLayerAdmin)
     191                 :            : {
     192                 :          0 :     ClearLayer();
     193                 :          0 :     pParent=rSrcLayerAdmin.pParent;
     194                 :            :     sal_uInt16 i;
     195                 :          0 :     sal_uInt16 nAnz=rSrcLayerAdmin.GetLayerCount();
     196         [ #  # ]:          0 :     for (i=0; i<nAnz; i++) {
     197 [ #  # ][ #  # ]:          0 :         aLayer.push_back(new SdrLayer(*rSrcLayerAdmin.GetLayer(i)));
     198                 :            :     }
     199                 :          0 :     return *this;
     200                 :            : }
     201                 :            : 
     202                 :          0 : bool SdrLayerAdmin::operator==(const SdrLayerAdmin& rCmpLayerAdmin) const
     203                 :            : {
     204   [ #  #  #  # ]:          0 :     if (pParent!=rCmpLayerAdmin.pParent ||
                 [ #  # ]
     205                 :          0 :         aLayer.size()!=rCmpLayerAdmin.aLayer.size())
     206                 :          0 :         return sal_False;
     207                 :          0 :     bool bOk = true;
     208                 :          0 :     sal_uInt16 nAnz=GetLayerCount();
     209                 :          0 :     sal_uInt16 i=0;
     210 [ #  # ][ #  # ]:          0 :     while (bOk && i<nAnz) {
                 [ #  # ]
     211                 :          0 :         bOk=*GetLayer(i)==*rCmpLayerAdmin.GetLayer(i);
     212                 :          0 :         i++;
     213                 :            :     }
     214                 :          0 :     return bOk;
     215                 :            : }
     216                 :            : 
     217                 :       3328 : void SdrLayerAdmin::SetModel(SdrModel* pNewModel)
     218                 :            : {
     219         [ +  - ]:       3328 :     if (pNewModel!=pModel) {
     220                 :       3328 :         pModel=pNewModel;
     221                 :       3328 :         sal_uInt16 nAnz=GetLayerCount();
     222                 :            :         sal_uInt16 i;
     223         [ -  + ]:       3328 :         for (i=0; i<nAnz; i++) {
     224                 :          0 :             GetLayer(i)->SetModel(pNewModel);
     225                 :            :         }
     226                 :            :     }
     227                 :       3328 : }
     228                 :            : 
     229                 :      10820 : void SdrLayerAdmin::Broadcast() const
     230                 :            : {
     231         [ +  - ]:      10820 :     if (pModel!=NULL) {
     232         [ +  - ]:      10820 :         SdrHint aHint(HINT_LAYERORDERCHG);
     233         [ +  - ]:      10820 :         pModel->Broadcast(aHint);
     234 [ +  - ][ +  - ]:      10820 :         pModel->SetChanged();
     235                 :            :     }
     236                 :      10820 : }
     237                 :            : 
     238                 :          2 : SdrLayer* SdrLayerAdmin::RemoveLayer(sal_uInt16 nPos)
     239                 :            : {
     240                 :          2 :     SdrLayer* pRetLayer=aLayer[nPos];
     241 [ +  - ][ +  - ]:          2 :     aLayer.erase(aLayer.begin()+nPos);
     242                 :          2 :     Broadcast();
     243                 :          2 :     return pRetLayer;
     244                 :            : }
     245                 :            : 
     246                 :      10818 : SdrLayer* SdrLayerAdmin::NewLayer(const XubString& rName, sal_uInt16 nPos)
     247                 :            : {
     248         [ +  - ]:      10818 :     SdrLayerID nID=GetUniqueLayerID();
     249 [ +  - ][ +  - ]:      10818 :     SdrLayer* pLay=new SdrLayer(nID,rName);
     250                 :      10818 :     pLay->SetModel(pModel);
     251         [ +  + ]:      10818 :     if(nPos==0xFFFF)
     252         [ +  - ]:       9206 :         aLayer.push_back(pLay);
     253                 :            :     else
     254 [ +  - ][ +  - ]:       1612 :         aLayer.insert(aLayer.begin() + nPos, pLay);
     255         [ +  - ]:      10818 :     Broadcast();
     256                 :      10818 :     return pLay;
     257                 :            : }
     258                 :            : 
     259                 :          0 : SdrLayer* SdrLayerAdmin::NewStandardLayer(sal_uInt16 nPos)
     260                 :            : {
     261         [ #  # ]:          0 :     SdrLayerID nID=GetUniqueLayerID();
     262 [ #  # ][ #  # ]:          0 :     SdrLayer* pLay=new SdrLayer(nID,String());
         [ #  # ][ #  # ]
     263         [ #  # ]:          0 :     pLay->SetStandardLayer();
     264                 :          0 :     pLay->SetModel(pModel);
     265         [ #  # ]:          0 :     if(nPos==0xFFFF)
     266         [ #  # ]:          0 :         aLayer.push_back(pLay);
     267                 :            :     else
     268 [ #  # ][ #  # ]:          0 :         aLayer.insert(aLayer.begin() + nPos, pLay);
     269         [ #  # ]:          0 :     Broadcast();
     270                 :          0 :     return pLay;
     271                 :            : }
     272                 :            : 
     273                 :          2 : sal_uInt16 SdrLayerAdmin::GetLayerPos(SdrLayer* pLayer) const
     274                 :            : {
     275                 :          2 :     sal_uIntPtr nRet=SDRLAYER_NOTFOUND;
     276         [ +  - ]:          2 :     if (pLayer!=NULL) {
     277         [ +  - ]:          2 :         std::vector<SdrLayer*>::const_iterator it = std::find(aLayer.begin(), aLayer.end(), pLayer);
     278 [ +  - ][ -  + ]:          2 :         if (it==aLayer.end()) {
     279                 :          0 :             nRet=SDRLAYER_NOTFOUND;
     280                 :            :         } else {
     281         [ +  - ]:          2 :             nRet=it - aLayer.begin();
     282                 :            :         }
     283                 :            :     }
     284                 :          2 :     return sal_uInt16(nRet);
     285                 :            : }
     286                 :            : 
     287                 :     106333 : const SdrLayer* SdrLayerAdmin::GetLayer(const XubString& rName, bool /*bInherited*/) const
     288                 :            : {
     289                 :     106333 :     sal_uInt16 i(0);
     290                 :     106333 :     const SdrLayer* pLay = NULL;
     291                 :            : 
     292 [ +  + ][ +  + ]:     344101 :     while(i < GetLayerCount() && !pLay)
                 [ +  + ]
     293                 :            :     {
     294         [ +  + ]:     237768 :         if(rName.Equals(GetLayer(i)->GetName()))
     295                 :      82685 :             pLay = GetLayer(i);
     296                 :            :         else
     297                 :     155083 :             i++;
     298                 :            :     }
     299                 :            : 
     300 [ +  + ][ +  + ]:     106333 :     if(!pLay && pParent)
     301                 :            :     {
     302                 :      20726 :         pLay = pParent->GetLayer(rName, sal_True);
     303                 :            :     }
     304                 :            : 
     305                 :     106333 :     return pLay;
     306                 :            : }
     307                 :            : 
     308                 :      85071 : SdrLayerID SdrLayerAdmin::GetLayerID(const XubString& rName, bool bInherited) const
     309                 :            : {
     310                 :      85071 :     SdrLayerID nRet=SDRLAYER_NOTFOUND;
     311                 :      85071 :     const SdrLayer* pLay=GetLayer(rName,bInherited);
     312         [ +  + ]:      85071 :     if (pLay!=NULL) nRet=pLay->GetID();
     313                 :      85071 :     return nRet;
     314                 :            : }
     315                 :            : 
     316                 :       3039 : const SdrLayer* SdrLayerAdmin::GetLayerPerID(sal_uInt16 nID) const
     317                 :            : {
     318                 :       3039 :     sal_uInt16 i=0;
     319                 :       3039 :     const SdrLayer* pLay=NULL;
     320 [ +  - ][ +  + ]:      11671 :     while (i<GetLayerCount() && pLay==NULL) {
                 [ +  + ]
     321         [ +  + ]:       8632 :         if (nID==GetLayer(i)->GetID()) pLay=GetLayer(i);
     322                 :       5593 :         else i++;
     323                 :            :     }
     324                 :       3039 :     return pLay;
     325                 :            : }
     326                 :            : 
     327                 :            : // Global LayerIDs begin at 0 and increase,
     328                 :            : // local LayerIDs begin at 254 and decrease;
     329                 :            : // 255 is reserved for SDRLAYER_NOTFOUND.
     330                 :            : 
     331                 :      10818 : SdrLayerID SdrLayerAdmin::GetUniqueLayerID() const
     332                 :            : {
     333                 :      10818 :     SetOfByte aSet;
     334                 :      10818 :     sal_Bool bDown = (pParent == NULL);
     335                 :            :     sal_uInt16 j;
     336         [ +  + ]:      36618 :     for (j=0; j<GetLayerCount(); j++)
     337                 :            :     {
     338         [ +  - ]:      25800 :         aSet.Set(GetLayer((sal_uInt16)j)->GetID());
     339                 :            :     }
     340                 :            :     SdrLayerID i;
     341         [ -  + ]:      10818 :     if (!bDown)
     342                 :            :     {
     343                 :          0 :         i=254;
     344 [ #  # ][ #  # ]:          0 :         while (i && aSet.IsSet(sal_uInt8(i)))
                 [ #  # ]
     345                 :          0 :             --i;
     346         [ #  # ]:          0 :         if (i == 0)
     347                 :          0 :             i=254;
     348                 :            :     }
     349                 :            :     else
     350                 :            :     {
     351                 :      10818 :         i=0;
     352 [ +  - ][ +  + ]:      36618 :         while (i<=254 && aSet.IsSet(sal_uInt8(i)))
                 [ +  + ]
     353                 :      25800 :             i++;
     354         [ -  + ]:      10818 :         if (i>254)
     355                 :          0 :             i=0;
     356                 :            :     }
     357                 :      10818 :     return i;
     358                 :            : }
     359                 :            : 
     360                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10