LCOV - code coverage report
Current view: top level - lotuswordpro/source/filter - lwpfootnote.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 127 225 56.4 %
Date: 2014-11-03 Functions: 23 30 76.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*************************************************************************
       3             :  *
       4             :  *  The Contents of this file are made available subject to the terms of
       5             :  *  either of the following licenses
       6             :  *
       7             :  *         - GNU Lesser General Public License Version 2.1
       8             :  *         - Sun Industry Standards Source License Version 1.1
       9             :  *
      10             :  *  Sun Microsystems Inc., October, 2000
      11             :  *
      12             :  *  GNU Lesser General Public License Version 2.1
      13             :  *  =============================================
      14             :  *  Copyright 2000 by Sun Microsystems, Inc.
      15             :  *  901 San Antonio Road, Palo Alto, CA 94303, USA
      16             :  *
      17             :  *  This library is free software; you can redistribute it and/or
      18             :  *  modify it under the terms of the GNU Lesser General Public
      19             :  *  License version 2.1, as published by the Free Software Foundation.
      20             :  *
      21             :  *  This library is distributed in the hope that it will be useful,
      22             :  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
      23             :  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      24             :  *  Lesser General Public License for more details.
      25             :  *
      26             :  *  You should have received a copy of the GNU Lesser General Public
      27             :  *  License along with this library; if not, write to the Free Software
      28             :  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
      29             :  *  MA  02111-1307  USA
      30             :  *
      31             :  *
      32             :  *  Sun Industry Standards Source License Version 1.1
      33             :  *  =================================================
      34             :  *  The contents of this file are subject to the Sun Industry Standards
      35             :  *  Source License Version 1.1 (the "License"); You may not use this file
      36             :  *  except in compliance with the License. You may obtain a copy of the
      37             :  *  License at http://www.openoffice.org/license.html.
      38             :  *
      39             :  *  Software provided under this License is provided on an "AS IS" basis,
      40             :  *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
      41             :  *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
      42             :  *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
      43             :  *  See the License for the specific provisions governing your rights and
      44             :  *  obligations concerning the Software.
      45             :  *
      46             :  *  The Initial Developer of the Original Code is: IBM Corporation
      47             :  *
      48             :  *  Copyright: 2008 by IBM Corporation
      49             :  *
      50             :  *  All Rights Reserved.
      51             :  *
      52             :  *  Contributor(s): _______________________________________
      53             :  *
      54             :  *
      55             :  ************************************************************************/
      56             : /**
      57             :  * @file
      58             :  *  footnote
      59             :  */
      60             : /*************************************************************************
      61             :  * Change History
      62             :  Mar 2005           Created
      63             :  ************************************************************************/
      64             : #include "lwpfootnote.hxx"
      65             : #include "lwpstory.hxx"
      66             : #include "xfilter/xffootnote.hxx"
      67             : #include "xfilter/xfendnote.hxx"
      68             : #include "xfilter/xffootnoteconfig.hxx"
      69             : #include "xfilter/xfendnoteconfig.hxx"
      70             : #include "xfilter/xfstylemanager.hxx"
      71             : #include "xfilter/xftextspan.hxx"
      72             : #include "lwppara.hxx"
      73             : #include "lwpdoc.hxx"
      74             : #include "lwpfnlayout.hxx"
      75             : #include "lwpglobalmgr.hxx"
      76             : 
      77           2 : LwpFribFootnote::LwpFribFootnote(LwpPara* pPara ):LwpFrib(pPara)
      78             : {
      79           2 : }
      80             : 
      81             : /**
      82             :  * @descr  read footnote frib information
      83             :  */
      84           2 : void LwpFribFootnote::Read(LwpObjectStream * pObjStrm, sal_uInt16 /*len*/)
      85             : {
      86           2 :     m_Footnote.ReadIndexed(pObjStrm);
      87           2 : }
      88             : 
      89             : /**
      90             :  * @descr  Register footnote style by calling LwpFootnote::RegisterStyle()
      91             :  */
      92           2 : void LwpFribFootnote::RegisterNewStyle()
      93             : {
      94           2 :     LwpFootnote* pFootnote = GetFootnote();
      95           2 :     if(pFootnote)
      96             :     {
      97             :         //register footnote number font style
      98           2 :         LwpFrib::RegisterStyle(m_pPara->GetFoundry());
      99             :         //register footnote content style
     100           2 :         pFootnote->SetFoundry(m_pPara->GetFoundry());
     101           2 :         pFootnote->RegisterStyle();
     102             :     }
     103           2 : }
     104             : 
     105             : /**
     106             :  * @descr  Parse footnote  by calling LwpFootnote::XFConvert()
     107             :  */
     108           2 : void LwpFribFootnote::XFConvert(XFContentContainer* pCont)
     109             : {
     110           2 :     LwpFootnote* pFootnote = GetFootnote();
     111           2 :     if(pFootnote)
     112             :     {
     113           2 :         XFContentContainer* pContent = NULL;
     114           2 :         if(pFootnote->GetType() == FN_FOOTNOTE)
     115             :         {
     116           2 :             pContent = new XFFootNote();
     117             :         }
     118             :         else
     119             :         {
     120           0 :             pContent = new XFEndNote();
     121             :         }
     122           2 :         pFootnote->XFConvert(pContent);
     123           2 :         if(m_ModFlag)
     124             :         {
     125             :             //set footnote number font style
     126           2 :             XFTextSpan *pSpan = new XFTextSpan();
     127           2 :             pSpan->SetStyleName(GetStyleName());
     128             :             //add the xffootnote into the content container
     129           2 :             pSpan->Add(pContent);
     130           2 :             pCont->Add(pSpan);
     131             :         }
     132             :         else
     133             :         {
     134           0 :             pCont->Add(pContent);
     135             :         }
     136             :     }
     137           2 : }
     138             : 
     139             : /**
     140             :  * @descr  Get foonote object
     141             :  */
     142           4 : LwpFootnote* LwpFribFootnote::GetFootnote()
     143             : {
     144           4 :     return dynamic_cast<LwpFootnote*>(m_Footnote.obj().get());
     145             : }
     146             : 
     147           2 : LwpFootnote::LwpFootnote(LwpObjectHeader &objHdr, LwpSvStream *pStrm)
     148             :     : LwpOrderedObject(objHdr, pStrm)
     149             :     , m_nType(0)
     150           2 :     , m_nRow(0)
     151             : {
     152           2 : }
     153             : 
     154           4 : LwpFootnote::~LwpFootnote()
     155             : {
     156             : 
     157           4 : }
     158             : 
     159             : /**
     160             :  * @descr  Read foonote object
     161             :  */
     162           2 : void LwpFootnote::Read()
     163             : {
     164           2 :     LwpOrderedObject::Read();
     165           2 :     m_nType = m_pObjStrm->QuickReaduInt16();
     166           2 :     m_nRow = m_pObjStrm->QuickReaduInt16();
     167           2 :     m_Content.ReadIndexed(m_pObjStrm);
     168           2 :     m_pObjStrm->SkipExtra();
     169           2 : }
     170             : 
     171             : /**
     172             :  * @descr  Register footnote style
     173             :  */
     174           2 : void LwpFootnote::RegisterStyle()
     175             : {
     176             :     //Only register footnote contents style,
     177             :     //Endnote contents style registers in LwpEnSuperTableLayout::RegisterStyle
     178           2 :     if(m_nType == FN_FOOTNOTE)
     179             :     {
     180           2 :         LwpContent* pContent = FindFootnoteContent();
     181           2 :         if(pContent)
     182             :         {
     183           2 :             pContent->SetFoundry(m_pFoundry);
     184           2 :             pContent->RegisterStyle();
     185             :         }
     186             :     }
     187           2 : }
     188             : 
     189             : /**
     190             :  * @descr  Parse footnote
     191             :  */
     192           2 : void LwpFootnote::XFConvert(XFContentContainer * pCont)
     193             : {
     194           2 :     LwpContent* pContent = FindFootnoteContent();
     195           2 :     if(pContent)
     196             :     {
     197           2 :         pContent->XFConvert(pCont);
     198             :     }
     199           2 : }
     200             : 
     201             : /**
     202             :  * @descr  Get endnote cell layout which contains current endnote content
     203             :  */
     204           0 : LwpCellLayout* LwpFootnote::GetCellLayout()
     205             : {
     206           0 :     LwpEnSuperTableLayout* pEnSuperLayout = FindFootnoteTableLayout();
     207           0 :     if(pEnSuperLayout)
     208             :     {
     209           0 :         LwpTableLayout* pTableLayout = static_cast<LwpTableLayout*>(pEnSuperLayout->GetMainTableLayout());
     210           0 :         if(pTableLayout)
     211             :         {
     212           0 :             LwpRowLayout* pRowLayout = pTableLayout->GetRowLayout(m_nRow);
     213           0 :             if(pRowLayout)
     214             :             {
     215           0 :                 return dynamic_cast<LwpCellLayout*>(pRowLayout->GetChildHead().obj().get());
     216             :             }
     217             :         }
     218             :     }
     219           0 :     return NULL;
     220             : }
     221             : 
     222             : /**
     223             :  * @descr  Get division which footnote table contains current footnote content, copy from lwp source code
     224             :  */
     225           0 : LwpDocument* LwpFootnote::GetFootnoteTableDivision()
     226             : {
     227           0 :     if(!m_pFoundry)
     228           0 :         return NULL;
     229             : 
     230           0 :     LwpDocument* pPrev =NULL;
     231           0 :     LwpDocument* pDivision = NULL;
     232           0 :     LwpDocument* pFootnoteDivision =NULL;
     233             : 
     234             :     // Make sure the footnote does belong to some division
     235             :     // The division might not have a DivisionInfo if it's being Destruct()ed
     236           0 :     pPrev = m_pFoundry->GetDocument();
     237           0 :     pFootnoteDivision = pPrev;
     238           0 :     if (!pPrev || pPrev->GetDivInfoID().IsNull())
     239           0 :         return NULL;
     240             : 
     241           0 :     switch (m_nType)
     242             :     {
     243             :         case FN_FOOTNOTE:
     244             :         {
     245             :             // Footnotes always use the source division
     246           0 :             return pFootnoteDivision;
     247             :         }
     248             :         case FN_DIVISION:
     249             :         {
     250             :             // Start with the footnote's division
     251           0 :             pDivision = pPrev;
     252           0 :             break;
     253             :         }
     254             :         case FN_DIVISION_SEPARATE:
     255             :         {
     256             :             // It had better be the next division
     257           0 :             pDivision = pPrev->GetNextDivision();
     258           0 :             break;
     259             :         }
     260             :         case FN_DIVISIONGROUP:
     261             :         case FN_DIVISIONGROUP_SEPARATE:
     262             :         {
     263           0 :             pDivision = pPrev->GetLastInGroupWithContents();
     264           0 :             pPrev = pDivision;
     265           0 :             break;
     266             :         }
     267             :         case FN_DOCUMENT:
     268             :         case FN_DOCUMENT_SEPARATE:
     269             :         {
     270           0 :             pDivision = pFootnoteDivision->GetRootDocument();
     271           0 :             if (pDivision)
     272           0 :                 pDivision = pDivision->GetLastDivisionWithContents();
     273           0 :             pPrev = pDivision;
     274           0 :             break;
     275             :         }
     276             : 
     277             :     }
     278             : 
     279             :     // Make sure we're using the proper endnote division, if it's separate
     280           0 :     if (m_nType & FN_MASK_SEPARATE)
     281           0 :         pDivision = GetEndnoteDivision(pDivision);
     282             :     // Don't use a division that's specifically for endnotes
     283             :     else
     284             :     {
     285           0 :         while (pDivision)
     286             :         {
     287           0 :             if (pDivision->GetEndnoteType() == FN_DONTCARE)
     288           0 :                 break;
     289           0 :             if (m_nType == FN_DIVISIONGROUP)
     290           0 :                 pDivision = pDivision->GetPreviousInGroup();
     291             :             else
     292           0 :                 pDivision = pDivision->GetPreviousDivisionWithContents();
     293             :         }
     294             :     }
     295           0 :     if (pDivision)
     296           0 :         return pDivision;
     297           0 :     return NULL;
     298             : }
     299             : 
     300             : /**
     301             :  * @descr  Get division which endnote table contains current endnote content, copy from lwp source code
     302             :  */
     303           0 : LwpDocument* LwpFootnote::GetEndnoteDivision(LwpDocument* pPossible)
     304             : {
     305           0 :     LwpDocument*  pDivision = pPossible;
     306             :     sal_uInt16 nDivType;
     307             : 
     308             :     // In case we have multiple endnote divisions, walk backwards until
     309             :     // we find one.
     310           0 :     while (pDivision)
     311             :     {
     312             :         // Do we already have the right division?
     313           0 :         nDivType = pDivision->GetEndnoteType();
     314           0 :         if (nDivType == m_nType)
     315           0 :             return pDivision;
     316             :         // When we hit the first non-endnote division, stop looking.
     317             :         // -- SDC 10/8/96
     318           0 :         if (nDivType == FN_DONTCARE)
     319           0 :             break;
     320           0 :         pDivision = pDivision->GetPreviousDivision();
     321             :     }
     322           0 :     return NULL;
     323             : }
     324             : 
     325             : /**
     326             :  * @descr  Get footnote table class name
     327             :  */
     328           0 : OUString LwpFootnote::GetTableClass()
     329             : {
     330           0 :     OUString strClassName;
     331           0 :     switch (GetType() & FN_MASK_BASE)
     332             :     {
     333             :         case FN_BASE_FOOTNOTE:
     334             :         {
     335           0 :             strClassName = STR_DivisionFootnote;
     336           0 :             break;
     337             :         }
     338             :         case FN_BASE_DOCUMENT:
     339             :         {
     340           0 :             strClassName = STR_DocumentEndnote;
     341           0 :             break;
     342             :         }
     343             :         case FN_BASE_DIVISION:
     344             :         {
     345           0 :             strClassName = STR_DivisionEndnote;
     346           0 :             break;
     347             :         }
     348             :         case FN_BASE_DIVISIONGROUP:
     349             :         {
     350           0 :             strClassName = STR_DivisionGroupEndnote;
     351           0 :             break;
     352             :         }
     353             :     }
     354           0 :     return strClassName;
     355             : }
     356             : 
     357             : /**
     358             :  * @descr  Find footnote tablelayout, copy from lwp source code
     359             :  */
     360           0 : LwpEnSuperTableLayout* LwpFootnote::FindFootnoteTableLayout()
     361             : {
     362           0 :     LwpDocument* pDivision = GetFootnoteTableDivision();
     363           0 :     if(!pDivision)
     364           0 :         return NULL;
     365             : 
     366           0 :     LwpFoundry* pFoundry = pDivision->GetFoundry();
     367           0 :     OUString strClassName = GetTableClass();
     368           0 :     if(strClassName.isEmpty() )
     369           0 :         return NULL;
     370             : 
     371           0 :     LwpContent* pContent = NULL;
     372             : 
     373           0 :     while ((pContent = pFoundry->EnumContents(pContent)) != NULL)
     374           0 :         if (pContent->IsTable() && (strClassName.equals(pContent->GetClassName())) &&
     375           0 :             pContent->IsActive() && pContent->GetLayout(NULL))
     376             :         {
     377             :             // Found it!
     378             :             return static_cast<LwpEnSuperTableLayout *>(
     379           0 :                 static_cast<LwpTable*>(pContent)->GetSuperTableLayout());
     380             :         }
     381             : 
     382           0 :     return NULL;
     383             : }
     384             : 
     385             : /**
     386             :  * @descr  Find footnote contents
     387             :  */
     388           4 : LwpContent* LwpFootnote::FindFootnoteContent()
     389             : {
     390           4 :     LwpContent* pContent = dynamic_cast<LwpContent*>(m_Content.obj().get());
     391             :     //if the content has layout, the content has footnote contents;
     392             :     //or looking for the celllayout and return the footnote contents.
     393           4 :     if(pContent && pContent->GetLayout(NULL))
     394           4 :         return pContent;
     395             : 
     396           0 :     LwpCellLayout* pCellLayout = GetCellLayout();
     397           0 :     if(pCellLayout)
     398             :     {
     399           0 :         pContent = dynamic_cast<LwpContent*>(pCellLayout->GetContent().obj().get());
     400             :     }
     401             : 
     402           0 :     return pContent;
     403             : }
     404             : 
     405           2 : LwpFootnoteTable::LwpFootnoteTable(LwpObjectHeader &objHdr, LwpSvStream *pStrm)
     406           2 :     : LwpTable(objHdr, pStrm)
     407             : {
     408           2 : }
     409             : 
     410           2 : void LwpFootnoteTable::Read()
     411             : {
     412           2 :     LwpTable::Read();
     413           2 :     m_pObjStrm->SkipExtra();
     414           2 : }
     415             : 
     416             : /**
     417             :  * @descr  Read footnote number options information
     418             :  */
     419          32 : void LwpFootnoteNumberOptions::Read(LwpObjectStream *pObjStrm)
     420             : {
     421          32 :     m_nFlag = pObjStrm->QuickReaduInt16();
     422          32 :     m_nStartingNumber = pObjStrm->QuickReaduInt16();
     423          32 :     m_LeadingText.Read(pObjStrm);
     424          32 :     m_TrailingText.Read(pObjStrm);
     425          32 :     pObjStrm->SkipExtra();
     426          32 : }
     427             : 
     428             : /**
     429             :  * @descr  Read footnote separator options information
     430             :  */
     431          16 : void LwpFootnoteSeparatorOptions::Read(LwpObjectStream *pObjStrm)
     432             : {
     433          16 :     m_nFlag = pObjStrm->QuickReaduInt16();
     434          16 :     m_nLength = pObjStrm->QuickReaduInt32();
     435          16 :     m_nIndent = pObjStrm->QuickReaduInt32();
     436          16 :     m_nAbove = pObjStrm->QuickReaduInt32();
     437          16 :     m_nBelow = pObjStrm->QuickReaduInt32();
     438          16 :     m_BorderStuff.Read(pObjStrm);
     439          16 :     pObjStrm->SkipExtra();
     440          16 : }
     441             : 
     442           8 : LwpFootnoteOptions::LwpFootnoteOptions(LwpObjectHeader &objHdr, LwpSvStream *pStrm)
     443             :     : LwpObject(objHdr, pStrm)
     444           8 :     , m_nFlag(0)
     445             : {
     446           8 : }
     447             : 
     448          16 : LwpFootnoteOptions::~LwpFootnoteOptions()
     449             : {
     450             : 
     451          16 : }
     452             : 
     453             : /**
     454             :  * @descr  Register footnote options object
     455             :  */
     456           8 : void LwpFootnoteOptions::Read()
     457             : {
     458           8 :     m_nFlag = m_pObjStrm->QuickReaduInt16();
     459           8 :     m_FootnoteNumbering.Read(m_pObjStrm);
     460           8 :     m_EndnoteDivisionNumbering.Read(m_pObjStrm);
     461           8 :     m_EndnoteDivisionGroupNumbering.Read(m_pObjStrm);
     462           8 :     m_EndnoteDocNumbering.Read(m_pObjStrm);
     463           8 :     m_FootnoteSeparator.Read(m_pObjStrm);
     464           8 :     m_FootnoteContinuedSeparator.Read(m_pObjStrm);
     465           8 :     m_ContinuedOnMessage.Read(m_pObjStrm);
     466           8 :     m_ContinuedFromMessage.Read(m_pObjStrm);
     467           8 :     m_pObjStrm->SkipExtra();
     468           8 : }
     469             : 
     470             : /**
     471             :  * @descr  Register footnote options style
     472             :  */
     473           8 : void LwpFootnoteOptions::RegisterStyle()
     474             : {
     475           8 :     RegisterFootnoteStyle();
     476           8 :     RegisterEndnoteStyle();
     477           8 : }
     478             : 
     479             : /**
     480             :  * @descr  Register footnote configuration information
     481             :  */
     482           8 : void LwpFootnoteOptions::RegisterFootnoteStyle()
     483             : {
     484           8 :     XFFootnoteConfig* pFootnoteConfig = new XFFootnoteConfig();
     485           8 :     pFootnoteConfig->SetStartValue(m_FootnoteNumbering.GetStartingNumber() -1);
     486           8 :     pFootnoteConfig->SetNumPrefix(m_FootnoteNumbering.GetLeadingText());
     487           8 :     pFootnoteConfig->SetNumSuffix(m_FootnoteNumbering.GetTrailingText());
     488           8 :     if(m_FootnoteNumbering.GetReset() == LwpFootnoteNumberOptions::RESET_PAGE)
     489             :     {
     490           0 :         pFootnoteConfig->SetRestartOnPage();
     491             :     }
     492           8 :     if(GetContinuedFrom())
     493             :     {
     494           0 :         pFootnoteConfig->SetMessageFrom(GetContinuedFromMessage());
     495             :     }
     496           8 :     if(GetContinuedOn())
     497             :     {
     498           0 :         pFootnoteConfig->SetMessageOn(GetContinuedOnMessage());
     499             :     }
     500             : 
     501           8 :     pFootnoteConfig->SetMasterPage( m_strMasterPage);
     502           8 :     XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
     503           8 :     pXFStyleManager->SetFootnoteConfig(pFootnoteConfig);
     504             : 
     505           8 : }
     506             : 
     507             : /**
     508             :  * @descr  Register endnote configuration information
     509             :  */
     510           8 : void LwpFootnoteOptions::RegisterEndnoteStyle()
     511             : {
     512           8 :     XFEndnoteConfig* pEndnoteConfig = new XFEndnoteConfig();
     513           8 :     pEndnoteConfig->SetStartValue(m_EndnoteDocNumbering.GetStartingNumber() -1);
     514           8 :     OUString message = m_EndnoteDocNumbering.GetLeadingText();
     515           8 :     if(message.isEmpty())
     516             :     {
     517           8 :         message = "[";//default prefix
     518             :     }
     519           8 :     pEndnoteConfig->SetNumPrefix(message);
     520           8 :     message = m_EndnoteDocNumbering.GetTrailingText();
     521           8 :     if(message.isEmpty())
     522             :     {
     523           8 :         message = "]";//default suffix
     524             :     }
     525           8 :     pEndnoteConfig->SetNumSuffix(message);
     526           8 :     if(m_EndnoteDocNumbering.GetReset() == LwpFootnoteNumberOptions::RESET_PAGE)
     527             :     {
     528           0 :         pEndnoteConfig->SetRestartOnPage();
     529             :     }
     530             : 
     531           8 :     pEndnoteConfig->SetMasterPage( m_strMasterPage);
     532             : 
     533           8 :     XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
     534           8 :     pXFStyleManager->SetEndnoteConfig(pEndnoteConfig);
     535           8 : }
     536             : 
     537             : /**
     538             :  * @descr  Get continue on message
     539             :  */
     540           0 : OUString LwpFootnoteOptions::GetContinuedOnMessage()
     541             : {
     542           0 :     if(m_ContinuedOnMessage.HasValue())
     543             :     {
     544           0 :         return m_ContinuedOnMessage.str();
     545             :     }
     546             :     // else reture defauls message
     547           0 :     return OUString(STRID_FOOTCONTINUEDON);
     548             : }
     549             : 
     550             : /**
     551             :  * @descr  Get continue from message
     552             :  */
     553           0 : OUString LwpFootnoteOptions::GetContinuedFromMessage()
     554             : {
     555           0 :     if(m_ContinuedFromMessage.HasValue())
     556             :     {
     557           0 :         return m_ContinuedFromMessage.str();
     558             :     }
     559             :     // else reture defauls message
     560           0 :     return OUString(STRID_FOOTCONTINUEDFROM);
     561             : }
     562             : 
     563             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10