LCOV - code coverage report
Current view: top level - libreoffice/svx/source/svdraw - svdlayer.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 76 176 43.2 %
Date: 2012-12-17 Functions: 12 24 50.0 %
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        2135 : sal_Bool SetOfByte::IsEmpty() const
      32             : {
      33        2391 :     for(sal_uInt16 i(0); i < 32; i++)
      34             :     {
      35        2383 :         if(aData[i] != 0)
      36        2127 :             return sal_False;
      37             :     }
      38             : 
      39           8 :     return sal_True;
      40             : }
      41             : 
      42          16 : void SetOfByte::operator&=(const SetOfByte& r2ndSet)
      43             : {
      44         528 :     for(sal_uInt16 i(0); i < 32; i++)
      45             :     {
      46         512 :         aData[i] &= r2ndSet.aData[i];
      47             :     }
      48          16 : }
      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        1946 : SdrLayerAdmin::SdrLayerAdmin(SdrLayerAdmin* pNewParent):
     153             :     aLayer(),
     154        1946 :     pModel(NULL)
     155             : {
     156        1946 :     aControlLayerName = String(RTL_CONSTASCII_USTRINGPARAM("Controls"));
     157        1946 :     pParent=pNewParent;
     158        1946 : }
     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        2124 : SdrLayerAdmin::~SdrLayerAdmin()
     170             : {
     171        1062 :     ClearLayer();
     172        1062 : }
     173             : 
     174        1736 : void SdrLayerAdmin::ClearLayer()
     175             : {
     176        3108 :     for( std::vector<SdrLayer*>::const_iterator it = aLayer.begin(); it != aLayer.end(); ++it )
     177        1372 :         delete *it;
     178        1736 :     aLayer.clear();
     179        1736 : }
     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         758 : void SdrLayerAdmin::SetModel(SdrModel* pNewModel)
     209             : {
     210         758 :     if (pNewModel!=pModel) {
     211         758 :         pModel=pNewModel;
     212         758 :         sal_uInt16 nAnz=GetLayerCount();
     213             :         sal_uInt16 i;
     214         758 :         for (i=0; i<nAnz; i++) {
     215           0 :             GetLayer(i)->SetModel(pNewModel);
     216             :         }
     217             :     }
     218         758 : }
     219             : 
     220        3910 : void SdrLayerAdmin::Broadcast() const
     221             : {
     222        3910 :     if (pModel!=NULL) {
     223        3910 :         SdrHint aHint(HINT_LAYERORDERCHG);
     224        3910 :         pModel->Broadcast(aHint);
     225        3910 :         pModel->SetChanged();
     226             :     }
     227        3910 : }
     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        3910 : SdrLayer* SdrLayerAdmin::NewLayer(const XubString& rName, sal_uInt16 nPos)
     238             : {
     239        3910 :     SdrLayerID nID=GetUniqueLayerID();
     240        3910 :     SdrLayer* pLay=new SdrLayer(nID,rName);
     241        3910 :     pLay->SetModel(pModel);
     242        3910 :     if(nPos==0xFFFF)
     243        3380 :         aLayer.push_back(pLay);
     244             :     else
     245         530 :         aLayer.insert(aLayer.begin() + nPos, pLay);
     246        3910 :     Broadcast();
     247        3910 :     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        7386 : const SdrLayer* SdrLayerAdmin::GetLayer(const XubString& rName, bool /*bInherited*/) const
     279             : {
     280        7386 :     sal_uInt16 i(0);
     281        7386 :     const SdrLayer* pLay = NULL;
     282             : 
     283       34012 :     while(i < GetLayerCount() && !pLay)
     284             :     {
     285       19240 :         if(rName.Equals(GetLayer(i)->GetName()))
     286        5528 :             pLay = GetLayer(i);
     287             :         else
     288       13712 :             i++;
     289             :     }
     290             : 
     291        7386 :     if(!pLay && pParent)
     292             :     {
     293        1858 :         pLay = pParent->GetLayer(rName, sal_True);
     294             :     }
     295             : 
     296        7386 :     return pLay;
     297             : }
     298             : 
     299        5238 : SdrLayerID SdrLayerAdmin::GetLayerID(const XubString& rName, bool bInherited) const
     300             : {
     301        5238 :     SdrLayerID nRet=SDRLAYER_NOTFOUND;
     302        5238 :     const SdrLayer* pLay=GetLayer(rName,bInherited);
     303        5238 :     if (pLay!=NULL) nRet=pLay->GetID();
     304        5238 :     return nRet;
     305             : }
     306             : 
     307         494 : const SdrLayer* SdrLayerAdmin::GetLayerPerID(sal_uInt16 nID) const
     308             : {
     309         494 :     sal_uInt16 i=0;
     310         494 :     const SdrLayer* pLay=NULL;
     311        2162 :     while (i<GetLayerCount() && pLay==NULL) {
     312        1174 :         if (nID==GetLayer(i)->GetID()) pLay=GetLayer(i);
     313         680 :         else i++;
     314             :     }
     315         494 :     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        3910 : SdrLayerID SdrLayerAdmin::GetUniqueLayerID() const
     323             : {
     324        3910 :     SetOfByte aSet;
     325        3910 :     sal_Bool bDown = (pParent == NULL);
     326             :     sal_uInt16 j;
     327       13320 :     for (j=0; j<GetLayerCount(); j++)
     328             :     {
     329        9410 :         aSet.Set(GetLayer((sal_uInt16)j)->GetID());
     330             :     }
     331             :     SdrLayerID i;
     332        3910 :     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        3910 :         i=0;
     343       17230 :         while (i<=254 && aSet.IsSet(sal_uInt8(i)))
     344        9410 :             i++;
     345        3910 :         if (i>254)
     346           0 :             i=0;
     347             :     }
     348        3910 :     return i;
     349             : }
     350             : 
     351             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10