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 : using ::rtl::OUStringBuffer;
36 :
37 2 : ScXMLExportDDELinks::ScXMLExportDDELinks(ScXMLExport& rTempExport)
38 2 : : rExport(rTempExport)
39 : {
40 2 : }
41 :
42 2 : ScXMLExportDDELinks::~ScXMLExportDDELinks()
43 : {
44 2 : }
45 :
46 0 : void ScXMLExportDDELinks::WriteCell(const ScMatrixValue& aVal, sal_Int32 nRepeat)
47 : {
48 0 : bool bString = ScMatrix::IsNonValueType(aVal.nType);
49 0 : bool bEmpty = ScMatrix::IsEmptyType(aVal.nType);
50 :
51 0 : if (!bEmpty)
52 : {
53 0 : if (bString)
54 : {
55 0 : rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_STRING);
56 0 : rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_STRING_VALUE, aVal.GetString());
57 : }
58 : else
59 : {
60 0 : OUStringBuffer aBuf;
61 0 : rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_FLOAT);
62 0 : ::sax::Converter::convertDouble(aBuf, aVal.fVal);
63 0 : rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE, aBuf.makeStringAndClear());
64 : }
65 : }
66 :
67 0 : if (nRepeat > 1)
68 : {
69 0 : OUStringBuffer aBuf;
70 0 : ::sax::Converter::convertNumber(aBuf, nRepeat);
71 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_NUMBER_COLUMNS_REPEATED, aBuf.makeStringAndClear());
72 : }
73 0 : SvXMLElementExport(rExport, XML_NAMESPACE_TABLE, XML_TABLE_CELL, true, true);
74 0 : }
75 :
76 0 : void ScXMLExportDDELinks::WriteTable(const sal_Int32 nPos)
77 : {
78 0 : ScDocument* pDoc = rExport.GetDocument();
79 0 : if (!pDoc)
80 : return;
81 :
82 0 : const ScMatrix* pMatrix = pDoc->GetDdeLinkResultMatrix(static_cast<sal_uInt16>(nPos));
83 0 : if (!pMatrix)
84 : return;
85 :
86 : SCSIZE nCols, nRows;
87 0 : pMatrix->GetDimensions(nCols, nRows);
88 :
89 0 : SvXMLElementExport aTableElem(rExport, XML_NAMESPACE_TABLE, XML_TABLE, true, true);
90 0 : if (nCols > 1)
91 : {
92 0 : OUStringBuffer aBuf;
93 0 : ::sax::Converter::convertNumber(aBuf, static_cast<sal_Int32>(nCols));
94 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_NUMBER_COLUMNS_REPEATED, aBuf.makeStringAndClear());
95 : }
96 : {
97 0 : SvXMLElementExport aElemCol(rExport, XML_NAMESPACE_TABLE, XML_TABLE_COLUMN, true, true);
98 : }
99 :
100 0 : for (SCSIZE nRow = 0; nRow < nRows; ++nRow)
101 : {
102 0 : sal_Int32 nRepeat = 0;
103 0 : ScMatrixValue aPrevVal;
104 0 : SvXMLElementExport aElemRow(rExport, XML_NAMESPACE_TABLE, XML_TABLE_ROW, true, true);
105 0 : for (SCSIZE nCol = 0; nCol < nCols; ++nCol, ++nRepeat)
106 : {
107 0 : ScMatrixValue aVal = pMatrix->Get(nCol, nRow);
108 0 : if (nCol > 0 && aVal != aPrevVal)
109 : {
110 : // Cell value differs. Flush the cell content.
111 0 : WriteCell(aPrevVal, nRepeat);
112 0 : nRepeat = 0;
113 : }
114 0 : aPrevVal = aVal;
115 0 : }
116 :
117 0 : WriteCell(aPrevVal, nRepeat);
118 0 : }
119 : }
120 :
121 2 : void ScXMLExportDDELinks::WriteDDELinks(uno::Reference<sheet::XSpreadsheetDocument>& xSpreadDoc)
122 : {
123 2 : uno::Reference <beans::XPropertySet> xPropertySet (xSpreadDoc, uno::UNO_QUERY);
124 2 : if (xPropertySet.is())
125 : {
126 2 : uno::Reference<container::XIndexAccess> xIndex(xPropertySet->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_DDELINKS))), uno::UNO_QUERY);
127 2 : if (xIndex.is())
128 : {
129 2 : sal_Int32 nCount = xIndex->getCount();
130 2 : if (nCount)
131 : {
132 0 : SvXMLElementExport aElemDDEs(rExport, XML_NAMESPACE_TABLE, XML_DDE_LINKS, true, true);
133 0 : for (sal_uInt16 nDDELink = 0; nDDELink < nCount; ++nDDELink)
134 : {
135 0 : uno::Reference<sheet::XDDELink> xDDELink(xIndex->getByIndex(nDDELink), uno::UNO_QUERY);
136 0 : if (xDDELink.is())
137 : {
138 0 : SvXMLElementExport aElemDDE(rExport, XML_NAMESPACE_TABLE, XML_DDE_LINK, true, true);
139 : {
140 0 : rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_DDE_APPLICATION, xDDELink->getApplication());
141 0 : rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_DDE_TOPIC, xDDELink->getTopic());
142 0 : rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_DDE_ITEM, xDDELink->getItem());
143 0 : rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_AUTOMATIC_UPDATE, XML_TRUE);
144 : sal_uInt8 nMode;
145 0 : if (rExport.GetDocument() &&
146 0 : rExport.GetDocument()->GetDdeLinkMode(nDDELink, nMode))
147 : {
148 0 : switch (nMode)
149 : {
150 : case SC_DDE_ENGLISH :
151 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_CONVERSION_MODE, XML_INTO_ENGLISH_NUMBER);
152 0 : break;
153 : case SC_DDE_TEXT :
154 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_CONVERSION_MODE, XML_KEEP_TEXT);
155 0 : break;
156 : }
157 : }
158 0 : SvXMLElementExport(rExport, XML_NAMESPACE_OFFICE, XML_DDE_SOURCE, true, true);
159 : }
160 0 : WriteTable(nDDELink);
161 : }
162 0 : }
163 : }
164 2 : }
165 2 : }
166 2 : }
167 :
168 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|