LCOV - code coverage report
Current view: top level - lotuswordpro/source/filter - lwpstory.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 217 0.0 %
Date: 2014-04-14 Functions: 0 22 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             :  * @file
      58             :  *  LwpStory:
      59             :         1. Word Pro object for paragraph list;
      60             :         2. the content of layout object
      61             :  ************************************************************************/
      62             : /*************************************************************************
      63             :  * Change History
      64             :  Jan 2005           Created
      65             :  ************************************************************************/
      66             : #include "lwpglobalmgr.hxx"
      67             : #include "lwpstory.hxx"
      68             : #include "xfilter/xfstylemanager.hxx"
      69             : 
      70           0 : LwpStory::LwpStory(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
      71             :     : LwpContent(objHdr, pStrm)
      72             :     , m_bPMModified(sal_False)
      73             :     , m_pCurrentLayout(NULL)
      74             :     , m_pTabLayout(NULL)
      75             :     , m_bDropcap(sal_False)
      76           0 :     , m_pHyperlinkMgr(new LwpHyperlinkMgr)
      77           0 :     , m_pXFContainer(NULL)
      78             : {
      79           0 : }
      80             : 
      81           0 : LwpStory::~LwpStory()
      82             : {
      83           0 :     delete m_pHyperlinkMgr;
      84           0 : }
      85             : 
      86           0 : void LwpStory::Read()
      87             : {
      88           0 :     LwpContent::Read();
      89           0 :     m_ParaList.Read(m_pObjStrm);
      90           0 :     m_FirstParaStyle.ReadIndexed(m_pObjStrm);
      91           0 :     m_pObjStrm->SkipExtra();
      92           0 : }
      93             : 
      94             : #include "lwppara.hxx"
      95             : #include "lwpobjfactory.hxx"
      96             : /**************************************************************************
      97             :  * @descr:   Convert all the contents in current story
      98             :  * @param:
      99             :  * @param:
     100             :  * @return:
     101             : **************************************************************************/
     102           0 : void LwpStory::XFConvert(XFContentContainer* pCont)
     103             : {
     104             :     //process frame which anchor frame
     105           0 :     XFConvertFrameInFrame(pCont);
     106             :     //process para list
     107           0 :     XFContentContainer* pParaCont = pCont;
     108           0 :     LwpPara* pPara = dynamic_cast<LwpPara*> ( GetFirstPara()->obj() );
     109           0 :     while(pPara)
     110             :     {
     111           0 :         pPara->SetFoundry(m_pFoundry);
     112           0 :         pPara->XFConvert(pParaCont);
     113             : 
     114             :         //Get the xfcontainer for the next para
     115           0 :         pParaCont = pPara->GetXFContainer();
     116           0 :         pPara = dynamic_cast<LwpPara*> ( pPara->GetNext()->obj() );
     117             :     }
     118             : 
     119             :     //process frame which anchor is to cell after converter all the para
     120           0 :     XFConvertFrameInCell(pCont);
     121           0 :     XFConvertFrameInHeaderFooter(pCont);
     122             : 
     123             :     //Release Lwp Objects
     124           0 :     LwpPara* pCur = dynamic_cast<LwpPara*> (GetFirstPara()->obj());
     125             :     LwpPara* pNext;
     126           0 :     while(pCur)
     127             :     {
     128           0 :         pCur->Release();
     129           0 :         pNext = dynamic_cast<LwpPara*> ( pCur->GetNext()->obj() );
     130           0 :         LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
     131           0 :         LwpObjectFactory* pObjMgr = pGlobal->GetLwpObjFactory();
     132           0 :         pObjMgr->ReleaseObject(*pCur->GetObjectID());
     133           0 :         pCur = pNext;
     134             :     }
     135           0 : }
     136             : 
     137           0 : void LwpStory::RegisterStyle()
     138             : {
     139           0 :     LwpPara* pPara = dynamic_cast<LwpPara*>( GetFirstPara()->obj() );
     140           0 :     while(pPara)
     141             :     {
     142           0 :         pPara->SetFoundry(m_pFoundry);
     143           0 :         pPara->RegisterStyle();
     144           0 :         pPara = dynamic_cast<LwpPara*>(pPara->GetNext()->obj());
     145             :     }
     146           0 : }
     147             : 
     148           0 : void LwpStory::Parse(IXFStream* pOutputStream)
     149             : {
     150           0 :     m_pXFContainer = new XFContentContainer;
     151           0 :     XFConvert(m_pXFContainer);
     152           0 :     m_pXFContainer->ToXml(pOutputStream);
     153           0 :     delete m_pXFContainer;
     154           0 :     m_pXFContainer = NULL;
     155             : 
     156             :     //It seems that, currently, we do not need to process the child story
     157             :     /*LwpObject* pChildStory = GetFirstStory()->obj();
     158             :     if(pChildStory)
     159             :     {
     160             :         pChildStory->SetFoundry(m_pFoundry);
     161             :         pChildStory->Parse(pOutputStream);
     162             :     }*/
     163             : 
     164             :     //Don't process the next story
     165             : /*  LwpObject* pNextStory = GetNextStory()->obj();
     166             :     if(pNextStory)
     167             :     {
     168             :         pNextStory->SetFoundry(m_pFoundry);
     169             :         pNextStory->Parse(pOutputStream);
     170             :     }*/
     171             : 
     172           0 : }
     173             : 
     174             : #include "lwppagelayout.hxx"
     175             : /**************************************************************************
     176             :  * @descr:   Set current page layout. If pPageLayout is a mirro page layout,
     177             :              use odd child page layout as current page layout.
     178             :  * @param:
     179             :  * @param:
     180             :  * @return:
     181             : **************************************************************************/
     182           0 : void LwpStory::SetCurrentLayout(LwpPageLayout *pPageLayout)
     183             : {
     184           0 :     LwpPageLayout* pLayout = pPageLayout->GetOddChildLayout();
     185           0 :     if(pLayout)
     186             :     {
     187           0 :         m_pCurrentLayout = pLayout;
     188           0 :         m_pTabLayout = pLayout;
     189             :     }
     190             :     else
     191             :     {
     192           0 :         m_pCurrentLayout = pPageLayout;
     193           0 :         m_pTabLayout = pPageLayout;
     194             :     }
     195           0 :     m_bPMModified = sal_True;
     196           0 : }
     197             : 
     198           0 : void LwpStory::AddPageLayout(LwpPageLayout * pObject)
     199             : {
     200           0 :     m_LayoutList.push_back(pObject);
     201           0 : }
     202             : /**************************************************************************
     203             :  * @descr:   Get the next page layout relative to m_pCurrentLayout
     204             :  * @param:
     205             :  * @param:
     206             :  * @return:
     207             : **************************************************************************/
     208           0 : LwpPageLayout* LwpStory::GetNextPageLayout()
     209             : {
     210           0 :     std::vector<LwpPageLayout*>::iterator it;
     211           0 :     for( it = m_LayoutList.begin(); it != m_LayoutList.end(); ++it )
     212             :     {
     213           0 :         if(m_pCurrentLayout == *it)
     214             :         {
     215           0 :             if((it+1) !=m_LayoutList.end())
     216             :             {
     217           0 :                 return *(it+1);
     218             :             }
     219             :         }
     220             :     }
     221           0 :     return NULL;
     222             : }
     223             : /**************************************************************************
     224             :  * @descr:   Sort the pagelayout according to their position
     225             :  * @param:
     226             :  * @param:
     227             :  * @return:
     228             : **************************************************************************/
     229           0 : void LwpStory::SortPageLayout()
     230             : {
     231             :     //Get all the pagelayout and store in list
     232           0 :     std::vector<LwpPageLayout*>  aLayoutList;
     233           0 :     LwpVirtualLayout* pLayout = GetLayout(NULL);
     234           0 :     while(pLayout)
     235             :     {
     236           0 :         if(pLayout->IsPage())
     237             :         {
     238           0 :             LwpLayout::UseWhenType eSectionType = static_cast<LwpPageLayout*>(pLayout)->GetUseWhenType();
     239             :             //for mirror page, the child  is pagelayout
     240           0 :             LwpVirtualLayout* pParent = pLayout->GetParentLayout();
     241           0 :             if(eSectionType != LwpLayout::StartWithinColume && pParent && !pParent->IsPage())
     242             :             {
     243           0 :                 aLayoutList.push_back(static_cast<LwpPageLayout*>(pLayout));
     244             :             }
     245             :         }
     246           0 :         pLayout = GetLayout(pLayout);
     247             :     }
     248             :     // sort the pagelayout according to their position
     249           0 :     std::vector<LwpPageLayout*>::iterator aIt;
     250           0 :     if (!aLayoutList.empty())
     251             :     {
     252           0 :         for( aIt = aLayoutList.begin(); aIt != aLayoutList.end() -1; ++aIt)
     253             :         {
     254           0 :             for( std::vector<LwpPageLayout*>::iterator bIt = aIt +1; bIt != aLayoutList.end(); ++bIt )
     255             :             {
     256           0 :                 if(**aIt < **bIt)
     257             :                 {
     258           0 :                     continue;
     259             :                 }
     260             :                 else
     261             :                 {
     262           0 :                     LwpPageLayout* pTemp = *aIt;
     263           0 :                     *aIt = *bIt;
     264           0 :                     *bIt = pTemp;
     265             :                 }
     266             :             }
     267             :         }
     268             :     }
     269             : 
     270             :     //put all the sorted  layouts into list
     271           0 :     m_LayoutList.clear();
     272             : 
     273           0 :     for( aIt = aLayoutList.begin(); aIt != aLayoutList.end(); ++aIt)
     274             :     {
     275           0 :         m_LayoutList.push_back(*aIt);
     276           0 :     }
     277           0 : }
     278             : 
     279             : /**************************************************************************
     280             :  * @descr:  whether need create a new section and reset column in current page layout
     281             :  * @param:
     282             :  * @param:
     283             :  * @return:  sal_True if need create a new section
     284             : **************************************************************************/
     285           0 : sal_Bool LwpStory::IsNeedSection()
     286             : {
     287           0 :     sal_Bool bColumns = sal_False;
     288           0 :     sal_Bool bNewSection = sal_False;
     289           0 :     if(m_pCurrentLayout)
     290             :     {
     291           0 :         if(m_pCurrentLayout->HasColumns())
     292             :         {
     293             :             //get the following pagelayout and its type
     294           0 :             bColumns = sal_True;
     295           0 :             LwpPageLayout* pNextLayout = GetNextPageLayout();
     296           0 :             if(pNextLayout)
     297             :             {
     298             :                 //get layout type
     299           0 :                 LwpLayout::UseWhenType eWhenType = pNextLayout->GetUseWhenType();
     300           0 :                 switch(eWhenType)
     301             :                 {
     302             :                 case LwpLayout::StartWithinColume://not support now
     303             :                 case LwpLayout::StartWithinPage:
     304             :                 {
     305           0 :                     bColumns =sal_False;
     306           0 :                     bNewSection = sal_True;
     307           0 :                     break;
     308             :                 }
     309             :                 case LwpLayout::StartOnNextPage:
     310             :                 case LwpLayout::StartOnOddPage://not support now
     311             :                 case LwpLayout::StartOnEvenPage://not support now
     312             :                 {
     313           0 :                     bColumns =sal_True;
     314           0 :                     bNewSection = sal_False;
     315           0 :                     break;
     316             :                 }
     317             :                 default:
     318           0 :                     break;
     319             :                 }
     320             :             }
     321             : 
     322             :             //if bColumns is ture, the page layout doesn't need columns, set the xfcolumns to NULL in page master
     323           0 :             if(!bColumns)
     324             :             {
     325           0 :                 m_pCurrentLayout->ResetXFColumns();
     326             :             }
     327             :         }
     328           0 :         SetPMModified(sal_False);
     329             :     }
     330           0 :     return bNewSection;
     331             : }
     332             : /**************************************************************************
     333             :  * @descr:  process frame which anchor type is to cell
     334             :  * @param:
     335             :  * @param:
     336             :  * @return:
     337             : **************************************************************************/
     338           0 : void LwpStory::XFConvertFrameInCell(XFContentContainer* pCont)
     339             : {
     340           0 :     LwpVirtualLayout* pLayout = GetLayout(NULL);
     341           0 :     while(pLayout)
     342             :     {
     343           0 :         LwpVirtualLayout* pFrameLayout = dynamic_cast<LwpVirtualLayout*>(pLayout->GetChildHead()->obj());
     344           0 :         while(pFrameLayout)
     345             :         {
     346             : 
     347             :             //if(pFrameLayout->IsAnchorCell())
     348           0 :             if(pFrameLayout->IsAnchorCell() && pFrameLayout->HasContent())
     349             :             {
     350             :                 //get the first xfpara
     351           0 :                 XFContentContainer* pXFFirtPara = static_cast<XFContentContainer*>(pCont->FindFirstContent(enumXFContentPara));
     352           0 :                 if(pXFFirtPara)
     353           0 :                     pFrameLayout->XFConvert(pXFFirtPara);
     354             :             }
     355           0 :             pFrameLayout = dynamic_cast<LwpVirtualLayout*>(pFrameLayout->GetNext()->obj());
     356             :         }
     357           0 :         pLayout = GetLayout(pLayout);
     358             :     }
     359           0 : }
     360             : 
     361             : /**************************************************************************
     362             :  * @descr:  process frame which anchor type is to page
     363             :  * @param:
     364             :  * @param:
     365             :  * @return:
     366             : **************************************************************************/
     367           0 : void LwpStory::XFConvertFrameInPage(XFContentContainer* pCont)
     368             : {
     369           0 :     LwpVirtualLayout* pLayout = GetLayout(NULL);
     370           0 :     while(pLayout)
     371             :     {
     372           0 :         LwpVirtualLayout* pFrameLayout = dynamic_cast<LwpVirtualLayout*>(pLayout->GetChildHead()->obj());
     373           0 :         while(pFrameLayout)
     374             :         {
     375           0 :             if((pFrameLayout->IsAnchorPage()
     376           0 :                 &&(pFrameLayout->IsFrame()
     377           0 :                       ||pFrameLayout->IsSuperTable()
     378           0 :                       ||pFrameLayout->IsGroupHead())))
     379             :             {
     380           0 :                 pFrameLayout->XFConvert(pCont);
     381             :             }
     382           0 :             pFrameLayout = dynamic_cast<LwpVirtualLayout*>(pFrameLayout->GetNext()->obj());
     383             :         }
     384           0 :         pLayout = GetLayout(pLayout);
     385             :     }
     386           0 : }
     387             : /**************************************************************************
     388             :  * @descr:  process frame which anchor type is to frame
     389             :  * @param:
     390             :  * @param:
     391             :  * @return:
     392             : **************************************************************************/
     393           0 : void LwpStory::XFConvertFrameInFrame(XFContentContainer* pCont)
     394             : {
     395           0 :     LwpVirtualLayout* pLayout = GetLayout(NULL);
     396           0 :     while(pLayout)
     397             :     {
     398           0 :         LwpVirtualLayout* pFrameLayout = dynamic_cast<LwpVirtualLayout*>(pLayout->GetChildHead()->obj());
     399           0 :         while(pFrameLayout)
     400             :         {
     401           0 :             if(pFrameLayout->IsAnchorFrame())
     402             :             {
     403           0 :                 pFrameLayout->XFConvert(pCont);
     404             :             }
     405           0 :             pFrameLayout = dynamic_cast<LwpVirtualLayout*>(pFrameLayout->GetNext()->obj());
     406             :         }
     407           0 :         pLayout = GetLayout(pLayout);
     408             :     }
     409           0 : }
     410             : /**************************************************************************
     411             :  * @descr:  process frame which anchor type is to page and the frame is contained by header or footer
     412             :  * @param:
     413             :  * @param:
     414             :  * @return:
     415             : **************************************************************************/
     416           0 : void LwpStory::XFConvertFrameInHeaderFooter(XFContentContainer* pCont)
     417             : {
     418           0 :     LwpVirtualLayout* pLayout = GetLayout(NULL);
     419           0 :     while(pLayout)
     420             :     {
     421           0 :         LwpVirtualLayout* pFrameLayout = dynamic_cast<LwpVirtualLayout*>(pLayout->GetChildHead()->obj());
     422           0 :         while(pFrameLayout)
     423             :         {
     424           0 :             if(pFrameLayout->IsAnchorPage() && (pLayout->IsHeader() || pLayout->IsFooter()))
     425             :             {
     426             :                 //The frame must be included by <text:p>
     427           0 :                 XFContentContainer* pXFFirtPara = static_cast<XFContentContainer*>(pCont->FindFirstContent(enumXFContentPara));
     428           0 :                 if(pXFFirtPara)
     429           0 :                     pFrameLayout->XFConvert(pXFFirtPara);
     430             :             }
     431           0 :             pFrameLayout = dynamic_cast<LwpVirtualLayout*>(pFrameLayout->GetNext()->obj());
     432             :         }
     433           0 :         pLayout = GetLayout(pLayout);
     434             :     }
     435           0 : }
     436             : 
     437           0 : void LwpStory::AddXFContent(XFContent* pContent)
     438             : {
     439           0 :     if(m_pXFContainer)
     440           0 :         m_pXFContainer->Add(pContent);
     441           0 : }
     442             : 
     443           0 : XFContentContainer* LwpStory::GetXFContent()
     444             : {
     445           0 :     if(m_pXFContainer)
     446           0 :         return m_pXFContainer;
     447             :     else
     448           0 :         return NULL;
     449             : }
     450             : 
     451           0 : LwpPara* LwpStory::GetLastParaOfPreviousStory()
     452             : {
     453           0 :     LwpVirtualLayout* pVLayout = this->GetLayout(NULL);
     454           0 :     if (pVLayout)
     455             :     {
     456           0 :         return pVLayout->GetLastParaOfPreviousStory();
     457             :     }
     458             : 
     459           0 :     return NULL;
     460             : }
     461             : /**************************************************************************
     462             :  * @descr:  get text from story
     463             :  * @param:
     464             :  * @param:
     465             :  * @return:
     466             : **************************************************************************/
     467           0 : OUString LwpStory::GetContentText(sal_Bool bAllText)
     468             : {
     469           0 :     if (bAllText)//convert all text fribs
     470             :     {
     471           0 :         OUString sText("");
     472             :         //process para list
     473           0 :         LwpPara* pPara = dynamic_cast<LwpPara*>(GetFirstPara()->obj());
     474           0 :         while (pPara)
     475             :         {
     476           0 :             pPara->SetFoundry(m_pFoundry);
     477           0 :             sText += pPara->GetContentText(sal_True);
     478           0 :             pPara = dynamic_cast<LwpPara*>(pPara->GetNext()->obj());
     479             :         }
     480           0 :         return sText;
     481             :     }
     482             :     else //only the first text frib
     483             :     {
     484           0 :         LwpObject* pObj = GetFirstPara()->obj();
     485           0 :         if(pObj)
     486             :         {
     487           0 :             LwpPara* pPara = dynamic_cast<LwpPara*>(pObj);
     488           0 :             if (!pPara || pPara->GetNext()->obj() != NULL)
     489           0 :                 return OUString("");
     490           0 :             pPara->SetFoundry(m_pFoundry);
     491           0 :             return pPara->GetContentText();
     492             :         }
     493           0 :         return  OUString("");
     494             :     }
     495             : 
     496             : }
     497           0 : OUString LwpStory::RegisterFirstFribStyle()
     498             : {
     499           0 :     LwpPara* pPara = dynamic_cast<LwpPara*>(GetFirstPara()->obj());
     500           0 :     if (!pPara)
     501           0 :         return OUString("");
     502           0 :     pPara->SetFoundry(m_pFoundry);
     503           0 :     LwpFribPtr* pFribs = pPara->GetFribs();
     504           0 :     if (pFribs)
     505             :     {
     506           0 :         LwpFrib* pFirstFrib = pFribs->GetFribs();
     507           0 :         pFirstFrib->RegisterStyle(m_pFoundry);
     508           0 :         XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
     509           0 :         XFTextStyle* pBaseStyle = pXFStyleManager->FindTextStyle(pFirstFrib->GetStyleName());
     510           0 :         if (pBaseStyle == NULL)
     511           0 :             return OUString("");
     512           0 :         XFTextStyle* pStyle = new XFTextStyle;
     513           0 :         *pStyle = *pBaseStyle;
     514           0 :         OUString sName = "Ruby" + pFirstFrib->GetStyleName();
     515           0 :         pStyle->SetStyleName(sName);
     516           0 :         pXFStyleManager->AddStyle(pStyle);
     517           0 :         return sName;
     518             :     }
     519           0 :     return OUString("");
     520             : }
     521             : 
     522           0 : sal_Bool LwpStory::IsBullStyleUsedBefore(const OUString& rStyleName, const sal_uInt8& nPos)
     523             : {
     524           0 :     std::vector <NamePosPair>::reverse_iterator rIter;
     525           0 :     for (rIter = m_vBulletStyleNameList.rbegin(); rIter != m_vBulletStyleNameList.rend(); ++rIter)
     526             :     {
     527           0 :         OUString aName = (*rIter).first;
     528           0 :         sal_uInt8 nPosition = (*rIter).second;
     529           0 :         if (aName == rStyleName && nPosition == nPos)
     530             :         {
     531           0 :             return sal_True;
     532             :         }
     533           0 :     }
     534           0 :     return sal_False;
     535             : }
     536             : 
     537             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10