LCOV - code coverage report
Current view: top level - sc/source/filter/xml - XMLExportDDELinks.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 15 76 19.7 %
Date: 2012-08-25 Functions: 3 5 60.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 10 143 7.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 "XMLExportDDELinks.hxx"
      30                 :            : #include <xmloff/xmltoken.hxx>
      31                 :            : #include <xmloff/xmlnmspe.hxx>
      32                 :            : #include <xmloff/nmspmap.hxx>
      33                 :            : #include <sax/tools/converter.hxx>
      34                 :            : #include "xmlexprt.hxx"
      35                 :            : #include "unonames.hxx"
      36                 :            : #include "document.hxx"
      37                 :            : #include "scmatrix.hxx"
      38                 :            : #include <com/sun/star/sheet/XDDELink.hpp>
      39                 :            : 
      40                 :            : class ScMatrix;
      41                 :            : 
      42                 :            : using namespace com::sun::star;
      43                 :            : using namespace xmloff::token;
      44                 :            : using ::rtl::OUStringBuffer;
      45                 :            : 
      46                 :          4 : ScXMLExportDDELinks::ScXMLExportDDELinks(ScXMLExport& rTempExport)
      47                 :          4 :     : rExport(rTempExport)
      48                 :            : {
      49                 :          4 : }
      50                 :            : 
      51                 :          4 : ScXMLExportDDELinks::~ScXMLExportDDELinks()
      52                 :            : {
      53                 :          4 : }
      54                 :            : 
      55                 :          0 : void ScXMLExportDDELinks::WriteCell(const ScMatrixValue& aVal, sal_Int32 nRepeat)
      56                 :            : {
      57                 :          0 :     bool bString = ScMatrix::IsNonValueType(aVal.nType);
      58                 :          0 :     bool bEmpty = ScMatrix::IsEmptyType(aVal.nType);
      59                 :            : 
      60         [ #  # ]:          0 :     if (!bEmpty)
      61                 :            :     {
      62         [ #  # ]:          0 :         if (bString)
      63                 :            :         {
      64                 :          0 :             rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_STRING);
      65                 :          0 :             rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_STRING_VALUE, aVal.GetString());
      66                 :            :         }
      67                 :            :         else
      68                 :            :         {
      69                 :          0 :             OUStringBuffer aBuf;
      70         [ #  # ]:          0 :             rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_FLOAT);
      71         [ #  # ]:          0 :             ::sax::Converter::convertDouble(aBuf, aVal.fVal);
      72 [ #  # ][ #  # ]:          0 :             rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE, aBuf.makeStringAndClear());
      73                 :            :         }
      74                 :            :     }
      75                 :            : 
      76         [ #  # ]:          0 :     if (nRepeat > 1)
      77                 :            :     {
      78                 :          0 :         OUStringBuffer aBuf;
      79         [ #  # ]:          0 :         ::sax::Converter::convertNumber(aBuf, nRepeat);
      80 [ #  # ][ #  # ]:          0 :         rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_NUMBER_COLUMNS_REPEATED, aBuf.makeStringAndClear());
      81                 :            :     }
      82                 :          0 :     SvXMLElementExport(rExport, XML_NAMESPACE_TABLE, XML_TABLE_CELL, true, true);
      83                 :          0 : }
      84                 :            : 
      85                 :          0 : void ScXMLExportDDELinks::WriteTable(const sal_Int32 nPos)
      86                 :            : {
      87                 :          0 :     ScDocument* pDoc = rExport.GetDocument();
      88         [ #  # ]:          0 :     if (!pDoc)
      89                 :            :         return;
      90                 :            : 
      91         [ #  # ]:          0 :     const ScMatrix* pMatrix = pDoc->GetDdeLinkResultMatrix(static_cast<sal_uInt16>(nPos));
      92         [ #  # ]:          0 :     if (!pMatrix)
      93                 :            :         return;
      94                 :            : 
      95                 :            :     SCSIZE nCols, nRows;
      96         [ #  # ]:          0 :     pMatrix->GetDimensions(nCols, nRows);
      97                 :            : 
      98         [ #  # ]:          0 :     SvXMLElementExport aTableElem(rExport, XML_NAMESPACE_TABLE, XML_TABLE, true, true);
      99         [ #  # ]:          0 :     if (nCols > 1)
     100                 :            :     {
     101                 :          0 :         OUStringBuffer aBuf;
     102         [ #  # ]:          0 :         ::sax::Converter::convertNumber(aBuf, static_cast<sal_Int32>(nCols));
     103 [ #  # ][ #  # ]:          0 :         rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_NUMBER_COLUMNS_REPEATED, aBuf.makeStringAndClear());
     104                 :            :     }
     105                 :            :     {
     106 [ #  # ][ #  # ]:          0 :         SvXMLElementExport aElemCol(rExport, XML_NAMESPACE_TABLE, XML_TABLE_COLUMN, true, true);
     107                 :            :     }
     108                 :            : 
     109         [ #  # ]:          0 :     for (SCSIZE nRow = 0; nRow < nRows; ++nRow)
     110                 :            :     {
     111                 :          0 :         sal_Int32 nRepeat = 0;
     112                 :          0 :         ScMatrixValue aPrevVal;
     113         [ #  # ]:          0 :         SvXMLElementExport aElemRow(rExport, XML_NAMESPACE_TABLE, XML_TABLE_ROW, true, true);
     114         [ #  # ]:          0 :         for (SCSIZE nCol = 0; nCol < nCols; ++nCol, ++nRepeat)
     115                 :            :         {
     116         [ #  # ]:          0 :             ScMatrixValue aVal = pMatrix->Get(nCol, nRow);
     117 [ #  # ][ #  # ]:          0 :             if (nCol > 0 && aVal != aPrevVal)
                 [ #  # ]
     118                 :            :             {
     119                 :            :                 // Cell value differs.  Flush the cell content.
     120         [ #  # ]:          0 :                 WriteCell(aPrevVal, nRepeat);
     121                 :          0 :                 nRepeat = 0;
     122                 :            :             }
     123                 :          0 :             aPrevVal = aVal;
     124                 :          0 :         }
     125                 :            : 
     126         [ #  # ]:          0 :         WriteCell(aPrevVal, nRepeat);
     127 [ #  # ][ #  # ]:          0 :     }
     128                 :            : }
     129                 :            : 
     130                 :          4 : void ScXMLExportDDELinks::WriteDDELinks(uno::Reference<sheet::XSpreadsheetDocument>& xSpreadDoc)
     131                 :            : {
     132         [ +  - ]:          4 :     uno::Reference <beans::XPropertySet> xPropertySet (xSpreadDoc, uno::UNO_QUERY);
     133         [ +  - ]:          4 :     if (xPropertySet.is())
     134                 :            :     {
     135 [ +  - ][ +  - ]:          4 :         uno::Reference<container::XIndexAccess> xIndex(xPropertySet->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_DDELINKS))), uno::UNO_QUERY);
         [ +  - ][ +  - ]
     136         [ +  - ]:          4 :         if (xIndex.is())
     137                 :            :         {
     138 [ +  - ][ +  - ]:          4 :             sal_Int32 nCount = xIndex->getCount();
     139         [ -  + ]:          4 :             if (nCount)
     140                 :            :             {
     141         [ #  # ]:          0 :                 SvXMLElementExport aElemDDEs(rExport, XML_NAMESPACE_TABLE, XML_DDE_LINKS, true, true);
     142         [ #  # ]:          0 :                 for (sal_uInt16 nDDELink = 0; nDDELink < nCount; ++nDDELink)
     143                 :            :                 {
     144 [ #  # ][ #  # ]:          0 :                     uno::Reference<sheet::XDDELink> xDDELink(xIndex->getByIndex(nDDELink), uno::UNO_QUERY);
                 [ #  # ]
     145         [ #  # ]:          0 :                     if (xDDELink.is())
     146                 :            :                     {
     147         [ #  # ]:          0 :                         SvXMLElementExport aElemDDE(rExport, XML_NAMESPACE_TABLE, XML_DDE_LINK, true, true);
     148                 :            :                         {
     149 [ #  # ][ #  # ]:          0 :                             rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_DDE_APPLICATION, xDDELink->getApplication());
                 [ #  # ]
     150 [ #  # ][ #  # ]:          0 :                             rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_DDE_TOPIC, xDDELink->getTopic());
                 [ #  # ]
     151 [ #  # ][ #  # ]:          0 :                             rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_DDE_ITEM, xDDELink->getItem());
                 [ #  # ]
     152         [ #  # ]:          0 :                             rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_AUTOMATIC_UPDATE, XML_TRUE);
     153                 :            :                             sal_uInt8 nMode;
     154 [ #  # ][ #  # ]:          0 :                             if (rExport.GetDocument() &&
                 [ #  # ]
     155         [ #  # ]:          0 :                                 rExport.GetDocument()->GetDdeLinkMode(nDDELink, nMode))
     156                 :            :                             {
     157      [ #  #  # ]:          0 :                                 switch (nMode)
     158                 :            :                                 {
     159                 :            :                                     case SC_DDE_ENGLISH :
     160         [ #  # ]:          0 :                                         rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_CONVERSION_MODE, XML_INTO_ENGLISH_NUMBER);
     161                 :          0 :                                     break;
     162                 :            :                                     case SC_DDE_TEXT :
     163         [ #  # ]:          0 :                                         rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_CONVERSION_MODE, XML_KEEP_TEXT);
     164                 :          0 :                                     break;
     165                 :            :                                 }
     166                 :            :                             }
     167 [ #  # ][ #  # ]:          0 :                             SvXMLElementExport(rExport, XML_NAMESPACE_OFFICE, XML_DDE_SOURCE, true, true);
     168                 :            :                         }
     169 [ #  # ][ #  # ]:          0 :                         WriteTable(nDDELink);
     170                 :            :                     }
     171         [ #  # ]:          0 :                 }
     172                 :            :             }
     173                 :          4 :         }
     174                 :          4 :     }
     175                 :          4 : }
     176                 :            : 
     177                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10