build fix
[LibreOffice.git] / lotuswordpro / source / filter / lwplayout.cxx
blob3f7aeda23cd4d3b082bdb5743da13a9a21be3ef0
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 "lwplayout.hxx"
62 #include "lwpusewhen.hxx"
63 #include "lwptools.hxx"
64 #include "lwplaypiece.hxx"
65 #include "xfilter/xfcolumns.hxx"
66 #include "lwpstory.hxx"
67 #include "lwpparastyle.hxx"
68 #include "lwpholder.hxx"
69 #include "lwpdoc.hxx"
70 #include "lwppagehint.hxx"
71 #include "lwpdivinfo.hxx"
72 #include "lwpgrfobj.hxx"
73 #include <osl/thread.h>
75 LwpVirtualLayout::LwpVirtualLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
76 : LwpDLNFPVList(objHdr, pStrm)
77 , m_bGettingHonorProtection(false)
78 , m_bGettingMarginsSameAsParent(false)
79 , m_bGettingHasProtection(false)
80 , m_bGettingIsProtected(false)
81 , m_bGettingIsAutoGrowDown(false)
82 , m_bGettingMarginsValue(false)
83 , m_bGettingExtMarginsValue(false)
84 , m_nAttributes(0)
85 , m_nAttributes2(0)
86 , m_nAttributes3(0)
87 , m_nOverrideFlag(0)
88 , m_nDirection(0)
89 , m_nEditorID(0)
93 void LwpVirtualLayout::Read()
95 LwpDLNFPVList::Read();
97 LwpObjectStream* pStrm = m_pObjStrm.get();
98 m_nAttributes = pStrm->QuickReaduInt32();
99 m_nAttributes2 = pStrm->QuickReaduInt32();
100 m_nAttributes3 = pStrm->QuickReaduInt32();
101 m_nOverrideFlag = pStrm->QuickReaduInt32();
102 m_nDirection = pStrm->QuickReaduInt16();
104 //Note that two bytes is read into m_nEditorID instead of one byte.
105 m_nEditorID = pStrm->QuickReaduInt16();
107 m_NextEnumerated.ReadIndexed(pStrm);
108 m_PreviousEnumerated.ReadIndexed(pStrm);
110 pStrm->SkipExtra();
113 bool LwpVirtualLayout::MarginsSameAsParent()
115 return (m_nAttributes2 & STYLE2_MARGINSSAMEASPARENT) != 0;
119 * @descr: Get column width
122 double LwpVirtualLayout::GetColWidth(sal_uInt16 /*nIndex*/)
124 //return GetContentWidth(); //not support now
125 //return LwpTools::ConvertToMetric(5); //test
126 return 0; //test
130 * @descr: Get the gap between columns
133 double LwpVirtualLayout::GetColGap(sal_uInt16 /*nIndex*/)
135 //return DEFAULTGAPSIZE;
136 //return LwpTools::ConvertToMetric(0.17);//DEFAULTGAPSIZE=0.17
137 return LwpTools::ConvertToMetric(0.17);
141 * @descr: Whether it is honoring protection
144 bool LwpVirtualLayout::HonorProtection()
146 if(!(m_nAttributes2 & STYLE2_HONORPROTECTION))
147 return false;
149 rtl::Reference<LwpVirtualLayout> xParent(dynamic_cast<LwpVirtualLayout*>(GetParent().obj().get()));
150 if (xParent.is() && !xParent->IsHeader())
152 return xParent->GetHonorProtection();
155 if(m_pFoundry)//is null now
157 LwpDocument* pDoc = m_pFoundry->GetDocument();
158 if(pDoc && pDoc->GetRootDocument())
159 return pDoc->GetRootDocument()->GetHonorProtection();
162 return true;
166 * @descr: Whether it is protected
169 bool LwpVirtualLayout::IsProtected()
171 bool bProtected = (m_nAttributes & STYLE_PROTECTED)!=0;
173 rtl::Reference<LwpVirtualLayout> xParent(dynamic_cast<LwpVirtualLayout*>(GetParent().obj().get()));
174 if (xParent.is() && !xParent->IsHeader())
176 if (xParent->GetHonorProtection() && (xParent->GetHasProtection()||bProtected))
178 return true;
181 else if(m_pFoundry)//is null now
183 LwpDocument* pDoc = m_pFoundry->GetDocument();
184 if(pDoc)
186 if (pDoc->GetHonorProtection() && bProtected)
188 return true;
193 return false;
197 * @descr: Whether it has protection
200 bool LwpVirtualLayout::HasProtection()
202 if(m_nAttributes & STYLE_PROTECTED)
203 return true;
205 rtl::Reference<LwpVirtualLayout> xParent(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()
220 return (m_nAttributes & STYLE_COMPLEX) != 0;
224 * @descr: Get usewhen pointer
227 LwpUseWhen* LwpVirtualLayout::GetUseWhen()
230 If we have a parent, and I'm not a page layout,
231 use my parents information.
233 if(GetLayoutType()!=LWP_PAGE_LAYOUT)
235 //get parent
236 rtl::Reference<LwpVirtualLayout> xParent(dynamic_cast<LwpVirtualLayout*>(GetParent().obj().get()));
237 if (xParent.is() && !xParent->IsHeader() && (xParent->GetLayoutType() != LWP_PAGE_LAYOUT))
238 return xParent->GetUseWhen();
242 return VirtualGetUseWhen();
245 * @descr: Whether this layout is page layout or not
247 bool LwpVirtualLayout::IsPage()
249 return (GetLayoutType() == LWP_PAGE_LAYOUT);
252 * @descr: Whether this layout is header layout or not
254 bool LwpVirtualLayout::IsHeader()
256 return (GetLayoutType() == LWP_HEADER_LAYOUT);
259 * @descr: Whether this layout is footer layout or not
261 bool LwpVirtualLayout::IsFooter()
263 return (GetLayoutType() == LWP_FOOTER_LAYOUT);
266 * @descr: Whether this layout is frame layout or not
268 bool LwpVirtualLayout::IsFrame()
270 return (GetLayoutType() == LWP_FRAME_LAYOUT);
274 * @descr: Whether this layout is cell layout or not
276 bool LwpVirtualLayout::IsCell()
278 return (GetLayoutType() == LWP_CELL_LAYOUT
279 || GetLayoutType() == LWP_CONNECTED_CELL_LAYOUT
280 || GetLayoutType() == LWP_HIDDEN_CELL_LAYOUT);
283 * @descr: Whether this layout is supertable layout or not
285 bool LwpVirtualLayout::IsSuperTable()
287 return (GetLayoutType() == LWP_SUPERTABLE_LAYOUT);
290 * @descr: Whether this layout is group layout or not
292 bool LwpVirtualLayout::IsGroupHead()
294 return (GetLayoutType() == LWP_GROUP_LAYOUT);
297 * @descr: get the relative type
299 sal_uInt8 LwpVirtualLayout::GetRelativeType()
301 return LwpLayoutRelativityGuts::LAY_PARENT_RELATIVE;
304 * @descr: whether it is relative anchored layout
306 bool LwpVirtualLayout::IsRelativeAnchored()
308 sal_uInt8 nType;
310 nType = GetRelativeType();
311 return (nType == LwpLayoutRelativityGuts::LAY_PARA_RELATIVE) || (nType == LwpLayoutRelativityGuts::LAY_INLINE)
312 || (nType == LwpLayoutRelativityGuts::LAY_INLINE_NEWLINE) || (nType == LwpLayoutRelativityGuts::LAY_INLINE_VERTICAL);
315 * @descr: whether it is MinimumHeight layout
317 bool LwpVirtualLayout::IsMinimumHeight()
319 return ((m_nAttributes3& STYLE3_MINHEIGHTVALID) != 0);
323 * @descr: Get parent layout
326 rtl::Reference<LwpVirtualLayout> LwpVirtualLayout::GetParentLayout()
328 return rtl::Reference<LwpVirtualLayout>(dynamic_cast<LwpVirtualLayout*>(GetParent().obj().get()));
332 * @descr: Register child layout style
335 void LwpVirtualLayout::RegisterChildStyle()
337 //Register all children styles
338 rtl::Reference<LwpVirtualLayout> xLayout(dynamic_cast<LwpVirtualLayout*>(GetChildHead().obj().get()));
339 while (xLayout.is())
341 xLayout->SetFoundry(m_pFoundry);
342 xLayout->RegisterStyle();
343 xLayout.set(dynamic_cast<LwpVirtualLayout*>(xLayout->GetNext().obj().get()));
347 bool LwpVirtualLayout::NoContentReference()
349 return (m_nAttributes2 & STYLE2_NOCONTENTREFERENCE) != 0;
352 bool LwpVirtualLayout::IsStyleLayout()
354 if (m_nAttributes3 & STYLE3_STYLELAYOUT)
355 return true;
357 rtl::Reference<LwpVirtualLayout> xParent(dynamic_cast<LwpVirtualLayout*>(GetParent().obj().get()));
358 if (xParent.is())
359 return xParent->IsStyleLayout();
360 return false;
364 * @descr: Find child layout by layout type
367 LwpVirtualLayout* LwpVirtualLayout::FindChildByType(LWP_LAYOUT_TYPE eType)
369 LwpObjectID& rID = GetChildHead();
371 while(!rID.IsNull())
373 LwpVirtualLayout * pLayout = dynamic_cast<LwpVirtualLayout *>(rID.obj().get());
374 if(!pLayout)
376 break;
379 if (pLayout && pLayout->GetLayoutType() == eType)
381 return pLayout;
383 rID = pLayout->GetNext();
386 return nullptr;
390 * @descr: Whether the size of layout is fit the graphic
393 bool LwpVirtualLayout::IsFitGraphic()
395 return IsAutoGrowRight() && !IsAutoGrowLeft() && GetIsAutoGrowDown();
399 * @descr: Whether the width of layout is auto grow
402 bool LwpVirtualLayout::IsAutoGrowWidth()
404 return IsAutoGrowLeft() || IsAutoGrowRight();
408 * @descr: Determine whether the layout width is to margin
411 bool LwpVirtualLayout::IsInlineToMargin()
413 return (m_nAttributes3 & STYLE3_INLINETOMARGIN) != 0;
416 void LwpAssociatedLayouts::Read(LwpObjectStream* pStrm)
418 m_OnlyLayout.ReadIndexed(pStrm);
419 m_Layouts.Read(pStrm);
420 pStrm->SkipExtra();
424 * @descr: Looking for the layout which follows the pStartLayout
425 * @param: pStartLayout - the layout which is used for looking for its following layout
427 rtl::Reference<LwpVirtualLayout> LwpAssociatedLayouts::GetLayout(LwpVirtualLayout *pStartLayout)
429 if (!pStartLayout && !m_OnlyLayout.IsNull())
430 /* Looking for the first layout and there's only one layout in the list.*/
431 return rtl::Reference<LwpVirtualLayout>(dynamic_cast<LwpVirtualLayout*>(m_OnlyLayout.obj().get()));
433 rtl::Reference<LwpObjectHolder> xObjHolder(dynamic_cast<LwpObjectHolder*>(m_Layouts.GetHead().obj().get()));
434 if (xObjHolder.is())
436 rtl::Reference<LwpVirtualLayout> xLayout(dynamic_cast<LwpVirtualLayout*>(xObjHolder->GetObject().obj().get()));
437 if (!pStartLayout)
438 return xLayout;
440 while (xObjHolder.is() && pStartLayout != xLayout.get())
442 xObjHolder.set(dynamic_cast<LwpObjectHolder*>(xObjHolder->GetNext().obj().get()));
443 if (xObjHolder.is())
445 xLayout.set(dynamic_cast<LwpVirtualLayout*>(xObjHolder->GetObject().obj().get()));
449 if (xObjHolder.is())
451 xObjHolder.set(dynamic_cast<LwpObjectHolder*>(xObjHolder->GetNext().obj().get()));
452 if (xObjHolder.is())
454 xLayout.set(dynamic_cast<LwpVirtualLayout*>(xObjHolder->GetObject().obj().get()));
455 return xLayout;
460 return rtl::Reference<LwpVirtualLayout>();
463 LwpHeadLayout::LwpHeadLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
464 : LwpVirtualLayout(objHdr, pStrm)
467 void LwpHeadLayout::Read()
469 LwpVirtualLayout::Read();
470 //For PermissiveLayout
471 m_pObjStrm->SkipExtra();
472 //For me
473 m_pObjStrm->SkipExtra();
476 void LwpHeadLayout::RegisterStyle()
478 //Register all children styles
479 rtl::Reference<LwpVirtualLayout> xLayout(dynamic_cast<LwpVirtualLayout*>(GetChildHead().obj().get()));
480 while (xLayout.is())
482 xLayout->SetFoundry(m_pFoundry);
483 //if the layout is relative to para, the layout will be registered in para
484 if (!xLayout->IsRelativeAnchored())
486 if (xLayout.get() == this)
488 OSL_FAIL("Layout points to itself");
489 break;
491 xLayout->DoRegisterStyle();
493 rtl::Reference<LwpVirtualLayout> xNext(dynamic_cast<LwpVirtualLayout*>(xLayout->GetNext().obj().get()));
494 if (xNext.get() == xLayout.get())
496 OSL_FAIL("Layout points to itself");
497 break;
499 xLayout = xNext;
504 * @descr find endnote supertable layout from the child layout list. Suppose that there is only one endnote supertablelayout in one division
505 * @return pointer to endnote supertable layout
507 rtl::Reference<LwpVirtualLayout> LwpHeadLayout::FindEnSuperTableLayout()
509 rtl::Reference<LwpVirtualLayout> xLayout(dynamic_cast<LwpVirtualLayout*>(GetChildHead().obj().get()));
510 while (xLayout.get())
512 if (xLayout->GetLayoutType() == LWP_ENDNOTE_SUPERTABLE_LAYOUT)
514 return xLayout;
516 xLayout.set(dynamic_cast<LwpVirtualLayout*>(xLayout->GetNext().obj().get()));
518 return rtl::Reference<LwpVirtualLayout>();
521 LwpLayoutStyle::LwpLayoutStyle()
522 : m_nStyleDefinition(0)
523 , m_pDescription(new LwpAtomHolder)
524 , m_nKey(0)
528 LwpLayoutStyle::~LwpLayoutStyle()
532 void LwpLayoutStyle::Read(LwpObjectStream* pStrm)
534 m_nStyleDefinition = pStrm->QuickReaduInt32();
535 m_pDescription->Read(pStrm);
536 if (pStrm->CheckExtra())
538 m_nKey = pStrm->QuickReaduInt16();
539 pStrm->SkipExtra();
543 LwpLayoutMisc::LwpLayoutMisc() :
544 m_nGridDistance(0), m_nGridType(0),
545 m_pContentStyle(new LwpAtomHolder)
549 LwpLayoutMisc::~LwpLayoutMisc()
551 if (m_pContentStyle)
553 delete m_pContentStyle;
557 void LwpLayoutMisc::Read(LwpObjectStream* pStrm)
559 m_nGridType = pStrm->QuickReaduInt16();
560 m_nGridDistance = pStrm->QuickReadInt32();
561 m_pContentStyle->Read(pStrm);
562 pStrm->SkipExtra();
565 LwpMiddleLayout::LwpMiddleLayout( LwpObjectHeader &objHdr, LwpSvStream* pStrm )
566 : LwpVirtualLayout(objHdr, pStrm)
567 , m_pStyleStuff(new LwpLayoutStyle)
568 , m_pMiscStuff(new LwpLayoutMisc)
569 , m_bGettingGeometry(false)
573 LwpMiddleLayout::~LwpMiddleLayout()
575 if (m_pStyleStuff)
577 delete m_pStyleStuff;
579 if (m_pMiscStuff)
581 delete m_pMiscStuff;
584 void LwpMiddleLayout::Read()
586 LwpObjectStream* pStrm = m_pObjStrm.get();
588 LwpVirtualLayout::Read();
590 //skip CLiteLayout data;
591 LwpAtomHolder ContentClass;
592 ContentClass.Read(pStrm);
593 pStrm->SkipExtra();
595 // before layout hierarchy rework
596 if(LwpFileHeader::m_nFileRevision < 0x000B)
597 return;
599 m_Content.ReadIndexed(pStrm);
601 // 01/20/2005
602 m_BasedOnStyle.ReadIndexed(pStrm);
603 m_TabPiece.ReadIndexed(pStrm);
605 sal_uInt8 nWhatsItGot = pStrm->QuickReaduInt8();
607 if (nWhatsItGot & DISK_GOT_STYLE_STUFF)
609 m_pStyleStuff->Read(pStrm);
611 if (nWhatsItGot & DISK_GOT_MISC_STUFF)
613 m_pMiscStuff->Read(pStrm);
616 m_LayGeometry.ReadIndexed(pStrm);
617 m_LayScale.ReadIndexed(pStrm);
618 m_LayMargins.ReadIndexed(pStrm);
619 m_LayBorderStuff.ReadIndexed(pStrm);
620 m_LayBackgroundStuff.ReadIndexed(pStrm);
622 if (pStrm->CheckExtra())
624 m_LayExtBorderStuff.ReadIndexed(pStrm);
625 pStrm->SkipExtra();
629 rtl::Reference<LwpObject> LwpMiddleLayout::GetBasedOnStyle()
631 rtl::Reference<LwpObject> xRet(m_BasedOnStyle.obj());
632 if (xRet.get() == this)
634 SAL_WARN("lwp", "style based on itself");
635 return rtl::Reference<LwpObject>();
637 return xRet;
641 * @descr: Get the geometry of current layout
644 LwpLayoutGeometry* LwpMiddleLayout::Geometry()
646 if( !m_LayGeometry.IsNull() )
648 return ( dynamic_cast<LwpLayoutGeometry*> (m_LayGeometry.obj().get()) );
650 else
652 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
653 if (LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*>(xBase.get()))
655 return pLay->GetGeometry();
658 return nullptr;
662 * @descr: Get layout height, measured by "cm"
665 double LwpMiddleLayout::GetGeometryHeight()
667 LwpLayoutGeometry* pGeo = GetGeometry();
668 if(pGeo)
670 return ( LwpTools::ConvertFromUnitsToMetric( pGeo->GetHeight() ) );
672 else
673 return -1;
677 * @descr: Get layout width, measured by "cm"
680 double LwpMiddleLayout::GetGeometryWidth()
682 LwpLayoutGeometry* pGeo = GetGeometry();
683 if(pGeo)
685 return ( LwpTools::ConvertFromUnitsToMetric( pGeo->GetWidth() ) );
687 else
688 return -1;
692 * @descr: Whether the margins is same as parent layout
695 bool LwpMiddleLayout::MarginsSameAsParent()
697 if(m_nOverrideFlag & OVER_MARGINS)
699 return LwpVirtualLayout::MarginsSameAsParent();
701 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
702 if (LwpVirtualLayout* pLay = dynamic_cast<LwpVirtualLayout*>(xBase.get()))
704 pLay->GetMarginsSameAsParent();
706 return LwpVirtualLayout::MarginsSameAsParent();
710 * @descr: Get margin
711 * @param: nWhichSide - 0: left, 1: right, 2:top, 3: bottom
713 double LwpMiddleLayout::MarginsValue(sal_uInt8 nWhichSide)
715 double fValue = 0;
716 if((nWhichSide==MARGIN_LEFT)||(nWhichSide==MARGIN_RIGHT))
718 if ( GetMarginsSameAsParent() )
720 rtl::Reference<LwpVirtualLayout> xParent(dynamic_cast<LwpVirtualLayout*>(GetParent().obj().get()));
721 if (xParent.is() && !xParent->IsHeader())
723 fValue = xParent->GetMarginsValue(nWhichSide);
724 return fValue;
729 if(m_nOverrideFlag & OVER_MARGINS)
731 LwpLayoutMargins* pMar1 = dynamic_cast<LwpLayoutMargins*> (m_LayMargins.obj().get());
732 if(pMar1)
734 fValue = pMar1->GetMargins().GetMarginsValue(nWhichSide);
735 return fValue;
738 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
739 LwpVirtualLayout* pStyle = dynamic_cast<LwpVirtualLayout*>(xBase.get());
740 if (pStyle)
742 fValue = pStyle->GetMarginsValue(nWhichSide);
743 return fValue;
745 return LwpVirtualLayout::MarginsValue(nWhichSide);
748 * @descr: Get extmargin value
749 * @param: nWhichSide - 0: left, 1: right, 2:top, 3: bottom
750 * @param:
751 * @return:
753 double LwpMiddleLayout::ExtMarginsValue(sal_uInt8 nWhichSide)
755 double fValue = 0;
756 if(m_nOverrideFlag & OVER_MARGINS)
758 LwpLayoutMargins* pMar1 = dynamic_cast<LwpLayoutMargins*> (m_LayMargins.obj().get());
759 if(pMar1)
761 fValue = pMar1->GetExtMargins().GetMarginsValue(nWhichSide);
762 return fValue;
765 LwpVirtualLayout* pStyle = dynamic_cast<LwpVirtualLayout*>(GetBasedOnStyle().get());
766 if(pStyle)
768 fValue = pStyle->GetExtMarginsValue(nWhichSide);
769 return fValue;
771 return LwpVirtualLayout::ExtMarginsValue(nWhichSide);
774 * @descr: Get the LwpBorderStuff object according to m_LayBorderStuff id.
776 LwpBorderStuff* LwpMiddleLayout::GetBorderStuff()
778 if(m_nOverrideFlag & OVER_BORDERS)
780 LwpLayoutBorder* pLayoutBorder = dynamic_cast<LwpLayoutBorder*>(m_LayBorderStuff.obj().get());
781 return pLayoutBorder ? &pLayoutBorder->GetBorderStuff() : nullptr;
783 else
785 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
786 if (LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*>(xBase.get()))
788 return pLay->GetBorderStuff();
791 return nullptr;
795 * @descr: Get LwpBackgroundStuff object according to m_LayBackgroundStuff id;
797 LwpBackgroundStuff* LwpMiddleLayout::GetBackgroundStuff()
799 if(m_nOverrideFlag & OVER_BACKGROUND)
801 LwpLayoutBackground* pLayoutBackground = dynamic_cast<LwpLayoutBackground*>(m_LayBackgroundStuff.obj().get());
802 return pLayoutBackground ? &pLayoutBackground->GetBackgoudStuff() : nullptr;
804 else
806 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
807 if (LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*>(xBase.get()))
809 return pLay->GetBackgroundStuff();
812 return nullptr;
815 * @descr: create xfborder.
817 XFBorders* LwpMiddleLayout::GetXFBorders()
819 LwpBorderStuff* pBorderStuff = GetBorderStuff();
820 if(pBorderStuff&&pBorderStuff->GetSide() != 0)
822 //copy from lwpparastyle.
823 XFBorders *pXFBorders = new XFBorders();
824 // apply 4 borders respectively
825 LwpBorderStuff::BorderType pType[] = { LwpBorderStuff::LEFT, LwpBorderStuff::RIGHT,
826 LwpBorderStuff::TOP, LwpBorderStuff::BOTTOM };
828 for (LwpBorderStuff::BorderType & nC : pType)
830 if (pBorderStuff->HasSide(nC))
832 LwpParaStyle::ApplySubBorder(pBorderStuff, nC, pXFBorders);
835 return pXFBorders;
837 return nullptr;
841 * @descr: Get text direction settings.
843 enumXFTextDir LwpMiddleLayout::GetTextDirection()
845 enumXFTextDir eTextDir = enumXFTextDirNone;
846 sal_uInt8 nDirection = GetContentOrientation();
847 switch(nDirection)
849 case TEXT_ORIENT_LRTB:
851 eTextDir = enumXFTextDirLR_TB;
852 break;
854 case TEXT_ORIENT_TBRL:
856 eTextDir = enumXFTextDirTB_RL;
857 break;
859 case TEXT_ORIENT_RLBT: // not supported now
861 eTextDir = enumXFTextDirNone;
862 break;
864 case TEXT_ORIENT_BTLR: // not supported now
866 eTextDir = enumXFTextDirNone;
867 break;
869 default:
870 break;
872 return eTextDir;
875 * @descr: Get back ground color.
877 LwpColor* LwpMiddleLayout::GetBackColor()
879 LwpBackgroundStuff* pBackgroundStuff = GetBackgroundStuff();
880 if(pBackgroundStuff && !pBackgroundStuff->IsTransparent())
882 LwpColor* pColor = pBackgroundStuff->GetFillColor();
883 if(pColor->IsValidColor())
885 return pColor;
888 return nullptr;
892 * @descr: Add back color settings into xfpagemaster.
894 LwpTabOverride* LwpMiddleLayout::GetTabOverride()
896 if(m_nAttributes & OVER_TABS)
898 if(!m_TabPiece.IsNull())
900 LwpTabPiece *pPiece = dynamic_cast<LwpTabPiece*>(m_TabPiece.obj().get());
901 return static_cast<LwpTabOverride*>(pPiece ? pPiece->GetOverride() : nullptr);
903 return nullptr;
905 else
907 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
908 if (LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*>(xBase.get()))
910 return pLay->GetTabOverride();
913 return nullptr;
917 * @descr: Layscale for graphic & watermark
919 sal_uInt16 LwpMiddleLayout::GetScaleMode()
921 if ((m_nOverrideFlag & OVER_SCALING) && m_LayScale.obj().is() && GetLayoutScale())
922 return GetLayoutScale()->GetScaleMode();
923 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
924 if (xBase.is())
925 return dynamic_cast<LwpMiddleLayout&>(*xBase.get()).GetScaleMode();
926 else
927 return (LwpLayoutScale::FIT_IN_FRAME | LwpLayoutScale::MAINTAIN_ASPECT_RATIO);
930 sal_uInt16 LwpMiddleLayout::GetScaleTile()
932 if ((m_nOverrideFlag & OVER_SCALING) && m_LayScale.obj().is() && GetLayoutScale())
933 return (GetLayoutScale()->GetPlacement() & LwpLayoutScale::TILED)
934 ? 1 : 0;
935 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
936 if (xBase.is())
937 return dynamic_cast<LwpMiddleLayout&>(*xBase.get()).GetScaleTile();
938 else
939 return 0;
942 sal_uInt16 LwpMiddleLayout::GetScaleCenter()
944 if ((m_nOverrideFlag & OVER_SCALING) && m_LayScale.obj().is() && GetLayoutScale())
946 return (GetLayoutScale()->GetPlacement() & LwpLayoutScale::CENTERED)
947 ? 1 : 0;
949 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
950 if (xBase.is())
951 return dynamic_cast<LwpMiddleLayout&>(*xBase.get()).GetScaleCenter();
952 else
953 return 0;
956 sal_uInt32 LwpMiddleLayout::GetScalePercentage()
958 if ((m_nOverrideFlag & OVER_SCALING) && m_LayScale.obj().is() && GetLayoutScale())
959 return GetLayoutScale()->GetScalePercentage()/10;//m_nScalePercentage 1000 = 100%
960 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
961 if (xBase.is())
962 return dynamic_cast<LwpMiddleLayout&>(*xBase.get()).GetScalePercentage();
963 else
964 return 100;
967 double LwpMiddleLayout::GetScaleWidth()
969 if ((m_nOverrideFlag & OVER_SCALING) && m_LayScale.obj().is() && GetLayoutScale())
970 return LwpTools::ConvertFromUnits(GetLayoutScale()->GetScaleWidth());
971 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
972 if (xBase.is())
973 return dynamic_cast<LwpMiddleLayout&>(*xBase.get()).GetScaleWidth();
974 else
975 return 0;
978 double LwpMiddleLayout::GetScaleHeight()
980 if ((m_nOverrideFlag & OVER_SCALING) && m_LayScale.obj().is() && GetLayoutScale())
981 return LwpTools::ConvertFromUnits(GetLayoutScale()->GetScaleHeight());
982 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
983 if (xBase.is())
984 return dynamic_cast<LwpMiddleLayout&>(*xBase.get()).GetScaleHeight();
985 else
986 return 0;
988 bool LwpMiddleLayout::CanSizeRight()
990 sal_uInt8 RelType = GetRelativeType();
992 if (RelType == LwpLayoutRelativityGuts::LAY_INLINE || RelType == LwpLayoutRelativityGuts::LAY_PARA_RELATIVE
993 || RelType == LwpLayoutRelativityGuts::LAY_INLINE_VERTICAL)
995 return false;
997 return true;
999 sal_Int32 LwpMiddleLayout::GetMinimumWidth()
1001 if (((m_nAttributes3 & STYLE3_WIDTHVALID) != 0) && GetGeometry())
1003 return GetGeometry()->GetWidth();
1005 else if (m_nOverrideFlag & OVER_SIZE)
1007 return DetermineWidth();
1009 return 0;
1011 sal_Int32 LwpMiddleLayout::DetermineWidth()
1013 if (IsSizeRightToContent())
1015 assert(false);
1017 else if (IsSizeRightToContainer())
1019 assert(false);
1021 else if (LwpLayoutGeometry* pGeo = GetGeometry())
1023 m_nAttributes3 |= STYLE3_WIDTHVALID;
1024 return pGeo->GetWidth();
1026 return 0;
1028 bool LwpMiddleLayout::IsSizeRightToContainer()
1030 if (!CanSizeRight())
1031 return false;
1033 if (m_nOverrideFlag & OVER_SIZE)
1035 return (m_nDirection & ((LAY_USEDIRECTION|LAY_AUTOSIZE|LAY_TOCONTAINER)
1036 << SHIFT_RIGHT))
1037 == ((LAY_USEDIRECTION | LAY_TOCONTAINER | LAY_AUTOSIZE) << SHIFT_RIGHT);
1039 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
1040 if (xBase.is())
1042 LwpMiddleLayout * pLayout = dynamic_cast<LwpMiddleLayout *>(xBase.get());
1043 return pLayout && pLayout->IsSizeRightToContainer();
1045 else
1046 return false;
1048 bool LwpMiddleLayout::IsSizeRightToContent()
1050 if (!CanSizeRight())
1051 return false;
1053 if (m_nOverrideFlag & OVER_SIZE)
1055 return (m_nDirection & ((LAY_USEDIRECTION|LAY_AUTOSIZE|LAY_TOCONTAINER)
1056 << SHIFT_RIGHT))
1057 == ((LAY_USEDIRECTION | LAY_AUTOSIZE) << SHIFT_RIGHT);
1059 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
1060 if (xBase.is())
1062 LwpMiddleLayout * pLayout = dynamic_cast<LwpMiddleLayout *>(xBase.get());
1063 return pLayout && pLayout->IsSizeRightToContent();
1065 else
1066 return false;
1070 * @descr: Get layout height
1073 double LwpMiddleLayout::GetHeight()
1075 return GetGeometryHeight();
1079 * @descr: Get layout height
1082 double LwpMiddleLayout::GetWidth()
1084 return GetGeometryWidth();
1087 * @descr: Get layout origin point
1090 LwpPoint LwpMiddleLayout::GetOrigin()
1092 LwpLayoutGeometry* pGeo = GetGeometry();
1093 if(pGeo)
1095 sal_uInt8 nType = GetRelativeType();
1096 if(nType == LwpLayoutRelativityGuts::LAY_INLINE
1097 || nType == LwpLayoutRelativityGuts::LAY_INLINE_NEWLINE )
1099 return pGeo->GetAbsoluteOrigin();
1101 else
1102 return pGeo->GetOrigin();
1106 return LwpPoint();
1110 * @descr: Whether the fill is pattern fill or not
1111 * @return: True if yes, false if not.
1113 bool LwpMiddleLayout::IsPatternFill()
1115 LwpBackgroundStuff* pBackgroundStuff = GetBackgroundStuff();
1116 if (pBackgroundStuff)
1118 return pBackgroundStuff->IsPatternFill();
1121 return false;
1125 * @descr: Get the fill pattern style. Data are saved in a XFBGImage object
1126 * @return: the fill pattern style.
1128 XFBGImage* LwpMiddleLayout::GetFillPattern()
1130 LwpBackgroundStuff* pBackgroundStuff = GetBackgroundStuff();
1131 if (pBackgroundStuff)
1133 return pBackgroundStuff->GetFillPattern();
1136 return nullptr;
1141 * @descr: Whether the height and width of layout is auto grow
1144 bool LwpMiddleLayout::IsAutoGrow()
1146 if(m_nOverrideFlag & OVER_SIZE)
1148 return (m_nDirection &
1149 ((LAY_AUTOGROW << SHIFT_UP) | (LAY_AUTOGROW << SHIFT_DOWN) |
1150 (LAY_AUTOGROW << SHIFT_RIGHT) | (LAY_AUTOGROW << SHIFT_LEFT))) != 0;
1152 else
1154 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
1155 if (LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*>(xBase.get()))
1157 return pLay->IsAutoGrow();
1160 return LwpVirtualLayout::IsAutoGrow();
1164 * @descr: Whether the height of layout is auto grow down
1167 bool LwpMiddleLayout::IsAutoGrowDown()
1169 if(m_nOverrideFlag & OVER_SIZE)
1171 return (m_nDirection & (LAY_AUTOGROW << SHIFT_DOWN)) != 0;
1173 else
1175 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
1176 if (LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*>(xBase.get()))
1178 return pLay->GetIsAutoGrowDown();
1181 return LwpVirtualLayout::IsAutoGrowDown();
1185 * @descr: Whether the height of layout is auto grow up
1188 bool LwpMiddleLayout::IsAutoGrowUp()
1190 if(m_nOverrideFlag & OVER_SIZE)
1192 return (m_nDirection & (LAY_AUTOGROW << SHIFT_UP)) != 0;
1194 else
1196 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
1197 if (LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*>(xBase.get()))
1199 return pLay->IsAutoGrowUp();
1202 return LwpVirtualLayout::IsAutoGrowUp();
1206 * @descr: Whether the height of layout is auto grow down
1209 bool LwpMiddleLayout::IsAutoGrowLeft()
1211 if(m_nOverrideFlag & OVER_SIZE)
1213 return (m_nDirection & (LAY_AUTOGROW << SHIFT_LEFT)) != 0;
1215 else
1217 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
1218 if (LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*>(xBase.get()))
1220 return pLay->IsAutoGrowLeft();
1223 return LwpVirtualLayout::IsAutoGrowLeft();
1227 * @descr: Whether the height of layout is auto grow down
1230 bool LwpMiddleLayout::IsAutoGrowRight()
1232 if(m_nOverrideFlag & OVER_SIZE)
1234 return (m_nDirection & (LAY_AUTOGROW << SHIFT_RIGHT)) != 0;
1236 else
1238 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
1239 if (LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*>(xBase.get()))
1241 return pLay->IsAutoGrowRight();
1244 return LwpVirtualLayout::IsAutoGrowRight();
1248 * @descr: Get contents orientation
1251 sal_uInt8 LwpMiddleLayout::GetContentOrientation()
1253 //content orientation in Graphic objects and OLE objects not supported now
1254 if((m_nOverrideFlag & OVER_ROTATION)&& !m_LayGeometry.IsNull())
1256 LwpLayoutGeometry* pLayGeometry = dynamic_cast<LwpLayoutGeometry*> (m_LayGeometry.obj().get());
1257 if (pLayGeometry)
1258 return pLayGeometry->GetContentOrientation();
1260 else
1262 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
1263 if (LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*>(xBase.get()))
1265 return pLay->GetContentOrientation();
1268 return LwpVirtualLayout::GetContentOrientation();
1272 * @descr: Whether it is honoring protection
1275 bool LwpMiddleLayout::HonorProtection()
1277 if(m_nOverrideFlag & OVER_MISC)
1279 if(!(m_nAttributes2 & STYLE2_HONORPROTECTION))
1280 return false;
1282 rtl::Reference<LwpVirtualLayout> xParent(dynamic_cast<LwpVirtualLayout*>(GetParent().obj().get()));
1283 if (xParent.is() && !xParent->IsHeader())
1285 return xParent->GetHonorProtection();
1288 if(m_pFoundry)//is null now
1290 LwpDocument* pDoc = m_pFoundry->GetDocument();
1291 if (pDoc)
1293 return pDoc->GetHonorProtection();
1297 else
1299 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
1300 if (LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*>(xBase.get()))
1302 return pLay->GetHonorProtection();
1306 return LwpVirtualLayout::HonorProtection();
1310 * @descr: Whether it is protected
1313 bool LwpMiddleLayout::IsProtected()
1315 bool bProtected = false;
1316 if(m_nOverrideFlag & OVER_MISC)
1318 bProtected = (m_nAttributes & STYLE_PROTECTED)!=0;
1320 else
1322 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
1323 if (LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*>(xBase.get()))
1325 bProtected = pLay->GetIsProtected();
1327 else
1328 bProtected = LwpVirtualLayout::IsProtected();
1331 rtl::Reference<LwpVirtualLayout> xParent(dynamic_cast<LwpVirtualLayout*>(GetParent().obj().get()));
1332 if (xParent.is() && !xParent->IsHeader())
1334 /* If a parent's protected then none of its children can be accessed. */
1335 if (xParent->GetIsProtected())
1336 return true;
1338 if (xParent->GetHonorProtection())
1339 return bProtected;
1341 /* If our parent isn't honoring protection then we aren't protected. */
1342 return false;
1345 if(m_pFoundry)//is null now
1347 LwpDocument* pDoc = m_pFoundry->GetDocument();
1348 if(pDoc)
1350 if (pDoc->GetHonorProtection())
1351 return bProtected;
1353 /* If the document isn't honoring protection then we aren't protected.*/
1354 return false;
1358 return bProtected;
1362 * @descr: Get watermark layout
1365 rtl::Reference<LwpVirtualLayout> LwpMiddleLayout::GetWaterMarkLayout()
1367 rtl::Reference<LwpVirtualLayout> xLay(dynamic_cast<LwpVirtualLayout*>(GetChildHead().obj().get()));
1368 while (xLay.is())
1370 if (xLay->IsForWaterMark())
1372 return xLay;
1374 xLay.set(dynamic_cast<LwpVirtualLayout*>(xLay->GetNext().obj().get()));
1376 return rtl::Reference<LwpVirtualLayout>();
1380 * @descr: Create and reture xfbgimage object for watermark
1383 XFBGImage* LwpMiddleLayout::GetXFBGImage()
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 XFBGImage* pXFBGImage = new XFBGImage();
1395 if(pGrfObj->IsLinked())
1397 //set file link
1398 OUString linkedfilepath = pGrfObj->GetLinkedFilePath();
1399 OUString fileURL = LwpTools::convertToFileUrl(OUStringToOString(linkedfilepath, osl_getThreadTextEncoding()));
1400 pXFBGImage->SetFileLink(fileURL);
1402 else
1404 sal_uInt8* pGrafData = nullptr;
1405 sal_uInt32 nDataLen = pGrfObj->GetRawGrafData(pGrafData);
1406 pXFBGImage->SetImageData(pGrafData, nDataLen);
1407 if(pGrafData)
1409 delete[] pGrafData;
1410 pGrafData = nullptr;
1414 //automatic, top left
1415 pXFBGImage->SetPosition(enumXFAlignStart,enumXFAlignTop);
1416 if(pLay->GetScaleCenter())
1418 //center
1419 pXFBGImage->SetPosition();
1421 else if(pLay->GetScaleTile())
1423 //tile
1424 pXFBGImage->SetRepeate();
1426 //fit type, area type
1427 if((pLay->GetScaleMode()& LwpLayoutScale::FIT_IN_FRAME)!=0)
1429 if((pLay->GetScaleMode()& LwpLayoutScale::MAINTAIN_ASPECT_RATIO)==0)
1431 pXFBGImage->SetStretch();
1434 return pXFBGImage;
1437 return nullptr;
1441 * @descr: Whether the page uses the printer setting
1444 bool LwpMiddleLayout::GetUsePrinterSettings()
1446 if(m_nOverrideFlag & OVER_SIZE)
1448 return (m_nAttributes3 & STYLE3_USEPRINTERSETTINGS) != 0;
1450 else
1452 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
1453 if (LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*>(xBase.get()))
1455 return pLay->GetUsePrinterSettings();
1458 return false;
1461 //Check whether there are contents in the layout
1462 bool LwpMiddleLayout::HasContent()
1464 rtl::Reference<LwpObject> content = m_Content.obj();
1465 if(content.is())
1466 return true;
1467 return false;
1470 LwpLayout::LwpLayout( LwpObjectHeader &objHdr, LwpSvStream* pStrm ) :
1471 LwpMiddleLayout(objHdr, pStrm), m_pUseWhen(new LwpUseWhen)
1474 LwpLayout::~LwpLayout()
1476 if (m_pUseWhen)
1478 delete m_pUseWhen;
1482 void LwpLayout::Read()
1484 LwpObjectStream* pStrm = m_pObjStrm.get();
1486 LwpMiddleLayout::Read();
1487 if (LwpFileHeader::m_nFileRevision < 0x000B)
1489 // read PreRevBLayout...
1491 else
1493 sal_uInt16 nSimple = pStrm->QuickReaduInt16();
1495 if (!nSimple)
1497 m_pUseWhen->Read(pStrm);
1499 sal_uInt8 nFlag = pStrm->QuickReaduInt8();
1500 if (nFlag)
1501 m_Position.ReadIndexed(pStrm);
1504 m_LayColumns.ReadIndexed(pStrm);
1505 m_LayGutterStuff.ReadIndexed(pStrm);
1506 m_LayJoinStuff.ReadIndexed(pStrm);
1507 m_LayShadow.ReadIndexed(pStrm);
1509 if (pStrm->CheckExtra())
1511 m_LayExtJoinStuff.ReadIndexed(pStrm);
1512 pStrm->SkipExtra();
1518 * @descr: Get columns number
1521 sal_uInt16 LwpLayout::GetNumCols()
1523 if(m_nOverrideFlag & OVER_COLUMNS)
1525 LwpLayoutColumns* pLayColumns = dynamic_cast<LwpLayoutColumns*>(m_LayColumns.obj().get());
1526 if(pLayColumns)
1528 return pLayColumns->GetNumCols();
1532 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
1533 LwpVirtualLayout* pStyle = dynamic_cast<LwpVirtualLayout*>(xBase.get());
1534 if (pStyle)
1536 return pStyle->GetNumCols();
1539 return LwpVirtualLayout::GetNumCols();
1544 * @descr: Get column width
1545 * @param: the order of column
1547 double LwpLayout::GetColWidth(sal_uInt16 nIndex)
1549 if((m_nOverrideFlag & OVER_COLUMNS)||(m_nAttributes2 & STYLE2_LOCALCOLUMNINFO))
1551 LwpLayoutColumns* pLayColumns = dynamic_cast<LwpLayoutColumns*>(m_LayColumns.obj().get());
1552 if(pLayColumns)
1554 return pLayColumns->GetColWidth(nIndex);
1558 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
1559 LwpVirtualLayout* pStyle = dynamic_cast<LwpVirtualLayout*>(xBase.get());
1560 if (pStyle)
1562 return pStyle->GetColWidth(nIndex);
1565 return LwpVirtualLayout::GetColWidth(nIndex);
1570 * @descr: Get gap between columns
1571 * @param: the order of column
1573 double LwpLayout::GetColGap(sal_uInt16 nIndex)
1575 if((m_nOverrideFlag & OVER_COLUMNS)||(m_nAttributes2 & STYLE2_LOCALCOLUMNINFO))
1577 LwpLayoutColumns* pLayColumns = dynamic_cast<LwpLayoutColumns*>(m_LayColumns.obj().get());
1578 if(pLayColumns)
1580 return pLayColumns->GetColGap(nIndex);
1584 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
1585 LwpVirtualLayout* pStyle = dynamic_cast<LwpVirtualLayout*>(xBase.get());
1586 if (pStyle)
1588 return pStyle->GetColGap(nIndex);
1591 return LwpVirtualLayout::GetColGap(nIndex);
1595 * @descr: Create and return XFColumns object
1598 XFColumns* LwpLayout::GetXFColumns()
1600 //if there is only one column, do not need insert columns
1601 sal_uInt16 nCols = GetNumCols();
1602 if(nCols==1)
1604 return nullptr;
1607 XFColumns* pColumns = new XFColumns();
1608 //set XFColumnSep
1609 std::unique_ptr<XFColumnSep> pColumnSep(GetColumnSep());
1610 if(pColumnSep)
1612 pColumns->SetSeparator(*pColumnSep);
1615 //set column count and column gap
1616 pColumns->SetCount(nCols);
1617 double fGap = GetColGap(0);
1618 pColumns->SetGap(fGap);
1620 //set xfcolumn
1621 for(sal_uInt16 nIndex = 0; nIndex<nCols; nIndex++)
1623 XFColumn aColumn;
1624 sal_Int32 nWidth = 8305/nCols; //relative width
1625 aColumn.SetRelWidth(nWidth);
1627 //the left and right margins is 0;
1628 double nGap = GetColGap(nIndex)/2;
1629 aColumn.SetMargins(nGap,nGap);
1630 if(nIndex==0)
1632 aColumn.SetMargins(0,nGap);
1634 if(nIndex==(nCols-1))
1636 aColumn.SetMargins(nGap,0);
1638 pColumns->AddColumn(aColumn);
1641 return pColumns;
1645 * @descr: Create and return XFColumnSep object
1648 XFColumnSep* LwpLayout::GetColumnSep()
1651 //Get LwpLayoutGutters
1652 LwpLayoutGutters* pLayoutGutters = dynamic_cast<LwpLayoutGutters*>(m_LayGutterStuff.obj().get());
1653 if(!pLayoutGutters)
1655 return nullptr;
1658 LwpBorderStuff& rBorderStuff = pLayoutGutters->GetBorderStuff();
1660 LwpBorderStuff::BorderType eType = LwpBorderStuff::LEFT;
1661 LwpColor aColor = rBorderStuff.GetSideColor(eType);
1662 double fWidth = rBorderStuff.GetSideWidth(eType);
1663 //sal_uInt16 nType = rBorderStuff->GetSideType(eType);
1665 XFColumnSep* pColumnSep = new XFColumnSep();
1666 XFColor aXFColor(aColor.To24Color());
1667 pColumnSep->SetColor(aXFColor);
1668 pColumnSep->SetWidth(fWidth);
1669 pColumnSep->SetRelHeight(100);
1670 pColumnSep->SetVerticalAlign(enumXFAlignTop);
1672 return pColumnSep;
1676 * @descr: Get use when type
1679 LwpLayout::UseWhenType LwpLayout::GetUseWhenType()
1681 UseWhenType eType = StartWithinPage;
1682 LwpUseWhen* pUseWhen = GetUseWhen();
1683 if(pUseWhen)
1685 if(pUseWhen->IsStartOnThisHF())
1687 eType = StartWithinColume;
1689 else if(pUseWhen->IsStartOnThisPage())
1691 eType = StartWithinPage;
1693 else if(pUseWhen->IsStartOnNextPage())
1695 eType = StartOnNextPage;
1697 else if(pUseWhen->IsStartOnNextOddPage())
1699 eType = StartOnOddPage;
1701 else if(pUseWhen->IsStartOnNextEvenPage())
1703 eType = StartOnEvenPage;
1707 else
1709 eType = StartOnNextPage;
1711 return eType;
1715 * @descr: Get use page
1718 sal_uInt16 LwpLayout::GetUsePage()
1720 if(m_nOverrideFlag & OVER_PLACEMENT)
1722 LwpUseWhen* pUseWhen = GetUseWhen();
1723 if(pUseWhen)
1724 return pUseWhen->GetUsePage();
1725 else
1726 return 0;
1728 else
1730 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
1731 if (LwpLayout* pLay = dynamic_cast<LwpLayout*>(xBase.get()))
1733 return pLay->GetUsePage();
1736 return 0;
1740 * @descr: Get usewhen pointer
1743 LwpUseWhen* LwpLayout::VirtualGetUseWhen()
1745 if(m_nOverrideFlag & OVER_PLACEMENT)
1747 return m_pUseWhen;
1749 else
1751 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
1752 if (LwpLayout* pLay = dynamic_cast<LwpLayout*>(xBase.get()))
1754 return pLay->VirtualGetUseWhen();
1757 return LwpVirtualLayout::VirtualGetUseWhen();
1761 * @descr: Whether it is use on all pages
1764 bool LwpLayout::IsUseOnAllPages()
1766 if(m_nOverrideFlag & OVER_PLACEMENT)
1768 LwpUseWhen* pUseWhen = GetUseWhen();
1769 if(pUseWhen)
1770 return pUseWhen->IsUseOnAllPages();
1771 else
1772 return false;
1774 else
1776 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
1777 if (LwpLayout* pLay = dynamic_cast<LwpLayout*>(xBase.get()))
1779 return pLay->IsUseOnAllPages();
1782 return LwpVirtualLayout::IsUseOnAllPages();
1786 * @descr: Whether it is use on all even pages
1789 bool LwpLayout::IsUseOnAllEvenPages()
1791 if(m_nOverrideFlag & OVER_PLACEMENT)
1793 LwpUseWhen* pUseWhen = GetUseWhen();
1794 if(pUseWhen)
1795 return pUseWhen->IsUseOnAllEvenPages();
1796 else
1797 return false;
1799 else
1801 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
1802 if (LwpLayout* pLay = dynamic_cast<LwpLayout*>(xBase.get()))
1804 return pLay->IsUseOnAllEvenPages();
1807 return LwpVirtualLayout::IsUseOnAllEvenPages();
1811 * @descr: Whether it is use on all odd pages
1814 bool LwpLayout::IsUseOnAllOddPages()
1816 if(m_nOverrideFlag & OVER_PLACEMENT)
1818 LwpUseWhen* pUseWhen = GetUseWhen();
1819 if(pUseWhen)
1820 return pUseWhen->IsUseOnAllOddPages();
1821 else
1822 return false;
1824 else
1826 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
1827 if (LwpLayout* pLay = dynamic_cast<LwpLayout*>(xBase.get()))
1829 return pLay->IsUseOnAllOddPages();
1832 return LwpVirtualLayout::IsUseOnAllOddPages();
1836 * @descr: Whether it is use on current page
1839 bool LwpLayout::IsUseOnPage()
1841 if(m_nOverrideFlag & OVER_PLACEMENT)
1843 LwpUseWhen* pUseWhen = GetUseWhen();
1844 if(pUseWhen)
1845 return pUseWhen->IsUseOnPage();
1846 else
1847 return false;
1849 else
1851 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
1852 if (LwpLayout* pLay = dynamic_cast<LwpLayout*>(xBase.get()))
1854 return pLay->IsUseOnPage();
1857 return LwpVirtualLayout::IsUseOnPage();
1861 * @descr: Get the LwpShadow object according to m_LayShadow id.
1863 LwpShadow* LwpLayout::GetShadow()
1865 if(m_nOverrideFlag & OVER_SHADOW)
1867 LwpLayoutShadow* pLayoutShadow = dynamic_cast<LwpLayoutShadow*>(m_LayShadow.obj().get());
1868 return pLayoutShadow ? &pLayoutShadow->GetShadow() : nullptr;
1870 else
1872 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
1873 if (LwpLayout* pLay = dynamic_cast<LwpLayout*>(xBase.get()))
1875 return pLay->GetShadow();
1878 return nullptr;
1882 * @descr: create xfshadow
1884 XFShadow* LwpLayout::GetXFShadow()
1886 LwpShadow* pShadow = GetShadow();
1887 if( pShadow )
1889 LwpColor color = pShadow->GetColor();
1890 double offsetX = pShadow->GetOffsetX();
1891 double offsetY = pShadow->GetOffsetY();
1893 if( offsetX && offsetY && color.IsValidColor() )
1895 XFShadow* pXFShadow = new XFShadow();
1896 enumXFShadowPos eXFShadowPos = enumXFShadowLeftTop;
1897 double fOffset = 0;
1899 bool left = false;
1900 bool top = false;
1901 if( offsetX < 0 )
1902 left = true;
1903 if( offsetY < 0 )
1904 top = true;
1905 if( left )
1907 fOffset = -offsetX;
1908 if( top )
1909 eXFShadowPos = enumXFShadowLeftTop;
1910 else
1911 eXFShadowPos = enumXFShadowLeftBottom;
1913 else
1915 fOffset = offsetX;
1916 if( top )
1917 eXFShadowPos = enumXFShadowRightTop;
1918 else
1919 eXFShadowPos = enumXFShadowRightBottom;
1922 pXFShadow->SetPosition(eXFShadowPos);
1923 pXFShadow->SetOffset(fOffset);
1924 pXFShadow->SetColor(XFColor(color.To24Color()));
1926 return pXFShadow;
1929 return nullptr;
1933 * @descr get the layout that containers the current frame layout
1936 rtl::Reference<LwpVirtualLayout> LwpLayout::GetContainerLayout()
1938 if(IsRelativeAnchored())
1940 //get position
1941 LwpPara* pPara = dynamic_cast<LwpPara*>(GetPosition().obj().get());
1942 if(pPara)
1944 LwpStory* pStory = pPara->GetStory();
1945 return pStory ? pStory->GetTabLayout() : nullptr;
1948 return GetParentLayout();
1951 LwpPlacableLayout::LwpPlacableLayout( LwpObjectHeader &objHdr, LwpSvStream* pStrm )
1952 : LwpLayout(objHdr, pStrm)
1953 , m_nWrapType(0)
1954 , m_nBuoyancy(0)
1955 , m_nBaseLineOffset(0)
1958 LwpPlacableLayout::~LwpPlacableLayout()
1961 void LwpPlacableLayout::Read()
1963 LwpObjectStream* pStrm = m_pObjStrm.get();
1964 LwpLayout::Read();
1965 if(LwpFileHeader::m_nFileRevision < 0x000B)
1967 assert(false);
1969 else
1971 sal_uInt16 simple = pStrm->QuickReaduInt16();
1972 if(!simple)
1974 m_nWrapType = pStrm->QuickReaduInt8();
1975 m_nBuoyancy = pStrm->QuickReaduInt8();
1976 m_nBaseLineOffset = pStrm->QuickReadInt32();
1977 m_Script.Read( pStrm);
1979 else
1981 m_nWrapType = LAY_WRAP_AROUND;
1982 m_nBuoyancy = LAY_BUOYNEUTRAL;
1983 m_nBaseLineOffset = 0;
1985 m_LayRelativity.ReadIndexed( pStrm);
1986 if(pStrm->CheckExtra())
1988 sal_uInt16 count = pStrm->QuickReaduInt16();
1989 if(count)
1991 // temporily added by to avoid assertion
1992 while (count)
1994 LwpPoint aPoint;
1995 aPoint.Read(pStrm);
1996 count--;
1999 pStrm->SkipExtra();
2004 * @descr: get wrap type
2006 sal_uInt8 LwpPlacableLayout::GetWrapType()
2008 if(m_nOverrideFlag & OVER_PLACEMENT)
2010 return m_nWrapType;
2012 else
2014 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
2015 if (LwpPlacableLayout* pLay = dynamic_cast<LwpPlacableLayout*>(xBase.get()))
2017 return pLay->GetWrapType();
2020 return LAY_WRAP_AROUND;
2023 * @descr: get LayoutRelativity
2025 LwpLayoutRelativity* LwpPlacableLayout::GetRelativityPiece()
2027 if(!m_LayRelativity.IsNull())
2029 if(m_nOverrideFlag & OVER_PLACEMENT)
2031 return dynamic_cast<LwpLayoutRelativity*>(m_LayRelativity.obj().get());
2034 else
2036 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
2037 if (LwpPlacableLayout* pLay = dynamic_cast<LwpPlacableLayout*>(xBase.get()))
2039 return pLay->GetRelativityPiece();
2042 return nullptr;
2045 * @descr: Get relative type
2048 sal_uInt8 LwpPlacableLayout::GetRelativeType()
2050 LwpLayoutRelativity* pLayRel = GetRelativityPiece();
2051 if(pLayRel)
2053 return pLayRel->GetRelGuts().GetRelativeType();
2055 return LwpVirtualLayout::GetRelativeType();
2058 * @descr: Get offset from the baseline
2061 sal_Int32 LwpPlacableLayout::GetBaseLineOffset()
2063 /* The baseline is only valid if this is flow-with-text */
2064 if(GetRelativeType()!=LwpLayoutRelativityGuts::LAY_INLINE)
2066 return 0;
2069 // First, ask our content if it has a baseline, ignore now
2071 if (Content && Content->GetBaseLineOffset(&Baseline))
2072 return Baseline;
2075 if(m_nOverrideFlag & OVER_PLACEMENT)
2077 return m_nBaseLineOffset;
2079 else
2081 rtl::Reference<LwpObject> xBase(GetBasedOnStyle());
2082 if (LwpPlacableLayout* pLay = dynamic_cast<LwpPlacableLayout*>(xBase.get()))
2084 return pLay->GetBaseLineOffset();
2087 return 0;
2091 * @descr: whether the parent layout is page layout
2094 bool LwpPlacableLayout::IsAnchorPage()
2096 if(IsRelativeAnchored())
2097 return false;
2099 rtl::Reference<LwpVirtualLayout> xLayout = GetParentLayout();
2100 if (xLayout.is() && (xLayout->IsPage() || xLayout->IsHeader() || xLayout->IsFooter()))
2102 return true;
2104 return false;
2107 * @descr: whether the parent layout is frame layout
2110 bool LwpPlacableLayout::IsAnchorFrame()
2112 if(IsRelativeAnchored())
2113 return false;
2115 rtl::Reference<LwpVirtualLayout> xLayout = GetParentLayout();
2116 if (xLayout.is() && (xLayout->IsFrame() || xLayout->IsGroupHead()))
2118 return true;
2120 return false;
2123 * @descr: whether the parent layout is cell layout
2126 bool LwpPlacableLayout::IsAnchorCell()
2128 if(IsRelativeAnchored())
2129 return false;
2131 rtl::Reference<LwpVirtualLayout> xLayout = GetParentLayout();
2132 if (xLayout.is() && xLayout->IsCell())
2134 return true;
2136 return false;
2140 * @descr: Set font style for setting position of frame
2143 void LwpPlacableLayout::SetFont(rtl::Reference<XFFont> const & pFont)
2145 m_pFont = pFont;
2148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */