Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / lotuswordpro / source / filter / lwpoverride.cxx
blob5856a4c8db423fbf55c310f5c2dee8f1684e981f
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,
29 * MA 02111-1307 USA
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 /*************************************************************************
57 * @file
58 * For LWP filter architecture prototype
59 ************************************************************************/
61 #include <memory>
63 #include "clone.hxx"
64 #include "lwpoverride.hxx"
65 #include "lwpfilehdr.hxx"
66 #include "lwpatomholder.hxx"
67 #include "lwpborderstuff.hxx"
68 #include "lwpmargins.hxx"
69 #include "lwpbackgroundstuff.hxx"
71 /*class LwpOverride*/
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();
84 pStrm->SkipExtra();
87 void LwpOverride::Clear()
89 m_nValues = 0;
90 m_nOverride = 0;
91 m_nApply = 0;
94 void LwpOverride::Override(sal_uInt16 nBits, STATE eState)
96 if (eState == STATE_STYLE)
98 m_nValues &= ~nBits;
99 m_nOverride &= ~nBits;
101 else
103 m_nOverride |= nBits;
104 if (eState == STATE_ON)
106 m_nValues |= nBits;
108 else /* State == STATE_OFF */
110 m_nValues &= ~nBits;
113 m_nApply |= nBits;
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())
132 ReadCommon(pStrm);
133 m_nLanguage = pStrm->QuickReaduInt16();
136 pStrm->SkipExtra();
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())
157 ReadCommon(pStrm);
158 m_nHideLevels = pStrm->QuickReaduInt16();
160 if (LwpFileHeader::m_nFileRevision > 0x000A)
161 m_nBaseLineOffset = pStrm->QuickReaduInt32();
164 pStrm->SkipExtra();
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())
188 ReadCommon(pStrm);
189 m_nLevels = pStrm->QuickReaduInt16();
192 pStrm->SkipExtra();
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())
212 m_bIsNull= false;
213 ReadCommon(pStrm);
214 m_SilverBullet.ReadIndexed(pStrm);
216 else
217 m_bIsNull = true;
219 pStrm->SkipExtra();
221 void LwpBulletOverride::OverrideSkip(bool bOver)
223 if (bOver)
225 LwpOverride::Override(BO_SKIP, STATE_ON);
227 else
229 LwpOverride::Override(BO_SKIP, STATE_OFF);
233 void LwpBulletOverride::OverrideRightAligned(bool bOver)
235 if(bOver)
237 LwpOverride::Override(BO_RIGHTALIGN,STATE_ON);
239 else
241 LwpOverride::Override(BO_RIGHTALIGN,STATE_OFF);
245 void LwpBulletOverride::OverrideSilverBullet(LwpObjectID aID)
247 if (!aID.IsNull())
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);
263 else
265 pOther->RevertSilverBullet();
269 if (m_nApply & BO_SKIP)
271 if (IsSkipOverridden())
273 pOther->OverrideSkip(IsSkip());
275 else
277 pOther->RevertSkip();
281 if (m_nApply & BO_RIGHTALIGN)
283 if (IsRightAlignedOverridden())
285 pOther->OverrideRightAligned(IsRightAligned());
287 else
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())
313 ReadCommon(pStrm);
314 m_nAlignType = static_cast<AlignType>(pStrm->QuickReaduInt8());
315 m_nPosition = pStrm->QuickReaduInt32();
316 m_nAlignChar = pStrm->QuickReaduInt16();
319 pStrm->SkipExtra();
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())
340 ReadCommon(pStrm);
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();
348 pStrm->SkipExtra();
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()
362 if (m_pSpacing)
364 delete m_pSpacing;
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())
406 ReadCommon(pStrm);
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);
416 pStrm->SkipExtra();
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())
438 ReadCommon(pStrm);
440 m_nAll = pStrm->QuickReadInt32();
441 m_nFirst = pStrm->QuickReadInt32();
442 m_nRest = pStrm->QuickReadInt32();
443 m_nRight = pStrm->QuickReadInt32();
446 pStrm->SkipExtra();
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())
481 ReadCommon(pStrm);
482 m_pBackgroundStuff->Read(pStrm);
484 else
486 Clear();
489 if (pStrm->CheckExtra())
491 m_nType = pStrm->QuickReaduInt16();
492 pStrm->SkipExtra();
494 else
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)
510 m_nAlignType = 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)
535 return RELATIVE_ALL;
536 return RELATIVE_REST;
539 bool LwpIndentOverride::IsUseRelative()
541 return (m_nValues & IO_USE_RELATIVE) != 0;
544 void LwpIndentOverride::OverrideIndentAll(sal_Int32 val)
546 m_nAll = val;
547 m_nOverride |= IO_ALL;
550 void LwpIndentOverride::OverrideIndentFirst(sal_Int32 val)
552 m_nFirst = val;
553 m_nOverride |= IO_FIRST;
556 void LwpIndentOverride::OverrideIndentRight(sal_Int32 val)
558 m_nRight = val;
559 m_nOverride |= IO_RIGHT;
562 void LwpIndentOverride::OverrideIndentRest(sal_Int32 val)
564 m_nRest = val;
565 // m_nAll = val;
566 // m_nFirst = 0-val;
567 m_nOverride |= IO_REST;
570 void LwpIndentOverride::OverrideUseRelative(bool use)
572 if (use)
574 m_nOverride |= IO_USE_RELATIVE;
575 m_nValues |= IO_USE_RELATIVE;
577 else
579 m_nOverride &= ~IO_USE_RELATIVE;
580 m_nValues &= ~IO_USE_RELATIVE;
584 void LwpIndentOverride::OverrideRelative(sal_uInt16 relative)
586 sal_uInt16 Flag;
588 if (relative == RELATIVE_FIRST)
589 Flag = IO_REL_FIRST;
590 else if (relative == RELATIVE_ALL)
591 Flag = IO_REL_ALL;
592 else
593 Flag = IO_REL_REST;
595 m_nOverride &= ~IO_REL_FLAGS;
596 m_nOverride |= Flag;
599 void LwpSpacingOverride::Override(LwpSpacingOverride* other)
601 if (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)
628 m_nAmount = val;
629 m_nOverride |= SPO_AMOUNT;
632 void LwpSpacingCommonOverride::OverrideMultiple(sal_Int32 val)
634 m_nMultiple = val;
635 m_nOverride |= SPO_MULTIPLE;
638 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */