Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * Version: MPL 1.1 / GPLv3+ / LGPLv3+
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Initial Developer of the Original Code is
16 : * Miklos Vajna <vmiklos@frugalware.org>
17 : * Portions created by the Initial Developer are Copyright (C) 2011 the
18 : * Initial Developer. All Rights Reserved.
19 : *
20 : * Contributor(s):
21 : *
22 : * Alternatively, the contents of this file may be used under the terms of
23 : * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
24 : * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
25 : * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
26 : * instead of those above.
27 : */
28 :
29 : #include <rtfreferenceproperties.hxx>
30 :
31 : namespace writerfilter {
32 : namespace rtftok {
33 :
34 : using rtl::OString;
35 : using rtl::OUString;
36 :
37 55905 : RTFValue::RTFValue(int nValue, rtl::OUString sValue, RTFSprms rAttributes,
38 : RTFSprms rSprms, uno::Reference<drawing::XShape> xShape,
39 : uno::Reference<io::XInputStream> xStream, uno::Reference<embed::XEmbeddedObject> xObject, bool bForceString)
40 : : m_nValue(nValue),
41 : m_sValue(sValue),
42 : m_xShape(xShape),
43 : m_xStream(xStream),
44 : m_xObject(xObject),
45 55905 : m_bForceString(bForceString)
46 : {
47 55905 : m_pAttributes.reset(new RTFSprms(rAttributes));
48 55905 : m_pSprms.reset(new RTFSprms(rSprms));
49 55905 : }
50 :
51 18873 : RTFValue::RTFValue(int nValue)
52 : : m_nValue(nValue),
53 : m_sValue(),
54 : m_xShape(),
55 : m_xStream(),
56 : m_xObject(),
57 18873 : m_bForceString(false)
58 : {
59 18873 : m_pAttributes.reset(new RTFSprms());
60 18873 : m_pSprms.reset(new RTFSprms());
61 18873 : }
62 :
63 1046 : RTFValue::RTFValue(OUString sValue, bool bForce)
64 : : m_nValue(),
65 : m_sValue(sValue),
66 : m_xShape(),
67 : m_xStream(),
68 : m_xObject(),
69 1046 : m_bForceString(bForce)
70 : {
71 1046 : m_pAttributes.reset(new RTFSprms());
72 1046 : m_pSprms.reset(new RTFSprms());
73 1046 : }
74 :
75 881 : RTFValue::RTFValue(RTFSprms rAttributes)
76 : : m_nValue(),
77 : m_sValue(),
78 : m_xShape(),
79 : m_xStream(),
80 : m_xObject(),
81 881 : m_bForceString(false)
82 : {
83 881 : m_pAttributes.reset(new RTFSprms(rAttributes));
84 881 : m_pSprms.reset(new RTFSprms());
85 881 : }
86 :
87 964 : RTFValue::RTFValue(RTFSprms rAttributes, RTFSprms rSprms)
88 : : m_nValue(),
89 : m_sValue(),
90 : m_xShape(),
91 : m_xStream(),
92 : m_xObject(),
93 964 : m_bForceString(false)
94 : {
95 964 : m_pAttributes.reset(new RTFSprms(rAttributes));
96 964 : m_pSprms.reset(new RTFSprms(rSprms));
97 964 : }
98 :
99 8 : RTFValue::RTFValue(uno::Reference<drawing::XShape> rShape)
100 : : m_nValue(),
101 : m_sValue(),
102 : m_xShape(rShape),
103 : m_xStream(),
104 : m_xObject(),
105 8 : m_bForceString(false)
106 : {
107 8 : m_pAttributes.reset(new RTFSprms());
108 8 : m_pSprms.reset(new RTFSprms());
109 8 : }
110 :
111 0 : RTFValue::RTFValue(uno::Reference<io::XInputStream> rStream)
112 : : m_nValue(),
113 : m_sValue(),
114 : m_xShape(),
115 : m_xStream(rStream),
116 : m_xObject(),
117 0 : m_bForceString(false)
118 : {
119 0 : m_pAttributes.reset(new RTFSprms());
120 0 : m_pSprms.reset(new RTFSprms());
121 0 : }
122 :
123 59 : RTFValue::RTFValue(uno::Reference<embed::XEmbeddedObject> xObject)
124 : : m_nValue(),
125 : m_sValue(),
126 : m_xShape(),
127 : m_xStream(),
128 : m_xObject(xObject),
129 59 : m_bForceString(false)
130 : {
131 59 : m_pAttributes.reset(new RTFSprms());
132 59 : m_pSprms.reset(new RTFSprms());
133 59 : }
134 :
135 155472 : RTFValue::~RTFValue()
136 : {
137 155472 : }
138 :
139 55963 : int RTFValue::getInt() const
140 : {
141 55963 : return m_nValue;
142 : }
143 :
144 21322 : OUString RTFValue::getString() const
145 : {
146 21322 : if (!m_sValue.isEmpty() || m_bForceString)
147 951 : return m_sValue;
148 : else
149 20371 : return OUString::valueOf(sal_Int32(m_nValue));
150 : }
151 :
152 10 : void RTFValue::setString(OUString sValue)
153 : {
154 10 : m_sValue = sValue;
155 10 : }
156 :
157 126 : uno::Any RTFValue::getAny() const
158 : {
159 126 : uno::Any ret;
160 126 : if (!m_sValue.isEmpty() || m_bForceString)
161 0 : ret <<= m_sValue;
162 126 : else if (m_xShape.is())
163 8 : ret <<= m_xShape;
164 118 : else if (m_xStream.is())
165 0 : ret <<= m_xStream;
166 118 : else if (m_xObject.is())
167 118 : ret <<= m_xObject;
168 : else
169 0 : ret <<= static_cast<sal_Int32>(m_nValue);
170 126 : return ret;
171 : }
172 :
173 1375 : writerfilter::Reference<Properties>::Pointer_t RTFValue::getProperties()
174 : {
175 : writerfilter::Reference<Properties>::Pointer_t const pProperties(
176 4125 : new RTFReferenceProperties(*m_pAttributes, *m_pSprms)
177 4125 : );
178 1375 : return pProperties;
179 : }
180 :
181 0 : writerfilter::Reference<Stream>::Pointer_t RTFValue::getStream()
182 : {
183 0 : return writerfilter::Reference<Stream>::Pointer_t();
184 : }
185 :
186 0 : writerfilter::Reference<BinaryObj>::Pointer_t RTFValue::getBinary()
187 : {
188 0 : return writerfilter::Reference<BinaryObj>::Pointer_t();
189 : }
190 :
191 0 : std::string RTFValue::toString() const
192 : {
193 0 : if (!m_sValue.isEmpty() || m_bForceString)
194 0 : return OUStringToOString(m_sValue, RTL_TEXTENCODING_UTF8).getStr();
195 : else
196 0 : return OString::valueOf(static_cast<sal_Int32>(m_nValue)).getStr();
197 : }
198 :
199 55905 : RTFValue* RTFValue::Clone()
200 : {
201 55905 : return new RTFValue(m_nValue, m_sValue, *m_pAttributes, *m_pSprms, m_xShape, m_xStream, m_xObject, m_bForceString);
202 : }
203 :
204 1016 : bool RTFValue::equals(RTFValue& rOther)
205 : {
206 1016 : return m_nValue == rOther.m_nValue;
207 : }
208 :
209 1914 : RTFSprms& RTFValue::getAttributes()
210 : {
211 1914 : return *m_pAttributes;
212 : }
213 :
214 1675 : RTFSprms& RTFValue::getSprms()
215 : {
216 1675 : return *m_pSprms;
217 : }
218 :
219 : } // namespace rtftok
220 15 : } // namespace writerfilter
221 :
222 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|