tdf#163948: fix crash when NotesPane is enabled on Tabbed UI
[LibreOffice.git] / lotuswordpro / source / filter / lwppagelayout.cxx
blobae5d63ae42a85cf02ec895950e8e920e233322e5
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 <memory>
58 #include "lwppagelayout.hxx"
59 #include "lwplaypiece.hxx"
60 #include "lwpfootnote.hxx"
61 #include "lwpdoc.hxx"
62 #include "lwpholder.hxx"
63 #include "lwppagehint.hxx"
64 #include "lwpdivinfo.hxx"
65 #include "lwpstory.hxx"
66 #include <o3tl/numeric.hxx>
67 #include <xfilter/xfstylemanager.hxx>
68 #include <xfilter/xfmasterpage.hxx>
69 #include <xfilter/xfcontentcontainer.hxx>
70 #include <xfilter/xfheader.hxx>
71 #include <xfilter/xfheaderstyle.hxx>
72 #include <xfilter/xffooterstyle.hxx>
73 #include <xfilter/xffooter.hxx>
74 #include <lwpchangemgr.hxx>
75 #include <lwpfilehdr.hxx>
76 #include <lwpglobalmgr.hxx>
77 #include <o3tl/sorted_vector.hxx>
78 #include <sal/log.hxx>
79 #include <vcl/print.hxx>
81 LwpPageLayout::LwpPageLayout(LwpObjectHeader const& objHdr, LwpSvStream* pStrm)
82 : LwpLayout(objHdr, pStrm)
83 , m_nPrinterBin(0)
84 , m_nBdroffset(0)
85 , m_pXFPageMaster(nullptr)
89 LwpPageLayout::~LwpPageLayout() {}
90 void LwpPageLayout::Read()
92 LwpLayout::Read();
94 if (LwpFileHeader::m_nFileRevision < 0x000B)
96 // read PreRevBLayout...
99 m_nPrinterBin = m_pObjStrm->QuickReaduInt16();
100 m_PrinterBinName.Read(m_pObjStrm.get());
102 if (LwpFileHeader::m_nFileRevision >= 0x000B)
103 m_nBdroffset = m_pObjStrm->QuickReadInt32();
105 if (m_pObjStrm->CheckExtra())
107 m_PaperName.Read(m_pObjStrm.get());
108 m_pObjStrm->SkipExtra();
112 void LwpPageLayout::Parse(IXFStream* pOutputStream)
114 //Only parse this layout
115 rtl::Reference<LwpObject> pStory = m_Content.obj();
116 if (pStory.is())
118 pStory->SetFoundry(m_pFoundry);
119 pStory->DoParse(pOutputStream); //Do not parse the next story
124 * @descr: set page margins
127 void LwpPageLayout::ParseMargins(XFPageMaster* pm1)
129 double fLeft = GetMarginsValue(MARGIN_LEFT);
130 double fRight = GetMarginsValue(MARGIN_RIGHT);
131 double fTop = GetMarginsValue(MARGIN_TOP);
132 double fBottom = GetMarginsValue(MARGIN_BOTTOM);
134 pm1->SetMargins(fLeft, fRight, fTop, fBottom);
138 * @descr: set page height and width
141 void LwpPageLayout::ParseGeometry(XFPageMaster* pm1)
144 LwpLayoutGeometry* pLayoutGeo = GetGeometry();
145 if(pLayoutGeo)
147 pm1->SetPageHeight( GetGeometryHeight() );
148 pm1->SetPageWidth( GetGeometryWidth() );
151 double fWidth = 0;
152 double fHeight = 0;
153 GetWidthAndHeight(fWidth, fHeight);
154 pm1->SetPageWidth(fWidth);
155 pm1->SetPageHeight(fHeight);
159 * @descr: set page watermark
162 void LwpPageLayout::ParseWaterMark(XFPageMaster* pm1)
164 std::unique_ptr<XFBGImage> xXFBGImage(GetXFBGImage());
165 if (xXFBGImage)
167 pm1->SetBackImage(xXFBGImage);
172 * @descr: set page columns
175 void LwpPageLayout::ParseColumns(XFPageMaster* pm1)
177 XFColumns* pColumns = GetXFColumns();
178 if (pColumns)
180 pm1->SetColumns(pColumns);
185 * @descr: set page borders
188 void LwpPageLayout::ParseBorders(XFPageMaster* pm1)
190 std::unique_ptr<XFBorders> pBordres = GetXFBorders();
191 if (pBordres)
193 pm1->SetBorders(std::move(pBordres));
198 * @descr: set page shadow
201 void LwpPageLayout::ParseShadow(XFPageMaster* pm1)
203 XFShadow* pXFShadow = GetXFShadow();
204 if (pXFShadow)
206 pm1->SetShadow(pXFShadow);
211 * @descr: set page back pattern
214 void LwpPageLayout::ParsePatternFill(XFPageMaster* pm1)
216 std::unique_ptr<XFBGImage> xXFBGImage(GetFillPattern());
217 if (xXFBGImage)
219 pm1->SetBackImage(xXFBGImage);
223 * @descr: set page background
226 void LwpPageLayout::ParseBackGround(XFPageMaster* pm1)
228 if (IsPatternFill())
230 ParsePatternFill(pm1);
232 else
234 ParseBackColor(pm1);
239 * @descr: set page back color
242 void LwpPageLayout::ParseBackColor(XFPageMaster* pm1)
244 LwpColor* pColor = GetBackColor();
245 if (pColor)
247 pm1->SetBackColor(XFColor(pColor->To24Color()));
252 * @descr: set page footnote separator information
255 void LwpPageLayout::ParseFootNoteSeparator(XFPageMaster* pm1)
257 //Get the footnoteoptions for the root document
258 LwpDocument* pDocument = m_pFoundry ? m_pFoundry->GetDocument() : nullptr;
259 if (!pDocument)
260 return;
262 LwpObjectID* pFontnodeId = pDocument->GetValidFootnoteOpts();
264 LwpFootnoteOptions* pFootnoteOpts
265 = pFontnodeId ? dynamic_cast<LwpFootnoteOptions*>(pFontnodeId->obj().get()) : nullptr;
266 if (!pFootnoteOpts)
267 return;
269 LwpFootnoteSeparatorOptions& rFootnoteSep = pFootnoteOpts->GetFootnoteSeparator();
270 //set length
271 sal_uInt32 nLengthPercent = 100;
272 double fWidth = 0;
273 if (rFootnoteSep.HasSeparator())
275 fWidth = rFootnoteSep.GetTopBorderWidth();
277 if (rFootnoteSep.HasCustomLength())
279 const double fMarginWidth = GetMarginWidth();
280 if (fMarginWidth == 0.0)
281 throw o3tl::divide_by_zero();
283 nLengthPercent = static_cast<sal_uInt32>(
284 100 * LwpTools::ConvertFromUnits(rFootnoteSep.GetLength()) / fMarginWidth);
285 if (nLengthPercent > 100)
286 nLengthPercent = 100;
288 double fAbove = LwpTools::ConvertFromUnits(rFootnoteSep.GetAbove());
289 double fBelow = LwpTools::ConvertFromUnits(rFootnoteSep.GetBelow());
290 LwpColor aColor = rFootnoteSep.GetTopBorderColor();
291 enumXFAlignType eAlignType = enumXFAlignStart;
292 if (rFootnoteSep.GetIndent() > 0)
294 const double fMarginWidth = GetMarginWidth();
295 if (fMarginWidth == 0.0)
296 throw o3tl::divide_by_zero();
298 //SODC don't support indent
299 sal_uInt32 nIndentPercent = static_cast<sal_uInt32>(
300 100 * LwpTools::ConvertFromUnits(rFootnoteSep.GetIndent()) / fMarginWidth);
301 if (nIndentPercent + nLengthPercent >= 100)
302 eAlignType = enumXFAlignEnd;
304 if (aColor.IsValidColor())
306 XFColor aXFColor(aColor.To24Color());
307 pm1->SetFootNoteSeparator(eAlignType, fWidth, nLengthPercent, fAbove, fBelow, aXFColor);
312 * @descr: Register master page and page master style
315 void LwpPageLayout::RegisterStyle()
317 std::unique_ptr<XFPageMaster> xpm1(new XFPageMaster);
319 ParseGeometry(xpm1.get());
320 //Does not process LayoutScale, for watermark is not supported in SODC.
321 ParseWaterMark(xpm1.get());
322 ParseMargins(xpm1.get());
323 ParseColumns(xpm1.get());
324 ParseBorders(xpm1.get());
325 ParseShadow(xpm1.get());
326 ParseBackGround(xpm1.get());
327 ParseFootNoteSeparator(xpm1.get());
328 xpm1->SetTextDir(GetTextDirection());
330 LwpUseWhen* pUseWhen = GetUseWhen();
331 if (IsComplex() || (pUseWhen && pUseWhen->IsUseOnAllOddPages()))
333 xpm1->SetPageUsage(enumXFPageUsageMirror);
336 //Add the page master to stylemanager
337 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
338 XFPageMaster* pm1
339 = static_cast<XFPageMaster*>(pXFStyleManager->AddStyle(std::move(xpm1)).m_pStyle);
340 m_pXFPageMaster = pm1;
341 OUString pmname = pm1->GetStyleName();
343 //Add master page
344 std::unique_ptr<XFMasterPage> p1(new XFMasterPage);
345 p1->SetStyleName(GetName().str());
346 p1->SetPageMaster(pmname);
347 XFMasterPage* p1_added
348 = static_cast<XFMasterPage*>(pXFStyleManager->AddStyle(std::move(p1)).m_pStyle);
349 m_StyleName = p1_added->GetStyleName();
351 //Set footer style
352 LwpFooterLayout* pLayoutFooter = GetFooterLayout();
353 if (pLayoutFooter)
355 pLayoutFooter->SetFoundry(m_pFoundry);
356 pLayoutFooter->RegisterStyle(pm1);
357 pLayoutFooter->RegisterStyle(p1_added);
360 //Set header style
361 LwpHeaderLayout* pLayoutHeader = GetHeaderLayout();
362 if (pLayoutHeader)
364 pLayoutHeader->SetFoundry(m_pFoundry);
365 pLayoutHeader->RegisterStyle(pm1);
366 pLayoutHeader->RegisterStyle(p1_added);
368 //register child layout style for mirror page and frame
369 RegisterChildStyle();
373 * @descr: Register master page for endnote which name is "endnote"
374 * @return: Return the master page name.
376 OUString LwpPageLayout::RegisterEndnoteStyle()
378 std::unique_ptr<XFPageMaster> pm1(new XFPageMaster);
380 ParseGeometry(pm1.get());
381 ParseWaterMark(pm1.get());
382 ParseMargins(pm1.get());
383 ParseColumns(pm1.get());
384 ParseBorders(pm1.get());
385 ParseShadow(pm1.get());
386 ParseBackGround(pm1.get());
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
398 = static_cast<XFPageMaster*>(pXFStyleManager->AddStyle(std::move(pm1)).m_pStyle);
399 OUString pmname = m_pXFPageMaster->GetStyleName();
401 //Add master page
402 std::unique_ptr<XFMasterPage> p1(new XFMasterPage);
403 p1->SetStyleName(u"Endnote"_ustr);
404 p1->SetPageMaster(pmname);
406 //Set footer style
407 LwpFooterLayout* pLayoutFooter = GetFooterLayout();
408 if (pLayoutFooter)
410 pLayoutFooter->SetFoundry(m_pFoundry);
411 pLayoutFooter->RegisterStyle(m_pXFPageMaster);
412 pLayoutFooter->RegisterStyle(p1.get());
415 //Set header style
416 LwpHeaderLayout* pLayoutHeader = GetHeaderLayout();
417 if (pLayoutHeader)
419 pLayoutHeader->SetFoundry(m_pFoundry);
420 pLayoutHeader->RegisterStyle(m_pXFPageMaster);
421 pLayoutHeader->RegisterStyle(p1.get());
424 return pXFStyleManager->AddStyle(std::move(p1)).m_pStyle->GetStyleName();
427 * @descr: Whether current page layout has columns
430 bool LwpPageLayout::HasColumns() { return GetNumCols() > 1; }
433 * @descr: Whether has filler page text in current page layout
436 bool LwpPageLayout::HasFillerPageText(LwpFoundry const* pFoundry)
438 if (!pFoundry)
439 return false;
441 bool bFillerPage = false;
442 LwpLayout::UseWhenType eWhenType = GetUseWhenType();
443 if (eWhenType == LwpLayout::StartOnOddPage || eWhenType == LwpLayout::StartOnEvenPage)
445 //get the page number that current page layout inserted
446 sal_Int32 nPageNumber = GetPageNumber(FIRST_LAYOUTPAGENO) - 1;
448 if (nPageNumber > 0)
450 if ((eWhenType == LwpLayout::StartOnOddPage) && (LwpTools::IsOddNumber(nPageNumber)))
452 bFillerPage = true;
454 else if ((eWhenType == LwpLayout::StartOnEvenPage)
455 && (LwpTools::IsEvenNumber(nPageNumber)))
457 bFillerPage = true;
459 else
461 bFillerPage = false;
466 return bFillerPage;
470 * @descr: Parse filler page text
473 void LwpPageLayout::ConvertFillerPageText(XFContentContainer* pCont)
475 if (!HasFillerPageText(m_pFoundry))
476 return;
478 //get fillerpage story from division info
479 LwpDocument* pDoc = m_pFoundry->GetDocument();
480 LwpDivInfo* pDivInfo = dynamic_cast<LwpDivInfo*>(pDoc->GetDivInfoID().obj().get());
481 LwpStory* pStory
482 = pDivInfo ? dynamic_cast<LwpStory*>(pDivInfo->GetFillerPageTextID().obj().get()) : nullptr;
484 //parse fillerpage story
485 if (pStory)
487 pStory->XFConvert(pCont);
491 * @descr: Clear columns style in page layout
494 void LwpPageLayout::ResetXFColumns()
496 if (m_pXFPageMaster)
498 m_pXFPageMaster->SetColumns(nullptr);
502 LwpHeaderLayout* LwpPageLayout::GetHeaderLayout()
504 rtl::Reference<LwpVirtualLayout> xLay(
505 dynamic_cast<LwpVirtualLayout*>(GetChildHead().obj().get()));
506 while (xLay.is())
508 if (xLay->GetLayoutType() == LWP_HEADER_LAYOUT)
509 return dynamic_cast<LwpHeaderLayout*>(xLay.get());
510 rtl::Reference<LwpVirtualLayout> xNext(
511 dynamic_cast<LwpVirtualLayout*>(xLay->GetNext().obj().get()));
512 if (xNext == xLay)
514 SAL_WARN("lwp", "loop in layout");
515 break;
517 xLay = std::move(xNext);
519 return nullptr;
522 LwpFooterLayout* LwpPageLayout::GetFooterLayout()
524 rtl::Reference<LwpVirtualLayout> xLay(
525 dynamic_cast<LwpVirtualLayout*>(GetChildHead().obj().get()));
526 while (xLay.is())
528 if (xLay->GetLayoutType() == LWP_FOOTER_LAYOUT)
529 return dynamic_cast<LwpFooterLayout*>(xLay.get());
530 rtl::Reference<LwpVirtualLayout> xNext(
531 dynamic_cast<LwpVirtualLayout*>(xLay->GetNext().obj().get()));
532 if (xNext == xLay)
534 SAL_WARN("lwp", "loop in layout");
535 break;
537 xLay = std::move(xNext);
539 return nullptr;
543 * @descr: Get the odd layout if current page layout is mirror page
546 LwpPageLayout* LwpPageLayout::GetOddChildLayout()
548 if (!IsComplex())
549 return nullptr;
550 rtl::Reference<LwpVirtualLayout> xLay(
551 dynamic_cast<LwpVirtualLayout*>(GetChildHead().obj().get()));
552 o3tl::sorted_vector<LwpVirtualLayout*> aSeen;
553 while (xLay.is())
555 bool bAlreadySeen = !aSeen.insert(xLay.get()).second;
556 if (bAlreadySeen)
557 throw std::runtime_error("loop in conversion");
559 if (xLay->GetLayoutType() == LWP_PAGE_LAYOUT)
561 LwpPageLayout* pPageLayout = static_cast<LwpPageLayout*>(xLay.get());
562 LwpUseWhen* pUseWhen = pPageLayout->GetUseWhen();
563 if (pUseWhen && pUseWhen->IsUseOnAllOddPages())
565 return pPageLayout;
568 xLay.set(dynamic_cast<LwpVirtualLayout*>(xLay->GetNext().obj().get()));
570 return nullptr;
574 * @descr: Get margin width of page
577 double LwpPageLayout::GetMarginWidth()
579 double fPagewidth = GetGeometryWidth();
580 double fLeftMargin = GetMarginsValue(MARGIN_LEFT);
581 double fRightMargin = GetMarginsValue(MARGIN_RIGHT);
583 return fPagewidth - (fLeftMargin + fRightMargin);
587 * @descr: Get the pagenumber
588 * @param: if nLayoutNumber =FIRST_LAYOUTPAGENO, return the first page number that current page layout covers
589 =LAST_LAYOUTPAGENO, return the last page number that current page layout covers
590 else, return the specified page number that current page layout covers
591 * @param:
592 * @return: if return value >=0, success to find the page number, or fail.
594 sal_Int32 LwpPageLayout::GetPageNumber(sal_uInt16 nLayoutNumber)
596 sal_Int16 nPageNumber = -1;
597 LwpFoundry* pFoundry = GetFoundry();
598 if (!pFoundry)
599 return nPageNumber;
600 LwpDocument* pDoc = pFoundry->GetDocument();
601 LwpDLVListHeadTailHolder* pHeadTail
602 = dynamic_cast<LwpDLVListHeadTailHolder*>(pDoc->GetPageHintsID().obj().get());
603 if (!pHeadTail)
604 return nPageNumber;
606 //get first pagehint
607 LwpPageHint* pPageHint = dynamic_cast<LwpPageHint*>(pHeadTail->GetHead().obj().get());
608 o3tl::sorted_vector<LwpPageHint*> aSeen;
609 while (pPageHint)
611 bool bAlreadySeen = !aSeen.insert(pPageHint).second;
612 if (bAlreadySeen)
613 throw std::runtime_error("loop in conversion");
615 if (GetObjectID() == pPageHint->GetPageLayoutID())
617 sal_uInt16 nNumber = pPageHint->GetPageNumber();
618 if (nLayoutNumber == FIRST_LAYOUTPAGENO && pPageHint->GetLayoutPageNumber() == 1)
620 //get the first page number
621 nPageNumber = nNumber;
622 break;
624 else if (nLayoutNumber == LAST_LAYOUTPAGENO && nNumber > nPageNumber)
626 //get the last page number
627 nPageNumber = nNumber;
628 if (pPageHint->GetNext().IsNull())
630 //if is last page number of entire document, return directly
631 return nPageNumber + pDoc->GetNumberOfPagesBefore();
634 else if (nLayoutNumber > 0 && pPageHint->GetLayoutPageNumber() == nLayoutNumber)
636 //get specified page number
637 nPageNumber = nNumber;
638 break;
642 pPageHint = dynamic_cast<LwpPageHint*>(pPageHint->GetNext().obj().get());
644 if (nPageNumber >= 0)
646 return nPageNumber + 1 + pDoc->GetNumberOfPagesBefore();
648 return -1;
652 * @descr: Get page width and height
655 void LwpPageLayout::GetWidthAndHeight(double& fWidth, double& fHeight)
657 //use customized size
658 LwpLayoutGeometry* pLayoutGeo = GetGeometry();
659 if (pLayoutGeo)
661 fWidth = GetGeometryWidth();
662 fHeight = GetGeometryHeight();
665 if (GetUsePrinterSettings())
667 //replaced by printer paper size
668 ScopedVclPtrInstance<Printer> pPrinter;
669 bool bScreen = pPrinter->IsDisplayPrinter();
670 if (!bScreen) //Printer available
672 Size aPaperSize = pPrinter->GetPaperSize();
673 aPaperSize = pPrinter->PixelToLogic(aPaperSize, MapMode(MapUnit::Map10thMM));
674 fWidth = static_cast<double>(aPaperSize.Width()) / 100; //cm unit
675 fHeight = static_cast<double>(aPaperSize.Height()) / 100;
679 //Follow the former design of Lotus WordPro filter, some default will be given:
680 //Page Width: 8.5 Inch -> 21.59 cm
681 //Page Height: 11 Inch -> 27.94 cm
682 if (fWidth < 4.39)
683 fWidth = 21.59;
684 if (fHeight < 4.49)
685 fHeight = 27.94;
686 //End of modification, by ZF
690 * @descr: Get page width
693 double LwpPageLayout::GetWidth()
695 double fWidth = 0, fHeight = 0;
696 GetWidthAndHeight(fWidth, fHeight);
697 return fWidth;
701 * @descr: Get page height
704 double LwpPageLayout::GetHeight()
706 double fWidth = 0, fHeight = 0;
707 GetWidthAndHeight(fWidth, fHeight);
708 return fHeight;
711 * @descr: Compare the position of layout. If the position of this layout is earlier than other layout,return true, or return false
714 bool LwpPageLayout::operator<(LwpPageLayout& Other)
716 LwpPara* pThisPara = GetPagePosition();
717 LwpPara* pOtherPara = Other.GetPagePosition();
718 if (pThisPara && pOtherPara)
720 if (pThisPara == pOtherPara)
722 //If the two layouts in the same para, compare which layout is earlied according to frib order
723 return pThisPara->ComparePagePosition(this, &Other);
725 else
727 return *pThisPara < *pOtherPara;
731 return pThisPara == nullptr;
735 * @descr: Get the position of pagelayout
738 LwpPara* LwpPageLayout::GetPagePosition()
740 LwpPara* pPara = dynamic_cast<LwpPara*>(GetPosition().obj().get());
741 if (pPara)
742 return pPara;
743 //Get the position from its related section
744 LwpFoundry* pFoundry = GetFoundry();
745 if (pFoundry)
747 LwpSection* pSection = nullptr;
748 while ((pSection = pFoundry->EnumSections(pSection)))
750 if (pSection->GetPageLayout() == this)
751 return dynamic_cast<LwpPara*>(pSection->GetPosition().obj().get());
755 return nullptr;
757 LwpHeaderLayout::LwpHeaderLayout(LwpObjectHeader const& objHdr, LwpSvStream* pStrm)
758 : LwpPlacableLayout(objHdr, pStrm)
759 , m_nBorderOffset(0)
763 LwpHeaderLayout::~LwpHeaderLayout() {}
765 void LwpHeaderLayout::Read()
767 LwpPlacableLayout::Read();
769 if (LwpFileHeader::m_nFileRevision >= 0x000E)
770 m_nBorderOffset = m_pObjStrm->QuickReadInt32();
771 else
772 m_nBorderOffset = 0;
773 m_pObjStrm->SkipExtra();
776 void LwpHeaderLayout::RegisterStyle(XFPageMaster* pm1)
778 std::unique_ptr<XFHeaderStyle> xHeaderStyle(new XFHeaderStyle);
780 //Modify page top margin
781 //page top margin: from top of header to the top edge
782 double top = GetMarginsValue(MARGIN_TOP);
783 pm1->SetMargins(-1, -1, top, -1);
785 ParseMargins(xHeaderStyle.get());
786 ParseBorder(xHeaderStyle.get());
787 ParseShadow(xHeaderStyle.get());
788 ParseBackGround(xHeaderStyle.get());
790 ParseWaterMark(xHeaderStyle.get());
791 //End by
793 pm1->SetHeaderStyle(xHeaderStyle.release());
796 void LwpHeaderLayout::ParseMargins(XFHeaderStyle* ph1)
798 //Set height: from top of header to top of body, including the spacing between header and body
799 double height = GetGeometryHeight() - GetMarginsValue(MARGIN_TOP);
800 if (GetIsAutoGrowDown())
802 ph1->SetMinHeight(height);
804 else
806 ph1->SetHeight(height);
809 //Set left,right,bottom margins
810 LwpMiddleLayout* parent = dynamic_cast<LwpMiddleLayout*>(GetParent().obj().get());
811 //left margin in SODC: the space from the left edge of body to the left edge of header
812 double left
813 = GetMarginsValue(MARGIN_LEFT) - (parent ? parent->GetMarginsValue(MARGIN_LEFT) : 0);
814 if (left <= 0) //The left margin in SODC can not be minus value
816 left = -1;
818 //left margin in SODC: the space from the right edge of header to the right edge of body
819 double right
820 = GetMarginsValue(MARGIN_RIGHT) - (parent ? parent->GetMarginsValue(MARGIN_RIGHT) : 0);
821 if (right <= 0) //The right margin in SODC can not be minus value
823 right = -1;
825 ph1->SetMargins(left, right, GetMarginsValue(MARGIN_BOTTOM));
827 //Word Pro has no dynamic spacing, should be set to false
828 ph1->SetDynamicSpace(false);
831 void LwpHeaderLayout::ParseBorder(XFHeaderStyle* pHeaderStyle)
833 std::unique_ptr<XFBorders> pBordres = GetXFBorders();
834 if (pBordres)
836 pHeaderStyle->SetBorders(std::move(pBordres));
840 void LwpHeaderLayout::ParseShadow(XFHeaderStyle* pHeaderStyle)
842 XFShadow* pXFShadow = GetXFShadow();
843 if (pXFShadow)
845 pHeaderStyle->SetShadow(pXFShadow);
850 * @descr: set header back pattern
853 void LwpHeaderLayout::ParsePatternFill(XFHeaderStyle* pHeaderStyle)
855 std::unique_ptr<XFBGImage> xXFBGImage(GetFillPattern());
856 if (xXFBGImage)
858 pHeaderStyle->SetBackImage(xXFBGImage);
862 * @descr: set header background
865 void LwpHeaderLayout::ParseBackGround(XFHeaderStyle* pHeaderStyle)
867 if (IsPatternFill())
869 ParsePatternFill(pHeaderStyle);
871 else
873 ParseBackColor(pHeaderStyle);
877 void LwpHeaderLayout::ParseBackColor(XFHeaderStyle* pHeaderStyle)
879 LwpColor* pColor = GetBackColor();
880 if (pColor)
882 pHeaderStyle->SetBackColor(XFColor(pColor->To24Color()));
886 void LwpHeaderLayout::ParseWaterMark(XFHeaderStyle* pHeaderStyle)
888 std::unique_ptr<XFBGImage> xXFBGImage(GetXFBGImage());
889 if (xXFBGImage)
891 pHeaderStyle->SetBackImage(xXFBGImage);
894 //End by
896 void LwpHeaderLayout::RegisterStyle(XFMasterPage* mp1)
898 rtl::Reference<XFHeader> xHeader(new XFHeader);
899 rtl::Reference<LwpObject> pStory = m_Content.obj();
900 if (pStory.is())
902 LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
903 LwpChangeMgr* pChangeMgr = pGlobal->GetLwpChangeMgr();
904 pChangeMgr->SetHeadFootFribMap(true);
906 //Call the RegisterStyle first to register the styles in header paras, and then XFConvert()
907 pStory->SetFoundry(m_pFoundry);
908 pStory->DoRegisterStyle();
909 //, 06/27/2005
910 //register child layout style for framelayout,
911 RegisterChildStyle();
912 //End
913 pChangeMgr->SetHeadFootChange(xHeader.get());
914 pStory->DoXFConvert(xHeader.get());
916 pChangeMgr->SetHeadFootFribMap(false);
918 mp1->SetHeader(xHeader);
921 LwpFooterLayout::LwpFooterLayout(LwpObjectHeader const& objHdr, LwpSvStream* pStrm)
922 : LwpPlacableLayout(objHdr, pStrm)
923 , m_nBorderOffset(0)
927 LwpFooterLayout::~LwpFooterLayout() {}
929 void LwpFooterLayout::Read()
931 LwpPlacableLayout::Read();
933 if (LwpFileHeader::m_nFileRevision >= 0x000E)
934 m_nBorderOffset = m_pObjStrm->QuickReadInt32();
935 else
936 m_nBorderOffset = 0;
937 m_pObjStrm->SkipExtra();
940 void LwpFooterLayout::RegisterStyle(XFPageMaster* pm1)
942 std::unique_ptr<XFFooterStyle> xFooterStyle(new XFFooterStyle);
944 //Modify page bottom margin
945 //page bottom margin: from bottom of footer to the bottom edge
946 double bottom = GetMarginsValue(MARGIN_BOTTOM);
947 pm1->SetMargins(-1, -1, -1, bottom);
949 ParseMargins(xFooterStyle.get());
950 ParseBorder(xFooterStyle.get());
951 ParseShadow(xFooterStyle.get());
952 ParseBackGround(xFooterStyle.get());
954 ParseWaterMark(xFooterStyle.get());
956 pm1->SetFooterStyle(xFooterStyle.release());
959 void LwpFooterLayout::ParseMargins(XFFooterStyle* pFooterStyle)
961 //Set height: from top of header to top of body, including the spacing between header and body
962 double height = GetGeometryHeight() - GetMarginsValue(MARGIN_BOTTOM);
963 if (IsAutoGrowUp())
965 pFooterStyle->SetMinHeight(height);
967 else
969 pFooterStyle->SetHeight(height);
972 //Set left,right,top margins
973 LwpMiddleLayout* parent = dynamic_cast<LwpMiddleLayout*>(GetParent().obj().get());
974 double left
975 = GetMarginsValue(MARGIN_LEFT) - (parent ? parent->GetMarginsValue(MARGIN_LEFT) : 0);
976 if (left <= 0) //The left margin in SODC can not be minus value
978 left = -1;
980 double right
981 = GetMarginsValue(MARGIN_RIGHT) - (parent ? parent->GetMarginsValue(MARGIN_RIGHT) : 0);
982 if (right <= 0) //The left margin in SODC can not be minus value
984 right = -1;
986 pFooterStyle->SetMargins(left, right, GetMarginsValue(MARGIN_TOP));
988 //Word Pro has no dynamic spacing, should be set to false
989 pFooterStyle->SetDynamicSpace(false);
992 void LwpFooterLayout::ParseBorder(XFFooterStyle* pFooterStyle)
994 std::unique_ptr<XFBorders> pBordres = GetXFBorders();
995 if (pBordres)
997 pFooterStyle->SetBorders(std::move(pBordres));
1001 void LwpFooterLayout::ParseShadow(XFFooterStyle* pFooterStyle)
1003 XFShadow* pXFShadow = GetXFShadow();
1004 if (pXFShadow)
1006 pFooterStyle->SetShadow(pXFShadow);
1010 * @descr: set footer back pattern
1013 void LwpFooterLayout::ParsePatternFill(XFFooterStyle* pFooterStyle)
1015 std::unique_ptr<XFBGImage> xXFBGImage(GetFillPattern());
1016 if (xXFBGImage)
1018 pFooterStyle->SetBackImage(xXFBGImage);
1022 * @descr: set footer background
1025 void LwpFooterLayout::ParseBackGround(XFFooterStyle* pFooterStyle)
1027 if (IsPatternFill())
1029 ParsePatternFill(pFooterStyle);
1031 else
1033 ParseBackColor(pFooterStyle);
1037 void LwpFooterLayout::ParseBackColor(XFFooterStyle* pFooterStyle)
1039 LwpColor* pColor = GetBackColor();
1040 if (pColor)
1042 pFooterStyle->SetBackColor(XFColor(pColor->To24Color()));
1046 void LwpFooterLayout::RegisterStyle(XFMasterPage* mp1)
1048 rtl::Reference<XFFooter> xFooter(new XFFooter);
1049 rtl::Reference<LwpObject> pStory = m_Content.obj(VO_STORY);
1050 //Call the RegisterStyle first to register the styles in footer paras, and then XFConvert()
1051 if (pStory.is())
1053 LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
1054 LwpChangeMgr* pChangeMgr = pGlobal->GetLwpChangeMgr();
1055 pChangeMgr->SetHeadFootFribMap(true);
1057 pStory->SetFoundry(m_pFoundry);
1058 pStory->DoRegisterStyle();
1059 //register child layout style for framelayout,
1060 RegisterChildStyle();
1062 pChangeMgr->SetHeadFootChange(xFooter.get());
1064 pStory->DoXFConvert(xFooter.get());
1066 pChangeMgr->SetHeadFootFribMap(false);
1068 mp1->SetFooter(xFooter);
1071 void LwpFooterLayout::ParseWaterMark(XFFooterStyle* pFooterStyle)
1073 std::unique_ptr<XFBGImage> xXFBGImage(GetXFBGImage());
1074 if (xXFBGImage)
1076 pFooterStyle->SetBackImage(xXFBGImage);
1080 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */