LCOV - code coverage report
Current view: top level - sw/source/ui/envelp - labelcfg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 171 0.0 %
Date: 2012-08-25 Functions: 0 12 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 292 0.0 %

           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 <swtypes.hxx>
      30                 :            : #include <labelcfg.hxx>
      31                 :            : #include <labimp.hxx>
      32                 :            : #include <comphelper/string.hxx>
      33                 :            : #include <unotools/configpaths.hxx>
      34                 :            : 
      35                 :            : #include <unomid.h>
      36                 :            : 
      37                 :            : using namespace utl;
      38                 :            : using namespace ::com::sun::star::uno;
      39                 :            : using namespace ::com::sun::star::beans;
      40                 :            : 
      41                 :            : using ::rtl::OUString;
      42                 :            : 
      43                 :          0 : SwLabelConfig::SwLabelConfig() :
      44 [ #  # ][ #  # ]:          0 :     ConfigItem(C2U("Office.Labels/Manufacturer"))
      45                 :            : {
      46 [ #  # ][ #  # ]:          0 :     aNodeNames = GetNodeNames(OUString());
                 [ #  # ]
      47                 :          0 : }
      48                 :            : 
      49         [ #  # ]:          0 : SwLabelConfig::~SwLabelConfig()
      50                 :            : {
      51         [ #  # ]:          0 : }
      52                 :            : 
      53                 :          0 : void    SwLabelConfig::Commit()
      54                 :            : {
      55                 :            :     // the config item is not writable yet
      56                 :          0 : }
      57                 :            : 
      58                 :          0 : void SwLabelConfig::Notify( const ::com::sun::star::uno::Sequence< rtl::OUString >& ) {}
      59                 :            : 
      60                 :          0 : Sequence<OUString> lcl_CreatePropertyNames(const OUString& rPrefix)
      61                 :            : {
      62                 :          0 :     Sequence<OUString> aProperties(2);
      63         [ #  # ]:          0 :     OUString* pProperties = aProperties.getArray();
      64         [ #  # ]:          0 :     for(sal_Int32 nProp = 0; nProp < 2; nProp++)
      65                 :          0 :         pProperties[nProp] = rPrefix;
      66                 :            : 
      67         [ #  # ]:          0 :     pProperties[ 0] += C2U("Name");
      68         [ #  # ]:          0 :     pProperties[ 1] += C2U("Measure");
      69                 :          0 :     return aProperties;
      70                 :            : }
      71                 :            : 
      72                 :          0 : SwLabRec* lcl_CreateSwLabRec(Sequence<Any>& rValues, const OUString& rManufacturer)
      73                 :            : {
      74 [ #  # ][ #  # ]:          0 :     SwLabRec* pNewRec = new SwLabRec;
      75                 :          0 :     const Any* pValues = rValues.getConstArray();
      76                 :          0 :     OUString sTmp;
      77         [ #  # ]:          0 :     pNewRec->aMake = rManufacturer;
      78                 :          0 :     pNewRec->lPWidth = 0;
      79                 :          0 :     pNewRec->lPHeight = 0;
      80         [ #  # ]:          0 :     for(sal_Int32 nProp = 0; nProp < rValues.getLength(); nProp++)
      81                 :            :     {
      82         [ #  # ]:          0 :         if(pValues[nProp].hasValue())
      83                 :            :         {
      84      [ #  #  # ]:          0 :             switch(nProp)
      85                 :            :             {
      86         [ #  # ]:          0 :                 case 0: pValues[nProp] >>= sTmp; pNewRec->aType = sTmp; break;
      87                 :            :                 case 1:
      88                 :            :                 {
      89                 :            :                     //all values are contained as colon-separated 1/100 mm values
      90                 :            :                     //except for the continuous flag ('C'/'S')
      91                 :          0 :                     pValues[nProp] >>= sTmp;
      92         [ #  # ]:          0 :                     String sMeasure(sTmp);
      93 [ #  # ][ #  # ]:          0 :                     sal_uInt16 nTokenCount = comphelper::string::getTokenCount(sMeasure, ';');
      94         [ #  # ]:          0 :                     for(sal_uInt16 i = 0; i < nTokenCount; i++)
      95                 :            :                     {
      96         [ #  # ]:          0 :                         String sToken(sMeasure.GetToken(i, ';' ));
      97         [ #  # ]:          0 :                         int nVal = sToken.ToInt32();
      98   [ #  #  #  #  :          0 :                         switch(i)
          #  #  #  #  #  
                #  #  # ]
      99                 :            :                         {
     100                 :          0 :                             case  0 : pNewRec->bCont = sToken.GetChar(0) == 'C'; break;
     101         [ #  # ]:          0 :                             case  1 : pNewRec->lHDist    = MM100_TO_TWIP(nVal);  break;
     102         [ #  # ]:          0 :                             case  2 : pNewRec->lVDist    = MM100_TO_TWIP(nVal);  break;
     103         [ #  # ]:          0 :                             case  3 : pNewRec->lWidth    = MM100_TO_TWIP(nVal);  break;
     104         [ #  # ]:          0 :                             case  4 : pNewRec->lHeight   = MM100_TO_TWIP(nVal);  break;
     105         [ #  # ]:          0 :                             case  5 : pNewRec->lLeft     = MM100_TO_TWIP(nVal);  break;
     106         [ #  # ]:          0 :                             case  6 : pNewRec->lUpper    = MM100_TO_TWIP(nVal);  break;
     107                 :          0 :                             case  7 : pNewRec->nCols     = nVal;                 break;
     108                 :          0 :                             case  8 : pNewRec->nRows     = nVal;                 break;
     109         [ #  # ]:          0 :                             case  9 : pNewRec->lPWidth   = MM100_TO_TWIP(nVal);  break;
     110         [ #  # ]:          0 :                             case 10 : pNewRec->lPHeight  = MM100_TO_TWIP(nVal);  break;
     111                 :            :                         }
     112 [ #  # ][ #  # ]:          0 :                     }
     113                 :            :                 }
     114                 :          0 :                 break;
     115                 :            :             }
     116                 :            :         }
     117                 :            :     }
     118                 :            :     // lines added for compatibility with custom label defintions saved before patch 44516
     119 [ #  # ][ #  # ]:          0 :     if (pNewRec->lPWidth == 0 || pNewRec->lPHeight == 0)
     120                 :            :     {
     121                 :            :         // old style definition (no paper dimensions), calculate probable values
     122                 :          0 :         pNewRec->lPWidth = 2 * pNewRec->lLeft + (pNewRec->nCols - 1) * pNewRec->lHDist + pNewRec->lWidth;
     123         [ #  # ]:          0 :         pNewRec->lPHeight = ( pNewRec->bCont ? pNewRec->nRows * pNewRec->lVDist : 2 * pNewRec->lUpper + (pNewRec->nRows - 1) * pNewRec->lVDist + pNewRec->lHeight );
     124                 :            :     }
     125                 :          0 :     return pNewRec;
     126                 :            : }
     127                 :            : 
     128                 :          0 : Sequence<PropertyValue> lcl_CreateProperties(
     129                 :            :     Sequence<OUString>& rPropNames, const SwLabRec& rRec)
     130                 :            : {
     131                 :          0 :     const OUString* pNames = rPropNames.getConstArray();
     132         [ #  # ]:          0 :     Sequence<PropertyValue> aRet(rPropNames.getLength());
     133         [ #  # ]:          0 :     PropertyValue* pValues = aRet.getArray();
     134         [ #  # ]:          0 :     OUString sColon(C2U(";"));
     135                 :            : 
     136         [ #  # ]:          0 :     for(sal_Int32 nProp = 0; nProp < rPropNames.getLength(); nProp++)
     137                 :            :     {
     138                 :          0 :         pValues[nProp].Name = pNames[nProp];
     139      [ #  #  # ]:          0 :         switch(nProp)
     140                 :            :         {
     141 [ #  # ][ #  # ]:          0 :             case 0: pValues[nProp].Value <<= OUString(rRec.aType); break;
     142                 :            :             case 1:
     143                 :            :             {
     144                 :          0 :                 OUString sTmp;
     145 [ #  # ][ #  # ]:          0 :                 sTmp += C2U( rRec.bCont ? "C" : "S");                         sTmp += sColon;
     146         [ #  # ]:          0 :                 sTmp += OUString::valueOf(TWIP_TO_MM100(rRec.lHDist) );       sTmp += sColon;
     147         [ #  # ]:          0 :                 sTmp += OUString::valueOf(TWIP_TO_MM100(rRec.lVDist));        sTmp += sColon;
     148         [ #  # ]:          0 :                 sTmp += OUString::valueOf(TWIP_TO_MM100(rRec.lWidth)  );      sTmp += sColon;
     149         [ #  # ]:          0 :                 sTmp += OUString::valueOf(TWIP_TO_MM100(rRec.lHeight) );      sTmp += sColon;
     150         [ #  # ]:          0 :                 sTmp += OUString::valueOf(TWIP_TO_MM100(rRec.lLeft)   );      sTmp += sColon;
     151         [ #  # ]:          0 :                 sTmp += OUString::valueOf(TWIP_TO_MM100(rRec.lUpper)  );      sTmp += sColon;
     152                 :          0 :                 sTmp += OUString::valueOf(rRec.nCols   );                     sTmp += sColon;
     153                 :          0 :                 sTmp += OUString::valueOf(rRec.nRows   );                     sTmp += sColon;
     154         [ #  # ]:          0 :                 sTmp += OUString::valueOf(TWIP_TO_MM100(rRec.lPWidth)  );     sTmp += sColon;
     155         [ #  # ]:          0 :                 sTmp += OUString::valueOf(TWIP_TO_MM100(rRec.lPHeight)  );
     156         [ #  # ]:          0 :                 pValues[nProp].Value <<= sTmp;
     157                 :            :             }
     158                 :          0 :             break;
     159                 :            :         }
     160                 :            :     }
     161                 :          0 :     return aRet;
     162                 :            : }
     163                 :            : 
     164                 :          0 : void    SwLabelConfig::FillLabels(const OUString& rManufacturer, SwLabRecs& rLabArr)
     165                 :            : {
     166         [ #  # ]:          0 :     OUString sManufacturer(wrapConfigurationElementName(rManufacturer));
     167         [ #  # ]:          0 :     const Sequence<OUString> aLabels = GetNodeNames(sManufacturer);
     168                 :          0 :     const OUString* pLabels = aLabels.getConstArray();
     169         [ #  # ]:          0 :     for(sal_Int32 nLabel = 0; nLabel < aLabels.getLength(); nLabel++)
     170                 :            :     {
     171                 :          0 :         OUString sPrefix(sManufacturer);
     172         [ #  # ]:          0 :         sPrefix += C2U("/");
     173                 :          0 :         sPrefix += pLabels[nLabel];
     174         [ #  # ]:          0 :         sPrefix += C2U("/");
     175         [ #  # ]:          0 :         Sequence<OUString> aPropNames = lcl_CreatePropertyNames(sPrefix);
     176         [ #  # ]:          0 :         Sequence<Any>   aValues = GetProperties(aPropNames);
     177         [ #  # ]:          0 :         SwLabRec* pNewRec = lcl_CreateSwLabRec(aValues, rManufacturer);
     178         [ #  # ]:          0 :         rLabArr.push_back( pNewRec );
     179 [ #  # ][ #  # ]:          0 :     }
                 [ #  # ]
     180                 :          0 : }
     181                 :            : 
     182                 :          0 : sal_Bool    SwLabelConfig::HasLabel(const rtl::OUString& rManufacturer, const rtl::OUString& rType)
     183                 :            : {
     184                 :          0 :     const OUString* pNode = aNodeNames.getConstArray();
     185                 :          0 :     sal_Bool bFound = sal_False;
     186 [ #  # ][ #  # ]:          0 :     for(sal_Int32 nNode = 0; nNode < aNodeNames.getLength() && !bFound; nNode++)
                 [ #  # ]
     187                 :            :     {
     188         [ #  # ]:          0 :         if(pNode[nNode] == rManufacturer)
     189                 :          0 :             bFound = sal_True;
     190                 :            :     }
     191         [ #  # ]:          0 :     if(bFound)
     192                 :            :     {
     193         [ #  # ]:          0 :         OUString sManufacturer(wrapConfigurationElementName(rManufacturer));
     194         [ #  # ]:          0 :         const Sequence<OUString> aLabels = GetNodeNames(sManufacturer);
     195                 :          0 :         const OUString* pLabels = aLabels.getConstArray();
     196         [ #  # ]:          0 :         for(sal_Int32 nLabel = 0; nLabel < aLabels.getLength(); nLabel++)
     197                 :            :         {
     198                 :          0 :             OUString sPrefix(sManufacturer);
     199         [ #  # ]:          0 :             sPrefix += C2U("/");
     200                 :          0 :             sPrefix += pLabels[nLabel];
     201         [ #  # ]:          0 :             sPrefix += C2U("/");
     202         [ #  # ]:          0 :             Sequence<OUString> aProperties(1);
     203         [ #  # ]:          0 :             aProperties.getArray()[0] = sPrefix;
     204 [ #  # ][ #  # ]:          0 :             aProperties.getArray()[0] += C2U("Name");
     205         [ #  # ]:          0 :             Sequence<Any>   aValues = GetProperties(aProperties);
     206                 :          0 :             const Any* pValues = aValues.getConstArray();
     207         [ #  # ]:          0 :             if(pValues[0].hasValue())
     208                 :            :             {
     209                 :          0 :                 OUString sTmp;
     210                 :          0 :                 pValues[0] >>= sTmp;
     211         [ #  # ]:          0 :                 if(rType == sTmp)
     212         [ #  # ]:          0 :                     return sal_True;
     213                 :            :             }
     214 [ #  # ][ #  # ]:          0 :         }
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     215                 :            :     }
     216                 :          0 :     return sal_False;
     217                 :            : }
     218                 :            : 
     219                 :          0 : sal_Bool lcl_Exists(const OUString& rNode, const Sequence<OUString>& rLabels)
     220                 :            : {
     221                 :          0 :     const OUString* pLabels = rLabels.getConstArray();
     222         [ #  # ]:          0 :     for(sal_Int32 i = 0; i < rLabels.getLength(); i++)
     223         [ #  # ]:          0 :         if(pLabels[i] == rNode)
     224                 :          0 :             return sal_True;
     225                 :          0 :     return sal_False;
     226                 :            : }
     227                 :            : 
     228                 :          0 : void SwLabelConfig::SaveLabel(  const rtl::OUString& rManufacturer,
     229                 :            :         const rtl::OUString& rType, const SwLabRec& rRec)
     230                 :            : {
     231                 :          0 :     const OUString* pNode = aNodeNames.getConstArray();
     232                 :          0 :     sal_Bool bFound = sal_False;
     233 [ #  # ][ #  # ]:          0 :     for(sal_Int32 nNode = 0; nNode < aNodeNames.getLength() && !bFound; nNode++)
                 [ #  # ]
     234                 :            :     {
     235         [ #  # ]:          0 :         if(pNode[nNode] == rManufacturer)
     236                 :          0 :             bFound = sal_True;
     237                 :            :     }
     238         [ #  # ]:          0 :     if(!bFound)
     239                 :            :     {
     240 [ #  # ][ #  # ]:          0 :         if(!AddNode(OUString(), rManufacturer))
     241                 :            :         {
     242                 :            :             OSL_FAIL("New configuration node could not be created");
     243                 :          0 :             return ;
     244                 :            :         }
     245                 :            :         else
     246                 :            :         {
     247 [ #  # ][ #  # ]:          0 :             aNodeNames = GetNodeNames(OUString());
                 [ #  # ]
     248                 :            :         }
     249                 :            :     }
     250                 :            : 
     251         [ #  # ]:          0 :     OUString sManufacturer(wrapConfigurationElementName(rManufacturer));
     252         [ #  # ]:          0 :     const Sequence<OUString> aLabels = GetNodeNames(sManufacturer);
     253                 :          0 :     const OUString* pLabels = aLabels.getConstArray();
     254                 :          0 :     OUString sFoundNode;
     255         [ #  # ]:          0 :     for(sal_Int32 nLabel = 0; nLabel < aLabels.getLength(); nLabel++)
     256                 :            :     {
     257                 :          0 :         OUString sPrefix(sManufacturer);
     258         [ #  # ]:          0 :         sPrefix += C2U("/");
     259                 :          0 :         sPrefix += pLabels[nLabel];
     260         [ #  # ]:          0 :         sPrefix += C2U("/");
     261         [ #  # ]:          0 :         Sequence<OUString> aProperties(1);
     262         [ #  # ]:          0 :         aProperties.getArray()[0] = sPrefix;
     263 [ #  # ][ #  # ]:          0 :         aProperties.getArray()[0] += C2U("Name");
     264         [ #  # ]:          0 :         Sequence<Any>   aValues = GetProperties(aProperties);
     265                 :          0 :         const Any* pValues = aValues.getConstArray();
     266         [ #  # ]:          0 :         if(pValues[0].hasValue())
     267                 :            :         {
     268                 :          0 :             OUString sTmp;
     269                 :          0 :             pValues[0] >>= sTmp;
     270         [ #  # ]:          0 :             if(rType == sTmp)
     271                 :            :             {
     272                 :          0 :                 sFoundNode = pLabels[nLabel];
     273                 :            :                 break;
     274         [ #  # ]:          0 :             }
     275                 :            :         }
     276 [ #  # ][ #  # ]:          0 :     }
         [ #  # ][ #  # ]
                 [ #  # ]
     277                 :            :     // if not found - generate a unique node name
     278         [ #  # ]:          0 :     if(sFoundNode.isEmpty())
     279                 :            :     {
     280                 :          0 :         sal_Int32 nIndex = aLabels.getLength();
     281         [ #  # ]:          0 :         OUString sPrefix(C2U("Label"));
     282                 :          0 :         sFoundNode = sPrefix;
     283                 :          0 :         sFoundNode += OUString::valueOf(nIndex);
     284 [ #  # ][ #  # ]:          0 :         while(lcl_Exists(sFoundNode, aLabels))
     285                 :            :         {
     286                 :          0 :             sFoundNode = sPrefix;
     287                 :          0 :             sFoundNode += OUString::valueOf(nIndex++);
     288                 :          0 :         }
     289                 :            :     }
     290         [ #  # ]:          0 :     OUString sPrefix(wrapConfigurationElementName(rManufacturer));
     291         [ #  # ]:          0 :     sPrefix += C2U("/");
     292                 :          0 :     sPrefix += sFoundNode;
     293         [ #  # ]:          0 :     sPrefix += C2U("/");
     294         [ #  # ]:          0 :     Sequence<OUString> aPropNames = lcl_CreatePropertyNames(sPrefix);
     295         [ #  # ]:          0 :     Sequence<PropertyValue> aPropValues = lcl_CreateProperties(aPropNames, rRec);
     296 [ #  # ][ #  # ]:          0 :     SetSetProperties(wrapConfigurationElementName(rManufacturer), aPropValues);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     297                 :            : 
     298                 :            : }
     299                 :            : 
     300                 :            : 
     301                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10