Update ooo320-m1
[ooovba.git] / writerfilter / source / doctok / WW8PropertySetImpl.cxx
blob32048ecc8576467fa3f02876f7213313a643b675
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: WW8PropertySetImpl.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "WW8DocumentImpl.hxx"
32 #include "WW8ResourceModelImpl.hxx"
33 #include <doctok/resourceids.hxx>
34 #include <resourcemodel/QNameToString.hxx>
36 namespace writerfilter {
37 namespace doctok
41 bool operator != (const WW8PropertySetIterator & rA,
42 const WW8PropertySetIterator & rB)
44 return ! (rA.equal(rB));
47 WW8Property::~WW8Property()
51 WW8PropertySet::~WW8PropertySet()
55 WW8PropertySetIterator::~WW8PropertySetIterator()
59 WW8PropertyImpl::WW8PropertyImpl(WW8Stream & rStream,
60 sal_uInt32 nOffset, sal_uInt32 nCount)
61 : WW8StructBase(rStream, nOffset, nCount)
65 WW8PropertyImpl::WW8PropertyImpl(const WW8StructBase & rBase,
66 sal_uInt32 nOffset,
67 sal_uInt32 nCount)
68 : WW8StructBase(rBase, nOffset, nCount)
72 WW8PropertyImpl::WW8PropertyImpl(WW8StructBase * pBase,
73 sal_uInt32 nOffset,
74 sal_uInt32 nCount)
75 : WW8StructBase(pBase, nOffset, nCount)
79 WW8PropertyImpl::~WW8PropertyImpl()
83 sal_uInt32 WW8PropertyImpl::getParam() const
85 sal_uInt32 nResult = 0;
87 switch (get_spra())
89 case 0:
90 case 1:
91 nResult = getU8(2);
93 break;
95 case 2:
96 case 4:
97 case 5:
98 nResult = getU16(2);
100 break;
102 case 3:
103 nResult = getU32(2);
105 break;
107 case 7:
108 nResult = getU16(2) + (getU8(4) << 16);
110 break;
112 default:
113 break;
116 return nResult;
119 WW8Stream::Sequence WW8PropertyImpl::getParams() const
121 return WW8Stream::Sequence(mSequence, 2, getCount() - 2);
124 sal_uInt32 WW8PropertyImpl::getByteLength() const
126 sal_uInt32 nParamSize = 0;
128 switch (get_spra())
130 case 0:
131 case 1:
132 nParamSize = 1;
134 break;
136 case 2:
137 case 4:
138 case 5:
139 nParamSize = 2;
141 break;
143 case 3:
144 nParamSize = 4;
146 break;
148 case 7:
149 nParamSize = 3;
151 break;
152 default:
153 nParamSize = getU8(2) + 1;
155 break;
158 return nParamSize + 2;
161 sal_uInt32 WW8PropertyImpl::getParamOffset() const
163 sal_uInt32 nReturn = 0;
165 if (get_spra() == 6)
166 nReturn = 1;
168 switch (getId())
170 case 0xd608:
171 case 0xd609:
172 nReturn = 3;
174 break;
176 default:
177 break;
180 return nReturn;
183 void WW8PropertyImpl::dump(OutputWithDepth<string> & o) const
185 o.addItem(toString());
188 string WW8PropertyImpl::toString() const
190 string aResult;
192 aResult += "<sprmcommon";
194 char sBuffer[256];
195 snprintf(sBuffer, sizeof(sBuffer), " id=\"%" SAL_PRIuUINT32 "\"", getId());
196 aResult += sBuffer;
197 aResult += " name=\"";
198 aResult += (*SprmIdToString::Instance())(getId());
199 aResult += "\"";
200 snprintf(sBuffer, sizeof(sBuffer), " sgc=\"%x\"", get_sgc());
201 aResult += sBuffer;
202 snprintf(sBuffer, sizeof(sBuffer), " spra=\"%x\"", get_spra());
203 aResult += sBuffer;
204 snprintf(sBuffer, sizeof(sBuffer), " size=\"%" SAL_PRIxUINT32 "\"", getByteLength());
205 aResult += sBuffer;
206 snprintf(sBuffer, sizeof(sBuffer), " param=\"%" SAL_PRIxUINT32 "\"", getParam());
207 aResult += sBuffer;
208 aResult += ">\n";
210 aResult += mSequence.toString();
212 aResult += "</sprmcommon>";
214 return aResult;
217 WW8PropertySetImpl::WW8PropertySetImpl(WW8Stream & rStream,
218 sal_uInt32 nOffset,
219 sal_uInt32 nCount,
220 bool bPap)
221 : WW8StructBase(rStream, nOffset, nCount), mbPap(bPap)
225 WW8PropertySetImpl::WW8PropertySetImpl(const WW8StructBase & rBase,
226 sal_uInt32 nOffset,
227 sal_uInt32 nCount,
228 bool bPap)
229 : WW8StructBase(rBase, nOffset, nCount), mbPap(bPap)
233 WW8PropertySetImpl::~WW8PropertySetImpl()
237 bool WW8PropertySetImpl::isPap() const
239 return mbPap;
242 sal_uInt32 WW8PropertySetImpl::get_istd() const
244 sal_uInt32 nResult = 0;
246 if (mbPap)
247 nResult = getU16(0);
249 return nResult;
252 WW8PropertySetIterator::Pointer_t WW8PropertySetImpl::begin()
254 return WW8PropertySetIterator::Pointer_t
255 (new WW8PropertySetIteratorImpl(this, mbPap ? 2 : 0));
258 WW8PropertySetIterator::Pointer_t WW8PropertySetImpl::end()
260 return WW8PropertySetIterator::Pointer_t
261 (new WW8PropertySetIteratorImpl(this, getCount()));
264 WW8PropertySetIteratorImpl::~WW8PropertySetIteratorImpl()
268 WW8Property::Pointer_t
269 WW8PropertySetImpl::getAttribute(sal_uInt32 nOffset) const
271 WW8PropertyImpl aTmpAttr(*this, nOffset, 3);
273 sal_uInt32 nLength = aTmpAttr.getByteLength();
275 if (nOffset + nLength > getCount())
276 nLength = getCount() - nOffset;
278 return WW8Property::Pointer_t
279 (new WW8PropertyImpl(*this, nOffset, nLength));
282 void WW8PropertySetImpl::dump(OutputWithDepth<string> & o) const
284 WW8StructBase::dump(o);
286 WW8PropertySetIterator::Pointer_t pIt =
287 const_cast<WW8PropertySetImpl *>(this)->begin();
288 WW8PropertySetIterator::Pointer_t pItEnd =
289 const_cast<WW8PropertySetImpl *>(this)->end();
291 while((*pIt) != (*pItEnd))
293 WW8Property::Pointer_t pAttr = pIt->get();
295 pAttr->dump(o);
296 ++(*pIt);
300 void WW8PropertySetImpl::dots(ostream & o)
302 WW8PropertySetIterator::Pointer_t pIt = begin();
303 WW8PropertySetIterator::Pointer_t pItEnd = end();
305 while((*pIt) != (*pItEnd))
307 WW8Property::Pointer_t pAttr = pIt->get();
309 o << "." << endl;
311 ++(*pIt);
315 string WW8PropertySetImpl::getType() const
317 return "WW8PropertySetImpl";
320 void WW8PropertySetImpl::resolveLocal(Sprm & sprm)
322 switch (sprm.getId())
324 case 0x6a03:
326 Value::Pointer_t pValue = sprm.getValue();
327 getDocument()->setPicLocation(pValue->getInt());
328 getDocument()->setPicIsData(false);
330 break;
331 case 0x806:
333 getDocument()->setPicIsData(true);
335 default:
336 break;
340 void WW8PropertySetImpl::resolve(Properties & rHandler)
342 if (getCount() >= (isPap() ? 5U : 3U))
344 WW8PropertySetIterator::Pointer_t pIt = begin();
345 WW8PropertySetIterator::Pointer_t pItEnd = end();
347 if (isPap())
349 WW8Value::Pointer_t pValue = createValue(getU16(0));
350 rHandler.attribute(NS_rtf::LN_ISTD, *pValue);
353 while((*pIt) != (*pItEnd))
355 WW8Sprm aSprm(pIt->get());
357 rHandler.sprm(aSprm);
359 resolveLocal(aSprm);
361 ++(*pIt);
366 WW8PropertySetIterator & WW8PropertySetIteratorImpl::operator++ ()
368 WW8Property::Pointer_t pTmpAttr = mpAttrSet->getAttribute(mnOffset);
370 mnOffset += dynamic_cast<WW8PropertyImpl *>(pTmpAttr.get())->
371 getByteLength();
373 if (mnOffset > mpAttrSet->getCount() ||
374 mpAttrSet->getCount() - mnOffset < 3)
375 mnOffset = mpAttrSet->getCount();
377 return *this;
380 WW8Property::Pointer_t WW8PropertySetIteratorImpl::get() const
382 return mpAttrSet->getAttribute(mnOffset);
385 bool WW8PropertySetIteratorImpl::equal
386 (const WW8PropertySetIterator & rIt) const
388 const WW8PropertySetIteratorImpl & rMyIt =
389 dynamic_cast<const WW8PropertySetIteratorImpl &>(rIt);
391 return mpAttrSet == rMyIt.mpAttrSet && mnOffset == rMyIt.mnOffset;
394 string WW8PropertySetIteratorImpl::toString() const
396 string sResult = "";
398 char sBuffer[256];
400 snprintf(sBuffer, sizeof(sBuffer), "(%" SAL_PRIuUINT32 ")", mnOffset);
401 sResult += sBuffer;
403 return sResult;