android: Update app-specific/MIME type icons
[LibreOffice.git] / lotuswordpro / source / filter / lwplayout.cxx
blob895137e282f2d072da023895f89232ff8d42f1e9
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>
62 #include "lwplayout.hxx"
63 #include "lwpusewhen.hxx"
64 #include <lwptools.hxx>
65 #include "lwplaypiece.hxx"
66 #include <xfilter/xfcolumns.hxx>
67 #include "lwpstory.hxx"
68 #include "lwpparastyle.hxx"
69 #include "lwpholder.hxx"
70 #include "lwpdoc.hxx"
71 #include "lwpgrfobj.hxx"
72 #include <lwpfilehdr.hxx>
73 #include <osl/thread.h>
74 #include <sal/log.hxx>
75 #include <o3tl/sorted_vector.hxx>
77 LwpVirtualLayout::LwpVirtualLayout(LwpObjectHeader const& objHdr, LwpSvStream* pStrm)
78 : LwpDLNFPVList(objHdr, pStrm)
79 , m_bGettingHonorProtection(false)
80 , m_bGettingMarginsSameAsParent(false)
81 , m_bGettingHasProtection(false)
82 , m_bGettingIsProtected(false)
83 , m_bGettingIsAutoGrowDown(false)
84 , m_bGettingMarginsValue(false)
85 , m_bGettingExtMarginsValue(false)
86 , m_bGettingUsePrinterSettings(false)
87 , m_bGettingScaleCenter(false)
88 , m_bGettingBorderStuff(false)
89 , m_bGettingUseWhen(false)
90 , m_bGettingStyleLayout(false)
91 , m_bGettingAutoGrowUp(false)
92 , m_nAttributes(0)
93 , m_nAttributes2(0)
94 , m_nAttributes3(0)
95 , m_nOverrideFlag(0)
96 , m_nDirection(0)
97 , m_nEditorID(0)
101 void LwpVirtualLayout::Read()
103 LwpDLNFPVList::Read();
105 LwpObjectStream* pStrm = m_pObjStrm.get();
106 m_nAttributes = pStrm->QuickReaduInt32();
107 m_nAttributes2 = pStrm->QuickReaduInt32();
108 m_nAttributes3 = pStrm->QuickReaduInt32();
109 m_nOverrideFlag = pStrm->QuickReaduInt32();
110 m_nDirection = pStrm->QuickReaduInt16();
112 //Note that two bytes is read into m_nEditorID instead of one byte.
113 m_nEditorID = pStrm->QuickReaduInt16();
115 m_NextEnumerated.ReadIndexed(pStrm);
116 m_PreviousEnumerated.ReadIndexed(pStrm);
118 pStrm->SkipExtra();
121 bool LwpVirtualLayout::MarginsSameAsParent()
123 return (m_nAttributes2 & STYLE2_MARGINSSAMEASPARENT) != 0;
127 * @descr: Get the gap between columns
130 double LwpVirtualLayout::GetColGap(sal_uInt16 /*nIndex*/)
132 //return DEFAULTGAPSIZE;
133 //return LwpTools::ConvertToMetric(0.17);//DEFAULTGAPSIZE=0.17
134 return LwpTools::ConvertToMetric(0.17);
138 * @descr: Whether it is honoring protection
141 bool LwpVirtualLayout::HonorProtection()
143 if (!(m_nAttributes2 & STYLE2_HONORPROTECTION))
144 return false;
146 rtl::Reference<LwpVirtualLayout> xParent(
147 dynamic_cast<LwpVirtualLayout*>(GetParent().obj().get()));
148 if (xParent.is() && !xParent->IsHeader())
150 return xParent->GetHonorProtection();
153 if (m_pFoundry) //is null now
155 LwpDocument* pDoc = m_pFoundry->GetDocument();
156 if (pDoc && pDoc->GetRootDocument())
157 return pDoc->GetRootDocument()->GetHonorProtection();
160 return true;
164 * @descr: Whether it is protected
167 bool LwpVirtualLayout::IsProtected()
169 bool bProtected = (m_nAttributes & STYLE_PROTECTED) != 0;
171 rtl::Reference<LwpVirtualLayout> xParent(
172 dynamic_cast<LwpVirtualLayout*>(GetParent().obj().get()));
173 if (xParent.is() && !xParent->IsHeader())
175 if (xParent->GetHonorProtection() && (xParent->GetHasProtection() || bProtected))
177 return true;
180 else if (m_pFoundry) //is null now
182 LwpDocument* pDoc = m_pFoundry->GetDocument();
183 if (pDoc)
185 if (pDoc->GetHonorProtection() && bProtected)
187 return true;
192 return false;
196 * @descr: Whether it has protection
199 bool LwpVirtualLayout::HasProtection()
201 if (m_nAttributes & STYLE_PROTECTED)
202 return true;
204 rtl::Reference<LwpVirtualLayout> xParent(
205 dynamic_cast<LwpVirtualLayout*>(GetParent().obj().get()));
206 if (xParent.is() && !xParent->IsHeader())
208 return xParent->GetHasProtection();
211 return false;
215 * @descr: Whether it is a mirror layout
218 bool LwpVirtualLayout::IsComplex() const { return (m_nAttributes & STYLE_COMPLEX) != 0; }
221 * @descr: Get usewhen pointer
224 LwpUseWhen* LwpVirtualLayout::GetUseWhen()
226 if (m_bGettingUseWhen)
227 throw std::runtime_error("recursion in layout");
228 m_bGettingUseWhen = true;
230 LwpUseWhen* pRet = nullptr;
233 If we have a parent, and I'm not a page layout,
234 use my parents information.
236 if (GetLayoutType() != LWP_PAGE_LAYOUT)
238 //get parent
239 rtl::Reference<LwpVirtualLayout> xParent(
240 dynamic_cast<LwpVirtualLayout*>(GetParent().obj().get()));
241 if (xParent.is() && !xParent->IsHeader() && (xParent->GetLayoutType() != LWP_PAGE_LAYOUT))
242 pRet = xParent->GetUseWhen();
245 if (!pRet)
246 pRet = VirtualGetUseWhen();
248 m_bGettingUseWhen = false;
250 return pRet;
253 * @descr: Whether this layout is page layout or not
255 bool LwpVirtualLayout::IsPage() { return (GetLayoutType() == LWP_PAGE_LAYOUT); }
257 * @descr: Whether this layout is header layout or not
259 bool LwpVirtualLayout::IsHeader() { return (GetLayoutType() == LWP_HEADER_LAYOUT); }
261 * @descr: Whether this layout is footer layout or not
263 bool LwpVirtualLayout::IsFooter() { return (GetLayoutType() == LWP_FOOTER_LAYOUT); }
265 * @descr: Whether this layout is frame layout or not
267 bool LwpVirtualLayout::IsFrame() { return (GetLayoutType() == LWP_FRAME_LAYOUT); }
270 * @descr: Whether this layout is cell layout or not
272 bool LwpVirtualLayout::IsCell()
274 return (GetLayoutType() == LWP_CELL_LAYOUT || GetLayoutType() == LWP_CONNECTED_CELL_LAYOUT
275 || GetLayoutType() == LWP_HIDDEN_CELL_LAYOUT);
278 * @descr: Whether this layout is supertable layout or not
280 bool LwpVirtualLayout::IsSuperTable() { return (GetLayoutType() == LWP_SUPERTABLE_LAYOUT); }
282 * @descr: Whether this layout is group layout or not
284 bool LwpVirtualLayout::IsGroupHead() { return (GetLayoutType() == LWP_GROUP_LAYOUT); }
286 * @descr: get the relative type
288 sal_uInt8 LwpVirtualLayout::GetRelativeType()
290 return LwpLayoutRelativityGuts::LAY_PARENT_RELATIVE;
293 * @descr: whether it is relative anchored layout
295 bool LwpVirtualLayout::IsRelativeAnchored()
297 sal_uInt8 nType;
299 nType = GetRelativeType();
300 return (nType == LwpLayoutRelativityGuts::LAY_PARA_RELATIVE)
301 || (nType == LwpLayoutRelativityGuts::LAY_INLINE)
302 || (nType == LwpLayoutRelativityGuts::LAY_INLINE_NEWLINE)
303 || (nType == LwpLayoutRelativityGuts::LAY_INLINE_VERTICAL);
306 * @descr: whether it is MinimumHeight layout
308 bool LwpVirtualLayout::IsMinimumHeight() const
310 return ((m_nAttributes3 & STYLE3_MINHEIGHTVALID) != 0);
314 * @descr: Get parent layout
317 rtl::Reference<LwpVirtualLayout> LwpVirtualLayout::GetParentLayout()
319 return rtl::Reference<LwpVirtualLayout>(
320 dynamic_cast<LwpVirtualLayout*>(GetParent().obj().get()));
324 * @descr: Register child layout style
327 void LwpVirtualLayout::RegisterChildStyle()
329 //Register all children styles
330 rtl::Reference<LwpVirtualLayout> xLayout(
331 dynamic_cast<LwpVirtualLayout*>(GetChildHead().obj().get()));
332 while (xLayout.is())
334 xLayout->SetFoundry(m_pFoundry);
335 xLayout->DoRegisterStyle();
336 xLayout.set(dynamic_cast<LwpVirtualLayout*>(xLayout->GetNext().obj().get()));
340 bool LwpVirtualLayout::NoContentReference()
342 return (m_nAttributes2 & STYLE2_NOCONTENTREFERENCE) != 0;
345 bool LwpVirtualLayout::IsStyleLayout()
347 if (m_bGettingStyleLayout)
348 throw std::runtime_error("recursion in layout");
349 m_bGettingStyleLayout = true;
351 bool bRet = false;
352 if (m_nAttributes3 & STYLE3_STYLELAYOUT)
353 bRet = true;
354 else
356 rtl::Reference<LwpVirtualLayout> xParent(
357 dynamic_cast<LwpVirtualLayout*>(GetParent().obj().get()));
358 if (xParent.is())
359 bRet = xParent->IsStyleLayout();
362 m_bGettingStyleLayout = false;
363 return bRet;
367 * @descr: Find child layout by layout type
370 LwpVirtualLayout* LwpVirtualLayout::FindChildByType(LWP_LAYOUT_TYPE eType)
372 LwpObjectID* pID = &GetChildHead();
373 o3tl::sorted_vector<LwpVirtualLayout*> aSeen;
375 while (pID && !pID->IsNull())
377 LwpVirtualLayout* pLayout = dynamic_cast<LwpVirtualLayout*>(pID->obj().get());
378 if (!pLayout)
379 break;
381 bool bAlreadySeen = !aSeen.insert(pLayout).second;
382 if (bAlreadySeen)
384 SAL_WARN("lwp", "loop in layout");
385 break;
388 if (pLayout->GetLayoutType() == eType)
389 return pLayout;
391 pID = &pLayout->GetNext();
394 return nullptr;
398 * @descr: Whether the size of layout is fit the graphic
401 bool LwpVirtualLayout::IsFitGraphic()
403 return IsAutoGrowRight() && !IsAutoGrowLeft() && GetIsAutoGrowDown();
407 * @descr: Whether the width of layout is auto grow
410 bool LwpVirtualLayout::IsAutoGrowWidth() { return IsAutoGrowLeft() || IsAutoGrowRight(); }
413 * @descr: Determine whether the layout width is to margin
416 bool LwpVirtualLayout::IsInlineToMargin() const
418 return (m_nAttributes3 & STYLE3_INLINETOMARGIN) != 0;
421 void LwpAssociatedLayouts::Read(LwpObjectStream* pStrm)
423 m_OnlyLayout.ReadIndexed(pStrm);
424 m_Layouts.Read(pStrm);
425 pStrm->SkipExtra();
429 * @descr: Looking for the layout which follows the pStartLayout
430 * @param: pStartLayout - the layout which is used for looking for its following layout
432 rtl::Reference<LwpVirtualLayout>
433 LwpAssociatedLayouts::GetLayout(LwpVirtualLayout const* pStartLayout)
435 if (!pStartLayout && !m_OnlyLayout.IsNull())
436 /* Looking for the first layout and there's only one layout in the list.*/
437 return rtl::Reference<LwpVirtualLayout>(
438 dynamic_cast<LwpVirtualLayout*>(m_OnlyLayout.obj().get()));
440 rtl::Reference<LwpObjectHolder> xObjHolder(
441 dynamic_cast<LwpObjectHolder*>(m_Layouts.GetHead().obj().get()));
442 if (xObjHolder.is())
444 rtl::Reference<LwpVirtualLayout> xLayout(
445 dynamic_cast<LwpVirtualLayout*>(xObjHolder->GetObject().obj().get()));
446 if (!pStartLayout)
447 return xLayout;
449 while (xObjHolder.is() && pStartLayout != xLayout.get())
451 xObjHolder.set(dynamic_cast<LwpObjectHolder*>(xObjHolder->GetNext().obj().get()));
452 if (xObjHolder.is())
454 xLayout.set(dynamic_cast<LwpVirtualLayout*>(xObjHolder->GetObject().obj().get()));
458 if (xObjHolder.is())
460 xObjHolder.set(dynamic_cast<LwpObjectHolder*>(xObjHolder->GetNext().obj().get()));
461 if (xObjHolder.is())
463 xLayout.set(dynamic_cast<LwpVirtualLayout*>(xObjHolder->GetObject().obj().get()));
464 return xLayout;
469 return rtl::Reference<LwpVirtualLayout>();
472 LwpHeadLayout::LwpHeadLayout(LwpObjectHeader const& objHdr, LwpSvStream* pStrm)
473 : LwpVirtualLayout(objHdr, pStrm)
477 void LwpHeadLayout::Read()
479 LwpVirtualLayout::Read();
480 //For PermissiveLayout
481 m_pObjStrm->SkipExtra();
482 //For me
483 m_pObjStrm->SkipExtra();
486 void LwpHeadLayout::RegisterStyle()
488 //Register all children styles
489 rtl::Reference<LwpVirtualLayout> xLayout(
490 dynamic_cast<LwpVirtualLayout*>(GetChildHead().obj().get()));
491 o3tl::sorted_vector<LwpVirtualLayout*> aSeen;
492 while (xLayout.is())
494 bool bAlreadySeen = !aSeen.insert(xLayout.get()).second;
495 if (bAlreadySeen)
496 throw std::runtime_error("loop in conversion");
497 xLayout->SetFoundry(m_pFoundry);
498 //if the layout is relative to para, the layout will be registered in para
499 if (!xLayout->IsRelativeAnchored())
500 xLayout->DoRegisterStyle();
501 rtl::Reference<LwpVirtualLayout> xNext(
502 dynamic_cast<LwpVirtualLayout*>(xLayout->GetNext().obj().get()));
503 xLayout = xNext;
508 * @descr find endnote supertable layout from the child layout list. Suppose that there is only one endnote supertablelayout in one division
509 * @return pointer to endnote supertable layout
511 rtl::Reference<LwpVirtualLayout> LwpHeadLayout::FindEnSuperTableLayout()
513 rtl::Reference<LwpVirtualLayout> xLayout(
514 dynamic_cast<LwpVirtualLayout*>(GetChildHead().obj().get()));
515 o3tl::sorted_vector<LwpVirtualLayout*> aSeen;
516 while (xLayout)
518 bool bAlreadySeen = !aSeen.insert(xLayout.get()).second;
519 if (bAlreadySeen)
520 throw std::runtime_error("loop in conversion");
521 if (xLayout->GetLayoutType() == LWP_ENDNOTE_SUPERTABLE_LAYOUT)
523 return xLayout;
525 xLayout.set(dynamic_cast<LwpVirtualLayout*>(xLayout->GetNext().obj().get()));
527 return rtl::Reference<LwpVirtualLayout>();
530 LwpLayoutStyle::LwpLayoutStyle()
531 : m_nStyleDefinition(0)
532 , m_nKey(0)
536 LwpLayoutStyle::~LwpLayoutStyle() {}
538 void LwpLayoutStyle::Read(LwpObjectStream* pStrm)
540 m_nStyleDefinition = pStrm->QuickReaduInt32();
541 m_aDescription.Read(pStrm);
542 if (pStrm->CheckExtra())
544 m_nKey = pStrm->QuickReaduInt16();
545 pStrm->SkipExtra();
549 LwpLayoutMisc::LwpLayoutMisc()
550 : m_nGridDistance(0)
551 , m_nGridType(0)
555 LwpLayoutMisc::~LwpLayoutMisc() {}
557 void LwpLayoutMisc::Read(LwpObjectStream* pStrm)
559 m_nGridType = pStrm->QuickReaduInt16();
560 m_nGridDistance = pStrm->QuickReadInt32();
561 m_aContentStyle.Read(pStrm);
562 pStrm->SkipExtra();
565 LwpMiddleLayout::LwpMiddleLayout(LwpObjectHeader const& objHdr, LwpSvStream* pStrm)
566 : LwpVirtualLayout(objHdr, pStrm)
567 , m_bGettingGeometry(false)
568 , m_bGettingBackgroundStuff(false)
572 LwpMiddleLayout::~LwpMiddleLayout() {}
574 void LwpMiddleLayout::Read()
576 LwpObjectStream* pStrm = m_pObjStrm.get();
578 LwpVirtualLayout::Read();
580 //skip CLiteLayout data;
581 LwpAtomHolder ContentClass;
582 ContentClass.Read(pStrm);
583 pStrm->SkipExtra();
585 // before layout hierarchy rework
586 if (LwpFileHeader::m_nFileRevision < 0x000B)
587 return;
589 m_Content.ReadIndexed(pStrm);
591 // 01/20/2005
592 m_BasedOnStyle.ReadIndexed(pStrm);
593 m_TabPiece.ReadIndexed(pStrm);
595 sal_uInt8 nWhatsItGot = pStrm->QuickReaduInt8();
597 if (nWhatsItGot & DISK_GOT_STYLE_STUFF)
599 m_aStyleStuff.Read(pStrm);
601 if (nWhatsItGot & DISK_GOT_MISC_STUFF)
603 m_aMiscStuff.Read(pStrm);
606 m_LayGeometry.ReadIndexed(pStrm);
607 m_LayScale.ReadIndexed(pStrm);
608 m_LayMargins.ReadIndexed(pStrm);
609 m_LayBorderStuff.ReadIndexed(pStrm);
610 m_LayBackgroundStuff.ReadIndexed(pStrm);
612 if (pStrm->CheckExtra())
614 m_LayExtBorderStuff.ReadIndexed(pStrm);
615 pStrm->SkipExtra();
619 rtl::Reference<LwpObject> LwpMiddleLayout::GetBasedOnStyle() const
621 rtl::Reference<LwpObject> xRet(m_BasedOnStyle.obj());
622 if (xRet.get() == this)
624 SAL_WARN("lwp", "style based on itself");
625 return rtl::Reference<LwpObject>();
627 return xRet;
631 * @descr: Get the geometry of current layout
634 LwpLayoutGeometry* LwpMiddleLayout::GetGeometry()
636 if (m_bGettingGeometry)
637 throw std::runtime_error("recursion in layout");
638 m_bGettingGeometry = true;
640 LwpLayoutGeometry* pRet = nullptr;
641 if (!m_LayGeometry.IsNull())
643 pRet = dynamic_cast<LwpLayoutGeometry*>(m_LayGeometry.obj().get());
645 else
647 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
648 if (LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*>(xBase.get()))
650 pRet = pLay->GetGeometry();
654 m_bGettingGeometry = false;
655 return pRet;
659 * @descr: Get layout height, measured by "cm"
662 double LwpMiddleLayout::GetGeometryHeight()
664 LwpLayoutGeometry* pGeo = GetGeometry();
665 if (pGeo)
667 return LwpTools::ConvertFromUnitsToMetric(pGeo->GetHeight());
669 else
670 return -1;
674 * @descr: Get layout width, measured by "cm"
677 double LwpMiddleLayout::GetGeometryWidth()
679 LwpLayoutGeometry* pGeo = GetGeometry();
680 if (pGeo)
682 return LwpTools::ConvertFromUnitsToMetric(pGeo->GetWidth());
684 else
685 return -1;
689 * @descr: Whether the margins is same as parent layout
692 bool LwpMiddleLayout::MarginsSameAsParent()
694 if (m_nOverrideFlag & OVER_MARGINS)
696 return LwpVirtualLayout::MarginsSameAsParent();
698 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
699 if (LwpVirtualLayout* pLay = dynamic_cast<LwpVirtualLayout*>(xBase.get()))
701 pLay->GetMarginsSameAsParent();
703 return LwpVirtualLayout::MarginsSameAsParent();
707 * @descr: Get margin
708 * @param: nWhichSide - 0: left, 1: right, 2:top, 3: bottom
710 double LwpMiddleLayout::MarginsValue(sal_uInt8 nWhichSide)
712 double fValue = 0;
713 if ((nWhichSide == MARGIN_LEFT) || (nWhichSide == MARGIN_RIGHT))
715 if (GetMarginsSameAsParent())
717 rtl::Reference<LwpVirtualLayout> xParent(
718 dynamic_cast<LwpVirtualLayout*>(GetParent().obj().get()));
719 if (xParent.is() && !xParent->IsHeader())
721 fValue = xParent->GetMarginsValue(nWhichSide);
722 return fValue;
727 if (m_nOverrideFlag & OVER_MARGINS)
729 LwpLayoutMargins* pMar1 = dynamic_cast<LwpLayoutMargins*>(m_LayMargins.obj().get());
730 if (pMar1)
732 fValue = pMar1->GetMargins().GetMarginsValue(nWhichSide);
733 return fValue;
736 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
737 LwpVirtualLayout* pStyle = dynamic_cast<LwpVirtualLayout*>(xBase.get());
738 if (pStyle)
740 fValue = pStyle->GetMarginsValue(nWhichSide);
741 return fValue;
743 return LwpVirtualLayout::MarginsValue(nWhichSide);
746 * @descr: Get extmargin value
747 * @param: nWhichSide - 0: left, 1: right, 2:top, 3: bottom
748 * @param:
749 * @return:
751 double LwpMiddleLayout::ExtMarginsValue(sal_uInt8 nWhichSide)
753 double fValue = 0;
754 if (m_nOverrideFlag & OVER_MARGINS)
756 LwpLayoutMargins* pMar1 = dynamic_cast<LwpLayoutMargins*>(m_LayMargins.obj().get());
757 if (pMar1)
759 fValue = pMar1->GetExtMargins().GetMarginsValue(nWhichSide);
760 return fValue;
763 LwpVirtualLayout* pStyle = dynamic_cast<LwpVirtualLayout*>(GetBasedOnStyle().get());
764 if (pStyle)
766 fValue = pStyle->GetExtMarginsValue(nWhichSide);
767 return fValue;
769 return LwpVirtualLayout::ExtMarginsValue(nWhichSide);
772 * @descr: Get the LwpBorderStuff object according to m_LayBorderStuff id.
774 LwpBorderStuff* LwpMiddleLayout::GetBorderStuff()
776 if (m_bGettingBorderStuff)
777 throw std::runtime_error("recursion in layout");
778 m_bGettingBorderStuff = true;
780 LwpBorderStuff* pRet = nullptr;
782 if (m_nOverrideFlag & OVER_BORDERS)
784 LwpLayoutBorder* pLayoutBorder
785 = dynamic_cast<LwpLayoutBorder*>(m_LayBorderStuff.obj().get());
786 pRet = pLayoutBorder ? &pLayoutBorder->GetBorderStuff() : nullptr;
788 else
790 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
791 if (LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*>(xBase.get()))
793 pRet = pLay->GetBorderStuff();
797 m_bGettingBorderStuff = false;
798 return pRet;
802 * @descr: Get LwpBackgroundStuff object according to m_LayBackgroundStuff id;
804 LwpBackgroundStuff* LwpMiddleLayout::GetBackgroundStuff()
806 if (m_bGettingBackgroundStuff)
807 throw std::runtime_error("recursion in layout");
808 m_bGettingBackgroundStuff = true;
810 LwpBackgroundStuff* pRet = nullptr;
812 if (m_nOverrideFlag & OVER_BACKGROUND)
814 LwpLayoutBackground* pLayoutBackground
815 = dynamic_cast<LwpLayoutBackground*>(m_LayBackgroundStuff.obj().get());
816 pRet = pLayoutBackground ? &pLayoutBackground->GetBackgoudStuff() : nullptr;
818 else
820 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
821 if (LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*>(xBase.get()))
823 pRet = pLay->GetBackgroundStuff();
827 m_bGettingBackgroundStuff = false;
828 return pRet;
832 * @descr: create xfborder.
834 std::unique_ptr<XFBorders> LwpMiddleLayout::GetXFBorders()
836 LwpBorderStuff* pBorderStuff = GetBorderStuff();
837 if (pBorderStuff && pBorderStuff->GetSide() != 0)
839 //copy from lwpparastyle.
840 std::unique_ptr<XFBorders> xXFBorders(new XFBorders);
841 // apply 4 borders respectively
842 LwpBorderStuff::BorderType const pType[] = { LwpBorderStuff::LEFT, LwpBorderStuff::RIGHT,
843 LwpBorderStuff::TOP, LwpBorderStuff::BOTTOM };
845 for (LwpBorderStuff::BorderType nC : pType)
847 if (pBorderStuff->HasSide(nC))
849 LwpParaStyle::ApplySubBorder(pBorderStuff, nC, xXFBorders.get());
852 return xXFBorders;
854 return nullptr;
858 * @descr: Get text direction settings.
860 enumXFTextDir LwpMiddleLayout::GetTextDirection()
862 enumXFTextDir eTextDir = enumXFTextDirNone;
863 sal_uInt8 nDirection = GetContentOrientation();
864 switch (nDirection)
866 case TEXT_ORIENT_LRTB:
868 eTextDir = enumXFTextDirLR_TB;
869 break;
871 case TEXT_ORIENT_TBRL:
873 eTextDir = enumXFTextDirTB_RL;
874 break;
876 case TEXT_ORIENT_RLBT: // not supported now
878 eTextDir = enumXFTextDirNone;
879 break;
881 case TEXT_ORIENT_BTLR: // not supported now
883 eTextDir = enumXFTextDirNone;
884 break;
886 default:
887 break;
889 return eTextDir;
892 * @descr: Get background color.
894 LwpColor* LwpMiddleLayout::GetBackColor()
896 LwpBackgroundStuff* pBackgroundStuff = GetBackgroundStuff();
897 if (pBackgroundStuff && !pBackgroundStuff->IsTransparent())
899 LwpColor* pColor = pBackgroundStuff->GetFillColor();
900 if (pColor->IsValidColor())
902 return pColor;
905 return nullptr;
909 * @descr: Add back color settings into xfpagemaster.
911 LwpTabOverride* LwpMiddleLayout::GetTabOverride()
913 if (m_nAttributes & OVER_TABS)
915 if (!m_TabPiece.IsNull())
917 LwpTabPiece* pPiece = dynamic_cast<LwpTabPiece*>(m_TabPiece.obj().get());
918 return static_cast<LwpTabOverride*>(pPiece ? pPiece->GetOverride() : nullptr);
920 return nullptr;
922 else
924 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
925 if (LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*>(xBase.get()))
927 return pLay->GetTabOverride();
930 return nullptr;
934 * @descr: Layscale for graphic & watermark
936 sal_uInt16 LwpMiddleLayout::GetScaleMode()
938 if ((m_nOverrideFlag & OVER_SCALING) && m_LayScale.obj().is() && GetLayoutScale())
939 return GetLayoutScale()->GetScaleMode();
940 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
941 if (xBase.is())
942 return dynamic_cast<LwpMiddleLayout&>(*xBase).GetScaleMode();
943 else
944 return (LwpLayoutScale::FIT_IN_FRAME | LwpLayoutScale::MAINTAIN_ASPECT_RATIO);
947 sal_uInt16 LwpMiddleLayout::GetScaleTile()
949 if ((m_nOverrideFlag & OVER_SCALING) && m_LayScale.obj().is() && GetLayoutScale())
950 return (GetLayoutScale()->GetPlacement() & LwpLayoutScale::TILED) ? 1 : 0;
951 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
952 if (xBase.is())
953 return dynamic_cast<LwpMiddleLayout&>(*xBase).GetScaleTile();
954 else
955 return 0;
958 sal_uInt16 LwpMiddleLayout::GetScaleCenter()
960 if (m_bGettingScaleCenter)
961 throw std::runtime_error("recursion in layout");
962 m_bGettingScaleCenter = true;
964 sal_uInt16 nRet = 0;
966 if ((m_nOverrideFlag & OVER_SCALING) && m_LayScale.obj().is() && GetLayoutScale())
968 nRet = (GetLayoutScale()->GetPlacement() & LwpLayoutScale::CENTERED) ? 1 : 0;
970 else
972 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
973 if (xBase.is())
974 nRet = dynamic_cast<LwpMiddleLayout&>(*xBase).GetScaleCenter();
977 m_bGettingScaleCenter = false;
978 return nRet;
981 bool LwpMiddleLayout::CanSizeRight()
983 sal_uInt8 RelType = GetRelativeType();
985 return !(RelType == LwpLayoutRelativityGuts::LAY_INLINE
986 || RelType == LwpLayoutRelativityGuts::LAY_PARA_RELATIVE
987 || RelType == LwpLayoutRelativityGuts::LAY_INLINE_VERTICAL);
989 sal_Int32 LwpMiddleLayout::GetMinimumWidth()
991 if (((m_nAttributes3 & STYLE3_WIDTHVALID) != 0) && GetGeometry())
993 return GetGeometry()->GetWidth();
995 else if (m_nOverrideFlag & OVER_SIZE)
997 return DetermineWidth();
999 return 0;
1001 sal_Int32 LwpMiddleLayout::DetermineWidth()
1003 if (IsSizeRightToContent())
1005 assert(false);
1007 else if (IsSizeRightToContainer())
1009 assert(false);
1011 else if (LwpLayoutGeometry* pGeo = GetGeometry())
1013 m_nAttributes3 |= STYLE3_WIDTHVALID;
1014 return pGeo->GetWidth();
1016 return 0;
1018 bool LwpMiddleLayout::IsSizeRightToContainer()
1020 if (!CanSizeRight())
1021 return false;
1023 if (m_nOverrideFlag & OVER_SIZE)
1025 return (m_nDirection & ((LAY_USEDIRECTION | LAY_AUTOSIZE | LAY_TOCONTAINER) << SHIFT_RIGHT))
1026 == ((LAY_USEDIRECTION | LAY_TOCONTAINER | LAY_AUTOSIZE) << SHIFT_RIGHT);
1028 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
1029 if (xBase.is())
1031 LwpMiddleLayout* pLayout = dynamic_cast<LwpMiddleLayout*>(xBase.get());
1032 return pLayout && pLayout->IsSizeRightToContainer();
1034 else
1035 return false;
1037 bool LwpMiddleLayout::IsSizeRightToContent()
1039 if (!CanSizeRight())
1040 return false;
1042 if (m_nOverrideFlag & OVER_SIZE)
1044 return (m_nDirection & ((LAY_USEDIRECTION | LAY_AUTOSIZE | LAY_TOCONTAINER) << SHIFT_RIGHT))
1045 == ((LAY_USEDIRECTION | LAY_AUTOSIZE) << SHIFT_RIGHT);
1047 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
1048 if (xBase.is())
1050 LwpMiddleLayout* pLayout = dynamic_cast<LwpMiddleLayout*>(xBase.get());
1051 return pLayout && pLayout->IsSizeRightToContent();
1053 else
1054 return false;
1058 * @descr: Get layout height
1061 double LwpMiddleLayout::GetHeight() { return GetGeometryHeight(); }
1064 * @descr: Get layout height
1067 double LwpMiddleLayout::GetWidth() { return GetGeometryWidth(); }
1069 * @descr: Get layout origin point
1072 LwpPoint LwpMiddleLayout::GetOrigin()
1074 LwpLayoutGeometry* pGeo = GetGeometry();
1075 if (pGeo)
1077 sal_uInt8 nType = GetRelativeType();
1078 if (nType == LwpLayoutRelativityGuts::LAY_INLINE
1079 || nType == LwpLayoutRelativityGuts::LAY_INLINE_NEWLINE)
1081 return pGeo->GetAbsoluteOrigin();
1083 else
1084 return pGeo->GetOrigin();
1087 return LwpPoint();
1091 * @descr: Whether the fill is pattern fill or not
1092 * @return: True if yes, false if not.
1094 bool LwpMiddleLayout::IsPatternFill()
1096 LwpBackgroundStuff* pBackgroundStuff = GetBackgroundStuff();
1097 if (pBackgroundStuff)
1099 return pBackgroundStuff->IsPatternFill();
1102 return false;
1106 * @descr: Get the fill pattern style. Data are saved in a XFBGImage object
1107 * @return: the fill pattern style.
1109 std::unique_ptr<XFBGImage> LwpMiddleLayout::GetFillPattern()
1111 LwpBackgroundStuff* pBackgroundStuff = GetBackgroundStuff();
1112 if (pBackgroundStuff)
1114 return pBackgroundStuff->GetFillPattern();
1117 return std::unique_ptr<XFBGImage>();
1121 * @descr: Whether the height and width of layout is auto grow
1124 bool LwpMiddleLayout::IsAutoGrow()
1126 if (m_nOverrideFlag & OVER_SIZE)
1128 return (m_nDirection
1129 & ((LAY_AUTOGROW << SHIFT_UP) | (LAY_AUTOGROW << SHIFT_DOWN)
1130 | (LAY_AUTOGROW << SHIFT_RIGHT) | (LAY_AUTOGROW << SHIFT_LEFT)))
1131 != 0;
1133 else
1135 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
1136 if (LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*>(xBase.get()))
1138 return pLay->IsAutoGrow();
1141 return LwpVirtualLayout::IsAutoGrow();
1145 * @descr: Whether the height of layout is auto grow down
1148 bool LwpMiddleLayout::IsAutoGrowDown()
1150 if (m_nOverrideFlag & OVER_SIZE)
1152 return (m_nDirection & (LAY_AUTOGROW << SHIFT_DOWN)) != 0;
1154 else
1156 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
1157 if (LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*>(xBase.get()))
1159 return pLay->GetIsAutoGrowDown();
1162 return LwpVirtualLayout::IsAutoGrowDown();
1166 * @descr: Whether the height of layout is auto grow up
1169 bool LwpMiddleLayout::IsAutoGrowUp()
1171 if (m_bGettingAutoGrowUp)
1172 throw std::runtime_error("recursion in layout");
1173 m_bGettingAutoGrowUp = true;
1175 bool bRet;
1177 if (m_nOverrideFlag & OVER_SIZE)
1179 bRet = (m_nDirection & (LAY_AUTOGROW << SHIFT_UP)) != 0;
1181 else
1183 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
1184 if (LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*>(xBase.get()))
1185 bRet = pLay->IsAutoGrowUp();
1186 else
1187 bRet = LwpVirtualLayout::IsAutoGrowUp();
1190 m_bGettingAutoGrowUp = false;
1191 return bRet;
1195 * @descr: Whether the height of layout is auto grow down
1198 bool LwpMiddleLayout::IsAutoGrowLeft()
1200 if (m_nOverrideFlag & OVER_SIZE)
1202 return (m_nDirection & (LAY_AUTOGROW << SHIFT_LEFT)) != 0;
1204 else
1206 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
1207 if (LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*>(xBase.get()))
1209 return pLay->IsAutoGrowLeft();
1212 return LwpVirtualLayout::IsAutoGrowLeft();
1216 * @descr: Whether the height of layout is auto grow down
1219 bool LwpMiddleLayout::IsAutoGrowRight()
1221 if (m_nOverrideFlag & OVER_SIZE)
1223 return (m_nDirection & (LAY_AUTOGROW << SHIFT_RIGHT)) != 0;
1225 else
1227 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
1228 if (LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*>(xBase.get()))
1230 return pLay->IsAutoGrowRight();
1233 return LwpVirtualLayout::IsAutoGrowRight();
1237 * @descr: Get contents orientation
1240 sal_uInt8 LwpMiddleLayout::GetContentOrientation()
1242 //content orientation in Graphic objects and OLE objects not supported now
1243 if ((m_nOverrideFlag & OVER_ROTATION) && !m_LayGeometry.IsNull())
1245 LwpLayoutGeometry* pLayGeometry
1246 = dynamic_cast<LwpLayoutGeometry*>(m_LayGeometry.obj().get());
1247 if (pLayGeometry)
1248 return pLayGeometry->GetContentOrientation();
1250 else
1252 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
1253 if (LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*>(xBase.get()))
1255 return pLay->GetContentOrientation();
1258 return LwpVirtualLayout::GetContentOrientation();
1262 * @descr: Whether it is honoring protection
1265 bool LwpMiddleLayout::HonorProtection()
1267 if (m_nOverrideFlag & OVER_MISC)
1269 if (!(m_nAttributes2 & STYLE2_HONORPROTECTION))
1270 return false;
1272 rtl::Reference<LwpVirtualLayout> xParent(
1273 dynamic_cast<LwpVirtualLayout*>(GetParent().obj().get()));
1274 if (xParent.is() && !xParent->IsHeader())
1276 return xParent->GetHonorProtection();
1279 if (m_pFoundry) //is null now
1281 LwpDocument* pDoc = m_pFoundry->GetDocument();
1282 if (pDoc)
1284 return pDoc->GetHonorProtection();
1288 else
1290 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
1291 if (LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*>(xBase.get()))
1293 return pLay->GetHonorProtection();
1297 return LwpVirtualLayout::HonorProtection();
1301 * @descr: Whether it is protected
1304 bool LwpMiddleLayout::IsProtected()
1306 bool bProtected = false;
1307 if (m_nOverrideFlag & OVER_MISC)
1309 bProtected = (m_nAttributes & STYLE_PROTECTED) != 0;
1311 else
1313 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
1314 if (LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*>(xBase.get()))
1316 bProtected = pLay->GetIsProtected();
1318 else
1319 bProtected = LwpVirtualLayout::IsProtected();
1322 rtl::Reference<LwpVirtualLayout> xParent(
1323 dynamic_cast<LwpVirtualLayout*>(GetParent().obj().get()));
1324 if (xParent.is() && !xParent->IsHeader())
1326 /* If a parent's protected then none of its children can be accessed. */
1327 if (xParent->GetIsProtected())
1328 return true;
1330 if (xParent->GetHonorProtection())
1331 return bProtected;
1333 /* If our parent isn't honoring protection then we aren't protected. */
1334 return false;
1336 if (m_pFoundry) //is null now
1338 LwpDocument* pDoc = m_pFoundry->GetDocument();
1339 if (pDoc)
1341 if (pDoc->GetHonorProtection())
1342 return bProtected;
1344 /* If the document isn't honoring protection then we aren't protected.*/
1345 return false;
1349 return bProtected;
1353 * @descr: Get watermark layout
1356 rtl::Reference<LwpVirtualLayout> LwpMiddleLayout::GetWaterMarkLayout()
1358 rtl::Reference<LwpVirtualLayout> xLay(
1359 dynamic_cast<LwpVirtualLayout*>(GetChildHead().obj().get()));
1360 o3tl::sorted_vector<LwpVirtualLayout*> aSeen;
1361 while (xLay.is())
1363 bool bAlreadySeen = !aSeen.insert(xLay.get()).second;
1364 if (bAlreadySeen)
1365 throw std::runtime_error("loop in conversion");
1366 if (xLay->IsForWaterMark())
1368 return xLay;
1370 rtl::Reference<LwpVirtualLayout> xNext(
1371 dynamic_cast<LwpVirtualLayout*>(xLay->GetNext().obj().get()));
1372 xLay = xNext;
1374 return rtl::Reference<LwpVirtualLayout>();
1378 * @descr: Create and return xfbgimage object for watermark
1381 std::unique_ptr<XFBGImage> LwpMiddleLayout::GetXFBGImage()
1383 std::unique_ptr<XFBGImage> xXFBGImage;
1385 rtl::Reference<LwpVirtualLayout> xWaterMarkLayout(GetWaterMarkLayout());
1386 LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*>(xWaterMarkLayout.get());
1387 if (pLay)
1389 //test BGImage
1390 LwpGraphicObject* pGrfObj = dynamic_cast<LwpGraphicObject*>(pLay->GetContent().obj().get());
1391 if (pGrfObj)
1393 xXFBGImage.reset(new XFBGImage);
1394 if (pGrfObj->IsLinked())
1396 //set file link
1397 OUString linkedfilepath = pGrfObj->GetLinkedFilePath();
1398 OUString fileURL = LwpTools::convertToFileUrl(
1399 OUStringToOString(linkedfilepath, osl_getThreadTextEncoding()));
1400 xXFBGImage->SetFileLink(fileURL);
1402 else
1404 std::vector<sal_uInt8> aGrafData = pGrfObj->GetRawGrafData();
1405 xXFBGImage->SetImageData(aGrafData.data(), aGrafData.size());
1408 //automatic, top left
1409 xXFBGImage->SetPosition(enumXFAlignStart, enumXFAlignTop);
1410 if (pLay->GetScaleCenter())
1412 //center
1413 xXFBGImage->SetPosition();
1415 else if (pLay->GetScaleTile())
1417 //tile
1418 xXFBGImage->SetRepeate();
1420 //fit type, area type
1421 if ((pLay->GetScaleMode() & LwpLayoutScale::FIT_IN_FRAME) != 0)
1423 if ((pLay->GetScaleMode() & LwpLayoutScale::MAINTAIN_ASPECT_RATIO) == 0)
1425 xXFBGImage->SetStretch();
1430 return xXFBGImage;
1434 * @descr: Whether the page uses the printer setting
1437 bool LwpMiddleLayout::GetUsePrinterSettings()
1439 if (m_bGettingUsePrinterSettings)
1440 throw std::runtime_error("recursion in layout");
1441 m_bGettingUsePrinterSettings = true;
1443 bool bRet = false;
1445 if (m_nOverrideFlag & OVER_SIZE)
1447 bRet = (m_nAttributes3 & STYLE3_USEPRINTERSETTINGS) != 0;
1449 else
1451 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
1452 if (LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*>(xBase.get()))
1454 bRet = pLay->GetUsePrinterSettings();
1458 m_bGettingUsePrinterSettings = false;
1459 return bRet;
1462 //Check whether there are contents in the layout
1463 bool LwpMiddleLayout::HasContent()
1465 rtl::Reference<LwpObject> content = m_Content.obj();
1466 return content.is();
1469 LwpLayout::LwpLayout(LwpObjectHeader const& objHdr, LwpSvStream* pStrm)
1470 : LwpMiddleLayout(objHdr, pStrm)
1471 , m_bGettingShadow(false)
1472 , m_bGettingNumCols(false)
1476 LwpLayout::~LwpLayout() {}
1478 void LwpLayout::Read()
1480 LwpObjectStream* pStrm = m_pObjStrm.get();
1482 LwpMiddleLayout::Read();
1483 if (LwpFileHeader::m_nFileRevision < 0x000B)
1485 // read PreRevBLayout...
1487 else
1489 sal_uInt16 nSimple = pStrm->QuickReaduInt16();
1491 if (!nSimple)
1493 m_aUseWhen.Read(pStrm);
1495 sal_uInt8 nFlag = pStrm->QuickReaduInt8();
1496 if (nFlag)
1497 m_Position.ReadIndexed(pStrm);
1500 m_LayColumns.ReadIndexed(pStrm);
1501 m_LayGutterStuff.ReadIndexed(pStrm);
1502 m_LayJoinStuff.ReadIndexed(pStrm);
1503 m_LayShadow.ReadIndexed(pStrm);
1505 if (pStrm->CheckExtra())
1507 m_LayExtJoinStuff.ReadIndexed(pStrm);
1508 pStrm->SkipExtra();
1514 * @descr: Get columns number
1517 sal_uInt16 LwpLayout::GetNumCols()
1519 if (m_bGettingNumCols)
1520 throw std::runtime_error("recursion in layout");
1521 m_bGettingNumCols = true;
1523 sal_uInt16 nRet = 0;
1524 LwpLayoutColumns* pLayColumns = (m_nOverrideFlag & OVER_COLUMNS)
1525 ? dynamic_cast<LwpLayoutColumns*>(m_LayColumns.obj().get())
1526 : nullptr;
1527 if (pLayColumns)
1529 nRet = pLayColumns->GetNumCols();
1531 else
1533 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
1534 LwpVirtualLayout* pStyle = dynamic_cast<LwpVirtualLayout*>(xBase.get());
1535 nRet = pStyle ? pStyle->GetNumCols() : LwpVirtualLayout::GetNumCols();
1537 m_bGettingNumCols = false;
1538 return nRet;
1542 * @descr: Get gap between columns
1543 * @param: the order of column
1545 double LwpLayout::GetColGap(sal_uInt16 nIndex)
1547 if ((m_nOverrideFlag & OVER_COLUMNS) || (m_nAttributes2 & STYLE2_LOCALCOLUMNINFO))
1549 LwpLayoutColumns* pLayColumns = dynamic_cast<LwpLayoutColumns*>(m_LayColumns.obj().get());
1550 if (pLayColumns)
1552 return pLayColumns->GetColGap(nIndex);
1556 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
1557 LwpVirtualLayout* pStyle = dynamic_cast<LwpVirtualLayout*>(xBase.get());
1558 if (pStyle)
1560 return pStyle->GetColGap(nIndex);
1563 return LwpVirtualLayout::GetColGap(nIndex);
1567 * @descr: Create and return XFColumns object
1570 XFColumns* LwpLayout::GetXFColumns()
1572 //if there is only one column, do not need insert columns
1573 sal_uInt16 nCols = GetNumCols();
1574 if (nCols == 1)
1576 return nullptr;
1579 std::unique_ptr<XFColumns> xColumns(new XFColumns);
1580 //set XFColumnSep
1581 std::unique_ptr<XFColumnSep> xColumnSep(GetColumnSep());
1582 if (xColumnSep)
1584 xColumns->SetSeparator(*xColumnSep);
1587 //set column count and column gap
1588 xColumns->SetCount(nCols);
1589 double fGap = GetColGap(0);
1590 xColumns->SetGap(fGap);
1592 //set xfcolumn
1593 for (sal_uInt16 nIndex = 0; nIndex < nCols; nIndex++)
1595 XFColumn aColumn;
1596 sal_Int32 nWidth = 8305 / nCols; //relative width
1597 aColumn.SetRelWidth(nWidth);
1599 //the left and right margins is 0;
1600 double nGap = GetColGap(nIndex) / 2;
1601 aColumn.SetMargins(nGap, nGap);
1602 if (nIndex == 0)
1604 aColumn.SetMargins(0, nGap);
1606 if (nIndex == (nCols - 1))
1608 aColumn.SetMargins(nGap, 0);
1610 xColumns->AddColumn(aColumn);
1613 return xColumns.release();
1617 * @descr: Create and return XFColumnSep object
1620 XFColumnSep* LwpLayout::GetColumnSep()
1622 //Get LwpLayoutGutters
1623 LwpLayoutGutters* pLayoutGutters
1624 = dynamic_cast<LwpLayoutGutters*>(m_LayGutterStuff.obj().get());
1625 if (!pLayoutGutters)
1627 return nullptr;
1630 LwpBorderStuff& rBorderStuff = pLayoutGutters->GetBorderStuff();
1632 LwpBorderStuff::BorderType eType = LwpBorderStuff::LEFT;
1633 LwpColor aColor = rBorderStuff.GetSideColor(eType);
1634 double fWidth = rBorderStuff.GetSideWidth(eType);
1635 //sal_uInt16 nType = rBorderStuff->GetSideType(eType);
1637 XFColumnSep* pColumnSep = new XFColumnSep();
1638 XFColor aXFColor(aColor.To24Color());
1639 pColumnSep->SetColor(aXFColor);
1640 pColumnSep->SetWidth(fWidth);
1641 pColumnSep->SetRelHeight(100);
1642 pColumnSep->SetVerticalAlign(enumXFAlignTop);
1644 return pColumnSep;
1648 * @descr: Get use when type
1651 LwpLayout::UseWhenType LwpLayout::GetUseWhenType()
1653 UseWhenType eType = StartWithinPage;
1654 LwpUseWhen* pUseWhen = GetUseWhen();
1655 if (pUseWhen)
1657 if (pUseWhen->IsStartOnThisHF())
1659 eType = StartWithinColume;
1661 else if (pUseWhen->IsStartOnThisPage())
1663 eType = StartWithinPage;
1665 else if (pUseWhen->IsStartOnNextPage())
1667 eType = StartOnNextPage;
1669 else if (pUseWhen->IsStartOnNextOddPage())
1671 eType = StartOnOddPage;
1673 else if (pUseWhen->IsStartOnNextEvenPage())
1675 eType = StartOnEvenPage;
1678 else
1680 eType = StartOnNextPage;
1682 return eType;
1686 * @descr: Get use page
1689 sal_uInt16 LwpLayout::GetUsePage()
1691 if (m_nOverrideFlag & OVER_PLACEMENT)
1693 LwpUseWhen* pUseWhen = GetUseWhen();
1694 if (pUseWhen)
1695 return pUseWhen->GetUsePage();
1696 else
1697 return 0;
1699 else
1701 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
1702 if (LwpLayout* pLay = dynamic_cast<LwpLayout*>(xBase.get()))
1704 return pLay->GetUsePage();
1707 return 0;
1711 * @descr: Get usewhen pointer
1714 LwpUseWhen* LwpLayout::VirtualGetUseWhen()
1716 if (m_nOverrideFlag & OVER_PLACEMENT)
1718 return &m_aUseWhen;
1720 else
1722 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
1723 if (LwpLayout* pLay = dynamic_cast<LwpLayout*>(xBase.get()))
1725 return pLay->VirtualGetUseWhen();
1728 return LwpVirtualLayout::VirtualGetUseWhen();
1732 * @descr: Whether it is use on all pages
1735 bool LwpLayout::IsUseOnAllPages()
1737 if (m_nOverrideFlag & OVER_PLACEMENT)
1739 LwpUseWhen* pUseWhen = GetUseWhen();
1740 if (pUseWhen)
1741 return pUseWhen->IsUseOnAllPages();
1742 else
1743 return false;
1745 else
1747 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
1748 if (LwpLayout* pLay = dynamic_cast<LwpLayout*>(xBase.get()))
1750 return pLay->IsUseOnAllPages();
1753 return LwpVirtualLayout::IsUseOnAllPages();
1757 * @descr: Whether it is use on all even pages
1760 bool LwpLayout::IsUseOnAllEvenPages()
1762 if (m_nOverrideFlag & OVER_PLACEMENT)
1764 LwpUseWhen* pUseWhen = GetUseWhen();
1765 if (pUseWhen)
1766 return pUseWhen->IsUseOnAllEvenPages();
1767 else
1768 return false;
1770 else
1772 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
1773 if (LwpLayout* pLay = dynamic_cast<LwpLayout*>(xBase.get()))
1775 return pLay->IsUseOnAllEvenPages();
1778 return LwpVirtualLayout::IsUseOnAllEvenPages();
1782 * @descr: Whether it is use on all odd pages
1785 bool LwpLayout::IsUseOnAllOddPages()
1787 if (m_nOverrideFlag & OVER_PLACEMENT)
1789 LwpUseWhen* pUseWhen = GetUseWhen();
1790 if (pUseWhen)
1791 return pUseWhen->IsUseOnAllOddPages();
1792 else
1793 return false;
1795 else
1797 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
1798 if (LwpLayout* pLay = dynamic_cast<LwpLayout*>(xBase.get()))
1800 return pLay->IsUseOnAllOddPages();
1803 return LwpVirtualLayout::IsUseOnAllOddPages();
1807 * @descr: Whether it is use on current page
1810 bool LwpLayout::IsUseOnPage()
1812 if (m_nOverrideFlag & OVER_PLACEMENT)
1814 LwpUseWhen* pUseWhen = GetUseWhen();
1815 if (pUseWhen)
1816 return pUseWhen->IsUseOnPage();
1817 else
1818 return false;
1820 else
1822 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
1823 if (LwpLayout* pLay = dynamic_cast<LwpLayout*>(xBase.get()))
1825 return pLay->IsUseOnPage();
1828 return LwpVirtualLayout::IsUseOnPage();
1832 * @descr: Get the LwpShadow object according to m_LayShadow id.
1834 LwpShadow* LwpLayout::GetShadow()
1836 if (m_bGettingShadow)
1837 throw std::runtime_error("recursion in layout");
1838 m_bGettingShadow = true;
1839 LwpShadow* pRet = nullptr;
1840 if (m_nOverrideFlag & OVER_SHADOW)
1842 LwpLayoutShadow* pLayoutShadow = dynamic_cast<LwpLayoutShadow*>(m_LayShadow.obj().get());
1843 pRet = pLayoutShadow ? &pLayoutShadow->GetShadow() : nullptr;
1845 else
1847 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
1848 if (LwpLayout* pLay = dynamic_cast<LwpLayout*>(xBase.get()))
1850 pRet = pLay->GetShadow();
1853 m_bGettingShadow = false;
1854 return pRet;
1858 * @descr: create xfshadow
1860 XFShadow* LwpLayout::GetXFShadow()
1862 LwpShadow* pShadow = GetShadow();
1863 if (!pShadow)
1864 return nullptr;
1865 LwpColor color = pShadow->GetColor();
1866 double offsetX = pShadow->GetOffsetX();
1867 double offsetY = pShadow->GetOffsetY();
1869 if (!offsetX || !offsetY || !color.IsValidColor())
1870 return nullptr;
1871 XFShadow* pXFShadow = new XFShadow();
1872 enumXFShadowPos eXFShadowPos = enumXFShadowLeftTop;
1873 double fOffset = 0;
1875 bool left = false;
1876 bool top = false;
1877 if (offsetX < 0)
1878 left = true;
1879 if (offsetY < 0)
1880 top = true;
1881 if (left)
1883 fOffset = -offsetX;
1884 if (top)
1885 eXFShadowPos = enumXFShadowLeftTop;
1886 else
1887 eXFShadowPos = enumXFShadowLeftBottom;
1889 else
1891 fOffset = offsetX;
1892 if (top)
1893 eXFShadowPos = enumXFShadowRightTop;
1894 else
1895 eXFShadowPos = enumXFShadowRightBottom;
1898 pXFShadow->SetPosition(eXFShadowPos);
1899 pXFShadow->SetOffset(fOffset);
1900 pXFShadow->SetColor(XFColor(color.To24Color()));
1902 return pXFShadow;
1906 * @descr get the layout that containers the current frame layout
1909 rtl::Reference<LwpVirtualLayout> LwpLayout::GetContainerLayout()
1911 if (IsRelativeAnchored())
1913 //get position
1914 LwpPara* pPara = dynamic_cast<LwpPara*>(GetPosition().obj().get());
1915 if (pPara)
1917 LwpStory* pStory = pPara->GetStory();
1918 return pStory ? pStory->GetTabLayout() : nullptr;
1921 return GetParentLayout();
1924 LwpPlacableLayout::LwpPlacableLayout(LwpObjectHeader const& objHdr, LwpSvStream* pStrm)
1925 : LwpLayout(objHdr, pStrm)
1926 , m_bGettingWrapType(false)
1927 , m_bGettingLayoutRelativity(false)
1928 , m_nWrapType(0)
1929 , m_nBuoyancy(0)
1930 , m_nBaseLineOffset(0)
1934 LwpPlacableLayout::~LwpPlacableLayout() {}
1936 void LwpPlacableLayout::Read()
1938 LwpObjectStream* pStrm = m_pObjStrm.get();
1939 LwpLayout::Read();
1940 if (LwpFileHeader::m_nFileRevision < 0x000B)
1942 assert(false);
1944 else
1946 sal_uInt16 simple = pStrm->QuickReaduInt16();
1947 if (!simple)
1949 m_nWrapType = pStrm->QuickReaduInt8();
1950 m_nBuoyancy = pStrm->QuickReaduInt8();
1951 m_nBaseLineOffset = pStrm->QuickReadInt32();
1952 m_Script.Read(pStrm);
1954 else
1956 m_nWrapType = LAY_WRAP_AROUND;
1957 m_nBuoyancy = LAY_BUOYNEUTRAL;
1958 m_nBaseLineOffset = 0;
1960 m_LayRelativity.ReadIndexed(pStrm);
1961 if (pStrm->CheckExtra())
1963 sal_uInt16 count = pStrm->QuickReaduInt16();
1964 if (count)
1966 // temporarily added by to avoid assertion
1967 while (count)
1969 LwpPoint aPoint;
1970 aPoint.Read(pStrm);
1971 count--;
1974 pStrm->SkipExtra();
1979 * @descr: get wrap type
1981 sal_uInt8 LwpPlacableLayout::GetWrapType()
1983 if (m_bGettingWrapType)
1984 throw std::runtime_error("recursion in layout");
1985 m_bGettingWrapType = true;
1986 sal_uInt8 nWrapType = LAY_WRAP_AROUND;
1987 if (m_nOverrideFlag & OVER_PLACEMENT)
1989 nWrapType = m_nWrapType;
1991 else
1993 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
1994 if (LwpPlacableLayout* pLay = dynamic_cast<LwpPlacableLayout*>(xBase.get()))
1996 nWrapType = pLay->GetWrapType();
1999 m_bGettingWrapType = false;
2000 return nWrapType;
2003 * @descr: get LayoutRelativity
2005 LwpLayoutRelativity* LwpPlacableLayout::GetRelativityPiece()
2007 if (m_bGettingLayoutRelativity)
2008 throw std::runtime_error("recursion in layout");
2009 m_bGettingLayoutRelativity = true;
2010 LwpLayoutRelativity* pRet = nullptr;
2011 if (!m_LayRelativity.IsNull())
2013 if (m_nOverrideFlag & OVER_PLACEMENT)
2015 pRet = dynamic_cast<LwpLayoutRelativity*>(m_LayRelativity.obj().get());
2018 else
2020 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
2021 if (LwpPlacableLayout* pLay = dynamic_cast<LwpPlacableLayout*>(xBase.get()))
2023 pRet = pLay->GetRelativityPiece();
2026 m_bGettingLayoutRelativity = false;
2027 return pRet;
2030 * @descr: Get relative type
2033 sal_uInt8 LwpPlacableLayout::GetRelativeType()
2035 LwpLayoutRelativity* pLayRel = GetRelativityPiece();
2036 if (pLayRel)
2038 return pLayRel->GetRelGuts().GetRelativeType();
2040 return LwpVirtualLayout::GetRelativeType();
2043 * @descr: Get offset from the baseline
2046 sal_Int32 LwpPlacableLayout::GetBaseLineOffset()
2048 /* The baseline is only valid if this is flow-with-text */
2049 if (GetRelativeType() != LwpLayoutRelativityGuts::LAY_INLINE)
2051 return 0;
2054 // First, ask our content if it has a baseline, ignore now
2056 if (Content && Content->GetBaseLineOffset(&Baseline))
2057 return Baseline;
2060 if (m_nOverrideFlag & OVER_PLACEMENT)
2062 return m_nBaseLineOffset;
2064 else
2066 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
2067 if (LwpPlacableLayout* pLay = dynamic_cast<LwpPlacableLayout*>(xBase.get()))
2069 return pLay->GetBaseLineOffset();
2072 return 0;
2075 * @descr: whether the parent layout is page layout
2078 bool LwpPlacableLayout::IsAnchorPage()
2080 if (IsRelativeAnchored())
2081 return false;
2083 rtl::Reference<LwpVirtualLayout> xLayout = GetParentLayout();
2084 return xLayout.is() && (xLayout->IsPage() || xLayout->IsHeader() || xLayout->IsFooter());
2087 * @descr: whether the parent layout is frame layout
2090 bool LwpPlacableLayout::IsAnchorFrame()
2092 if (IsRelativeAnchored())
2093 return false;
2095 rtl::Reference<LwpVirtualLayout> xLayout = GetParentLayout();
2096 return xLayout.is() && (xLayout->IsFrame() || xLayout->IsGroupHead());
2099 * @descr: whether the parent layout is cell layout
2102 bool LwpPlacableLayout::IsAnchorCell()
2104 if (IsRelativeAnchored())
2105 return false;
2107 rtl::Reference<LwpVirtualLayout> xLayout = GetParentLayout();
2108 return xLayout.is() && xLayout->IsCell();
2112 * @descr: Set font style for setting position of frame
2115 void LwpPlacableLayout::SetFont(rtl::Reference<XFFont> const& pFont) { m_pFont = pFont; }
2117 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */