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

Generated by: LCOV version 1.10