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 :
10 : #include <rtfreferenceproperties.hxx>
11 : #include <rtfdocumentimpl.hxx>
12 :
13 : using namespace com::sun::star;
14 :
15 : namespace writerfilter
16 : {
17 : namespace rtftok
18 : {
19 :
20 :
21 198361 : RTFValue::RTFValue(int nValue, const OUString& sValue,
22 : RTFSprms rAttributes, RTFSprms rSprms,
23 : uno::Reference<drawing::XShape> const& xShape,
24 : uno::Reference<io::XInputStream> const& xStream,
25 : uno::Reference<embed::XEmbeddedObject> const& xObject,
26 : bool bForceString,
27 : const RTFShape& aShape)
28 : : m_nValue(nValue),
29 : m_sValue(sValue),
30 : m_pAttributes(std::make_shared<RTFSprms>(rAttributes)),
31 : m_pSprms(std::make_shared<RTFSprms>(rSprms)),
32 : m_xShape(xShape),
33 : m_xStream(xStream),
34 : m_xObject(xObject),
35 : m_bForceString(bForceString),
36 198361 : m_pShape(std::make_shared<RTFShape>(aShape))
37 : {
38 198361 : }
39 :
40 102 : RTFValue::RTFValue()
41 : : m_nValue(0),
42 : m_sValue(),
43 : m_pAttributes(std::make_shared<RTFSprms>()),
44 : m_pSprms(std::make_shared<RTFSprms>()),
45 : m_xShape(),
46 : m_xStream(),
47 : m_xObject(),
48 : m_bForceString(false),
49 102 : m_pShape(std::make_shared<RTFShape>())
50 : {
51 102 : }
52 :
53 108439 : RTFValue::RTFValue(int nValue)
54 : : m_nValue(nValue),
55 : m_sValue(),
56 : m_pAttributes(std::make_shared<RTFSprms>()),
57 : m_pSprms(std::make_shared<RTFSprms>()),
58 : m_xShape(),
59 : m_xStream(),
60 : m_xObject(),
61 108439 : m_bForceString(false)
62 : {
63 108439 : m_pShape.reset(new RTFShape());
64 108439 : }
65 :
66 26095 : RTFValue::RTFValue(const OUString& sValue, bool bForce)
67 : : m_nValue(),
68 : m_sValue(sValue),
69 : m_pAttributes(std::make_shared<RTFSprms>()),
70 : m_pSprms(std::make_shared<RTFSprms>()),
71 : m_xShape(),
72 : m_xStream(),
73 : m_xObject(),
74 : m_bForceString(bForce),
75 26095 : m_pShape(std::make_shared<RTFShape>())
76 : {
77 26095 : }
78 :
79 15585 : RTFValue::RTFValue(RTFSprms rAttributes)
80 : : m_nValue(),
81 : m_sValue(),
82 : m_pAttributes(std::make_shared<RTFSprms>(rAttributes)),
83 : m_pSprms(std::make_shared<RTFSprms>()),
84 : m_xShape(),
85 : m_xStream(),
86 : m_xObject(),
87 : m_bForceString(false),
88 15585 : m_pShape(std::make_shared<RTFShape>())
89 : {
90 15585 : }
91 :
92 7145 : RTFValue::RTFValue(RTFSprms rAttributes, RTFSprms rSprms)
93 : : m_nValue(),
94 : m_sValue(),
95 : m_pAttributes(std::make_shared<RTFSprms>(rAttributes)),
96 : m_pSprms(std::make_shared<RTFSprms>(rSprms)),
97 : m_xShape(),
98 : m_xStream(),
99 : m_xObject(),
100 : m_bForceString(false),
101 7145 : m_pShape(std::make_shared<RTFShape>())
102 : {
103 7145 : }
104 :
105 37 : RTFValue::RTFValue(uno::Reference<drawing::XShape> const& xShape)
106 : : m_nValue(),
107 : m_sValue(),
108 : m_pAttributes(std::make_shared<RTFSprms>()),
109 : m_pSprms(std::make_shared<RTFSprms>()),
110 : m_xShape(xShape),
111 : m_xStream(),
112 : m_xObject(),
113 : m_bForceString(false),
114 37 : m_pShape(std::make_shared<RTFShape>())
115 : {
116 37 : }
117 :
118 4 : RTFValue::RTFValue(uno::Reference<io::XInputStream> const& xStream)
119 : : m_nValue(),
120 : m_sValue(),
121 : m_pAttributes(std::make_shared<RTFSprms>()),
122 : m_pSprms(std::make_shared<RTFSprms>()),
123 : m_xShape(),
124 : m_xStream(xStream),
125 : m_xObject(),
126 : m_bForceString(false),
127 4 : m_pShape(std::make_shared<RTFShape>())
128 : {
129 4 : }
130 :
131 73 : RTFValue::RTFValue(uno::Reference<embed::XEmbeddedObject> const& xObject)
132 : : m_nValue(),
133 : m_sValue(),
134 : m_pAttributes(std::make_shared<RTFSprms>()),
135 : m_pSprms(std::make_shared<RTFSprms>()),
136 : m_xShape(),
137 : m_xStream(),
138 : m_xObject(xObject),
139 : m_bForceString(false),
140 73 : m_pShape(std::make_shared<RTFShape>())
141 : {
142 73 : }
143 :
144 1 : RTFValue::RTFValue(const RTFShape& aShape)
145 : : m_nValue(),
146 : m_sValue(),
147 : m_pAttributes(std::make_shared<RTFSprms>()),
148 : m_pSprms(std::make_shared<RTFSprms>()),
149 : m_xShape(),
150 : m_xStream(),
151 : m_xObject(),
152 : m_bForceString(false),
153 1 : m_pShape(std::make_shared<RTFShape>(aShape))
154 : {
155 1 : }
156 :
157 554203 : RTFValue::~RTFValue()
158 : {
159 554203 : }
160 :
161 172401 : int RTFValue::getInt() const
162 : {
163 172401 : return m_nValue;
164 : }
165 :
166 82000 : OUString RTFValue::getString() const
167 : {
168 82000 : if (!m_sValue.isEmpty() || m_bForceString)
169 20963 : return m_sValue;
170 : else
171 61037 : return OUString::number(m_nValue);
172 : }
173 :
174 630 : void RTFValue::setString(const OUString& sValue)
175 : {
176 630 : m_sValue = sValue;
177 630 : }
178 :
179 187 : uno::Any RTFValue::getAny() const
180 : {
181 187 : uno::Any ret;
182 187 : if (!m_sValue.isEmpty() || m_bForceString)
183 0 : ret <<= m_sValue;
184 187 : else if (m_xShape.is())
185 36 : ret <<= m_xShape;
186 151 : else if (m_xStream.is())
187 3 : ret <<= m_xStream;
188 148 : else if (m_xObject.is())
189 146 : ret <<= m_xObject;
190 : else
191 2 : ret <<= static_cast<sal_Int32>(m_nValue);
192 187 : return ret;
193 : }
194 :
195 1 : RTFShape& RTFValue::getShape() const
196 : {
197 1 : return *m_pShape;
198 : }
199 :
200 29603 : writerfilter::Reference<Properties>::Pointer_t RTFValue::getProperties()
201 : {
202 29603 : return std::make_shared<RTFReferenceProperties>(*m_pAttributes, *m_pSprms);
203 : }
204 :
205 0 : writerfilter::Reference<Stream>::Pointer_t RTFValue::getStream()
206 : {
207 0 : return writerfilter::Reference<Stream>::Pointer_t();
208 : }
209 :
210 0 : writerfilter::Reference<BinaryObj>::Pointer_t RTFValue::getBinary()
211 : {
212 0 : return writerfilter::Reference<BinaryObj>::Pointer_t();
213 : }
214 :
215 : #ifdef DEBUG_WRITERFILTER
216 : std::string RTFValue::toString() const
217 : {
218 : if (!m_sValue.isEmpty() || m_bForceString)
219 : return OUStringToOString(m_sValue, RTL_TEXTENCODING_UTF8).getStr();
220 : else
221 : return OString::number(m_nValue).getStr();
222 : }
223 : #endif
224 :
225 193707 : RTFValue* RTFValue::Clone()
226 : {
227 193707 : return new RTFValue(m_nValue, m_sValue, *m_pAttributes, *m_pSprms, m_xShape, m_xStream, m_xObject, m_bForceString, *m_pShape);
228 : }
229 :
230 4654 : RTFValue* RTFValue::CloneWithSprms(RTFSprms const& rAttributes, RTFSprms const& rSprms)
231 : {
232 4654 : return new RTFValue(m_nValue, m_sValue, rAttributes, rSprms, m_xShape, m_xStream, m_xObject, m_bForceString, *m_pShape);
233 : }
234 :
235 21291 : bool RTFValue::equals(RTFValue& rOther)
236 : {
237 21291 : if (m_nValue != rOther.m_nValue)
238 505 : return false;
239 20786 : if (m_sValue != rOther.m_sValue)
240 2737 : return false;
241 18049 : if (m_pAttributes->size() != rOther.m_pAttributes->size())
242 2515 : return false;
243 15534 : else if (!m_pAttributes->equals(rOther))
244 2664 : return false;
245 12870 : if (m_pSprms->size() != rOther.m_pSprms->size())
246 0 : return false;
247 12870 : else if (!m_pSprms->equals(rOther))
248 0 : return false;
249 12870 : return true;
250 : }
251 :
252 132853 : RTFSprms& RTFValue::getAttributes()
253 : {
254 132853 : return *m_pAttributes;
255 : }
256 :
257 106414 : RTFSprms& RTFValue::getSprms()
258 : {
259 106414 : return *m_pSprms;
260 : }
261 :
262 : } // namespace rtftok
263 72 : } // namespace writerfilter
264 :
265 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|