Bump version to 4.3-4
[LibreOffice.git] / lotuswordpro / source / filter / lwplayout.cxx
blobac118a38f8d15d6b723c4ad63ab1046c7bd70568
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 ************************************************************************/
60 /*************************************************************************
61 * Change History
62 Jan 2005 Created
63 Feb 2005 Process gemotry, margins
64 ************************************************************************/
66 #include "lwplayout.hxx"
67 #include "lwpusewhen.hxx"
68 #include "lwptools.hxx"
69 #include "xfilter/xfcolumns.hxx"
70 #include "lwpstory.hxx"
71 #include "lwpparastyle.hxx"
72 #include "lwpholder.hxx"
73 #include "lwpdoc.hxx"
74 #include "lwppagehint.hxx"
75 #include "lwpdivinfo.hxx"
76 #include "lwpgrfobj.hxx"
77 #include <osl/thread.h>
79 LwpVirtualLayout::LwpVirtualLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
80 : LwpDLNFPVList(objHdr, pStrm)
81 , m_nAttributes(0)
82 , m_nAttributes2(0)
83 , m_nAttributes3(0)
84 , m_nOverrideFlag(0)
85 , m_nDirection(0)
86 , m_nEditorID(0)
90 void LwpVirtualLayout::Read()
92 LwpDLNFPVList::Read();
94 LwpObjectStream* pStrm = m_pObjStrm;
95 m_nAttributes = pStrm->QuickReaduInt32();
96 m_nAttributes2 = pStrm->QuickReaduInt32();
97 m_nAttributes3 = pStrm->QuickReaduInt32();
98 m_nOverrideFlag = pStrm->QuickReaduInt32();
99 m_nDirection = pStrm->QuickReaduInt16();
101 //Note that two bytes is read into m_nEditorID instead of one byte.
102 m_nEditorID = pStrm->QuickReaduInt16();
104 m_NextEnumerated.ReadIndexed(pStrm);
105 m_PreviousEnumerated.ReadIndexed(pStrm);
107 pStrm->SkipExtra();
110 bool LwpVirtualLayout::MarginsSameAsParent()
112 return m_nAttributes2 & STYLE2_MARGINSSAMEASPARENT ? sal_True : sal_False;
116 * @descr: Get column width
119 double LwpVirtualLayout::GetColWidth(sal_uInt16 /*nIndex*/)
121 //return GetContentWidth(); //not support now
122 //return LwpTools::ConvertToMetric(5); //test
123 return 0; //test
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 LwpVirtualLayout* pParent = dynamic_cast<LwpVirtualLayout*> (GetParent()->obj());
147 if(pParent && !pParent->IsHeader())
149 return pParent->HonorProtection();
152 if(m_pFoundry)//is null now
154 LwpDocument* pDoc = m_pFoundry->GetDocument();
155 /*if(pDoc)
157 return pDoc->HonorProtection();
159 if(pDoc && pDoc->GetRootDocument())
160 return pDoc->GetRootDocument()->HonorProtection();
163 return true;
167 * @descr: Whether it is protected
170 bool LwpVirtualLayout::IsProtected()
172 bool bProtected = (m_nAttributes & STYLE_PROTECTED)!=0;
174 LwpVirtualLayout* pParent = dynamic_cast<LwpVirtualLayout*> (GetParent()->obj());
175 if(pParent && !pParent->IsHeader())
177 if(pParent->HonorProtection()&&(pParent->HasProtection()||bProtected))
179 return true;
182 else if(m_pFoundry)//is null now
184 LwpDocument* pDoc = m_pFoundry->GetDocument();
185 if(pDoc)
187 if (pDoc->HonorProtection() && bProtected)
189 return true;
194 return false;
198 * @descr: Whether it has protection
201 bool LwpVirtualLayout::HasProtection()
203 if(m_nAttributes & STYLE_PROTECTED)
204 return true;
206 LwpVirtualLayout* pParent = dynamic_cast<LwpVirtualLayout*> (GetParent()->obj());
207 if(pParent && !pParent->IsHeader())
209 return pParent->HasProtection();
212 return false;
216 * @descr: Whether it is a mirror layout
219 bool LwpVirtualLayout::IsComplex()
221 return m_nAttributes & STYLE_COMPLEX ? sal_True : sal_False;
225 * @descr: Get usewhen pointer
228 LwpUseWhen* LwpVirtualLayout::GetUseWhen()
231 If we have a parent, and I'm not a page layout,
232 use my parents information.
234 if(GetLayoutType()!=LWP_PAGE_LAYOUT)
236 //get parent
237 LwpVirtualLayout* pParent = dynamic_cast<LwpVirtualLayout*> (GetParent()->obj());
238 if(pParent && !pParent->IsHeader()&& (pParent->GetLayoutType()!=LWP_PAGE_LAYOUT))
239 return pParent->GetUseWhen();
243 return VirtualGetUseWhen();
246 * @descr: Whether this layout is page layout or not
247 * @param:
248 * @return:
250 bool LwpVirtualLayout::IsPage()
252 return (GetLayoutType() == LWP_PAGE_LAYOUT);
255 * @descr: Whether this layout is heaer layout or not
256 * @param:
257 * @return:
259 bool LwpVirtualLayout::IsHeader()
261 return (GetLayoutType() == LWP_HEADER_LAYOUT);
264 * @descr: Whether this layout is footer layout or not
265 * @param:
266 * @return:
268 bool LwpVirtualLayout::IsFooter()
270 return (GetLayoutType() == LWP_FOOTER_LAYOUT);
273 * @descr: Whether this layout is frame layout or not
274 * @param:
275 * @return:
277 bool LwpVirtualLayout::IsFrame()
279 return (GetLayoutType() == LWP_FRAME_LAYOUT);
283 * @descr: Whether this layout is cell layout or not
284 * @param:
285 * @return:
287 bool LwpVirtualLayout::IsCell()
289 return (GetLayoutType() == LWP_CELL_LAYOUT
290 || GetLayoutType() == LWP_CONNECTED_CELL_LAYOUT
291 || GetLayoutType() == LWP_HIDDEN_CELL_LAYOUT);
294 * @descr: Whether this layout is supertable layout or not
295 * @param:
296 * @return:
298 bool LwpVirtualLayout::IsSuperTable()
300 return (GetLayoutType() == LWP_SUPERTABLE_LAYOUT);
303 * @descr: Whether this layout is group layout or not
304 * @param:
305 * @return:
307 bool LwpVirtualLayout::IsGroupHead()
309 return (GetLayoutType() == LWP_GROUP_LAYOUT);
312 * @descr: get the relative type
313 * @param:
314 * @return:
316 sal_uInt8 LwpVirtualLayout::GetRelativeType()
318 return LwpLayoutRelativityGuts::LAY_PARENT_RELATIVE;
321 * @descr: whether it is relative anchored layout
322 * @param:
323 * @return:
325 bool LwpVirtualLayout::IsRelativeAnchored()
327 sal_uInt8 nType;
329 nType = GetRelativeType();
330 return (nType == LwpLayoutRelativityGuts::LAY_PARA_RELATIVE) || (nType == LwpLayoutRelativityGuts::LAY_INLINE)
331 || (nType == LwpLayoutRelativityGuts::LAY_INLINE_NEWLINE) || (nType == LwpLayoutRelativityGuts::LAY_INLINE_VERTICAL);
334 * @descr: whether it is MinimumHeight layout
335 * @param:
336 * @return:
338 bool LwpVirtualLayout::IsMinimumHeight()
340 return ((m_nAttributes3& STYLE3_MINHEIGHTVALID) != 0);
344 * @descr: Get parent layout
347 LwpVirtualLayout* LwpVirtualLayout::GetParentLayout()
349 return dynamic_cast<LwpVirtualLayout*> (GetParent()->obj());
353 * @descr: Register child layout style
356 void LwpVirtualLayout::RegisterChildStyle()
358 //Register all children styles
359 LwpVirtualLayout* pLayout = dynamic_cast<LwpVirtualLayout*>(GetChildHead()->obj());
360 while(pLayout)
362 pLayout->SetFoundry(m_pFoundry);
363 pLayout->RegisterStyle();
364 pLayout = dynamic_cast<LwpVirtualLayout*>(pLayout->GetNext()->obj());
368 bool LwpVirtualLayout::NoContentReference()
370 return (m_nAttributes2 & STYLE2_NOCONTENTREFERENCE) != 0;
373 bool LwpVirtualLayout::IsStyleLayout()
375 if (m_nAttributes3 & STYLE3_STYLELAYOUT)
376 return true;
378 LwpVirtualLayout* pParent = dynamic_cast<LwpVirtualLayout*>(GetParent()->obj());
379 if (pParent)
380 return pParent->IsStyleLayout();
381 return false;
385 * @descr: Find child layout by layout type
388 LwpVirtualLayout* LwpVirtualLayout::FindChildByType(LWP_LAYOUT_TYPE eType)
390 LwpObjectID *pID = GetChildHead();
392 while(pID && !pID->IsNull())
394 LwpVirtualLayout * pLayout = dynamic_cast<LwpVirtualLayout *>(pID->obj());
395 if(!pLayout)
397 break;
400 if (pLayout && pLayout->GetLayoutType() == eType)
402 return pLayout;
404 pID = pLayout->GetNext();
407 return NULL;
411 * @descr: Whether the size of layout is fit the graphic
414 bool LwpVirtualLayout::IsFitGraphic()
416 return IsAutoGrowRight() && !IsAutoGrowLeft() && IsAutoGrowDown();
420 * @descr: Whether the width of layout is auto grow
423 bool LwpVirtualLayout::IsAutoGrowWidth()
425 return IsAutoGrowLeft() || IsAutoGrowRight();
429 * @descr: Determine whether the layout width is to margin
432 bool LwpVirtualLayout::IsInlineToMargin()
434 return (m_nAttributes3 & STYLE3_INLINETOMARGIN) != 0;
437 void LwpAssociatedLayouts::Read(LwpObjectStream* pStrm)
439 m_OnlyLayout.ReadIndexed(pStrm);
440 m_Layouts.Read(pStrm);
441 pStrm->SkipExtra();
445 * @descr: Looking for the layout which follows the pStartLayout
446 * @param: pStartLayout - the layout which is used for looking for its following layout
448 LwpVirtualLayout* LwpAssociatedLayouts::GetLayout(LwpVirtualLayout *pStartLayout)
450 LwpVirtualLayout* pLayout = NULL;
452 if (!pStartLayout && !m_OnlyLayout.IsNull())
453 /* Looking for the first layout and there's only one layout in the list.*/
454 return dynamic_cast<LwpVirtualLayout*>(m_OnlyLayout.obj());
456 LwpObjectHolder* pObjHolder = dynamic_cast<LwpObjectHolder*>(m_Layouts.GetHead()->obj());
457 if(pObjHolder)
459 pLayout = dynamic_cast<LwpVirtualLayout*>(pObjHolder->GetObject()->obj());
460 if(!pStartLayout )
461 return pLayout;
463 while(pObjHolder && pStartLayout != pLayout)
465 pObjHolder = dynamic_cast<LwpObjectHolder*>(pObjHolder->GetNext()->obj());
466 if(pObjHolder)
468 pLayout = dynamic_cast<LwpVirtualLayout*>(pObjHolder->GetObject()->obj());
472 if(pObjHolder)
474 pObjHolder = dynamic_cast<LwpObjectHolder*>(pObjHolder->GetNext()->obj());
475 if(pObjHolder)
477 pLayout = dynamic_cast<LwpVirtualLayout*>(pObjHolder->GetObject()->obj());
478 return pLayout;
482 //return pLayout;
485 return NULL;
488 LwpHeadLayout::LwpHeadLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
489 : LwpVirtualLayout(objHdr, pStrm)
492 void LwpHeadLayout::Read()
494 LwpVirtualLayout::Read();
495 //For PermissiveLayout
496 m_pObjStrm->SkipExtra();
497 //For me
498 m_pObjStrm->SkipExtra();
501 void LwpHeadLayout::RegisterStyle()
503 //Register all children styles
504 LwpVirtualLayout* pLayout = dynamic_cast<LwpVirtualLayout*>(GetChildHead()->obj());
505 while(pLayout)
507 pLayout->SetFoundry(m_pFoundry);
508 //if the layout is relative to para, the layout will be registered in para
509 if(!pLayout->IsRelativeAnchored())
511 if (pLayout == this)
513 OSL_FAIL("Layout points to itself");
514 break;
516 pLayout->RegisterStyle();
518 LwpVirtualLayout *pNext = dynamic_cast<LwpVirtualLayout*>(pLayout->GetNext()->obj());
519 if (pNext == pLayout)
521 OSL_FAIL("Layout points to itself");
522 break;
524 pLayout = pNext;
529 * @descr find endnote supertable layout from the child layout list. Suppose that there is only one endnote supertablelayout in one division
530 * @return pointer to endnote supertable layout
532 LwpVirtualLayout* LwpHeadLayout::FindEnSuperTableLayout()
534 LwpVirtualLayout* pLayout = dynamic_cast<LwpVirtualLayout*>(GetChildHead()->obj());
535 while(pLayout)
537 if(pLayout->GetLayoutType() == LWP_ENDNOTE_SUPERTABLE_LAYOUT)
539 return pLayout;
541 pLayout = dynamic_cast<LwpVirtualLayout*>(pLayout->GetNext()->obj());
543 return NULL;
546 LwpLayoutStyle::LwpLayoutStyle()
547 : m_nStyleDefinition(0)
548 , m_pDescription(new LwpAtomHolder)
549 , m_nKey(0)
553 LwpLayoutStyle::~LwpLayoutStyle()
555 delete m_pDescription;
558 void LwpLayoutStyle::Read(LwpObjectStream* pStrm)
560 m_nStyleDefinition = pStrm->QuickReaduInt32();
561 m_pDescription->Read(pStrm);
562 if (pStrm->CheckExtra())
564 m_nKey = pStrm->QuickReaduInt16();
565 pStrm->SkipExtra();
569 LwpLayoutMisc::LwpLayoutMisc() :
570 m_nGridDistance(0), m_nGridType(0),
571 m_pContentStyle(new LwpAtomHolder)
575 LwpLayoutMisc::~LwpLayoutMisc()
577 if (m_pContentStyle)
579 delete m_pContentStyle;
583 void LwpLayoutMisc::Read(LwpObjectStream* pStrm)
585 m_nGridType = pStrm->QuickReaduInt16();
586 m_nGridDistance = pStrm->QuickReadInt32();
587 m_pContentStyle->Read(pStrm);
588 pStrm->SkipExtra();
591 LwpMiddleLayout::LwpMiddleLayout( LwpObjectHeader &objHdr, LwpSvStream* pStrm )
592 : LwpVirtualLayout(objHdr, pStrm),
593 m_pStyleStuff(new LwpLayoutStyle), m_pMiscStuff(new LwpLayoutMisc)
596 LwpMiddleLayout::~LwpMiddleLayout()
598 if (m_pStyleStuff)
600 delete m_pStyleStuff;
602 if (m_pMiscStuff)
604 delete m_pMiscStuff;
607 void LwpMiddleLayout::Read()
609 LwpObjectStream* pStrm = m_pObjStrm;
611 LwpVirtualLayout::Read();
613 //skip CLiteLayout data;
614 LwpAtomHolder ContentClass;
615 ContentClass.Read(pStrm);
616 pStrm->SkipExtra();
618 // before layout hierarchy rework
619 if(LwpFileHeader::m_nFileRevision < 0x000B)
620 return;
622 m_Content.ReadIndexed(pStrm);
624 // 01/20/2005
625 m_BasedOnStyle.ReadIndexed(pStrm);
626 m_TabPiece.ReadIndexed(pStrm);
628 sal_uInt8 nWhatsItGot = pStrm->QuickReaduInt8();
630 if (nWhatsItGot & DISK_GOT_STYLE_STUFF)
632 m_pStyleStuff->Read(pStrm);
634 if (nWhatsItGot & DISK_GOT_MISC_STUFF)
636 m_pMiscStuff->Read(pStrm);
639 m_LayGeometry.ReadIndexed(pStrm);
640 m_LayScale.ReadIndexed(pStrm);
641 m_LayMargins.ReadIndexed(pStrm);
642 m_LayBorderStuff.ReadIndexed(pStrm);
643 m_LayBackgroundStuff.ReadIndexed(pStrm);
645 if (pStrm->CheckExtra())
647 m_LayExtBorderStuff.ReadIndexed(pStrm);
648 pStrm->SkipExtra();
650 //end
653 #include "lwplaypiece.hxx"
656 * @descr: Get the geometry of current layout
659 LwpLayoutGeometry* LwpMiddleLayout::GetGeometry()
661 if( !m_LayGeometry.IsNull() )
663 return ( dynamic_cast<LwpLayoutGeometry*> (m_LayGeometry.obj()) );
665 else if( !m_BasedOnStyle.IsNull() )
667 LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj() );
668 return pLay ? pLay->GetGeometry() : NULL;
670 return NULL;
674 * @descr: Get layout height, measured by "cm"
677 double LwpMiddleLayout::GetGeometryHeight()
679 LwpLayoutGeometry* pGeo = GetGeometry();
680 if(pGeo)
682 return ( LwpTools::ConvertFromUnitsToMetric( pGeo->GetHeight() ) );
684 else
685 return -1;
689 * @descr: Get layout width, measured by "cm"
692 double LwpMiddleLayout::GetGeometryWidth()
694 LwpLayoutGeometry* pGeo = GetGeometry();
695 if(pGeo)
697 return ( LwpTools::ConvertFromUnitsToMetric( pGeo->GetWidth() ) );
699 else
700 return -1;
704 * @descr: Whether the margins is same as parent layout
707 bool LwpMiddleLayout::MarginsSameAsParent()
709 if(m_nOverrideFlag & OVER_MARGINS)
711 return LwpVirtualLayout::MarginsSameAsParent();
713 if(!m_BasedOnStyle.IsNull())
715 LwpVirtualLayout* pLay = dynamic_cast<LwpVirtualLayout*> (m_BasedOnStyle.obj());
716 if (pLay)
717 pLay->MarginsSameAsParent();
719 return LwpVirtualLayout::MarginsSameAsParent();
724 * @descr: Get margin
725 * @param: nWhichSide - 0: left, 1: right, 2:top, 3: bottom
727 double LwpMiddleLayout::GetMarginsValue(const sal_uInt8 &nWhichSide)
729 double fValue = 0;
730 if((nWhichSide==MARGIN_LEFT)||(nWhichSide==MARGIN_RIGHT))
732 if ( MarginsSameAsParent() )
734 LwpVirtualLayout* pParent = dynamic_cast<LwpVirtualLayout*> (GetParent()->obj());
735 if(pParent && !pParent->IsHeader())
737 fValue = pParent->GetMarginsValue(nWhichSide);
738 return fValue;
743 if(m_nOverrideFlag & OVER_MARGINS)
745 LwpLayoutMargins* pMar1 = dynamic_cast<LwpLayoutMargins*> (m_LayMargins.obj());
746 if(pMar1)
748 fValue = pMar1->GetMargins()->GetMarginsValue(nWhichSide);
749 return fValue;
752 LwpVirtualLayout* pStyle = dynamic_cast<LwpVirtualLayout*> (m_BasedOnStyle.obj());
753 if(pStyle)
755 fValue = pStyle->GetMarginsValue(nWhichSide);
756 return fValue;
758 return LwpVirtualLayout::GetMarginsValue(nWhichSide);
761 * @descr: Get extmargin value
762 * @param: nWhichSide - 0: left, 1: right, 2:top, 3: bottom
763 * @param:
764 * @return:
766 double LwpMiddleLayout::GetExtMarginsValue(const sal_uInt8 &nWhichSide)
768 double fValue = 0;
769 if(m_nOverrideFlag & OVER_MARGINS)
771 LwpLayoutMargins* pMar1 = dynamic_cast<LwpLayoutMargins*> (m_LayMargins.obj());
772 if(pMar1)
774 fValue = pMar1->GetExtMargins()->GetMarginsValue(nWhichSide);
775 return fValue;
778 LwpVirtualLayout* pStyle = dynamic_cast<LwpVirtualLayout*> (m_BasedOnStyle.obj());
779 if(pStyle)
781 fValue = pStyle->GetExtMarginsValue(nWhichSide);
782 return fValue;
784 return LwpVirtualLayout::GetExtMarginsValue(nWhichSide);
787 * @descr: Get the LwpBorderStuff object according to m_LayBorderStuff id.
788 * @param:
789 * @param:
790 * @return:
792 LwpBorderStuff* LwpMiddleLayout::GetBorderStuff()
794 if(m_nOverrideFlag & OVER_BORDERS)
796 LwpLayoutBorder* pLayoutBorder = dynamic_cast<LwpLayoutBorder*>(m_LayBorderStuff.obj());
797 return pLayoutBorder ? pLayoutBorder->GetBorderStuff() : NULL;
799 else if( !m_BasedOnStyle.IsNull() )
801 LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj() );
802 return pLay ? pLay->GetBorderStuff() : NULL;
804 return NULL;
808 * @descr: Get LwpBackgroundStuff object according to m_LayBackgroundStuff id;
809 * @param:
810 * @param:
811 * @return:
813 LwpBackgroundStuff* LwpMiddleLayout::GetBackgroundStuff()
815 if(m_nOverrideFlag & OVER_BACKGROUND)
817 LwpLayoutBackground* pLayoutBackground = dynamic_cast<LwpLayoutBackground*>(m_LayBackgroundStuff.obj());
818 return pLayoutBackground ? pLayoutBackground->GetBackgoudStuff() : NULL;
820 else if( !m_BasedOnStyle.IsNull() )
822 LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj() );
823 return pLay ? pLay->GetBackgroundStuff() : NULL;
825 return NULL;
828 * @descr: create xfborder.
829 * @param:
830 * @param:
831 * @return:
833 XFBorders* LwpMiddleLayout::GetXFBorders()
835 LwpBorderStuff* pBorderStuff = GetBorderStuff();
836 if(pBorderStuff&&pBorderStuff->GetSide() != 0)
838 //copy from lwpparastyle.
839 XFBorders *pXFBorders = new XFBorders();
840 // apply 4 borders respectively
841 LwpBorderStuff::BorderType pType[] = { LwpBorderStuff::LEFT, LwpBorderStuff::RIGHT,
842 LwpBorderStuff::TOP, LwpBorderStuff::BOTTOM };
844 for (sal_uInt8 nC = 0; nC < 4; nC++)
846 if (pBorderStuff->HasSide(pType[nC]))
848 LwpParaStyle::ApplySubBorder(pBorderStuff, pType[nC], pXFBorders);
851 return pXFBorders;
853 return NULL;
857 * @descr: Get text direction settings.
858 * @param:
859 * @param:
860 * @return:
862 enumXFTextDir LwpMiddleLayout::GetTextDirection()
864 enumXFTextDir eTextDir = enumXFTextDirNone;
865 sal_uInt8 nDirection = GetContentOrientation();
866 switch(nDirection)
868 case TEXT_ORIENT_LRTB:
870 eTextDir = enumXFTextDirLR_TB;
871 break;
873 case TEXT_ORIENT_TBRL:
875 eTextDir = enumXFTextDirTB_RL;
876 break;
878 case TEXT_ORIENT_RLBT: // not supported now
880 eTextDir = enumXFTextDirNone;
881 break;
883 case TEXT_ORIENT_BTLR: // not supported now
885 eTextDir = enumXFTextDirNone;
886 break;
888 default:
889 break;
891 return eTextDir;
894 * @descr: Get back ground color.
895 * @param:
896 * @param:
897 * @return:
899 LwpColor* LwpMiddleLayout::GetBackColor()
901 LwpBackgroundStuff* pBackgroundStuff = GetBackgroundStuff();
902 if(pBackgroundStuff && !pBackgroundStuff->IsTransparent())
904 LwpColor* pColor = pBackgroundStuff->GetFillColor();
905 if(pColor->IsValidColor())
907 return pColor;
910 return NULL;
914 * @descr: Add back color settings into xfpagemaster.
915 * @param:
916 * @param:
917 * @return:
919 LwpTabOverride* LwpMiddleLayout::GetTabOverride()
921 if(m_nAttributes & OVER_TABS)
923 if(!m_TabPiece.IsNull())
925 LwpTabPiece *pPiece = dynamic_cast<LwpTabPiece*>(m_TabPiece.obj());
926 return (LwpTabOverride*)(pPiece ? pPiece->GetOverride() : NULL);
928 return NULL;
930 else if( !m_BasedOnStyle.IsNull() )
932 LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj() );
933 return pLay ? pLay->GetTabOverride() : NULL;
935 return NULL;
939 * @descr: Layscale for graphic & watermark
940 * @param:
941 * @param:
942 * @return:
944 sal_uInt16 LwpMiddleLayout::GetScaleMode(void)
946 if ((m_nOverrideFlag & OVER_SCALING) && m_LayScale.obj())
947 return GetLayoutScale()->GetScaleMode();
948 else if (m_BasedOnStyle.obj())
949 return dynamic_cast<LwpMiddleLayout*>(m_BasedOnStyle.obj())->GetScaleMode();
950 else
951 return (LwpLayoutScale::FIT_IN_FRAME | LwpLayoutScale::MAINTAIN_ASPECT_RATIO);
954 sal_uInt16 LwpMiddleLayout::GetScaleTile(void)
956 if ((m_nOverrideFlag & OVER_SCALING) && m_LayScale.obj())
957 return (GetLayoutScale()->GetPlacement() & LwpLayoutScale::TILED)
958 ? 1 : 0;
959 else if (m_BasedOnStyle.obj())
960 return dynamic_cast<LwpMiddleLayout*>(m_BasedOnStyle.obj())->GetScaleTile();
961 else
962 return 0;
965 sal_uInt16 LwpMiddleLayout::GetScaleCenter(void)
967 if ((m_nOverrideFlag & OVER_SCALING) && m_LayScale.obj())
968 return (GetLayoutScale()->GetPlacement() & LwpLayoutScale::CENTERED)
969 ? 1 : 0;
970 else if (m_BasedOnStyle.obj())
971 return dynamic_cast<LwpMiddleLayout*>(m_BasedOnStyle.obj())->GetScaleCenter();
972 else
973 return 0;
976 sal_uInt32 LwpMiddleLayout::GetScalePercentage(void)
978 if ((m_nOverrideFlag & OVER_SCALING) && m_LayScale.obj())
979 return GetLayoutScale()->GetScalePercentage()/10;//m_nScalePercentage 1000 = 100%
980 else if (m_BasedOnStyle.obj())
981 return dynamic_cast<LwpMiddleLayout*>(m_BasedOnStyle.obj())->GetScalePercentage();
982 else
983 return 100;
986 double LwpMiddleLayout::GetScaleWidth(void)
988 if ((m_nOverrideFlag & OVER_SCALING) && m_LayScale.obj())
989 return LwpTools::ConvertFromUnits(GetLayoutScale()->GetScaleWidth());
990 else if (m_BasedOnStyle.obj())
991 return dynamic_cast<LwpMiddleLayout*>(m_BasedOnStyle.obj())->GetScaleWidth();
992 else
993 return 0;
996 double LwpMiddleLayout::GetScaleHeight(void)
998 if ((m_nOverrideFlag & OVER_SCALING) && m_LayScale.obj())
999 return LwpTools::ConvertFromUnits(GetLayoutScale()->GetScaleHeight());
1000 else if (m_BasedOnStyle.obj())
1001 return dynamic_cast<LwpMiddleLayout*>(m_BasedOnStyle.obj())->GetScaleHeight();
1002 else
1003 return 0;
1005 bool LwpMiddleLayout::CanSizeRight(void)
1007 sal_uInt8 RelType = GetRelativeType();
1009 if (RelType == LwpLayoutRelativityGuts::LAY_INLINE || RelType == LwpLayoutRelativityGuts::LAY_PARA_RELATIVE
1010 || RelType == LwpLayoutRelativityGuts::LAY_INLINE_VERTICAL)
1012 return false;
1014 return true;
1016 sal_Int32 LwpMiddleLayout::GetMinimumWidth()
1018 if (((m_nAttributes3 & STYLE3_WIDTHVALID) != 0) && GetGeometry())
1020 return GetGeometry()->GetWidth();
1022 else if (m_nOverrideFlag & OVER_SIZE)
1024 return DetermineWidth();
1026 return 0;
1028 sal_Int32 LwpMiddleLayout::DetermineWidth()
1030 if (IsSizeRightToContent())
1032 assert(false);
1034 else if (IsSizeRightToContainer())
1036 assert(false);
1038 else
1040 m_nAttributes3 |= STYLE3_WIDTHVALID;
1041 return GetGeometry()->GetWidth();
1043 return 0;
1045 bool LwpMiddleLayout::IsSizeRightToContainer(void)
1047 if (!CanSizeRight())
1048 return false;
1050 if (m_nOverrideFlag & OVER_SIZE)
1052 return (m_nDirection & ((LAY_USEDIRECTION|LAY_AUTOSIZE|LAY_TOCONTAINER)
1053 << SHIFT_RIGHT))
1054 == ((LAY_USEDIRECTION | LAY_TOCONTAINER | LAY_AUTOSIZE) << SHIFT_RIGHT);
1056 else if (m_BasedOnStyle.obj())
1058 LwpMiddleLayout * pLayout = dynamic_cast<LwpMiddleLayout *>(m_BasedOnStyle.obj());
1059 return pLayout ? pLayout->IsSizeRightToContainer() : sal_False;
1061 else
1062 return false;
1064 bool LwpMiddleLayout::IsSizeRightToContent(void)
1066 if (!CanSizeRight())
1067 return false;
1069 if (m_nOverrideFlag & OVER_SIZE)
1071 return (m_nDirection & ((LAY_USEDIRECTION|LAY_AUTOSIZE|LAY_TOCONTAINER)
1072 << SHIFT_RIGHT))
1073 == ((LAY_USEDIRECTION | LAY_AUTOSIZE) << SHIFT_RIGHT);
1075 else if (m_BasedOnStyle.obj())
1077 LwpMiddleLayout * pLayout = dynamic_cast<LwpMiddleLayout *>(m_BasedOnStyle.obj());
1078 return pLayout ? pLayout->IsSizeRightToContent() : sal_False;
1080 else
1081 return false;
1085 * @descr: Get layout height
1088 double LwpMiddleLayout::GetHeight()
1090 return GetGeometryHeight();
1094 * @descr: Get layout height
1097 double LwpMiddleLayout::GetWidth()
1099 return GetGeometryWidth();
1102 * @descr: Get layout orgin point
1105 LwpPoint LwpMiddleLayout::GetOrigin()
1107 LwpLayoutGeometry* pGeo = GetGeometry();
1108 if(pGeo)
1110 sal_uInt8 nType = GetRelativeType();
1111 if(nType == LwpLayoutRelativityGuts::LAY_INLINE
1112 || nType == LwpLayoutRelativityGuts::LAY_INLINE_NEWLINE )
1114 return pGeo->GetAbsoluteOrigin();
1116 else
1117 return pGeo->GetOrigin();
1121 return LwpPoint();
1125 * @descr: Whether the fill is pattern fill or not
1126 * @return: True if yes, false if not.
1128 bool LwpMiddleLayout::IsPatternFill()
1130 LwpBackgroundStuff* pBackgroundStuff = GetBackgroundStuff();
1131 if (pBackgroundStuff)
1133 return pBackgroundStuff->IsPatternFill();
1136 return false;
1140 * @descr: Get the fill pattern style. Data are saved in a XFBGImage object
1141 * @return: the fill pattern style.
1143 XFBGImage* LwpMiddleLayout::GetFillPattern()
1145 LwpBackgroundStuff* pBackgroundStuff = GetBackgroundStuff();
1146 if (pBackgroundStuff)
1148 return pBackgroundStuff->GetFillPattern();
1151 return NULL;
1156 * @descr: Whether the height and width of layout is auto grow
1159 bool LwpMiddleLayout::IsAutoGrow()
1161 if(m_nOverrideFlag & OVER_SIZE)
1163 return m_nDirection &
1164 ((LAY_AUTOGROW << SHIFT_UP) | (LAY_AUTOGROW << SHIFT_DOWN) |
1165 (LAY_AUTOGROW << SHIFT_RIGHT) | (LAY_AUTOGROW << SHIFT_LEFT))
1166 ? sal_True : sal_False;
1168 else if( !m_BasedOnStyle.IsNull() )
1170 LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj() );
1171 return pLay ? pLay->IsAutoGrow() : sal_False;
1173 return LwpVirtualLayout::IsAutoGrow();
1177 * @descr: Whether the height of layout is auto grow down
1180 bool LwpMiddleLayout::IsAutoGrowDown()
1182 if(m_nOverrideFlag & OVER_SIZE)
1184 return m_nDirection & (LAY_AUTOGROW << SHIFT_DOWN) ? sal_True : sal_False;
1186 else if( !m_BasedOnStyle.IsNull() )
1188 LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj() );
1189 return pLay ? pLay->IsAutoGrowDown() : sal_False;
1191 return LwpVirtualLayout::IsAutoGrowDown();
1195 * @descr: Whether the height of layout is auto grow up
1198 bool LwpMiddleLayout::IsAutoGrowUp()
1200 if(m_nOverrideFlag & OVER_SIZE)
1202 return m_nDirection & (LAY_AUTOGROW << SHIFT_UP) ? sal_True : sal_False;
1204 else if( !m_BasedOnStyle.IsNull() )
1206 LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj() );
1207 return pLay ? pLay->IsAutoGrowUp() : sal_False;
1209 return LwpVirtualLayout::IsAutoGrowUp();
1213 * @descr: Whether the height of layout is auto grow down
1216 bool LwpMiddleLayout::IsAutoGrowLeft()
1218 if(m_nOverrideFlag & OVER_SIZE)
1220 return m_nDirection & (LAY_AUTOGROW << SHIFT_LEFT) ? sal_True : sal_False;
1222 else if( !m_BasedOnStyle.IsNull() )
1224 LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj() );
1225 if (pLay)
1226 return pLay->IsAutoGrowLeft();
1228 return LwpVirtualLayout::IsAutoGrowLeft();
1232 * @descr: Whether the height of layout is auto grow down
1235 bool LwpMiddleLayout::IsAutoGrowRight()
1237 if(m_nOverrideFlag & OVER_SIZE)
1239 return m_nDirection & (LAY_AUTOGROW << SHIFT_RIGHT) ? sal_True : sal_False;
1241 else if( !m_BasedOnStyle.IsNull() )
1243 LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj() );
1244 return pLay ? pLay->IsAutoGrowRight() : sal_False;
1246 return LwpVirtualLayout::IsAutoGrowRight();
1250 * @descr: Get contents orientation
1253 sal_uInt8 LwpMiddleLayout::GetContentOrientation()
1255 //content orientation in Graphic objects and OLE objects not supported now
1256 if((m_nOverrideFlag & OVER_ROTATION)&& !m_LayGeometry.IsNull())
1258 LwpLayoutGeometry* pLayGeometry = dynamic_cast<LwpLayoutGeometry*> (m_LayGeometry.obj());
1259 if (pLayGeometry)
1260 return pLayGeometry->GetContentOrientation();
1262 else if( !m_BasedOnStyle.IsNull() )
1264 LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj() );
1265 if (pLay)
1266 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 LwpVirtualLayout* pParent = dynamic_cast<LwpVirtualLayout*> (GetParent()->obj());
1283 if(pParent && !pParent->IsHeader())
1285 return pParent->HonorProtection();
1288 if(m_pFoundry)//is null now
1290 LwpDocument* pDoc = m_pFoundry->GetDocument();
1291 if(pDoc)
1293 return pDoc->HonorProtection();
1297 else if( !m_BasedOnStyle.IsNull() )
1299 LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj() );
1300 if (pLay)
1301 return pLay->HonorProtection();
1304 return LwpVirtualLayout::HonorProtection();
1308 * @descr: Whether it is pretected
1311 bool LwpMiddleLayout::IsProtected()
1313 bool bProtected = false;
1314 if(m_nOverrideFlag & OVER_MISC)
1316 bProtected = (m_nAttributes & STYLE_PROTECTED)!=0;
1318 else if( !m_BasedOnStyle.IsNull() )
1320 LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj() );
1321 bProtected = pLay ? pLay->IsProtected() : sal_False;
1323 else
1324 bProtected = LwpVirtualLayout::IsProtected();
1326 LwpVirtualLayout* pParent = dynamic_cast<LwpVirtualLayout*> (GetParent()->obj());
1327 if(pParent && !pParent->IsHeader())
1329 /* If a parent's protected then none of its children can be accessed. */
1330 if(pParent->IsProtected())
1331 return true;
1333 if(pParent->HonorProtection())
1334 return bProtected;
1336 /* If our parent isn't honoring protection then we aren't protected. */
1337 return false;
1340 if(m_pFoundry)//is null now
1342 LwpDocument* pDoc = m_pFoundry->GetDocument();
1343 if(pDoc)
1345 if (pDoc->HonorProtection())
1346 return bProtected;
1348 /* If the document isn't honoring protection then we aren't protected.*/
1349 return false;
1353 return bProtected;
1357 * @descr: Get watermark layout
1360 LwpVirtualLayout* LwpMiddleLayout::GetWaterMarkLayout()
1362 LwpVirtualLayout* pLay = dynamic_cast<LwpVirtualLayout*>(GetChildHead()->obj());
1363 while(pLay)
1365 if( pLay->IsForWaterMark())
1367 return pLay;
1369 pLay = dynamic_cast<LwpVirtualLayout*> (pLay->GetNext()->obj());
1371 return NULL;
1375 * @descr: Create and reture xfbgimage object for watermark
1378 XFBGImage* LwpMiddleLayout::GetXFBGImage()
1380 LwpMiddleLayout* pLay = static_cast<LwpMiddleLayout*>(GetWaterMarkLayout());
1381 if(pLay)
1383 //test BGImage
1384 LwpGraphicObject* pGrfObj = dynamic_cast<LwpGraphicObject*>(pLay->GetContent()->obj());
1385 if(pGrfObj)
1387 XFBGImage* pXFBGImage = new XFBGImage();
1389 if(pGrfObj->IsLinked())
1391 //set file link
1392 OUString linkedfilepath = pGrfObj->GetLinkedFilePath();
1393 OUString fileURL = LwpTools::convertToFileUrl(OUStringToOString(linkedfilepath, osl_getThreadTextEncoding()));
1394 pXFBGImage->SetFileLink(fileURL);
1396 else
1398 sal_uInt8* pGrafData = NULL;
1399 sal_uInt32 nDataLen = pGrfObj->GetRawGrafData(pGrafData);
1400 pXFBGImage->SetImageData(pGrafData, nDataLen);
1401 if(pGrafData)
1403 delete[] pGrafData;
1404 pGrafData = NULL;
1408 //automatic, top left
1409 pXFBGImage->SetPosition(enumXFAlignStart,enumXFAlignTop);
1410 if(pLay->GetScaleCenter())
1412 //center
1413 pXFBGImage->SetPosition(enumXFAlignCenter,enumXFAlignCenter);
1415 else if(pLay->GetScaleTile())
1417 //tile
1418 pXFBGImage->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 pXFBGImage->SetStretch();
1428 return pXFBGImage;
1431 return NULL;
1435 * @descr: Whether the page uses the printer setting
1438 bool LwpMiddleLayout::GetUsePrinterSettings()
1440 if(m_nOverrideFlag & OVER_SIZE)
1442 return (m_nAttributes3 & STYLE3_USEPRINTERSETTINGS) != 0;
1444 else if( !m_BasedOnStyle.IsNull() )
1446 LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj() );
1447 return pLay ? pLay->GetUsePrinterSettings() : sal_False;
1449 return false;
1452 //Check whether there are contents in the layout
1453 bool LwpMiddleLayout::HasContent()
1455 LwpObject* content = m_Content.obj();
1456 if(content)
1457 return true;
1458 return false;
1460 //End by
1462 LwpLayout::LwpLayout( LwpObjectHeader &objHdr, LwpSvStream* pStrm ) :
1463 LwpMiddleLayout(objHdr, pStrm), m_pUseWhen(new LwpUseWhen)
1466 LwpLayout::~LwpLayout()
1468 if (m_pUseWhen)
1470 delete m_pUseWhen;
1474 void LwpLayout::Read()
1476 LwpObjectStream* pStrm = m_pObjStrm;
1478 LwpMiddleLayout::Read();
1479 if (LwpFileHeader::m_nFileRevision < 0x000B)
1481 // read PreRevBLayout...
1483 else
1485 sal_uInt16 nSimple = pStrm->QuickReaduInt16();
1487 if (!nSimple)
1489 m_pUseWhen->Read(pStrm);
1491 sal_uInt8 nFlag = pStrm->QuickReaduInt8();
1492 if (nFlag)
1493 m_Positon.ReadIndexed(pStrm);
1496 m_LayColumns.ReadIndexed(pStrm);
1497 m_LayGutterStuff.ReadIndexed(pStrm);
1498 m_LayJoinStuff.ReadIndexed(pStrm);
1499 m_LayShadow.ReadIndexed(pStrm);
1501 if (pStrm->CheckExtra())
1503 m_LayExtJoinStuff.ReadIndexed(pStrm);
1504 pStrm->SkipExtra();
1510 * @descr: Get columns number
1513 sal_uInt16 LwpLayout::GetNumCols()
1515 if(m_nOverrideFlag & OVER_COLUMNS)
1517 LwpLayoutColumns* pLayColumns = dynamic_cast<LwpLayoutColumns*>(m_LayColumns.obj());
1518 if(pLayColumns)
1520 return pLayColumns->GetNumCols();
1524 LwpVirtualLayout* pStyle = dynamic_cast<LwpVirtualLayout*> (m_BasedOnStyle.obj());
1525 if(pStyle)
1527 return pStyle->GetNumCols();
1530 return LwpVirtualLayout::GetNumCols();
1535 * @descr: Get column width
1536 * @param: the order of column
1538 double LwpLayout::GetColWidth(sal_uInt16 nIndex)
1540 if((m_nOverrideFlag & OVER_COLUMNS)||(m_nAttributes2 & STYLE2_LOCALCOLUMNINFO))
1542 LwpLayoutColumns* pLayColumns = dynamic_cast<LwpLayoutColumns*>(m_LayColumns.obj());
1543 if(pLayColumns)
1545 return pLayColumns->GetColWidth(nIndex);
1549 LwpVirtualLayout* pStyle = dynamic_cast<LwpVirtualLayout*> (m_BasedOnStyle.obj());
1550 if(pStyle)
1552 return pStyle->GetColWidth(nIndex);
1555 return LwpVirtualLayout::GetColWidth(nIndex);
1560 * @descr: Get gap between columns
1561 * @param: the order of column
1563 double LwpLayout::GetColGap(sal_uInt16 nIndex)
1565 if((m_nOverrideFlag & OVER_COLUMNS)||(m_nAttributes2 & STYLE2_LOCALCOLUMNINFO))
1567 LwpLayoutColumns* pLayColumns = dynamic_cast<LwpLayoutColumns*>(m_LayColumns.obj());
1568 if(pLayColumns)
1570 return pLayColumns->GetColGap(nIndex);
1574 LwpVirtualLayout* pStyle = dynamic_cast<LwpVirtualLayout*> (m_BasedOnStyle.obj());
1575 if(pStyle)
1577 return pStyle->GetColGap(nIndex);
1580 return LwpVirtualLayout::GetColGap(nIndex);
1584 * @descr: Create and return XFColumns object
1587 XFColumns* LwpLayout::GetXFColumns()
1589 //if there is only one column, do not need insert columns
1590 sal_uInt16 nCols = GetNumCols();
1591 if(nCols==1)
1593 return NULL;
1596 XFColumns* pColumns = new XFColumns();
1597 //set XFColumnSep
1598 boost::scoped_ptr<XFColumnSep> pColumnSep(GetColumnSep());
1599 if(pColumnSep)
1601 pColumns->SetSeparator(*pColumnSep);
1604 //set column count and column gap
1605 pColumns->SetCount(nCols);
1606 double fGap = GetColGap(0);
1607 pColumns->SetGap(fGap);
1609 //set xfcolumn
1610 for(sal_uInt16 nIndex = 0; nIndex<nCols; nIndex++)
1612 XFColumn aColumn;
1613 sal_Int32 nWidth = static_cast<sal_Int32>(GetColWidth(nIndex));
1614 nWidth=8305/nCols; //relative width
1615 aColumn.SetRelWidth(nWidth);
1617 //the left and right margins is 0;
1618 double nGap = GetColGap(nIndex)/2;
1619 //nGap=0;
1620 aColumn.SetMargins(nGap,nGap);
1621 if(nIndex==0)
1623 aColumn.SetMargins(0,nGap);
1625 if(nIndex==(nCols-1))
1627 aColumn.SetMargins(nGap,0);
1629 pColumns->AddColumn(aColumn);
1632 return pColumns;
1636 * @descr: Create and return XFColumnSep object
1639 XFColumnSep* LwpLayout::GetColumnSep()
1642 //Get LwpLayoutGutters
1643 LwpLayoutGutters* pLayoutGutters = dynamic_cast<LwpLayoutGutters*>(m_LayGutterStuff.obj());
1644 if(!pLayoutGutters)
1646 return NULL;
1649 LwpBorderStuff* pBorderStuff = pLayoutGutters->GetBorderStuff();
1651 if(pBorderStuff)
1653 LwpBorderStuff::BorderType eType = LwpBorderStuff::LEFT;
1654 LwpColor aColor = pBorderStuff->GetSideColor(eType);
1655 double fWidth = pBorderStuff->GetSideWidth(eType);
1656 //sal_uInt16 nType = pBorderStuff->GetSideType(eType);
1658 XFColumnSep* pColumnSep = new XFColumnSep();
1659 XFColor aXFColor(aColor.To24Color());
1660 pColumnSep->SetColor(aXFColor);
1661 pColumnSep->SetWidth(fWidth);
1662 pColumnSep->SetRelHeight(100);
1663 pColumnSep->SetVerticalAlign(enumXFAlignTop);
1665 return pColumnSep;
1667 return NULL;
1672 * @descr: Get use when type
1675 LwpLayout::UseWhenType LwpLayout::GetUseWhenType()
1677 UseWhenType eType = StartWithinPage;
1678 LwpUseWhen* pUseWhen = GetUseWhen();
1679 if(pUseWhen)
1681 if(pUseWhen->IsStartOnThisHF())
1683 eType = StartWithinColume;
1685 else if(pUseWhen->IsStartOnThisPage())
1687 eType = StartWithinPage;
1689 else if(pUseWhen->IsStartOnNextPage())
1691 eType = StartOnNextPage;
1693 else if(pUseWhen->IsStartOnNextOddPage())
1695 eType = StartOnOddPage;
1697 else if(pUseWhen->IsStartOnNextEvenPage())
1699 eType = StartOnEvenPage;
1703 else
1705 eType = StartOnNextPage;
1707 return eType;
1711 * @descr: Get use page
1714 sal_uInt16 LwpLayout::GetUsePage()
1716 if(m_nOverrideFlag & OVER_PLACEMENT)
1718 LwpUseWhen* pUseWhen = GetUseWhen();
1719 if(pUseWhen)
1720 return pUseWhen->GetUsePage();
1721 else
1722 return 0;
1724 else if( !m_BasedOnStyle.IsNull() )
1726 LwpLayout* pLay = dynamic_cast<LwpLayout*> ( m_BasedOnStyle.obj() );
1727 return pLay ? pLay->GetUsePage() : 0;
1729 return 0;
1733 * @descr: Get usewhen pointer
1736 LwpUseWhen* LwpLayout::VirtualGetUseWhen()
1738 if(m_nOverrideFlag & OVER_PLACEMENT)
1740 return m_pUseWhen;
1742 else if( !m_BasedOnStyle.IsNull() )
1744 LwpLayout* pLay = dynamic_cast<LwpLayout*> ( m_BasedOnStyle.obj() );
1745 return pLay ? pLay->VirtualGetUseWhen() : NULL;
1747 return LwpVirtualLayout::VirtualGetUseWhen();
1751 * @descr: Whether it is use on all pages
1754 bool LwpLayout::IsUseOnAllPages()
1756 if(m_nOverrideFlag & OVER_PLACEMENT)
1758 LwpUseWhen* pUseWhen = GetUseWhen();
1759 if(pUseWhen)
1760 return pUseWhen->IsUseOnAllPages();
1761 else
1762 return false;
1764 else if( !m_BasedOnStyle.IsNull() )
1766 LwpLayout* pLay = dynamic_cast<LwpLayout*> ( m_BasedOnStyle.obj() );
1767 if (pLay)
1768 return pLay->IsUseOnAllPages();
1770 return LwpVirtualLayout::IsUseOnAllPages();
1774 * @descr: Whether it is use on all even pages
1777 bool LwpLayout::IsUseOnAllEvenPages()
1779 if(m_nOverrideFlag & OVER_PLACEMENT)
1781 LwpUseWhen* pUseWhen = GetUseWhen();
1782 if(pUseWhen)
1783 return pUseWhen->IsUseOnAllEvenPages();
1784 else
1785 return false;
1787 else if( !m_BasedOnStyle.IsNull() )
1789 LwpLayout* pLay = dynamic_cast<LwpLayout*> ( m_BasedOnStyle.obj() );
1790 if (pLay)
1791 return pLay->IsUseOnAllEvenPages();
1793 return LwpVirtualLayout::IsUseOnAllEvenPages();
1797 * @descr: Whether it is use on all odd pages
1800 bool LwpLayout::IsUseOnAllOddPages()
1802 if(m_nOverrideFlag & OVER_PLACEMENT)
1804 LwpUseWhen* pUseWhen = GetUseWhen();
1805 if(pUseWhen)
1806 return pUseWhen->IsUseOnAllOddPages();
1807 else
1808 return false;
1810 else if( !m_BasedOnStyle.IsNull() )
1812 LwpLayout* pLay = dynamic_cast<LwpLayout*> ( m_BasedOnStyle.obj() );
1813 if (pLay)
1814 return pLay->IsUseOnAllOddPages();
1816 return LwpVirtualLayout::IsUseOnAllOddPages();
1820 * @descr: Whether it is use on current page
1823 bool LwpLayout::IsUseOnPage()
1825 if(m_nOverrideFlag & OVER_PLACEMENT)
1827 LwpUseWhen* pUseWhen = GetUseWhen();
1828 if(pUseWhen)
1829 return pUseWhen->IsUseOnPage();
1830 else
1831 return false;
1833 else if( !m_BasedOnStyle.IsNull() )
1835 LwpLayout* pLay = dynamic_cast<LwpLayout*> ( m_BasedOnStyle.obj() );
1836 if (pLay)
1837 return pLay->IsUseOnPage();
1839 return LwpVirtualLayout::IsUseOnPage();
1843 * @descr: Get the LwpShadow object according to m_LayShadow id.
1844 * @param:
1845 * @param:
1846 * @return:
1848 LwpShadow* LwpLayout::GetShadow()
1850 if(m_nOverrideFlag & OVER_SHADOW)
1852 LwpLayoutShadow* pLayoutShadow = dynamic_cast<LwpLayoutShadow*>(m_LayShadow.obj());
1853 return pLayoutShadow ? pLayoutShadow->GetShadow() : NULL;
1855 else if( !m_BasedOnStyle.IsNull() )
1857 LwpLayout* pLay = dynamic_cast<LwpLayout*> ( m_BasedOnStyle.obj() );
1858 return pLay ? pLay->GetShadow() : NULL;
1860 return NULL;
1864 * @descr: create xfshadow
1865 * @param:
1866 * @param:
1867 * @return:
1869 XFShadow* LwpLayout::GetXFShadow()
1871 LwpShadow* pShadow = GetShadow();
1872 if( pShadow )
1874 LwpColor color = pShadow->GetColor();
1875 double offsetX = pShadow->GetOffsetX();
1876 double offsetY = pShadow->GetOffsetY();
1878 if( offsetX && offsetY && color.IsValidColor() )
1880 XFShadow* pXFShadow = new XFShadow();
1881 enumXFShadowPos eXFShadowPos = enumXFShadowLeftTop;
1882 double fOffset = 0;
1884 bool left = false;
1885 bool top = false;
1886 if( offsetX < 0 )
1887 left = true;
1888 if( offsetY < 0 )
1889 top = true;
1890 if( left )
1892 fOffset = -offsetX;
1893 if( top )
1894 eXFShadowPos = enumXFShadowLeftTop;
1895 else
1896 eXFShadowPos = enumXFShadowLeftBottom;
1898 else
1900 fOffset = offsetX;
1901 if( top )
1902 eXFShadowPos = enumXFShadowRightTop;
1903 else
1904 eXFShadowPos = enumXFShadowRightBottom;
1907 pXFShadow->SetPosition(eXFShadowPos);
1908 pXFShadow->SetOffset(fOffset);
1909 pXFShadow->SetColor(XFColor(color.To24Color()));
1911 return pXFShadow;
1914 return NULL;
1918 * @descr get the layout that containers the current frame layout
1921 LwpVirtualLayout* LwpLayout::GetContainerLayout()
1923 if(IsRelativeAnchored())
1925 //get position
1926 LwpPara* pPara = dynamic_cast<LwpPara*>(GetPosition()->obj());
1927 if(pPara)
1929 LwpStory* pStory = pPara->GetStory();
1930 return pStory ? pStory->GetTabLayout() : NULL;
1933 return GetParentLayout();
1936 LwpPlacableLayout::LwpPlacableLayout( LwpObjectHeader &objHdr, LwpSvStream* pStrm )
1937 : LwpLayout(objHdr, pStrm)
1938 , m_nWrapType(0)
1939 , m_nBuoyancy(0)
1940 , m_nBaseLineOffset(0)
1941 , m_nPageNumber(0)
1942 , m_pFont(NULL)
1945 LwpPlacableLayout::~LwpPlacableLayout()
1948 void LwpPlacableLayout::Read()
1950 LwpObjectStream* pStrm = m_pObjStrm;
1951 LwpLayout::Read();
1952 if(LwpFileHeader::m_nFileRevision < 0x000B)
1954 assert(false);
1956 else
1958 sal_uInt16 simple = pStrm->QuickReaduInt16();
1959 if(!simple)
1961 m_nWrapType = pStrm->QuickReaduInt8();
1962 m_nBuoyancy = pStrm->QuickReaduInt8();
1963 m_nBaseLineOffset = pStrm->QuickReadInt32();
1964 m_Script.Read( pStrm);
1966 else
1968 m_nWrapType = LAY_WRAP_AROUND;
1969 m_nBuoyancy = LAY_BUOYNEUTRAL;
1970 m_nBaseLineOffset = 0;
1972 m_LayRelativity.ReadIndexed( pStrm);
1973 if(pStrm->CheckExtra())
1975 sal_uInt16 count = pStrm->QuickReaduInt16();
1976 if(count)
1978 // temporily added by to avoid assertion
1979 while (count)
1981 LwpPoint aPoint;
1982 aPoint.Read(pStrm);
1983 count--;
1985 // end added by
1987 pStrm->SkipExtra();
1992 * @descr: get wrap type
1993 * @param:
1994 * @param:
1995 * @return:
1997 sal_uInt8 LwpPlacableLayout::GetWrapType()
1999 if(m_nOverrideFlag & OVER_PLACEMENT)
2001 return m_nWrapType;
2003 else if( !m_BasedOnStyle.IsNull() )
2005 LwpPlacableLayout* pLay = dynamic_cast<LwpPlacableLayout*> ( m_BasedOnStyle.obj() );
2006 if (pLay)
2007 return pLay->GetWrapType();
2009 return LAY_WRAP_AROUND;
2012 * @descr: get LayoutRelativity
2013 * @param:
2014 * @param:
2015 * @return:
2017 LwpLayoutRelativity* LwpPlacableLayout::GetRelativityPiece()
2019 if(!m_LayRelativity.IsNull())
2021 if(m_nOverrideFlag & OVER_PLACEMENT)
2023 return dynamic_cast<LwpLayoutRelativity*>(m_LayRelativity.obj());
2026 else if( !m_BasedOnStyle.IsNull() )
2028 LwpPlacableLayout* pLay = dynamic_cast<LwpPlacableLayout*> ( m_BasedOnStyle.obj() );
2029 return pLay ? pLay->GetRelativityPiece() : NULL;
2031 return NULL;
2034 * @descr: Get relative type
2037 sal_uInt8 LwpPlacableLayout::GetRelativeType()
2039 LwpLayoutRelativity* pLayRel = GetRelativityPiece();
2040 if(pLayRel)
2042 return pLayRel->GetRelGuts()->GetRelativeType();
2044 return LwpVirtualLayout::GetRelativeType();
2047 * @descr: Get offset from the baseline
2050 sal_Int32 LwpPlacableLayout::GetBaseLineOffset()
2052 /* The baseline is only valid if this is flow-with-text */
2053 if(GetRelativeType()!=LwpLayoutRelativityGuts::LAY_INLINE)
2055 return 0;
2058 // First, ask our content if it has a baseline, ignore now
2060 if (Content && Content->GetBaseLineOffset(&Baseline))
2061 return Baseline;
2064 if(m_nOverrideFlag & OVER_PLACEMENT)
2066 return m_nBaseLineOffset;
2068 else if( !m_BasedOnStyle.IsNull() )
2070 LwpPlacableLayout* pLay = dynamic_cast<LwpPlacableLayout*> ( m_BasedOnStyle.obj() );
2071 return pLay ? pLay->GetBaseLineOffset() : 0;
2073 return 0;
2077 * @descr: whether the parent layout is page layout
2080 bool LwpPlacableLayout::IsAnchorPage()
2082 if(IsRelativeAnchored())
2083 return false;
2085 LwpVirtualLayout* pLayout = GetParentLayout();
2086 if(pLayout && (pLayout->IsPage() || pLayout->IsHeader() || pLayout->IsFooter()))
2087 //if(pLayout && pLayout->IsPage())
2089 return true;
2091 return false;
2094 * @descr: whether the parent layout is frame layout
2097 bool LwpPlacableLayout::IsAnchorFrame()
2099 if(IsRelativeAnchored())
2100 return false;
2102 LwpVirtualLayout* pLayout = GetParentLayout();
2103 if(pLayout && (pLayout->IsFrame()||pLayout->IsGroupHead()))
2105 return true;
2107 return false;
2110 * @descr: whether the parent layout is cell layout
2113 bool LwpPlacableLayout::IsAnchorCell()
2115 if(IsRelativeAnchored())
2116 return false;
2118 LwpVirtualLayout* pLayout = GetParentLayout();
2119 if(pLayout && pLayout->IsCell())
2121 return true;
2123 return false;
2127 * @descr: Get font style for setting position of frame
2130 XFFont* LwpPlacableLayout::GetFont()
2132 return m_pFont;
2135 * @descr: Set font style for setting position of frame
2138 void LwpPlacableLayout::SetFont(XFFont * pFont)
2140 m_pFont = pFont;
2143 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */