LCOV - code coverage report
Current view: top level - lotuswordpro/source/filter - lwppagelayout.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 467 0.0 %
Date: 2014-04-14 Functions: 0 57 0.0 %
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           0 : LwpPageLayout::LwpPageLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
      80             :     : LwpLayout(objHdr, pStrm)
      81           0 :     , m_pPrinterBinName(new LwpAtomHolder)
      82             :     , m_nPrinterBin(0)
      83             :     , m_nBdroffset(0)
      84           0 :     , m_pPaperName(new LwpAtomHolder)
      85           0 :     , m_pXFPageMaster(NULL)
      86             : {
      87           0 : }
      88             : 
      89           0 : LwpPageLayout::~LwpPageLayout()
      90             : {
      91           0 :     if (m_pPrinterBinName)
      92             :     {
      93           0 :         delete m_pPrinterBinName;
      94             :     }
      95           0 :     if (m_pPaperName)
      96             :     {
      97           0 :         delete m_pPaperName;
      98             :     }
      99           0 : }
     100           0 : void LwpPageLayout::Read()
     101             : {
     102           0 :     LwpLayout::Read();
     103             : 
     104           0 :     if (LwpFileHeader::m_nFileRevision < 0x000B)
     105             :     {
     106             :         // read PreRevBLayout...
     107             :     }
     108             : 
     109           0 :     m_nPrinterBin = m_pObjStrm->QuickReaduInt16();
     110           0 :     m_pPrinterBinName->Read(m_pObjStrm);
     111             : 
     112           0 :     if (LwpFileHeader::m_nFileRevision >= 0x000B)
     113           0 :         m_nBdroffset = m_pObjStrm->QuickReadInt32();
     114             : 
     115           0 :     if (m_pObjStrm->CheckExtra())
     116             :     {
     117           0 :         m_pPaperName->Read(m_pObjStrm);
     118           0 :         m_pObjStrm->SkipExtra();
     119             :     }
     120             : 
     121           0 : }
     122             : 
     123           0 : void LwpPageLayout::Parse(IXFStream* pOutputStream)
     124             : {
     125             :     //Only parse this layout
     126           0 :     LwpObject* pStory = m_Content.obj();
     127           0 :     if(pStory)
     128             :     {
     129           0 :         pStory->SetFoundry(m_pFoundry);
     130           0 :         pStory->Parse(pOutputStream);   //Do not parse the next story
     131             :     }
     132           0 : }
     133             : 
     134             : /**
     135             : * @descr:   set page margins
     136             : *
     137             : */
     138           0 : void LwpPageLayout::ParseMargins(XFPageMaster* pm1)
     139             : {
     140           0 :     double fLeft    = GetMarginsValue(MARGIN_LEFT);
     141           0 :     double fRight   = GetMarginsValue(MARGIN_RIGHT);
     142           0 :     double fTop = GetMarginsValue(MARGIN_TOP);
     143           0 :     double fBottom  = GetMarginsValue(MARGIN_BOTTOM);
     144             : 
     145           0 :     pm1->SetMargins( fLeft, fRight, fTop, fBottom );
     146             : 
     147           0 : }
     148             : 
     149             : /**
     150             : * @descr:   set page height and width
     151             : *
     152             : */
     153           0 : 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           0 :     double fWidth =0;
     164           0 :     double fHeight = 0;
     165           0 :     GetWidthAndHeight(fWidth, fHeight);
     166           0 :     pm1->SetPageWidth( fWidth );
     167           0 :     pm1->SetPageHeight( fHeight );
     168           0 : }
     169             : 
     170             : /**
     171             : * @descr:   set page watermark
     172             : *
     173             : */
     174           0 : void LwpPageLayout::ParseWaterMark(XFPageMaster *pm1)
     175             : {
     176           0 :     XFBGImage* pXFBGImage = GetXFBGImage();
     177           0 :     if(pXFBGImage)
     178             :     {
     179           0 :         pm1->SetBackImage(pXFBGImage);
     180             :     }
     181           0 : }
     182             : 
     183             : /**
     184             : * @descr:   set page columns
     185             : *
     186             : */
     187           0 : void LwpPageLayout::ParseColumns(XFPageMaster * pm1)
     188             : {
     189           0 :     XFColumns* pColumns = GetXFColumns();
     190           0 :     if(pColumns)
     191             :     {
     192           0 :         pm1->SetColumns(pColumns);
     193             :     }
     194           0 : }
     195             : 
     196             : /**
     197             : * @descr:   set page borders
     198             : *
     199             : */
     200           0 : void LwpPageLayout::ParseBorders(XFPageMaster *pm1)
     201             : {
     202           0 :     XFBorders* pBordres = GetXFBorders();
     203           0 :     if(pBordres)
     204             :     {
     205           0 :         pm1->SetBorders(pBordres);
     206             :     }
     207           0 : }
     208             : 
     209             : /**
     210             : * @descr:   set page shadow
     211             : *
     212             : */
     213           0 : void LwpPageLayout::ParseShadow(XFPageMaster *pm1)
     214             : {
     215           0 :     XFShadow* pXFShadow = GetXFShadow();
     216           0 :     if(pXFShadow)
     217             :     {
     218           0 :         pm1->SetShadow(pXFShadow);
     219             :     }
     220           0 : }
     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           0 : void LwpPageLayout::ParseBackGround(XFPageMaster* pm1)
     239             : {
     240           0 :     if (this->IsPatternFill())
     241             :     {
     242           0 :         ParsePatternFill(pm1);
     243             :     }
     244             :     else
     245             :     {
     246           0 :         ParseBackColor(pm1);
     247             :     }
     248           0 : }
     249             : 
     250             : /**
     251             : * @descr:   set page back color
     252             : *
     253             : */
     254           0 : void LwpPageLayout::ParseBackColor(XFPageMaster* pm1)
     255             : {
     256           0 :     LwpColor* pColor = GetBackColor();
     257           0 :     if(pColor)
     258             :     {
     259           0 :         pm1->SetBackColor(XFColor(pColor->To24Color()));
     260             :     }
     261           0 : }
     262             : 
     263             : /**
     264             : * @descr:   set page footnote separator information
     265             : *
     266             : */
     267           0 : void LwpPageLayout::ParseFootNoteSeparator(XFPageMaster * pm1)
     268             : {
     269             :     //Get the footnoteoptions for the root document
     270           0 :     LwpDocument* pDocument = m_pFoundry->GetDocument();
     271           0 :     if(pDocument)
     272             :     {
     273           0 :         LwpObjectID* pFontnodeId = pDocument->GetValidFootnoteOpts();
     274             : 
     275           0 :         LwpFootnoteOptions* pFootnoteOpts = pFontnodeId ? dynamic_cast<LwpFootnoteOptions*>(pFontnodeId->obj()) : NULL;
     276           0 :         if(pFootnoteOpts)
     277             :         {
     278           0 :             LwpFootnoteSeparatorOptions* pFootnoteSep = pFootnoteOpts->GetFootnoteSeparator();
     279             :             //set length
     280           0 :             sal_uInt32 nLengthPercent = 100;
     281           0 :             double fWidth = 0;
     282           0 :             if(pFootnoteSep->HasSeparator())
     283             :             {
     284           0 :                 fWidth = pFootnoteSep->GetTopBorderWidth();
     285             :             }
     286           0 :             if(pFootnoteSep->HasCustomLength())
     287             :             {
     288           0 :                 nLengthPercent =  static_cast<sal_uInt32>(100*LwpTools::ConvertFromUnitsToMetric(pFootnoteSep->GetLength())/GetMarginWidth());
     289           0 :                 if(nLengthPercent > 100)
     290           0 :                     nLengthPercent = 100;
     291             :             }
     292           0 :             double fAbove = LwpTools::ConvertFromUnitsToMetric(pFootnoteSep->GetAbove());
     293           0 :             double fBelow = LwpTools::ConvertFromUnitsToMetric(pFootnoteSep->GetBelow());
     294           0 :             LwpColor aColor = pFootnoteSep->GetTopBorderColor();
     295           0 :             enumXFAlignType eAlignType = enumXFAlignStart;
     296           0 :             if(pFootnoteSep->GetIndent() > 0)
     297             :             {
     298             :                 //SODC don't support indent
     299           0 :                 sal_uInt32 nIndentPercent =  static_cast<sal_uInt32>(100*LwpTools::ConvertFromUnitsToMetric(pFootnoteSep->GetIndent())/GetMarginWidth());
     300           0 :                 if(nIndentPercent + nLengthPercent >= 100)
     301           0 :                     eAlignType = enumXFAlignEnd;
     302             :             }
     303           0 :             if(aColor.IsValidColor())
     304             :             {
     305           0 :                 XFColor aXFColor(aColor.To24Color());
     306           0 :                 pm1->SetFootNoteSeparator(eAlignType,fWidth, nLengthPercent, fAbove, fBelow, aXFColor);
     307           0 :             }
     308             :         }
     309             :     }
     310           0 : }
     311             : 
     312             : /**
     313             : * @descr:   Register master page and page master style
     314             : *
     315             : */
     316           0 : void LwpPageLayout::RegisterStyle()
     317             : {
     318           0 :     XFPageMaster* pm1 = new XFPageMaster();
     319           0 :     m_pXFPageMaster = pm1;
     320             : 
     321           0 :     ParseGeometry( pm1 );
     322             :     //Does not process LayoutScale, for watermark is not supported in SODC.
     323           0 :     ParseWaterMark( pm1);
     324           0 :     ParseMargins( pm1);
     325           0 :     ParseColumns(pm1);
     326           0 :     ParseBorders(pm1);
     327           0 :     ParseShadow(pm1);
     328             : //  ParseBackColor(pm1);
     329           0 :     ParseBackGround(pm1);
     330           0 :     ParseFootNoteSeparator(pm1);
     331           0 :     pm1->SetTextDir(GetTextDirection());
     332             : 
     333           0 :     LwpUseWhen* pUseWhen = GetUseWhen();
     334           0 :     if(IsComplex() ||( pUseWhen && pUseWhen->IsUseOnAllOddPages()))
     335             :     {
     336           0 :         pm1->SetPageUsage(enumXFPageUsageMirror);
     337             :     }
     338             : 
     339             :     //Add the page master to stylemanager
     340           0 :     XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
     341           0 :     m_pXFPageMaster = pm1 = (XFPageMaster*)pXFStyleManager->AddStyle(pm1);
     342           0 :     OUString pmname = pm1->GetStyleName();
     343             : 
     344             :     //Add master page
     345           0 :     XFMasterPage* mp1 = new XFMasterPage();
     346           0 :     mp1->SetStyleName(GetName()->str());
     347           0 :     mp1->SetPageMaster(pmname);
     348           0 :     mp1 = (XFMasterPage*)pXFStyleManager->AddStyle(mp1);
     349           0 :     m_StyleName = mp1->GetStyleName();
     350             : 
     351             :     //Set footer style
     352           0 :     LwpFooterLayout* pLayoutFooter = GetFooterLayout();
     353           0 :     if(pLayoutFooter)
     354             :     {
     355           0 :         pLayoutFooter->SetFoundry(m_pFoundry);
     356           0 :         pLayoutFooter->RegisterStyle(pm1);
     357           0 :         pLayoutFooter->RegisterStyle(mp1);
     358             :     }
     359             : 
     360             :     //Set header style
     361           0 :     LwpHeaderLayout* pLayoutHeader = GetHeaderLayout();
     362           0 :     if(pLayoutHeader)
     363             :     {
     364           0 :         pLayoutHeader->SetFoundry(m_pFoundry);
     365           0 :         pLayoutHeader->RegisterStyle(pm1);
     366           0 :         pLayoutHeader->RegisterStyle(mp1);
     367             :     }
     368             :     //register child layout style for mirror page and frame
     369           0 :     RegisterChildStyle();
     370           0 : }
     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 = (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           0 : sal_Bool LwpPageLayout::HasColumns()
     433             : {
     434           0 :     return GetNumCols() > 1 ? sal_True : sal_False;
     435             : }
     436             : 
     437             : /**
     438             : * @descr:   Whether has filler page text in current page layout
     439             : *
     440             : */
     441           0 : sal_Bool LwpPageLayout::HasFillerPageText(LwpFoundry* pFoundry)
     442             : {
     443           0 :     if(!pFoundry) return sal_False;
     444             : 
     445           0 :     sal_Bool bFillerPage = sal_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 = sal_True;
     460             :             }
     461           0 :             else if((eWhenType==LwpLayout::StartOnEvenPage)&&(LwpTools::IsEvenNumber(nPageNumber)))
     462             :             {
     463           0 :                 bFillerPage = sal_True;
     464             :             }
     465             :             else
     466             :             {
     467           0 :                 bFillerPage = sal_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());
     486           0 :         LwpStory* pStory = dynamic_cast<LwpStory*>(pDivInfo->GetFillerPageTextID()->obj());
     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           0 : LwpHeaderLayout* LwpPageLayout::GetHeaderLayout()
     508             : {
     509           0 :     LwpVirtualLayout* pLay = dynamic_cast<LwpVirtualLayout*>(GetChildHead()->obj());
     510           0 :     while(pLay)
     511             :     {
     512           0 :         if( pLay->GetLayoutType() == LWP_HEADER_LAYOUT )
     513           0 :             return ( static_cast<LwpHeaderLayout*> (pLay) );
     514           0 :         pLay = dynamic_cast<LwpVirtualLayout*> (pLay->GetNext()->obj());
     515             :     }
     516           0 :     return NULL;
     517             : }
     518             : 
     519           0 : LwpFooterLayout* LwpPageLayout::GetFooterLayout()
     520             : {
     521           0 :     LwpVirtualLayout* pLay = dynamic_cast<LwpVirtualLayout*>(GetChildHead()->obj());
     522           0 :     while(pLay)
     523             :     {
     524           0 :         if( pLay->GetLayoutType() == LWP_FOOTER_LAYOUT )
     525           0 :             return ( static_cast<LwpFooterLayout*> (pLay) );
     526           0 :         pLay = dynamic_cast<LwpVirtualLayout*> (pLay->GetNext()->obj());
     527             :     }
     528           0 :     return NULL;
     529             : }
     530             : 
     531             : /**
     532             : * @descr:   Get the odd layout if current page layout is mirror page
     533             : *
     534             : */
     535           0 : LwpPageLayout* LwpPageLayout::GetOddChildLayout()
     536             : {
     537           0 :     if(IsComplex())
     538             :     {
     539           0 :         LwpVirtualLayout* pLay = dynamic_cast<LwpVirtualLayout*>(GetChildHead()->obj());
     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());
     552             :         }
     553             :     }
     554           0 :     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());
     584           0 :     if(!pHeadTail) return nPageNumber;
     585             : 
     586             :     //get first pagehint
     587           0 :     LwpPageHint* pPageHint = dynamic_cast<LwpPageHint*>(pHeadTail->GetHead()->obj());
     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());
     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           0 : void LwpPageLayout::GetWidthAndHeight(double& fWidth, double& fHeight)
     631             : {
     632             :     //use customized size
     633           0 :     LwpLayoutGeometry* pLayoutGeo = GetGeometry();
     634           0 :     if(pLayoutGeo)
     635             :     {
     636           0 :         fWidth = GetGeometryWidth();
     637           0 :         fHeight = GetGeometryHeight();
     638             :     }
     639             : 
     640           0 :     if(GetUsePrinterSettings())
     641             :     {
     642             :         //replaced by printer paper size
     643           0 :         Printer aPrinter;
     644           0 :         sal_Bool bScreen = aPrinter.IsDisplayPrinter();
     645           0 :         if (!bScreen)//Printer available
     646             :         {
     647           0 :             Size aPaperSize = aPrinter.GetPaperSize();
     648           0 :             aPaperSize = aPrinter.PixelToLogic( aPaperSize, MapMode( MAP_10TH_MM ) );
     649           0 :             fWidth = static_cast<double>(aPaperSize.Width())/100;   //cm unit
     650           0 :             fHeight = static_cast<double>(aPaperSize.Height())/100;
     651           0 :         }
     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           0 :     if (fWidth < 4.39)
     658           0 :         fWidth = 21.59;
     659           0 :     if (fHeight < 4.49)
     660           0 :         fHeight = 27.94;
     661             :     //End of modification, by ZF
     662           0 : }
     663             : 
     664             : /**
     665             : * @descr:   Get page width
     666             : *
     667             : */
     668           0 : double LwpPageLayout::GetWidth()
     669             : {
     670           0 :     double fWidth =0, fHeight = 0;
     671           0 :     GetWidthAndHeight(fWidth, fHeight);
     672           0 :     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 : sal_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 sal_True;
     708             : 
     709           0 :     return sal_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());
     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());
     730             :         }
     731             :     }
     732             : 
     733           0 :     return NULL;
     734             : }
     735           0 : LwpHeaderLayout::LwpHeaderLayout( LwpObjectHeader &objHdr, LwpSvStream* pStrm )
     736             :     : LwpPlacableLayout(objHdr, pStrm)
     737           0 :     , m_nBorderOffset(0)
     738             : {
     739           0 : }
     740             : 
     741           0 : LwpHeaderLayout::~LwpHeaderLayout()
     742             : {
     743           0 : }
     744             : 
     745           0 : void LwpHeaderLayout::Read()
     746             : {
     747           0 :     LwpPlacableLayout::Read();
     748             : 
     749           0 :     if(LwpFileHeader::m_nFileRevision >= 0x000E)
     750           0 :         m_nBorderOffset = m_pObjStrm->QuickReadInt32();
     751             :     else
     752           0 :         m_nBorderOffset = 0;
     753           0 :     m_pObjStrm->SkipExtra();
     754           0 : }
     755             : 
     756           0 : void LwpHeaderLayout::RegisterStyle(XFPageMaster* pm1)
     757             : {
     758           0 :     XFHeaderStyle* pHeaderStyle = new XFHeaderStyle();
     759             : 
     760             :     //Modify page top margin
     761             :     //page top maring: from top of header to the top edge
     762           0 :     double top = GetMarginsValue(MARGIN_TOP);
     763           0 :     pm1->SetMargins(-1, -1, top, -1);
     764             : 
     765           0 :     ParseMargins(pHeaderStyle);
     766           0 :     ParseBorder(pHeaderStyle);
     767           0 :     ParseShadow(pHeaderStyle);
     768             : //  ParseBackColor(pHeaderStyle);
     769           0 :     ParseBackGround(pHeaderStyle);
     770             : 
     771           0 :     ParseWaterMark(pHeaderStyle);
     772             :     //End by
     773             : 
     774           0 :     pm1->SetHeaderStyle(pHeaderStyle);
     775           0 : }
     776             : 
     777           0 : 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           0 :     double height = GetGeometryHeight()- GetMarginsValue(MARGIN_TOP);
     781           0 :     if( IsAutoGrowDown() )
     782             :     {
     783           0 :         ph1->SetMinHeight(height);
     784             :     }
     785             :     else
     786             :     {
     787           0 :         ph1->SetHeight(height);
     788             :     }
     789             : 
     790             :     //Set left,right,bottom margins
     791           0 :     LwpMiddleLayout* parent = dynamic_cast<LwpMiddleLayout*> (GetParent()->obj());
     792             :     //left margin in SODC: the space from the left edge of body to the left edge of header
     793           0 :     double left = GetMarginsValue(MARGIN_LEFT) - (parent ? parent->GetMarginsValue(MARGIN_LEFT) : 0);
     794           0 :     if(left<=0) //The left margin in SODC can not be minus value
     795             :     {
     796           0 :         left = -1;
     797             :     }
     798             :     //left margin in SODC: the space from the right edge of header to the right edge of body
     799           0 :     double right = GetMarginsValue(MARGIN_RIGHT) - (parent ? parent->GetMarginsValue(MARGIN_RIGHT) : 0);
     800           0 :     if(right<=0)//The right margin in SODC can not be minus value
     801             :     {
     802           0 :         right = -1;
     803             :     }
     804           0 :     ph1->SetMargins( left, right, GetMarginsValue(MARGIN_BOTTOM));
     805             : 
     806             :     //Word Pro has no dynamic spacing, should be set to false
     807           0 :     ph1->SetDynamicSpace(sal_False);
     808           0 : }
     809             : 
     810           0 : void LwpHeaderLayout::ParseBorder(XFHeaderStyle* pHeaderStyle)
     811             : {
     812           0 :     XFBorders* pBordres = GetXFBorders();
     813           0 :     if(pBordres)
     814             :     {
     815           0 :         pHeaderStyle->SetBorders(pBordres);
     816             :     }
     817           0 : }
     818             : 
     819           0 : void LwpHeaderLayout::ParseShadow(XFHeaderStyle* pHeaderStyle)
     820             : {
     821           0 :     XFShadow* pXFShadow = GetXFShadow();
     822           0 :     if(pXFShadow)
     823             :     {
     824           0 :         pHeaderStyle->SetShadow(pXFShadow);
     825             :     }
     826           0 : }
     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           0 : void LwpHeaderLayout::ParseBackGround(XFHeaderStyle* pHeaderStyle)
     845             : {
     846           0 :     if (this->IsPatternFill())
     847             :     {
     848           0 :         ParsePatternFill(pHeaderStyle);
     849             :     }
     850             :     else
     851             :     {
     852           0 :         ParseBackColor(pHeaderStyle);
     853             :     }
     854           0 : }
     855             : 
     856           0 : void LwpHeaderLayout::ParseBackColor(XFHeaderStyle* pHeaderStyle)
     857             : {
     858           0 :     LwpColor* pColor = GetBackColor();
     859           0 :     if(pColor)
     860             :     {
     861           0 :         pHeaderStyle->SetBackColor(XFColor(pColor->To24Color()));
     862             :     }
     863           0 : }
     864             : 
     865           0 : void LwpHeaderLayout::ParseWaterMark(XFHeaderStyle * pHeaderStyle)
     866             : {
     867           0 :     XFBGImage* pXFBGImage = GetXFBGImage();
     868           0 :     if(pXFBGImage)
     869             :     {
     870           0 :         pHeaderStyle->SetBackImage(pXFBGImage);
     871             :     }
     872           0 : }
     873             : //End by
     874             : 
     875           0 : void LwpHeaderLayout::RegisterStyle(XFMasterPage* mp1)
     876             : {
     877           0 :     XFHeader* pHeader = new XFHeader();
     878           0 :     LwpObject* pStory = m_Content.obj();
     879           0 :     if(pStory)
     880             :     {
     881           0 :         LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
     882           0 :         LwpChangeMgr* pChangeMgr = pGlobal->GetLwpChangeMgr();
     883           0 :         pChangeMgr->SetHeadFootFribMap(sal_True);
     884             : 
     885             :         //Call the RegisterStyle first to register the styles in header paras, and then XFConvert()
     886           0 :         pStory->SetFoundry(m_pFoundry);
     887           0 :         pStory->RegisterStyle();
     888             :         //, 06/27/2005
     889             :         //register child layout style for framelayout,
     890           0 :         RegisterChildStyle();
     891             :         //End
     892           0 :         pChangeMgr->SetHeadFootChange(pHeader);
     893           0 :         pStory->XFConvert(pHeader);
     894             : 
     895           0 :         pChangeMgr->SetHeadFootFribMap(sal_False);
     896             :     }
     897           0 :     mp1->SetHeader(pHeader);
     898           0 : }
     899             : 
     900           0 : LwpFooterLayout::LwpFooterLayout( LwpObjectHeader &objHdr, LwpSvStream* pStrm )
     901             :     : LwpPlacableLayout( objHdr, pStrm )
     902           0 :     , m_nBorderOffset(0)
     903             : {
     904           0 : }
     905             : 
     906           0 : LwpFooterLayout::~LwpFooterLayout()
     907             : {
     908           0 : }
     909             : 
     910           0 : void LwpFooterLayout::Read()
     911             : {
     912           0 :     LwpPlacableLayout::Read();
     913             : 
     914           0 :     if(LwpFileHeader::m_nFileRevision >= 0x000E)
     915           0 :         m_nBorderOffset = m_pObjStrm->QuickReadInt32();
     916             :     else
     917           0 :         m_nBorderOffset = 0;
     918           0 :     m_pObjStrm->SkipExtra();
     919           0 : }
     920             : 
     921           0 : void LwpFooterLayout::RegisterStyle(XFPageMaster* pm1)
     922             : {
     923           0 :     XFFooterStyle* pFooterStyle = new XFFooterStyle();
     924             : 
     925             :     //Modify page bottom margin
     926             :     //page bottom maring: from bottom of footer to the bottom edge
     927           0 :     double bottom = GetMarginsValue(MARGIN_BOTTOM);
     928           0 :     pm1->SetMargins(-1, -1, -1, bottom);
     929             : 
     930           0 :     ParseMargins(pFooterStyle);
     931           0 :     ParseBorder(pFooterStyle);
     932           0 :     ParseShadow(pFooterStyle);
     933           0 :     ParseBackGround(pFooterStyle);
     934             : //  ParseBackColor(pFooterStyle);
     935             : 
     936           0 :     ParseWaterMark(pFooterStyle);
     937             :     //End by
     938             : 
     939           0 :     pm1->SetFooterStyle(pFooterStyle);
     940           0 : }
     941             : 
     942           0 : 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           0 :     double height = GetGeometryHeight() - GetMarginsValue(MARGIN_BOTTOM);
     947           0 :     if( IsAutoGrowUp() )
     948             :     {
     949           0 :         pFooterStyle->SetMinHeight(height);
     950             :     }
     951             :     else
     952             :     {
     953           0 :         pFooterStyle->SetHeight(height);
     954             :     }
     955             : 
     956             :     //Set left,right,top margins
     957           0 :     LwpMiddleLayout* parent = dynamic_cast<LwpMiddleLayout*> (GetParent()->obj());
     958           0 :     double left = GetMarginsValue(MARGIN_LEFT) - (parent ? parent->GetMarginsValue(MARGIN_LEFT) : 0);
     959           0 :     if(left<=0) //The left margin in SODC can not be minus value
     960             :     {
     961           0 :         left = -1;
     962             :     }
     963           0 :     double right = GetMarginsValue(MARGIN_RIGHT) - (parent ? parent->GetMarginsValue(MARGIN_RIGHT) : 0);
     964           0 :     if(right<=0)//The left margin in SODC can not be minus value
     965             :     {
     966           0 :         right = -1;
     967             :     }
     968           0 :     pFooterStyle->SetMargins( left, right, GetMarginsValue(MARGIN_TOP));
     969             : 
     970             :     //Word Pro has no dynamic spacing, should be set to false
     971           0 :     pFooterStyle->SetDynamicSpace(sal_False);
     972           0 : }
     973             : 
     974           0 : void LwpFooterLayout::ParseBorder(XFFooterStyle* pFooterStyle)
     975             : {
     976           0 :     XFBorders* pBordres = GetXFBorders();
     977           0 :     if(pBordres)
     978             :     {
     979           0 :         pFooterStyle->SetBorders(pBordres);
     980             :     }
     981           0 : }
     982             : 
     983           0 : void LwpFooterLayout::ParseShadow(XFFooterStyle* pFooterStyle)
     984             : {
     985           0 :     XFShadow* pXFShadow = GetXFShadow();
     986           0 :     if(pXFShadow)
     987             :     {
     988           0 :         pFooterStyle->SetShadow(pXFShadow);
     989             :     }
     990           0 : }
     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           0 : void LwpFooterLayout::ParseBackGround(XFFooterStyle* pFooterStyle)
    1008             : {
    1009           0 :     if (this->IsPatternFill())
    1010             :     {
    1011           0 :         ParsePatternFill(pFooterStyle);
    1012             :     }
    1013             :     else
    1014             :     {
    1015           0 :         ParseBackColor(pFooterStyle);
    1016             :     }
    1017           0 : }
    1018             : 
    1019           0 : void LwpFooterLayout::ParseBackColor(XFFooterStyle* pFooterStyle)
    1020             : {
    1021           0 :     LwpColor* pColor = GetBackColor();
    1022           0 :     if(pColor)
    1023             :     {
    1024           0 :         pFooterStyle->SetBackColor(XFColor(pColor->To24Color()));
    1025             :     }
    1026           0 : }
    1027             : 
    1028           0 : void LwpFooterLayout::RegisterStyle(XFMasterPage* mp1)
    1029             : {
    1030           0 :     XFFooter* pFooter = new XFFooter();
    1031           0 :     LwpObject* pStory = m_Content.obj(VO_STORY);
    1032             :     //Call the RegisterStyle first to register the styles in footer paras, and then XFConvert()
    1033           0 :     if(pStory)
    1034             :     {
    1035           0 :         LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
    1036           0 :         LwpChangeMgr* pChangeMgr = pGlobal->GetLwpChangeMgr();
    1037           0 :         pChangeMgr->SetHeadFootFribMap(sal_True);
    1038             : 
    1039           0 :         pStory->SetFoundry(m_pFoundry);
    1040           0 :         pStory->RegisterStyle();
    1041             :         //, 06/27/2005
    1042             :         //register child layout style for framelayout,
    1043           0 :         RegisterChildStyle();
    1044             :         //End
    1045             : 
    1046           0 :         pChangeMgr->SetHeadFootChange(pFooter);//add by ,7/6
    1047             : 
    1048           0 :         pStory->XFConvert(pFooter);
    1049             : 
    1050           0 :         pChangeMgr->SetHeadFootFribMap(sal_False);
    1051             :     }
    1052           0 :     mp1->SetFooter(pFooter);
    1053           0 : }
    1054             : 
    1055           0 : void LwpFooterLayout::ParseWaterMark(XFFooterStyle * pFooterStyle)
    1056             : {
    1057           0 :     XFBGImage* pXFBGImage = GetXFBGImage();
    1058           0 :     if(pXFBGImage)
    1059             :     {
    1060           0 :         pFooterStyle->SetBackImage(pXFBGImage);
    1061             :     }
    1062           0 : }
    1063             : //End by
    1064             : 
    1065             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10