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