1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: WW8PropertySetImpl.cxx,v $
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
{
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
,
68 : WW8StructBase(rBase
, nOffset
, nCount
)
72 WW8PropertyImpl::WW8PropertyImpl(WW8StructBase
* pBase
,
75 : WW8StructBase(pBase
, nOffset
, nCount
)
79 WW8PropertyImpl::~WW8PropertyImpl()
83 sal_uInt32
WW8PropertyImpl::getParam() const
85 sal_uInt32 nResult
= 0;
108 nResult
= getU16(2) + (getU8(4) << 16);
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;
153 nParamSize
= getU8(2) + 1;
158 return nParamSize
+ 2;
161 sal_uInt32
WW8PropertyImpl::getParamOffset() const
163 sal_uInt32 nReturn
= 0;
183 void WW8PropertyImpl::dump(OutputWithDepth
<string
> & o
) const
185 o
.addItem(toString());
188 string
WW8PropertyImpl::toString() const
192 aResult
+= "<sprmcommon";
195 snprintf(sBuffer
, sizeof(sBuffer
), " id=\"%" SAL_PRIuUINT32
"\"", getId());
197 aResult
+= " name=\"";
198 aResult
+= (*SprmIdToString::Instance())(getId());
200 snprintf(sBuffer
, sizeof(sBuffer
), " sgc=\"%x\"", get_sgc());
202 snprintf(sBuffer
, sizeof(sBuffer
), " spra=\"%x\"", get_spra());
204 snprintf(sBuffer
, sizeof(sBuffer
), " size=\"%" SAL_PRIxUINT32
"\"", getByteLength());
206 snprintf(sBuffer
, sizeof(sBuffer
), " param=\"%" SAL_PRIxUINT32
"\"", getParam());
210 aResult
+= mSequence
.toString();
212 aResult
+= "</sprmcommon>";
217 WW8PropertySetImpl::WW8PropertySetImpl(WW8Stream
& rStream
,
221 : WW8StructBase(rStream
, nOffset
, nCount
), mbPap(bPap
)
225 WW8PropertySetImpl::WW8PropertySetImpl(const WW8StructBase
& rBase
,
229 : WW8StructBase(rBase
, nOffset
, nCount
), mbPap(bPap
)
233 WW8PropertySetImpl::~WW8PropertySetImpl()
237 bool WW8PropertySetImpl::isPap() const
242 sal_uInt32
WW8PropertySetImpl::get_istd() const
244 sal_uInt32 nResult
= 0;
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();
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();
315 string
WW8PropertySetImpl::getType() const
317 return "WW8PropertySetImpl";
320 void WW8PropertySetImpl::resolveLocal(Sprm
& sprm
)
322 switch (sprm
.getId())
326 Value::Pointer_t pValue
= sprm
.getValue();
327 getDocument()->setPicLocation(pValue
->getInt());
328 getDocument()->setPicIsData(false);
333 getDocument()->setPicIsData(true);
340 void WW8PropertySetImpl::resolve(Properties
& rHandler
)
342 if (getCount() >= (isPap() ? 5U : 3U))
344 WW8PropertySetIterator::Pointer_t pIt
= begin();
345 WW8PropertySetIterator::Pointer_t pItEnd
= end();
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
);
366 WW8PropertySetIterator
& WW8PropertySetIteratorImpl::operator++ ()
368 WW8Property::Pointer_t pTmpAttr
= mpAttrSet
->getAttribute(mnOffset
);
370 mnOffset
+= dynamic_cast<WW8PropertyImpl
*>(pTmpAttr
.get())->
373 if (mnOffset
> mpAttrSet
->getCount() ||
374 mpAttrSet
->getCount() - mnOffset
< 3)
375 mnOffset
= mpAttrSet
->getCount();
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
400 snprintf(sBuffer
, sizeof(sBuffer
), "(%" SAL_PRIuUINT32
")", mnOffset
);