update dev300-m57
[ooovba.git] / lotuswordpro / source / filter / lwplayout.cxx
blobd39451f907709416c94c22c8d018372e7016a135
1 /*************************************************************************
3 * The Contents of this file are made available subject to the terms of
4 * either of the following licenses
6 * - GNU Lesser General Public License Version 2.1
7 * - Sun Industry Standards Source License Version 1.1
9 * Sun Microsystems Inc., October, 2000
11 * GNU Lesser General Public License Version 2.1
12 * =============================================
13 * Copyright 2000 by Sun Microsystems, Inc.
14 * 901 San Antonio Road, Palo Alto, CA 94303, USA
16 * This library is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU Lesser General Public
18 * License version 2.1, as published by the Free Software Foundation.
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 * MA 02111-1307 USA
31 * Sun Industry Standards Source License Version 1.1
32 * =================================================
33 * The contents of this file are subject to the Sun Industry Standards
34 * Source License Version 1.1 (the "License"); You may not use this file
35 * except in compliance with the License. You may obtain a copy of the
36 * License at http://www.openoffice.org/license.html.
38 * Software provided under this License is provided on an "AS IS" basis,
39 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
40 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
41 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
42 * See the License for the specific provisions governing your rights and
43 * obligations concerning the Software.
45 * The Initial Developer of the Original Code is: IBM Corporation
47 * Copyright: 2008 by IBM Corporation
49 * All Rights Reserved.
51 * Contributor(s): _______________________________________
54 ************************************************************************/
55 /*************************************************************************
56 * @file
57 * For LWP filter architecture prototype
58 ************************************************************************/
59 /*************************************************************************
60 * Change History
61 Jan 2005 Created
62 Feb 2005 Process gemotry, margins
63 ************************************************************************/
65 #include "lwplayout.hxx"
66 #include "lwpusewhen.hxx"
67 #include "lwptools.hxx"
68 #include "xfilter/xfcolumns.hxx"
69 #include "lwpstory.hxx"
70 #include "lwpparastyle.hxx"
71 #include "lwpholder.hxx"
72 #include "lwpdoc.hxx"
73 #include "lwppagehint.hxx"
74 #include "lwpdivinfo.hxx"
75 #include "lwpgrfobj.hxx"
76 #ifndef _OSL_THREAD_H_
77 #include <osl/thread.h>
78 #endif
80 LwpVirtualLayout::LwpVirtualLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
81 : LwpDLNFPVList(objHdr, pStrm)
84 void LwpVirtualLayout::Read()
86 LwpDLNFPVList::Read();
88 LwpObjectStream* pStrm = m_pObjStrm;
89 pStrm->QuickRead(&m_nAttributes, sizeof(m_nAttributes));
90 pStrm->QuickRead(&m_nAttributes2, sizeof(m_nAttributes2));
91 pStrm->QuickRead(&m_nAttributes3, sizeof(m_nAttributes3));
92 pStrm->QuickRead(&m_nOverrideFlag, sizeof(m_nOverrideFlag));
93 pStrm->QuickRead(&m_nDirection, sizeof(m_nDirection));
95 //Note that two bytes is read into m_nEditorID instead of one byte.
96 pStrm->QuickRead(&m_nEditorID, sizeof(m_nEditorID));
98 m_NextEnumerated.ReadIndexed(pStrm);
99 m_PreviousEnumerated.ReadIndexed(pStrm);
101 pStrm->SkipExtra();
104 sal_Bool LwpVirtualLayout::MarginsSameAsParent()
106 return m_nAttributes2 & STYLE2_MARGINSSAMEASPARENT ? sal_True : sal_False;
110 * @descr: Get column width
113 double LwpVirtualLayout::GetColWidth(sal_uInt16 nIndex)
115 //return GetContentWidth(); //not support now
116 //return LwpTools::ConvertToMetric(5); //test
117 return 0; //test
121 * @descr: Get the gap between columns
124 double LwpVirtualLayout::GetColGap(sal_uInt16 nIndex)
126 //return DEFAULTGAPSIZE;
127 //return LwpTools::ConvertToMetric(0.17);//DEFAULTGAPSIZE=0.17
128 return LwpTools::ConvertToMetric(0.17);
132 * @descr: Whether it is honoring protection
135 sal_Bool LwpVirtualLayout::HonorProtection()
137 if(!(m_nAttributes2 & STYLE2_HONORPROTECTION))
138 return sal_False;
140 LwpVirtualLayout* pParent = static_cast<LwpVirtualLayout*> (GetParent()->obj());
141 if(pParent && !pParent->IsHeader())
143 return pParent->HonorProtection();
146 if(m_pFoundry)//is null now
148 LwpDocument* pDoc = m_pFoundry->GetDocument();
149 /*if(pDoc)
151 return pDoc->HonorProtection();
153 if(pDoc && pDoc->GetRootDocument())
154 return pDoc->GetRootDocument()->HonorProtection();
157 return sal_True;
161 * @descr: Whether it is protected
164 sal_Bool LwpVirtualLayout::IsProtected()
166 sal_Bool bProtected = (m_nAttributes & STYLE_PROTECTED)!=0;
168 LwpVirtualLayout* pParent = static_cast<LwpVirtualLayout*> (GetParent()->obj());
169 if(pParent && !pParent->IsHeader())
171 if(pParent->HonorProtection()&&(pParent->HasProtection()||bProtected))
173 return sal_True;
176 else if(m_pFoundry)//is null now
178 LwpDocument* pDoc = m_pFoundry->GetDocument();
179 if(pDoc)
181 if (pDoc->HonorProtection() && bProtected)
183 return sal_True;
188 return sal_False;
192 * @descr: Whether it has protection
195 sal_Bool LwpVirtualLayout::HasProtection()
197 if(m_nAttributes & STYLE_PROTECTED)
198 return sal_True;
200 LwpVirtualLayout* pParent = static_cast<LwpVirtualLayout*> (GetParent()->obj());
201 if(pParent && !pParent->IsHeader())
203 return pParent->HasProtection();
206 return sal_False;
210 * @descr: Whether it is a mirror layout
213 sal_Bool LwpVirtualLayout::IsComplex()
215 return m_nAttributes & STYLE_COMPLEX ? sal_True : sal_False;
219 * @descr: Get usewhen pointer
222 LwpUseWhen* LwpVirtualLayout::GetUseWhen()
225 If we have a parent, and I'm not a page layout,
226 use my parents information.
228 if(GetLayoutType()!=LWP_PAGE_LAYOUT)
230 //get parent
231 LwpVirtualLayout* pParent = static_cast<LwpVirtualLayout*> (GetParent()->obj());
232 if(pParent && !pParent->IsHeader()&& (pParent->GetLayoutType()!=LWP_PAGE_LAYOUT))
233 return pParent->GetUseWhen();
237 return VirtualGetUseWhen();
240 * @descr: Whether this layout is page layout or not
241 * @param:
242 * @return:
244 sal_Bool LwpVirtualLayout::IsPage()
246 return (GetLayoutType() == LWP_PAGE_LAYOUT);
249 * @descr: Whether this layout is heaer layout or not
250 * @param:
251 * @return:
253 sal_Bool LwpVirtualLayout::IsHeader()
255 return (GetLayoutType() == LWP_HEADER_LAYOUT);
258 * @descr: Whether this layout is footer layout or not
259 * @param:
260 * @return:
262 sal_Bool LwpVirtualLayout::IsFooter()
264 return (GetLayoutType() == LWP_FOOTER_LAYOUT);
267 * @descr: Whether this layout is frame layout or not
268 * @param:
269 * @return:
271 sal_Bool LwpVirtualLayout::IsFrame()
273 return (GetLayoutType() == LWP_FRAME_LAYOUT);
277 * @descr: Whether this layout is cell layout or not
278 * @param:
279 * @return:
281 sal_Bool LwpVirtualLayout::IsCell()
283 return (GetLayoutType() == LWP_CELL_LAYOUT
284 || GetLayoutType() == LWP_CONNECTED_CELL_LAYOUT
285 || GetLayoutType() == LWP_HIDDEN_CELL_LAYOUT);
288 * @descr: Whether this layout is supertable layout or not
289 * @param:
290 * @return:
292 sal_Bool LwpVirtualLayout::IsSuperTable()
294 return (GetLayoutType() == LWP_SUPERTABLE_LAYOUT);
297 * @descr: Whether this layout is group layout or not
298 * @param:
299 * @return:
301 sal_Bool LwpVirtualLayout::IsGroupHead()
303 return (GetLayoutType() == LWP_GROUP_LAYOUT);
306 * @descr: get the relative type
307 * @param:
308 * @return:
310 sal_uInt8 LwpVirtualLayout::GetRelativeType()
312 return LwpLayoutRelativityGuts::LAY_PARENT_RELATIVE;
315 * @descr: whether it is relative anchored layout
316 * @param:
317 * @return:
319 sal_Bool LwpVirtualLayout::IsRelativeAnchored()
321 sal_uInt8 nType;
323 nType = GetRelativeType();
324 return (nType == LwpLayoutRelativityGuts::LAY_PARA_RELATIVE) || (nType == LwpLayoutRelativityGuts::LAY_INLINE)
325 || (nType == LwpLayoutRelativityGuts::LAY_INLINE_NEWLINE) || (nType == LwpLayoutRelativityGuts::LAY_INLINE_VERTICAL);
328 * @descr: whether it is MinimumHeight layout
329 * @param:
330 * @return:
332 sal_Bool LwpVirtualLayout::IsMinimumHeight()
334 return ((m_nAttributes3& STYLE3_MINHEIGHTVALID) != 0);
338 * @descr: Get parent layout
341 LwpVirtualLayout* LwpVirtualLayout::GetParentLayout()
343 return static_cast<LwpVirtualLayout*> (GetParent()->obj());
347 * @descr: Register child layout style
350 void LwpVirtualLayout::RegisterChildStyle()
352 //Register all children styles
353 LwpVirtualLayout* pLayout = static_cast<LwpVirtualLayout*>(GetChildHead()->obj());
354 while(pLayout)
356 pLayout->SetFoundry(m_pFoundry);
357 pLayout->RegisterStyle();
358 pLayout = static_cast<LwpVirtualLayout*>(pLayout->GetNext()->obj());
362 sal_Bool LwpVirtualLayout::NoContentReference()
364 return (m_nAttributes2 & STYLE2_NOCONTENTREFERENCE) != 0;
367 sal_Bool LwpVirtualLayout::IsStyleLayout()
369 if (m_nAttributes3 & STYLE3_STYLELAYOUT)
370 return sal_True;
372 LwpVirtualLayout* pParent =static_cast<LwpVirtualLayout*>(GetParent()->obj());
373 if (pParent)
374 return pParent->IsStyleLayout();
375 return sal_False;
379 * @descr: Find child layout by layout type
382 LwpVirtualLayout* LwpVirtualLayout::FindChildByType(LWP_LAYOUT_TYPE eType)
384 LwpObjectID *pID = GetChildHead();
386 while(pID && !pID->IsNull())
388 LwpVirtualLayout * pLayout = static_cast<LwpVirtualLayout *>(pID->obj());
389 if(!pLayout)
391 break;
394 if (pLayout && pLayout->GetLayoutType() == eType)
396 return pLayout;
398 pID = pLayout->GetNext();
401 return NULL;
405 * @descr: Whether the size of layout is fit the graphic
408 sal_Bool LwpVirtualLayout::IsFitGraphic()
410 return IsAutoGrowRight() && !IsAutoGrowLeft() && IsAutoGrowDown();
414 * @descr: Whether the width of layout is auto grow
417 sal_Bool LwpVirtualLayout::IsAutoGrowWidth()
419 return IsAutoGrowLeft() || IsAutoGrowRight();
423 * @descr: Determine whether the layout width is to margin
426 sal_Bool LwpVirtualLayout::IsInlineToMargin()
428 return (m_nAttributes3 & STYLE3_INLINETOMARGIN) != 0;
431 void LwpAssociatedLayouts::Read(LwpObjectStream* pStrm)
433 m_OnlyLayout.ReadIndexed(pStrm);
434 m_Layouts.Read(pStrm);
435 pStrm->SkipExtra();
439 * @descr: Looking for the layout which follows the pStartLayout
440 * @param: pStartLayout - the layout which is used for looking for its following layout
442 LwpVirtualLayout* LwpAssociatedLayouts::GetLayout(LwpVirtualLayout *pStartLayout)
444 LwpVirtualLayout* pLayout = NULL;
446 if (!pStartLayout && !m_OnlyLayout.IsNull())
447 /* Looking for the first layout and there's only one layout in the list.*/
448 return static_cast<LwpVirtualLayout*>(m_OnlyLayout.obj());
450 LwpObjectHolder* pObjHolder =static_cast<LwpObjectHolder*>(m_Layouts.GetHead()->obj());
451 if(pObjHolder)
453 pLayout = static_cast<LwpVirtualLayout*>(pObjHolder->GetObject()->obj());
454 if(!pStartLayout )
455 return pLayout;
457 while(pObjHolder && pStartLayout != pLayout)
459 pObjHolder = static_cast<LwpObjectHolder*>(pObjHolder->GetNext()->obj());
460 if(pObjHolder)
462 pLayout = static_cast<LwpVirtualLayout*>(pObjHolder->GetObject()->obj());
466 if(pObjHolder)
468 pObjHolder = static_cast<LwpObjectHolder*>(pObjHolder->GetNext()->obj());
469 if(pObjHolder)
471 pLayout = static_cast<LwpVirtualLayout*>(pObjHolder->GetObject()->obj());
472 return pLayout;
476 //return pLayout;
479 return NULL;
482 LwpHeadLayout::LwpHeadLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
483 : LwpVirtualLayout(objHdr, pStrm)
486 void LwpHeadLayout::Read()
488 LwpVirtualLayout::Read();
489 //For PermissiveLayout
490 m_pObjStrm->SkipExtra();
491 //For me
492 m_pObjStrm->SkipExtra();
495 void LwpHeadLayout::RegisterStyle()
497 //Register all children styles
498 LwpVirtualLayout* pLayout = static_cast<LwpVirtualLayout*>(GetChildHead()->obj());
499 while(pLayout)
501 pLayout->SetFoundry(m_pFoundry);
502 //if the layout is relative to para, the layout will be registered in para
503 if(!pLayout->IsRelativeAnchored())
505 pLayout->RegisterStyle();
507 pLayout = static_cast<LwpVirtualLayout*>(pLayout->GetNext()->obj());
512 * @descr find endnote supertable layout from the child layout list. Suppose that there is only one endnote supertablelayout in one division
513 * @return pointer to endnote supertable layout
515 LwpVirtualLayout* LwpHeadLayout::FindEnSuperTableLayout()
517 LwpVirtualLayout* pLayout = static_cast<LwpVirtualLayout*>(GetChildHead()->obj());
518 while(pLayout)
520 if(pLayout->GetLayoutType() == LWP_ENDNOTE_SUPERTABLE_LAYOUT)
522 return pLayout;
524 pLayout = static_cast<LwpVirtualLayout*>(pLayout->GetNext()->obj());
526 return NULL;
529 LwpLayoutStyle::LwpLayoutStyle() :
530 m_nStyleDefinition(0), m_nKey(0),
531 m_pDescription(new LwpAtomHolder)
535 LwpLayoutStyle::~LwpLayoutStyle()
537 if (m_pDescription)
539 delete m_pDescription;
543 void LwpLayoutStyle::Read(LwpObjectStream* pStrm)
545 pStrm->QuickRead(&m_nStyleDefinition, sizeof(m_nStyleDefinition));
546 m_pDescription->Read(pStrm);
547 if (pStrm->CheckExtra())
549 pStrm->QuickRead(&m_nKey, 2);
550 pStrm->SkipExtra();
554 LwpLayoutMisc::LwpLayoutMisc() :
555 m_nGridDistance(0), m_nGridType(0),
556 m_pContentStyle(new LwpAtomHolder)
560 LwpLayoutMisc::~LwpLayoutMisc()
562 if (m_pContentStyle)
564 delete m_pContentStyle;
568 void LwpLayoutMisc::Read(LwpObjectStream* pStrm)
570 pStrm->QuickRead(&m_nGridType, 2);
571 pStrm->QuickRead(&m_nGridDistance, 4);
572 m_pContentStyle->Read(pStrm);
573 pStrm->SkipExtra();
576 LwpMiddleLayout::LwpMiddleLayout( LwpObjectHeader &objHdr, LwpSvStream* pStrm )
577 : LwpVirtualLayout(objHdr, pStrm),
578 m_pStyleStuff(new LwpLayoutStyle), m_pMiscStuff(new LwpLayoutMisc)
581 LwpMiddleLayout::~LwpMiddleLayout()
583 if (m_pStyleStuff)
585 delete m_pStyleStuff;
587 if (m_pMiscStuff)
589 delete m_pMiscStuff;
592 void LwpMiddleLayout::Read()
594 LwpObjectStream* pStrm = m_pObjStrm;
596 LwpVirtualLayout::Read();
598 //skip CLiteLayout data;
599 LwpAtomHolder ContentClass;
600 ContentClass.Read(pStrm);
601 pStrm->SkipExtra();
603 // before layout hierarchy rework
604 if(LwpFileHeader::m_nFileRevision < 0x000B)
605 return;
607 m_Content.ReadIndexed(pStrm);
609 // 01/20/2005
610 m_BasedOnStyle.ReadIndexed(pStrm);
611 m_TabPiece.ReadIndexed(pStrm);
613 sal_uInt8 nWhatsItGot = 0;
614 pStrm->QuickRead(&nWhatsItGot, 1);
616 if (nWhatsItGot & DISK_GOT_STYLE_STUFF)
618 m_pStyleStuff->Read(pStrm);
620 if (nWhatsItGot & DISK_GOT_MISC_STUFF)
622 m_pMiscStuff->Read(pStrm);
625 m_LayGeometry.ReadIndexed(pStrm);
626 m_LayScale.ReadIndexed(pStrm);
627 m_LayMargins.ReadIndexed(pStrm);
628 m_LayBorderStuff.ReadIndexed(pStrm);
629 m_LayBackgroundStuff.ReadIndexed(pStrm);
631 if (pStrm->CheckExtra())
633 m_LayExtBorderStuff.ReadIndexed(pStrm);
634 pStrm->SkipExtra();
636 //end
639 #include "lwplaypiece.hxx"
642 * @descr: Get the geometry of current layout
645 LwpLayoutGeometry* LwpMiddleLayout::GetGeometry()
647 if( !m_LayGeometry.IsNull() )
649 return ( static_cast<LwpLayoutGeometry*> (m_LayGeometry.obj()) );
651 else if( !m_BasedOnStyle.IsNull() )
653 LwpMiddleLayout* pLay = static_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj() );
654 return pLay->GetGeometry();
656 return NULL;
660 * @descr: Get layout height, measured by "cm"
663 double LwpMiddleLayout::GetGeometryHeight()
665 LwpLayoutGeometry* pGeo = GetGeometry();
666 if(pGeo)
668 return ( LwpTools::ConvertFromUnitsToMetric( pGeo->GetHeight() ) );
670 else
671 return -1;
675 * @descr: Get layout width, measured by "cm"
678 double LwpMiddleLayout::GetGeometryWidth()
680 LwpLayoutGeometry* pGeo = GetGeometry();
681 if(pGeo)
683 return ( LwpTools::ConvertFromUnitsToMetric( pGeo->GetWidth() ) );
685 else
686 return -1;
690 * @descr: Whether the margins is same as parent layout
693 BOOL LwpMiddleLayout::MarginsSameAsParent()
695 if(m_nOverrideFlag & OVER_MARGINS)
697 return LwpVirtualLayout::MarginsSameAsParent();
699 if(!m_BasedOnStyle.IsNull())
701 LwpVirtualLayout* play = static_cast<LwpVirtualLayout*> (m_BasedOnStyle.obj());
702 play->MarginsSameAsParent();
704 return LwpVirtualLayout::MarginsSameAsParent();
709 * @descr: Get margin
710 * @param: nWhichSide - 0: left, 1: right, 2:top, 3: bottom
712 double LwpMiddleLayout::GetMarginsValue(const sal_uInt8 &nWhichSide)
714 double fValue = 0;
715 if((nWhichSide==MARGIN_LEFT)||(nWhichSide==MARGIN_RIGHT))
717 if ( MarginsSameAsParent() )
719 LwpVirtualLayout* pParent = static_cast<LwpVirtualLayout*> (GetParent()->obj());
720 if(pParent && !pParent->IsHeader())
722 fValue = pParent->GetMarginsValue(nWhichSide);
723 return fValue;
728 if(m_nOverrideFlag & OVER_MARGINS)
730 LwpLayoutMargins* pMar1 = static_cast<LwpLayoutMargins*> (m_LayMargins.obj());
731 if(pMar1)
733 fValue = pMar1->GetMargins()->GetMarginsValue(nWhichSide);
734 return fValue;
737 LwpVirtualLayout* pStyle = static_cast<LwpVirtualLayout*> (m_BasedOnStyle.obj());
738 if(pStyle)
740 fValue = pStyle->GetMarginsValue(nWhichSide);
741 return fValue;
743 return LwpVirtualLayout::GetMarginsValue(nWhichSide);
746 * @descr: Get extmargin value
747 * @param: nWhichSide - 0: left, 1: right, 2:top, 3: bottom
748 * @param:
749 * @return:
751 double LwpMiddleLayout::GetExtMarginsValue(const sal_uInt8 &nWhichSide)
753 double fValue = 0;
754 if(m_nOverrideFlag & OVER_MARGINS)
756 LwpLayoutMargins* pMar1 = static_cast<LwpLayoutMargins*> (m_LayMargins.obj());
757 if(pMar1)
759 fValue = pMar1->GetExtMargins()->GetMarginsValue(nWhichSide);
760 return fValue;
763 LwpVirtualLayout* pStyle = static_cast<LwpVirtualLayout*> (m_BasedOnStyle.obj());
764 if(pStyle)
766 fValue = pStyle->GetExtMarginsValue(nWhichSide);
767 return fValue;
769 return LwpVirtualLayout::GetExtMarginsValue(nWhichSide);
772 * @descr: Get the LwpBorderStuff object according to m_LayBorderStuff id.
773 * @param:
774 * @param:
775 * @return:
777 LwpBorderStuff* LwpMiddleLayout::GetBorderStuff()
779 if(m_nOverrideFlag & OVER_BORDERS)
781 LwpLayoutBorder* pLayoutBorder = static_cast<LwpLayoutBorder*>(m_LayBorderStuff.obj());
782 return pLayoutBorder->GetBorderStuff();
784 else if( !m_BasedOnStyle.IsNull() )
786 LwpMiddleLayout* pLay = static_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj() );
787 return pLay->GetBorderStuff();
789 return NULL;
793 * @descr: Get LwpBackgroundStuff object according to m_LayBackgroundStuff id;
794 * @param:
795 * @param:
796 * @return:
798 LwpBackgroundStuff* LwpMiddleLayout::GetBackgroundStuff()
800 if(m_nOverrideFlag & OVER_BACKGROUND)
802 LwpLayoutBackground* pLayoutBackground = static_cast<LwpLayoutBackground*>(m_LayBackgroundStuff.obj());
803 return pLayoutBackground->GetBackgoudStuff();
805 else if( !m_BasedOnStyle.IsNull() )
807 LwpMiddleLayout* pLay = static_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj() );
808 return pLay->GetBackgroundStuff();
810 return NULL;
813 * @descr: create xfborder.
814 * @param:
815 * @param:
816 * @return:
818 XFBorders* LwpMiddleLayout::GetXFBorders()
820 LwpBorderStuff* pBorderStuff = GetBorderStuff();
821 if(pBorderStuff&&pBorderStuff->GetSide() != 0)
823 //copy from lwpparastyle.
824 XFBorders *pXFBorders = new XFBorders();
825 // apply 4 borders respectively
826 LwpBorderStuff::BorderType pType[] = { LwpBorderStuff::LEFT, LwpBorderStuff::RIGHT,
827 LwpBorderStuff::TOP, LwpBorderStuff::BOTTOM };
829 for (sal_uInt8 nC = 0; nC < 4; nC++)
831 if (pBorderStuff->HasSide(pType[nC]))
833 LwpParaStyle::ApplySubBorder(pBorderStuff, pType[nC], pXFBorders);
836 return pXFBorders;
838 return NULL;
842 * @descr: Get text direction settings.
843 * @param:
844 * @param:
845 * @return:
847 enumXFTextDir LwpMiddleLayout::GetTextDirection()
849 enumXFTextDir eTextDir = enumXFTextDirNone;
850 sal_uInt8 nDirection = GetContentOrientation();
851 switch(nDirection)
853 case TEXT_ORIENT_LRTB:
855 eTextDir = enumXFTextDirLR_TB;
856 break;
858 case TEXT_ORIENT_TBRL:
860 eTextDir = enumXFTextDirTB_RL;
861 break;
863 case TEXT_ORIENT_RLBT: // not supported now
865 eTextDir = enumXFTextDirNone;
866 break;
868 case TEXT_ORIENT_BTLR: // not supported now
870 eTextDir = enumXFTextDirNone;
871 break;
873 default:
874 break;
876 return eTextDir;
879 * @descr: Get back ground color.
880 * @param:
881 * @param:
882 * @return:
884 LwpColor* LwpMiddleLayout::GetBackColor()
886 LwpBackgroundStuff* pBackgroundStuff = GetBackgroundStuff();
887 if(pBackgroundStuff && !pBackgroundStuff->IsTransparent())
889 LwpColor* pColor = pBackgroundStuff->GetFillColor();
890 if(pColor->IsValidColor())
892 return pColor;
895 return NULL;
899 * @descr: Add back color settings into xfpagemaster.
900 * @param:
901 * @param:
902 * @return:
904 LwpTabOverride* LwpMiddleLayout::GetTabOverride()
906 if(m_nAttributes & OVER_TABS)
908 if(!m_TabPiece.IsNull())
909 return (LwpTabOverride*)static_cast<LwpTabPiece*>(m_TabPiece.obj())->GetOverride();
910 return NULL;
912 else if( !m_BasedOnStyle.IsNull() )
914 LwpMiddleLayout* pLay = static_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj() );
915 return pLay->GetTabOverride();
917 return NULL;
921 * @descr: Layscale for graphic & watermark
922 * @param:
923 * @param:
924 * @return:
926 sal_uInt16 LwpMiddleLayout::GetScaleMode(void)
928 if ((m_nOverrideFlag & OVER_SCALING) && m_LayScale.obj())
929 return GetLayoutScale()->GetScaleMode();
930 else if (m_BasedOnStyle.obj())
931 return static_cast<LwpMiddleLayout*>(m_BasedOnStyle.obj())->GetScaleMode();
932 else
933 return (LwpLayoutScale::FIT_IN_FRAME | LwpLayoutScale::MAINTAIN_ASPECT_RATIO);
936 void LwpMiddleLayout::SetScaleMode(sal_uInt16 nVal)
938 m_nOverrideFlag |= OVER_SCALING;
939 // nVal |= LwpLayoutScale::MAINTAIN_ASPECT_RATIO;
940 GetLayoutScale()->SetScaleMode(nVal);
943 sal_uInt16 LwpMiddleLayout::GetScaleTile(void)
945 if ((m_nOverrideFlag & OVER_SCALING) && m_LayScale.obj())
946 return (GetLayoutScale()->GetPlacement() & LwpLayoutScale::TILED)
947 ? 1 : 0;
948 else if (m_BasedOnStyle.obj())
949 return static_cast<LwpMiddleLayout*>(m_BasedOnStyle.obj())->GetScaleTile();
950 else
951 return 0;
954 void LwpMiddleLayout::SetScaleTile(sal_uInt16 nVal)
956 m_nOverrideFlag |= OVER_SCALING;
957 if (nVal)
958 GetLayoutScale()->SetPlacement(GetLayoutScale()->GetPlacement() | LwpLayoutScale::TILED);
959 else
960 GetLayoutScale()->SetPlacement(GetLayoutScale()->GetPlacement() & ~LwpLayoutScale::TILED);
963 sal_uInt16 LwpMiddleLayout::GetScaleCenter(void)
965 if ((m_nOverrideFlag & OVER_SCALING) && m_LayScale.obj())
966 return (GetLayoutScale()->GetPlacement() & LwpLayoutScale::CENTERED)
967 ? 1 : 0;
968 else if (m_BasedOnStyle.obj())
969 return static_cast<LwpMiddleLayout*>(m_BasedOnStyle.obj())->GetScaleCenter();
970 else
971 return 0;
974 void LwpMiddleLayout::SetScaleCenter(sal_uInt16 nVal)
976 m_nOverrideFlag |= OVER_SCALING;
977 if (nVal)
978 GetLayoutScale()->SetPlacement(GetLayoutScale()->GetPlacement() | LwpLayoutScale::CENTERED);
979 else
980 GetLayoutScale()->SetPlacement(GetLayoutScale()->GetPlacement() & ~LwpLayoutScale::CENTERED);
983 sal_uInt32 LwpMiddleLayout::GetScalePercentage(void)
985 if ((m_nOverrideFlag & OVER_SCALING) && m_LayScale.obj())
986 return GetLayoutScale()->GetScalePercentage()/10;//m_nScalePercentage 1000 = 100%
987 else if (m_BasedOnStyle.obj())
988 return static_cast<LwpMiddleLayout*>(m_BasedOnStyle.obj())->GetScalePercentage();
989 else
990 return 100;
993 void LwpMiddleLayout::SetScalePercentage(sal_uInt32 nVal)
995 m_nOverrideFlag |= OVER_SCALING;
996 GetLayoutScale()->SetScalePercentage(nVal*10);
999 double LwpMiddleLayout::GetScaleWidth(void)
1001 if ((m_nOverrideFlag & OVER_SCALING) && m_LayScale.obj())
1002 return LwpTools::ConvertFromUnits(GetLayoutScale()->GetScaleWidth());
1003 else if (m_BasedOnStyle.obj())
1004 return static_cast<LwpMiddleLayout*>(m_BasedOnStyle.obj())->GetScaleWidth();
1005 else
1006 return 0;
1009 void LwpMiddleLayout::SetScaleWidth(double fVal)
1011 m_nOverrideFlag |= OVER_SCALING;
1012 GetLayoutScale()->SetScaleWidth(LwpTools::ConvertToUnits(fVal));
1015 double LwpMiddleLayout::GetScaleHeight(void)
1017 if ((m_nOverrideFlag & OVER_SCALING) && m_LayScale.obj())
1018 return LwpTools::ConvertFromUnits(GetLayoutScale()->GetScaleHeight());
1019 else if (m_BasedOnStyle.obj())
1020 return static_cast<LwpMiddleLayout*>(m_BasedOnStyle.obj())->GetScaleHeight();
1021 else
1022 return 0;
1024 sal_Bool LwpMiddleLayout::CanSizeRight(void)
1026 sal_uInt8 RelType = GetRelativeType();
1028 if (RelType == LwpLayoutRelativityGuts::LAY_INLINE || RelType == LwpLayoutRelativityGuts::LAY_PARA_RELATIVE
1029 || RelType == LwpLayoutRelativityGuts::LAY_INLINE_VERTICAL)
1031 return sal_False;
1033 return sal_True;
1035 sal_Int32 LwpMiddleLayout::GetMinimumWidth()
1037 if (((m_nAttributes3 & STYLE3_WIDTHVALID) != 0) && GetGeometry())
1039 return GetGeometry()->GetWidth();
1041 else if (m_nOverrideFlag & OVER_SIZE)
1043 return DetermineWidth();
1045 return 0;
1047 sal_Int32 LwpMiddleLayout::DetermineWidth()
1049 if (IsSizeRightToContent())
1051 assert(sal_False);
1053 else if (IsSizeRightToContainer())
1055 assert(sal_False);
1057 else
1059 m_nAttributes3 |= STYLE3_WIDTHVALID;
1060 return GetGeometry()->GetWidth();
1062 return 0;
1064 sal_Bool LwpMiddleLayout::IsSizeRightToContainer(void)
1066 if (!CanSizeRight())
1067 return sal_False;
1069 if (m_nOverrideFlag & OVER_SIZE)
1071 return (m_nDirection & ((LAY_USEDIRECTION|LAY_AUTOSIZE|LAY_TOCONTAINER)
1072 << SHIFT_RIGHT))
1073 == ((LAY_USEDIRECTION | LAY_TOCONTAINER | LAY_AUTOSIZE) << SHIFT_RIGHT);
1075 else if (m_BasedOnStyle.obj())
1077 LwpMiddleLayout * pLayout = static_cast<LwpMiddleLayout *>(m_BasedOnStyle.obj());
1078 return pLayout->IsSizeRightToContainer();
1080 else
1081 return sal_False;
1083 sal_Bool LwpMiddleLayout::IsSizeRightToContent(void)
1085 if (!CanSizeRight())
1086 return sal_False;
1088 if (m_nOverrideFlag & OVER_SIZE)
1090 return (m_nDirection & ((LAY_USEDIRECTION|LAY_AUTOSIZE|LAY_TOCONTAINER)
1091 << SHIFT_RIGHT))
1092 == ((LAY_USEDIRECTION | LAY_AUTOSIZE) << SHIFT_RIGHT);
1094 else if (m_BasedOnStyle.obj())
1096 LwpMiddleLayout * pLayout = static_cast<LwpMiddleLayout *>(m_BasedOnStyle.obj());
1097 return pLayout->IsSizeRightToContent();
1099 else
1100 return sal_False;
1104 * @descr: Get layout height
1107 double LwpMiddleLayout::GetHeight()
1109 return GetGeometryHeight();
1113 * @descr: Get layout height
1116 double LwpMiddleLayout::GetWidth()
1118 return GetGeometryWidth();
1121 * @descr: Get layout orgin point
1124 LwpPoint LwpMiddleLayout::GetOrigin()
1126 LwpLayoutGeometry* pGeo = GetGeometry();
1127 if(pGeo)
1129 sal_uInt8 nType = GetRelativeType();
1130 if(nType == LwpLayoutRelativityGuts::LAY_INLINE
1131 || nType == LwpLayoutRelativityGuts::LAY_INLINE_NEWLINE )
1133 return pGeo->GetAbsoluteOrigin();
1135 else
1136 return pGeo->GetOrigin();
1140 return LwpPoint();
1143 void LwpMiddleLayout::SetScaleHeight(double fVal)
1145 m_nOverrideFlag |= OVER_SCALING;
1146 GetLayoutScale()->SetScaleHeight(LwpTools::ConvertToUnits(fVal));
1150 * @descr: Whether the fill is pattern fill or not
1151 * @return: True if yes, false if not.
1153 sal_Bool LwpMiddleLayout::IsPatternFill()
1155 LwpBackgroundStuff* pBackgroundStuff = GetBackgroundStuff();
1156 if (pBackgroundStuff)
1158 return pBackgroundStuff->IsPatternFill();
1161 return sal_False;
1165 * @descr: Get the fill pattern style. Data are saved in a XFBGImage object
1166 * @return: the fill pattern style.
1168 XFBGImage* LwpMiddleLayout::GetFillPattern()
1170 LwpBackgroundStuff* pBackgroundStuff = GetBackgroundStuff();
1171 if (pBackgroundStuff)
1173 return pBackgroundStuff->GetFillPattern();
1176 return NULL;
1181 * @descr: Whether the height and width of layout is auto grow
1184 sal_Bool LwpMiddleLayout::IsAutoGrow()
1186 if(m_nOverrideFlag & OVER_SIZE)
1188 return m_nDirection &
1189 ((LAY_AUTOGROW << SHIFT_UP) | (LAY_AUTOGROW << SHIFT_DOWN) |
1190 (LAY_AUTOGROW << SHIFT_RIGHT) | (LAY_AUTOGROW << SHIFT_LEFT))
1191 ? sal_True : sal_False;
1193 else if( !m_BasedOnStyle.IsNull() )
1195 LwpMiddleLayout* pLay = static_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj() );
1196 return pLay->IsAutoGrow();
1198 return LwpVirtualLayout::IsAutoGrow();
1202 * @descr: Whether the height of layout is auto grow down
1205 sal_Bool LwpMiddleLayout::IsAutoGrowDown()
1207 if(m_nOverrideFlag & OVER_SIZE)
1209 return m_nDirection & (LAY_AUTOGROW << SHIFT_DOWN) ? sal_True : sal_False;
1211 else if( !m_BasedOnStyle.IsNull() )
1213 LwpMiddleLayout* pLay = static_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj() );
1214 return pLay->IsAutoGrowDown();
1216 return LwpVirtualLayout::IsAutoGrowDown();
1220 * @descr: Whether the height of layout is auto grow up
1223 sal_Bool LwpMiddleLayout::IsAutoGrowUp()
1225 if(m_nOverrideFlag & OVER_SIZE)
1227 return m_nDirection & (LAY_AUTOGROW << SHIFT_UP) ? sal_True : sal_False;
1229 else if( !m_BasedOnStyle.IsNull() )
1231 LwpMiddleLayout* pLay = static_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj() );
1232 return pLay->IsAutoGrowUp();
1234 return LwpVirtualLayout::IsAutoGrowUp();
1238 * @descr: Whether the height of layout is auto grow down
1241 sal_Bool LwpMiddleLayout::IsAutoGrowLeft()
1243 if(m_nOverrideFlag & OVER_SIZE)
1245 return m_nDirection & (LAY_AUTOGROW << SHIFT_LEFT) ? sal_True : sal_False;
1247 else if( !m_BasedOnStyle.IsNull() )
1249 LwpMiddleLayout* pLay = static_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj() );
1250 return pLay->IsAutoGrowLeft();
1252 return LwpVirtualLayout::IsAutoGrowLeft();
1256 * @descr: Whether the height of layout is auto grow down
1259 sal_Bool LwpMiddleLayout::IsAutoGrowRight()
1261 if(m_nOverrideFlag & OVER_SIZE)
1263 return m_nDirection & (LAY_AUTOGROW << SHIFT_RIGHT) ? sal_True : sal_False;
1265 else if( !m_BasedOnStyle.IsNull() )
1267 LwpMiddleLayout* pLay = static_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj() );
1268 return pLay->IsAutoGrowRight();
1270 return LwpVirtualLayout::IsAutoGrowRight();
1275 * @descr: Get contents orientation
1278 sal_uInt8 LwpMiddleLayout::GetContentOrientation()
1280 //content orientation in Graphic objects and OLE objects not supported now
1281 if((m_nOverrideFlag & OVER_ROTATION)&& !m_LayGeometry.IsNull())
1283 LwpLayoutGeometry* pLayGeometry = static_cast<LwpLayoutGeometry*> (m_LayGeometry.obj());
1284 return pLayGeometry->GetContentOrientation();
1286 else if( !m_BasedOnStyle.IsNull() )
1288 LwpMiddleLayout* pLay = static_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj() );
1289 return pLay->GetContentOrientation();
1291 return LwpVirtualLayout::GetContentOrientation();
1295 * @descr: Whether it is honoring protection
1298 sal_Bool LwpMiddleLayout::HonorProtection()
1300 if(m_nOverrideFlag & OVER_MISC)
1302 if(!(m_nAttributes2 & STYLE2_HONORPROTECTION))
1303 return sal_False;
1305 LwpVirtualLayout* pParent = static_cast<LwpVirtualLayout*> (GetParent()->obj());
1306 if(pParent && !pParent->IsHeader())
1308 return pParent->HonorProtection();
1311 if(m_pFoundry)//is null now
1313 LwpDocument* pDoc = m_pFoundry->GetDocument();
1314 if(pDoc)
1316 return pDoc->HonorProtection();
1320 else if( !m_BasedOnStyle.IsNull() )
1322 LwpMiddleLayout* pLay = static_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj() );
1323 return pLay->HonorProtection();
1326 return LwpVirtualLayout::HonorProtection();
1330 * @descr: Whether it is pretected
1333 sal_Bool LwpMiddleLayout::IsProtected()
1335 sal_Bool bProtected = sal_False;
1336 if(m_nOverrideFlag & OVER_MISC)
1338 bProtected = (m_nAttributes & STYLE_PROTECTED)!=0;
1340 else if( !m_BasedOnStyle.IsNull() )
1342 LwpMiddleLayout* pLay = static_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj() );
1343 bProtected = pLay->IsProtected();
1345 else
1346 bProtected = LwpVirtualLayout::IsProtected();
1348 LwpVirtualLayout* pParent = static_cast<LwpVirtualLayout*> (GetParent()->obj());
1349 if(pParent && !pParent->IsHeader())
1351 /* If a parent's protected then none of its children can be accessed. */
1352 if(pParent->IsProtected())
1353 return sal_True;
1355 if(pParent->HonorProtection())
1356 return bProtected;
1358 /* If our parent isn't honoring protection then we aren't protected. */
1359 return sal_False;
1362 if(m_pFoundry)//is null now
1364 LwpDocument* pDoc = m_pFoundry->GetDocument();
1365 if(pDoc)
1367 if (pDoc->HonorProtection())
1368 return bProtected;
1370 /* If the document isn't honoring protection then we aren't protected.*/
1371 return sal_False;
1375 return bProtected;
1379 * @descr: Get watermark layout
1382 LwpVirtualLayout* LwpMiddleLayout::GetWaterMarkLayout()
1384 LwpVirtualLayout* pLay = static_cast<LwpVirtualLayout*>(GetChildHead()->obj());
1385 while(pLay)
1387 if( pLay->IsForWaterMark())
1389 return pLay;
1391 pLay = static_cast<LwpVirtualLayout*> (pLay->GetNext()->obj());
1393 return NULL;
1397 * @descr: Create and reture xfbgimage object for watermark
1400 XFBGImage* LwpMiddleLayout::GetXFBGImage()
1402 LwpMiddleLayout* pLay = static_cast<LwpMiddleLayout*>(GetWaterMarkLayout());
1403 if(pLay)
1405 //test BGImage
1406 LwpGraphicObject* pGrfObj = static_cast<LwpGraphicObject*>(pLay->GetContent()->obj());
1407 if(pGrfObj)
1409 XFBGImage* pXFBGImage = new XFBGImage();
1411 if(pGrfObj->IsLinked())
1413 //set file link
1414 OUString linkedfilepath = pGrfObj->GetLinkedFilePath();
1415 OUString fileURL = LwpTools::convertToFileUrl(OUStringToOString(linkedfilepath, osl_getThreadTextEncoding()));
1416 pXFBGImage->SetFileLink(fileURL);
1418 else
1420 sal_uInt8* pGrafData = NULL;
1421 sal_uInt32 nDataLen = pGrfObj->GetRawGrafData(pGrafData);
1422 pXFBGImage->SetImageData(pGrafData, nDataLen);
1423 if(pGrafData)
1425 delete pGrafData;
1426 pGrafData = NULL;
1431 //automatic, top left
1432 pXFBGImage->SetPosition(enumXFAlignStart,enumXFAlignTop);
1433 if(pLay->GetScaleCenter())
1435 //center
1436 pXFBGImage->SetPosition(enumXFAlignCenter,enumXFAlignCenter);
1438 else if(pLay->GetScaleTile())
1440 //tile
1441 pXFBGImage->SetRepeate();
1443 //fit type, area type
1444 if((pLay->GetScaleMode()& LwpLayoutScale::FIT_IN_FRAME)!=0)
1446 if((pLay->GetScaleMode()& LwpLayoutScale::MAINTAIN_ASPECT_RATIO)==0)
1448 pXFBGImage->SetStretch();
1451 return pXFBGImage;
1454 return NULL;
1458 * @descr: Whether the page uses the printer setting
1461 sal_Bool LwpMiddleLayout::GetUsePrinterSettings()
1463 if(m_nOverrideFlag & OVER_SIZE)
1465 return (m_nAttributes3 & STYLE3_USEPRINTERSETTINGS) != 0;
1467 else if( !m_BasedOnStyle.IsNull() )
1469 LwpMiddleLayout* pLay = static_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj() );
1470 return pLay->GetUsePrinterSettings();
1472 return sal_False;
1476 //Check whether there are contents in the layout
1477 sal_Bool LwpMiddleLayout::HasContent()
1479 LwpObject* content = m_Content.obj();
1480 if(content)
1481 return sal_True;
1482 return sal_False;
1484 //End by
1486 LwpLayout::LwpLayout( LwpObjectHeader &objHdr, LwpSvStream* pStrm ) :
1487 LwpMiddleLayout(objHdr, pStrm), m_pUseWhen(new LwpUseWhen)
1490 LwpLayout::~LwpLayout()
1492 if (m_pUseWhen)
1494 delete m_pUseWhen;
1498 void LwpLayout::Read()
1500 LwpObjectStream* pStrm = m_pObjStrm;
1502 LwpMiddleLayout::Read();
1503 if (LwpFileHeader::m_nFileRevision < 0x000B)
1505 // read PreRevBLayout...
1507 else
1509 sal_uInt16 nSimple;
1510 pStrm->QuickRead(&nSimple, 2);
1512 if (!nSimple)
1514 m_pUseWhen->Read(pStrm);
1516 sal_uInt8 nFlag;
1517 pStrm->QuickRead(&nFlag, 1);
1518 if (nFlag)
1520 m_Positon.ReadIndexed(pStrm);
1524 m_LayColumns.ReadIndexed(pStrm);
1525 m_LayGutterStuff.ReadIndexed(pStrm);
1526 m_LayJoinStuff.ReadIndexed(pStrm);
1527 m_LayShadow.ReadIndexed(pStrm);
1529 if (pStrm->CheckExtra())
1531 m_LayExtJoinStuff.ReadIndexed(pStrm);
1532 pStrm->SkipExtra();
1538 * @descr: Get columns number
1541 sal_uInt16 LwpLayout::GetNumCols()
1543 if(m_nOverrideFlag & OVER_COLUMNS)
1545 LwpLayoutColumns* pLayColumns = static_cast<LwpLayoutColumns*>(m_LayColumns.obj());
1546 if(pLayColumns)
1548 return pLayColumns->GetNumCols();
1552 LwpVirtualLayout* pStyle = static_cast<LwpVirtualLayout*> (m_BasedOnStyle.obj());
1553 if(pStyle)
1555 return pStyle->GetNumCols();
1558 return LwpVirtualLayout::GetNumCols();
1563 * @descr: Get column width
1564 * @param: the order of column
1566 double LwpLayout::GetColWidth(sal_uInt16 nIndex)
1568 if((m_nOverrideFlag & OVER_COLUMNS)||(m_nAttributes2 & STYLE2_LOCALCOLUMNINFO))
1570 LwpLayoutColumns* pLayColumns = static_cast<LwpLayoutColumns*>(m_LayColumns.obj());
1571 if(pLayColumns)
1573 return pLayColumns->GetColWidth(nIndex);
1577 LwpVirtualLayout* pStyle = static_cast<LwpVirtualLayout*> (m_BasedOnStyle.obj());
1578 if(pStyle)
1580 return pStyle->GetColWidth(nIndex);
1583 return LwpVirtualLayout::GetColWidth(nIndex);
1588 * @descr: Get gap between columns
1589 * @param: the order of column
1591 double LwpLayout::GetColGap(sal_uInt16 nIndex)
1593 if((m_nOverrideFlag & OVER_COLUMNS)||(m_nAttributes2 & STYLE2_LOCALCOLUMNINFO))
1595 LwpLayoutColumns* pLayColumns = static_cast<LwpLayoutColumns*>(m_LayColumns.obj());
1596 if(pLayColumns)
1598 return pLayColumns->GetColGap(nIndex);
1602 LwpVirtualLayout* pStyle = static_cast<LwpVirtualLayout*> (m_BasedOnStyle.obj());
1603 if(pStyle)
1605 return pStyle->GetColGap(nIndex);
1608 return LwpVirtualLayout::GetColGap(nIndex);
1612 * @descr: Create and return XFColumns object
1615 XFColumns* LwpLayout::GetXFColumns()
1617 //if there is only one column, do not need insert columns
1618 sal_uInt16 nCols = GetNumCols();
1619 if(nCols==1)
1621 return NULL;
1624 XFColumns* pColumns = new XFColumns();
1625 //set XFColumnSep
1626 XFColumnSep* pColumnSep = GetColumnSep();
1627 if(pColumnSep)
1629 pColumns->SetSeperator(*pColumnSep);
1632 //set column count and column gap
1633 pColumns->SetCount(nCols);
1634 double fGap = GetColGap(0);
1635 pColumns->SetGap(fGap);
1637 //set xfcolumn
1638 for(sal_uInt16 nIndex = 0; nIndex<nCols; nIndex++)
1640 XFColumn* pColumn = new XFColumn();
1641 sal_Int32 nWidth = static_cast<sal_Int32>(GetColWidth(nIndex));
1642 nWidth=8305/nCols; //relative width
1643 pColumn->SetRelWidth(nWidth);
1645 //the left and right margins is 0;
1646 double nGap = GetColGap(nIndex)/2;
1647 //nGap=0;
1648 pColumn->SetMargins(nGap,nGap);
1649 if(nIndex==0)
1651 pColumn->SetMargins(0,nGap);
1653 if(nIndex==(nCols-1))
1655 pColumn->SetMargins(nGap,0);
1657 pColumns->AddColumn(*pColumn);
1660 return pColumns;
1664 * @descr: Create and return XFColumnSep object
1667 XFColumnSep* LwpLayout::GetColumnSep()
1670 //Get LwpLayoutGutters
1671 LwpLayoutGutters* pLayoutGutters = static_cast<LwpLayoutGutters*>(m_LayGutterStuff.obj());
1672 if(!pLayoutGutters)
1674 return NULL;
1677 LwpBorderStuff* pBorderStuff = pLayoutGutters->GetBorderStuff();
1679 if(pBorderStuff)
1681 LwpBorderStuff::BorderType eType = LwpBorderStuff::LEFT;
1682 LwpColor aColor = pBorderStuff->GetSideColor(eType);
1683 double fWidth = pBorderStuff->GetSideWidth(eType);
1684 //sal_uInt16 nType = pBorderStuff->GetSideType(eType);
1686 XFColumnSep* pColumnSep = new XFColumnSep();
1687 XFColor aXFColor(aColor.To24Color());
1688 pColumnSep->SetColor(aXFColor);
1689 pColumnSep->SetWidth(fWidth);
1690 pColumnSep->SetRelHeight(100);
1691 pColumnSep->SetVerticalAlign(enumXFAlignTop);
1693 return pColumnSep;
1695 return NULL;
1700 * @descr: Get use when type
1703 LwpLayout::UseWhenType LwpLayout::GetUseWhenType()
1705 UseWhenType eType = StartWithinPage;
1706 LwpUseWhen* pUseWhen = GetUseWhen();
1707 if(pUseWhen)
1709 if(pUseWhen->IsStartOnThisHF())
1711 eType = StartWithinColume;
1713 else if(pUseWhen->IsStartOnThisPage())
1715 eType = StartWithinPage;
1717 else if(pUseWhen->IsStartOnNextPage())
1719 eType = StartOnNextPage;
1721 else if(pUseWhen->IsStartOnNextOddPage())
1723 eType = StartOnOddPage;
1725 else if(pUseWhen->IsStartOnNextEvenPage())
1727 eType = StartOnEvenPage;
1731 else
1733 eType = StartOnNextPage;
1735 return eType;
1739 * @descr: Get use page
1742 sal_uInt16 LwpLayout::GetUsePage()
1744 if(m_nOverrideFlag & OVER_PLACEMENT)
1746 LwpUseWhen* pUseWhen = GetUseWhen();
1747 if(pUseWhen)
1748 return pUseWhen->GetUsePage();
1749 else
1750 return NULL;
1752 else if( !m_BasedOnStyle.IsNull() )
1754 LwpLayout* pLay = static_cast<LwpLayout*> ( m_BasedOnStyle.obj() );
1755 return pLay->GetUsePage();
1757 return 0;
1761 * @descr: Get usewhen pointer
1764 LwpUseWhen* LwpLayout::VirtualGetUseWhen()
1766 if(m_nOverrideFlag & OVER_PLACEMENT)
1768 return m_pUseWhen;
1770 else if( !m_BasedOnStyle.IsNull() )
1772 LwpLayout* pLay = static_cast<LwpLayout*> ( m_BasedOnStyle.obj() );
1773 return pLay->VirtualGetUseWhen();
1775 return LwpVirtualLayout::VirtualGetUseWhen();
1779 * @descr: Whether it is use on all pages
1782 sal_Bool LwpLayout::IsUseOnAllPages()
1784 if(m_nOverrideFlag & OVER_PLACEMENT)
1786 LwpUseWhen* pUseWhen = GetUseWhen();
1787 if(pUseWhen)
1788 return pUseWhen->IsUseOnAllPages();
1789 else
1790 return NULL;
1792 else if( !m_BasedOnStyle.IsNull() )
1794 LwpLayout* pLay = static_cast<LwpLayout*> ( m_BasedOnStyle.obj() );
1795 return pLay->IsUseOnAllPages();
1797 return LwpVirtualLayout::IsUseOnAllPages();
1801 * @descr: Whether it is use on all even pages
1804 sal_Bool LwpLayout::IsUseOnAllEvenPages()
1806 if(m_nOverrideFlag & OVER_PLACEMENT)
1808 LwpUseWhen* pUseWhen = GetUseWhen();
1809 if(pUseWhen)
1810 return pUseWhen->IsUseOnAllEvenPages();
1811 else
1812 return NULL;
1814 else if( !m_BasedOnStyle.IsNull() )
1816 LwpLayout* pLay = static_cast<LwpLayout*> ( m_BasedOnStyle.obj() );
1817 return pLay->IsUseOnAllEvenPages();
1819 return LwpVirtualLayout::IsUseOnAllEvenPages();
1823 * @descr: Whether it is use on all odd pages
1826 sal_Bool LwpLayout::IsUseOnAllOddPages()
1828 if(m_nOverrideFlag & OVER_PLACEMENT)
1830 LwpUseWhen* pUseWhen = GetUseWhen();
1831 if(pUseWhen)
1832 return pUseWhen->IsUseOnAllOddPages();
1833 else
1834 return NULL;
1836 else if( !m_BasedOnStyle.IsNull() )
1838 LwpLayout* pLay = static_cast<LwpLayout*> ( m_BasedOnStyle.obj() );
1839 return pLay->IsUseOnAllOddPages();
1841 return LwpVirtualLayout::IsUseOnAllOddPages();
1845 * @descr: Whether it is use on current page
1848 sal_Bool LwpLayout::IsUseOnPage()
1850 if(m_nOverrideFlag & OVER_PLACEMENT)
1852 LwpUseWhen* pUseWhen = GetUseWhen();
1853 if(pUseWhen)
1854 return pUseWhen->IsUseOnPage();
1855 else
1856 return NULL;
1858 else if( !m_BasedOnStyle.IsNull() )
1860 LwpLayout* pLay = static_cast<LwpLayout*> ( m_BasedOnStyle.obj() );
1861 return pLay->IsUseOnPage();
1863 return LwpVirtualLayout::IsUseOnPage();
1867 * @descr: Get the LwpShadow object according to m_LayShadow id.
1868 * @param:
1869 * @param:
1870 * @return:
1872 LwpShadow* LwpLayout::GetShadow()
1874 if(m_nOverrideFlag & OVER_SHADOW)
1876 LwpLayoutShadow* pLayoutShadow = static_cast<LwpLayoutShadow*>(m_LayShadow.obj());
1877 return pLayoutShadow->GetShadow();
1879 else if( !m_BasedOnStyle.IsNull() )
1881 LwpLayout* pLay = static_cast<LwpLayout*> ( m_BasedOnStyle.obj() );
1882 return pLay->GetShadow();
1884 return NULL;
1888 * @descr: create xfshadow
1889 * @param:
1890 * @param:
1891 * @return:
1893 XFShadow* LwpLayout::GetXFShadow()
1895 LwpShadow* pShadow = GetShadow();
1896 if( pShadow )
1898 LwpColor color = pShadow->GetColor();
1899 double offsetX = pShadow->GetOffsetX();
1900 double offsetY = pShadow->GetOffsetY();
1902 if( offsetX && offsetY && color.IsValidColor() )
1904 XFShadow* pXFShadow = new XFShadow();
1905 enumXFShadowPos eXFShadowPos = enumXFShadowLeftTop;
1906 double fOffset = 0;
1908 sal_Bool left = sal_False;
1909 sal_Bool top = sal_False;
1910 if( offsetX < 0 )
1911 left = sal_True;
1912 if( offsetY < 0 )
1913 top = sal_True;
1914 if( left )
1916 fOffset = -offsetX;
1917 if( top )
1918 eXFShadowPos = enumXFShadowLeftTop;
1919 else
1920 eXFShadowPos = enumXFShadowLeftBottom;
1922 else
1924 fOffset = offsetX;
1925 if( top )
1926 eXFShadowPos = enumXFShadowRightTop;
1927 else
1928 eXFShadowPos = enumXFShadowRightBottom;
1931 pXFShadow->SetPosition(eXFShadowPos);
1932 pXFShadow->SetOffset(fOffset);
1933 pXFShadow->SetColor(XFColor(color.To24Color()));
1935 return pXFShadow;
1938 return NULL;
1942 * @descr get the layout that containers the current frame layout
1945 LwpVirtualLayout* LwpLayout::GetContainerLayout()
1947 if(IsRelativeAnchored())
1949 //get position
1950 LwpPara* pPara = static_cast<LwpPara*>(GetPosition()->obj());
1951 if(pPara)
1953 LwpStory* pStory = pPara->GetStory();
1954 return pStory->GetTabLayout();
1957 return GetParentLayout();
1960 LwpPlacableLayout::LwpPlacableLayout( LwpObjectHeader &objHdr, LwpSvStream* pStrm )
1961 : LwpLayout(objHdr, pStrm),m_pFont(NULL)
1964 LwpPlacableLayout::~LwpPlacableLayout()
1967 void LwpPlacableLayout::Read()
1969 LwpObjectStream* pStrm = m_pObjStrm;
1970 LwpLayout::Read();
1971 if(LwpFileHeader::m_nFileRevision < 0x000B)
1973 assert(false);
1975 else
1977 sal_uInt16 simple;
1978 pStrm->QuickRead(&simple, sizeof(simple));
1979 if(!simple)
1981 pStrm->QuickRead(&m_nWrapType, sizeof(m_nWrapType));
1982 pStrm->QuickRead(&m_nBuoyancy, sizeof(m_nBuoyancy));
1983 pStrm->QuickRead(&m_nBaseLineOffset, sizeof(m_nBaseLineOffset));
1984 m_Script.Read( pStrm);
1986 else
1988 m_nWrapType = LAY_WRAP_AROUND;
1989 m_nBuoyancy = LAY_BUOYNEUTRAL;
1990 m_nBaseLineOffset = 0;
1992 m_LayRelativity.ReadIndexed( pStrm);
1993 if(pStrm->CheckExtra())
1995 sal_uInt16 count;
1996 pStrm->QuickRead(&count, sizeof(count));
1997 if(count)
1999 // temporily added by to avoid assertion
2000 while (count)
2002 LwpPoint aPoint;
2003 aPoint.Read(pStrm);
2004 count--;
2006 // end added by
2008 pStrm->SkipExtra();
2013 * @descr: get wrap type
2014 * @param:
2015 * @param:
2016 * @return:
2018 sal_uInt8 LwpPlacableLayout::GetWrapType()
2020 if(m_nOverrideFlag & OVER_PLACEMENT)
2022 return m_nWrapType;
2024 else if( !m_BasedOnStyle.IsNull() )
2026 LwpPlacableLayout* pLay = static_cast<LwpPlacableLayout*> ( m_BasedOnStyle.obj() );
2027 return pLay->GetWrapType();
2029 return LAY_WRAP_AROUND;
2032 * @descr: get LayoutRelativity
2033 * @param:
2034 * @param:
2035 * @return:
2037 LwpLayoutRelativity* LwpPlacableLayout::GetRelativityPiece()
2039 if(!m_LayRelativity.IsNull())
2041 if(m_nOverrideFlag & OVER_PLACEMENT)
2043 return static_cast<LwpLayoutRelativity*>(m_LayRelativity.obj());
2046 else if( !m_BasedOnStyle.IsNull() )
2048 LwpPlacableLayout* pLay = static_cast<LwpPlacableLayout*> ( m_BasedOnStyle.obj() );
2049 return pLay->GetRelativityPiece();
2051 return NULL;
2054 * @descr: Get relative type
2057 sal_uInt8 LwpPlacableLayout::GetRelativeType()
2059 LwpLayoutRelativity* pLayRel = GetRelativityPiece();
2060 if(pLayRel)
2062 return pLayRel->GetRelGuts()->GetRelativeType();
2064 return LwpVirtualLayout::GetRelativeType();
2067 * @descr: Get relative from where type
2070 sal_uInt8 LwpPlacableLayout::GetRelativeFromWhere()
2072 LwpLayoutRelativity* pLayRel = GetRelativityPiece();
2073 if(pLayRel)
2075 return pLayRel->GetRelGuts()->GetRelativeFromWhere();
2077 return 0;
2080 * @descr: Get relative distance
2083 LwpPoint LwpPlacableLayout::GetRelativeDistance()
2085 LwpPoint aPoint;
2086 LwpLayoutRelativity* pLayRel = GetRelativityPiece();
2087 if(pLayRel)
2089 aPoint = pLayRel->GetRelGuts()->GetRelativeDistance();
2091 return aPoint;
2094 * @descr: Get tether type
2097 sal_uInt8 LwpPlacableLayout::GetTetherType()
2099 LwpLayoutRelativity* pLayRel = GetRelativityPiece();
2100 if(pLayRel)
2102 return pLayRel->GetRelGuts()->GetTetherType();
2104 return 0;
2107 * @descr: Get tether where type
2110 sal_uInt8 LwpPlacableLayout::GetTetherWhere()
2112 LwpLayoutRelativity* pLayRel = GetRelativityPiece();
2113 if(pLayRel)
2115 return pLayRel->GetRelGuts()->GetTetherWhere();
2117 return 0;
2120 * @descr: Get offset from the baseline
2123 sal_Int32 LwpPlacableLayout::GetBaseLineOffset()
2125 /* The baseline is only valid if this is flow-with-text */
2126 if(GetRelativeType()!=LwpLayoutRelativityGuts::LAY_INLINE)
2128 return 0;
2131 // First, ask our content if it has a baseline, ignore now
2133 if (Content && Content->GetBaseLineOffset(&Baseline))
2134 return Baseline;
2137 if(m_nOverrideFlag & OVER_PLACEMENT)
2139 return m_nBaseLineOffset;
2141 else if( !m_BasedOnStyle.IsNull() )
2143 LwpPlacableLayout* pLay = static_cast<LwpPlacableLayout*> ( m_BasedOnStyle.obj() );
2144 return pLay->GetBaseLineOffset();
2146 return 0;
2151 * @descr: whether the parent layout is page layout
2154 sal_Bool LwpPlacableLayout::IsAnchorPage()
2156 if(IsRelativeAnchored())
2157 return sal_False;
2159 LwpVirtualLayout* pLayout = GetParentLayout();
2160 if(pLayout && (pLayout->IsPage() || pLayout->IsHeader() || pLayout->IsFooter()))
2161 //if(pLayout && pLayout->IsPage())
2163 return sal_True;
2165 return sal_False;
2168 * @descr: whether the parent layout is frame layout
2171 sal_Bool LwpPlacableLayout::IsAnchorFrame()
2173 if(IsRelativeAnchored())
2174 return sal_False;
2176 LwpVirtualLayout* pLayout = GetParentLayout();
2177 if(pLayout && (pLayout->IsFrame()||pLayout->IsGroupHead()))
2179 return sal_True;
2181 return sal_False;
2184 * @descr: whether the parent layout is cell layout
2187 sal_Bool LwpPlacableLayout::IsAnchorCell()
2189 if(IsRelativeAnchored())
2190 return sal_False;
2192 LwpVirtualLayout* pLayout = GetParentLayout();
2193 if(pLayout && pLayout->IsCell())
2195 return sal_True;
2197 return sal_False;
2201 * @descr: Get font style for setting position of frame
2204 XFFont* LwpPlacableLayout::GetFont()
2206 return m_pFont;
2209 * @descr: Set font style for setting position of frame
2212 void LwpPlacableLayout::SetFont(XFFont * pFont)
2214 m_pFont = pFont;