tdf#163948: fix crash when NotesPane is enabled on Tabbed UI
[LibreOffice.git] / lotuswordpro / source / filter / lwpoverride.cxx
blob928d642d61b098ed7e9264a2edb9882f4a5eaa09
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 <sal/log.hxx>
62 #include <memory>
64 #include "clone.hxx"
65 #include <lwpoverride.hxx>
66 #include <lwpfilehdr.hxx>
67 #include "lwpbackgroundstuff.hxx"
69 /*class LwpOverride*/
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();
82 pStrm->SkipExtra();
85 void LwpOverride::Clear()
87 m_nValues = 0;
88 m_nOverride = 0;
89 m_nApply = 0;
92 void LwpOverride::Override(sal_uInt16 nBits, STATE eState)
94 if (eState == STATE_STYLE)
96 m_nValues &= ~nBits;
97 m_nOverride &= ~nBits;
99 else
101 m_nOverride |= nBits;
102 if (eState == STATE_ON)
104 m_nValues |= nBits;
106 else /* State == STATE_OFF */
108 m_nValues &= ~nBits;
111 m_nApply |= nBits;
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())
130 ReadCommon(pStrm);
131 m_nLanguage = pStrm->QuickReaduInt16();
134 pStrm->SkipExtra();
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())
154 ReadCommon(pStrm);
155 m_nHideLevels = pStrm->QuickReaduInt16();
157 if (LwpFileHeader::m_nFileRevision > 0x000A)
158 m_nBaseLineOffset = pStrm->QuickReaduInt32();
161 pStrm->SkipExtra();
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())
182 ReadCommon(pStrm);
183 m_nLevels = pStrm->QuickReaduInt16();
186 pStrm->SkipExtra();
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())
203 m_bIsNull = false;
204 ReadCommon(pStrm);
205 m_SilverBullet.ReadIndexed(pStrm);
207 else
208 m_bIsNull = true;
210 pStrm->SkipExtra();
212 void LwpBulletOverride::OverrideSkip(bool bOver)
214 if (bOver)
216 LwpOverride::Override(BO_SKIP, STATE_ON);
218 else
220 LwpOverride::Override(BO_SKIP, STATE_OFF);
224 void LwpBulletOverride::OverrideRightAligned(bool bOver)
226 if (bOver)
228 LwpOverride::Override(BO_RIGHTALIGN, STATE_ON);
230 else
232 LwpOverride::Override(BO_RIGHTALIGN, STATE_OFF);
236 void LwpBulletOverride::OverrideSilverBullet(LwpObjectID aID)
238 if (!aID.IsNull())
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);
254 else
256 pOther->RevertSilverBullet();
260 if (m_nApply & BO_SKIP)
262 if (IsSkipOverridden())
264 pOther->OverrideSkip(IsSkip());
266 else
268 pOther->RevertSkip();
272 if (m_nApply & BO_RIGHTALIGN)
274 if (IsRightAlignedOverridden())
276 pOther->OverrideRightAligned(IsRightAligned());
278 else
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())
303 ReadCommon(pStrm);
304 sal_uInt8 nAlignType = pStrm->QuickReaduInt8();
305 if (nAlignType <= ALIGN_SQUEEZE)
306 m_nAlignType = static_cast<AlignType>(nAlignType);
307 else
308 SAL_WARN("lwp", "unknown align type:" << nAlignType);
309 m_nPosition = pStrm->QuickReaduInt32();
310 m_nAlignChar = pStrm->QuickReaduInt16();
313 pStrm->SkipExtra();
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())
334 ReadCommon(pStrm);
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();
342 pStrm->SkipExtra();
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())
371 ReadCommon(pStrm);
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);
381 pStrm->SkipExtra();
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())
400 ReadCommon(pStrm);
402 m_nAll = pStrm->QuickReadInt32();
403 m_nFirst = pStrm->QuickReadInt32();
404 m_nRest = pStrm->QuickReadInt32();
405 m_nRight = pStrm->QuickReadInt32();
408 pStrm->SkipExtra();
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())
433 ReadCommon(pStrm);
434 m_pBackgroundStuff->Read(pStrm);
436 else
438 Clear();
441 if (pStrm->CheckExtra())
443 m_nType = pStrm->QuickReaduInt16();
444 pStrm->SkipExtra();
446 else
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)
462 m_nAlignType = 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)
487 return RELATIVE_ALL;
488 return RELATIVE_REST;
491 bool LwpIndentOverride::IsUseRelative() const { return (m_nValues & IO_USE_RELATIVE) != 0; }
493 void LwpIndentOverride::OverrideIndentAll(sal_Int32 val)
495 m_nAll = val;
496 m_nOverride |= IO_ALL;
499 void LwpIndentOverride::OverrideIndentFirst(sal_Int32 val)
501 m_nFirst = val;
502 m_nOverride |= IO_FIRST;
505 void LwpIndentOverride::OverrideIndentRight(sal_Int32 val)
507 m_nRight = val;
508 m_nOverride |= IO_RIGHT;
511 void LwpIndentOverride::OverrideIndentRest(sal_Int32 val)
513 m_nRest = val;
514 // m_nAll = val;
515 // m_nFirst = 0-val;
516 m_nOverride |= IO_REST;
519 void LwpIndentOverride::OverrideUseRelative(bool use)
521 if (use)
523 m_nOverride |= IO_USE_RELATIVE;
524 m_nValues |= IO_USE_RELATIVE;
526 else
528 m_nOverride &= ~IO_USE_RELATIVE;
529 m_nValues &= ~IO_USE_RELATIVE;
533 void LwpIndentOverride::OverrideRelative(sal_uInt16 relative)
535 sal_uInt16 Flag;
537 if (relative == RELATIVE_FIRST)
538 Flag = IO_REL_FIRST;
539 else if (relative == RELATIVE_ALL)
540 Flag = IO_REL_ALL;
541 else
542 Flag = IO_REL_REST;
544 m_nOverride &= ~IO_REL_FLAGS;
545 m_nOverride |= Flag;
548 void LwpSpacingOverride::Override(LwpSpacingOverride* other)
550 if (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)
577 m_nAmount = val;
578 m_nOverride |= SPO_AMOUNT;
581 void LwpSpacingCommonOverride::OverrideMultiple(sal_Int32 val)
583 m_nMultiple = val;
584 m_nOverride |= SPO_MULTIPLE;
587 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */