LCOV - code coverage report
Current view: top level - svx/source/xoutdev - xtable.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 98 153 64.1 %
Date: 2014-04-11 Functions: 22 34 64.7 %
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 <svx/XPropertyTable.hxx>
      21             : #include "xmlxtexp.hxx"
      22             : #include "xmlxtimp.hxx"
      23             : #include <tools/urlobj.hxx>
      24             : #include <svx/xtable.hxx>
      25             : #include <svx/xpool.hxx>
      26             : #include <svx/svdobj.hxx>
      27             : #include <svx/svdpool.hxx>
      28             : 
      29             : using namespace com::sun::star;
      30             : 
      31             : // Helper for other sub-classes to have easy-to-read constructors
      32       24245 : Color RGB_Color( ColorData nColorName )
      33             : {
      34       24245 :     Color aColor( nColorName );
      35       24245 :     Color aRGBColor( aColor.GetRed(), aColor.GetGreen(), aColor.GetBlue() );
      36       24245 :     return aRGBColor;
      37             : }
      38             : 
      39             : // class XColorEntry
      40             : 
      41       10521 : XColorEntry::XColorEntry(const Color& rColor, const OUString& rName)
      42             : :   XPropertyEntry(rName),
      43       10521 :     aColor(rColor)
      44             : {
      45       10521 : }
      46             : 
      47           0 : XColorEntry::XColorEntry(const XColorEntry& rOther)
      48             : :   XPropertyEntry(rOther),
      49           0 : aColor(rOther.aColor)
      50             : {
      51           0 : }
      52             : 
      53             : // class XLineEndEntry
      54             : 
      55          40 : XLineEndEntry::XLineEndEntry(const basegfx::B2DPolyPolygon& rB2DPolyPolygon, const OUString& rName)
      56             : :   XPropertyEntry(rName),
      57          40 :     aB2DPolyPolygon(rB2DPolyPolygon)
      58             : {
      59          40 : }
      60             : 
      61           0 : XLineEndEntry::XLineEndEntry(const XLineEndEntry& rOther)
      62             : :   XPropertyEntry(rOther),
      63           0 :     aB2DPolyPolygon(rOther.aB2DPolyPolygon)
      64             : {
      65           0 : }
      66             : 
      67             : // class XDashEntry
      68             : 
      69         741 : XDashEntry::XDashEntry(const XDash& rDash, const OUString& rName)
      70             : :   XPropertyEntry(rName),
      71         741 :     aDash(rDash)
      72             : {
      73         741 : }
      74             : 
      75           0 : XDashEntry::XDashEntry(const XDashEntry& rOther)
      76             : :   XPropertyEntry(rOther),
      77           0 : aDash(rOther.aDash)
      78             : {
      79           0 : }
      80             : 
      81             : // class XHatchEntry
      82             : 
      83          59 : XHatchEntry::XHatchEntry(const XHatch& rHatch, const OUString& rName)
      84             : :   XPropertyEntry(rName),
      85          59 :     aHatch(rHatch)
      86             : {
      87          59 : }
      88             : 
      89           0 : XHatchEntry::XHatchEntry(const XHatchEntry& rOther)
      90             : :   XPropertyEntry(rOther),
      91           0 :     aHatch(rOther.aHatch)
      92             : {
      93           0 : }
      94             : 
      95             : // class XGradientEntry
      96             : 
      97         124 : XGradientEntry::XGradientEntry(const XGradient& rGradient, const OUString& rName)
      98             : :   XPropertyEntry(rName),
      99         124 :     aGradient(rGradient)
     100             : {
     101         124 : }
     102             : 
     103           0 : XGradientEntry::XGradientEntry(const XGradientEntry& rOther)
     104             : :   XPropertyEntry(rOther),
     105           0 :     aGradient(rOther.aGradient)
     106             : {
     107           0 : }
     108             : 
     109             : // class XBitmapEntry
     110             : 
     111          42 : XBitmapEntry::XBitmapEntry(const GraphicObject& rGraphicObject, const OUString& rName)
     112             : :   XPropertyEntry(rName),
     113          42 :     maGraphicObject(rGraphicObject)
     114             : {
     115          42 : }
     116             : 
     117           0 : XBitmapEntry::XBitmapEntry(const XBitmapEntry& rOther)
     118             : :   XPropertyEntry(rOther),
     119           0 :     maGraphicObject(rOther.maGraphicObject)
     120             : {
     121           0 : }
     122             : 
     123       12927 : XPropertyList::XPropertyList(
     124             :     XPropertyListType type,
     125             :     const OUString& rPath, const OUString& rReferer
     126             : ) : meType           ( type ),
     127             :     maName           ( "standard" ),
     128             :     maPath           ( rPath ),
     129             :     maReferer        ( rReferer ),
     130             :     mbListDirty      ( true ),
     131       12927 :     mbEmbedInDocument( false )
     132             : {
     133             : //    fprintf (stderr, "Create type %d count %d\n", (int)meType, count++);
     134       12927 : }
     135             : 
     136       23868 : XPropertyList::~XPropertyList()
     137             : {
     138             : //    fprintf (stderr, "Destroy type %d count %d\n", (int)meType, --count);
     139       20194 :     for( size_t i = 0, n = maList.size(); i < n; ++i )
     140        8260 :         delete maList[ i ];
     141             : 
     142       11934 :     maList.clear();
     143       11934 : }
     144             : 
     145       23139 : long XPropertyList::Count() const
     146             : {
     147       23139 :     if( mbListDirty )
     148             :     {
     149         158 :         if( !( (XPropertyList*) this )->Load() )
     150          37 :             ( (XPropertyList*) this )->Create();
     151             :     }
     152       23139 :     return maList.size();
     153             : }
     154             : 
     155     1777854 : XPropertyEntry* XPropertyList::Get( long nIndex ) const
     156             : {
     157     1777854 :     if( mbListDirty )
     158             :     {
     159           0 :         if( !( (XPropertyList*) this )->Load() )
     160           0 :             ( (XPropertyList*) this )->Create();
     161             :     }
     162     1777854 :     return ( (size_t)nIndex < maList.size() ) ? maList[ nIndex ] : NULL;
     163             : }
     164             : 
     165         257 : long XPropertyList::GetIndex(const OUString& rName) const
     166             : {
     167         257 :     if( mbListDirty )
     168             :     {
     169           7 :         if( !( (XPropertyList*) this )->Load() )
     170           6 :             ( (XPropertyList*) this )->Create();
     171             :     }
     172             : 
     173        2666 :     for( long i = 0, n = maList.size(); i < n; ++i ) {
     174        2409 :         if (rName.equals(maList[ i ]->GetName())) {
     175           0 :             return i;
     176             :         }
     177             :     }
     178         257 :     return -1;
     179             : }
     180             : 
     181         620 : Bitmap XPropertyList::GetUiBitmap( long nIndex ) const
     182             : {
     183         620 :     Bitmap aRetval;
     184         620 :     XPropertyEntry* pEntry = ( (size_t)nIndex < maList.size() ) ? maList[ nIndex ] : NULL;
     185         620 :     if(pEntry)
     186             :     {
     187         620 :         aRetval = pEntry->GetUiBitmap();
     188             : 
     189         620 :         if(aRetval.IsEmpty())
     190             :         {
     191         620 :             aRetval = const_cast< XPropertyList* >(this)->CreateBitmapForUI(nIndex);
     192         620 :             pEntry->SetUiBitmap(aRetval);
     193             :         }
     194             :     }
     195         620 :     return aRetval;
     196             : }
     197             : 
     198       11464 : void XPropertyList::Insert( XPropertyEntry* pEntry, long nIndex )
     199             : {
     200       11464 :     if ( (size_t)nIndex < maList.size() ) {
     201           0 :         maList.insert( maList.begin() + nIndex, pEntry );
     202             :     } else {
     203       11464 :         maList.push_back( pEntry );
     204             :     }
     205       11464 : }
     206             : 
     207          63 : XPropertyEntry* XPropertyList::Replace( XPropertyEntry* pEntry, long nIndex )
     208             : {
     209          63 :     XPropertyEntry* pOldEntry = (size_t)nIndex < maList.size() ? maList[ nIndex ] : NULL;
     210          63 :     if ( pOldEntry ) {
     211          63 :         maList[ nIndex ] = pEntry;
     212             :     }
     213          63 :     return pOldEntry;
     214             : }
     215             : 
     216           0 : XPropertyEntry* XPropertyList::Remove( long nIndex )
     217             : {
     218           0 :     XPropertyEntry* pEntry = NULL;
     219           0 :     if ( (size_t)nIndex < maList.size() ) {
     220           0 :         pEntry = maList[ nIndex ];
     221           0 :         maList.erase( maList.begin() + nIndex );
     222             :     }
     223           0 :     return pEntry;
     224             : }
     225             : 
     226          84 : void XPropertyList::SetName( const OUString& rString )
     227             : {
     228          84 :     if(!rString.isEmpty())
     229             :     {
     230          84 :         maName = rString;
     231             :     }
     232          84 : }
     233             : 
     234         165 : bool XPropertyList::Load()
     235             : {
     236         165 :     if( mbListDirty )
     237             :     {
     238         165 :         mbListDirty = false;
     239             : 
     240         165 :         INetURLObject aURL( maPath );
     241             : 
     242         165 :         if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
     243             :         {
     244             :             DBG_ASSERT( maPath.isEmpty(), "invalid URL" );
     245           0 :             return false;
     246             :         }
     247             : 
     248         165 :         aURL.Append( maName );
     249             : 
     250         165 :         if( aURL.getExtension().isEmpty() )
     251         165 :             aURL.setExtension( GetDefaultExt() );
     252             : 
     253             :         return SvxXMLXTableImport::load( aURL.GetMainURL( INetURLObject::NO_DECODE ), maReferer,
     254             :                                          uno::Reference < embed::XStorage >(),
     255         165 :                                          createInstance(), NULL );
     256             :     }
     257           0 :     return false;
     258             : }
     259             : 
     260          84 : bool XPropertyList::LoadFrom( const uno::Reference < embed::XStorage > &xStorage,
     261             :                               const OUString &rURL, const OUString &rReferer )
     262             : {
     263          84 :     if( !mbListDirty )
     264           0 :         return false;
     265          84 :     mbListDirty = false;
     266          84 :     return SvxXMLXTableImport::load( rURL, rReferer, xStorage, createInstance(), &mbEmbedInDocument );
     267             : }
     268             : 
     269           0 : bool XPropertyList::Save()
     270             : {
     271           0 :     INetURLObject aURL( maPath );
     272             : 
     273           0 :     if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
     274             :     {
     275             :         DBG_ASSERT( maPath.isEmpty(), "invalid URL" );
     276           0 :         return false;
     277             :     }
     278             : 
     279           0 :     aURL.Append( maName );
     280             : 
     281           0 :     if( aURL.getExtension().isEmpty() )
     282           0 :         aURL.setExtension( GetDefaultExt() );
     283             : 
     284             :     return SvxXMLXTableExportComponent::save( aURL.GetMainURL( INetURLObject::NO_DECODE ),
     285           0 :                                               createInstance(),
     286           0 :                                               uno::Reference< embed::XStorage >(), NULL );
     287             : }
     288             : 
     289           0 : bool XPropertyList::SaveTo( const uno::Reference< embed::XStorage > &xStorage,
     290             :                             const OUString &rURL, OUString *pOptName )
     291             : {
     292           0 :     return SvxXMLXTableExportComponent::save( rURL, createInstance(), xStorage, pOptName );
     293             : }
     294             : 
     295       12927 : XPropertyListRef XPropertyList::CreatePropertyList( XPropertyListType t,
     296             :                                                     const OUString& rPath,
     297             :                                                     const OUString& rReferer )
     298             : {
     299       12927 :     XPropertyListRef pRet;
     300             : 
     301             : #define MAP(e,c) \
     302             :         case e: pRet = XPropertyListRef (new c( rPath, rReferer ) ); break
     303       12927 :     switch (t) {
     304         452 :         MAP( XCOLOR_LIST, XColorList );
     305        2495 :         MAP( XLINE_END_LIST, XLineEndList );
     306        2495 :         MAP( XDASH_LIST, XDashList );
     307        2495 :         MAP( XHATCH_LIST, XHatchList );
     308        2495 :         MAP( XGRADIENT_LIST, XGradientList );
     309        2495 :         MAP( XBITMAP_LIST, XBitmapList );
     310             :     default:
     311             :         OSL_FAIL("unknown xproperty type");
     312           0 :         break;
     313             :     }
     314             : #undef MAP
     315             :     OSL_ASSERT( !pRet.is() || pRet->meType == t );
     316             : 
     317       12927 :     return pRet;
     318             : }
     319             : 
     320             : XPropertyListRef
     321           0 : XPropertyList::CreatePropertyListFromURL( XPropertyListType t,
     322             :                                           const OUString & rURLStr )
     323             : {
     324           0 :     INetURLObject aURL( rURLStr );
     325           0 :     INetURLObject aPathURL( aURL );
     326             : 
     327           0 :     aPathURL.removeSegment();
     328           0 :     aPathURL.removeFinalSlash();
     329             : 
     330             :     XPropertyListRef pList = XPropertyList::CreatePropertyList(
     331           0 :         t, aPathURL.GetMainURL( INetURLObject::NO_DECODE ), "" );
     332           0 :     pList->SetName( aURL.getName() );
     333             : 
     334           0 :     return pList;
     335             : }
     336             : 
     337             : // catch people being silly with ref counting ...
     338             : 
     339       12927 : void* XPropertyList::operator new (size_t nCount)
     340             : {
     341       12927 :     return rtl_allocateMemory( nCount );
     342             : }
     343             : 
     344       11934 : void XPropertyList::operator delete(void *pPtr)
     345             : {
     346       11934 :     return rtl_freeMemory( pPtr );
     347             : }
     348             : 
     349             : static struct {
     350             :     XPropertyListType t;
     351             :     const char *pExt;
     352             : } pExtnMap[] = {
     353             :     { XCOLOR_LIST,    "soc" },
     354             :     { XLINE_END_LIST, "soe" },
     355             :     { XDASH_LIST,     "sod" },
     356             :     { XHATCH_LIST,    "soh" },
     357             :     { XGRADIENT_LIST, "sog" },
     358             :     { XBITMAP_LIST,   "sob" }
     359             : };
     360             : 
     361         297 : OUString XPropertyList::GetDefaultExt( XPropertyListType t )
     362             : {
     363         876 :     for (size_t i = 0; i < SAL_N_ELEMENTS (pExtnMap); i++)
     364             :     {
     365         876 :         if( pExtnMap[i].t == t )
     366         297 :             return OUString::createFromAscii( pExtnMap[ i ].pExt );
     367             :     }
     368           0 :     return OUString();
     369             : }
     370             : 
     371           0 : OUString XPropertyList::GetDefaultExtFilter( XPropertyListType t )
     372             : {
     373           0 :     OUString aFilter( "*." );
     374           0 :     return aFilter + GetDefaultExt( t );
     375             : }
     376             : 
     377             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10