Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / lotuswordpro / source / filter / lwppagelayout.cxx
blob3a0fd641a92fef24ad560a509804bc4f65cef983
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 ************************************************************************/
57 #include "lwppagelayout.hxx"
58 #include "lwplaypiece.hxx"
59 #include "lwpfootnote.hxx"
60 #include "lwpdoc.hxx"
61 #include "lwpholder.hxx"
62 #include "lwppagehint.hxx"
63 #include "lwpdivinfo.hxx"
64 #include "lwpstory.hxx"
65 #include "xfilter/xfstylemanager.hxx"
66 #include "xfilter/xfmasterpage.hxx"
67 #include "xfilter/xfcontentcontainer.hxx"
68 #include "xfilter/xfheader.hxx"
69 #include "xfilter/xfheaderstyle.hxx"
70 #include "xfilter/xffooterstyle.hxx"
71 #include "xfilter/xffooter.hxx"
72 #include <sfx2/printer.hxx>
73 #include "lwpchangemgr.hxx"
74 #include "lwpglobalmgr.hxx"
76 LwpPageLayout::LwpPageLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
77 : LwpLayout(objHdr, pStrm)
78 , m_pPrinterBinName(new LwpAtomHolder)
79 , m_nPrinterBin(0)
80 , m_nBdroffset(0)
81 , m_pPaperName(new LwpAtomHolder)
82 , m_pXFPageMaster(nullptr)
86 LwpPageLayout::~LwpPageLayout()
88 if (m_pPrinterBinName)
90 delete m_pPrinterBinName;
92 if (m_pPaperName)
94 delete m_pPaperName;
97 void LwpPageLayout::Read()
99 LwpLayout::Read();
101 if (LwpFileHeader::m_nFileRevision < 0x000B)
103 // read PreRevBLayout...
106 m_nPrinterBin = m_pObjStrm->QuickReaduInt16();
107 m_pPrinterBinName->Read(m_pObjStrm);
109 if (LwpFileHeader::m_nFileRevision >= 0x000B)
110 m_nBdroffset = m_pObjStrm->QuickReadInt32();
112 if (m_pObjStrm->CheckExtra())
114 m_pPaperName->Read(m_pObjStrm);
115 m_pObjStrm->SkipExtra();
120 void LwpPageLayout::Parse(IXFStream* pOutputStream)
122 //Only parse this layout
123 rtl::Reference<LwpObject> pStory = m_Content.obj();
124 if(pStory.is())
126 pStory->SetFoundry(m_pFoundry);
127 pStory->DoParse(pOutputStream); //Do not parse the next story
132 * @descr: set page margins
135 void LwpPageLayout::ParseMargins(XFPageMaster* pm1)
137 double fLeft = GetMarginsValue(MARGIN_LEFT);
138 double fRight = GetMarginsValue(MARGIN_RIGHT);
139 double fTop = GetMarginsValue(MARGIN_TOP);
140 double fBottom = GetMarginsValue(MARGIN_BOTTOM);
142 pm1->SetMargins( fLeft, fRight, fTop, fBottom );
147 * @descr: set page height and width
150 void LwpPageLayout::ParseGeometry(XFPageMaster* pm1)
153 LwpLayoutGeometry* pLayoutGeo = GetGeometry();
154 if(pLayoutGeo)
156 pm1->SetPageHeight( GetGeometryHeight() );
157 pm1->SetPageWidth( GetGeometryWidth() );
160 double fWidth =0;
161 double fHeight = 0;
162 GetWidthAndHeight(fWidth, fHeight);
163 pm1->SetPageWidth( fWidth );
164 pm1->SetPageHeight( fHeight );
168 * @descr: set page watermark
171 void LwpPageLayout::ParseWaterMark(XFPageMaster *pm1)
173 XFBGImage* pXFBGImage = GetXFBGImage();
174 if(pXFBGImage)
176 pm1->SetBackImage(pXFBGImage);
181 * @descr: set page columns
184 void LwpPageLayout::ParseColumns(XFPageMaster * pm1)
186 XFColumns* pColumns = GetXFColumns();
187 if(pColumns)
189 pm1->SetColumns(pColumns);
194 * @descr: set page borders
197 void LwpPageLayout::ParseBorders(XFPageMaster *pm1)
199 XFBorders* pBordres = GetXFBorders();
200 if(pBordres)
202 pm1->SetBorders(pBordres);
207 * @descr: set page shadow
210 void LwpPageLayout::ParseShadow(XFPageMaster *pm1)
212 XFShadow* pXFShadow = GetXFShadow();
213 if(pXFShadow)
215 pm1->SetShadow(pXFShadow);
220 * @descr: set page back pattern
223 void LwpPageLayout::ParsePatternFill(XFPageMaster* pm1)
225 XFBGImage* pXFBGImage = GetFillPattern();
226 if (pXFBGImage)
228 pm1->SetBackImage(pXFBGImage);
232 * @descr: set page background
235 void LwpPageLayout::ParseBackGround(XFPageMaster* pm1)
237 if (IsPatternFill())
239 ParsePatternFill(pm1);
241 else
243 ParseBackColor(pm1);
248 * @descr: set page back color
251 void LwpPageLayout::ParseBackColor(XFPageMaster* pm1)
253 LwpColor* pColor = GetBackColor();
254 if(pColor)
256 pm1->SetBackColor(XFColor(pColor->To24Color()));
261 * @descr: set page footnote separator information
264 void LwpPageLayout::ParseFootNoteSeparator(XFPageMaster * pm1)
266 //Get the footnoteoptions for the root document
267 LwpDocument* pDocument = m_pFoundry ? m_pFoundry->GetDocument() : nullptr;
268 if (pDocument)
270 LwpObjectID* pFontnodeId = pDocument->GetValidFootnoteOpts();
272 LwpFootnoteOptions* pFootnoteOpts = pFontnodeId ? dynamic_cast<LwpFootnoteOptions*>(pFontnodeId->obj().get()) : nullptr;
273 if(pFootnoteOpts)
275 LwpFootnoteSeparatorOptions& rFootnoteSep = pFootnoteOpts->GetFootnoteSeparator();
276 //set length
277 sal_uInt32 nLengthPercent = 100;
278 double fWidth = 0;
279 if(rFootnoteSep.HasSeparator())
281 fWidth = rFootnoteSep.GetTopBorderWidth();
283 if(rFootnoteSep.HasCustomLength())
285 nLengthPercent = static_cast<sal_uInt32>(100*LwpTools::ConvertFromUnitsToMetric(rFootnoteSep.GetLength())/GetMarginWidth());
286 if(nLengthPercent > 100)
287 nLengthPercent = 100;
289 double fAbove = LwpTools::ConvertFromUnitsToMetric(rFootnoteSep.GetAbove());
290 double fBelow = LwpTools::ConvertFromUnitsToMetric(rFootnoteSep.GetBelow());
291 LwpColor aColor = rFootnoteSep.GetTopBorderColor();
292 enumXFAlignType eAlignType = enumXFAlignStart;
293 if(rFootnoteSep.GetIndent() > 0)
295 //SODC don't support indent
296 sal_uInt32 nIndentPercent = static_cast<sal_uInt32>(100*LwpTools::ConvertFromUnitsToMetric(rFootnoteSep.GetIndent())/GetMarginWidth());
297 if(nIndentPercent + nLengthPercent >= 100)
298 eAlignType = enumXFAlignEnd;
300 if(aColor.IsValidColor())
302 XFColor aXFColor(aColor.To24Color());
303 pm1->SetFootNoteSeparator(eAlignType,fWidth, nLengthPercent, fAbove, fBelow, aXFColor);
310 * @descr: Register master page and page master style
313 void LwpPageLayout::RegisterStyle()
315 XFPageMaster* pm1 = new XFPageMaster();
316 m_pXFPageMaster = pm1;
318 ParseGeometry( pm1 );
319 //Does not process LayoutScale, for watermark is not supported in SODC.
320 ParseWaterMark( pm1);
321 ParseMargins( pm1);
322 ParseColumns(pm1);
323 ParseBorders(pm1);
324 ParseShadow(pm1);
325 // ParseBackColor(pm1);
326 ParseBackGround(pm1);
327 ParseFootNoteSeparator(pm1);
328 pm1->SetTextDir(GetTextDirection());
330 LwpUseWhen* pUseWhen = GetUseWhen();
331 if(IsComplex() ||( pUseWhen && pUseWhen->IsUseOnAllOddPages()))
333 pm1->SetPageUsage(enumXFPageUsageMirror);
336 //Add the page master to stylemanager
337 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
338 m_pXFPageMaster = pm1 = static_cast<XFPageMaster*>(pXFStyleManager->AddStyle(pm1).m_pStyle);
339 OUString pmname = pm1->GetStyleName();
341 //Add master page
342 XFMasterPage* p1 = new XFMasterPage();
343 p1->SetStyleName(GetName().str());
344 p1->SetPageMaster(pmname);
345 p1 = static_cast<XFMasterPage*>(pXFStyleManager->AddStyle(p1).m_pStyle);
346 m_StyleName = p1->GetStyleName();
348 //Set footer style
349 LwpFooterLayout* pLayoutFooter = GetFooterLayout();
350 if(pLayoutFooter)
352 pLayoutFooter->SetFoundry(m_pFoundry);
353 pLayoutFooter->RegisterStyle(pm1);
354 pLayoutFooter->RegisterStyle(p1);
357 //Set header style
358 LwpHeaderLayout* pLayoutHeader = GetHeaderLayout();
359 if(pLayoutHeader)
361 pLayoutHeader->SetFoundry(m_pFoundry);
362 pLayoutHeader->RegisterStyle(pm1);
363 pLayoutHeader->RegisterStyle(p1);
365 //register child layout style for mirror page and frame
366 RegisterChildStyle();
370 * @descr: Register master page for endnote which name is "endnote"
371 * @return: Return the master page name.
373 OUString LwpPageLayout::RegisterEndnoteStyle()
375 XFPageMaster* pm1 = new XFPageMaster();
376 m_pXFPageMaster = pm1;
378 ParseGeometry( pm1 );
379 ParseWaterMark( pm1);
380 ParseMargins( pm1);
381 ParseColumns(pm1);
382 ParseBorders(pm1);
383 ParseShadow(pm1);
384 // ParseBackColor(pm1);
385 ParseBackGround(pm1);
386 //ParseFootNoteSeparator(pm1);
387 pm1->SetTextDir(GetTextDirection());
389 LwpUseWhen* pUseWhen = GetUseWhen();
390 if(IsComplex() ||( pUseWhen && pUseWhen->IsUseOnAllOddPages()))
392 pm1->SetPageUsage(enumXFPageUsageMirror);
395 //Add the page master to stylemanager
396 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
397 m_pXFPageMaster = pm1 = static_cast<XFPageMaster*>(pXFStyleManager->AddStyle(pm1).m_pStyle);
398 OUString pmname = pm1->GetStyleName();
400 //Add master page
401 XFMasterPage* p1 = new XFMasterPage();
402 p1->SetStyleName("Endnote");
403 p1->SetPageMaster(pmname);
405 //Set footer style
406 LwpFooterLayout* pLayoutFooter = GetFooterLayout();
407 if(pLayoutFooter)
409 pLayoutFooter->SetFoundry(m_pFoundry);
410 pLayoutFooter->RegisterStyle(pm1);
411 pLayoutFooter->RegisterStyle(p1);
414 //Set header style
415 LwpHeaderLayout* pLayoutHeader = GetHeaderLayout();
416 if(pLayoutHeader)
418 pLayoutHeader->SetFoundry(m_pFoundry);
419 pLayoutHeader->RegisterStyle(pm1);
420 pLayoutHeader->RegisterStyle(p1);
423 return pXFStyleManager->AddStyle(p1).m_pStyle->GetStyleName();
426 * @descr: Whether current page layout has columns
429 bool LwpPageLayout::HasColumns()
431 return GetNumCols() > 1;
435 * @descr: Whether has filler page text in current page layout
438 bool LwpPageLayout::HasFillerPageText(LwpFoundry* pFoundry)
440 if(!pFoundry) return false;
442 bool bFillerPage = false;
443 LwpLayout::UseWhenType eWhenType = GetUseWhenType();
444 if(eWhenType==LwpLayout::StartOnOddPage||eWhenType==LwpLayout::StartOnEvenPage)
446 //get pagenumber
447 sal_uInt16 nPageNumber = 0;
449 //get the page number that current page layout inserted
450 nPageNumber = GetPageNumber(FIRST_LAYOUTPAGENO)-1;
452 if(nPageNumber>0)
454 if((eWhenType==LwpLayout::StartOnOddPage)&&(LwpTools::IsOddNumber(nPageNumber)))
456 bFillerPage = true;
458 else if((eWhenType==LwpLayout::StartOnEvenPage)&&(LwpTools::IsEvenNumber(nPageNumber)))
460 bFillerPage = true;
462 else
464 bFillerPage = false;
469 return bFillerPage;
473 * @descr: Parse filler page text
476 void LwpPageLayout::ConvertFillerPageText(XFContentContainer* pCont)
478 if(HasFillerPageText(m_pFoundry))
480 //get fillerpage story from division info
481 LwpDocument* pDoc = m_pFoundry->GetDocument();
482 LwpDivInfo* pDivInfo = dynamic_cast<LwpDivInfo*>(pDoc->GetDivInfoID().obj().get());
483 LwpStory* pStory = dynamic_cast<LwpStory*>(pDivInfo->GetFillerPageTextID().obj().get());
485 //parse fillerpage story
486 if(pStory)
488 pStory->XFConvert(pCont);
493 * @descr: Clear columns style in page layout
496 void LwpPageLayout::ResetXFColumns()
498 if(m_pXFPageMaster)
500 m_pXFPageMaster->SetColumns(nullptr);
504 LwpHeaderLayout* LwpPageLayout::GetHeaderLayout()
506 rtl::Reference<LwpVirtualLayout> xLay(dynamic_cast<LwpVirtualLayout*>(GetChildHead().obj().get()));
507 while (xLay.is())
509 if (xLay->GetLayoutType() == LWP_HEADER_LAYOUT)
510 return dynamic_cast<LwpHeaderLayout*>(xLay.get());
511 xLay.set(dynamic_cast<LwpVirtualLayout*>(xLay->GetNext().obj().get()));
513 return nullptr;
516 LwpFooterLayout* LwpPageLayout::GetFooterLayout()
518 rtl::Reference<LwpVirtualLayout> xLay(dynamic_cast<LwpVirtualLayout*>(GetChildHead().obj().get()));
519 while (xLay.is())
521 if (xLay->GetLayoutType() == LWP_FOOTER_LAYOUT)
522 return dynamic_cast<LwpFooterLayout*>(xLay.get());
523 xLay.set(dynamic_cast<LwpVirtualLayout*>(xLay->GetNext().obj().get()));
525 return nullptr;
529 * @descr: Get the odd layout if current page layout is mirror page
532 LwpPageLayout* LwpPageLayout::GetOddChildLayout()
534 if(IsComplex())
536 rtl::Reference<LwpVirtualLayout> xLay(dynamic_cast<LwpVirtualLayout*>(GetChildHead().obj().get()));
537 while (xLay.is())
539 if (xLay->GetLayoutType() == LWP_PAGE_LAYOUT)
541 LwpPageLayout* pPageLayout = static_cast<LwpPageLayout*>(xLay.get());
542 LwpUseWhen* pUseWhen = pPageLayout->GetUseWhen();
543 if(pUseWhen && pUseWhen->IsUseOnAllOddPages())
545 return pPageLayout;
548 xLay.set(dynamic_cast<LwpVirtualLayout*>(xLay->GetNext().obj().get()));
551 return nullptr;
555 * @descr: Get margin width of page
558 double LwpPageLayout::GetMarginWidth()
560 double fPagewidth = GetGeometryWidth();
561 double fLeftMargin = GetMarginsValue(MARGIN_LEFT);
562 double fRightMargin = GetMarginsValue(MARGIN_RIGHT);
564 return fPagewidth - (fLeftMargin + fRightMargin);
568 * @descr: Get the pagenumber
569 * @param: if nLayoutNumber =FIRST_LAYOUTPAGENO, return the first page number that current page layout covers
570 =LAST_LAYOUTPAGENO, return the last page number that current page layout covers
571 else, return the specified page number that current page layout covers
572 * @param:
573 * @return: if reture value >=0, success to find the page number, or fail.
575 sal_Int32 LwpPageLayout::GetPageNumber(sal_uInt16 nLayoutNumber)
577 sal_Int16 nPageNumber = -1;
578 LwpFoundry* pFoundry = GetFoundry();
579 if (!pFoundry)
580 return nPageNumber;
581 LwpDocument* pDoc = pFoundry->GetDocument();
582 LwpDLVListHeadTailHolder* pHeadTail = dynamic_cast<LwpDLVListHeadTailHolder*>(pDoc->GetPageHintsID().obj().get());
583 if(!pHeadTail) return nPageNumber;
585 //get first pagehint
586 LwpPageHint* pPageHint = dynamic_cast<LwpPageHint*>(pHeadTail->GetHead().obj().get());
587 while(pPageHint)
589 if(GetObjectID() == pPageHint->GetPageLayoutID())
591 sal_uInt16 nNumber = pPageHint->GetPageNumber();
592 if(nLayoutNumber==FIRST_LAYOUTPAGENO && pPageHint->GetLayoutPageNumber()==1)
594 //get the first page number
595 nPageNumber = nNumber;
596 break;
598 else if( nLayoutNumber ==LAST_LAYOUTPAGENO && nNumber >nPageNumber )
600 //get the last page number
601 nPageNumber = nNumber;
602 if(pPageHint->GetNext().IsNull())
604 //if is last page number of entire document, reture directly
605 return nPageNumber + pDoc->GetNumberOfPagesBefore();
608 else if(nLayoutNumber > 0 && pPageHint->GetLayoutPageNumber() == nLayoutNumber)
610 //get specified page number
611 nPageNumber = nNumber;
612 break;
616 pPageHint = dynamic_cast<LwpPageHint*>(pPageHint->GetNext().obj().get());
618 if(nPageNumber>=0)
620 return nPageNumber + 1 + pDoc->GetNumberOfPagesBefore();
622 return -1;
626 * @descr: Get page width and height
629 void LwpPageLayout::GetWidthAndHeight(double& fWidth, double& fHeight)
631 //use customized size
632 LwpLayoutGeometry* pLayoutGeo = GetGeometry();
633 if(pLayoutGeo)
635 fWidth = GetGeometryWidth();
636 fHeight = GetGeometryHeight();
639 if(GetUsePrinterSettings())
641 //replaced by printer paper size
642 ScopedVclPtrInstance< Printer > pPrinter;
643 bool bScreen = pPrinter->IsDisplayPrinter();
644 if (!bScreen)//Printer available
646 Size aPaperSize = pPrinter->GetPaperSize();
647 aPaperSize = pPrinter->PixelToLogic( aPaperSize, MapMode( MAP_10TH_MM ) );
648 fWidth = static_cast<double>(aPaperSize.Width())/100; //cm unit
649 fHeight = static_cast<double>(aPaperSize.Height())/100;
653 //Follow the former design of Lotus WordPro filter, some default will be given:
654 //Page Width: 8.5 Inch -> 21.59 cm
655 //Page Height: 11 Inch -> 27.94 cm
656 if (fWidth < 4.39)
657 fWidth = 21.59;
658 if (fHeight < 4.49)
659 fHeight = 27.94;
660 //End of modification, by ZF
664 * @descr: Get page width
667 double LwpPageLayout::GetWidth()
669 double fWidth =0, fHeight = 0;
670 GetWidthAndHeight(fWidth, fHeight);
671 return fWidth;
675 * @descr: Get page height
678 double LwpPageLayout::GetHeight()
680 double fWidth =0, fHeight = 0;
681 GetWidthAndHeight(fWidth, fHeight);
682 return fHeight;
685 * @descr: Compare the position of layout. If the position of this layout is earlier than other layout,return true, or return false
688 bool LwpPageLayout::operator<(LwpPageLayout& Other)
690 LwpPara* pThisPara = GetPagePosition();
691 LwpPara* pOtherPara = Other.GetPagePosition();
692 if(pThisPara && pOtherPara)
694 if(pThisPara == pOtherPara)
696 //If the two layouts in the same para, compare which layout is earlied according to frib order
697 return pThisPara->ComparePagePosition(this, &Other);
699 else
701 return *pThisPara < *pOtherPara;
705 if(!pThisPara)
706 return true;
708 return false;
712 * @descr: Get the position of pagelayout
715 LwpPara* LwpPageLayout::GetPagePosition()
717 LwpPara* pPara = dynamic_cast<LwpPara*>(GetPosition().obj().get());
718 if(pPara)
719 return pPara;
720 //Get the position from its related section
721 LwpFoundry* pFoundry = GetFoundry();
722 if(pFoundry)
724 LwpSection* pSection = nullptr;
725 while( (pSection = pFoundry->EnumSections(pSection)) )
727 if(pSection->GetPageLayout() == this)
728 return dynamic_cast<LwpPara*>(pSection->GetPosition().obj().get());
732 return nullptr;
734 LwpHeaderLayout::LwpHeaderLayout( LwpObjectHeader &objHdr, LwpSvStream* pStrm )
735 : LwpPlacableLayout(objHdr, pStrm)
736 , m_nBorderOffset(0)
740 LwpHeaderLayout::~LwpHeaderLayout()
744 void LwpHeaderLayout::Read()
746 LwpPlacableLayout::Read();
748 if(LwpFileHeader::m_nFileRevision >= 0x000E)
749 m_nBorderOffset = m_pObjStrm->QuickReadInt32();
750 else
751 m_nBorderOffset = 0;
752 m_pObjStrm->SkipExtra();
755 void LwpHeaderLayout::RegisterStyle(XFPageMaster* pm1)
757 XFHeaderStyle* pHeaderStyle = new XFHeaderStyle();
759 //Modify page top margin
760 //page top marging: from top of header to the top edge
761 double top = GetMarginsValue(MARGIN_TOP);
762 pm1->SetMargins(-1, -1, top, -1);
764 ParseMargins(pHeaderStyle);
765 ParseBorder(pHeaderStyle);
766 ParseShadow(pHeaderStyle);
767 // ParseBackColor(pHeaderStyle);
768 ParseBackGround(pHeaderStyle);
770 ParseWaterMark(pHeaderStyle);
771 //End by
773 pm1->SetHeaderStyle(pHeaderStyle);
776 void LwpHeaderLayout::ParseMargins(XFHeaderStyle* ph1)
778 //Set height: from top of header to top of body, including the spacing between header and body
779 double height = GetGeometryHeight()- GetMarginsValue(MARGIN_TOP);
780 if( IsAutoGrowDown() )
782 ph1->SetMinHeight(height);
784 else
786 ph1->SetHeight(height);
789 //Set left,right,bottom margins
790 LwpMiddleLayout* parent = dynamic_cast<LwpMiddleLayout*> (GetParent().obj().get());
791 //left margin in SODC: the space from the left edge of body to the left edge of header
792 double left = GetMarginsValue(MARGIN_LEFT) - (parent ? parent->GetMarginsValue(MARGIN_LEFT) : 0);
793 if(left<=0) //The left margin in SODC can not be minus value
795 left = -1;
797 //left margin in SODC: the space from the right edge of header to the right edge of body
798 double right = GetMarginsValue(MARGIN_RIGHT) - (parent ? parent->GetMarginsValue(MARGIN_RIGHT) : 0);
799 if(right<=0)//The right margin in SODC can not be minus value
801 right = -1;
803 ph1->SetMargins( left, right, GetMarginsValue(MARGIN_BOTTOM));
805 //Word Pro has no dynamic spacing, should be set to false
806 ph1->SetDynamicSpace(false);
809 void LwpHeaderLayout::ParseBorder(XFHeaderStyle* pHeaderStyle)
811 XFBorders* pBordres = GetXFBorders();
812 if(pBordres)
814 pHeaderStyle->SetBorders(pBordres);
818 void LwpHeaderLayout::ParseShadow(XFHeaderStyle* pHeaderStyle)
820 XFShadow* pXFShadow = GetXFShadow();
821 if(pXFShadow)
823 pHeaderStyle->SetShadow(pXFShadow);
828 * @descr: set header back pattern
831 void LwpHeaderLayout::ParsePatternFill(XFHeaderStyle* pHeaderStyle)
833 XFBGImage* pXFBGImage = GetFillPattern();
834 if (pXFBGImage)
836 pHeaderStyle->SetBackImage(pXFBGImage);
840 * @descr: set header background
843 void LwpHeaderLayout::ParseBackGround(XFHeaderStyle* pHeaderStyle)
845 if (IsPatternFill())
847 ParsePatternFill(pHeaderStyle);
849 else
851 ParseBackColor(pHeaderStyle);
855 void LwpHeaderLayout::ParseBackColor(XFHeaderStyle* pHeaderStyle)
857 LwpColor* pColor = GetBackColor();
858 if(pColor)
860 pHeaderStyle->SetBackColor(XFColor(pColor->To24Color()));
864 void LwpHeaderLayout::ParseWaterMark(XFHeaderStyle * pHeaderStyle)
866 XFBGImage* pXFBGImage = GetXFBGImage();
867 if(pXFBGImage)
869 pHeaderStyle->SetBackImage(pXFBGImage);
872 //End by
874 void LwpHeaderLayout::RegisterStyle(XFMasterPage* mp1)
876 XFHeader* pHeader = new XFHeader();
877 rtl::Reference<LwpObject> pStory = m_Content.obj();
878 if(pStory.is())
880 LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
881 LwpChangeMgr* pChangeMgr = pGlobal->GetLwpChangeMgr();
882 pChangeMgr->SetHeadFootFribMap(true);
884 //Call the RegisterStyle first to register the styles in header paras, and then XFConvert()
885 pStory->SetFoundry(m_pFoundry);
886 pStory->DoRegisterStyle();
887 //, 06/27/2005
888 //register child layout style for framelayout,
889 RegisterChildStyle();
890 //End
891 pChangeMgr->SetHeadFootChange(pHeader);
892 pStory->DoXFConvert(pHeader);
894 pChangeMgr->SetHeadFootFribMap(false);
896 mp1->SetHeader(pHeader);
899 LwpFooterLayout::LwpFooterLayout( LwpObjectHeader &objHdr, LwpSvStream* pStrm )
900 : LwpPlacableLayout( objHdr, pStrm )
901 , m_nBorderOffset(0)
905 LwpFooterLayout::~LwpFooterLayout()
909 void LwpFooterLayout::Read()
911 LwpPlacableLayout::Read();
913 if(LwpFileHeader::m_nFileRevision >= 0x000E)
914 m_nBorderOffset = m_pObjStrm->QuickReadInt32();
915 else
916 m_nBorderOffset = 0;
917 m_pObjStrm->SkipExtra();
920 void LwpFooterLayout::RegisterStyle(XFPageMaster* pm1)
922 XFFooterStyle* pFooterStyle = new XFFooterStyle();
924 //Modify page bottom margin
925 //page bottom margin: from bottom of footer to the bottom edge
926 double bottom = GetMarginsValue(MARGIN_BOTTOM);
927 pm1->SetMargins(-1, -1, -1, bottom);
929 ParseMargins(pFooterStyle);
930 ParseBorder(pFooterStyle);
931 ParseShadow(pFooterStyle);
932 ParseBackGround(pFooterStyle);
933 // ParseBackColor(pFooterStyle);
935 ParseWaterMark(pFooterStyle);
936 //End by
938 pm1->SetFooterStyle(pFooterStyle);
941 void LwpFooterLayout::ParseMargins(XFFooterStyle* pFooterStyle)
944 //Set height: from top of header to top of body, including the spacing between header and body
945 double height = GetGeometryHeight() - GetMarginsValue(MARGIN_BOTTOM);
946 if( IsAutoGrowUp() )
948 pFooterStyle->SetMinHeight(height);
950 else
952 pFooterStyle->SetHeight(height);
955 //Set left,right,top margins
956 LwpMiddleLayout* parent = dynamic_cast<LwpMiddleLayout*> (GetParent().obj().get());
957 double left = GetMarginsValue(MARGIN_LEFT) - (parent ? parent->GetMarginsValue(MARGIN_LEFT) : 0);
958 if(left<=0) //The left margin in SODC can not be minus value
960 left = -1;
962 double right = GetMarginsValue(MARGIN_RIGHT) - (parent ? parent->GetMarginsValue(MARGIN_RIGHT) : 0);
963 if(right<=0)//The left margin in SODC can not be minus value
965 right = -1;
967 pFooterStyle->SetMargins( left, right, GetMarginsValue(MARGIN_TOP));
969 //Word Pro has no dynamic spacing, should be set to false
970 pFooterStyle->SetDynamicSpace(false);
973 void LwpFooterLayout::ParseBorder(XFFooterStyle* pFooterStyle)
975 XFBorders* pBordres = GetXFBorders();
976 if(pBordres)
978 pFooterStyle->SetBorders(pBordres);
982 void LwpFooterLayout::ParseShadow(XFFooterStyle* pFooterStyle)
984 XFShadow* pXFShadow = GetXFShadow();
985 if(pXFShadow)
987 pFooterStyle->SetShadow(pXFShadow);
991 * @descr: set footer back pattern
994 void LwpFooterLayout::ParsePatternFill(XFFooterStyle* pFooterStyle)
996 XFBGImage* pXFBGImage = GetFillPattern();
997 if (pXFBGImage)
999 pFooterStyle->SetBackImage(pXFBGImage);
1003 * @descr: set footer background
1006 void LwpFooterLayout::ParseBackGround(XFFooterStyle* pFooterStyle)
1008 if (IsPatternFill())
1010 ParsePatternFill(pFooterStyle);
1012 else
1014 ParseBackColor(pFooterStyle);
1018 void LwpFooterLayout::ParseBackColor(XFFooterStyle* pFooterStyle)
1020 LwpColor* pColor = GetBackColor();
1021 if(pColor)
1023 pFooterStyle->SetBackColor(XFColor(pColor->To24Color()));
1027 void LwpFooterLayout::RegisterStyle(XFMasterPage* mp1)
1029 XFFooter* pFooter = new XFFooter();
1030 rtl::Reference<LwpObject> pStory = m_Content.obj(VO_STORY);
1031 //Call the RegisterStyle first to register the styles in footer paras, and then XFConvert()
1032 if(pStory.is())
1034 LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
1035 LwpChangeMgr* pChangeMgr = pGlobal->GetLwpChangeMgr();
1036 pChangeMgr->SetHeadFootFribMap(true);
1038 pStory->SetFoundry(m_pFoundry);
1039 pStory->DoRegisterStyle();
1040 //register child layout style for framelayout,
1041 RegisterChildStyle();
1043 pChangeMgr->SetHeadFootChange(pFooter);
1045 pStory->DoXFConvert(pFooter);
1047 pChangeMgr->SetHeadFootFribMap(false);
1049 mp1->SetFooter(pFooter);
1052 void LwpFooterLayout::ParseWaterMark(XFFooterStyle * pFooterStyle)
1054 XFBGImage* pXFBGImage = GetXFBGImage();
1055 if(pXFBGImage)
1057 pFooterStyle->SetBackImage(pXFBGImage);
1061 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */