LCOV - code coverage report
Current view: top level - svx/source/xoutdev - xtable.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 73 143 51.0 %
Date: 2012-08-25 Functions: 13 22 59.1 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 69 249 27.7 %

           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                 :            : 
      30                 :            : #include <svx/XPropertyTable.hxx>
      31                 :            : #include "xmlxtexp.hxx"
      32                 :            : #include "xmlxtimp.hxx"
      33                 :            : #include <tools/urlobj.hxx>
      34                 :            : #include <svx/xtable.hxx>
      35                 :            : #include <svx/xpool.hxx>
      36                 :            : 
      37                 :            : using namespace com::sun::star;
      38                 :            : 
      39                 :            : // Helper for other sub-classes to have easy-to-read constructors
      40                 :      24949 : Color RGB_Color( ColorData nColorName )
      41                 :            : {
      42                 :      24949 :     Color aColor( nColorName );
      43                 :      24949 :     Color aRGBColor( aColor.GetRed(), aColor.GetGreen(), aColor.GetBlue() );
      44                 :      24949 :     return aRGBColor;
      45                 :            : }
      46                 :            : 
      47                 :            : // static int count = 0;
      48                 :            : 
      49                 :      18446 : XPropertyList::XPropertyList(
      50                 :            :     XPropertyListType type,
      51                 :            :     const String& rPath,
      52                 :            :     XOutdevItemPool* pInPool
      53                 :            : ) : eType           ( type ),
      54                 :            :     aName           ( RTL_CONSTASCII_USTRINGPARAM( "standard" ) ),
      55                 :            :     aPath           ( rPath ),
      56                 :            :     pXPool          ( pInPool ),
      57                 :            :     pBmpList        ( NULL ),
      58                 :            :     bListDirty      ( true ),
      59                 :            :     bBitmapsDirty   ( true ),
      60                 :            :     bOwnPool        ( false ),
      61 [ +  - ][ +  - ]:      18446 :     bEmbedInDocument( false )
                 [ +  - ]
      62                 :            : {
      63         [ +  + ]:      18446 :     if( !pXPool )
      64                 :            :     {
      65                 :        120 :         bOwnPool = true;
      66 [ +  - ][ +  - ]:        120 :         pXPool = new XOutdevItemPool;
      67                 :            :         DBG_ASSERT( pXPool, "XOutPool konnte nicht erzeugt werden!" );
      68                 :            :     }
      69                 :            : //    fprintf (stderr, "Create type %d count %d\n", (int)eType, count++);
      70                 :      18446 : }
      71                 :            : 
      72 [ +  - ][ +  - ]:      17897 : XPropertyList::~XPropertyList()
      73                 :            : {
      74                 :            : //    fprintf (stderr, "Destroy type %d count %d\n", (int)eType, --count);
      75         [ +  + ]:      36880 :     for( size_t i = 0, n = aList.size(); i < n; ++i )
      76 [ +  - ][ +  - ]:      18983 :         delete aList[ i ];
      77                 :            : 
      78                 :      17897 :     aList.clear();
      79                 :            : 
      80         [ +  + ]:      17897 :     if( pBmpList )
      81                 :            :     {
      82         [ -  + ]:      12936 :         for ( size_t i = 0, n = pBmpList->size(); i < n; ++i ) {
      83 [ #  # ][ #  # ]:          0 :             delete (*pBmpList)[ i ];
                 [ #  # ]
      84                 :            :         }
      85                 :      12936 :         pBmpList->clear();
      86         [ +  - ]:      12936 :         delete pBmpList;
      87                 :      12936 :         pBmpList = NULL;
      88                 :            :     }
      89                 :            : 
      90 [ +  + ][ +  - ]:      17897 :     if( bOwnPool && pXPool )
      91         [ +  - ]:         99 :         SfxItemPool::Free(pXPool);
      92         [ -  + ]:      17897 : }
      93                 :            : 
      94                 :      31410 : long XPropertyList::Count() const
      95                 :            : {
      96         [ +  + ]:      31410 :     if( bListDirty )
      97                 :            :     {
      98         [ +  + ]:       1626 :         if( !( (XPropertyList*) this )->Load() )
      99                 :       1386 :             ( (XPropertyList*) this )->Create();
     100                 :            :     }
     101                 :      31410 :     return( aList.size() );
     102                 :            : }
     103                 :            : 
     104                 :    1331600 : XPropertyEntry* XPropertyList::Get( long nIndex, sal_uInt16 /*nDummy*/) const
     105                 :            : {
     106         [ -  + ]:    1331600 :     if( bListDirty )
     107                 :            :     {
     108         [ #  # ]:          0 :         if( !( (XPropertyList*) this )->Load() )
     109                 :          0 :             ( (XPropertyList*) this )->Create();
     110                 :            :     }
     111         [ +  - ]:    1331600 :     return ( (size_t)nIndex < aList.size() ) ? aList[ nIndex ] : NULL;
     112                 :            : }
     113                 :            : 
     114                 :          0 : long XPropertyList::Get(const XubString& rName)
     115                 :            : {
     116         [ #  # ]:          0 :     if( bListDirty )
     117                 :            :     {
     118         [ #  # ]:          0 :         if( !Load() )
     119                 :          0 :             Create();
     120                 :            :     }
     121                 :            : 
     122         [ #  # ]:          0 :     for( long i = 0, n = aList.size(); i < n; ++i ) {
     123         [ #  # ]:          0 :         if ( aList[ i ]->GetName() == rName ) {
     124                 :          0 :             return i;
     125                 :            :         }
     126                 :            :     }
     127                 :          0 :     return -1;
     128                 :            : }
     129                 :            : 
     130                 :          0 : Bitmap* XPropertyList::GetBitmap( long nIndex ) const
     131                 :            : {
     132         [ #  # ]:          0 :     if( pBmpList )
     133                 :            :     {
     134         [ #  # ]:          0 :         if( bBitmapsDirty )
     135                 :            :         {
     136                 :          0 :             ( (XPropertyList*) this )->bBitmapsDirty = false;
     137                 :          0 :             ( (XPropertyList*) this )->CreateBitmapsForUI();
     138                 :            :         }
     139         [ #  # ]:          0 :         if( (size_t)nIndex < pBmpList->size() )
     140                 :          0 :             return (*pBmpList)[ nIndex ];
     141                 :            :     }
     142                 :          0 :     return NULL;
     143                 :            : }
     144                 :            : 
     145                 :      18983 : void XPropertyList::Insert( XPropertyEntry* pEntry, long nIndex )
     146                 :            : {
     147         [ -  + ]:      18983 :     if ( (size_t)nIndex < aList.size() ) {
     148 [ #  # ][ #  # ]:          0 :         aList.insert( aList.begin() + nIndex, pEntry );
     149                 :            :     } else {
     150                 :      18983 :         aList.push_back( pEntry );
     151                 :            :     }
     152                 :            : 
     153 [ +  + ][ -  + ]:      18983 :     if( pBmpList && !bBitmapsDirty )
     154                 :            :     {
     155                 :            :         Bitmap* pBmp = CreateBitmapForUI(
     156                 :          0 :             (size_t)nIndex < aList.size() ? nIndex : aList.size() - 1
     157 [ #  # ][ #  # ]:          0 :         );
     158         [ #  # ]:          0 :         if ( (size_t)nIndex < pBmpList->size() ) {
     159 [ #  # ][ #  # ]:          0 :             pBmpList->insert( pBmpList->begin() + nIndex, pBmp );
     160                 :            :         } else {
     161         [ #  # ]:          0 :             pBmpList->push_back( pBmp );
     162                 :            :         }
     163                 :            :     }
     164                 :      18983 : }
     165                 :            : 
     166                 :          0 : XPropertyEntry* XPropertyList::Replace( XPropertyEntry* pEntry, long nIndex )
     167                 :            : {
     168         [ #  # ]:          0 :     XPropertyEntry* pOldEntry = (size_t)nIndex < aList.size() ? aList[ nIndex ] : NULL;
     169         [ #  # ]:          0 :     if ( pOldEntry ) {
     170                 :          0 :         aList[ nIndex ] = pEntry;
     171                 :            :     }
     172                 :            : 
     173 [ #  # ][ #  # ]:          0 :     if( pBmpList && !bBitmapsDirty )
     174                 :            :     {
     175         [ #  # ]:          0 :         Bitmap* pBmp = CreateBitmapForUI( (sal_uIntPtr) nIndex );
     176         [ #  # ]:          0 :         if ( (size_t)nIndex < pBmpList->size() )
     177                 :            :         {
     178 [ #  # ][ #  # ]:          0 :             delete (*pBmpList)[ nIndex ];
                 [ #  # ]
     179         [ #  # ]:          0 :             (*pBmpList)[ nIndex ] = pBmp;
     180                 :            :         }
     181                 :            :         else {
     182         [ #  # ]:          0 :             pBmpList->push_back( pBmp );
     183                 :            :         }
     184                 :            :     }
     185                 :          0 :     return pOldEntry;
     186                 :            : }
     187                 :            : 
     188                 :          0 : XPropertyEntry* XPropertyList::Remove( long nIndex )
     189                 :            : {
     190 [ #  # ][ #  # ]:          0 :     if( pBmpList && !bBitmapsDirty )
     191                 :            :     {
     192         [ #  # ]:          0 :         if ( (size_t)nIndex < pBmpList->size() )
     193                 :            :         {
     194         [ #  # ]:          0 :             delete (*pBmpList)[ nIndex ];
     195 [ #  # ][ #  # ]:          0 :             pBmpList->erase( pBmpList->begin() + nIndex );
     196                 :            :         }
     197                 :            :     }
     198                 :            : 
     199                 :          0 :     XPropertyEntry* pEntry = NULL;
     200         [ #  # ]:          0 :     if ( (size_t)nIndex < aList.size() ) {
     201                 :          0 :         pEntry = aList[ nIndex ];
     202 [ #  # ][ #  # ]:          0 :         aList.erase( aList.begin() + nIndex );
     203                 :            :     }
     204                 :          0 :     return pEntry;
     205                 :            : }
     206                 :            : 
     207                 :         66 : void XPropertyList::SetName( const String& rString )
     208                 :            : {
     209         [ +  - ]:         66 :     if(rString.Len())
     210                 :            :     {
     211                 :         66 :         aName = rString;
     212                 :            :     }
     213                 :         66 : }
     214                 :            : 
     215                 :       1626 : bool XPropertyList::Load()
     216                 :            : {
     217         [ +  - ]:       1626 :     if( bListDirty )
     218                 :            :     {
     219                 :       1626 :         bListDirty = false;
     220                 :            : 
     221 [ +  - ][ +  - ]:       1626 :         INetURLObject aURL( aPath );
     222                 :            : 
     223         [ +  + ]:       1626 :         if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
     224                 :            :         {
     225                 :            :             DBG_ASSERT( !aPath.Len(), "invalid URL" );
     226                 :       1386 :             return false;
     227                 :            :         }
     228                 :            : 
     229 [ +  - ][ +  - ]:        240 :         aURL.Append( aName );
     230                 :            : 
     231 [ +  - ][ +  - ]:        240 :         if( aURL.getExtension().isEmpty() )
     232 [ +  - ][ +  - ]:        240 :             aURL.setExtension( GetDefaultExt() );
     233                 :            : 
     234                 :            :         return SvxXMLXTableImport::load( aURL.GetMainURL( INetURLObject::NO_DECODE ),
     235                 :            :                                          uno::Reference < embed::XStorage >(),
     236 [ +  - ][ +  - ]:       1626 :                                          createInstance(), NULL );
                 [ +  - ]
     237                 :            : 
     238                 :            :     }
     239                 :       1626 :     return false;
     240                 :            : }
     241                 :            : 
     242                 :         66 : bool XPropertyList::LoadFrom( const uno::Reference < embed::XStorage > &xStorage,
     243                 :            :                                   const rtl::OUString &rURL )
     244                 :            : {
     245         [ -  + ]:         66 :     if( !bListDirty )
     246                 :          0 :         return false;
     247                 :         66 :     bListDirty = false;
     248                 :         66 :     return SvxXMLXTableImport::load( rURL, xStorage, createInstance(), &bEmbedInDocument );
     249                 :            : }
     250                 :            : 
     251                 :          0 : bool XPropertyList::Save()
     252                 :            : {
     253 [ #  # ][ #  # ]:          0 :     INetURLObject aURL( aPath );
     254                 :            : 
     255         [ #  # ]:          0 :     if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
     256                 :            :     {
     257                 :            :         DBG_ASSERT( !aPath.Len(), "invalid URL" );
     258                 :          0 :         return false;
     259                 :            :     }
     260                 :            : 
     261 [ #  # ][ #  # ]:          0 :     aURL.Append( aName );
     262                 :            : 
     263 [ #  # ][ #  # ]:          0 :     if( aURL.getExtension().isEmpty() )
     264 [ #  # ][ #  # ]:          0 :         aURL.setExtension( GetDefaultExt() );
     265                 :            : 
     266                 :            :     return SvxXMLXTableExportComponent::save( aURL.GetMainURL( INetURLObject::NO_DECODE ),
     267                 :          0 :                                               createInstance(),
     268 [ #  # ][ #  # ]:          0 :                                               uno::Reference< embed::XStorage >(), NULL );
                 [ #  # ]
     269                 :            : }
     270                 :            : 
     271                 :          0 : bool XPropertyList::SaveTo( const uno::Reference< embed::XStorage > &xStorage,
     272                 :            :                             const rtl::OUString &rURL, rtl::OUString *pOptName )
     273                 :            : {
     274                 :          0 :     return SvxXMLXTableExportComponent::save( rURL, createInstance(), xStorage, pOptName );
     275                 :            : }
     276                 :            : 
     277                 :      18446 : XPropertyListRef XPropertyList::CreatePropertyList( XPropertyListType t,
     278                 :            :                                                     const String& rPath,
     279                 :            :                                                     XOutdevItemPool* pXPool )
     280                 :            : {
     281                 :      18446 :     XPropertyListRef pRet;
     282                 :            : 
     283                 :            : #define MAP(e,c) \
     284                 :            :         case e: pRet = XPropertyListRef (new c( rPath, pXPool ) ); break
     285   [ +  +  +  +  :      18446 :     switch (t) {
                +  +  - ]
     286 [ +  - ][ +  - ]:       1751 :         MAP( XCOLOR_LIST, XColorList );
     287 [ +  - ][ +  - ]:       3339 :         MAP( XLINE_END_LIST, XLineEndList );
     288 [ +  - ][ +  - ]:       3339 :         MAP( XDASH_LIST, XDashList );
     289 [ +  - ][ +  - ]:       3339 :         MAP( XHATCH_LIST, XHatchList );
     290 [ +  - ][ +  - ]:       3339 :         MAP( XGRADIENT_LIST, XGradientList );
     291 [ +  - ][ +  - ]:       3339 :         MAP( XBITMAP_LIST, XBitmapList );
     292                 :            :     default:
     293                 :            :         OSL_FAIL("unknown xproperty type");
     294                 :          0 :         break;
     295                 :            :     }
     296                 :            : #undef MAP
     297                 :            :     OSL_ASSERT( !pRet.is() || pRet->eType == t );
     298                 :            : 
     299                 :      18446 :     return pRet;
     300                 :            : }
     301                 :            : 
     302                 :            : XPropertyListRef
     303                 :          0 : XPropertyList::CreatePropertyListFromURL( XPropertyListType t,
     304                 :            :                                           const rtl::OUString & rURLStr,
     305                 :            :                                           XOutdevItemPool* pXPool )
     306                 :            : {
     307         [ #  # ]:          0 :     INetURLObject aURL( rURLStr );
     308         [ #  # ]:          0 :     INetURLObject aPathURL( aURL );
     309                 :            : 
     310         [ #  # ]:          0 :     aPathURL.removeSegment();
     311         [ #  # ]:          0 :     aPathURL.removeFinalSlash();
     312                 :            : 
     313                 :            :     XPropertyListRef pList = XPropertyList::CreatePropertyList(
     314 [ #  # ][ #  # ]:          0 :         t, aPathURL.GetMainURL( INetURLObject::NO_DECODE ), pXPool );
         [ #  # ][ #  # ]
     315 [ #  # ][ #  # ]:          0 :     pList->SetName( aURL.getName() );
         [ #  # ][ #  # ]
     316                 :            : 
     317 [ #  # ][ #  # ]:          0 :     return pList;
     318                 :            : }
     319                 :            : 
     320                 :            : // catch people being silly with ref counting ...
     321                 :            : 
     322                 :      18446 : void* XPropertyList::operator new (size_t nCount)
     323                 :            : {
     324                 :      18446 :     return rtl_allocateMemory( nCount );
     325                 :            : }
     326                 :            : 
     327                 :      17897 : void XPropertyList::operator delete(void *pPtr)
     328                 :            : {
     329                 :      17897 :     return rtl_freeMemory( pPtr );
     330                 :            : }
     331                 :            : 
     332                 :            : static struct {
     333                 :            :     XPropertyListType t;
     334                 :            :     const char *pExt;
     335                 :            : } pExtnMap[] = {
     336                 :            :     { XCOLOR_LIST,    "soc" },
     337                 :            :     { XLINE_END_LIST, "soe" },
     338                 :            :     { XDASH_LIST,     "sod" },
     339                 :            :     { XHATCH_LIST,    "soh" },
     340                 :            :     { XGRADIENT_LIST, "sog" },
     341                 :            :     { XBITMAP_LIST,   "sob" }
     342                 :            : };
     343                 :            : 
     344                 :        312 : rtl::OUString XPropertyList::GetDefaultExt( XPropertyListType t )
     345                 :            : {
     346         [ +  - ]:        730 :     for (size_t i = 0; i < SAL_N_ELEMENTS (pExtnMap); i++)
     347                 :            :     {
     348         [ +  + ]:        730 :         if( pExtnMap[i].t == t )
     349                 :        312 :             return rtl::OUString::createFromAscii( pExtnMap[ i ].pExt );
     350                 :            :     }
     351                 :        312 :     return rtl::OUString();
     352                 :            : }
     353                 :            : 
     354                 :          0 : rtl::OUString XPropertyList::GetDefaultExtFilter( XPropertyListType t )
     355                 :            : {
     356         [ #  # ]:          0 :     rtl::OUString aFilter( RTL_CONSTASCII_USTRINGPARAM( "*." ) );
     357         [ #  # ]:          0 :     return aFilter + GetDefaultExt( t );
     358                 :            : }
     359                 :            : 
     360                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10