1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
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::rtftok
18 RTFValue::RTFValue(int nValue
, OUString sValue
, const RTFSprms
& rAttributes
, const RTFSprms
& rSprms
,
19 uno::Reference
<drawing::XShape
> xShape
, uno::Reference
<io::XInputStream
> xStream
,
20 uno::Reference
<embed::XEmbeddedObject
> xObject
, bool bForceString
,
21 const RTFShape
& aShape
, const RTFPicture
& rPicture
)
23 , m_sValue(std::move(sValue
))
24 , m_pAttributes(new RTFSprms(rAttributes
))
25 , m_pSprms(new RTFSprms(rSprms
))
26 , m_xShape(std::move(xShape
))
27 , m_xStream(std::move(xStream
))
28 , m_xObject(std::move(xObject
))
29 , m_bForceString(bForceString
)
30 , m_pShape(new RTFShape(aShape
))
31 , m_pPicture(new RTFPicture(rPicture
))
36 : m_pAttributes(new RTFSprms())
37 , m_pSprms(new RTFSprms())
38 , m_pShape(new RTFShape())
39 , m_pPicture(new RTFPicture
)
43 RTFValue::RTFValue(int nValue
)
45 , m_pAttributes(new RTFSprms())
46 , m_pSprms(new RTFSprms())
47 , m_pShape(new RTFShape())
48 , m_pPicture(new RTFPicture
)
52 RTFValue::RTFValue(OUString sValue
, bool bForce
)
53 : m_sValue(std::move(sValue
))
54 , m_pAttributes(new RTFSprms())
55 , m_pSprms(new RTFSprms())
56 , m_bForceString(bForce
)
57 , m_pShape(new RTFShape())
58 , m_pPicture(new RTFPicture
)
62 RTFValue::RTFValue(const RTFSprms
& rAttributes
)
63 : m_pAttributes(new RTFSprms(rAttributes
))
64 , m_pSprms(new RTFSprms())
65 , m_pShape(new RTFShape())
66 , m_pPicture(new RTFPicture
)
70 RTFValue::RTFValue(const RTFSprms
& rAttributes
, const RTFSprms
& rSprms
)
71 : m_pAttributes(new RTFSprms(rAttributes
))
72 , m_pSprms(new RTFSprms(rSprms
))
73 , m_pShape(new RTFShape())
74 , m_pPicture(new RTFPicture
)
78 RTFValue::RTFValue(uno::Reference
<drawing::XShape
> xShape
)
79 : m_pAttributes(new RTFSprms())
80 , m_pSprms(new RTFSprms())
81 , m_xShape(std::move(xShape
))
82 , m_pShape(new RTFShape())
83 , m_pPicture(new RTFPicture
)
87 RTFValue::RTFValue(uno::Reference
<io::XInputStream
> xStream
)
88 : m_pAttributes(new RTFSprms())
89 , m_pSprms(new RTFSprms())
90 , m_xStream(std::move(xStream
))
91 , m_pShape(new RTFShape())
92 , m_pPicture(new RTFPicture
)
96 RTFValue::RTFValue(uno::Reference
<embed::XEmbeddedObject
> xObject
)
97 : m_pAttributes(new RTFSprms())
98 , m_pSprms(new RTFSprms())
99 , m_xObject(std::move(xObject
))
100 , m_pShape(new RTFShape())
101 , m_pPicture(new RTFPicture
)
105 RTFValue::RTFValue(const RTFShape
& aShape
)
106 : m_pAttributes(new RTFSprms())
107 , m_pSprms(new RTFSprms())
108 , m_pShape(new RTFShape(aShape
))
109 , m_pPicture(new RTFPicture
)
113 RTFValue::RTFValue(const RTFPicture
& rPicture
)
114 : m_pAttributes(new RTFSprms())
115 , m_pSprms(new RTFSprms())
116 , m_pShape(new RTFShape())
117 , m_pPicture(new RTFPicture(rPicture
))
121 RTFValue::~RTFValue() = default;
123 int RTFValue::getInt() const { return m_nValue
; }
125 OUString
RTFValue::getString() const
127 if (!m_sValue
.isEmpty() || m_bForceString
)
130 return OUString::number(m_nValue
);
133 void RTFValue::setString(const OUString
& sValue
) { m_sValue
= sValue
; }
135 uno::Any
RTFValue::getAny() const
138 if (!m_sValue
.isEmpty() || m_bForceString
)
140 else if (m_xShape
.is())
142 else if (m_xStream
.is())
144 else if (m_xObject
.is())
147 ret
<<= static_cast<sal_Int32
>(m_nValue
);
151 RTFShape
& RTFValue::getShape() const { return *m_pShape
; }
153 RTFPicture
& RTFValue::getPicture() const { return *m_pPicture
; }
155 writerfilter::Reference
<Properties
>::Pointer_t
RTFValue::getProperties()
157 return new RTFReferenceProperties(*m_pAttributes
, *m_pSprms
);
160 writerfilter::Reference
<BinaryObj
>::Pointer_t
RTFValue::getBinary()
162 return writerfilter::Reference
<BinaryObj
>::Pointer_t();
166 std::string
RTFValue::toString() const
168 if (!m_sValue
.isEmpty() || m_bForceString
)
169 return OUStringToOString(m_sValue
, RTL_TEXTENCODING_UTF8
).getStr();
171 return OString::number(m_nValue
).getStr();
175 RTFValue
* RTFValue::Clone()
177 return new RTFValue(m_nValue
, m_sValue
, *m_pAttributes
, *m_pSprms
, m_xShape
, m_xStream
,
178 m_xObject
, m_bForceString
, *m_pShape
, *m_pPicture
);
181 RTFValue
* RTFValue::CloneWithSprms(RTFSprms
const& rAttributes
, RTFSprms
const& rSprms
)
183 return new RTFValue(m_nValue
, m_sValue
, rAttributes
, rSprms
, m_xShape
, m_xStream
, m_xObject
,
184 m_bForceString
, *m_pShape
, *m_pPicture
);
187 bool RTFValue::equals(const RTFValue
& rOther
) const
189 if (m_nValue
!= rOther
.m_nValue
)
191 if (m_sValue
!= rOther
.m_sValue
)
193 if (m_pAttributes
->size() != rOther
.m_pAttributes
->size())
195 if (!m_pAttributes
->equals(rOther
))
197 if (m_pSprms
->size() != rOther
.m_pSprms
->size())
199 if (!m_pSprms
->equals(rOther
))
204 RTFSprms
& RTFValue::getAttributes() { return *m_pAttributes
; }
206 RTFSprms
& RTFValue::getSprms() { return *m_pSprms
; }
208 } // namespace writerfilter::rtftok
210 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */