LCOV - code coverage report
Current view: top level - libreoffice/lotuswordpro/source/filter - lwptoc.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 170 0.0 %
Date: 2012-12-27 Functions: 0 19 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             :  *  For LWP filter architecture prototype - TOC related object
      59             :  */
      60             : /*************************************************************************
      61             :  * Change History
      62             :  April 2005         Created
      63             :  April 2005         Modified
      64             :  April 2005                 Modified - add LwpTocLevelData class
      65             :  ************************************************************************/
      66             : #include "lwptoc.hxx"
      67             : #include "lwpfoundry.hxx"
      68             : #include "lwpdoc.hxx"
      69             : #include "lwpframelayout.hxx"
      70             : #include "lwpglobalmgr.hxx"
      71             : 
      72             : #include "xfilter/xffont.hxx"
      73             : #include "xfilter/xftextstyle.hxx"
      74             : #include "xfilter/xfstylemanager.hxx"
      75             : #include "xfilter/xfparagraph.hxx"
      76             : #include "xfilter/xfparastyle.hxx"
      77             : #include "xfilter/xfindex.hxx"
      78             : #include    "xfilter/xffloatframe.hxx"
      79             : #include "xfilter/xfframestyle.hxx"
      80             : #include "xfilter/xfframe.hxx"
      81             : #include "xfilter/xftable.hxx"
      82             : 
      83           0 : LwpTocSuperLayout::LwpTocSuperLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
      84           0 :     : LwpSuperTableLayout(objHdr, pStrm)
      85           0 : {}
      86             : 
      87           0 : LwpTocSuperLayout::~LwpTocSuperLayout()
      88           0 : {}
      89             : /**
      90             :  * @short   Read TOCSUPERTABLELAYOUT object
      91             :  * @return  none
      92             :  */
      93           0 : void LwpTocSuperLayout::Read()
      94             : {
      95           0 :     LwpSuperTableLayout::Read();
      96           0 :     m_TextMarker.Read(m_pObjStrm);
      97           0 :     m_ParentName.Read(m_pObjStrm);
      98           0 :     m_DivisionName.Read(m_pObjStrm);
      99           0 :     m_SectionName.Read(m_pObjStrm);
     100           0 :     m_nFrom = m_pObjStrm->QuickReaduInt16();
     101             : 
     102           0 :     m_SearchItems.Read(m_pObjStrm);
     103             : 
     104             :     sal_uInt16 i;
     105           0 :     sal_uInt16 count = m_pObjStrm->QuickReaduInt16();
     106           0 :     for (i = 0; (i < MAX_LEVELS) && (count > 0); i++, count--)
     107           0 :         m_DestName[i].Read(m_pObjStrm);
     108             : 
     109           0 :     count = m_pObjStrm->QuickReaduInt16();
     110           0 :     for (i = 0; (i < MAX_LEVELS) && (count > 0); i++, count--)
     111           0 :         m_DestPGName[i].Read(m_pObjStrm);
     112             : 
     113           0 :     count = m_pObjStrm->QuickReaduInt16();
     114           0 :     for (i = 0; i < count; i++)
     115           0 :         m_nFlags[i] = m_pObjStrm->QuickReaduInt32();
     116             : 
     117           0 :     m_pObjStrm->SkipExtra();
     118           0 : }
     119             : /**
     120             :  * @short   Register style of TOC
     121             :  * @return  none
     122             :  */
     123           0 : void LwpTocSuperLayout::RegisterStyle()
     124             : {
     125           0 :     LwpSuperTableLayout::RegisterStyle();
     126             : 
     127             :     // Get font info of default text style and set into tab style
     128           0 :     XFParaStyle* pBaseStyle = static_cast<XFParaStyle*>(m_pFoundry->GetStyleManager()->GetStyle(*m_pFoundry->GetDefaultTextStyle()));
     129           0 :     XFTextStyle*pTextStyle = new XFTextStyle;
     130           0 :     pTextStyle->SetFont(pBaseStyle->GetFont()); // who delete this font?????
     131           0 :     XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
     132           0 :     m_TabStyleName = pXFStyleManager->AddStyle(pTextStyle)->GetStyleName();
     133             : 
     134           0 : }
     135             : /**
     136             :  * @short   Convert TOC
     137             :  * @param  pCont - container
     138             :  * @return none
     139             :  */
     140           0 : void  LwpTocSuperLayout::XFConvert(XFContentContainer* pCont)
     141             : {
     142           0 :     XFIndex* pToc = new XFIndex();
     143             : 
     144           0 :     pToc->SetProtected(sal_False);
     145           0 :     pToc->SetIndexType(enumXFIndexTOC);
     146             : 
     147             :     // add TOC template
     148           0 :     for (sal_uInt16 i = 1; i<= MAX_LEVELS; i++)
     149             :     {
     150           0 :         LwpTocLevelData * pLevel = GetSearchLevelPtr(i);
     151           0 :         XFIndexTemplate * pTemplate = new XFIndexTemplate();
     152             : 
     153           0 :         if(!pLevel)
     154             :         {
     155             :             // add an blank template so that SODC won't add default style to this level
     156           0 :             pToc->AddTemplate(Int32ToOUString(i),  rtl::OUString(), pTemplate);
     157           0 :             continue;
     158             :         }
     159             : 
     160           0 :         sal_Bool bInserted = sal_False;
     161           0 :         do
     162             :         {
     163             :             // One level has 1 template
     164           0 :             if (!bInserted)
     165             :             {
     166           0 :                 pTemplate->SetLevel(Int32ToOUString(i));
     167           0 :                 if(pLevel->GetUseLeadingText())
     168             :                 {
     169           0 :                     pTemplate->AddEntry(enumXFIndexTemplateChapter, pLevel->GetSearchStyle());
     170             :                 }
     171           0 :                 if(pLevel->GetUseText())
     172             :                 {
     173           0 :                     pTemplate->AddEntry(enumXFIndexTemplateText, pLevel->GetSearchStyle());
     174             :                 }
     175           0 :                 if(GetUsePageNumber(i))
     176             :                 {
     177           0 :                     sal_uInt16 nLeaderType = GetSeparatorType(i);
     178           0 :                     if (GetRightAlignPageNumber(i))
     179             :                     {
     180           0 :                         char cSep = ' ';
     181           0 :                         switch(nLeaderType)
     182             :                         {
     183             :                         default: // go through
     184             :                         case NONE: // no leaders
     185           0 :                             cSep = ' ';
     186           0 :                             break;
     187             :                         case LEADERDOTS:
     188           0 :                             cSep = '.';
     189           0 :                             break;
     190             :                         case LEADERDASHES:
     191           0 :                             cSep = '-';
     192           0 :                             break;
     193             :                         case LEADERUNDERLINE:
     194           0 :                             cSep = '_';
     195           0 :                             break;
     196             :                         }
     197             : 
     198           0 :                         pTemplate->AddTabEntry(enumXFTabRight, 0, cSep, 'd', m_TabStyleName);
     199             :                     }
     200             :                     else
     201             :                     {
     202             :                         char sSep[8];
     203           0 :                         switch(nLeaderType)
     204             :                         {
     205             :                         default: // go through
     206             :                         case NONE: // no leaders
     207           0 :                             strcpy(sSep, "  ");
     208           0 :                             break;
     209             :                         case SEPARATORCOMMA:
     210           0 :                             strcpy(sSep, ", ");
     211           0 :                             break;
     212             :                         case SEPARATORDOTS:
     213           0 :                             strcpy(sSep, "...");
     214           0 :                             break;
     215             :                         }
     216           0 :                         pTemplate->AddTextEntry(A2OUSTR(sSep), m_TabStyleName);
     217             :                     }
     218             :                     //"TOC Page Number Text Style" style always exists in Word Pro file
     219           0 :                     pTemplate->AddEntry(enumXFIndexTemplatePage, A2OUSTR("TOC Page Number Text Style"));
     220             :                 }
     221             : 
     222           0 :                 pToc->AddTemplate(Int16ToOUString(i),  m_pFoundry->FindActuralStyleName(pLevel->GetSearchStyle()), pTemplate);
     223           0 :                 bInserted = sal_True;
     224             :             }
     225             : 
     226             :             // 1 style in WordPro may be mapped to several styles in SODC
     227           0 :             LwpDocument * pDocument = m_pFoundry->GetDocument()->GetRootDocument();
     228           0 :             AddSourceStyle(pToc, pLevel,  pDocument->GetFoundry());
     229             : 
     230             :             // one level may have several corresponding Styles
     231           0 :             pLevel = GetNextSearchLevelPtr(i, pLevel);  // find next LwpTocLevelData which is same index
     232             :         }while (pLevel != NULL);
     233             :     }
     234             : 
     235           0 :     m_pCont = pCont;
     236             :     // add TOC content
     237           0 :     LwpSuperTableLayout::XFConvert(pToc);
     238             : 
     239             :     // if current TOC is located in a cell, we must add a frame between upper level container and TOC
     240           0 :     if ( !GetContainerLayout()->IsCell() )
     241             :     {
     242           0 :         pCont->Add(pToc);
     243             :     }
     244           0 : }
     245             : 
     246             : /**
     247             :  * @short   convert frame which anchor to page
     248             :  * @param pCont -
     249             :  * @return
     250             :  */
     251           0 : void  LwpTocSuperLayout::XFConvertFrame(XFContentContainer* pCont, sal_Int32 nStart , sal_Int32 nEnd , sal_Bool bAll)
     252             : {
     253           0 :     if(m_pFrame)
     254             :     {
     255           0 :         XFFrame* pXFFrame = NULL;
     256           0 :         if(nEnd < nStart)
     257             :         {
     258           0 :             pXFFrame = new XFFrame();
     259             :         }
     260             :         else
     261             :         {
     262           0 :             pXFFrame = new XFFloatFrame(nStart, nEnd, bAll);
     263             :         }
     264             : 
     265           0 :         m_pFrame->Parse(pXFFrame, static_cast<sal_uInt16>(nStart));
     266             : 
     267             :         //parse table, and add table to frame or TOC
     268           0 :         LwpTableLayout * pTableLayout = GetTableLayout();
     269           0 :         if (pTableLayout)
     270             :         {
     271           0 :             XFContentContainer * pTableContainer = pXFFrame;
     272             :             // if *this is a TOCSuperTableLayout and it's located in a cell
     273             :             // add the frame to upper level and add TOCSuperTableLayout into the frame
     274           0 :             if ( GetContainerLayout()->IsCell() )
     275             :             {
     276           0 :                 pTableContainer = pCont; // TOC contain table directly
     277           0 :                 pXFFrame->Add(pCont);
     278           0 :                 m_pCont->Add(pXFFrame);
     279             :             }
     280             :             else
     281             :             {
     282             :                 //add frame to the container
     283           0 :                 pCont ->Add(pXFFrame);
     284             :             }
     285           0 :             pTableLayout->XFConvert(pTableContainer);
     286             :         }
     287             :     }
     288             : 
     289           0 : }
     290             : 
     291             : /**
     292             :  * @short   Add source style into TOC
     293             :  * @param  pToc - TOC pointer
     294             :  * @param  pLevel - TOC level data
     295             :  * @param  pFoundry - foundry pointer
     296             :  * @return sal_Bool
     297             :  */
     298           0 : void LwpTocSuperLayout::AddSourceStyle(XFIndex* pToc, LwpTocLevelData * pLevel, LwpFoundry * pFoundry)
     299             : {
     300           0 :     if (!pLevel)
     301             :     {
     302           0 :         return;
     303             :     }
     304             : 
     305           0 :     OUString sLwpStyleName = pLevel->GetSearchStyle();
     306             : 
     307           0 :     if (pFoundry)
     308             :     {
     309           0 :         LwpDocument * pDoc = pFoundry->GetDocument();
     310           0 :         if (pDoc && pDoc->IsChildDoc())
     311             :         {
     312           0 :             OUString sSodcStyleName = pFoundry->FindActuralStyleName(sLwpStyleName);
     313           0 :             pToc->AddTocSource(pLevel->GetLevel(), sSodcStyleName);
     314             :         }
     315             :         else
     316             :         {
     317           0 :             pDoc = pDoc->GetFirstDivision();
     318           0 :             while (pDoc)
     319             :             {
     320           0 :                 AddSourceStyle(pToc, pLevel, pDoc->GetFoundry() );
     321           0 :                 pDoc = pDoc->GetNextDivision();
     322             :             }
     323             :         }
     324           0 :     }
     325             : }
     326             : 
     327             : /**
     328             :  * @short   Get whether page number is right alignment
     329             :  * @param  index - TOC level
     330             :  * @return sal_Bool
     331             :  */
     332           0 : sal_Bool LwpTocSuperLayout::GetRightAlignPageNumber(sal_uInt16 index)
     333             : {
     334           0 :     if (index < MAX_LEVELS)
     335           0 :         return (m_nFlags[index] & TS_RIGHTALIGN) ? sal_True : sal_False;
     336           0 :     return sal_False;
     337             : }
     338             : /**
     339             :  * @short   Get whether page number is used in TOC entries
     340             :  * @param  index - TOC level
     341             :  * @return sal_Bool
     342             :  */
     343           0 : sal_Bool LwpTocSuperLayout::GetUsePageNumber(sal_uInt16 index)
     344             : {
     345           0 :     if (index < MAX_LEVELS)
     346           0 :         return (m_nFlags[index] & TS_PAGENUMBER) ? sal_True : sal_False;
     347           0 :     return sal_False;
     348             : }
     349             : /**
     350             :  * @short   Get what is used for separater
     351             :  * @param  index - TOC level
     352             :  * @return sal_uInt16 - separator type
     353             :  */
     354           0 : sal_uInt16 LwpTocSuperLayout::GetSeparatorType(sal_uInt16 index)
     355             : {
     356           0 :     sal_uInt16 Flag = (sal_uInt16)m_nFlags[index];
     357             : 
     358           0 :     if (Flag & TS_LEADERDOTS)
     359           0 :         return LEADERDOTS;
     360           0 :     else if (Flag & TS_LEADERDASHES)
     361           0 :         return LEADERDASHES;
     362           0 :     else if (Flag & TS_LEADERUNDERLINE)
     363           0 :         return LEADERUNDERLINE;
     364           0 :     else if (Flag & TS_SEPARATORCOMMA)
     365           0 :         return SEPARATORCOMMA;
     366           0 :     else if (Flag & TS_SEPARATORDOTS)
     367           0 :         return SEPARATORDOTS;
     368             :     else
     369           0 :         return NONE;
     370             : }
     371             : 
     372             : /**
     373             :  * @short   Get TOCLEVELDATA obj
     374             :  * @param  index - TOC level
     375             :  * @return LwpTocLevelData * - pointer to TOCLEVELDATA obj
     376             :  */
     377           0 : LwpTocLevelData * LwpTocSuperLayout::GetSearchLevelPtr(sal_uInt16 index)
     378             : {
     379           0 :     LwpObjectID * pID = m_SearchItems.GetHead(); // not necessary to check pID NULL or not
     380           0 :     LwpTocLevelData * pObj = dynamic_cast<LwpTocLevelData *>(pID->obj());
     381             : 
     382           0 :     while(pObj)
     383             :     {
     384           0 :         if(pObj->GetLevel()== index)
     385             :         {
     386           0 :             return pObj;
     387             :         }
     388             : 
     389           0 :         pID = pObj->GetNext(); // not necessary to check pID NULL or not
     390           0 :         pObj = dynamic_cast<LwpTocLevelData *>(pID->obj());
     391             :     }
     392             : 
     393           0 :     return NULL;
     394             : }
     395             : /**
     396             :  * @short   Get next TOCLEVELDATA obj from current position
     397             :  * @param  index - TOC level
     398             :  * @param  pCurData - current LwpTocLevelData
     399             :  * @return LwpTocLevelData * - pointer to TOCLEVELDATA obj
     400             :  */
     401           0 : LwpTocLevelData * LwpTocSuperLayout::GetNextSearchLevelPtr(sal_uInt16 index, LwpTocLevelData * pCurData)
     402             : {
     403           0 :     LwpObjectID * pID = pCurData->GetNext();
     404           0 :     LwpTocLevelData * pObj = dynamic_cast<LwpTocLevelData *>(pID->obj());
     405             : 
     406           0 :     while(pObj)
     407             :     {
     408           0 :         if(pObj->GetLevel()== index)
     409             :         {
     410           0 :             return pObj;
     411             :         }
     412             : 
     413           0 :         pID = pObj->GetNext(); // not necessary to check pID NULL or not
     414           0 :         pObj = dynamic_cast<LwpTocLevelData *>(pID->obj());
     415             :     }
     416             : 
     417           0 :     return NULL;
     418             : }
     419             : 
     420           0 : LwpTocLevelData::LwpTocLevelData(LwpObjectHeader &objHdr, LwpSvStream* pStrm):LwpDLVList(objHdr, pStrm)
     421             : {
     422           0 :     m_nFlags = 0;
     423           0 :     m_nLevel = 0;
     424           0 : }
     425           0 : LwpTocLevelData::~LwpTocLevelData()
     426             : {
     427           0 : }
     428             : /**
     429             :  * @short   Register style
     430             :  * @param
     431             :  * @return
     432             :  */
     433           0 : void LwpTocLevelData::RegisterStyle()
     434             : {
     435           0 : }
     436             : /**
     437             :  * @short   Convert
     438             :  * @param  pCont - container
     439             :  * @return none
     440             :  */
     441           0 : void LwpTocLevelData::XFConvert(XFContentContainer* /*pCont*/)
     442             : {
     443           0 : }
     444             : /**
     445             :  * @short   Read TOCLEVELDATA obj
     446             :  * @param
     447             :  * @return
     448             :  */
     449           0 : void LwpTocLevelData::Read()
     450             : {
     451           0 :     LwpDLVList::Read();
     452           0 :     m_nFlags = m_pObjStrm->QuickReaduInt16();
     453           0 :     m_nLevel = m_pObjStrm->QuickReaduInt16();
     454           0 :     m_SearchName.Read(m_pObjStrm);
     455             : 
     456           0 :     m_pObjStrm->SkipExtra();
     457           0 : }
     458             : 
     459             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10