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 ************************************************************************/
64 #include "lwpoverride.hxx"
65 #include "lwpfilehdr.hxx"
66 #include "lwpatomholder.hxx"
67 #include "lwpborderstuff.hxx"
68 #include "lwpmargins.hxx"
69 #include "lwpbackgroundstuff.hxx"
72 LwpOverride::LwpOverride(LwpOverride
const& rOther
)
73 : m_nValues(rOther
.m_nValues
)
74 , m_nOverride(rOther
.m_nOverride
)
75 , m_nApply(rOther
.m_nApply
)
79 void LwpOverride::ReadCommon(LwpObjectStream
* pStrm
)
81 m_nValues
= pStrm
->QuickReaduInt16();
82 m_nOverride
= pStrm
->QuickReaduInt16();
83 m_nApply
= pStrm
->QuickReaduInt16();
87 void LwpOverride::Clear()
94 void LwpOverride::Override(sal_uInt16 nBits
, STATE eState
)
96 if (eState
== STATE_STYLE
)
99 m_nOverride
&= ~nBits
;
103 m_nOverride
|= nBits
;
104 if (eState
== STATE_ON
)
108 else /* State == STATE_OFF */
116 /*class LwpTextLanguageOverride*/
117 LwpTextLanguageOverride::LwpTextLanguageOverride(LwpTextLanguageOverride
const& rOther
)
118 : LwpOverride(rOther
)
119 , m_nLanguage(rOther
.m_nLanguage
)
123 LwpTextLanguageOverride
* LwpTextLanguageOverride::clone() const
125 return new LwpTextLanguageOverride(*this);
128 void LwpTextLanguageOverride::Read(LwpObjectStream
* pStrm
)
130 if (pStrm
->QuickReadBool())
133 m_nLanguage
= pStrm
->QuickReaduInt16();
140 /*class LwpTextAttributeOverride*/
141 LwpTextAttributeOverride::LwpTextAttributeOverride(LwpTextAttributeOverride
const& rOther
)
142 : LwpOverride(rOther
)
143 , m_nHideLevels(rOther
.m_nHideLevels
)
144 , m_nBaseLineOffset(rOther
.m_nBaseLineOffset
)
148 LwpTextAttributeOverride
* LwpTextAttributeOverride::clone() const
150 return new LwpTextAttributeOverride(*this);
153 void LwpTextAttributeOverride::Read(LwpObjectStream
* pStrm
)
155 if (pStrm
->QuickReadBool())
158 m_nHideLevels
= pStrm
->QuickReaduInt16();
160 if (LwpFileHeader::m_nFileRevision
> 0x000A)
161 m_nBaseLineOffset
= pStrm
->QuickReaduInt32();
167 bool LwpTextAttributeOverride::IsHighlight()
169 return (m_nValues
& TAO_HIGHLIGHT
) != 0;
172 /*class LwpKinsokuOptsOverride*/
173 LwpKinsokuOptsOverride::LwpKinsokuOptsOverride(LwpKinsokuOptsOverride
const& rOther
)
174 : LwpOverride(rOther
)
175 , m_nLevels(rOther
.m_nLevels
)
179 LwpKinsokuOptsOverride
* LwpKinsokuOptsOverride::clone() const
181 return new LwpKinsokuOptsOverride(*this);
184 void LwpKinsokuOptsOverride::Read(LwpObjectStream
* pStrm
)
186 if (pStrm
->QuickReadBool())
189 m_nLevels
= pStrm
->QuickReaduInt16();
195 /*class LwpBulletOverride*/
196 LwpBulletOverride::LwpBulletOverride(LwpBulletOverride
const& rOther
)
197 : LwpOverride(rOther
)
198 , m_SilverBullet(rOther
.m_SilverBullet
)
199 , m_bIsNull(rOther
.m_bIsNull
)
203 LwpBulletOverride
* LwpBulletOverride::clone() const
205 return new LwpBulletOverride(*this);
208 void LwpBulletOverride::Read(LwpObjectStream
* pStrm
)
210 if (pStrm
->QuickReadBool())
214 m_SilverBullet
.ReadIndexed(pStrm
);
221 void LwpBulletOverride::OverrideSkip(bool bOver
)
225 LwpOverride::Override(BO_SKIP
, STATE_ON
);
229 LwpOverride::Override(BO_SKIP
, STATE_OFF
);
233 void LwpBulletOverride::OverrideRightAligned(bool bOver
)
237 LwpOverride::Override(BO_RIGHTALIGN
,STATE_ON
);
241 LwpOverride::Override(BO_RIGHTALIGN
,STATE_OFF
);
245 void LwpBulletOverride::OverrideSilverBullet(LwpObjectID aID
)
249 m_SilverBullet
= aID
;
252 LwpOverride::Override(BO_SILVERBULLET
,STATE_ON
);
255 void LwpBulletOverride::Override(LwpBulletOverride
* pOther
)
257 if (m_nApply
& BO_SILVERBULLET
)
259 if (IsSilverBulletOverridden())
261 pOther
->OverrideSilverBullet(m_SilverBullet
);
265 pOther
->RevertSilverBullet();
269 if (m_nApply
& BO_SKIP
)
271 if (IsSkipOverridden())
273 pOther
->OverrideSkip(IsSkip());
277 pOther
->RevertSkip();
281 if (m_nApply
& BO_RIGHTALIGN
)
283 if (IsRightAlignedOverridden())
285 pOther
->OverrideRightAligned(IsRightAligned());
289 pOther
->RevertRightAligned();
295 /*class LwpAlignmentOverride*/
296 LwpAlignmentOverride::LwpAlignmentOverride(LwpAlignmentOverride
const& rOther
)
297 : LwpOverride(rOther
)
298 , m_nAlignType(rOther
.m_nAlignType
)
299 , m_nPosition(rOther
.m_nPosition
)
300 , m_nAlignChar(rOther
.m_nAlignChar
)
304 LwpAlignmentOverride
* LwpAlignmentOverride::clone() const
306 return new LwpAlignmentOverride(*this);
309 void LwpAlignmentOverride::Read(LwpObjectStream
* pStrm
)
311 if (pStrm
->QuickReadBool())
314 m_nAlignType
= static_cast<AlignType
>(pStrm
->QuickReaduInt8());
315 m_nPosition
= pStrm
->QuickReaduInt32();
316 m_nAlignChar
= pStrm
->QuickReaduInt16();
322 /*class LwpSpacingCommonOverride*/
323 LwpSpacingCommonOverride::LwpSpacingCommonOverride(LwpSpacingCommonOverride
const& rOther
)
324 : LwpOverride(rOther
)
325 , m_nSpacingType(rOther
.m_nSpacingType
)
326 , m_nAmount(rOther
.m_nAmount
)
327 , m_nMultiple(rOther
.m_nMultiple
)
331 LwpSpacingCommonOverride
* LwpSpacingCommonOverride::clone() const
333 return new LwpSpacingCommonOverride(*this);
336 void LwpSpacingCommonOverride::Read(LwpObjectStream
* pStrm
)
338 if (pStrm
->QuickReadBool())
341 const sal_uInt16 nSpacingType
= pStrm
->QuickReaduInt16();
342 //only the bottom pair of bits matter
343 m_nSpacingType
= static_cast<SpacingType
>(nSpacingType
& 0x3);
344 m_nAmount
= pStrm
->QuickReadInt32();
345 m_nMultiple
= pStrm
->QuickReadInt32();
351 /*class LwpSpacingOverride*/
352 LwpSpacingOverride::LwpSpacingOverride() :
353 m_pSpacing(new LwpSpacingCommonOverride
),
354 m_pAboveLineSpacing(new LwpSpacingCommonOverride
),
355 m_pParaSpacingAbove(new LwpSpacingCommonOverride
),
356 m_pParaSpacingBelow(new LwpSpacingCommonOverride
)
360 LwpSpacingOverride::~LwpSpacingOverride()
366 if (m_pAboveLineSpacing
)
368 delete m_pAboveLineSpacing
;
370 if (m_pParaSpacingAbove
)
372 delete m_pParaSpacingAbove
;
374 if (m_pParaSpacingBelow
)
376 delete m_pParaSpacingBelow
;
380 LwpSpacingOverride::LwpSpacingOverride(LwpSpacingOverride
const& rOther
)
381 : LwpOverride(rOther
)
382 , m_pSpacing(nullptr)
383 , m_pAboveLineSpacing(nullptr)
384 , m_pParaSpacingAbove(nullptr)
385 , m_pParaSpacingBelow(nullptr)
387 std::unique_ptr
<LwpSpacingCommonOverride
> pSpacing(::clone(rOther
.m_pSpacing
));
388 std::unique_ptr
<LwpSpacingCommonOverride
> pAboveLineSpacing(::clone(rOther
.m_pAboveLineSpacing
));
389 std::unique_ptr
<LwpSpacingCommonOverride
> pParaSpacingAbove(::clone(rOther
.m_pParaSpacingAbove
));
390 std::unique_ptr
<LwpSpacingCommonOverride
> pParaSpacingBelow(::clone(rOther
.m_pParaSpacingBelow
));
391 m_pSpacing
= pSpacing
.release();
392 m_pAboveLineSpacing
= pAboveLineSpacing
.release();
393 m_pParaSpacingAbove
= pParaSpacingAbove
.release();
394 m_pParaSpacingBelow
= pParaSpacingBelow
.release();
397 LwpSpacingOverride
* LwpSpacingOverride::clone() const
399 return new LwpSpacingOverride(*this);
402 void LwpSpacingOverride::Read(LwpObjectStream
* pStrm
)
404 if (pStrm
->QuickReadBool())
407 m_pSpacing
->Read(pStrm
);
408 if (LwpFileHeader::m_nFileRevision
>= 0x000d)
410 m_pAboveLineSpacing
->Read(pStrm
);
412 m_pParaSpacingAbove
->Read(pStrm
);
413 m_pParaSpacingBelow
->Read(pStrm
);
419 /*class LwpIndentOverride*/
420 LwpIndentOverride::LwpIndentOverride(LwpIndentOverride
const& rOther
)
421 : LwpOverride(rOther
)
422 , m_nAll(rOther
.m_nAll
)
423 , m_nFirst(rOther
.m_nFirst
)
424 , m_nRest(rOther
.m_nRest
)
425 , m_nRight(rOther
.m_nRight
)
429 LwpIndentOverride
* LwpIndentOverride::clone() const
431 return new LwpIndentOverride(*this);
434 void LwpIndentOverride::Read(LwpObjectStream
* pStrm
)
436 if (pStrm
->QuickReadBool())
440 m_nAll
= pStrm
->QuickReadInt32();
441 m_nFirst
= pStrm
->QuickReadInt32();
442 m_nRest
= pStrm
->QuickReadInt32();
443 m_nRight
= pStrm
->QuickReadInt32();
449 /*class LwpAmikakeOverride*/
450 LwpAmikakeOverride::LwpAmikakeOverride() :
451 m_pBackgroundStuff(new LwpBackgroundStuff
), m_nType(AMIKAKE_NONE
)
455 LwpAmikakeOverride::~LwpAmikakeOverride()
457 if (m_pBackgroundStuff
)
459 delete m_pBackgroundStuff
;
463 LwpAmikakeOverride::LwpAmikakeOverride(LwpAmikakeOverride
const& rOther
)
464 : LwpOverride(rOther
)
465 , m_pBackgroundStuff(nullptr)
466 , m_nType(rOther
.m_nType
)
468 std::unique_ptr
<LwpBackgroundStuff
> pBackgroundStuff(::clone(rOther
.m_pBackgroundStuff
));
469 m_pBackgroundStuff
= pBackgroundStuff
.release();
472 LwpAmikakeOverride
* LwpAmikakeOverride::clone() const
474 return new LwpAmikakeOverride(*this);
477 void LwpAmikakeOverride::Read(LwpObjectStream
* pStrm
)
479 if (pStrm
->QuickReadBool())
482 m_pBackgroundStuff
->Read(pStrm
);
489 if (pStrm
->CheckExtra())
491 m_nType
= pStrm
->QuickReaduInt16();
496 m_nType
= AMIKAKE_NONE
;
500 void LwpAlignmentOverride::Override(LwpAlignmentOverride
* other
)
502 if (m_nOverride
& AO_TYPE
)
504 other
->OverrideAlignment(m_nAlignType
);
508 void LwpAlignmentOverride::OverrideAlignment(AlignType val
)
511 m_nOverride
|= AO_TYPE
;
514 void LwpIndentOverride::Override(LwpIndentOverride
* other
)
516 if(m_nOverride
& IO_ALL
)
517 other
->OverrideIndentAll(m_nAll
);
518 if(m_nOverride
& IO_FIRST
)
519 other
->OverrideIndentFirst(m_nFirst
);
520 if(m_nOverride
& IO_RIGHT
)
521 other
->OverrideIndentRight(m_nRight
);
522 if(m_nOverride
& IO_REST
)
523 other
->OverrideIndentRest(m_nRest
);
524 if(m_nOverride
& IO_USE_RELATIVE
)
525 other
->OverrideUseRelative(IsUseRelative());
526 if (m_nOverride
& IO_REL_FLAGS
)
527 other
->OverrideRelative(GetRelative());
530 sal_uInt16
LwpIndentOverride::GetRelative()
532 if ((m_nOverride
& IO_REL_FLAGS
) == IO_REL_FIRST
)
533 return RELATIVE_FIRST
;
534 else if ((m_nOverride
& IO_REL_FLAGS
) == IO_REL_ALL
)
536 return RELATIVE_REST
;
539 bool LwpIndentOverride::IsUseRelative()
541 return (m_nValues
& IO_USE_RELATIVE
) != 0;
544 void LwpIndentOverride::OverrideIndentAll(sal_Int32 val
)
547 m_nOverride
|= IO_ALL
;
550 void LwpIndentOverride::OverrideIndentFirst(sal_Int32 val
)
553 m_nOverride
|= IO_FIRST
;
556 void LwpIndentOverride::OverrideIndentRight(sal_Int32 val
)
559 m_nOverride
|= IO_RIGHT
;
562 void LwpIndentOverride::OverrideIndentRest(sal_Int32 val
)
567 m_nOverride
|= IO_REST
;
570 void LwpIndentOverride::OverrideUseRelative(bool use
)
574 m_nOverride
|= IO_USE_RELATIVE
;
575 m_nValues
|= IO_USE_RELATIVE
;
579 m_nOverride
&= ~IO_USE_RELATIVE
;
580 m_nValues
&= ~IO_USE_RELATIVE
;
584 void LwpIndentOverride::OverrideRelative(sal_uInt16 relative
)
588 if (relative
== RELATIVE_FIRST
)
590 else if (relative
== RELATIVE_ALL
)
595 m_nOverride
&= ~IO_REL_FLAGS
;
599 void LwpSpacingOverride::Override(LwpSpacingOverride
* other
)
603 m_pSpacing
->Override(other
->GetSpacing());
604 m_pAboveLineSpacing
->Override(other
->GetAboveLineSpacing());
605 m_pParaSpacingAbove
->Override(other
->GetAboveSpacing());
606 m_pParaSpacingBelow
->Override(other
->GetBelowSpacing());
610 void LwpSpacingCommonOverride::Override(LwpSpacingCommonOverride
* other
)
612 if (m_nOverride
& SPO_TYPE
)
613 other
->OverrideType(m_nSpacingType
);
614 if (m_nOverride
& SPO_AMOUNT
)
615 other
->OverrideAmount(m_nAmount
);
616 if (m_nOverride
& SPO_MULTIPLE
)
617 other
->OverrideMultiple(m_nMultiple
);
620 void LwpSpacingCommonOverride::OverrideType(SpacingType val
)
622 m_nSpacingType
= val
;
623 m_nOverride
|= SPO_TYPE
;
626 void LwpSpacingCommonOverride::OverrideAmount(sal_Int32 val
)
629 m_nOverride
|= SPO_AMOUNT
;
632 void LwpSpacingCommonOverride::OverrideMultiple(sal_Int32 val
)
635 m_nOverride
|= SPO_MULTIPLE
;
638 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */