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/xmlnmspe.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 
42 {
43 }
44 
45 void ScXMLExportDDELinks::WriteCell(const ScMatrixValue& aVal, sal_Int32 nRepeat)
46 {
47  bool bString = ScMatrix::IsNonValueType(aVal.nType);
48  bool bEmpty = ScMatrix::IsEmptyType(aVal.nType);
49 
50  if (!bEmpty)
51  {
52  if (bString)
53  {
56  }
57  else
58  {
59  OUStringBuffer aBuf;
62  rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE, aBuf.makeStringAndClear());
63  }
64  }
65 
66  if (nRepeat > 1)
67  {
69  }
71 }
72 
73 void ScXMLExportDDELinks::WriteTable(const sal_Int32 nPos)
74 {
75  ScDocument* pDoc = rExport.GetDocument();
76  if (!pDoc)
77  return;
78 
79  const ScMatrix* pMatrix = pDoc->GetDdeLinkResultMatrix(static_cast<sal_uInt16>(nPos));
80  if (!pMatrix)
81  return;
82 
83  SCSIZE nCols, nRows;
84  pMatrix->GetDimensions(nCols, nRows);
85 
86  SvXMLElementExport aTableElem(rExport, XML_NAMESPACE_TABLE, XML_TABLE, true, true);
87  if (nCols > 1)
88  {
90  }
91  {
93  }
94 
95  for (SCSIZE nRow = 0; nRow < nRows; ++nRow)
96  {
97  sal_Int32 nRepeat = 0;
98  ScMatrixValue aPrevVal;
100  for (SCSIZE nCol = 0; nCol < nCols; ++nCol, ++nRepeat)
101  {
102  ScMatrixValue aVal = pMatrix->Get(nCol, nRow);
103  if (nCol > 0 && aVal != aPrevVal)
104  {
105  // Cell value differs. Flush the cell content.
106  WriteCell(aPrevVal, nRepeat);
107  nRepeat = 0;
108  }
109  aPrevVal = aVal;
110  }
111 
112  WriteCell(aPrevVal, nRepeat);
113  }
114 }
115 
116 void ScXMLExportDDELinks::WriteDDELinks(const uno::Reference<sheet::XSpreadsheetDocument>& xSpreadDoc)
117 {
118  uno::Reference <beans::XPropertySet> xPropertySet (xSpreadDoc, uno::UNO_QUERY);
119  if (!xPropertySet.is())
120  return;
121 
122  uno::Reference<container::XIndexAccess> xIndex(xPropertySet->getPropertyValue(SC_UNO_DDELINKS), uno::UNO_QUERY);
123  if (!xIndex.is())
124  return;
125 
126  sal_Int32 nCount = xIndex->getCount();
127  if (!nCount)
128  return;
129 
131  for (sal_Int32 nDDELink = 0; nDDELink < nCount; ++nDDELink)
132  {
133  uno::Reference<sheet::XDDELink> xDDELink(xIndex->getByIndex(nDDELink), uno::UNO_QUERY);
134  if (xDDELink.is())
135  {
137  {
138  rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_DDE_APPLICATION, xDDELink->getApplication());
139  rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_DDE_TOPIC, xDDELink->getTopic());
140  rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_DDE_ITEM, xDDELink->getItem());
142  sal_uInt8 nMode;
143  if (rExport.GetDocument() &&
144  rExport.GetDocument()->GetDdeLinkMode(nDDELink, nMode))
145  {
146  switch (nMode)
147  {
148  case SC_DDE_ENGLISH :
150  break;
151  case SC_DDE_TEXT :
153  break;
154  }
155  }
157  }
158  WriteTable(nDDELink);
159  }
160  }
161 }
162 
163 /* 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:173
Matrix data type that can store values of mixed types.
Definition: scmatrix.hxx:113
OUString getString() const
XML_VALUE_TYPE
XML_STRING
ScMatrixValue Get(SCSIZE nC, SCSIZE nR) const
: If bString the ScMatrixValue->pS may still be NULL to indicate an empty string! ...
Definition: scmatrix.cxx:3078
XML_VALUE
XML_CONVERSION_MODE
aBuf
const sal_uInt8 SC_DDE_TEXT
Definition: document.hxx:293
Try NOT to use this struct.
Definition: scmatrix.hxx:53
static void convertDouble(OUStringBuffer &rBuffer, double fNumber, bool bWriteUnits, sal_Int16 nSourceUnit, sal_Int16 nTargetUnit)
double fVal
Definition: scmatrix.hxx:55
XML_DDE_LINK
XML_TABLE_CELL
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:45
XML_TABLE
XML_NUMBER_COLUMNS_REPEATED
int nCount
void AddAttribute(sal_uInt16 nPrefix, const char *pName, const OUString &rValue)
XML_FLOAT
static bool IsEmptyType(ScMatValType nType)
Empty, but not empty path or any other type.
Definition: scmatrix.hxx:187
XML_TABLE_ROW
XML_DDE_SOURCE
XML_DDE_APPLICATION
void GetDimensions(SCSIZE &rC, SCSIZE &rR) const
Definition: scmatrix.cxx:2968
SC_DLLPUBLIC const ScMatrix * GetDdeLinkResultMatrix(size_t nDdePos) const
Returns the result matrix of the specified DDE link.
Definition: documen8.cxx:985
bool GetDdeLinkMode(size_t nDdePos, sal_uInt8 &rnMode) const
Returns the link mode of the specified DDE link.
Definition: documen8.cxx:975
XML_STRING_VALUE
XML_INTO_ENGLISH_NUMBER
ScMatValType nType
Definition: scmatrix.hxx:57
const svl::SharedString & GetString() const
Only valid if ScMatrix methods indicate so!
Definition: scmatrix.hxx:60
ScDocument * GetDocument()
Definition: xmlexprt.hxx:240
#define SC_UNO_DDELINKS
Definition: unonames.hxx:39
unsigned char sal_uInt8
constexpr sal_uInt16 XML_NAMESPACE_TABLE
XML_DDE_TOPIC
XML_DDE_ITEM
XML_TABLE_COLUMN
XML_DDE_LINKS
XML_TRUE
const sal_uInt8 SC_DDE_ENGLISH
Definition: document.hxx:292
XML_KEEP_TEXT
XML_AUTOMATIC_UPDATE
css::uno::Any const SvXMLExport & rExport
constexpr sal_uInt16 XML_NAMESPACE_OFFICE