1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * The Contents of this file are made available subject to the terms of
5 * either of the following licenses
7 * - GNU Lesser General Public License Version 2.1
8 * - Sun Industry Standards Source License Version 1.1
10 * Sun Microsystems Inc., October, 2000
12 * GNU Lesser General Public License Version 2.1
13 * =============================================
14 * Copyright 2000 by Sun Microsystems, Inc.
15 * 901 San Antonio Road, Palo Alto, CA 94303, USA
17 * This library is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU Lesser General Public
19 * License version 2.1, as published by the Free Software Foundation.
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * Lesser General Public License for more details.
26 * You should have received a copy of the GNU Lesser General Public
27 * License along with this library; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 * Sun Industry Standards Source License Version 1.1
33 * =================================================
34 * The contents of this file are subject to the Sun Industry Standards
35 * Source License Version 1.1 (the "License"); You may not use this file
36 * except in compliance with the License. You may obtain a copy of the
37 * License at http://www.openoffice.org/license.html.
39 * Software provided under this License is provided on an "AS IS" basis,
40 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
41 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
42 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
43 * See the License for the specific provisions governing your rights and
44 * obligations concerning the Software.
46 * The Initial Developer of the Original Code is: IBM Corporation
48 * Copyright: 2008 by IBM Corporation
50 * All Rights Reserved.
52 * Contributor(s): _______________________________________
55 ************************************************************************/
56 /*************************************************************************
58 * For LWP filter architecture prototype
59 ************************************************************************/
61 #include <sal/log.hxx>
65 #include <lwpoverride.hxx>
66 #include <lwpfilehdr.hxx>
67 #include "lwpbackgroundstuff.hxx"
70 LwpOverride::LwpOverride(LwpOverride
const& rOther
)
71 : m_nValues(rOther
.m_nValues
)
72 , m_nOverride(rOther
.m_nOverride
)
73 , m_nApply(rOther
.m_nApply
)
77 void LwpOverride::ReadCommon(LwpObjectStream
* pStrm
)
79 m_nValues
= pStrm
->QuickReaduInt16();
80 m_nOverride
= pStrm
->QuickReaduInt16();
81 m_nApply
= pStrm
->QuickReaduInt16();
85 void LwpOverride::Clear()
92 void LwpOverride::Override(sal_uInt16 nBits
, STATE eState
)
94 if (eState
== STATE_STYLE
)
97 m_nOverride
&= ~nBits
;
101 m_nOverride
|= nBits
;
102 if (eState
== STATE_ON
)
106 else /* State == STATE_OFF */
114 /*class LwpTextLanguageOverride*/
115 LwpTextLanguageOverride::LwpTextLanguageOverride(LwpTextLanguageOverride
const& rOther
)
116 : LwpOverride(rOther
)
117 , m_nLanguage(rOther
.m_nLanguage
)
121 LwpTextLanguageOverride
* LwpTextLanguageOverride::clone() const
123 return new LwpTextLanguageOverride(*this);
126 void LwpTextLanguageOverride::Read(LwpObjectStream
* pStrm
)
128 if (pStrm
->QuickReadBool())
131 m_nLanguage
= pStrm
->QuickReaduInt16();
137 /*class LwpTextAttributeOverride*/
138 LwpTextAttributeOverride::LwpTextAttributeOverride(LwpTextAttributeOverride
const& rOther
)
139 : LwpOverride(rOther
)
140 , m_nHideLevels(rOther
.m_nHideLevels
)
141 , m_nBaseLineOffset(rOther
.m_nBaseLineOffset
)
145 LwpTextAttributeOverride
* LwpTextAttributeOverride::clone() const
147 return new LwpTextAttributeOverride(*this);
150 void LwpTextAttributeOverride::Read(LwpObjectStream
* pStrm
)
152 if (pStrm
->QuickReadBool())
155 m_nHideLevels
= pStrm
->QuickReaduInt16();
157 if (LwpFileHeader::m_nFileRevision
> 0x000A)
158 m_nBaseLineOffset
= pStrm
->QuickReaduInt32();
164 bool LwpTextAttributeOverride::IsHighlight() const { return (m_nValues
& TAO_HIGHLIGHT
) != 0; }
166 /*class LwpKinsokuOptsOverride*/
167 LwpKinsokuOptsOverride::LwpKinsokuOptsOverride(LwpKinsokuOptsOverride
const& rOther
)
168 : LwpOverride(rOther
)
169 , m_nLevels(rOther
.m_nLevels
)
173 LwpKinsokuOptsOverride
* LwpKinsokuOptsOverride::clone() const
175 return new LwpKinsokuOptsOverride(*this);
178 void LwpKinsokuOptsOverride::Read(LwpObjectStream
* pStrm
)
180 if (pStrm
->QuickReadBool())
183 m_nLevels
= pStrm
->QuickReaduInt16();
189 /*class LwpBulletOverride*/
190 LwpBulletOverride::LwpBulletOverride(LwpBulletOverride
const& rOther
)
191 : LwpOverride(rOther
)
192 , m_SilverBullet(rOther
.m_SilverBullet
)
193 , m_bIsNull(rOther
.m_bIsNull
)
197 LwpBulletOverride
* LwpBulletOverride::clone() const { return new LwpBulletOverride(*this); }
199 void LwpBulletOverride::Read(LwpObjectStream
* pStrm
)
201 if (pStrm
->QuickReadBool())
205 m_SilverBullet
.ReadIndexed(pStrm
);
212 void LwpBulletOverride::OverrideSkip(bool bOver
)
216 LwpOverride::Override(BO_SKIP
, STATE_ON
);
220 LwpOverride::Override(BO_SKIP
, STATE_OFF
);
224 void LwpBulletOverride::OverrideRightAligned(bool bOver
)
228 LwpOverride::Override(BO_RIGHTALIGN
, STATE_ON
);
232 LwpOverride::Override(BO_RIGHTALIGN
, STATE_OFF
);
236 void LwpBulletOverride::OverrideSilverBullet(LwpObjectID aID
)
240 m_SilverBullet
= aID
;
243 LwpOverride::Override(BO_SILVERBULLET
, STATE_ON
);
246 void LwpBulletOverride::Override(LwpBulletOverride
* pOther
)
248 if (m_nApply
& BO_SILVERBULLET
)
250 if (IsSilverBulletOverridden())
252 pOther
->OverrideSilverBullet(m_SilverBullet
);
256 pOther
->RevertSilverBullet();
260 if (m_nApply
& BO_SKIP
)
262 if (IsSkipOverridden())
264 pOther
->OverrideSkip(IsSkip());
268 pOther
->RevertSkip();
272 if (m_nApply
& BO_RIGHTALIGN
)
274 if (IsRightAlignedOverridden())
276 pOther
->OverrideRightAligned(IsRightAligned());
280 pOther
->RevertRightAligned();
285 /*class LwpAlignmentOverride*/
286 LwpAlignmentOverride::LwpAlignmentOverride(LwpAlignmentOverride
const& rOther
)
287 : LwpOverride(rOther
)
288 , m_nAlignType(rOther
.m_nAlignType
)
289 , m_nPosition(rOther
.m_nPosition
)
290 , m_nAlignChar(rOther
.m_nAlignChar
)
294 LwpAlignmentOverride
* LwpAlignmentOverride::clone() const
296 return new LwpAlignmentOverride(*this);
299 void LwpAlignmentOverride::Read(LwpObjectStream
* pStrm
)
301 if (pStrm
->QuickReadBool())
304 sal_uInt8 nAlignType
= pStrm
->QuickReaduInt8();
305 if (nAlignType
<= ALIGN_SQUEEZE
)
306 m_nAlignType
= static_cast<AlignType
>(nAlignType
);
308 SAL_WARN("lwp", "unknown align type:" << nAlignType
);
309 m_nPosition
= pStrm
->QuickReaduInt32();
310 m_nAlignChar
= pStrm
->QuickReaduInt16();
316 /*class LwpSpacingCommonOverride*/
317 LwpSpacingCommonOverride::LwpSpacingCommonOverride(LwpSpacingCommonOverride
const& rOther
)
318 : LwpOverride(rOther
)
319 , m_nSpacingType(rOther
.m_nSpacingType
)
320 , m_nAmount(rOther
.m_nAmount
)
321 , m_nMultiple(rOther
.m_nMultiple
)
325 LwpSpacingCommonOverride
* LwpSpacingCommonOverride::clone() const
327 return new LwpSpacingCommonOverride(*this);
330 void LwpSpacingCommonOverride::Read(LwpObjectStream
* pStrm
)
332 if (pStrm
->QuickReadBool())
335 const sal_uInt16 nSpacingType
= pStrm
->QuickReaduInt16();
336 //only the bottom pair of bits matter
337 m_nSpacingType
= static_cast<SpacingType
>(nSpacingType
& 0x3);
338 m_nAmount
= pStrm
->QuickReadInt32();
339 m_nMultiple
= pStrm
->QuickReadInt32();
345 /*class LwpSpacingOverride*/
346 LwpSpacingOverride::LwpSpacingOverride()
347 : m_pSpacing(new LwpSpacingCommonOverride
)
348 , m_pAboveLineSpacing(new LwpSpacingCommonOverride
)
349 , m_pParaSpacingAbove(new LwpSpacingCommonOverride
)
350 , m_pParaSpacingBelow(new LwpSpacingCommonOverride
)
354 LwpSpacingOverride::~LwpSpacingOverride() {}
356 LwpSpacingOverride::LwpSpacingOverride(LwpSpacingOverride
const& rOther
)
357 : LwpOverride(rOther
)
359 m_pSpacing
.reset(::clone(rOther
.m_pSpacing
.get()));
360 m_pAboveLineSpacing
.reset(::clone(rOther
.m_pAboveLineSpacing
.get()));
361 m_pParaSpacingAbove
.reset(::clone(rOther
.m_pParaSpacingAbove
.get()));
362 m_pParaSpacingBelow
.reset(::clone(rOther
.m_pParaSpacingBelow
.get()));
365 LwpSpacingOverride
* LwpSpacingOverride::clone() const { return new LwpSpacingOverride(*this); }
367 void LwpSpacingOverride::Read(LwpObjectStream
* pStrm
)
369 if (pStrm
->QuickReadBool())
372 m_pSpacing
->Read(pStrm
);
373 if (LwpFileHeader::m_nFileRevision
>= 0x000d)
375 m_pAboveLineSpacing
->Read(pStrm
);
377 m_pParaSpacingAbove
->Read(pStrm
);
378 m_pParaSpacingBelow
->Read(pStrm
);
384 /*class LwpIndentOverride*/
385 LwpIndentOverride::LwpIndentOverride(LwpIndentOverride
const& rOther
)
386 : LwpOverride(rOther
)
387 , m_nAll(rOther
.m_nAll
)
388 , m_nFirst(rOther
.m_nFirst
)
389 , m_nRest(rOther
.m_nRest
)
390 , m_nRight(rOther
.m_nRight
)
394 LwpIndentOverride
* LwpIndentOverride::clone() const { return new LwpIndentOverride(*this); }
396 void LwpIndentOverride::Read(LwpObjectStream
* pStrm
)
398 if (pStrm
->QuickReadBool())
402 m_nAll
= pStrm
->QuickReadInt32();
403 m_nFirst
= pStrm
->QuickReadInt32();
404 m_nRest
= pStrm
->QuickReadInt32();
405 m_nRight
= pStrm
->QuickReadInt32();
411 /*class LwpAmikakeOverride*/
412 LwpAmikakeOverride::LwpAmikakeOverride()
413 : m_pBackgroundStuff(new LwpBackgroundStuff
)
414 , m_nType(AMIKAKE_NONE
)
418 LwpAmikakeOverride::~LwpAmikakeOverride() {}
420 LwpAmikakeOverride::LwpAmikakeOverride(LwpAmikakeOverride
const& rOther
)
421 : LwpOverride(rOther
)
422 , m_pBackgroundStuff(::clone(rOther
.m_pBackgroundStuff
.get()))
423 , m_nType(rOther
.m_nType
)
427 LwpAmikakeOverride
* LwpAmikakeOverride::clone() const { return new LwpAmikakeOverride(*this); }
429 void LwpAmikakeOverride::Read(LwpObjectStream
* pStrm
)
431 if (pStrm
->QuickReadBool())
434 m_pBackgroundStuff
->Read(pStrm
);
441 if (pStrm
->CheckExtra())
443 m_nType
= pStrm
->QuickReaduInt16();
448 m_nType
= AMIKAKE_NONE
;
452 void LwpAlignmentOverride::Override(LwpAlignmentOverride
* other
)
454 if (m_nOverride
& AO_TYPE
)
456 other
->OverrideAlignment(m_nAlignType
);
460 void LwpAlignmentOverride::OverrideAlignment(AlignType val
)
463 m_nOverride
|= AO_TYPE
;
466 void LwpIndentOverride::Override(LwpIndentOverride
* other
)
468 if (m_nOverride
& IO_ALL
)
469 other
->OverrideIndentAll(m_nAll
);
470 if (m_nOverride
& IO_FIRST
)
471 other
->OverrideIndentFirst(m_nFirst
);
472 if (m_nOverride
& IO_RIGHT
)
473 other
->OverrideIndentRight(m_nRight
);
474 if (m_nOverride
& IO_REST
)
475 other
->OverrideIndentRest(m_nRest
);
476 if (m_nOverride
& IO_USE_RELATIVE
)
477 other
->OverrideUseRelative(IsUseRelative());
478 if (m_nOverride
& IO_REL_FLAGS
)
479 other
->OverrideRelative(GetRelative());
482 sal_uInt16
LwpIndentOverride::GetRelative() const
484 if ((m_nOverride
& IO_REL_FLAGS
) == IO_REL_FIRST
)
485 return RELATIVE_FIRST
;
486 else if ((m_nOverride
& IO_REL_FLAGS
) == IO_REL_ALL
)
488 return RELATIVE_REST
;
491 bool LwpIndentOverride::IsUseRelative() const { return (m_nValues
& IO_USE_RELATIVE
) != 0; }
493 void LwpIndentOverride::OverrideIndentAll(sal_Int32 val
)
496 m_nOverride
|= IO_ALL
;
499 void LwpIndentOverride::OverrideIndentFirst(sal_Int32 val
)
502 m_nOverride
|= IO_FIRST
;
505 void LwpIndentOverride::OverrideIndentRight(sal_Int32 val
)
508 m_nOverride
|= IO_RIGHT
;
511 void LwpIndentOverride::OverrideIndentRest(sal_Int32 val
)
516 m_nOverride
|= IO_REST
;
519 void LwpIndentOverride::OverrideUseRelative(bool use
)
523 m_nOverride
|= IO_USE_RELATIVE
;
524 m_nValues
|= IO_USE_RELATIVE
;
528 m_nOverride
&= ~IO_USE_RELATIVE
;
529 m_nValues
&= ~IO_USE_RELATIVE
;
533 void LwpIndentOverride::OverrideRelative(sal_uInt16 relative
)
537 if (relative
== RELATIVE_FIRST
)
539 else if (relative
== RELATIVE_ALL
)
544 m_nOverride
&= ~IO_REL_FLAGS
;
548 void LwpSpacingOverride::Override(LwpSpacingOverride
* other
)
552 m_pSpacing
->Override(other
->GetSpacing());
553 m_pAboveLineSpacing
->Override(other
->GetAboveLineSpacing());
554 m_pParaSpacingAbove
->Override(other
->GetAboveSpacing());
555 m_pParaSpacingBelow
->Override(other
->GetBelowSpacing());
559 void LwpSpacingCommonOverride::Override(LwpSpacingCommonOverride
* other
)
561 if (m_nOverride
& SPO_TYPE
)
562 other
->OverrideType(m_nSpacingType
);
563 if (m_nOverride
& SPO_AMOUNT
)
564 other
->OverrideAmount(m_nAmount
);
565 if (m_nOverride
& SPO_MULTIPLE
)
566 other
->OverrideMultiple(m_nMultiple
);
569 void LwpSpacingCommonOverride::OverrideType(SpacingType val
)
571 m_nSpacingType
= val
;
572 m_nOverride
|= SPO_TYPE
;
575 void LwpSpacingCommonOverride::OverrideAmount(sal_Int32 val
)
578 m_nOverride
|= SPO_AMOUNT
;
581 void LwpSpacingCommonOverride::OverrideMultiple(sal_Int32 val
)
584 m_nOverride
|= SPO_MULTIPLE
;
587 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */