LCOV - code coverage report
Current view: top level - libreoffice/lotuswordpro/source/filter - lwpdoc.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 258 361 71.5 %
Date: 2012-12-27 Functions: 36 43 83.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             : #include "lwpglobalmgr.hxx"
      57             : #include "lwpdoc.hxx"
      58             : #include "lwpfootnote.hxx"
      59             : #include "lwppagehint.hxx"
      60             : #include "lwpdivinfo.hxx"
      61             : #include "lwpholder.hxx"
      62             : #include "lwpparastyle.hxx"
      63             : #include "lwpstory.hxx"
      64             : #include "lwppara.hxx"
      65             : #include "lwpsilverbullet.hxx"
      66             : #include "lwplayout.hxx"
      67             : #include "lwppagelayout.hxx"
      68             : #include "xfilter/xfstylemanager.hxx"
      69             : #include <osl/thread.h>
      70             : 
      71          10 : LwpDocument::LwpDocument(LwpObjectHeader& objHdr, LwpSvStream* pStrm)
      72          10 :     : LwpDLNFPVList(objHdr, pStrm), m_pOwnedFoundry(NULL), m_pLnOpts(NULL)
      73           9 : {}
      74             : 
      75          24 : LwpDocument::~LwpDocument()
      76             : {
      77           8 :     if(m_pLnOpts)
      78             :     {
      79           8 :         delete m_pLnOpts;
      80             :     }
      81           8 :     if(m_pOwnedFoundry)
      82             :     {
      83           8 :         delete m_pOwnedFoundry;
      84             :     }
      85          16 : }
      86             : /**
      87             :  * @descr   Read VO_Document from object stream
      88             :  **/
      89           9 : void LwpDocument::Read()
      90             : {
      91           9 :     LwpDLNFPVList::Read();
      92             : 
      93           9 :     ReadPlug();
      94             : 
      95           9 :     m_nPersistentFlags = m_pObjStrm->QuickReaduInt32();
      96             : 
      97             :     //Skip the SortOption and UIDocument
      98             :     {
      99           9 :         LwpSortOption m_DocSort( m_pObjStrm );
     100           9 :         LwpUIDocument m_UIDoc( m_pObjStrm );
     101             :     }
     102             : 
     103           9 :     m_pLnOpts = new LwpLineNumberOptions(m_pObjStrm);
     104             : 
     105             :     //Skip LwpUserDictFiles
     106             :     {
     107           9 :         LwpUserDictFiles m_UsrDicts( m_pObjStrm );
     108             :     }
     109             : 
     110           9 :     if( !IsChildDoc())
     111             :     {
     112             :         //Skip LwpPrinterInfo
     113           5 :         LwpPrinterInfo m_PrtInfo( m_pObjStrm );
     114             :     }
     115             : 
     116           9 :     m_pFoundry = m_pOwnedFoundry = new LwpFoundry(m_pObjStrm, this);
     117             : 
     118           9 :     m_DivOpts.ReadIndexed(m_pObjStrm);
     119             : 
     120           9 :     if(!IsChildDoc())
     121             :     {
     122           5 :         m_FootnoteOpts.ReadIndexed(m_pObjStrm);
     123           5 :         m_DocData.ReadIndexed(m_pObjStrm);
     124             :     }
     125             :     else
     126             :     {
     127             :         //Skip the docdata used in old version
     128           4 :         LwpObjectID dummyDocData;
     129           4 :         dummyDocData.ReadIndexed(m_pObjStrm);
     130             :     }
     131           9 :     m_DivInfo.ReadIndexed(m_pObjStrm);
     132           9 :     m_Epoch.Read(m_pObjStrm);
     133           9 :     m_WYSIWYGPageHints.ReadIndexed(m_pObjStrm);
     134           8 :     m_VerDoc.ReadIndexed(m_pObjStrm);
     135           8 :     m_STXInfo.ReadIndexed(m_pObjStrm);
     136           8 : }
     137             : 
     138             : /**
     139             :  * @descr   Read plug related data from m_pObjStram
     140             :  **/
     141           9 : void LwpDocument::ReadPlug()
     142             : {
     143           9 :     m_DocSockID.ReadIndexed(m_pObjStrm);
     144           9 :     m_nFlags = m_pObjStrm->QuickReaduInt16();
     145           9 :     m_pObjStrm->SkipExtra();
     146           9 : }
     147             : 
     148             : /**
     149             :  * @descr   Parse obj to IXFStream
     150             :  **/
     151           6 : void LwpDocument::Parse(IXFStream* pOutputStream)
     152             : {
     153             :     //check the name and skip script division
     154           6 :     if (!IsSkippedDivision())
     155             :     {
     156             :         //the frames which anchor are to page must output before other contents
     157           6 :         ParseFrameInPage(pOutputStream);
     158           6 :         ParseDocContent(pOutputStream);
     159             :     }
     160             : 
     161           6 :     LwpObject* pDocSock = GetSocket()->obj( VO_DOCSOCK );
     162           6 :     if(pDocSock!=NULL)
     163             :     {
     164           6 :         pDocSock->Parse(pOutputStream);
     165             :     }
     166           6 : }
     167             : 
     168           6 : sal_Bool LwpDocument::IsSkippedDivision()
     169             : {
     170           6 :     OUString sDivName;
     171           6 :     sal_uInt8 ret = sal_False;
     172           6 :     LwpDivInfo* pDiv = dynamic_cast<LwpDivInfo*>(GetDivInfoID()->obj(VO_DIVISIONINFO));
     173           6 :     if (pDiv == NULL)
     174           0 :         return sal_True;
     175           6 :     sDivName = pDiv->GetDivName();
     176           6 :     if (!sDivName.isEmpty() && !pDiv->IsGotoable()) //including toa,scripts division
     177           0 :         return sal_True;
     178             :     //skip endnote division
     179           6 :     OUString strClassName = pDiv->GetClassName();
     180          36 :     if (strClassName.equals(A2OUSTR(STR_DivisionEndnote))
     181          18 :         || strClassName.equals(A2OUSTR(STR_DivisionGroupEndnote))
     182          18 :         || strClassName.equals(A2OUSTR(STR_DocumentEndnote)))
     183             :     {
     184           0 :         LwpPageLayout* pPageLayout = dynamic_cast<LwpPageLayout*>(pDiv->GetInitialLayoutID()->obj(VO_PAGELAYOUT));
     185           0 :         if(pPageLayout)
     186             :         {
     187           0 :             LwpStory* pStory = dynamic_cast<LwpStory*>(pPageLayout->GetContent()->obj(VO_STORY));
     188           0 :             if(pStory)
     189             :             {
     190             :                 //This judgement maybe have problem. If there is only one para in the story,
     191             :                 //this endnote division has no other contents except endnote table.
     192           0 :                 LwpObjectID* pFirst = pStory->GetFirstPara();
     193           0 :                 LwpObjectID* pLast = pStory->GetLastPara();
     194           0 :                 if(*pFirst == *pLast)
     195           0 :                     ret = sal_True;
     196             :             }
     197             :         }
     198             :     }
     199           6 :     return ret;
     200             : }
     201             : 
     202             : /**
     203             :  * @descr  Register all styles in this division
     204             :  */
     205           8 : void LwpDocument::RegisterStyle()
     206             : {
     207           8 :     RegisterDefaultParaStyles();
     208           8 :     RegisterGraphicsStyles();
     209           8 :     RegisterBulletStyles();
     210             : 
     211           8 :     RegisterTextStyles();
     212           8 :     RegisterLayoutStyles();
     213           8 :     RegisterStylesInPara();
     214             : 
     215           7 :     RegisterLinenumberStyles();
     216           7 :     RegisterFootnoteStyles();
     217             : 
     218             :     //Register styles in other document connected with this document: next doc, children doc
     219           7 :     LwpObject* pDocSock = GetSocket()->obj();
     220           7 :     if(pDocSock!=NULL)
     221             :     {
     222           7 :         pDocSock->RegisterStyle();
     223             :     }
     224           6 : }
     225             : /**
     226             :  * @descr  Register all named para styles
     227             :  */
     228           8 : void LwpDocument::RegisterTextStyles()
     229             : {
     230             :     //Register all text styles: para styles, character styles
     231           8 :     LwpDLVListHeadHolder* pParaStyleHolder = dynamic_cast<LwpDLVListHeadHolder*>(m_pFoundry->GetTextStyleHead()->obj());
     232           8 :     if(pParaStyleHolder)
     233             :     {
     234           8 :         LwpTextStyle* pParaStyle = dynamic_cast<LwpTextStyle*> (pParaStyleHolder->GetHeadID()->obj());
     235          84 :         while(pParaStyle)
     236             :         {
     237          68 :             pParaStyle->SetFoundry(m_pFoundry);
     238          68 :             pParaStyle->RegisterStyle();
     239          68 :             pParaStyle = dynamic_cast<LwpParaStyle*>(pParaStyle->GetNext()->obj());
     240             :         }
     241             :     }
     242           8 :     ChangeStyleName();//add by ,for click here block,05/5/26
     243           8 : }
     244             : /**
     245             :  * @descr  Register all layouts styles (page master and master page)
     246             :  *       All para styles used in master page (header and footer) are registered and then showed
     247             :  */
     248           8 : void LwpDocument::RegisterLayoutStyles()
     249             : {
     250             :     //Register all layout styles, before register all styles in para
     251           8 :     m_pFoundry->RegisterAllLayouts();
     252             : 
     253             :     //set initial pagelayout in story for parsing pagelayout
     254           8 :     LwpDivInfo* pDivInfo = dynamic_cast<LwpDivInfo*> (m_DivInfo.obj( VO_DIVISIONINFO));
     255           8 :     LwpPageLayout* pPageLayout = NULL;
     256           8 :     if(pDivInfo)
     257             :     {
     258           8 :         pPageLayout = dynamic_cast<LwpPageLayout*>(pDivInfo->GetInitialLayoutID()->obj(VO_PAGELAYOUT));
     259           8 :         if(pPageLayout)
     260             :         {
     261             :             //In Ole division, the content of pagelayout is VO_OLEOBJECT
     262           4 :             LwpStory* pStory = dynamic_cast<LwpStory*>(pPageLayout->GetContent()->obj(VO_STORY));
     263           4 :             if(pStory)
     264             :             {
     265             :                 //add all the pagelayout in order into the pagelayout list;
     266           4 :                 pStory->SortPageLayout();
     267           4 :                 pStory->SetCurrentLayout(pPageLayout);
     268             :             }
     269             :         }
     270             :     }
     271           8 : }
     272             : /**
     273             :  * @descr  Register all styles used in para
     274             :  */
     275           8 : void LwpDocument::RegisterStylesInPara()
     276             : {
     277             :     //Register all automatic styles in para
     278           8 :     LwpHeadContent* pContent = dynamic_cast<LwpHeadContent*> (m_pFoundry->GetContentManager()->GetContentList()->obj());
     279           8 :     if(pContent)
     280             :     {
     281           8 :         LwpStory* pStory = dynamic_cast<LwpStory*>(pContent->GetChildHead()->obj(VO_STORY));
     282          55 :         while(pStory)
     283             :         {
     284             :             //Register the child para
     285          40 :             pStory->SetFoundry(m_pFoundry);
     286          40 :             pStory->RegisterStyle();
     287          39 :             pStory = dynamic_cast<LwpStory*>(pStory->GetNext()->obj(VO_STORY));
     288             :         }
     289             :     }
     290           7 : }
     291             : /**
     292             :  * @descr  Register all bullet styles used in this division
     293             :  */
     294           8 : void LwpDocument::RegisterBulletStyles()
     295             : {
     296             :     //Register bullet styles
     297             :     LwpDLVListHeadHolder* mBulletHead = dynamic_cast<LwpDLVListHeadHolder*>
     298           8 :                 (m_pFoundry->GetBulletManagerID()->obj(VO_HEADHOLDER));
     299           8 :     if( mBulletHead )
     300             :     {
     301             :         LwpSilverBullet* pBullet = dynamic_cast<LwpSilverBullet*>
     302           8 :                             (mBulletHead->GetHeadID()->obj());
     303          29 :         while(pBullet)
     304             :         {
     305          13 :             pBullet->SetFoundry(m_pFoundry);
     306          13 :             pBullet->RegisterStyle();
     307          13 :             pBullet = dynamic_cast<LwpSilverBullet*> (pBullet->GetNext()->obj());
     308             :         }
     309             :     }
     310           8 : }
     311             : /**
     312             :  * @descr  Register all styles used in VO_Graphic
     313             :  */
     314           8 : void LwpDocument::RegisterGraphicsStyles()
     315             : {
     316             :     //Register all graphics styles, the first object should register the next;
     317           8 :     LwpObject* pGraphic = m_pFoundry->GetGraphicListHead()->obj(VO_GRAPHIC);
     318           8 :     if(pGraphic)
     319             :     {
     320           0 :         pGraphic->SetFoundry(m_pFoundry);
     321           0 :         pGraphic->RegisterStyle();
     322             :     }
     323           8 : }
     324             : /**
     325             :  * @descr  Register line number styles
     326             :  */
     327           7 : void LwpDocument::RegisterLinenumberStyles()
     328             : {
     329           7 :     if (!m_pLnOpts)
     330           7 :         return;
     331           7 :     m_pLnOpts->RegisterStyle();
     332             : }
     333             : 
     334             : /**
     335             : * @descr   Register footnote/endnote configuration for the entire document
     336             : */
     337           7 : void LwpDocument::RegisterFootnoteStyles()
     338             : {
     339             :     //Register footnote and endnote configuration for the entire document
     340           7 :     if(!m_FootnoteOpts.IsNull())
     341             :     {
     342           4 :         LwpFootnoteOptions* pFootnoteOpts = dynamic_cast<LwpFootnoteOptions*>(m_FootnoteOpts.obj());
     343           4 :         if (pFootnoteOpts)
     344             :         {
     345           4 :             pFootnoteOpts->SetMasterPage(A2OUSTR("Endnote"));
     346           4 :             pFootnoteOpts->RegisterStyle();
     347             :         }
     348             :     }
     349             :     //Register endnote page style for endnote configuration, use the last division that has endnote for the endnote page style
     350             :     //This page style must register after its division default styles have registered
     351           7 :     LwpDocument* pEndnoteDiv = GetLastDivisionThatHasEndnote();
     352           7 :     if(this == pEndnoteDiv)
     353             :     {
     354           0 :         LwpDLVListHeadTailHolder* pHeadTail = dynamic_cast<LwpDLVListHeadTailHolder*>(GetPageHintsID()->obj());
     355           0 :         if(pHeadTail)
     356             :         {
     357           0 :             LwpPageHint* pPageHint = dynamic_cast<LwpPageHint*>(pHeadTail->GetTail()->obj());
     358           0 :             if(pPageHint && !pPageHint->GetPageLayoutID()->IsNull())
     359             :             {
     360           0 :                 LwpPageLayout* pPageLayout = dynamic_cast<LwpPageLayout*>(pPageHint->GetPageLayoutID()->obj());
     361           0 :                 if(pPageLayout)
     362             :                 {
     363           0 :                     pPageLayout->SetFoundry(GetFoundry());
     364           0 :                     pPageLayout->RegisterEndnoteStyle();
     365             :                 }
     366             :             }
     367             :         }
     368             :     }
     369           7 : }
     370             : 
     371             : /**
     372             : * @descr   Register default para styles
     373             : */
     374             : #include "lwpverdocument.hxx"
     375           8 : void LwpDocument::RegisterDefaultParaStyles()
     376             : {
     377           8 :     if(!IsChildDoc())
     378             :     {
     379             :         //Get First Division
     380             :         //LwpDocument* pFirstDoc = GetFirstDivision();
     381           4 :         LwpDocument* pFirstDoc = GetFirstDivisionWithContentsThatIsNotOLE();
     382           4 :         if(pFirstDoc)
     383             :         {
     384           4 :             LwpVerDocument* pVerDoc = dynamic_cast<LwpVerDocument*>(pFirstDoc->GetVerDoc()->obj());
     385           4 :             if(pVerDoc)
     386             :             {
     387           4 :                 pVerDoc->RegisterStyle();
     388             :             }
     389             :         }
     390             : 
     391             :     }
     392           8 : }
     393             : 
     394             : /**
     395             :  * @descr  Parse content in this division to IXFStream
     396             :  * LwpDocument->LwpDivInfo->LwpPageLayout.Parse()
     397             :  */
     398           6 : void LwpDocument::ParseDocContent(IXFStream* pOutputStream)
     399             : {
     400             :     //Parse content in PageLayout
     401           6 :     LwpDivInfo* pDivInfo = dynamic_cast<LwpDivInfo*> (m_DivInfo.obj());
     402           6 :     if(pDivInfo==NULL) return;
     403             : 
     404           6 :     LwpObject* pLayoutObj = pDivInfo->GetInitialLayoutID()->obj();
     405           6 :     if(pLayoutObj==NULL)
     406             :     {
     407             :         //master document not supported now.
     408           3 :         return;
     409             :     }
     410           3 :     pLayoutObj->SetFoundry(m_pFoundry);
     411           3 :     pLayoutObj->Parse(pOutputStream);
     412             : }
     413             : 
     414             : /**
     415             :  * @descr    Get the footnoteoptions from the root document
     416             :  */
     417           8 : LwpObjectID* LwpDocument::GetValidFootnoteOpts()
     418             : {
     419           8 :     LwpDocument* pRoot = GetRootDocument();
     420           8 :     if(pRoot)
     421             :     {
     422           8 :         return pRoot->GetFootnoteOpts();
     423             :     }
     424           0 :     return NULL;
     425             : }
     426             : 
     427             : /**
     428             :  * @descr    Get the endnote type
     429             :  */
     430           0 : sal_uInt16 LwpDocument::GetEndnoteType()
     431             : {
     432           0 :     LwpDivInfo* pDivInfo = dynamic_cast<LwpDivInfo*>(GetDivInfoID()->obj());
     433           0 :     if (!pDivInfo)
     434           0 :         return FN_DONTCARE;
     435           0 :     OUString strClassName = pDivInfo->GetClassName();
     436           0 :     if (strClassName.equals(A2OUSTR(STR_DivisionEndnote)))
     437           0 :         return FN_DIVISION_SEPARATE;
     438           0 :     if (strClassName.equals(A2OUSTR(STR_DivisionGroupEndnote)))
     439           0 :         return FN_DIVISIONGROUP_SEPARATE;
     440           0 :     if (strClassName.equals(A2OUSTR(STR_DocumentEndnote)))
     441           0 :         return FN_DOCUMENT_SEPARATE;
     442           0 :     return FN_DONTCARE;
     443             : }
     444             : /**
     445             :  * @descr       Get previous division
     446             :  */
     447          14 : LwpDocument* LwpDocument::GetPreviousDivision()
     448             : {
     449          14 :     LwpDocSock* pDocSock = dynamic_cast<LwpDocSock*>(GetSocket()->obj());
     450          14 :     if(pDocSock)
     451             :     {
     452          14 :         return dynamic_cast<LwpDocument*>(pDocSock->GetPrevious()->obj());
     453             :     }
     454           0 :     return NULL;
     455             : }
     456             : /**
     457             :  * @descr    Get next division
     458             :  */
     459           3 :  LwpDocument* LwpDocument::GetNextDivision()
     460             : {
     461           3 :     LwpDocSock* pDocSock = dynamic_cast<LwpDocSock*>(GetSocket()->obj());
     462           3 :     if(pDocSock)
     463             :     {
     464           3 :         return dynamic_cast<LwpDocument*>(pDocSock->GetNext()->obj());
     465             :     }
     466           0 :     return NULL;
     467             : }
     468             : /**
     469             :  * @descr    Get parent division
     470             :  */
     471         268 :  LwpDocument* LwpDocument::GetParentDivision()
     472             : {
     473         268 :     LwpDocSock* pDocSock = dynamic_cast<LwpDocSock*>(GetSocket()->obj());
     474         268 :     if(pDocSock)
     475             :     {
     476         268 :         return dynamic_cast<LwpDocument*>(pDocSock->GetParent()->obj());
     477             :     }
     478           0 :     return NULL;
     479             : }
     480             : /**
     481             :  * @descr    Get previous division in group, copy from lwp source code
     482             :  */
     483           0 :  LwpDocument* LwpDocument::GetPreviousInGroup()
     484             : {
     485           0 :     LwpDocument* pPrev = NULL;
     486             : 
     487           0 :     for (pPrev = GetPreviousDivision(); pPrev; pPrev = pPrev->GetPreviousDivision())
     488             :     {
     489           0 :         LwpDivInfo* pDivInfo = dynamic_cast<LwpDivInfo*>(pPrev->GetDivInfoID()->obj());
     490           0 :         if(pDivInfo && pDivInfo->HasContents())
     491           0 :             return pPrev;
     492             :     }
     493           0 :     return NULL;
     494             : }
     495             : /**
     496             :  * @descr       Get previous division in group, copy from lwp source code
     497             :  */
     498           0 :  LwpDocument* LwpDocument::GetNextInGroup()
     499             : {
     500           0 :     LwpDocument* pNext = NULL;
     501             : 
     502           0 :     for (pNext = GetNextDivision(); pNext; pNext = pNext->GetNextDivision())
     503             :     {
     504           0 :         LwpDivInfo* pDivInfo = dynamic_cast<LwpDivInfo*>(pNext->GetDivInfoID()->obj());
     505           0 :         if(pDivInfo && pDivInfo->HasContents())
     506           0 :             return pNext;
     507             :     }
     508             : 
     509           0 :     return NULL;
     510             : }
     511             : /**
     512             :  * @descr    Get previous division which has contents, copy from lwp source code
     513             :  */
     514          14 :  LwpDocument* LwpDocument::GetPreviousDivisionWithContents()
     515             : {
     516          14 :     if(GetPreviousDivision())
     517             :     {
     518           0 :         LwpDocument* pDoc = GetPreviousDivision()->GetLastDivisionWithContents();
     519           0 :         if (pDoc)
     520           0 :             return pDoc;
     521             :     }
     522          14 :     if(GetParentDivision())
     523           7 :         return GetParentDivision()->GetPreviousDivisionWithContents();
     524           7 :     return NULL;
     525             : }
     526             :  /**
     527             :  * @descr    Get last division which has contents, copy from lwp source code
     528             :  */
     529          14 :  LwpDocument* LwpDocument::GetLastDivisionWithContents()
     530             : {
     531          14 :     LwpDivInfo* pDivInfo = dynamic_cast<LwpDivInfo*>(GetDivInfoID()->obj());
     532          14 :     if(pDivInfo && pDivInfo->HasContents())
     533             :     {
     534           7 :         return this;
     535             :     }
     536             : 
     537           7 :     LwpDocument* pDivision = GetLastDivision();
     538           7 :     LwpDocument* pContentDivision = NULL;
     539             : 
     540          14 :     while(pDivision)
     541             :     {
     542           7 :         pContentDivision = pDivision->GetLastDivisionWithContents();
     543           7 :         if(pContentDivision)
     544             :         {
     545           7 :             return pContentDivision;
     546             :         }
     547           0 :         pDivision = pDivision->GetPreviousDivision();
     548             :     }
     549             : 
     550           0 :     return NULL;
     551             : }
     552             :  /**
     553             :  * @descr    Get last division in group  which has contents, copy from lwp source code
     554             :  */
     555           0 :  LwpDocument* LwpDocument::GetLastInGroupWithContents()
     556             : {
     557           0 :     LwpDocument* pLast = NULL;
     558           0 :     LwpDocument* pNext = this;
     559             : 
     560           0 :     while (pNext)
     561             :     {
     562           0 :         LwpDivInfo* pDivInfo = dynamic_cast<LwpDivInfo*>(pNext->GetDivInfoID()->obj());
     563           0 :         if (pDivInfo && pDivInfo->HasContents())
     564           0 :             pLast = pNext;
     565           0 :         pNext = pNext->GetNextInGroup();
     566             :     }
     567           0 :     if (pLast)
     568           0 :         return pLast;
     569           0 :     return NULL;
     570             : }
     571             :   /**
     572             :  * @descr    Get last division
     573             :  */
     574           7 :  LwpDocument* LwpDocument::GetLastDivision()
     575             : {
     576           7 :     LwpDocSock* pDocSock = dynamic_cast<LwpDocSock*>(GetSocket()->obj());
     577           7 :     if(pDocSock)
     578           7 :         return dynamic_cast<LwpDocument*>(pDocSock->GetChildTail()->obj());
     579           0 :     return NULL;
     580             : }
     581             : 
     582             :   /**
     583             :  * @descr    Get first division
     584             :  */
     585          10 :  LwpDocument* LwpDocument::GetFirstDivision()
     586             : {
     587          10 :     LwpDocSock* pDocSock = dynamic_cast<LwpDocSock*>(GetSocket()->obj());
     588          10 :     if(pDocSock)
     589          10 :         return dynamic_cast<LwpDocument*>(pDocSock->GetChildHead()->obj());
     590           0 :     return NULL;
     591             : }
     592             : 
     593             :  /**
     594             :  * @descr    Get root document
     595             :  */
     596         251 :  LwpDocument* LwpDocument::GetRootDocument()
     597             : {
     598         251 :     LwpDocument* pRoot = this;
     599         749 :     while(pRoot)
     600             :     {
     601         498 :         if(!pRoot->IsChildDoc())
     602         251 :             return pRoot;
     603         247 :         pRoot = pRoot->GetParentDivision();
     604             :     }
     605           0 :     return NULL;
     606             : }
     607             :   /**
     608             :  * @descr    Get first division with contents that is not ole, copy from lwp-source code
     609             :  */
     610           8 :  LwpDocument* LwpDocument::GetFirstDivisionWithContentsThatIsNotOLE()
     611             : {
     612           8 :     LwpDivInfo* pDivInfo = dynamic_cast<LwpDivInfo*>(GetDivInfoID()->obj());
     613          12 :     if(pDivInfo && pDivInfo->HasContents()
     614           4 :         && !pDivInfo->IsOleDivision())
     615           4 :         return this;
     616             : 
     617           4 :     LwpDocument* pDivision = GetFirstDivision();
     618             : 
     619           4 :     LwpDocument*  pContentDivision = NULL;
     620             : 
     621           8 :     while (pDivision)
     622             :     {
     623           4 :         pContentDivision = pDivision->GetFirstDivisionWithContentsThatIsNotOLE();
     624           4 :         if(pContentDivision)
     625           4 :             return pContentDivision;
     626           0 :         pDivision = pDivision->GetNextDivision();
     627             :     }
     628           0 :     return NULL;
     629             : }
     630             :  /**
     631             :  * @descr    Get last division that has endnote
     632             :  */
     633           7 :  LwpDocument* LwpDocument::GetLastDivisionThatHasEndnote()
     634             : {
     635           7 :     LwpDocument* pRoot = GetRootDocument();
     636           7 :     LwpDocument *pLastDoc = pRoot->GetLastDivisionWithContents();
     637          21 :     while(pLastDoc)
     638             :     {
     639           7 :         if(pLastDoc->GetEnSuperTableLayout())
     640           0 :             return pLastDoc;
     641           7 :         pLastDoc = pLastDoc->GetPreviousDivisionWithContents();
     642             :     }
     643           7 :     return NULL;
     644             : 
     645             : }
     646             :  /**
     647             :  * @descr    Get endnote supertable layout, every division has only one endnote supertable layout.
     648             :  */
     649           7 :  LwpVirtualLayout* LwpDocument::GetEnSuperTableLayout()
     650             : {
     651           7 :     LwpHeadLayout* pHeadLayout = dynamic_cast<LwpHeadLayout*>(GetFoundry()->GetLayout()->obj());
     652           7 :     if(pHeadLayout)
     653             :     {
     654           7 :         return pHeadLayout->FindEnSuperTableLayout();
     655             :     }
     656           0 :     return NULL;
     657             : }
     658             : 
     659             : /**
     660             :  * @descr    Get the numbers of page  before pEndDivision, copy from lwp source code
     661             :  */
     662           0 :  sal_Bool LwpDocument::GetNumberOfPages(LwpDocument* pEndDivision, sal_uInt16& nCount)
     663             : {
     664           0 :     if(this == pEndDivision)
     665           0 :         return sal_True;
     666             : 
     667           0 :     LwpDivInfo* pDivInfo = dynamic_cast<LwpDivInfo*>(m_DivInfo.obj());
     668           0 :     if(pDivInfo)
     669             :     {
     670           0 :         pDivInfo->GetNumberOfPages(nCount);
     671             :     }
     672             : 
     673           0 :     LwpDocument* pDivision = GetFirstDivision();
     674           0 :     while(pDivision)
     675             :     {
     676           0 :         if(pDivision->GetNumberOfPages(pEndDivision,nCount))
     677           0 :             return sal_True;
     678           0 :         pDivision = pDivision->GetNextDivision();
     679             : 
     680             :     }
     681           0 :     return sal_False;
     682             : }
     683             : /**
     684             :  * @descr    Get the numbers of page  before curruent division
     685             :  */
     686           0 : sal_uInt16 LwpDocument::GetNumberOfPagesBefore()
     687             : {
     688           0 :     sal_uInt16 nPageNumber = 0;
     689           0 :     LwpDocument* pRoot = GetRootDocument();
     690           0 :     if(pRoot)
     691           0 :         pRoot->GetNumberOfPages(this,nPageNumber);
     692           0 :     return nPageNumber;
     693             : }
     694             : 
     695             :  /**
     696             :  * @descr    Get Max number of pages
     697             :  */
     698           0 :  void  LwpDocument::MaxNumberOfPages(sal_uInt16& nNumPages)
     699             : {
     700           0 :     LwpDocument* pDivision = GetFirstDivision();
     701             : 
     702           0 :     LwpDivInfo* pDivInfo = dynamic_cast<LwpDivInfo*>(m_DivInfo.obj());
     703           0 :     if(pDivInfo)
     704           0 :         nNumPages += pDivInfo->GetMaxNumberOfPages();
     705           0 :     while(pDivision)
     706             :     {
     707           0 :         pDivision->MaxNumberOfPages(nNumPages);
     708           0 :         pDivision = pDivision->GetNextDivision();
     709             :     }
     710           0 : }
     711             :   /**
     712             :  * @descr    Parse the frame which anchor is to page before parse other contents,
     713             :  *          This method is called when the document is root document.
     714             :  */
     715           6 : void LwpDocument::ParseFrameInPage(IXFStream * pOutputStream)
     716             : {
     717           6 :     if(IsChildDoc())
     718           9 :         return;
     719             : 
     720           3 :     XFContentContainer* pXFContainer = new XFContentContainer;
     721             : 
     722           3 :     XFConvertFrameInPage(pXFContainer);
     723             : 
     724           3 :     pXFContainer->ToXml(pOutputStream);
     725           3 :     delete pXFContainer;
     726           3 :     pXFContainer = NULL;
     727             : }
     728             :  /**
     729             :  * @descr    Parse the frame which anchor is to page in the entire document
     730             :  */
     731           6 : void LwpDocument::XFConvertFrameInPage(XFContentContainer * pCont)
     732             : {
     733           6 :     LwpDocument* pDivision = GetFirstDivision();
     734             : 
     735           6 :     LwpDivInfo* pDivInfo = dynamic_cast<LwpDivInfo*> (GetDivInfoID()->obj());
     736           6 :     if(pDivInfo)
     737             :     {
     738           6 :         LwpPageLayout*  pPageLayout = dynamic_cast<LwpPageLayout*>(pDivInfo->GetInitialLayoutID()->obj());
     739           6 :         if(pPageLayout)
     740             :         {
     741           3 :             LwpStory* pStory = dynamic_cast<LwpStory*>(pPageLayout->GetContent()->obj());
     742           3 :             if(pStory)
     743           3 :                 pStory->XFConvertFrameInPage(pCont);
     744             :         }
     745             :     }
     746          15 :     while(pDivision)
     747             :     {
     748           3 :         pDivision->XFConvertFrameInPage(pCont);
     749           3 :         pDivision = pDivision->GetNextDivision();
     750             :     }
     751           6 : }
     752             :  /**
     753             :  * @descr    change click here to placeholder
     754             :  */
     755           8 : void LwpDocument::ChangeStyleName()
     756             : {
     757           8 :     XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
     758           8 :     XFTextStyle* pStyle = dynamic_cast<XFTextStyle*>(pXFStyleManager->FindStyle(A2OUSTR("ClickHere")));
     759           8 :     if (pStyle)
     760             :     {
     761           0 :         pStyle->SetStyleName(A2OUSTR("Placeholder"));
     762             :     }
     763           8 : }
     764           8 : LwpDocSock::LwpDocSock(LwpObjectHeader& objHdr, LwpSvStream* pStrm)
     765           8 :     :LwpDLNFVList(objHdr, pStrm)
     766           8 : {}
     767             : 
     768             :  /**
     769             :  * @descr    read VO_DOCSOCK from file
     770             :  */
     771           8 : void LwpDocSock::Read()
     772             : {
     773           8 :     LwpDLNFVList::Read();
     774           8 :     m_Doc.ReadIndexed(m_pObjStrm);
     775           8 :     m_pObjStrm->SkipExtra();
     776           8 : }
     777             :  /**
     778             :  * @descr    register styles in documents plugged
     779             :  */
     780           7 : void LwpDocSock::RegisterStyle()
     781             : {
     782           7 :     LwpObject* pDoc = GetNext()->obj();
     783           7 :     if(pDoc)
     784           0 :         pDoc->RegisterStyle();
     785             : 
     786           7 :     pDoc = GetChildHead()->obj();
     787           7 :     if(pDoc)
     788           4 :         pDoc->RegisterStyle();
     789           6 : }
     790             :  /**
     791             :  * @descr    parse contents of documents plugged
     792             :  */
     793           6 : void LwpDocSock::Parse(IXFStream* pOutputStream)
     794             : {
     795           6 :     LwpObject* pDoc = GetChildHead()->obj();
     796           6 :     if(pDoc)
     797           3 :         pDoc->Parse(pOutputStream);
     798             : 
     799           6 :     pDoc = GetNext()->obj();
     800           6 :     if(pDoc)
     801           0 :         pDoc->Parse(pOutputStream);
     802           6 : }
     803             : 
     804             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10