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

Generated by: LCOV version 1.11