Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / writerfilter / source / rtftok / rtfvalue.cxx
blob49ebfc10eef4c281c8330d68b4c254c647d7aa3d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #include "rtfreferenceproperties.hxx"
11 #include "rtfdocumentimpl.hxx"
12 #include <com/sun/star/embed/XEmbeddedObject.hpp>
14 using namespace com::sun::star;
16 namespace writerfilter
18 namespace rtftok
20 RTFValue::RTFValue(int nValue, OUString sValue, const RTFSprms& rAttributes, const RTFSprms& rSprms,
21 uno::Reference<drawing::XShape> xShape, uno::Reference<io::XInputStream> xStream,
22 uno::Reference<embed::XEmbeddedObject> xObject, bool bForceString,
23 const RTFShape& aShape, const RTFPicture& rPicture)
24 : m_nValue(nValue)
25 , m_sValue(std::move(sValue))
26 , m_pAttributes(new RTFSprms(rAttributes))
27 , m_pSprms(new RTFSprms(rSprms))
28 , m_xShape(std::move(xShape))
29 , m_xStream(std::move(xStream))
30 , m_xObject(std::move(xObject))
31 , m_bForceString(bForceString)
32 , m_pShape(new RTFShape(aShape))
33 , m_pPicture(new RTFPicture(rPicture))
37 RTFValue::RTFValue()
38 : m_pAttributes(new RTFSprms())
39 , m_pSprms(new RTFSprms())
40 , m_pShape(new RTFShape())
41 , m_pPicture(new RTFPicture)
45 RTFValue::RTFValue(int nValue)
46 : m_nValue(nValue)
47 , m_pAttributes(new RTFSprms())
48 , m_pSprms(new RTFSprms())
49 , m_pShape(new RTFShape())
50 , m_pPicture(new RTFPicture)
54 RTFValue::RTFValue(OUString sValue, bool bForce)
55 : m_sValue(std::move(sValue))
56 , m_pAttributes(new RTFSprms())
57 , m_pSprms(new RTFSprms())
58 , m_bForceString(bForce)
59 , m_pShape(new RTFShape())
60 , m_pPicture(new RTFPicture)
64 RTFValue::RTFValue(const RTFSprms& rAttributes)
65 : m_pAttributes(new RTFSprms(rAttributes))
66 , m_pSprms(new RTFSprms())
67 , m_pShape(new RTFShape())
68 , m_pPicture(new RTFPicture)
72 RTFValue::RTFValue(const RTFSprms& rAttributes, const RTFSprms& rSprms)
73 : m_pAttributes(new RTFSprms(rAttributes))
74 , m_pSprms(new RTFSprms(rSprms))
75 , m_pShape(new RTFShape())
76 , m_pPicture(new RTFPicture)
80 RTFValue::RTFValue(uno::Reference<drawing::XShape> xShape)
81 : m_pAttributes(new RTFSprms())
82 , m_pSprms(new RTFSprms())
83 , m_xShape(std::move(xShape))
84 , m_pShape(new RTFShape())
85 , m_pPicture(new RTFPicture)
89 RTFValue::RTFValue(uno::Reference<io::XInputStream> xStream)
90 : m_pAttributes(new RTFSprms())
91 , m_pSprms(new RTFSprms())
92 , m_xStream(std::move(xStream))
93 , m_pShape(new RTFShape())
94 , m_pPicture(new RTFPicture)
98 RTFValue::RTFValue(uno::Reference<embed::XEmbeddedObject> xObject)
99 : m_pAttributes(new RTFSprms())
100 , m_pSprms(new RTFSprms())
101 , m_xObject(std::move(xObject))
102 , m_pShape(new RTFShape())
103 , m_pPicture(new RTFPicture)
107 RTFValue::RTFValue(const RTFShape& aShape)
108 : m_pAttributes(new RTFSprms())
109 , m_pSprms(new RTFSprms())
110 , m_pShape(new RTFShape(aShape))
111 , m_pPicture(new RTFPicture)
115 RTFValue::RTFValue(const RTFPicture& rPicture)
116 : m_pAttributes(new RTFSprms())
117 , m_pSprms(new RTFSprms())
118 , m_pShape(new RTFShape())
119 , m_pPicture(new RTFPicture(rPicture))
123 RTFValue::~RTFValue() = default;
125 int RTFValue::getInt() const { return m_nValue; }
127 OUString RTFValue::getString() const
129 if (!m_sValue.isEmpty() || m_bForceString)
130 return m_sValue;
132 return OUString::number(m_nValue);
135 void RTFValue::setString(const OUString& sValue) { m_sValue = sValue; }
137 uno::Any RTFValue::getAny() const
139 uno::Any ret;
140 if (!m_sValue.isEmpty() || m_bForceString)
141 ret <<= m_sValue;
142 else if (m_xShape.is())
143 ret <<= m_xShape;
144 else if (m_xStream.is())
145 ret <<= m_xStream;
146 else if (m_xObject.is())
147 ret <<= m_xObject;
148 else
149 ret <<= static_cast<sal_Int32>(m_nValue);
150 return ret;
153 RTFShape& RTFValue::getShape() const { return *m_pShape; }
155 RTFPicture& RTFValue::getPicture() const { return *m_pPicture; }
157 writerfilter::Reference<Properties>::Pointer_t RTFValue::getProperties()
159 return new RTFReferenceProperties(*m_pAttributes, *m_pSprms);
162 writerfilter::Reference<BinaryObj>::Pointer_t RTFValue::getBinary()
164 return writerfilter::Reference<BinaryObj>::Pointer_t();
167 #ifdef DBG_UTIL
168 std::string RTFValue::toString() const
170 if (!m_sValue.isEmpty() || m_bForceString)
171 return OUStringToOString(m_sValue, RTL_TEXTENCODING_UTF8).getStr();
173 return OString::number(m_nValue).getStr();
175 #endif
177 RTFValue* RTFValue::Clone()
179 return new RTFValue(m_nValue, m_sValue, *m_pAttributes, *m_pSprms, m_xShape, m_xStream,
180 m_xObject, m_bForceString, *m_pShape, *m_pPicture);
183 RTFValue* RTFValue::CloneWithSprms(RTFSprms const& rAttributes, RTFSprms const& rSprms)
185 return new RTFValue(m_nValue, m_sValue, rAttributes, rSprms, m_xShape, m_xStream, m_xObject,
186 m_bForceString, *m_pShape, *m_pPicture);
189 bool RTFValue::equals(const RTFValue& rOther) const
191 if (m_nValue != rOther.m_nValue)
192 return false;
193 if (m_sValue != rOther.m_sValue)
194 return false;
195 if (m_pAttributes->size() != rOther.m_pAttributes->size())
196 return false;
197 if (!m_pAttributes->equals(rOther))
198 return false;
199 if (m_pSprms->size() != rOther.m_pSprms->size())
200 return false;
201 if (!m_pSprms->equals(rOther))
202 return false;
203 return true;
206 RTFSprms& RTFValue::getAttributes() { return *m_pAttributes; }
208 RTFSprms& RTFValue::getSprms() { return *m_pSprms; }
210 } // namespace rtftok
211 } // namespace writerfilter
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */