LibreOffice Module sc (master)  1
XMLExportDDELinks.cxx
Go to the documentation of this file.
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/xmlnamespace.hxx>
23 #include <sax/tools/converter.hxx>
24 #include "xmlexprt.hxx"
25 #include <unonames.hxx>
26 #include <document.hxx>
27 #include <scmatrix.hxx>
28 #include <com/sun/star/sheet/XDDELink.hpp>
29 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
30 #include <com/sun/star/container/XIndexAccess.hpp>
31 #include <com/sun/star/beans/XPropertySet.hpp>
32 
33 using namespace com::sun::star;
34 using namespace xmloff::token;
35 
37  : rExport(rTempExport)
38 {
39 }
40 
41 void ScXMLExportDDELinks::WriteCell(const ScMatrixValue& aVal, sal_Int32 nRepeat)
42 {
43  bool bString = ScMatrix::IsNonValueType(aVal.nType);
44  bool bEmpty = ScMatrix::IsEmptyType(aVal.nType);
45 
46  if (!bEmpty)
47  {
48  if (bString)
49  {
52  }
53  else
54  {
55  OUStringBuffer aBuf;
58  rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE, aBuf.makeStringAndClear());
59  }
60  }
61 
62  if (nRepeat > 1)
63  {
65  }
67 }
68 
69 void ScXMLExportDDELinks::WriteTable(const sal_Int32 nPos)
70 {
71  ScDocument* pDoc = rExport.GetDocument();
72  if (!pDoc)
73  return;
74 
75  const ScMatrix* pMatrix = pDoc->GetDdeLinkResultMatrix(static_cast<sal_uInt16>(nPos));
76  if (!pMatrix)
77  return;
78 
79  SCSIZE nCols, nRows;
80  pMatrix->GetDimensions(nCols, nRows);
81 
82  SvXMLElementExport aTableElem(rExport, XML_NAMESPACE_TABLE, XML_TABLE, true, true);
83  if (nCols > 1)
84  {
86  }
87  {
89  }
90 
91  for (SCSIZE nRow = 0; nRow < nRows; ++nRow)
92  {
93  sal_Int32 nRepeat = 0;
94  ScMatrixValue aPrevVal;
96  for (SCSIZE nCol = 0; nCol < nCols; ++nCol, ++nRepeat)
97  {
98  ScMatrixValue aVal = pMatrix->Get(nCol, nRow);
99  if (nCol > 0 && aVal != aPrevVal)
100  {
101  // Cell value differs. Flush the cell content.
102  WriteCell(aPrevVal, nRepeat);
103  nRepeat = 0;
104  }
105  aPrevVal = aVal;
106  }
107 
108  WriteCell(aPrevVal, nRepeat);
109  }
110 }
111 
112 void ScXMLExportDDELinks::WriteDDELinks(const uno::Reference<sheet::XSpreadsheetDocument>& xSpreadDoc)
113 {
114  uno::Reference <beans::XPropertySet> xPropertySet (xSpreadDoc, uno::UNO_QUERY);
115  if (!xPropertySet.is())
116  return;
117 
118  uno::Reference<container::XIndexAccess> xIndex(xPropertySet->getPropertyValue(SC_UNO_DDELINKS), uno::UNO_QUERY);
119  if (!xIndex.is())
120  return;
121 
122  sal_Int32 nCount = xIndex->getCount();
123  if (!nCount)
124  return;
125 
127  for (sal_Int32 nDDELink = 0; nDDELink < nCount; ++nDDELink)
128  {
129  uno::Reference<sheet::XDDELink> xDDELink(xIndex->getByIndex(nDDELink), uno::UNO_QUERY);
130  if (xDDELink.is())
131  {
133  {
134  rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_DDE_APPLICATION, xDDELink->getApplication());
135  rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_DDE_TOPIC, xDDELink->getTopic());
136  rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_DDE_ITEM, xDDELink->getItem());
138  sal_uInt8 nMode;
139  if (rExport.GetDocument() &&
140  rExport.GetDocument()->GetDdeLinkMode(nDDELink, nMode))
141  {
142  switch (nMode)
143  {
144  case SC_DDE_ENGLISH :
146  break;
147  case SC_DDE_TEXT :
149  break;
150  }
151  }
153  }
154  WriteTable(nDDELink);
155  }
156  }
157 }
158 
159 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static bool IsNonValueType(ScMatValType nType)
String, empty or empty path, but not value nor boolean.
Definition: scmatrix.hxx:190
Matrix data type that can store values of mixed types.
Definition: scmatrix.hxx:112
OUString getString() const
constexpr sal_uInt16 XML_NAMESPACE_OFFICE
XML_DDE_ITEM
XML_DDE_APPLICATION
ScMatrixValue Get(SCSIZE nC, SCSIZE nR) const
: If bString the ScMatrixValue->pS may still be NULL to indicate an empty string! ...
Definition: scmatrix.cxx:3040
XML_AUTOMATIC_UPDATE
aBuf
XML_VALUE_TYPE
XML_VALUE
XML_TABLE_CELL
const sal_uInt8 SC_DDE_TEXT
Definition: document.hxx:302
XML_KEEP_TEXT
Try NOT to use this struct.
Definition: scmatrix.hxx:52
static void convertDouble(OUStringBuffer &rBuffer, double fNumber, bool bWriteUnits, sal_Int16 nSourceUnit, sal_Int16 nTargetUnit)
double fVal
Definition: scmatrix.hxx:54
size_t SCSIZE
size_t typedef to be able to find places where code was changed from USHORT to size_t and is used to ...
Definition: address.hxx:44
int nCount
void AddAttribute(sal_uInt16 nPrefix, const OUString &rName, const OUString &rValue)
XML_FLOAT
XML_NUMBER_COLUMNS_REPEATED
static bool IsEmptyType(ScMatValType nType)
Empty, but not empty path or any other type.
Definition: scmatrix.hxx:204
XML_TABLE_ROW
XML_DDE_LINK
XML_INTO_ENGLISH_NUMBER
void GetDimensions(SCSIZE &rC, SCSIZE &rR) const
Definition: scmatrix.cxx:2930
SC_DLLPUBLIC const ScMatrix * GetDdeLinkResultMatrix(size_t nDdePos) const
Returns the result matrix of the specified DDE link.
Definition: documen8.cxx:987
XML_TABLE
bool GetDdeLinkMode(size_t nDdePos, sal_uInt8 &rnMode) const
Returns the link mode of the specified DDE link.
Definition: documen8.cxx:977
XML_STRING_VALUE
ScMatValType nType
Definition: scmatrix.hxx:56
XML_TRUE
const svl::SharedString & GetString() const
Only valid if ScMatrix methods indicate so!
Definition: scmatrix.hxx:59
ScDocument * GetDocument()
Definition: xmlexprt.hxx:240
#define SC_UNO_DDELINKS
Definition: unonames.hxx:40
XML_TABLE_COLUMN
constexpr sal_uInt16 XML_NAMESPACE_TABLE
unsigned char sal_uInt8
XML_DDE_TOPIC
XML_STRING
const sal_uInt8 SC_DDE_ENGLISH
Definition: document.hxx:301
XML_DDE_SOURCE
XML_DDE_LINKS
XML_CONVERSION_MODE