fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / lotuswordpro / source / filter / lwplayout.cxx
blob38634586e8ea1efbbbc272b0072dae74378b4948
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) != 0;
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().get());
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().get());
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().get());
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) != 0;
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().get());
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().get());
353 * @descr: Register child layout style
356 void LwpVirtualLayout::RegisterChildStyle()
358 //Register all children styles
359 LwpVirtualLayout* pLayout = dynamic_cast<LwpVirtualLayout*>(GetChildHead().obj().get());
360 while(pLayout)
362 pLayout->SetFoundry(m_pFoundry);
363 pLayout->RegisterStyle();
364 pLayout = dynamic_cast<LwpVirtualLayout*>(pLayout->GetNext().obj().get());
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().get());
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& rID = GetChildHead();
392 while(!rID.IsNull())
394 LwpVirtualLayout * pLayout = dynamic_cast<LwpVirtualLayout *>(rID.obj().get());
395 if(!pLayout)
397 break;
400 if (pLayout && pLayout->GetLayoutType() == eType)
402 return pLayout;
404 rID = 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 if (!pStartLayout && !m_OnlyLayout.IsNull())
451 /* Looking for the first layout and there's only one layout in the list.*/
452 return dynamic_cast<LwpVirtualLayout*>(m_OnlyLayout.obj().get());
454 LwpObjectHolder* pObjHolder = dynamic_cast<LwpObjectHolder*>(m_Layouts.GetHead().obj().get());
455 if(pObjHolder)
457 LwpVirtualLayout* pLayout = dynamic_cast<LwpVirtualLayout*>(pObjHolder->GetObject().obj().get());
458 if(!pStartLayout )
459 return pLayout;
461 while(pObjHolder && pStartLayout != pLayout)
463 pObjHolder = dynamic_cast<LwpObjectHolder*>(pObjHolder->GetNext().obj().get());
464 if(pObjHolder)
466 pLayout = dynamic_cast<LwpVirtualLayout*>(pObjHolder->GetObject().obj().get());
470 if(pObjHolder)
472 pObjHolder = dynamic_cast<LwpObjectHolder*>(pObjHolder->GetNext().obj().get());
473 if(pObjHolder)
475 pLayout = dynamic_cast<LwpVirtualLayout*>(pObjHolder->GetObject().obj().get());
476 return pLayout;
480 //return pLayout;
483 return NULL;
486 LwpHeadLayout::LwpHeadLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
487 : LwpVirtualLayout(objHdr, pStrm)
490 void LwpHeadLayout::Read()
492 LwpVirtualLayout::Read();
493 //For PermissiveLayout
494 m_pObjStrm->SkipExtra();
495 //For me
496 m_pObjStrm->SkipExtra();
499 void LwpHeadLayout::RegisterStyle()
501 //Register all children styles
502 LwpVirtualLayout* pLayout = dynamic_cast<LwpVirtualLayout*>(GetChildHead().obj().get());
503 while(pLayout)
505 pLayout->SetFoundry(m_pFoundry);
506 //if the layout is relative to para, the layout will be registered in para
507 if(!pLayout->IsRelativeAnchored())
509 if (pLayout == this)
511 OSL_FAIL("Layout points to itself");
512 break;
514 pLayout->RegisterStyle();
516 LwpVirtualLayout *pNext = dynamic_cast<LwpVirtualLayout*>(pLayout->GetNext().obj().get());
517 if (pNext == pLayout)
519 OSL_FAIL("Layout points to itself");
520 break;
522 pLayout = pNext;
527 * @descr find endnote supertable layout from the child layout list. Suppose that there is only one endnote supertablelayout in one division
528 * @return pointer to endnote supertable layout
530 LwpVirtualLayout* LwpHeadLayout::FindEnSuperTableLayout()
532 LwpVirtualLayout* pLayout = dynamic_cast<LwpVirtualLayout*>(GetChildHead().obj().get());
533 while(pLayout)
535 if(pLayout->GetLayoutType() == LWP_ENDNOTE_SUPERTABLE_LAYOUT)
537 return pLayout;
539 pLayout = dynamic_cast<LwpVirtualLayout*>(pLayout->GetNext().obj().get());
541 return NULL;
544 LwpLayoutStyle::LwpLayoutStyle()
545 : m_nStyleDefinition(0)
546 , m_pDescription(new LwpAtomHolder)
547 , m_nKey(0)
551 LwpLayoutStyle::~LwpLayoutStyle()
553 delete m_pDescription;
556 void LwpLayoutStyle::Read(LwpObjectStream* pStrm)
558 m_nStyleDefinition = pStrm->QuickReaduInt32();
559 m_pDescription->Read(pStrm);
560 if (pStrm->CheckExtra())
562 m_nKey = pStrm->QuickReaduInt16();
563 pStrm->SkipExtra();
567 LwpLayoutMisc::LwpLayoutMisc() :
568 m_nGridDistance(0), m_nGridType(0),
569 m_pContentStyle(new LwpAtomHolder)
573 LwpLayoutMisc::~LwpLayoutMisc()
575 if (m_pContentStyle)
577 delete m_pContentStyle;
581 void LwpLayoutMisc::Read(LwpObjectStream* pStrm)
583 m_nGridType = pStrm->QuickReaduInt16();
584 m_nGridDistance = pStrm->QuickReadInt32();
585 m_pContentStyle->Read(pStrm);
586 pStrm->SkipExtra();
589 LwpMiddleLayout::LwpMiddleLayout( LwpObjectHeader &objHdr, LwpSvStream* pStrm )
590 : LwpVirtualLayout(objHdr, pStrm),
591 m_pStyleStuff(new LwpLayoutStyle), m_pMiscStuff(new LwpLayoutMisc)
594 LwpMiddleLayout::~LwpMiddleLayout()
596 if (m_pStyleStuff)
598 delete m_pStyleStuff;
600 if (m_pMiscStuff)
602 delete m_pMiscStuff;
605 void LwpMiddleLayout::Read()
607 LwpObjectStream* pStrm = m_pObjStrm;
609 LwpVirtualLayout::Read();
611 //skip CLiteLayout data;
612 LwpAtomHolder ContentClass;
613 ContentClass.Read(pStrm);
614 pStrm->SkipExtra();
616 // before layout hierarchy rework
617 if(LwpFileHeader::m_nFileRevision < 0x000B)
618 return;
620 m_Content.ReadIndexed(pStrm);
622 // 01/20/2005
623 m_BasedOnStyle.ReadIndexed(pStrm);
624 m_TabPiece.ReadIndexed(pStrm);
626 sal_uInt8 nWhatsItGot = pStrm->QuickReaduInt8();
628 if (nWhatsItGot & DISK_GOT_STYLE_STUFF)
630 m_pStyleStuff->Read(pStrm);
632 if (nWhatsItGot & DISK_GOT_MISC_STUFF)
634 m_pMiscStuff->Read(pStrm);
637 m_LayGeometry.ReadIndexed(pStrm);
638 m_LayScale.ReadIndexed(pStrm);
639 m_LayMargins.ReadIndexed(pStrm);
640 m_LayBorderStuff.ReadIndexed(pStrm);
641 m_LayBackgroundStuff.ReadIndexed(pStrm);
643 if (pStrm->CheckExtra())
645 m_LayExtBorderStuff.ReadIndexed(pStrm);
646 pStrm->SkipExtra();
648 //end
651 #include "lwplaypiece.hxx"
654 * @descr: Get the geometry of current layout
657 LwpLayoutGeometry* LwpMiddleLayout::GetGeometry()
659 if( !m_LayGeometry.IsNull() )
661 return ( dynamic_cast<LwpLayoutGeometry*> (m_LayGeometry.obj().get()) );
663 else if( !m_BasedOnStyle.IsNull() )
665 LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj().get() );
666 return pLay ? pLay->GetGeometry() : NULL;
668 return NULL;
672 * @descr: Get layout height, measured by "cm"
675 double LwpMiddleLayout::GetGeometryHeight()
677 LwpLayoutGeometry* pGeo = GetGeometry();
678 if(pGeo)
680 return ( LwpTools::ConvertFromUnitsToMetric( pGeo->GetHeight() ) );
682 else
683 return -1;
687 * @descr: Get layout width, measured by "cm"
690 double LwpMiddleLayout::GetGeometryWidth()
692 LwpLayoutGeometry* pGeo = GetGeometry();
693 if(pGeo)
695 return ( LwpTools::ConvertFromUnitsToMetric( pGeo->GetWidth() ) );
697 else
698 return -1;
702 * @descr: Whether the margins is same as parent layout
705 bool LwpMiddleLayout::MarginsSameAsParent()
707 if(m_nOverrideFlag & OVER_MARGINS)
709 return LwpVirtualLayout::MarginsSameAsParent();
711 if(!m_BasedOnStyle.IsNull())
713 LwpVirtualLayout* pLay = dynamic_cast<LwpVirtualLayout*> (m_BasedOnStyle.obj().get());
714 if (pLay)
715 pLay->MarginsSameAsParent();
717 return LwpVirtualLayout::MarginsSameAsParent();
722 * @descr: Get margin
723 * @param: nWhichSide - 0: left, 1: right, 2:top, 3: bottom
725 double LwpMiddleLayout::GetMarginsValue(const sal_uInt8 &nWhichSide)
727 double fValue = 0;
728 if((nWhichSide==MARGIN_LEFT)||(nWhichSide==MARGIN_RIGHT))
730 if ( MarginsSameAsParent() )
732 LwpVirtualLayout* pParent = dynamic_cast<LwpVirtualLayout*> (GetParent().obj().get());
733 if(pParent && !pParent->IsHeader())
735 fValue = pParent->GetMarginsValue(nWhichSide);
736 return fValue;
741 if(m_nOverrideFlag & OVER_MARGINS)
743 LwpLayoutMargins* pMar1 = dynamic_cast<LwpLayoutMargins*> (m_LayMargins.obj().get());
744 if(pMar1)
746 fValue = pMar1->GetMargins().GetMarginsValue(nWhichSide);
747 return fValue;
750 LwpVirtualLayout* pStyle = dynamic_cast<LwpVirtualLayout*> (m_BasedOnStyle.obj().get());
751 if(pStyle)
753 fValue = pStyle->GetMarginsValue(nWhichSide);
754 return fValue;
756 return LwpVirtualLayout::GetMarginsValue(nWhichSide);
759 * @descr: Get extmargin value
760 * @param: nWhichSide - 0: left, 1: right, 2:top, 3: bottom
761 * @param:
762 * @return:
764 double LwpMiddleLayout::GetExtMarginsValue(const sal_uInt8 &nWhichSide)
766 double fValue = 0;
767 if(m_nOverrideFlag & OVER_MARGINS)
769 LwpLayoutMargins* pMar1 = dynamic_cast<LwpLayoutMargins*> (m_LayMargins.obj().get());
770 if(pMar1)
772 fValue = pMar1->GetExtMargins().GetMarginsValue(nWhichSide);
773 return fValue;
776 LwpVirtualLayout* pStyle = dynamic_cast<LwpVirtualLayout*> (m_BasedOnStyle.obj().get());
777 if(pStyle)
779 fValue = pStyle->GetExtMarginsValue(nWhichSide);
780 return fValue;
782 return LwpVirtualLayout::GetExtMarginsValue(nWhichSide);
785 * @descr: Get the LwpBorderStuff object according to m_LayBorderStuff id.
786 * @param:
787 * @param:
788 * @return:
790 LwpBorderStuff* LwpMiddleLayout::GetBorderStuff()
792 if(m_nOverrideFlag & OVER_BORDERS)
794 LwpLayoutBorder* pLayoutBorder = dynamic_cast<LwpLayoutBorder*>(m_LayBorderStuff.obj().get());
795 return pLayoutBorder ? &pLayoutBorder->GetBorderStuff() : NULL;
797 else if( !m_BasedOnStyle.IsNull() )
799 LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj().get() );
800 return pLay ? pLay->GetBorderStuff() : NULL;
802 return NULL;
806 * @descr: Get LwpBackgroundStuff object according to m_LayBackgroundStuff id;
807 * @param:
808 * @param:
809 * @return:
811 LwpBackgroundStuff* LwpMiddleLayout::GetBackgroundStuff()
813 if(m_nOverrideFlag & OVER_BACKGROUND)
815 LwpLayoutBackground* pLayoutBackground = dynamic_cast<LwpLayoutBackground*>(m_LayBackgroundStuff.obj().get());
816 return pLayoutBackground ? &pLayoutBackground->GetBackgoudStuff() : NULL;
818 else if( !m_BasedOnStyle.IsNull() )
820 LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj().get() );
821 return pLay ? pLay->GetBackgroundStuff() : NULL;
823 return NULL;
826 * @descr: create xfborder.
827 * @param:
828 * @param:
829 * @return:
831 XFBorders* LwpMiddleLayout::GetXFBorders()
833 LwpBorderStuff* pBorderStuff = GetBorderStuff();
834 if(pBorderStuff&&pBorderStuff->GetSide() != 0)
836 //copy from lwpparastyle.
837 XFBorders *pXFBorders = new XFBorders();
838 // apply 4 borders respectively
839 LwpBorderStuff::BorderType pType[] = { LwpBorderStuff::LEFT, LwpBorderStuff::RIGHT,
840 LwpBorderStuff::TOP, LwpBorderStuff::BOTTOM };
842 for (sal_uInt8 nC = 0; nC < 4; nC++)
844 if (pBorderStuff->HasSide(pType[nC]))
846 LwpParaStyle::ApplySubBorder(pBorderStuff, pType[nC], pXFBorders);
849 return pXFBorders;
851 return NULL;
855 * @descr: Get text direction settings.
856 * @param:
857 * @param:
858 * @return:
860 enumXFTextDir LwpMiddleLayout::GetTextDirection()
862 enumXFTextDir eTextDir = enumXFTextDirNone;
863 sal_uInt8 nDirection = GetContentOrientation();
864 switch(nDirection)
866 case TEXT_ORIENT_LRTB:
868 eTextDir = enumXFTextDirLR_TB;
869 break;
871 case TEXT_ORIENT_TBRL:
873 eTextDir = enumXFTextDirTB_RL;
874 break;
876 case TEXT_ORIENT_RLBT: // not supported now
878 eTextDir = enumXFTextDirNone;
879 break;
881 case TEXT_ORIENT_BTLR: // not supported now
883 eTextDir = enumXFTextDirNone;
884 break;
886 default:
887 break;
889 return eTextDir;
892 * @descr: Get back ground color.
893 * @param:
894 * @param:
895 * @return:
897 LwpColor* LwpMiddleLayout::GetBackColor()
899 LwpBackgroundStuff* pBackgroundStuff = GetBackgroundStuff();
900 if(pBackgroundStuff && !pBackgroundStuff->IsTransparent())
902 LwpColor* pColor = pBackgroundStuff->GetFillColor();
903 if(pColor->IsValidColor())
905 return pColor;
908 return NULL;
912 * @descr: Add back color settings into xfpagemaster.
913 * @param:
914 * @param:
915 * @return:
917 LwpTabOverride* LwpMiddleLayout::GetTabOverride()
919 if(m_nAttributes & OVER_TABS)
921 if(!m_TabPiece.IsNull())
923 LwpTabPiece *pPiece = dynamic_cast<LwpTabPiece*>(m_TabPiece.obj().get());
924 return static_cast<LwpTabOverride*>(pPiece ? pPiece->GetOverride() : NULL);
926 return NULL;
928 else if( !m_BasedOnStyle.IsNull() )
930 LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj().get() );
931 return pLay ? pLay->GetTabOverride() : NULL;
933 return NULL;
937 * @descr: Layscale for graphic & watermark
938 * @param:
939 * @param:
940 * @return:
942 sal_uInt16 LwpMiddleLayout::GetScaleMode()
944 if ((m_nOverrideFlag & OVER_SCALING) && m_LayScale.obj().is())
945 return GetLayoutScale()->GetScaleMode();
946 else if (m_BasedOnStyle.obj().is())
947 return dynamic_cast<LwpMiddleLayout*>(m_BasedOnStyle.obj().get())->GetScaleMode();
948 else
949 return (LwpLayoutScale::FIT_IN_FRAME | LwpLayoutScale::MAINTAIN_ASPECT_RATIO);
952 sal_uInt16 LwpMiddleLayout::GetScaleTile()
954 if ((m_nOverrideFlag & OVER_SCALING) && m_LayScale.obj().is())
955 return (GetLayoutScale()->GetPlacement() & LwpLayoutScale::TILED)
956 ? 1 : 0;
957 else if (m_BasedOnStyle.obj().is())
958 return dynamic_cast<LwpMiddleLayout*>(m_BasedOnStyle.obj().get())->GetScaleTile();
959 else
960 return 0;
963 sal_uInt16 LwpMiddleLayout::GetScaleCenter()
965 if ((m_nOverrideFlag & OVER_SCALING) && m_LayScale.obj().is())
966 return (GetLayoutScale()->GetPlacement() & LwpLayoutScale::CENTERED)
967 ? 1 : 0;
968 else if (m_BasedOnStyle.obj().is())
969 return dynamic_cast<LwpMiddleLayout*>(m_BasedOnStyle.obj().get())->GetScaleCenter();
970 else
971 return 0;
974 sal_uInt32 LwpMiddleLayout::GetScalePercentage()
976 if ((m_nOverrideFlag & OVER_SCALING) && m_LayScale.obj().is())
977 return GetLayoutScale()->GetScalePercentage()/10;//m_nScalePercentage 1000 = 100%
978 else if (m_BasedOnStyle.obj().is())
979 return dynamic_cast<LwpMiddleLayout*>(m_BasedOnStyle.obj().get())->GetScalePercentage();
980 else
981 return 100;
984 double LwpMiddleLayout::GetScaleWidth()
986 if ((m_nOverrideFlag & OVER_SCALING) && m_LayScale.obj().is())
987 return LwpTools::ConvertFromUnits(GetLayoutScale()->GetScaleWidth());
988 else if (m_BasedOnStyle.obj().is())
989 return dynamic_cast<LwpMiddleLayout*>(m_BasedOnStyle.obj().get())->GetScaleWidth();
990 else
991 return 0;
994 double LwpMiddleLayout::GetScaleHeight()
996 if ((m_nOverrideFlag & OVER_SCALING) && m_LayScale.obj().is())
997 return LwpTools::ConvertFromUnits(GetLayoutScale()->GetScaleHeight());
998 else if (m_BasedOnStyle.obj().is())
999 return dynamic_cast<LwpMiddleLayout*>(m_BasedOnStyle.obj().get())->GetScaleHeight();
1000 else
1001 return 0;
1003 bool LwpMiddleLayout::CanSizeRight()
1005 sal_uInt8 RelType = GetRelativeType();
1007 if (RelType == LwpLayoutRelativityGuts::LAY_INLINE || RelType == LwpLayoutRelativityGuts::LAY_PARA_RELATIVE
1008 || RelType == LwpLayoutRelativityGuts::LAY_INLINE_VERTICAL)
1010 return false;
1012 return true;
1014 sal_Int32 LwpMiddleLayout::GetMinimumWidth()
1016 if (((m_nAttributes3 & STYLE3_WIDTHVALID) != 0) && GetGeometry())
1018 return GetGeometry()->GetWidth();
1020 else if (m_nOverrideFlag & OVER_SIZE)
1022 return DetermineWidth();
1024 return 0;
1026 sal_Int32 LwpMiddleLayout::DetermineWidth()
1028 if (IsSizeRightToContent())
1030 assert(false);
1032 else if (IsSizeRightToContainer())
1034 assert(false);
1036 else
1038 m_nAttributes3 |= STYLE3_WIDTHVALID;
1039 return GetGeometry()->GetWidth();
1041 return 0;
1043 bool LwpMiddleLayout::IsSizeRightToContainer()
1045 if (!CanSizeRight())
1046 return false;
1048 if (m_nOverrideFlag & OVER_SIZE)
1050 return (m_nDirection & ((LAY_USEDIRECTION|LAY_AUTOSIZE|LAY_TOCONTAINER)
1051 << SHIFT_RIGHT))
1052 == ((LAY_USEDIRECTION | LAY_TOCONTAINER | LAY_AUTOSIZE) << SHIFT_RIGHT);
1054 else if (m_BasedOnStyle.obj().is())
1056 LwpMiddleLayout * pLayout = dynamic_cast<LwpMiddleLayout *>(m_BasedOnStyle.obj().get());
1057 return pLayout && pLayout->IsSizeRightToContainer();
1059 else
1060 return false;
1062 bool LwpMiddleLayout::IsSizeRightToContent()
1064 if (!CanSizeRight())
1065 return false;
1067 if (m_nOverrideFlag & OVER_SIZE)
1069 return (m_nDirection & ((LAY_USEDIRECTION|LAY_AUTOSIZE|LAY_TOCONTAINER)
1070 << SHIFT_RIGHT))
1071 == ((LAY_USEDIRECTION | LAY_AUTOSIZE) << SHIFT_RIGHT);
1073 else if (m_BasedOnStyle.obj().is())
1075 LwpMiddleLayout * pLayout = dynamic_cast<LwpMiddleLayout *>(m_BasedOnStyle.obj().get());
1076 return pLayout && pLayout->IsSizeRightToContent();
1078 else
1079 return false;
1083 * @descr: Get layout height
1086 double LwpMiddleLayout::GetHeight()
1088 return GetGeometryHeight();
1092 * @descr: Get layout height
1095 double LwpMiddleLayout::GetWidth()
1097 return GetGeometryWidth();
1100 * @descr: Get layout origin point
1103 LwpPoint LwpMiddleLayout::GetOrigin()
1105 LwpLayoutGeometry* pGeo = GetGeometry();
1106 if(pGeo)
1108 sal_uInt8 nType = GetRelativeType();
1109 if(nType == LwpLayoutRelativityGuts::LAY_INLINE
1110 || nType == LwpLayoutRelativityGuts::LAY_INLINE_NEWLINE )
1112 return pGeo->GetAbsoluteOrigin();
1114 else
1115 return pGeo->GetOrigin();
1119 return LwpPoint();
1123 * @descr: Whether the fill is pattern fill or not
1124 * @return: True if yes, false if not.
1126 bool LwpMiddleLayout::IsPatternFill()
1128 LwpBackgroundStuff* pBackgroundStuff = GetBackgroundStuff();
1129 if (pBackgroundStuff)
1131 return pBackgroundStuff->IsPatternFill();
1134 return false;
1138 * @descr: Get the fill pattern style. Data are saved in a XFBGImage object
1139 * @return: the fill pattern style.
1141 XFBGImage* LwpMiddleLayout::GetFillPattern()
1143 LwpBackgroundStuff* pBackgroundStuff = GetBackgroundStuff();
1144 if (pBackgroundStuff)
1146 return pBackgroundStuff->GetFillPattern();
1149 return NULL;
1154 * @descr: Whether the height and width of layout is auto grow
1157 bool LwpMiddleLayout::IsAutoGrow()
1159 if(m_nOverrideFlag & OVER_SIZE)
1161 return (m_nDirection &
1162 ((LAY_AUTOGROW << SHIFT_UP) | (LAY_AUTOGROW << SHIFT_DOWN) |
1163 (LAY_AUTOGROW << SHIFT_RIGHT) | (LAY_AUTOGROW << SHIFT_LEFT))) != 0;
1165 else if( !m_BasedOnStyle.IsNull() )
1167 LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj().get() );
1168 return pLay && pLay->IsAutoGrow();
1170 return LwpVirtualLayout::IsAutoGrow();
1174 * @descr: Whether the height of layout is auto grow down
1177 bool LwpMiddleLayout::IsAutoGrowDown()
1179 if(m_nOverrideFlag & OVER_SIZE)
1181 return (m_nDirection & (LAY_AUTOGROW << SHIFT_DOWN)) != 0;
1183 else if( !m_BasedOnStyle.IsNull() )
1185 LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj().get() );
1186 return pLay && pLay->IsAutoGrowDown();
1188 return LwpVirtualLayout::IsAutoGrowDown();
1192 * @descr: Whether the height of layout is auto grow up
1195 bool LwpMiddleLayout::IsAutoGrowUp()
1197 if(m_nOverrideFlag & OVER_SIZE)
1199 return (m_nDirection & (LAY_AUTOGROW << SHIFT_UP)) != 0;
1201 else if( !m_BasedOnStyle.IsNull() )
1203 LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj().get() );
1204 return pLay && pLay->IsAutoGrowUp();
1206 return LwpVirtualLayout::IsAutoGrowUp();
1210 * @descr: Whether the height of layout is auto grow down
1213 bool LwpMiddleLayout::IsAutoGrowLeft()
1215 if(m_nOverrideFlag & OVER_SIZE)
1217 return (m_nDirection & (LAY_AUTOGROW << SHIFT_LEFT)) != 0;
1219 else if( !m_BasedOnStyle.IsNull() )
1221 LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj().get() );
1222 if (pLay)
1223 return pLay->IsAutoGrowLeft();
1225 return LwpVirtualLayout::IsAutoGrowLeft();
1229 * @descr: Whether the height of layout is auto grow down
1232 bool LwpMiddleLayout::IsAutoGrowRight()
1234 if(m_nOverrideFlag & OVER_SIZE)
1236 return (m_nDirection & (LAY_AUTOGROW << SHIFT_RIGHT)) != 0;
1238 else if( !m_BasedOnStyle.IsNull() )
1240 LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj().get() );
1241 return pLay && pLay->IsAutoGrowRight();
1243 return LwpVirtualLayout::IsAutoGrowRight();
1247 * @descr: Get contents orientation
1250 sal_uInt8 LwpMiddleLayout::GetContentOrientation()
1252 //content orientation in Graphic objects and OLE objects not supported now
1253 if((m_nOverrideFlag & OVER_ROTATION)&& !m_LayGeometry.IsNull())
1255 LwpLayoutGeometry* pLayGeometry = dynamic_cast<LwpLayoutGeometry*> (m_LayGeometry.obj().get());
1256 if (pLayGeometry)
1257 return pLayGeometry->GetContentOrientation();
1259 else if( !m_BasedOnStyle.IsNull() )
1261 LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj().get() );
1262 if (pLay)
1263 return pLay->GetContentOrientation();
1265 return LwpVirtualLayout::GetContentOrientation();
1269 * @descr: Whether it is honoring protection
1272 bool LwpMiddleLayout::HonorProtection()
1274 if(m_nOverrideFlag & OVER_MISC)
1276 if(!(m_nAttributes2 & STYLE2_HONORPROTECTION))
1277 return false;
1279 LwpVirtualLayout* pParent = dynamic_cast<LwpVirtualLayout*> (GetParent().obj().get());
1280 if(pParent && !pParent->IsHeader())
1282 return pParent->HonorProtection();
1285 if(m_pFoundry)//is null now
1287 LwpDocument* pDoc = m_pFoundry->GetDocument();
1288 if(pDoc)
1290 return pDoc->HonorProtection();
1294 else if( !m_BasedOnStyle.IsNull() )
1296 LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj().get() );
1297 if (pLay)
1298 return pLay->HonorProtection();
1301 return LwpVirtualLayout::HonorProtection();
1305 * @descr: Whether it is pretected
1308 bool LwpMiddleLayout::IsProtected()
1310 bool bProtected = false;
1311 if(m_nOverrideFlag & OVER_MISC)
1313 bProtected = (m_nAttributes & STYLE_PROTECTED)!=0;
1315 else if( !m_BasedOnStyle.IsNull() )
1317 LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj().get() );
1318 bProtected = pLay && pLay->IsProtected();
1320 else
1321 bProtected = LwpVirtualLayout::IsProtected();
1323 LwpVirtualLayout* pParent = dynamic_cast<LwpVirtualLayout*> (GetParent().obj().get());
1324 if(pParent && !pParent->IsHeader())
1326 /* If a parent's protected then none of its children can be accessed. */
1327 if(pParent->IsProtected())
1328 return true;
1330 if(pParent->HonorProtection())
1331 return bProtected;
1333 /* If our parent isn't honoring protection then we aren't protected. */
1334 return false;
1337 if(m_pFoundry)//is null now
1339 LwpDocument* pDoc = m_pFoundry->GetDocument();
1340 if(pDoc)
1342 if (pDoc->HonorProtection())
1343 return bProtected;
1345 /* If the document isn't honoring protection then we aren't protected.*/
1346 return false;
1350 return bProtected;
1354 * @descr: Get watermark layout
1357 LwpVirtualLayout* LwpMiddleLayout::GetWaterMarkLayout()
1359 LwpVirtualLayout* pLay = dynamic_cast<LwpVirtualLayout*>(GetChildHead().obj().get());
1360 while(pLay)
1362 if( pLay->IsForWaterMark())
1364 return pLay;
1366 pLay = dynamic_cast<LwpVirtualLayout*> (pLay->GetNext().obj().get());
1368 return NULL;
1372 * @descr: Create and reture xfbgimage object for watermark
1375 XFBGImage* LwpMiddleLayout::GetXFBGImage()
1377 LwpMiddleLayout* pLay = static_cast<LwpMiddleLayout*>(GetWaterMarkLayout());
1378 if(pLay)
1380 //test BGImage
1381 LwpGraphicObject* pGrfObj = dynamic_cast<LwpGraphicObject*>(pLay->GetContent().obj().get());
1382 if(pGrfObj)
1384 XFBGImage* pXFBGImage = new XFBGImage();
1386 if(pGrfObj->IsLinked())
1388 //set file link
1389 OUString linkedfilepath = pGrfObj->GetLinkedFilePath();
1390 OUString fileURL = LwpTools::convertToFileUrl(OUStringToOString(linkedfilepath, osl_getThreadTextEncoding()));
1391 pXFBGImage->SetFileLink(fileURL);
1393 else
1395 sal_uInt8* pGrafData = NULL;
1396 sal_uInt32 nDataLen = pGrfObj->GetRawGrafData(pGrafData);
1397 pXFBGImage->SetImageData(pGrafData, nDataLen);
1398 if(pGrafData)
1400 delete[] pGrafData;
1401 pGrafData = NULL;
1405 //automatic, top left
1406 pXFBGImage->SetPosition(enumXFAlignStart,enumXFAlignTop);
1407 if(pLay->GetScaleCenter())
1409 //center
1410 pXFBGImage->SetPosition(enumXFAlignCenter,enumXFAlignCenter);
1412 else if(pLay->GetScaleTile())
1414 //tile
1415 pXFBGImage->SetRepeate();
1417 //fit type, area type
1418 if((pLay->GetScaleMode()& LwpLayoutScale::FIT_IN_FRAME)!=0)
1420 if((pLay->GetScaleMode()& LwpLayoutScale::MAINTAIN_ASPECT_RATIO)==0)
1422 pXFBGImage->SetStretch();
1425 return pXFBGImage;
1428 return NULL;
1432 * @descr: Whether the page uses the printer setting
1435 bool LwpMiddleLayout::GetUsePrinterSettings()
1437 if(m_nOverrideFlag & OVER_SIZE)
1439 return (m_nAttributes3 & STYLE3_USEPRINTERSETTINGS) != 0;
1441 else if( !m_BasedOnStyle.IsNull() )
1443 LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj().get() );
1444 return pLay && pLay->GetUsePrinterSettings();
1446 return false;
1449 //Check whether there are contents in the layout
1450 bool LwpMiddleLayout::HasContent()
1452 rtl::Reference<LwpObject> content = m_Content.obj();
1453 if(content.is())
1454 return true;
1455 return false;
1457 //End by
1459 LwpLayout::LwpLayout( LwpObjectHeader &objHdr, LwpSvStream* pStrm ) :
1460 LwpMiddleLayout(objHdr, pStrm), m_pUseWhen(new LwpUseWhen)
1463 LwpLayout::~LwpLayout()
1465 if (m_pUseWhen)
1467 delete m_pUseWhen;
1471 void LwpLayout::Read()
1473 LwpObjectStream* pStrm = m_pObjStrm;
1475 LwpMiddleLayout::Read();
1476 if (LwpFileHeader::m_nFileRevision < 0x000B)
1478 // read PreRevBLayout...
1480 else
1482 sal_uInt16 nSimple = pStrm->QuickReaduInt16();
1484 if (!nSimple)
1486 m_pUseWhen->Read(pStrm);
1488 sal_uInt8 nFlag = pStrm->QuickReaduInt8();
1489 if (nFlag)
1490 m_Positon.ReadIndexed(pStrm);
1493 m_LayColumns.ReadIndexed(pStrm);
1494 m_LayGutterStuff.ReadIndexed(pStrm);
1495 m_LayJoinStuff.ReadIndexed(pStrm);
1496 m_LayShadow.ReadIndexed(pStrm);
1498 if (pStrm->CheckExtra())
1500 m_LayExtJoinStuff.ReadIndexed(pStrm);
1501 pStrm->SkipExtra();
1507 * @descr: Get columns number
1510 sal_uInt16 LwpLayout::GetNumCols()
1512 if(m_nOverrideFlag & OVER_COLUMNS)
1514 LwpLayoutColumns* pLayColumns = dynamic_cast<LwpLayoutColumns*>(m_LayColumns.obj().get());
1515 if(pLayColumns)
1517 return pLayColumns->GetNumCols();
1521 LwpVirtualLayout* pStyle = dynamic_cast<LwpVirtualLayout*> (m_BasedOnStyle.obj().get());
1522 if(pStyle)
1524 return pStyle->GetNumCols();
1527 return LwpVirtualLayout::GetNumCols();
1532 * @descr: Get column width
1533 * @param: the order of column
1535 double LwpLayout::GetColWidth(sal_uInt16 nIndex)
1537 if((m_nOverrideFlag & OVER_COLUMNS)||(m_nAttributes2 & STYLE2_LOCALCOLUMNINFO))
1539 LwpLayoutColumns* pLayColumns = dynamic_cast<LwpLayoutColumns*>(m_LayColumns.obj().get());
1540 if(pLayColumns)
1542 return pLayColumns->GetColWidth(nIndex);
1546 LwpVirtualLayout* pStyle = dynamic_cast<LwpVirtualLayout*> (m_BasedOnStyle.obj().get());
1547 if(pStyle)
1549 return pStyle->GetColWidth(nIndex);
1552 return LwpVirtualLayout::GetColWidth(nIndex);
1557 * @descr: Get gap between columns
1558 * @param: the order of column
1560 double LwpLayout::GetColGap(sal_uInt16 nIndex)
1562 if((m_nOverrideFlag & OVER_COLUMNS)||(m_nAttributes2 & STYLE2_LOCALCOLUMNINFO))
1564 LwpLayoutColumns* pLayColumns = dynamic_cast<LwpLayoutColumns*>(m_LayColumns.obj().get());
1565 if(pLayColumns)
1567 return pLayColumns->GetColGap(nIndex);
1571 LwpVirtualLayout* pStyle = dynamic_cast<LwpVirtualLayout*> (m_BasedOnStyle.obj().get());
1572 if(pStyle)
1574 return pStyle->GetColGap(nIndex);
1577 return LwpVirtualLayout::GetColGap(nIndex);
1581 * @descr: Create and return XFColumns object
1584 XFColumns* LwpLayout::GetXFColumns()
1586 //if there is only one column, do not need insert columns
1587 sal_uInt16 nCols = GetNumCols();
1588 if(nCols==1)
1590 return NULL;
1593 XFColumns* pColumns = new XFColumns();
1594 //set XFColumnSep
1595 boost::scoped_ptr<XFColumnSep> pColumnSep(GetColumnSep());
1596 if(pColumnSep)
1598 pColumns->SetSeparator(*pColumnSep);
1601 //set column count and column gap
1602 pColumns->SetCount(nCols);
1603 double fGap = GetColGap(0);
1604 pColumns->SetGap(fGap);
1606 //set xfcolumn
1607 for(sal_uInt16 nIndex = 0; nIndex<nCols; nIndex++)
1609 XFColumn aColumn;
1610 sal_Int32 nWidth = static_cast<sal_Int32>(GetColWidth(nIndex));
1611 nWidth=8305/nCols; //relative width
1612 aColumn.SetRelWidth(nWidth);
1614 //the left and right margins is 0;
1615 double nGap = GetColGap(nIndex)/2;
1616 //nGap=0;
1617 aColumn.SetMargins(nGap,nGap);
1618 if(nIndex==0)
1620 aColumn.SetMargins(0,nGap);
1622 if(nIndex==(nCols-1))
1624 aColumn.SetMargins(nGap,0);
1626 pColumns->AddColumn(aColumn);
1629 return pColumns;
1633 * @descr: Create and return XFColumnSep object
1636 XFColumnSep* LwpLayout::GetColumnSep()
1639 //Get LwpLayoutGutters
1640 LwpLayoutGutters* pLayoutGutters = dynamic_cast<LwpLayoutGutters*>(m_LayGutterStuff.obj().get());
1641 if(!pLayoutGutters)
1643 return NULL;
1646 LwpBorderStuff& pBorderStuff = pLayoutGutters->GetBorderStuff();
1648 LwpBorderStuff::BorderType eType = LwpBorderStuff::LEFT;
1649 LwpColor aColor = pBorderStuff.GetSideColor(eType);
1650 double fWidth = pBorderStuff.GetSideWidth(eType);
1651 //sal_uInt16 nType = pBorderStuff->GetSideType(eType);
1653 XFColumnSep* pColumnSep = new XFColumnSep();
1654 XFColor aXFColor(aColor.To24Color());
1655 pColumnSep->SetColor(aXFColor);
1656 pColumnSep->SetWidth(fWidth);
1657 pColumnSep->SetRelHeight(100);
1658 pColumnSep->SetVerticalAlign(enumXFAlignTop);
1660 return pColumnSep;
1664 * @descr: Get use when type
1667 LwpLayout::UseWhenType LwpLayout::GetUseWhenType()
1669 UseWhenType eType = StartWithinPage;
1670 LwpUseWhen* pUseWhen = GetUseWhen();
1671 if(pUseWhen)
1673 if(pUseWhen->IsStartOnThisHF())
1675 eType = StartWithinColume;
1677 else if(pUseWhen->IsStartOnThisPage())
1679 eType = StartWithinPage;
1681 else if(pUseWhen->IsStartOnNextPage())
1683 eType = StartOnNextPage;
1685 else if(pUseWhen->IsStartOnNextOddPage())
1687 eType = StartOnOddPage;
1689 else if(pUseWhen->IsStartOnNextEvenPage())
1691 eType = StartOnEvenPage;
1695 else
1697 eType = StartOnNextPage;
1699 return eType;
1703 * @descr: Get use page
1706 sal_uInt16 LwpLayout::GetUsePage()
1708 if(m_nOverrideFlag & OVER_PLACEMENT)
1710 LwpUseWhen* pUseWhen = GetUseWhen();
1711 if(pUseWhen)
1712 return pUseWhen->GetUsePage();
1713 else
1714 return 0;
1716 else if( !m_BasedOnStyle.IsNull() )
1718 LwpLayout* pLay = dynamic_cast<LwpLayout*> ( m_BasedOnStyle.obj().get() );
1719 return pLay ? pLay->GetUsePage() : 0;
1721 return 0;
1725 * @descr: Get usewhen pointer
1728 LwpUseWhen* LwpLayout::VirtualGetUseWhen()
1730 if(m_nOverrideFlag & OVER_PLACEMENT)
1732 return m_pUseWhen;
1734 else if( !m_BasedOnStyle.IsNull() )
1736 LwpLayout* pLay = dynamic_cast<LwpLayout*> ( m_BasedOnStyle.obj().get() );
1737 return pLay ? pLay->VirtualGetUseWhen() : NULL;
1739 return LwpVirtualLayout::VirtualGetUseWhen();
1743 * @descr: Whether it is use on all pages
1746 bool LwpLayout::IsUseOnAllPages()
1748 if(m_nOverrideFlag & OVER_PLACEMENT)
1750 LwpUseWhen* pUseWhen = GetUseWhen();
1751 if(pUseWhen)
1752 return pUseWhen->IsUseOnAllPages();
1753 else
1754 return false;
1756 else if( !m_BasedOnStyle.IsNull() )
1758 LwpLayout* pLay = dynamic_cast<LwpLayout*> ( m_BasedOnStyle.obj().get() );
1759 if (pLay)
1760 return pLay->IsUseOnAllPages();
1762 return LwpVirtualLayout::IsUseOnAllPages();
1766 * @descr: Whether it is use on all even pages
1769 bool LwpLayout::IsUseOnAllEvenPages()
1771 if(m_nOverrideFlag & OVER_PLACEMENT)
1773 LwpUseWhen* pUseWhen = GetUseWhen();
1774 if(pUseWhen)
1775 return pUseWhen->IsUseOnAllEvenPages();
1776 else
1777 return false;
1779 else if( !m_BasedOnStyle.IsNull() )
1781 LwpLayout* pLay = dynamic_cast<LwpLayout*> ( m_BasedOnStyle.obj().get() );
1782 if (pLay)
1783 return pLay->IsUseOnAllEvenPages();
1785 return LwpVirtualLayout::IsUseOnAllEvenPages();
1789 * @descr: Whether it is use on all odd pages
1792 bool LwpLayout::IsUseOnAllOddPages()
1794 if(m_nOverrideFlag & OVER_PLACEMENT)
1796 LwpUseWhen* pUseWhen = GetUseWhen();
1797 if(pUseWhen)
1798 return pUseWhen->IsUseOnAllOddPages();
1799 else
1800 return false;
1802 else if( !m_BasedOnStyle.IsNull() )
1804 LwpLayout* pLay = dynamic_cast<LwpLayout*> ( m_BasedOnStyle.obj().get() );
1805 if (pLay)
1806 return pLay->IsUseOnAllOddPages();
1808 return LwpVirtualLayout::IsUseOnAllOddPages();
1812 * @descr: Whether it is use on current page
1815 bool LwpLayout::IsUseOnPage()
1817 if(m_nOverrideFlag & OVER_PLACEMENT)
1819 LwpUseWhen* pUseWhen = GetUseWhen();
1820 if(pUseWhen)
1821 return pUseWhen->IsUseOnPage();
1822 else
1823 return false;
1825 else if( !m_BasedOnStyle.IsNull() )
1827 LwpLayout* pLay = dynamic_cast<LwpLayout*> ( m_BasedOnStyle.obj().get() );
1828 if (pLay)
1829 return pLay->IsUseOnPage();
1831 return LwpVirtualLayout::IsUseOnPage();
1835 * @descr: Get the LwpShadow object according to m_LayShadow id.
1836 * @param:
1837 * @param:
1838 * @return:
1840 LwpShadow* LwpLayout::GetShadow()
1842 if(m_nOverrideFlag & OVER_SHADOW)
1844 LwpLayoutShadow* pLayoutShadow = dynamic_cast<LwpLayoutShadow*>(m_LayShadow.obj().get());
1845 return pLayoutShadow ? &pLayoutShadow->GetShadow() : NULL;
1847 else if( !m_BasedOnStyle.IsNull() )
1849 LwpLayout* pLay = dynamic_cast<LwpLayout*> ( m_BasedOnStyle.obj().get() );
1850 return pLay ? pLay->GetShadow() : NULL;
1852 return NULL;
1856 * @descr: create xfshadow
1857 * @param:
1858 * @param:
1859 * @return:
1861 XFShadow* LwpLayout::GetXFShadow()
1863 LwpShadow* pShadow = GetShadow();
1864 if( pShadow )
1866 LwpColor color = pShadow->GetColor();
1867 double offsetX = pShadow->GetOffsetX();
1868 double offsetY = pShadow->GetOffsetY();
1870 if( offsetX && offsetY && color.IsValidColor() )
1872 XFShadow* pXFShadow = new XFShadow();
1873 enumXFShadowPos eXFShadowPos = enumXFShadowLeftTop;
1874 double fOffset = 0;
1876 bool left = false;
1877 bool top = false;
1878 if( offsetX < 0 )
1879 left = true;
1880 if( offsetY < 0 )
1881 top = true;
1882 if( left )
1884 fOffset = -offsetX;
1885 if( top )
1886 eXFShadowPos = enumXFShadowLeftTop;
1887 else
1888 eXFShadowPos = enumXFShadowLeftBottom;
1890 else
1892 fOffset = offsetX;
1893 if( top )
1894 eXFShadowPos = enumXFShadowRightTop;
1895 else
1896 eXFShadowPos = enumXFShadowRightBottom;
1899 pXFShadow->SetPosition(eXFShadowPos);
1900 pXFShadow->SetOffset(fOffset);
1901 pXFShadow->SetColor(XFColor(color.To24Color()));
1903 return pXFShadow;
1906 return NULL;
1910 * @descr get the layout that containers the current frame layout
1913 LwpVirtualLayout* LwpLayout::GetContainerLayout()
1915 if(IsRelativeAnchored())
1917 //get position
1918 LwpPara* pPara = dynamic_cast<LwpPara*>(GetPosition().obj().get());
1919 if(pPara)
1921 LwpStory* pStory = pPara->GetStory();
1922 return pStory ? pStory->GetTabLayout() : NULL;
1925 return GetParentLayout();
1928 LwpPlacableLayout::LwpPlacableLayout( LwpObjectHeader &objHdr, LwpSvStream* pStrm )
1929 : LwpLayout(objHdr, pStrm)
1930 , m_nWrapType(0)
1931 , m_nBuoyancy(0)
1932 , m_nBaseLineOffset(0)
1933 , m_nPageNumber(0)
1936 LwpPlacableLayout::~LwpPlacableLayout()
1939 void LwpPlacableLayout::Read()
1941 LwpObjectStream* pStrm = m_pObjStrm;
1942 LwpLayout::Read();
1943 if(LwpFileHeader::m_nFileRevision < 0x000B)
1945 assert(false);
1947 else
1949 sal_uInt16 simple = pStrm->QuickReaduInt16();
1950 if(!simple)
1952 m_nWrapType = pStrm->QuickReaduInt8();
1953 m_nBuoyancy = pStrm->QuickReaduInt8();
1954 m_nBaseLineOffset = pStrm->QuickReadInt32();
1955 m_Script.Read( pStrm);
1957 else
1959 m_nWrapType = LAY_WRAP_AROUND;
1960 m_nBuoyancy = LAY_BUOYNEUTRAL;
1961 m_nBaseLineOffset = 0;
1963 m_LayRelativity.ReadIndexed( pStrm);
1964 if(pStrm->CheckExtra())
1966 sal_uInt16 count = pStrm->QuickReaduInt16();
1967 if(count)
1969 // temporily added by to avoid assertion
1970 while (count)
1972 LwpPoint aPoint;
1973 aPoint.Read(pStrm);
1974 count--;
1976 // end added by
1978 pStrm->SkipExtra();
1983 * @descr: get wrap type
1984 * @param:
1985 * @param:
1986 * @return:
1988 sal_uInt8 LwpPlacableLayout::GetWrapType()
1990 if(m_nOverrideFlag & OVER_PLACEMENT)
1992 return m_nWrapType;
1994 else if( !m_BasedOnStyle.IsNull() )
1996 LwpPlacableLayout* pLay = dynamic_cast<LwpPlacableLayout*> ( m_BasedOnStyle.obj().get() );
1997 if (pLay)
1998 return pLay->GetWrapType();
2000 return LAY_WRAP_AROUND;
2003 * @descr: get LayoutRelativity
2004 * @param:
2005 * @param:
2006 * @return:
2008 LwpLayoutRelativity* LwpPlacableLayout::GetRelativityPiece()
2010 if(!m_LayRelativity.IsNull())
2012 if(m_nOverrideFlag & OVER_PLACEMENT)
2014 return dynamic_cast<LwpLayoutRelativity*>(m_LayRelativity.obj().get());
2017 else if( !m_BasedOnStyle.IsNull() )
2019 LwpPlacableLayout* pLay = dynamic_cast<LwpPlacableLayout*> ( m_BasedOnStyle.obj().get() );
2020 return pLay ? pLay->GetRelativityPiece() : NULL;
2022 return NULL;
2025 * @descr: Get relative type
2028 sal_uInt8 LwpPlacableLayout::GetRelativeType()
2030 LwpLayoutRelativity* pLayRel = GetRelativityPiece();
2031 if(pLayRel)
2033 return pLayRel->GetRelGuts().GetRelativeType();
2035 return LwpVirtualLayout::GetRelativeType();
2038 * @descr: Get offset from the baseline
2041 sal_Int32 LwpPlacableLayout::GetBaseLineOffset()
2043 /* The baseline is only valid if this is flow-with-text */
2044 if(GetRelativeType()!=LwpLayoutRelativityGuts::LAY_INLINE)
2046 return 0;
2049 // First, ask our content if it has a baseline, ignore now
2051 if (Content && Content->GetBaseLineOffset(&Baseline))
2052 return Baseline;
2055 if(m_nOverrideFlag & OVER_PLACEMENT)
2057 return m_nBaseLineOffset;
2059 else if( !m_BasedOnStyle.IsNull() )
2061 LwpPlacableLayout* pLay = dynamic_cast<LwpPlacableLayout*> ( m_BasedOnStyle.obj().get() );
2062 return pLay ? pLay->GetBaseLineOffset() : 0;
2064 return 0;
2068 * @descr: whether the parent layout is page layout
2071 bool LwpPlacableLayout::IsAnchorPage()
2073 if(IsRelativeAnchored())
2074 return false;
2076 LwpVirtualLayout* pLayout = GetParentLayout();
2077 if(pLayout && (pLayout->IsPage() || pLayout->IsHeader() || pLayout->IsFooter()))
2078 //if(pLayout && pLayout->IsPage())
2080 return true;
2082 return false;
2085 * @descr: whether the parent layout is frame layout
2088 bool LwpPlacableLayout::IsAnchorFrame()
2090 if(IsRelativeAnchored())
2091 return false;
2093 LwpVirtualLayout* pLayout = GetParentLayout();
2094 if(pLayout && (pLayout->IsFrame()||pLayout->IsGroupHead()))
2096 return true;
2098 return false;
2101 * @descr: whether the parent layout is cell layout
2104 bool LwpPlacableLayout::IsAnchorCell()
2106 if(IsRelativeAnchored())
2107 return false;
2109 LwpVirtualLayout* pLayout = GetParentLayout();
2110 if(pLayout && pLayout->IsCell())
2112 return true;
2114 return false;
2118 * @descr: Set font style for setting position of frame
2121 void LwpPlacableLayout::SetFont(rtl::Reference<XFFont> const & pFont)
2123 m_pFont = pFont;
2126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */