LCOV - code coverage report
Current view: top level - lotuswordpro/source/filter - lwppagelayout.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 303 468 64.7 %
Date: 2014-11-03 Functions: 47 59 79.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*************************************************************************
       3             :  *
       4             :  *  The Contents of this file are made available subject to the terms of
       5             :  *  either of the following licenses
       6             :  *
       7             :  *         - GNU Lesser General Public License Version 2.1
       8             :  *         - Sun Industry Standards Source License Version 1.1
       9             :  *
      10             :  *  Sun Microsystems Inc., October, 2000
      11             :  *
      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
      16             :  *
      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.
      20             :  *
      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.
      25             :  *
      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
      30             :  *
      31             :  *
      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.
      38             :  *
      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.
      45             :  *
      46             :  *  The Initial Developer of the Original Code is: IBM Corporation
      47             :  *
      48             :  *  Copyright: 2008 by IBM Corporation
      49             :  *
      50             :  *  All Rights Reserved.
      51             :  *
      52             :  *  Contributor(s): _______________________________________
      53             :  *
      54             :  *
      55             :  ************************************************************************/
      56             : /*************************************************************************
      57             :  * Change History
      58             : Mar 2005            Created
      59             :  ************************************************************************/
      60             : #include "lwppagelayout.hxx"
      61             : #include "lwplaypiece.hxx"
      62             : #include "lwpfootnote.hxx"
      63             : #include "lwpdoc.hxx"
      64             : #include "lwpholder.hxx"
      65             : #include "lwppagehint.hxx"
      66             : #include "lwpdivinfo.hxx"
      67             : #include "lwpstory.hxx"
      68             : #include "xfilter/xfstylemanager.hxx"
      69             : #include "xfilter/xfmasterpage.hxx"
      70             : #include "xfilter/xfcontentcontainer.hxx"
      71             : #include "xfilter/xfheader.hxx"
      72             : #include "xfilter/xfheaderstyle.hxx"
      73             : #include "xfilter/xffooterstyle.hxx"
      74             : #include "xfilter/xffooter.hxx"
      75             : #include <sfx2/printer.hxx>
      76             : #include "lwpchangemgr.hxx"
      77             : #include "lwpglobalmgr.hxx"
      78             : 
      79          16 : LwpPageLayout::LwpPageLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
      80             :     : LwpLayout(objHdr, pStrm)
      81          16 :     , m_pPrinterBinName(new LwpAtomHolder)
      82             :     , m_nPrinterBin(0)
      83             :     , m_nBdroffset(0)
      84          16 :     , m_pPaperName(new LwpAtomHolder)
      85          48 :     , m_pXFPageMaster(NULL)
      86             : {
      87          16 : }
      88             : 
      89          48 : LwpPageLayout::~LwpPageLayout()
      90             : {
      91          16 :     if (m_pPrinterBinName)
      92             :     {
      93          16 :         delete m_pPrinterBinName;
      94             :     }
      95          16 :     if (m_pPaperName)
      96             :     {
      97          16 :         delete m_pPaperName;
      98             :     }
      99          32 : }
     100          16 : void LwpPageLayout::Read()
     101             : {
     102          16 :     LwpLayout::Read();
     103             : 
     104          16 :     if (LwpFileHeader::m_nFileRevision < 0x000B)
     105             :     {
     106             :         // read PreRevBLayout...
     107             :     }
     108             : 
     109          16 :     m_nPrinterBin = m_pObjStrm->QuickReaduInt16();
     110          16 :     m_pPrinterBinName->Read(m_pObjStrm);
     111             : 
     112          16 :     if (LwpFileHeader::m_nFileRevision >= 0x000B)
     113          16 :         m_nBdroffset = m_pObjStrm->QuickReadInt32();
     114             : 
     115          16 :     if (m_pObjStrm->CheckExtra())
     116             :     {
     117          12 :         m_pPaperName->Read(m_pObjStrm);
     118          12 :         m_pObjStrm->SkipExtra();
     119             :     }
     120             : 
     121          16 : }
     122             : 
     123           6 : void LwpPageLayout::Parse(IXFStream* pOutputStream)
     124             : {
     125             :     //Only parse this layout
     126           6 :     rtl::Reference<LwpObject> pStory = m_Content.obj();
     127           6 :     if(pStory.is())
     128             :     {
     129           6 :         pStory->SetFoundry(m_pFoundry);
     130           6 :         pStory->Parse(pOutputStream);   //Do not parse the next story
     131           6 :     }
     132           6 : }
     133             : 
     134             : /**
     135             : * @descr:   set page margins
     136             : *
     137             : */
     138          16 : void LwpPageLayout::ParseMargins(XFPageMaster* pm1)
     139             : {
     140          16 :     double fLeft    = GetMarginsValue(MARGIN_LEFT);
     141          16 :     double fRight   = GetMarginsValue(MARGIN_RIGHT);
     142          16 :     double fTop = GetMarginsValue(MARGIN_TOP);
     143          16 :     double fBottom  = GetMarginsValue(MARGIN_BOTTOM);
     144             : 
     145          16 :     pm1->SetMargins( fLeft, fRight, fTop, fBottom );
     146             : 
     147          16 : }
     148             : 
     149             : /**
     150             : * @descr:   set page height and width
     151             : *
     152             : */
     153          16 : void LwpPageLayout::ParseGeometry(XFPageMaster* pm1)
     154             : {
     155             :     /*
     156             :     LwpLayoutGeometry* pLayoutGeo = GetGeometry();
     157             :     if(pLayoutGeo)
     158             :     {
     159             :         pm1->SetPageHeight( GetGeometryHeight() );
     160             :         pm1->SetPageWidth( GetGeometryWidth() );
     161             :     }
     162             :     */
     163          16 :     double fWidth =0;
     164          16 :     double fHeight = 0;
     165          16 :     GetWidthAndHeight(fWidth, fHeight);
     166          16 :     pm1->SetPageWidth( fWidth );
     167          16 :     pm1->SetPageHeight( fHeight );
     168          16 : }
     169             : 
     170             : /**
     171             : * @descr:   set page watermark
     172             : *
     173             : */
     174          16 : void LwpPageLayout::ParseWaterMark(XFPageMaster *pm1)
     175             : {
     176          16 :     XFBGImage* pXFBGImage = GetXFBGImage();
     177          16 :     if(pXFBGImage)
     178             :     {
     179           0 :         pm1->SetBackImage(pXFBGImage);
     180             :     }
     181          16 : }
     182             : 
     183             : /**
     184             : * @descr:   set page columns
     185             : *
     186             : */
     187          16 : void LwpPageLayout::ParseColumns(XFPageMaster * pm1)
     188             : {
     189          16 :     XFColumns* pColumns = GetXFColumns();
     190          16 :     if(pColumns)
     191             :     {
     192           0 :         pm1->SetColumns(pColumns);
     193             :     }
     194          16 : }
     195             : 
     196             : /**
     197             : * @descr:   set page borders
     198             : *
     199             : */
     200          16 : void LwpPageLayout::ParseBorders(XFPageMaster *pm1)
     201             : {
     202          16 :     XFBorders* pBordres = GetXFBorders();
     203          16 :     if(pBordres)
     204             :     {
     205           0 :         pm1->SetBorders(pBordres);
     206             :     }
     207          16 : }
     208             : 
     209             : /**
     210             : * @descr:   set page shadow
     211             : *
     212             : */
     213          16 : void LwpPageLayout::ParseShadow(XFPageMaster *pm1)
     214             : {
     215          16 :     XFShadow* pXFShadow = GetXFShadow();
     216          16 :     if(pXFShadow)
     217             :     {
     218           0 :         pm1->SetShadow(pXFShadow);
     219             :     }
     220          16 : }
     221             : 
     222             : /**
     223             : * @descr:   set page back pattern
     224             : *
     225             : */
     226           0 : void LwpPageLayout::ParsePatternFill(XFPageMaster* pm1)
     227             : {
     228           0 :     XFBGImage* pXFBGImage = this->GetFillPattern();
     229           0 :     if (pXFBGImage)
     230             :     {
     231           0 :         pm1->SetBackImage(pXFBGImage);
     232             :     }
     233           0 : }
     234             : /**
     235             : * @descr:   set page background
     236             : *
     237             : */
     238          16 : void LwpPageLayout::ParseBackGround(XFPageMaster* pm1)
     239             : {
     240          16 :     if (this->IsPatternFill())
     241             :     {
     242           0 :         ParsePatternFill(pm1);
     243             :     }
     244             :     else
     245             :     {
     246          16 :         ParseBackColor(pm1);
     247             :     }
     248          16 : }
     249             : 
     250             : /**
     251             : * @descr:   set page back color
     252             : *
     253             : */
     254          16 : void LwpPageLayout::ParseBackColor(XFPageMaster* pm1)
     255             : {
     256          16 :     LwpColor* pColor = GetBackColor();
     257          16 :     if(pColor)
     258             :     {
     259          16 :         pm1->SetBackColor(XFColor(pColor->To24Color()));
     260             :     }
     261          16 : }
     262             : 
     263             : /**
     264             : * @descr:   set page footnote separator information
     265             : *
     266             : */
     267          16 : void LwpPageLayout::ParseFootNoteSeparator(XFPageMaster * pm1)
     268             : {
     269             :     //Get the footnoteoptions for the root document
     270          16 :     LwpDocument* pDocument = m_pFoundry->GetDocument();
     271          16 :     if(pDocument)
     272             :     {
     273          16 :         LwpObjectID* pFontnodeId = pDocument->GetValidFootnoteOpts();
     274             : 
     275          16 :         LwpFootnoteOptions* pFootnoteOpts = pFontnodeId ? dynamic_cast<LwpFootnoteOptions*>(pFontnodeId->obj().get()) : NULL;
     276          16 :         if(pFootnoteOpts)
     277             :         {
     278          16 :             LwpFootnoteSeparatorOptions& rFootnoteSep = pFootnoteOpts->GetFootnoteSeparator();
     279             :             //set length
     280          16 :             sal_uInt32 nLengthPercent = 100;
     281          16 :             double fWidth = 0;
     282          16 :             if(rFootnoteSep.HasSeparator())
     283             :             {
     284          16 :                 fWidth = rFootnoteSep.GetTopBorderWidth();
     285             :             }
     286          16 :             if(rFootnoteSep.HasCustomLength())
     287             :             {
     288           0 :                 nLengthPercent =  static_cast<sal_uInt32>(100*LwpTools::ConvertFromUnitsToMetric(rFootnoteSep.GetLength())/GetMarginWidth());
     289           0 :                 if(nLengthPercent > 100)
     290           0 :                     nLengthPercent = 100;
     291             :             }
     292          16 :             double fAbove = LwpTools::ConvertFromUnitsToMetric(rFootnoteSep.GetAbove());
     293          16 :             double fBelow = LwpTools::ConvertFromUnitsToMetric(rFootnoteSep.GetBelow());
     294          16 :             LwpColor aColor = rFootnoteSep.GetTopBorderColor();
     295          16 :             enumXFAlignType eAlignType = enumXFAlignStart;
     296          16 :             if(rFootnoteSep.GetIndent() > 0)
     297             :             {
     298             :                 //SODC don't support indent
     299           0 :                 sal_uInt32 nIndentPercent =  static_cast<sal_uInt32>(100*LwpTools::ConvertFromUnitsToMetric(rFootnoteSep.GetIndent())/GetMarginWidth());
     300           0 :                 if(nIndentPercent + nLengthPercent >= 100)
     301           0 :                     eAlignType = enumXFAlignEnd;
     302             :             }
     303          16 :             if(aColor.IsValidColor())
     304             :             {
     305          16 :                 XFColor aXFColor(aColor.To24Color());
     306          16 :                 pm1->SetFootNoteSeparator(eAlignType,fWidth, nLengthPercent, fAbove, fBelow, aXFColor);
     307          16 :             }
     308             :         }
     309             :     }
     310          16 : }
     311             : 
     312             : /**
     313             : * @descr:   Register master page and page master style
     314             : *
     315             : */
     316          16 : void LwpPageLayout::RegisterStyle()
     317             : {
     318          16 :     XFPageMaster* pm1 = new XFPageMaster();
     319          16 :     m_pXFPageMaster = pm1;
     320             : 
     321          16 :     ParseGeometry( pm1 );
     322             :     //Does not process LayoutScale, for watermark is not supported in SODC.
     323          16 :     ParseWaterMark( pm1);
     324          16 :     ParseMargins( pm1);
     325          16 :     ParseColumns(pm1);
     326          16 :     ParseBorders(pm1);
     327          16 :     ParseShadow(pm1);
     328             : //  ParseBackColor(pm1);
     329          16 :     ParseBackGround(pm1);
     330          16 :     ParseFootNoteSeparator(pm1);
     331          16 :     pm1->SetTextDir(GetTextDirection());
     332             : 
     333          16 :     LwpUseWhen* pUseWhen = GetUseWhen();
     334          16 :     if(IsComplex() ||( pUseWhen && pUseWhen->IsUseOnAllOddPages()))
     335             :     {
     336           0 :         pm1->SetPageUsage(enumXFPageUsageMirror);
     337             :     }
     338             : 
     339             :     //Add the page master to stylemanager
     340          16 :     XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
     341          16 :     m_pXFPageMaster = pm1 = static_cast<XFPageMaster*>(pXFStyleManager->AddStyle(pm1));
     342          16 :     OUString pmname = pm1->GetStyleName();
     343             : 
     344             :     //Add master page
     345          16 :     XFMasterPage* mp1 = new XFMasterPage();
     346          16 :     mp1->SetStyleName(GetName().str());
     347          16 :     mp1->SetPageMaster(pmname);
     348          16 :     mp1 = static_cast<XFMasterPage*>(pXFStyleManager->AddStyle(mp1));
     349          16 :     m_StyleName = mp1->GetStyleName();
     350             : 
     351             :     //Set footer style
     352          16 :     LwpFooterLayout* pLayoutFooter = GetFooterLayout();
     353          16 :     if(pLayoutFooter)
     354             :     {
     355          16 :         pLayoutFooter->SetFoundry(m_pFoundry);
     356          16 :         pLayoutFooter->RegisterStyle(pm1);
     357          16 :         pLayoutFooter->RegisterStyle(mp1);
     358             :     }
     359             : 
     360             :     //Set header style
     361          16 :     LwpHeaderLayout* pLayoutHeader = GetHeaderLayout();
     362          16 :     if(pLayoutHeader)
     363             :     {
     364          16 :         pLayoutHeader->SetFoundry(m_pFoundry);
     365          16 :         pLayoutHeader->RegisterStyle(pm1);
     366          16 :         pLayoutHeader->RegisterStyle(mp1);
     367             :     }
     368             :     //register child layout style for mirror page and frame
     369          16 :     RegisterChildStyle();
     370          16 : }
     371             : 
     372             : /**
     373             : * @descr:   Register master page for endnote which name is "endnote"
     374             : * @return:  Return the master page name.
     375             : */
     376           0 : OUString LwpPageLayout::RegisterEndnoteStyle()
     377             : {
     378           0 :     XFPageMaster* pm1 = new XFPageMaster();
     379           0 :     m_pXFPageMaster = pm1;
     380             : 
     381           0 :     ParseGeometry( pm1 );
     382           0 :     ParseWaterMark( pm1);
     383           0 :     ParseMargins( pm1);
     384           0 :     ParseColumns(pm1);
     385           0 :     ParseBorders(pm1);
     386           0 :     ParseShadow(pm1);
     387             : //  ParseBackColor(pm1);
     388           0 :     ParseBackGround(pm1);
     389             :     //ParseFootNoteSeparator(pm1);
     390           0 :     pm1->SetTextDir(GetTextDirection());
     391             : 
     392           0 :     LwpUseWhen* pUseWhen = GetUseWhen();
     393           0 :     if(IsComplex() ||( pUseWhen && pUseWhen->IsUseOnAllOddPages()))
     394             :     {
     395           0 :         pm1->SetPageUsage(enumXFPageUsageMirror);
     396             :     }
     397             : 
     398             :     //Add the page master to stylemanager
     399           0 :     XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
     400           0 :     m_pXFPageMaster = pm1 = static_cast<XFPageMaster*>(pXFStyleManager->AddStyle(pm1));
     401           0 :     OUString pmname = pm1->GetStyleName();
     402             : 
     403             :     //Add master page
     404           0 :     XFMasterPage* mp1 = new XFMasterPage();
     405           0 :     mp1->SetStyleName("Endnote");
     406           0 :     mp1->SetPageMaster(pmname);
     407             : 
     408             :     //Set footer style
     409           0 :     LwpFooterLayout* pLayoutFooter = GetFooterLayout();
     410           0 :     if(pLayoutFooter)
     411             :     {
     412           0 :         pLayoutFooter->SetFoundry(m_pFoundry);
     413           0 :         pLayoutFooter->RegisterStyle(pm1);
     414           0 :         pLayoutFooter->RegisterStyle(mp1);
     415             :     }
     416             : 
     417             :     //Set header style
     418           0 :     LwpHeaderLayout* pLayoutHeader = GetHeaderLayout();
     419           0 :     if(pLayoutHeader)
     420             :     {
     421           0 :         pLayoutHeader->SetFoundry(m_pFoundry);
     422           0 :         pLayoutHeader->RegisterStyle(pm1);
     423           0 :         pLayoutHeader->RegisterStyle(mp1);
     424             :     }
     425             : 
     426           0 :     return pXFStyleManager->AddStyle(mp1)->GetStyleName();
     427             : }
     428             : /**
     429             : * @descr:   Whether current page layout has columns
     430             : *
     431             : */
     432           8 : bool LwpPageLayout::HasColumns()
     433             : {
     434           8 :     return GetNumCols() > 1;
     435             : }
     436             : 
     437             : /**
     438             : * @descr:   Whether has filler page text in current page layout
     439             : *
     440             : */
     441           0 : bool LwpPageLayout::HasFillerPageText(LwpFoundry* pFoundry)
     442             : {
     443           0 :     if(!pFoundry) return false;
     444             : 
     445           0 :     bool bFillerPage = false;
     446           0 :     LwpLayout::UseWhenType eWhenType = GetUseWhenType();
     447           0 :     if(eWhenType==LwpLayout::StartOnOddPage||eWhenType==LwpLayout::StartOnEvenPage)
     448             :     {
     449             :         //get pagenumber
     450           0 :         sal_uInt16 nPageNumber = 0;
     451             : 
     452             :         //get the page number that current page layout inserted
     453           0 :         nPageNumber = GetPageNumber(FIRST_LAYOUTPAGENO)-1;
     454             : 
     455           0 :         if(nPageNumber>0)
     456             :         {
     457           0 :             if((eWhenType==LwpLayout::StartOnOddPage)&&(LwpTools::IsOddNumber(nPageNumber)))
     458             :             {
     459           0 :                 bFillerPage = true;
     460             :             }
     461           0 :             else if((eWhenType==LwpLayout::StartOnEvenPage)&&(LwpTools::IsEvenNumber(nPageNumber)))
     462             :             {
     463           0 :                 bFillerPage = true;
     464             :             }
     465             :             else
     466             :             {
     467           0 :                 bFillerPage = false;
     468             :             }
     469             :         }
     470             :     }
     471             : 
     472           0 :     return bFillerPage;
     473             : }
     474             : 
     475             : /**
     476             : * @descr:   Parse filler page text
     477             : *
     478             : */
     479           0 : void LwpPageLayout::ConvertFillerPageText(XFContentContainer* pCont)
     480             : {
     481           0 :     if(HasFillerPageText(m_pFoundry))
     482             :     {
     483             :         //get filerpage story from division info
     484           0 :         LwpDocument* pDoc = m_pFoundry->GetDocument();
     485           0 :         LwpDivInfo* pDivInfo = dynamic_cast<LwpDivInfo*>(pDoc->GetDivInfoID().obj().get());
     486           0 :         LwpStory* pStory = dynamic_cast<LwpStory*>(pDivInfo->GetFillerPageTextID().obj().get());
     487             : 
     488             :         //parse fillerpage story
     489           0 :         if(pStory)
     490             :         {
     491           0 :             pStory->XFConvert(pCont);
     492             :         }
     493             :     }
     494           0 : }
     495             : /**
     496             : * @descr:   Clear columns style in page layout
     497             : *
     498             : */
     499           0 : void LwpPageLayout::ResetXFColumns()
     500             : {
     501           0 :     if(m_pXFPageMaster)
     502             :     {
     503           0 :         m_pXFPageMaster->SetColumns(NULL);
     504             :     }
     505           0 : }
     506             : 
     507          16 : LwpHeaderLayout* LwpPageLayout::GetHeaderLayout()
     508             : {
     509          16 :     LwpVirtualLayout* pLay = dynamic_cast<LwpVirtualLayout*>(GetChildHead().obj().get());
     510          48 :     while(pLay)
     511             :     {
     512          32 :         if( pLay->GetLayoutType() == LWP_HEADER_LAYOUT )
     513          16 :             return ( static_cast<LwpHeaderLayout*> (pLay) );
     514          16 :         pLay = dynamic_cast<LwpVirtualLayout*> (pLay->GetNext().obj().get());
     515             :     }
     516           0 :     return NULL;
     517             : }
     518             : 
     519          16 : LwpFooterLayout* LwpPageLayout::GetFooterLayout()
     520             : {
     521          16 :     LwpVirtualLayout* pLay = dynamic_cast<LwpVirtualLayout*>(GetChildHead().obj().get());
     522          32 :     while(pLay)
     523             :     {
     524          16 :         if( pLay->GetLayoutType() == LWP_FOOTER_LAYOUT )
     525          16 :             return ( static_cast<LwpFooterLayout*> (pLay) );
     526           0 :         pLay = dynamic_cast<LwpVirtualLayout*> (pLay->GetNext().obj().get());
     527             :     }
     528           0 :     return NULL;
     529             : }
     530             : 
     531             : /**
     532             : * @descr:   Get the odd layout if current page layout is mirror page
     533             : *
     534             : */
     535           8 : LwpPageLayout* LwpPageLayout::GetOddChildLayout()
     536             : {
     537           8 :     if(IsComplex())
     538             :     {
     539           0 :         LwpVirtualLayout* pLay = dynamic_cast<LwpVirtualLayout*>(GetChildHead().obj().get());
     540           0 :         while(pLay)
     541             :         {
     542           0 :             if( pLay->GetLayoutType() == LWP_PAGE_LAYOUT )
     543             :             {
     544           0 :                 LwpPageLayout* pPageLayout = static_cast<LwpPageLayout*> (pLay);
     545           0 :                 LwpUseWhen* pUseWhen = pPageLayout->GetUseWhen();
     546           0 :                 if(pUseWhen && pUseWhen->IsUseOnAllOddPages())
     547             :                 {
     548           0 :                     return pPageLayout;
     549             :                 }
     550             :             }
     551           0 :             pLay = dynamic_cast<LwpVirtualLayout*> (pLay->GetNext().obj().get());
     552             :         }
     553             :     }
     554           8 :     return NULL;
     555             : }
     556             : 
     557             : /**
     558             : * @descr:   Get margin width of page
     559             : *
     560             : */
     561           0 : double LwpPageLayout::GetMarginWidth()
     562             : {
     563           0 :     double fPagewidth = GetGeometryWidth();
     564           0 :     double fLeftMargin = GetMarginsValue(MARGIN_LEFT);
     565           0 :     double fRightMargin = GetMarginsValue(MARGIN_RIGHT);
     566             : 
     567           0 :     return fPagewidth - (fLeftMargin + fRightMargin);
     568             : }
     569             : 
     570             : /**
     571             :  * @descr:  Get the pagenumber
     572             :  * @param:  if  nLayoutNumber =FIRST_LAYOUTPAGENO,  return the first page number  that current page layout covers
     573             :                               =LAST_LAYOUTPAGENO, return the last page number that current page layout covers
     574             :                                else, return the specified page number that current page layout covers
     575             :  * @param:
     576             :  * @return:  if reture value >=0, success to find the page number, or fail.
     577             : */
     578           0 : sal_Int32 LwpPageLayout::GetPageNumber(sal_uInt16 nLayoutNumber)
     579             : {
     580           0 :     sal_Int16 nPageNumber = -1;
     581           0 :     LwpFoundry* pFoundry = this->GetFoundry();
     582           0 :     LwpDocument* pDoc = pFoundry->GetDocument();
     583           0 :     LwpDLVListHeadTailHolder* pHeadTail = dynamic_cast<LwpDLVListHeadTailHolder*>(pDoc->GetPageHintsID().obj().get());
     584           0 :     if(!pHeadTail) return nPageNumber;
     585             : 
     586             :     //get first pagehint
     587           0 :     LwpPageHint* pPageHint = dynamic_cast<LwpPageHint*>(pHeadTail->GetHead().obj().get());
     588           0 :     while(pPageHint)
     589             :     {
     590           0 :         if(this->GetObjectID() == pPageHint->GetPageLayoutID())
     591             :         {
     592           0 :             sal_uInt16 nNumber = pPageHint->GetPageNumber();
     593           0 :             if(nLayoutNumber==FIRST_LAYOUTPAGENO && pPageHint->GetLayoutPageNumber()==1)
     594             :             {
     595             :                 //get the first page number
     596           0 :                 nPageNumber = nNumber;
     597           0 :                 break;
     598             :             }
     599           0 :             else if( nLayoutNumber ==LAST_LAYOUTPAGENO && nNumber >nPageNumber )
     600             :             {
     601             :                 //get the last page number
     602           0 :                 nPageNumber = nNumber;
     603           0 :                 if(pPageHint->GetNext().IsNull())
     604             :                 {
     605             :                     //if is last page number of entire document, reture directly
     606           0 :                     return nPageNumber + pDoc->GetNumberOfPagesBefore();
     607             :                 }
     608             :             }
     609           0 :             else if(nLayoutNumber > 0 && pPageHint->GetLayoutPageNumber() == nLayoutNumber)
     610             :             {
     611             :                 //get specified page number
     612           0 :                 nPageNumber = nNumber;
     613           0 :                 break;
     614             :             }
     615             : 
     616             :         }
     617           0 :         pPageHint = dynamic_cast<LwpPageHint*>(pPageHint->GetNext().obj().get());
     618             :     }
     619           0 :     if(nPageNumber>=0)
     620             :     {
     621           0 :         return nPageNumber + 1 + pDoc->GetNumberOfPagesBefore();
     622             :     }
     623           0 :     return -1;
     624             : }
     625             : 
     626             : /**
     627             : * @descr:   Get page width and height
     628             : *
     629             : */
     630          58 : void LwpPageLayout::GetWidthAndHeight(double& fWidth, double& fHeight)
     631             : {
     632             :     //use customized size
     633          58 :     LwpLayoutGeometry* pLayoutGeo = GetGeometry();
     634          58 :     if(pLayoutGeo)
     635             :     {
     636          58 :         fWidth = GetGeometryWidth();
     637          58 :         fHeight = GetGeometryHeight();
     638             :     }
     639             : 
     640          58 :     if(GetUsePrinterSettings())
     641             :     {
     642             :         //replaced by printer paper size
     643          54 :         Printer aPrinter;
     644          54 :         bool bScreen = aPrinter.IsDisplayPrinter();
     645          54 :         if (!bScreen)//Printer available
     646             :         {
     647          54 :             Size aPaperSize = aPrinter.GetPaperSize();
     648          54 :             aPaperSize = aPrinter.PixelToLogic( aPaperSize, MapMode( MAP_10TH_MM ) );
     649          54 :             fWidth = static_cast<double>(aPaperSize.Width())/100;   //cm unit
     650          54 :             fHeight = static_cast<double>(aPaperSize.Height())/100;
     651          54 :         }
     652             :     }
     653             : 
     654             :     //Follow the former design of Lotus WordPro filter, some default will be given:
     655             :     //Page Width: 8.5 Inch -> 21.59 cm
     656             :     //Page Height: 11 Inch -> 27.94 cm
     657          58 :     if (fWidth < 4.39)
     658           0 :         fWidth = 21.59;
     659          58 :     if (fHeight < 4.49)
     660           0 :         fHeight = 27.94;
     661             :     //End of modification, by ZF
     662          58 : }
     663             : 
     664             : /**
     665             : * @descr:   Get page width
     666             : *
     667             : */
     668          42 : double LwpPageLayout::GetWidth()
     669             : {
     670          42 :     double fWidth =0, fHeight = 0;
     671          42 :     GetWidthAndHeight(fWidth, fHeight);
     672          42 :     return fWidth;
     673             : }
     674             : 
     675             : /**
     676             : * @descr:   Get page height
     677             : *
     678             : */
     679           0 : double LwpPageLayout::GetHeight()
     680             : {
     681           0 :     double fWidth =0, fHeight = 0;
     682           0 :     GetWidthAndHeight(fWidth, fHeight);
     683           0 :     return fHeight;
     684             : }
     685             : /**
     686             : * @descr:  Compare the position of layout. If the poistion of this layout is earlier than other layout,return ture, or return false
     687             : *
     688             : */
     689           0 : bool LwpPageLayout::operator<(LwpPageLayout& Other)
     690             : {
     691           0 :     LwpPara* pThisPara = GetPagePosition();
     692           0 :     LwpPara* pOtherPara = Other.GetPagePosition();
     693           0 :     if(pThisPara && pOtherPara)
     694             :     {
     695           0 :         if(pThisPara == pOtherPara)
     696             :         {
     697             :             //If the two layouts in the same para, compare which layout is earlied according to frib order
     698           0 :             return pThisPara->ComparePagePosition(this, &Other);
     699             :         }
     700             :         else
     701             :         {
     702           0 :             return *pThisPara < *pOtherPara;
     703             :         }
     704             :     }
     705             : 
     706           0 :     if(!pThisPara)
     707           0 :         return true;
     708             : 
     709           0 :     return false;
     710             : }
     711             : 
     712             : /**
     713             : * @descr:  Get the position of pagelayout
     714             : *
     715             : */
     716           0 : LwpPara* LwpPageLayout::GetPagePosition()
     717             : {
     718           0 :     LwpPara* pPara = dynamic_cast<LwpPara*>(GetPosition().obj().get());
     719           0 :     if(pPara)
     720           0 :         return pPara;
     721             :     //Get the position from its related section
     722           0 :     LwpSection* pSection = NULL;
     723           0 :     LwpFoundry* pFoundry = GetFoundry();
     724           0 :     if(pFoundry)
     725             :     {
     726           0 :         while( (pSection = pFoundry->EnumSections(pSection)) )
     727             :         {
     728           0 :             if(pSection->GetPageLayout() == this)
     729           0 :                 return dynamic_cast<LwpPara*>(pSection->GetPosition().obj().get());
     730             :         }
     731             :     }
     732             : 
     733           0 :     return NULL;
     734             : }
     735          24 : LwpHeaderLayout::LwpHeaderLayout( LwpObjectHeader &objHdr, LwpSvStream* pStrm )
     736             :     : LwpPlacableLayout(objHdr, pStrm)
     737          24 :     , m_nBorderOffset(0)
     738             : {
     739          24 : }
     740             : 
     741          48 : LwpHeaderLayout::~LwpHeaderLayout()
     742             : {
     743          48 : }
     744             : 
     745          24 : void LwpHeaderLayout::Read()
     746             : {
     747          24 :     LwpPlacableLayout::Read();
     748             : 
     749          24 :     if(LwpFileHeader::m_nFileRevision >= 0x000E)
     750          24 :         m_nBorderOffset = m_pObjStrm->QuickReadInt32();
     751             :     else
     752           0 :         m_nBorderOffset = 0;
     753          24 :     m_pObjStrm->SkipExtra();
     754          24 : }
     755             : 
     756          16 : void LwpHeaderLayout::RegisterStyle(XFPageMaster* pm1)
     757             : {
     758          16 :     XFHeaderStyle* pHeaderStyle = new XFHeaderStyle();
     759             : 
     760             :     //Modify page top margin
     761             :     //page top maring: from top of header to the top edge
     762          16 :     double top = GetMarginsValue(MARGIN_TOP);
     763          16 :     pm1->SetMargins(-1, -1, top, -1);
     764             : 
     765          16 :     ParseMargins(pHeaderStyle);
     766          16 :     ParseBorder(pHeaderStyle);
     767          16 :     ParseShadow(pHeaderStyle);
     768             : //  ParseBackColor(pHeaderStyle);
     769          16 :     ParseBackGround(pHeaderStyle);
     770             : 
     771          16 :     ParseWaterMark(pHeaderStyle);
     772             :     //End by
     773             : 
     774          16 :     pm1->SetHeaderStyle(pHeaderStyle);
     775          16 : }
     776             : 
     777          16 : void LwpHeaderLayout::ParseMargins(XFHeaderStyle* ph1)
     778             : {
     779             :     //Set height: from top of header to top of body, including the spacing between header and body
     780          16 :     double height = GetGeometryHeight()- GetMarginsValue(MARGIN_TOP);
     781          16 :     if( IsAutoGrowDown() )
     782             :     {
     783           0 :         ph1->SetMinHeight(height);
     784             :     }
     785             :     else
     786             :     {
     787          16 :         ph1->SetHeight(height);
     788             :     }
     789             : 
     790             :     //Set left,right,bottom margins
     791          16 :     LwpMiddleLayout* parent = dynamic_cast<LwpMiddleLayout*> (GetParent().obj().get());
     792             :     //left margin in SODC: the space from the left edge of body to the left edge of header
     793          16 :     double left = GetMarginsValue(MARGIN_LEFT) - (parent ? parent->GetMarginsValue(MARGIN_LEFT) : 0);
     794          16 :     if(left<=0) //The left margin in SODC can not be minus value
     795             :     {
     796          16 :         left = -1;
     797             :     }
     798             :     //left margin in SODC: the space from the right edge of header to the right edge of body
     799          16 :     double right = GetMarginsValue(MARGIN_RIGHT) - (parent ? parent->GetMarginsValue(MARGIN_RIGHT) : 0);
     800          16 :     if(right<=0)//The right margin in SODC can not be minus value
     801             :     {
     802          16 :         right = -1;
     803             :     }
     804          16 :     ph1->SetMargins( left, right, GetMarginsValue(MARGIN_BOTTOM));
     805             : 
     806             :     //Word Pro has no dynamic spacing, should be set to false
     807          16 :     ph1->SetDynamicSpace(false);
     808          16 : }
     809             : 
     810          16 : void LwpHeaderLayout::ParseBorder(XFHeaderStyle* pHeaderStyle)
     811             : {
     812          16 :     XFBorders* pBordres = GetXFBorders();
     813          16 :     if(pBordres)
     814             :     {
     815           0 :         pHeaderStyle->SetBorders(pBordres);
     816             :     }
     817          16 : }
     818             : 
     819          16 : void LwpHeaderLayout::ParseShadow(XFHeaderStyle* pHeaderStyle)
     820             : {
     821          16 :     XFShadow* pXFShadow = GetXFShadow();
     822          16 :     if(pXFShadow)
     823             :     {
     824           0 :         pHeaderStyle->SetShadow(pXFShadow);
     825             :     }
     826          16 : }
     827             : 
     828             : /**
     829             : * @descr:   set header back pattern
     830             : *
     831             : */
     832           0 : void LwpHeaderLayout::ParsePatternFill(XFHeaderStyle* pHeaderStyle)
     833             : {
     834           0 :     XFBGImage* pXFBGImage = this->GetFillPattern();
     835           0 :     if (pXFBGImage)
     836             :     {
     837           0 :         pHeaderStyle->SetBackImage(pXFBGImage);
     838             :     }
     839           0 : }
     840             : /**
     841             : * @descr:   set header background
     842             : *
     843             : */
     844          16 : void LwpHeaderLayout::ParseBackGround(XFHeaderStyle* pHeaderStyle)
     845             : {
     846          16 :     if (this->IsPatternFill())
     847             :     {
     848           0 :         ParsePatternFill(pHeaderStyle);
     849             :     }
     850             :     else
     851             :     {
     852          16 :         ParseBackColor(pHeaderStyle);
     853             :     }
     854          16 : }
     855             : 
     856          16 : void LwpHeaderLayout::ParseBackColor(XFHeaderStyle* pHeaderStyle)
     857             : {
     858          16 :     LwpColor* pColor = GetBackColor();
     859          16 :     if(pColor)
     860             :     {
     861           0 :         pHeaderStyle->SetBackColor(XFColor(pColor->To24Color()));
     862             :     }
     863          16 : }
     864             : 
     865          16 : void LwpHeaderLayout::ParseWaterMark(XFHeaderStyle * pHeaderStyle)
     866             : {
     867          16 :     XFBGImage* pXFBGImage = GetXFBGImage();
     868          16 :     if(pXFBGImage)
     869             :     {
     870           0 :         pHeaderStyle->SetBackImage(pXFBGImage);
     871             :     }
     872          16 : }
     873             : //End by
     874             : 
     875          16 : void LwpHeaderLayout::RegisterStyle(XFMasterPage* mp1)
     876             : {
     877          16 :     XFHeader* pHeader = new XFHeader();
     878          16 :     rtl::Reference<LwpObject> pStory = m_Content.obj();
     879          16 :     if(pStory.is())
     880             :     {
     881          16 :         LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
     882          16 :         LwpChangeMgr* pChangeMgr = pGlobal->GetLwpChangeMgr();
     883          16 :         pChangeMgr->SetHeadFootFribMap(true);
     884             : 
     885             :         //Call the RegisterStyle first to register the styles in header paras, and then XFConvert()
     886          16 :         pStory->SetFoundry(m_pFoundry);
     887          16 :         pStory->RegisterStyle();
     888             :         //, 06/27/2005
     889             :         //register child layout style for framelayout,
     890          16 :         RegisterChildStyle();
     891             :         //End
     892          16 :         pChangeMgr->SetHeadFootChange(pHeader);
     893          16 :         pStory->XFConvert(pHeader);
     894             : 
     895          16 :         pChangeMgr->SetHeadFootFribMap(false);
     896             :     }
     897          16 :     mp1->SetHeader(pHeader);
     898          16 : }
     899             : 
     900          24 : LwpFooterLayout::LwpFooterLayout( LwpObjectHeader &objHdr, LwpSvStream* pStrm )
     901             :     : LwpPlacableLayout( objHdr, pStrm )
     902          24 :     , m_nBorderOffset(0)
     903             : {
     904          24 : }
     905             : 
     906          48 : LwpFooterLayout::~LwpFooterLayout()
     907             : {
     908          48 : }
     909             : 
     910          24 : void LwpFooterLayout::Read()
     911             : {
     912          24 :     LwpPlacableLayout::Read();
     913             : 
     914          24 :     if(LwpFileHeader::m_nFileRevision >= 0x000E)
     915          24 :         m_nBorderOffset = m_pObjStrm->QuickReadInt32();
     916             :     else
     917           0 :         m_nBorderOffset = 0;
     918          24 :     m_pObjStrm->SkipExtra();
     919          24 : }
     920             : 
     921          16 : void LwpFooterLayout::RegisterStyle(XFPageMaster* pm1)
     922             : {
     923          16 :     XFFooterStyle* pFooterStyle = new XFFooterStyle();
     924             : 
     925             :     //Modify page bottom margin
     926             :     //page bottom maring: from bottom of footer to the bottom edge
     927          16 :     double bottom = GetMarginsValue(MARGIN_BOTTOM);
     928          16 :     pm1->SetMargins(-1, -1, -1, bottom);
     929             : 
     930          16 :     ParseMargins(pFooterStyle);
     931          16 :     ParseBorder(pFooterStyle);
     932          16 :     ParseShadow(pFooterStyle);
     933          16 :     ParseBackGround(pFooterStyle);
     934             : //  ParseBackColor(pFooterStyle);
     935             : 
     936          16 :     ParseWaterMark(pFooterStyle);
     937             :     //End by
     938             : 
     939          16 :     pm1->SetFooterStyle(pFooterStyle);
     940          16 : }
     941             : 
     942          16 : void LwpFooterLayout::ParseMargins(XFFooterStyle* pFooterStyle)
     943             : {
     944             : 
     945             :     //Set height: from top of header to top of body, including the spacing between header and body
     946          16 :     double height = GetGeometryHeight() - GetMarginsValue(MARGIN_BOTTOM);
     947          16 :     if( IsAutoGrowUp() )
     948             :     {
     949           0 :         pFooterStyle->SetMinHeight(height);
     950             :     }
     951             :     else
     952             :     {
     953          16 :         pFooterStyle->SetHeight(height);
     954             :     }
     955             : 
     956             :     //Set left,right,top margins
     957          16 :     LwpMiddleLayout* parent = dynamic_cast<LwpMiddleLayout*> (GetParent().obj().get());
     958          16 :     double left = GetMarginsValue(MARGIN_LEFT) - (parent ? parent->GetMarginsValue(MARGIN_LEFT) : 0);
     959          16 :     if(left<=0) //The left margin in SODC can not be minus value
     960             :     {
     961          16 :         left = -1;
     962             :     }
     963          16 :     double right = GetMarginsValue(MARGIN_RIGHT) - (parent ? parent->GetMarginsValue(MARGIN_RIGHT) : 0);
     964          16 :     if(right<=0)//The left margin in SODC can not be minus value
     965             :     {
     966          16 :         right = -1;
     967             :     }
     968          16 :     pFooterStyle->SetMargins( left, right, GetMarginsValue(MARGIN_TOP));
     969             : 
     970             :     //Word Pro has no dynamic spacing, should be set to false
     971          16 :     pFooterStyle->SetDynamicSpace(false);
     972          16 : }
     973             : 
     974          16 : void LwpFooterLayout::ParseBorder(XFFooterStyle* pFooterStyle)
     975             : {
     976          16 :     XFBorders* pBordres = GetXFBorders();
     977          16 :     if(pBordres)
     978             :     {
     979           0 :         pFooterStyle->SetBorders(pBordres);
     980             :     }
     981          16 : }
     982             : 
     983          16 : void LwpFooterLayout::ParseShadow(XFFooterStyle* pFooterStyle)
     984             : {
     985          16 :     XFShadow* pXFShadow = GetXFShadow();
     986          16 :     if(pXFShadow)
     987             :     {
     988           0 :         pFooterStyle->SetShadow(pXFShadow);
     989             :     }
     990          16 : }
     991             : /**
     992             : * @descr:   set footer back pattern
     993             : *
     994             : */
     995           0 : void LwpFooterLayout::ParsePatternFill(XFFooterStyle* pFooterStyle)
     996             : {
     997           0 :     XFBGImage* pXFBGImage = this->GetFillPattern();
     998           0 :     if (pXFBGImage)
     999             :     {
    1000           0 :         pFooterStyle->SetBackImage(pXFBGImage);
    1001             :     }
    1002           0 : }
    1003             : /**
    1004             : * @descr:   set footer background
    1005             : *
    1006             : */
    1007          16 : void LwpFooterLayout::ParseBackGround(XFFooterStyle* pFooterStyle)
    1008             : {
    1009          16 :     if (this->IsPatternFill())
    1010             :     {
    1011           0 :         ParsePatternFill(pFooterStyle);
    1012             :     }
    1013             :     else
    1014             :     {
    1015          16 :         ParseBackColor(pFooterStyle);
    1016             :     }
    1017          16 : }
    1018             : 
    1019          16 : void LwpFooterLayout::ParseBackColor(XFFooterStyle* pFooterStyle)
    1020             : {
    1021          16 :     LwpColor* pColor = GetBackColor();
    1022          16 :     if(pColor)
    1023             :     {
    1024           0 :         pFooterStyle->SetBackColor(XFColor(pColor->To24Color()));
    1025             :     }
    1026          16 : }
    1027             : 
    1028          16 : void LwpFooterLayout::RegisterStyle(XFMasterPage* mp1)
    1029             : {
    1030          16 :     XFFooter* pFooter = new XFFooter();
    1031          16 :     rtl::Reference<LwpObject> pStory = m_Content.obj(VO_STORY);
    1032             :     //Call the RegisterStyle first to register the styles in footer paras, and then XFConvert()
    1033          16 :     if(pStory.is())
    1034             :     {
    1035          16 :         LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
    1036          16 :         LwpChangeMgr* pChangeMgr = pGlobal->GetLwpChangeMgr();
    1037          16 :         pChangeMgr->SetHeadFootFribMap(true);
    1038             : 
    1039          16 :         pStory->SetFoundry(m_pFoundry);
    1040          16 :         pStory->RegisterStyle();
    1041             :         //, 06/27/2005
    1042             :         //register child layout style for framelayout,
    1043          16 :         RegisterChildStyle();
    1044             :         //End
    1045             : 
    1046          16 :         pChangeMgr->SetHeadFootChange(pFooter);//add by ,7/6
    1047             : 
    1048          16 :         pStory->XFConvert(pFooter);
    1049             : 
    1050          16 :         pChangeMgr->SetHeadFootFribMap(false);
    1051             :     }
    1052          16 :     mp1->SetFooter(pFooter);
    1053          16 : }
    1054             : 
    1055          16 : void LwpFooterLayout::ParseWaterMark(XFFooterStyle * pFooterStyle)
    1056             : {
    1057          16 :     XFBGImage* pXFBGImage = GetXFBGImage();
    1058          16 :     if(pXFBGImage)
    1059             :     {
    1060           0 :         pFooterStyle->SetBackImage(pXFBGImage);
    1061             :     }
    1062          22 : }
    1063             : //End by
    1064             : 
    1065             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10