LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sw/source/filter/xml - xmltble.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 3 543 0.6 %
Date: 2013-07-09 Functions: 3 41 7.3 %
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             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include <com/sun/star/text/XTextTable.hpp>
      22             : #include <com/sun/star/text/XTextSection.hpp>
      23             : 
      24             : #include <hintids.hxx>
      25             : #include <rtl/ustrbuf.hxx>
      26             : #include <xmloff/xmlnmspe.hxx>
      27             : #include <xmloff/xmltoken.hxx>
      28             : #include <xmloff/xmluconv.hxx>
      29             : #include <xmloff/numehelp.hxx>
      30             : #include <svl/zforlist.hxx>
      31             : #include <editeng/brushitem.hxx>
      32             : #include <editeng/boxitem.hxx>
      33             : #include <fmtrowsplt.hxx>
      34             : #include <editeng/frmdiritem.hxx>
      35             : #include <list>
      36             : #include "swtable.hxx"
      37             : #include "doc.hxx"
      38             : #include "pam.hxx"
      39             : #include "frmfmt.hxx"
      40             : #include "wrtswtbl.hxx"
      41             : #include "fmtfsize.hxx"
      42             : #include "fmtornt.hxx"
      43             : #include "cellatr.hxx"
      44             : #include "ddefld.hxx"
      45             : #include "swddetbl.hxx"
      46             : #include <ndole.hxx>
      47             : #include <xmloff/nmspmap.hxx>
      48             : #include <sfx2/linkmgr.hxx>  // for cTokenSeparator
      49             : #include "unotbl.hxx"
      50             : #include "xmltexte.hxx"
      51             : #include "xmlexp.hxx"
      52             : #include <boost/foreach.hpp>
      53             : #include <o3tl/sorted_vector.hxx>
      54             : 
      55             : using namespace ::com::sun::star;
      56             : using namespace ::com::sun::star::uno;
      57             : using namespace ::com::sun::star::text;
      58             : using namespace ::com::sun::star::beans;
      59             : using namespace ::com::sun::star::lang;
      60             : using namespace ::com::sun::star::container;
      61             : using namespace ::xmloff::token;
      62             : using table::XCell;
      63             : using ::std::vector;
      64             : using ::std::advance;
      65             : 
      66           0 : class SwXMLTableColumn_Impl : public SwWriteTableCol
      67             : {
      68             :     OUString    sStyleName;
      69             :     sal_uInt32  nRelWidth;
      70             : 
      71             : public:
      72             : 
      73             : 
      74           0 :     SwXMLTableColumn_Impl( sal_uInt32 nPosition ) :
      75             :         SwWriteTableCol( nPosition ),
      76           0 :         nRelWidth( 0UL )
      77           0 :     {};
      78             : 
      79           0 :     void SetStyleName( const OUString& rName ) { sStyleName = rName; }
      80           0 :     const OUString& GetStyleName() const { return sStyleName; }
      81             : 
      82           0 :     void SetRelWidth( sal_uInt32 nSet ) { nRelWidth = nSet; }
      83           0 :     sal_uInt32 GetRelWidth() const { return nRelWidth; }
      84             : };
      85             : 
      86             : struct SwXMLTableColumnCmpWidth_Impl
      87             : {
      88           0 :     bool operator()( SwXMLTableColumn_Impl* const& lhs, SwXMLTableColumn_Impl* const& rhs ) const
      89             :     {
      90           0 :         sal_Int32 n = (sal_Int32)lhs->GetWidthOpt() - (sal_Int32)rhs->GetWidthOpt();
      91           0 :         if( !n )
      92           0 :             n = (sal_Int32)lhs->GetRelWidth() - (sal_Int32)rhs->GetRelWidth();
      93           0 :         return n < 0;
      94             :     }
      95             : };
      96             : 
      97             : // ---------------------------------------------------------------------
      98             : 
      99           0 : class SwXMLTableColumns_Impl : public o3tl::sorted_vector<SwXMLTableColumn_Impl*, o3tl::less_ptr_to<SwXMLTableColumn_Impl> > {
     100             : public:
     101           0 :     ~SwXMLTableColumns_Impl() { DeleteAndDestroyAll(); }
     102             : };
     103             : 
     104           0 : class SwXMLTableColumnsSortByWidth_Impl : public o3tl::sorted_vector<SwXMLTableColumn_Impl*, SwXMLTableColumnCmpWidth_Impl> {};
     105             : 
     106             : class SwXMLTableLines_Impl
     107             : {
     108             :     SwXMLTableColumns_Impl  aCols;
     109             :     const SwTableLines      *pLines;
     110             :     sal_uInt32              nWidth;
     111             : 
     112             : public:
     113             : 
     114             :     SwXMLTableLines_Impl( const SwTableLines& rLines );
     115             : 
     116           0 :     ~SwXMLTableLines_Impl() {}
     117             : 
     118           0 :     sal_uInt32 GetWidth() const { return nWidth; }
     119           0 :     const SwTableLines *GetLines() const { return pLines; }
     120             : 
     121           0 :     const SwXMLTableColumns_Impl& GetColumns() const { return aCols; }
     122             : };
     123             : 
     124           0 : SwXMLTableLines_Impl::SwXMLTableLines_Impl( const SwTableLines& rLines ) :
     125             :     pLines( &rLines ),
     126           0 :     nWidth( 0UL )
     127             : {
     128             : #if OSL_DEBUG_LEVEL > 0
     129             :     sal_uInt32 nEndCPos = 0U;
     130             : #endif
     131           0 :     sal_uInt16 nLines = rLines.size();
     132             :     sal_uInt16 nLine;
     133           0 :     for( nLine=0U; nLine<nLines; nLine++ )
     134             :     {
     135           0 :         const SwTableLine *pLine = rLines[nLine];
     136           0 :         const SwTableBoxes& rBoxes = pLine->GetTabBoxes();
     137           0 :         sal_uInt16 nBoxes = rBoxes.size();
     138             : 
     139           0 :         sal_uInt32 nCPos = 0U;
     140           0 :         for( sal_uInt16 nBox=0U; nBox<nBoxes; nBox++ )
     141             :         {
     142           0 :             const SwTableBox *pBox = rBoxes[nBox];
     143             : 
     144           0 :             if( nBox < nBoxes-1U || nWidth==0UL )
     145             :             {
     146           0 :                 nCPos = nCPos + SwWriteTable::GetBoxWidth( pBox );
     147             :                 SwXMLTableColumn_Impl *pCol =
     148           0 :                     new SwXMLTableColumn_Impl( nCPos );
     149             : 
     150           0 :                 if( !aCols.insert( pCol ).second )
     151           0 :                     delete pCol;
     152             : 
     153           0 :                 if( nBox==nBoxes-1U )
     154             :                 {
     155             :                     OSL_ENSURE( nLine==0U && nWidth==0UL,
     156             :                             "parent width will be lost" );
     157           0 :                     nWidth = nCPos;
     158           0 :                 }
     159             :             }
     160             :             else
     161             :             {
     162             : #if OSL_DEBUG_LEVEL > 0
     163             :                 sal_uInt32 nCheckPos =
     164             :                     nCPos + SwWriteTable::GetBoxWidth( pBox );
     165             :                 if( !nEndCPos )
     166             :                 {
     167             :                     nEndCPos = nCheckPos;
     168             :                 }
     169             : #endif
     170           0 :                 nCPos = nWidth;
     171             : #if OSL_DEBUG_LEVEL > 0
     172             :                 SwXMLTableColumn_Impl aCol( nWidth );
     173             :                 OSL_ENSURE( aCols.find(&aCol) != aCols.end(), "couldn't find last column" );
     174             :                 OSL_ENSURE( SwXMLTableColumn_Impl(nCheckPos) ==
     175             :                                             SwXMLTableColumn_Impl(nCPos),
     176             :                         "rows have different total widths" );
     177             : #endif
     178             :             }
     179             :         }
     180             :     }
     181           0 : }
     182             : 
     183             : // ---------------------------------------------------------------------
     184             : 
     185             : typedef vector< SwFrmFmt* > SwXMLFrmFmts_Impl;
     186             : 
     187           0 : class SwXMLTableFrmFmtsSort_Impl
     188             : {
     189             : private:
     190             :     SwXMLFrmFmts_Impl aFormatList;
     191             : 
     192             : public:
     193           0 :     SwXMLTableFrmFmtsSort_Impl ( sal_uInt16 /* nInit */, sal_uInt16 /*nGrow*/ )
     194           0 :     {}
     195             : 
     196             :     bool AddRow( SwFrmFmt& rFrmFmt, const OUString& rNamePrefix, sal_uInt32 nLine );
     197             :     bool AddCell( SwFrmFmt& rFrmFmt, const OUString& rNamePrefix,
     198             :                   sal_uInt32 nCol, sal_uInt32 nRow, sal_Bool bTop );
     199             : };
     200             : 
     201           0 : bool SwXMLTableFrmFmtsSort_Impl::AddRow( SwFrmFmt& rFrmFmt,
     202             :                                          const OUString& rNamePrefix,
     203             :                                             sal_uInt32 nLine )
     204             : {
     205           0 :     const SwFmtFrmSize *pFrmSize = 0;
     206           0 :     const SwFmtRowSplit* pRowSplit = 0;
     207           0 :     const SvxBrushItem *pBrush = 0;
     208             : 
     209           0 :     const SfxItemSet& rItemSet = rFrmFmt.GetAttrSet();
     210             :     const SfxPoolItem *pItem;
     211           0 :     if( SFX_ITEM_SET == rItemSet.GetItemState( RES_FRM_SIZE, sal_False, &pItem ) )
     212           0 :         pFrmSize = (const SwFmtFrmSize *)pItem;
     213             : 
     214           0 :     if( SFX_ITEM_SET == rItemSet.GetItemState( RES_ROW_SPLIT, sal_False, &pItem ) )
     215           0 :         pRowSplit = (const SwFmtRowSplit *)pItem;
     216             : 
     217           0 :     if( SFX_ITEM_SET == rItemSet.GetItemState( RES_BACKGROUND, sal_False, &pItem ) )
     218           0 :         pBrush = (const SvxBrushItem *)pItem;
     219             : 
     220             :     // empty styles have not to be exported
     221           0 :     if( !pFrmSize && !pBrush && !pRowSplit )
     222           0 :         return false;
     223             : 
     224             :     // order is: -/brush, size/-, size/brush
     225           0 :     bool bInsert = true;
     226           0 :     SwXMLFrmFmts_Impl::iterator i;
     227           0 :     for( i = aFormatList.begin(); i < aFormatList.end(); ++i )
     228             :     {
     229           0 :         const SwFmtFrmSize *pTestFrmSize = 0;
     230           0 :         const SwFmtRowSplit* pTestRowSplit = 0;
     231           0 :         const SvxBrushItem *pTestBrush = 0;
     232           0 :         const SwFrmFmt *pTestFmt = *i;
     233           0 :         const SfxItemSet& rTestSet = pTestFmt->GetAttrSet();
     234           0 :         if( SFX_ITEM_SET == rTestSet.GetItemState( RES_FRM_SIZE, sal_False,
     235           0 :                                                   &pItem ) )
     236             :         {
     237           0 :             if( !pFrmSize )
     238           0 :                 break;
     239             : 
     240           0 :             pTestFrmSize = (const SwFmtFrmSize *)pItem;
     241             :         }
     242             :         else
     243             :         {
     244           0 :             if( pFrmSize )
     245           0 :                 continue;
     246             :         }
     247             : 
     248           0 :         if( SFX_ITEM_SET == rTestSet.GetItemState( RES_BACKGROUND, sal_False,
     249           0 :                                                   &pItem ) )
     250             :         {
     251           0 :             if( !pBrush )
     252           0 :                 break;
     253             : 
     254           0 :             pTestBrush = (const SvxBrushItem *)pItem;
     255             :         }
     256             :         else
     257             :         {
     258           0 :             if( pBrush )
     259           0 :                 continue;
     260             :         }
     261             : 
     262           0 :         if( SFX_ITEM_SET == rTestSet.GetItemState( RES_ROW_SPLIT, sal_False,
     263           0 :                                                   &pItem ) )
     264             :         {
     265           0 :             if( !pRowSplit )
     266           0 :                 break;
     267             : 
     268           0 :             pTestRowSplit = (const SwFmtRowSplit *)pItem;
     269             :         }
     270             :         else
     271             :         {
     272           0 :             if( pRowSplit )
     273           0 :                 continue;
     274             :         }
     275             : 
     276             : 
     277           0 :         if( pFrmSize &&
     278           0 :             ( pFrmSize->GetHeightSizeType() != pTestFrmSize->GetHeightSizeType() ||
     279           0 :               pFrmSize->GetHeight() != pTestFrmSize->GetHeight() ) )
     280           0 :             continue;
     281             : 
     282           0 :         if( pBrush && (*pBrush != *pTestBrush) )
     283           0 :             continue;
     284             : 
     285           0 :         if( pRowSplit && (!pRowSplit->GetValue() != !pTestRowSplit->GetValue()) )
     286           0 :             continue;
     287             : 
     288             :         // found!
     289           0 :         const String& rFmtName = pTestFmt->GetName();
     290           0 :         rFrmFmt.SetName( rFmtName );
     291           0 :         bInsert = false;
     292           0 :         break;
     293             :     }
     294             : 
     295           0 :     if( bInsert )
     296             :     {
     297           0 :         OUStringBuffer sBuffer( rNamePrefix.getLength() + 4UL );
     298           0 :         sBuffer.append( rNamePrefix );
     299           0 :         sBuffer.append( (sal_Unicode)'.' );
     300           0 :         sBuffer.append( (sal_Int32)(nLine+1UL) );
     301             : 
     302           0 :         rFrmFmt.SetName( sBuffer.makeStringAndClear() );
     303           0 :         if ( i != aFormatList.end() ) ++i;
     304           0 :         aFormatList.insert( i, &rFrmFmt );
     305             :     }
     306             : 
     307           0 :     return bInsert;
     308             : }
     309             : 
     310             : void sw_GetTblBoxColStr( sal_uInt16 nCol, String& rNm );
     311           0 : static void lcl_xmltble_appendBoxPrefix( OUStringBuffer& rBuffer,
     312             :                                   const OUString& rNamePrefix,
     313             :                                   sal_uInt32 nCol, sal_uInt32 nRow, sal_Bool bTop )
     314             : {
     315           0 :     rBuffer.append( rNamePrefix );
     316           0 :     rBuffer.append( (sal_Unicode)'.' );
     317           0 :     if( bTop )
     318             :     {
     319           0 :         String sTmp;
     320           0 :         sw_GetTblBoxColStr( (sal_uInt16)nCol, sTmp );
     321           0 :         rBuffer.append( sTmp );
     322             :     }
     323             :     else
     324             :     {
     325           0 :         rBuffer.append( (sal_Int32)(nCol + 1));
     326           0 :         rBuffer.append( (sal_Unicode)'.' );
     327             :     }
     328           0 :     rBuffer.append( (sal_Int32)(nRow + 1));
     329           0 : }
     330             : 
     331           0 : bool SwXMLTableFrmFmtsSort_Impl::AddCell( SwFrmFmt& rFrmFmt,
     332             :                                          const OUString& rNamePrefix,
     333             :                                             sal_uInt32 nCol, sal_uInt32 nRow, sal_Bool bTop )
     334             : {
     335           0 :     const SwFmtVertOrient *pVertOrient = 0;
     336           0 :     const SvxBrushItem *pBrush = 0;
     337           0 :     const SvxBoxItem *pBox = 0;
     338           0 :     const SwTblBoxNumFormat *pNumFmt = 0;
     339           0 :     const SvxFrameDirectionItem *pFrameDir = 0;
     340             : 
     341           0 :     const SfxItemSet& rItemSet = rFrmFmt.GetAttrSet();
     342             :     const SfxPoolItem *pItem;
     343           0 :     if( SFX_ITEM_SET == rItemSet.GetItemState( RES_VERT_ORIENT, sal_False,
     344           0 :                                                &pItem ) )
     345           0 :         pVertOrient = (const SwFmtVertOrient *)pItem;
     346             : 
     347           0 :     if( SFX_ITEM_SET == rItemSet.GetItemState( RES_BACKGROUND, sal_False, &pItem ) )
     348           0 :         pBrush = (const SvxBrushItem *)pItem;
     349             : 
     350           0 :     if( SFX_ITEM_SET == rItemSet.GetItemState( RES_BOX, sal_False, &pItem ) )
     351           0 :         pBox = (const SvxBoxItem *)pItem;
     352             : 
     353           0 :     if ( SFX_ITEM_SET == rItemSet.GetItemState( RES_BOXATR_FORMAT,
     354           0 :                                                 sal_False, &pItem ) )
     355           0 :         pNumFmt = (const SwTblBoxNumFormat *)pItem;
     356           0 :     if ( SFX_ITEM_SET == rItemSet.GetItemState( RES_FRAMEDIR,
     357           0 :                                                 sal_False, &pItem ) )
     358           0 :         pFrameDir = (const SvxFrameDirectionItem *)pItem;
     359             : 
     360             :     // empty styles have not to be exported
     361           0 :     if( !pVertOrient && !pBrush && !pBox && !pNumFmt && !pFrameDir )
     362           0 :         return false;
     363             : 
     364             :     // order is: -/-/-/num,
     365             :     //           -/-/box/-, --/-/box/num,
     366             :     //           -/brush/-/-, -/brush/-/num, -/brush/box/-, -/brush/box/num,
     367             :     //           vert/-/-/-, vert/-/-/num, vert/-/box/-, ver/-/box/num,
     368             :     //           vert/brush/-/-, vert/brush/-/num, vert/brush/box/-,
     369             :     //           vert/brush/box/num
     370           0 :     bool bInsert = true;
     371           0 :     SwXMLFrmFmts_Impl::iterator i;
     372           0 :     for( i = aFormatList.begin(); i < aFormatList.end(); ++i )
     373             :     {
     374           0 :         const SwFmtVertOrient *pTestVertOrient = 0;
     375           0 :         const SvxBrushItem *pTestBrush = 0;
     376           0 :         const SvxBoxItem *pTestBox = 0;
     377           0 :         const SwTblBoxNumFormat *pTestNumFmt = 0;
     378           0 :         const SvxFrameDirectionItem *pTestFrameDir = 0;
     379           0 :         const SwFrmFmt* pTestFmt = *i;
     380           0 :         const SfxItemSet& rTestSet = pTestFmt->GetAttrSet();
     381           0 :         if( SFX_ITEM_SET == rTestSet.GetItemState( RES_VERT_ORIENT, sal_False,
     382           0 :                                                   &pItem ) )
     383             :         {
     384           0 :             if( !pVertOrient )
     385           0 :                 break;
     386             : 
     387           0 :             pTestVertOrient = (const SwFmtVertOrient *)pItem;
     388             :         }
     389             :         else
     390             :         {
     391           0 :             if( pVertOrient )
     392           0 :                 continue;
     393             :         }
     394             : 
     395           0 :         if( SFX_ITEM_SET == rTestSet.GetItemState( RES_BACKGROUND, sal_False,
     396           0 :                                                   &pItem ) )
     397             :         {
     398           0 :             if( !pBrush )
     399           0 :                 break;
     400             : 
     401           0 :             pTestBrush = (const SvxBrushItem *)pItem;
     402             :         }
     403             :         else
     404             :         {
     405           0 :             if( pBrush )
     406           0 :                 continue;
     407             :         }
     408             : 
     409           0 :         if( SFX_ITEM_SET == rTestSet.GetItemState( RES_BOX, sal_False, &pItem ) )
     410             :         {
     411           0 :             if( !pBox )
     412           0 :                 break;
     413             : 
     414           0 :             pTestBox = (const SvxBoxItem *)pItem;
     415             :         }
     416             :         else
     417             :         {
     418           0 :             if( pBox )
     419           0 :                 continue;
     420             :         }
     421             : 
     422           0 :         if ( SFX_ITEM_SET == rTestSet.GetItemState( RES_BOXATR_FORMAT,
     423           0 :                                                 sal_False, &pItem ) )
     424             :         {
     425           0 :             if( !pNumFmt )
     426           0 :                 break;
     427             : 
     428           0 :             pTestNumFmt = (const SwTblBoxNumFormat *)pItem;
     429             :         }
     430             :         else
     431             :         {
     432           0 :             if( pNumFmt )
     433           0 :                 continue;
     434             : 
     435             :         }
     436             : 
     437           0 :         if ( SFX_ITEM_SET == rTestSet.GetItemState( RES_FRAMEDIR,
     438           0 :                                                 sal_False, &pItem ) )
     439             :         {
     440           0 :             if( !pFrameDir )
     441           0 :                 break;
     442             : 
     443           0 :             pTestFrameDir = (const SvxFrameDirectionItem *)pItem;
     444             :         }
     445             :         else
     446             :         {
     447           0 :             if( pFrameDir )
     448           0 :                 continue;
     449             : 
     450             :         }
     451             : 
     452           0 :         if( pVertOrient &&
     453           0 :             pVertOrient->GetVertOrient() != pTestVertOrient->GetVertOrient() )
     454           0 :             continue;
     455             : 
     456           0 :         if( pBrush && ( *pBrush != *pTestBrush ) )
     457           0 :             continue;
     458             : 
     459           0 :         if( pBox && ( *pBox != *pTestBox ) )
     460           0 :             continue;
     461             : 
     462           0 :         if( pNumFmt && pNumFmt->GetValue() != pTestNumFmt->GetValue() )
     463           0 :             continue;
     464             : 
     465           0 :         if( pFrameDir && pFrameDir->GetValue() != pTestFrameDir->GetValue() )
     466           0 :             continue;
     467             : 
     468             :         // found!
     469           0 :         const String& rFmtName = pTestFmt->GetName();
     470           0 :         rFrmFmt.SetName( rFmtName );
     471           0 :         bInsert = false;
     472           0 :         break;
     473             :     }
     474             : 
     475           0 :     if( bInsert )
     476             :     {
     477           0 :         OUStringBuffer sBuffer( rNamePrefix.getLength() + 8UL );
     478           0 :         lcl_xmltble_appendBoxPrefix( sBuffer, rNamePrefix, nCol, nRow, bTop );
     479           0 :         rFrmFmt.SetName( sBuffer.makeStringAndClear() );
     480           0 :         if ( i != aFormatList.end() ) ++i;
     481           0 :         aFormatList.insert( i, &rFrmFmt );
     482             :     }
     483             : 
     484           0 :     return bInsert;
     485             : }
     486             : // ---------------------------------------------------------------------
     487             : 
     488           0 : class SwXMLTableInfo_Impl
     489             : {
     490             :     const SwTable *pTable;
     491             :     Reference < XTextSection > xBaseSection;
     492             :     bool bBaseSectionValid;
     493             : 
     494             : public:
     495             : 
     496             :     inline SwXMLTableInfo_Impl( const SwTable *pTbl );
     497             : 
     498           0 :     const SwTable *GetTable() const { return pTable; }
     499           0 :     const SwFrmFmt *GetTblFmt() const { return pTable->GetFrmFmt(); }
     500             : 
     501           0 :     bool IsBaseSectionValid() const { return bBaseSectionValid; }
     502           0 :     const Reference < XTextSection >& GetBaseSection() const { return xBaseSection; }
     503             :     inline void SetBaseSection( const Reference < XTextSection >& rBase );
     504             : };
     505             : 
     506           0 : inline SwXMLTableInfo_Impl::SwXMLTableInfo_Impl( const SwTable *pTbl ) :
     507             :     pTable( pTbl ),
     508           0 :     bBaseSectionValid( false )
     509             : {
     510           0 : }
     511             : 
     512           0 : inline void SwXMLTableInfo_Impl::SetBaseSection(
     513             :         const Reference < XTextSection >& rBaseSection )
     514             : {
     515           0 :     xBaseSection = rBaseSection;
     516           0 :     bBaseSectionValid = true;
     517           0 : }
     518             : 
     519             : // ---------------------------------------------------------------------
     520             : 
     521             : 
     522           0 : void SwXMLExport::ExportTableColumnStyle( const SwXMLTableColumn_Impl& rCol )
     523             : {
     524             :     // <style:style ...>
     525           0 :     CheckAttrList();
     526             : 
     527             :     // style:name="..."
     528           0 :     sal_Bool bEncoded = sal_False;
     529             :     AddAttribute( XML_NAMESPACE_STYLE, XML_NAME,
     530           0 :                     EncodeStyleName( rCol.GetStyleName(), &bEncoded ) );
     531           0 :     if( bEncoded )
     532           0 :         AddAttribute( XML_NAMESPACE_STYLE, XML_DISPLAY_NAME, rCol.GetStyleName() );
     533             : 
     534             :     // style:family="table-column"
     535           0 :     AddAttribute( XML_NAMESPACE_STYLE, XML_FAMILY, XML_TABLE_COLUMN );
     536             : 
     537             :     {
     538             :         SvXMLElementExport aElem( *this, XML_NAMESPACE_STYLE, XML_STYLE, sal_True,
     539           0 :                                   sal_True );
     540           0 :         OUStringBuffer sValue;
     541           0 :         if( rCol.GetWidthOpt() )
     542             :         {
     543           0 :             GetTwipUnitConverter().convertMeasureToXML( sValue,
     544           0 :                     rCol.GetWidthOpt() );
     545             :             AddAttribute( XML_NAMESPACE_STYLE, XML_COLUMN_WIDTH,
     546           0 :                           sValue.makeStringAndClear() );
     547             :         }
     548           0 :         if( rCol.GetRelWidth() )
     549             :         {
     550           0 :             sValue.append( (sal_Int32)rCol.GetRelWidth() );
     551           0 :             sValue.append( (sal_Unicode)'*' );
     552             :             AddAttribute( XML_NAMESPACE_STYLE, XML_REL_COLUMN_WIDTH,
     553           0 :                           sValue.makeStringAndClear() );
     554             :         }
     555             : 
     556             :         {
     557             :             SvXMLElementExport aElemExport( *this, XML_NAMESPACE_STYLE,
     558             :                                       XML_TABLE_COLUMN_PROPERTIES,
     559           0 :                                       sal_True, sal_True );
     560           0 :         }
     561             :     }
     562           0 : }
     563             : 
     564           0 : void SwXMLExport::ExportTableLinesAutoStyles( const SwTableLines& rLines,
     565             :                                     sal_uInt32 nAbsWidth, sal_uInt32 nBaseWidth,
     566             :                                     const OUString& rNamePrefix,
     567             :                                     SwXMLTableColumnsSortByWidth_Impl& rExpCols,
     568             :                                     SwXMLTableFrmFmtsSort_Impl& rExpRows,
     569             :                                     SwXMLTableFrmFmtsSort_Impl& rExpCells,
     570             :                                     SwXMLTableInfo_Impl& rTblInfo,
     571             :                                     sal_Bool bTop )
     572             : {
     573             :     // pass 1: calculate columns
     574           0 :     SwXMLTableLines_Impl *pLines = new SwXMLTableLines_Impl( rLines );
     575           0 :     if( !pTableLines )
     576           0 :         pTableLines = new SwXMLTableLinesCache_Impl();
     577             : 
     578           0 :     pTableLines->push_back( pLines );
     579             : 
     580           0 :     OUStringBuffer sBuffer( rNamePrefix.getLength() + 8L );
     581             : 
     582             :     // pass 2: export column styles
     583             :     {
     584           0 :         const SwXMLTableColumns_Impl& rCols = pLines->GetColumns();
     585           0 :         sal_uInt32 nCPos = 0U;
     586           0 :         sal_uInt16 nColumns = rCols.size();
     587           0 :         for( sal_uInt16 nColumn=0U; nColumn<nColumns; nColumn++ )
     588             :         {
     589           0 :             SwXMLTableColumn_Impl *pColumn = rCols[nColumn];
     590             : 
     591           0 :             sal_uInt32 nOldCPos = nCPos;
     592           0 :             nCPos = pColumn->GetPos();
     593             : 
     594           0 :             sal_uInt32 nWidth = nCPos - nOldCPos;
     595             : 
     596             :             // If a base width is given, the table has either an automatic
     597             :             // or margin alignment, or an percentage width. In either case,
     598             :             // relative widths should be exported.
     599           0 :             if( nBaseWidth )
     600             :             {
     601           0 :                 pColumn->SetRelWidth( nWidth );
     602             :             }
     603             : 
     604             :             // If an absolute width is given, the table either has a fixed
     605             :             // width, or the current width is known from the layout. In the
     606             :             // later case, a base width is set in addition and must be used
     607             :             // to "absoultize" the relative column width.
     608           0 :             if( nAbsWidth )
     609             :             {
     610           0 :                 sal_uInt32 nColAbsWidth = nWidth;
     611           0 :                 if( nBaseWidth )
     612             :                 {
     613           0 :                     nColAbsWidth *= nAbsWidth;
     614           0 :                     nColAbsWidth += (nBaseWidth/2UL);
     615           0 :                     nColAbsWidth /= nBaseWidth;
     616             :                 }
     617           0 :                 pColumn->SetWidthOpt( nColAbsWidth, false );
     618             :             }
     619             : 
     620           0 :             SwXMLTableColumnsSortByWidth_Impl::const_iterator it = rExpCols.find( pColumn );
     621           0 :             if( it != rExpCols.end() )
     622             :             {
     623           0 :                 pColumn->SetStyleName( (*it)->GetStyleName() );
     624             :             }
     625             :             else
     626             :             {
     627           0 :                 sBuffer.append( rNamePrefix );
     628           0 :                 sBuffer.append( (sal_Unicode)'.' );
     629           0 :                 if( bTop )
     630             :                 {
     631           0 :                     String sTmp;
     632           0 :                     sw_GetTblBoxColStr( nColumn, sTmp );
     633           0 :                     sBuffer.append( sTmp );
     634             :                 }
     635             :                 else
     636             :                 {
     637           0 :                     sBuffer.append( (sal_Int32)(nColumn + 1U) );
     638             :                 }
     639             : 
     640           0 :                 pColumn->SetStyleName( sBuffer.makeStringAndClear() );
     641           0 :                 ExportTableColumnStyle( *pColumn );
     642           0 :                 rExpCols.insert( pColumn );
     643             :             }
     644             :         }
     645             :     }
     646             : 
     647             :     // pass 3: export line/rows
     648           0 :     sal_uInt16 nLines = rLines.size();
     649           0 :     for( sal_uInt16 nLine=0U; nLine<nLines; nLine++ )
     650             :     {
     651           0 :         SwTableLine *pLine = rLines[nLine];
     652             : 
     653           0 :         SwFrmFmt *pFrmFmt = pLine->GetFrmFmt();
     654           0 :         if( rExpRows.AddRow( *pFrmFmt, rNamePrefix, nLine ) )
     655           0 :             ExportFmt( *pFrmFmt, XML_TABLE_ROW );
     656             : 
     657           0 :         const SwTableBoxes& rBoxes = pLine->GetTabBoxes();
     658           0 :         sal_uInt16 nBoxes = rBoxes.size();
     659             : 
     660           0 :         sal_uInt32 nCPos = 0U;
     661           0 :         sal_uInt16 nCol = 0U;
     662           0 :         for( sal_uInt16 nBox=0U; nBox<nBoxes; nBox++ )
     663             :         {
     664           0 :             SwTableBox *pBox = rBoxes[nBox];
     665             : 
     666           0 :             if( nBox < nBoxes-1U )
     667           0 :                 nCPos = nCPos + SwWriteTable::GetBoxWidth( pBox );
     668             :             else
     669           0 :                 nCPos = pLines->GetWidth();
     670             : 
     671             : 
     672             :             // Und ihren Index
     673           0 :             sal_uInt16 nOldCol = nCol;
     674           0 :             SwXMLTableColumn_Impl aCol( nCPos );
     675           0 :             SwXMLTableColumns_Impl::const_iterator it = pLines->GetColumns().find( &aCol );
     676             :             OSL_ENSURE( it != pLines->GetColumns().end(), "couldn't find column" );
     677           0 :             nCol = it - pLines->GetColumns().begin();
     678             : 
     679           0 :             const SwStartNode *pBoxSttNd = pBox->GetSttNd();
     680           0 :             if( pBoxSttNd )
     681             :             {
     682           0 :                 SwFrmFmt *pFrmFmt2 = pBox->GetFrmFmt();
     683           0 :                 if( rExpCells.AddCell( *pFrmFmt2, rNamePrefix, nOldCol, nLine,
     684           0 :                                        bTop) )
     685           0 :                     ExportFmt( *pFrmFmt2, XML_TABLE_CELL );
     686             : 
     687             :                 Reference < XCell > xCell = SwXCell::CreateXCell(
     688           0 :                                                 (SwFrmFmt *)rTblInfo.GetTblFmt(),
     689             :                                                   pBox,
     690           0 :                                                  (SwTable *)rTblInfo.GetTable() );
     691           0 :                 if (xCell.is())
     692             :                 {
     693           0 :                     Reference < XText > xText( xCell, UNO_QUERY );
     694           0 :                     if( !rTblInfo.IsBaseSectionValid() )
     695             :                     {
     696             :                         Reference<XPropertySet> xCellPropertySet( xCell,
     697           0 :                                                                  UNO_QUERY );
     698           0 :                         OUString sTextSection("TextSection");
     699           0 :                         Any aAny = xCellPropertySet->getPropertyValue(sTextSection);
     700           0 :                         Reference < XTextSection > xTextSection;
     701           0 :                         aAny >>= xTextSection;
     702           0 :                         rTblInfo.SetBaseSection( xTextSection );
     703             :                     }
     704             : 
     705           0 :                     const bool bExportContent = (getExportFlags() & EXPORT_CONTENT ) != 0;
     706           0 :                     if ( !bExportContent )
     707             :                     {
     708             :                         // AUTOSTYLES - not needed anymore if we are currently exporting content.xml
     709             :                         GetTextParagraphExport()->collectTextAutoStyles(
     710           0 :                             xText, rTblInfo.GetBaseSection(), IsShowProgress() );
     711           0 :                     }
     712             :                 }
     713             :                 else {
     714             :                     OSL_FAIL("here should be a XCell");
     715           0 :                 }
     716             :             }
     717             :             else
     718             :             {
     719             :                 lcl_xmltble_appendBoxPrefix( sBuffer, rNamePrefix, nOldCol,
     720           0 :                                              nLine, bTop );
     721             : 
     722           0 :                 ExportTableLinesAutoStyles( pBox->GetTabLines(),
     723             :                                             nAbsWidth, nBaseWidth,
     724             :                                             sBuffer.makeStringAndClear(),
     725             :                                             rExpCols, rExpRows, rExpCells,
     726           0 :                                              rTblInfo );
     727             :             }
     728             : 
     729           0 :             nCol++;
     730           0 :         }
     731           0 :     }
     732           0 : }
     733             : 
     734           0 : void SwXMLExport::ExportTableAutoStyles( const SwTableNode& rTblNd )
     735             : {
     736           0 :     const SwTable& rTbl = rTblNd.GetTable();
     737           0 :     const SwFrmFmt *pTblFmt = rTbl.GetFrmFmt();
     738             : 
     739           0 :     if( pTblFmt )
     740             :     {
     741           0 :         sal_Int16 eTabHoriOri = pTblFmt->GetHoriOrient().GetHoriOrient();
     742           0 :         const SwFmtFrmSize& rFrmSize = pTblFmt->GetFrmSize();
     743             : 
     744           0 :         sal_uInt32 nAbsWidth = rFrmSize.GetSize().Width();
     745           0 :         sal_uInt32 nBaseWidth = 0UL;
     746           0 :         sal_Int8 nPrcWidth = rFrmSize.GetWidthPercent();
     747             : 
     748           0 :         bool bFixAbsWidth = nPrcWidth != 0 || /*text::*/HoriOrientation::NONE == eTabHoriOri
     749           0 :                                            || /*text::*/HoriOrientation::FULL == eTabHoriOri;
     750           0 :         if( bFixAbsWidth )
     751             :         {
     752           0 :             nBaseWidth = nAbsWidth;
     753           0 :             nAbsWidth = pTblFmt->FindLayoutRect(sal_True).Width();
     754             :             if( !nAbsWidth )
     755             :             {
     756             :                 // TODO???
     757             :             }
     758             :         }
     759           0 :         ExportTableFmt( *pTblFmt, nAbsWidth );
     760             : 
     761           0 :         OUString sName( pTblFmt->GetName() );
     762           0 :         SwXMLTableColumnsSortByWidth_Impl aExpCols;
     763           0 :         SwXMLTableFrmFmtsSort_Impl aExpRows( 10, 10 );
     764           0 :         SwXMLTableFrmFmtsSort_Impl aExpCells( 10, 10 );
     765           0 :         SwXMLTableInfo_Impl aTblInfo( &rTbl );
     766           0 :         ExportTableLinesAutoStyles( rTbl.GetTabLines(), nAbsWidth, nBaseWidth,
     767             :                                     sName, aExpCols, aExpRows, aExpCells,
     768           0 :                                     aTblInfo, sal_True);
     769             :     }
     770           0 : }
     771             : 
     772             : // ---------------------------------------------------------------------
     773             : 
     774           0 : void SwXMLExport::ExportTableBox( const SwTableBox& rBox,
     775             :                                   sal_uInt16 nColSpan,
     776             :                                   sal_uInt16 nRowSpan,
     777             :                                   SwXMLTableInfo_Impl& rTblInfo )
     778             : {
     779           0 :     const SwStartNode *pBoxSttNd = rBox.GetSttNd();
     780           0 :     if( pBoxSttNd )
     781             :     {
     782           0 :         const SwFrmFmt *pFrmFmt = rBox.GetFrmFmt();
     783           0 :         if( pFrmFmt )
     784             :         {
     785           0 :             const String& rName = pFrmFmt->GetName();
     786           0 :             if( rName.Len() )
     787             :             {
     788           0 :                 AddAttribute( XML_NAMESPACE_TABLE, XML_STYLE_NAME, EncodeStyleName(rName) );
     789             :             }
     790             :         }
     791             :     }
     792             : 
     793           0 :     if( nRowSpan != 1 )
     794             :     {
     795           0 :         OUStringBuffer sTmp;
     796           0 :         sTmp.append( (sal_Int32)nRowSpan );
     797             :         AddAttribute( XML_NAMESPACE_TABLE, XML_NUMBER_ROWS_SPANNED,
     798           0 :                       sTmp.makeStringAndClear() );
     799             :     }
     800             : 
     801           0 :     if( nColSpan != 1 )
     802             :     {
     803           0 :         OUStringBuffer sTmp;
     804           0 :         sTmp.append( (sal_Int32)nColSpan );
     805             :         AddAttribute( XML_NAMESPACE_TABLE, XML_NUMBER_COLUMNS_SPANNED,
     806           0 :                       sTmp.makeStringAndClear() );
     807             :     }
     808             : 
     809             :     {
     810           0 :         if( pBoxSttNd )
     811             :         {
     812             :             // start node -> normal cell
     813             : 
     814             :             // get cell range for table
     815           0 :             Reference<XCell> xCell = SwXCell::CreateXCell( (SwFrmFmt *)rTblInfo.GetTblFmt(),
     816             :                                                             (SwTableBox *)&rBox,
     817           0 :                                                             (SwTable *)rTblInfo.GetTable() );
     818             : 
     819           0 :             if (xCell.is())
     820             :             {
     821           0 :                 Reference<XText> xText( xCell, UNO_QUERY );
     822             : 
     823             :                 // get formula (and protection)
     824           0 :                 OUString sCellFormula = xCell->getFormula();
     825             : 
     826             :                 // if this cell has a formula, export it
     827             :                 //     (with value and number format)
     828           0 :                 if (!sCellFormula.isEmpty())
     829             :                 {
     830             :                     OUString sQValue =
     831           0 :                         GetNamespaceMap().GetQNameByKey(
     832           0 :                                 XML_NAMESPACE_OOOW, sCellFormula, sal_False );
     833             :                     // formula
     834           0 :                     AddAttribute(XML_NAMESPACE_TABLE, XML_FORMULA, sQValue );
     835             :                 }
     836             : 
     837             :                 // value and format (if NumberFormat != -1)
     838             :                 Reference<XPropertySet> xCellPropertySet(xCell,
     839           0 :                                                         UNO_QUERY);
     840           0 :                 if (xCellPropertySet.is())
     841             :                 {
     842           0 :                     sal_Int32 nNumberFormat = 0;
     843           0 :                     Any aAny = xCellPropertySet->getPropertyValue(sNumberFormat);
     844           0 :                     aAny >>= nNumberFormat;
     845             : 
     846           0 :                     if (NUMBERFORMAT_TEXT == nNumberFormat)
     847             :                     {
     848             :                         // text format
     849             :                         AddAttribute( XML_NAMESPACE_OFFICE,
     850           0 :                                     XML_VALUE_TYPE, XML_STRING );
     851             :                     }
     852           0 :                     else if ( (-1 != nNumberFormat) && !xText->getString().isEmpty() )
     853             :                     {
     854             :                         // number format key:
     855             :                         // (export values only if cell contains text;)
     856             :                         XMLNumberFormatAttributesExportHelper::
     857             :                             SetNumberFormatAttributes(
     858           0 :                                 *this, nNumberFormat, xCell->getValue(),
     859           0 :                                  sal_True );
     860             :                     }
     861             :                     // else: invalid key; ignore
     862             : 
     863             :                     // cell protection
     864           0 :                     aAny = xCellPropertySet->getPropertyValue(sIsProtected);
     865           0 :                     if (*(sal_Bool*)aAny.getValue())
     866             :                     {
     867             :                         AddAttribute( XML_NAMESPACE_TABLE, XML_PROTECTED,
     868           0 :                                         XML_TRUE );
     869             :                     }
     870             : 
     871           0 :                     if( !rTblInfo.IsBaseSectionValid() )
     872             :                     {
     873           0 :                         OUString sTextSection("TextSection");
     874           0 :                         aAny = xCellPropertySet->getPropertyValue(sTextSection);
     875           0 :                         Reference < XTextSection > xTextSection;
     876           0 :                         aAny >>= xTextSection;
     877           0 :                         rTblInfo.SetBaseSection( xTextSection );
     878           0 :                     }
     879             :                 }
     880             : 
     881             :                 // export cell element
     882             :                 SvXMLElementExport aElem( *this, XML_NAMESPACE_TABLE,
     883           0 :                                         XML_TABLE_CELL, sal_True, sal_True );
     884             : 
     885             :                 // export cell content
     886             :                 GetTextParagraphExport()->exportText( xText,
     887           0 :                                                     rTblInfo.GetBaseSection(),
     888           0 :                                                     IsShowProgress() );
     889             :             }
     890             :             else
     891             :             {
     892             :                 OSL_FAIL("here should be a XCell");
     893           0 :                 ClearAttrList();
     894           0 :             }
     895             :         }
     896             :         else
     897             :         {
     898             :             // no start node -> merged cells: export subtable in cell
     899             :             SvXMLElementExport aElem( *this, XML_NAMESPACE_TABLE,
     900           0 :                                       XML_TABLE_CELL, sal_True, sal_True );
     901             :             {
     902             :                 AddAttribute( XML_NAMESPACE_TABLE, XML_IS_SUB_TABLE,
     903           0 :                                 GetXMLToken( XML_TRUE ) );
     904             : 
     905             :                 SvXMLElementExport aElemExport( *this, XML_NAMESPACE_TABLE,
     906           0 :                                           XML_TABLE, sal_True, sal_True );
     907           0 :                 ExportTableLines( rBox.GetTabLines(), rTblInfo );
     908           0 :             }
     909             :         }
     910             :     }
     911           0 : }
     912             : 
     913           0 : void SwXMLExport::ExportTableLine( const SwTableLine& rLine,
     914             :                                    const SwXMLTableLines_Impl& rLines,
     915             :                                    SwXMLTableInfo_Impl& rTblInfo )
     916             : {
     917           0 :     if( rLine.hasSoftPageBreak() )
     918             :     {
     919             :         SvXMLElementExport aElem( *this, XML_NAMESPACE_TEXT,
     920           0 :                                   XML_SOFT_PAGE_BREAK, sal_True, sal_True );
     921             :     }
     922           0 :     const SwFrmFmt *pFrmFmt = rLine.GetFrmFmt();
     923           0 :     if( pFrmFmt )
     924             :     {
     925           0 :         const String& rName = pFrmFmt->GetName();
     926           0 :         if( rName.Len() )
     927             :         {
     928           0 :             AddAttribute( XML_NAMESPACE_TABLE, XML_STYLE_NAME, EncodeStyleName(rName) );
     929             :         }
     930             :     }
     931             : 
     932             :     {
     933             :         SvXMLElementExport aElem( *this, XML_NAMESPACE_TABLE,
     934           0 :                                   XML_TABLE_ROW, sal_True, sal_True );
     935           0 :         const SwTableBoxes& rBoxes = rLine.GetTabBoxes();
     936           0 :         sal_uInt16 nBoxes = rBoxes.size();
     937             : 
     938           0 :         sal_uInt32 nCPos = 0U;
     939           0 :         sal_uInt16 nCol = 0U;
     940           0 :         for( sal_uInt16 nBox=0U; nBox<nBoxes; nBox++ )
     941             :         {
     942           0 :             const SwTableBox *pBox = rBoxes[nBox];
     943             : 
     944             :             // NEW TABLES
     945           0 :             const long nRowSpan = pBox->getRowSpan();
     946           0 :             if( nRowSpan < 1 )
     947             :             {
     948             :                 SvXMLElementExport aElem2( *this, XML_NAMESPACE_TABLE,
     949             :                                           XML_COVERED_TABLE_CELL, sal_True,
     950           0 :                                           sal_False );
     951             :             }
     952             : 
     953           0 :             if( nBox < nBoxes-1U )
     954           0 :                 nCPos = nCPos + SwWriteTable::GetBoxWidth( pBox );
     955             :             else
     956           0 :                 nCPos = rLines.GetWidth();
     957             : 
     958             :             // Und ihren Index
     959           0 :             const sal_uInt16 nOldCol = nCol;
     960           0 :             SwXMLTableColumn_Impl aCol( nCPos );
     961           0 :             SwXMLTableColumns_Impl::const_iterator it = rLines.GetColumns().find( &aCol );
     962             :             OSL_ENSURE( it != rLines.GetColumns().end(), "couldn't find column" );
     963           0 :             nCol = it - rLines.GetColumns().begin();
     964             : 
     965             :             // #i95726# - Some fault tolerance, if table is somehow corrupted.
     966           0 :             if ( nCol < nOldCol )
     967             :             {
     968             :                 OSL_FAIL( "table and/or table information seems to be corrupted." );
     969             :                 // NOTE: nOldCol is not necessarily a valid index into
     970             :                 // GetColumns(), but that doesn't matter here
     971           0 :                 nCol = nOldCol;
     972             :             }
     973             : 
     974           0 :             sal_uInt16 nColSpan = nCol - nOldCol + 1U;
     975             : 
     976           0 :             if ( nRowSpan >= 1 )
     977           0 :                 ExportTableBox( *pBox, nColSpan, static_cast< sal_uInt16 >(nRowSpan), rTblInfo );
     978             : 
     979           0 :             for( sal_uInt16 i=nOldCol; i<nCol; i++ )
     980             :             {
     981             :                 SvXMLElementExport aElemExport( *this, XML_NAMESPACE_TABLE,
     982             :                                           XML_COVERED_TABLE_CELL, sal_True,
     983           0 :                                           sal_False );
     984           0 :             }
     985             : 
     986           0 :             nCol++;
     987           0 :         }
     988             :     }
     989           0 : }
     990             : 
     991           0 : void SwXMLExport::ExportTableLines( const SwTableLines& rLines,
     992             :                                     SwXMLTableInfo_Impl& rTblInfo,
     993             :                                     sal_uInt16 nHeaderRows )
     994             : {
     995             :     OSL_ENSURE( pTableLines && !pTableLines->empty(),
     996             :             "SwXMLExport::ExportTableLines: table columns infos missing" );
     997           0 :     if( !pTableLines || pTableLines->empty() )
     998           0 :         return;
     999             : 
    1000           0 :     SwXMLTableLines_Impl* pLines = NULL;
    1001             :     size_t nInfoPos;
    1002           0 :     for( nInfoPos=0; nInfoPos < pTableLines->size(); nInfoPos++ )
    1003             :     {
    1004           0 :         if( pTableLines->at( nInfoPos )->GetLines() == &rLines )
    1005             :         {
    1006           0 :             pLines = pTableLines->at( nInfoPos );
    1007           0 :             break;
    1008             :         }
    1009             :     }
    1010             :     OSL_ENSURE( pLines,
    1011             :             "SwXMLExport::ExportTableLines: table columns info missing" );
    1012             :     OSL_ENSURE( 0==nInfoPos,
    1013             :             "SwXMLExport::ExportTableLines: table columns infos are unsorted" );
    1014           0 :     if( !pLines )
    1015           0 :         return;
    1016             : 
    1017           0 :     SwXMLTableLinesCache_Impl::iterator it = pTableLines->begin();
    1018           0 :     advance( it, nInfoPos );
    1019           0 :     pTableLines->erase( it );
    1020             : 
    1021           0 :     if( pTableLines->empty() )
    1022             :     {
    1023           0 :         delete pTableLines ;
    1024           0 :         pTableLines = NULL;
    1025             :     }
    1026             : 
    1027             :     // pass 2: export columns
    1028           0 :     const SwXMLTableColumns_Impl& rCols = pLines->GetColumns();
    1029           0 :     sal_uInt16 nColumn = 0U;
    1030           0 :     sal_uInt16 nColumns = rCols.size();
    1031           0 :     sal_uInt16 nColRep = 1U;
    1032           0 :     SwXMLTableColumn_Impl *pColumn = (nColumns > 0) ? rCols[0U] : 0;
    1033           0 :     while( pColumn )
    1034             :     {
    1035           0 :         nColumn++;
    1036             :         SwXMLTableColumn_Impl *pNextColumn =
    1037           0 :             (nColumn < nColumns) ? rCols[nColumn] : 0;
    1038           0 :         if( pNextColumn &&
    1039           0 :             pNextColumn->GetStyleName() == pColumn->GetStyleName() )
    1040             :         {
    1041           0 :             nColRep++;
    1042             :         }
    1043             :         else
    1044             :         {
    1045             :             AddAttribute( XML_NAMESPACE_TABLE, XML_STYLE_NAME,
    1046           0 :                           EncodeStyleName(pColumn->GetStyleName()) );
    1047             : 
    1048           0 :             if( nColRep > 1U )
    1049             :             {
    1050           0 :                 OUStringBuffer sTmp(4);
    1051           0 :                 sTmp.append( (sal_Int32)nColRep );
    1052             :                 AddAttribute( XML_NAMESPACE_TABLE, XML_NUMBER_COLUMNS_REPEATED,
    1053           0 :                               sTmp.makeStringAndClear() );
    1054             :             }
    1055             : 
    1056             :             {
    1057             :                 SvXMLElementExport aElem( *this, XML_NAMESPACE_TABLE,
    1058           0 :                                           XML_TABLE_COLUMN, sal_True, sal_True );
    1059             :             }
    1060             : 
    1061           0 :             nColRep = 1U;
    1062             :         }
    1063           0 :         pColumn = pNextColumn;
    1064             :     }
    1065             : 
    1066             :     // pass 3: export line/rows
    1067           0 :     sal_uInt16 nLines = rLines.size();
    1068             :     // export header rows, if present
    1069           0 :     if( nHeaderRows > 0 )
    1070             :     {
    1071             :         SvXMLElementExport aElem( *this, XML_NAMESPACE_TABLE,
    1072           0 :                                   XML_TABLE_HEADER_ROWS, sal_True, sal_True );
    1073             : 
    1074             :         OSL_ENSURE( nHeaderRows <= nLines, "more headers then lines?" );
    1075           0 :         for( sal_uInt16 nLine = 0U; nLine < nHeaderRows; nLine++ )
    1076           0 :             ExportTableLine( *(rLines[nLine]), *pLines, rTblInfo );
    1077             :     }
    1078             :     // export remaining rows
    1079           0 :     for( sal_uInt16 nLine = nHeaderRows; nLine < nLines; nLine++ )
    1080             :     {
    1081           0 :         ExportTableLine( *(rLines[nLine]), *pLines, rTblInfo );
    1082             :     }
    1083             : 
    1084           0 :     delete pLines;
    1085             : }
    1086             : 
    1087             : static void lcl_xmltble_ClearName_Line( SwTableLine* pLine );
    1088             : 
    1089           0 : static void lcl_xmltble_ClearName_Box( SwTableBox* pBox )
    1090             : {
    1091           0 :     if( !pBox->GetSttNd() )
    1092             :     {
    1093           0 :         BOOST_FOREACH( SwTableLine* pLine, pBox->GetTabLines() )
    1094           0 :             lcl_xmltble_ClearName_Line( pLine );
    1095             :     }
    1096             :     else
    1097             :     {
    1098           0 :         SwFrmFmt *pFrmFmt = pBox->GetFrmFmt();
    1099           0 :         if( pFrmFmt && pFrmFmt->GetName().Len() )
    1100           0 :             pFrmFmt->SetName( aEmptyStr );
    1101             :     }
    1102           0 : }
    1103             : 
    1104           0 : void lcl_xmltble_ClearName_Line( SwTableLine* pLine )
    1105             : {
    1106           0 :     BOOST_FOREACH( SwTableBox* pBox, pLine->GetTabBoxes() )
    1107           0 :         lcl_xmltble_ClearName_Box( pBox );
    1108           0 : }
    1109             : 
    1110           0 : void SwXMLExport::ExportTable( const SwTableNode& rTblNd )
    1111             : {
    1112           0 :     const SwTable& rTbl = rTblNd.GetTable();
    1113           0 :     const SwFrmFmt *pTblFmt = rTbl.GetFrmFmt();
    1114           0 :     if( pTblFmt && pTblFmt->GetName().Len() )
    1115             :     {
    1116           0 :         AddAttribute( XML_NAMESPACE_TABLE, XML_NAME, pTblFmt->GetName() );
    1117             :         AddAttribute( XML_NAMESPACE_TABLE, XML_STYLE_NAME,
    1118           0 :                       EncodeStyleName( pTblFmt->GetName() ) );
    1119             :     }
    1120             : 
    1121             :     {
    1122             :         SvXMLElementExport aElem( *this, XML_NAMESPACE_TABLE, XML_TABLE,
    1123           0 :                                   sal_True, sal_True );
    1124             : 
    1125             :         // export DDE source (if this is a DDE table)
    1126           0 :         if ( rTbl.ISA(SwDDETable) )
    1127             :         {
    1128             :             // get DDE Field Type (contains the DDE connection)
    1129             :             const SwDDEFieldType* pDDEFldType =
    1130           0 :                 ((SwDDETable&)rTbl).GetDDEFldType();
    1131             : 
    1132             :             // connection name
    1133             :             AddAttribute( XML_NAMESPACE_OFFICE, XML_NAME,
    1134           0 :                           pDDEFldType->GetName() );
    1135             : 
    1136             :             // DDE command
    1137           0 :             const String sCmd = pDDEFldType->GetCmd();
    1138             :             AddAttribute( XML_NAMESPACE_OFFICE, XML_DDE_APPLICATION,
    1139           0 :                           sCmd.GetToken(0, sfx2::cTokenSeparator) );
    1140             :             AddAttribute( XML_NAMESPACE_OFFICE, XML_DDE_ITEM,
    1141           0 :                           sCmd.GetToken(1, sfx2::cTokenSeparator) );
    1142             :             AddAttribute( XML_NAMESPACE_OFFICE, XML_DDE_TOPIC,
    1143           0 :                           sCmd.GetToken(2, sfx2::cTokenSeparator) );
    1144             : 
    1145             :             // auto update
    1146           0 :             if (pDDEFldType->GetType() == sfx2::LINKUPDATE_ALWAYS)
    1147             :             {
    1148             :                 AddAttribute( XML_NAMESPACE_OFFICE,
    1149           0 :                               XML_AUTOMATIC_UPDATE, XML_TRUE );
    1150             :             }
    1151             : 
    1152             :             // DDE source element (always empty)
    1153             :             SvXMLElementExport aSource(*this, XML_NAMESPACE_OFFICE,
    1154           0 :                                        XML_DDE_SOURCE, sal_True, sal_False);
    1155             :         }
    1156             : 
    1157           0 :         SwXMLTableInfo_Impl aTblInfo( &rTbl );
    1158           0 :         ExportTableLines( rTbl.GetTabLines(), aTblInfo, rTbl.GetRowsToRepeat() );
    1159             : 
    1160           0 :         BOOST_FOREACH( SwTableLine *pLine, ((SwTable &)rTbl).GetTabLines() )
    1161           0 :             lcl_xmltble_ClearName_Line( pLine );
    1162             :     }
    1163           0 : }
    1164             : 
    1165           0 : void SwXMLTextParagraphExport::exportTable(
    1166             :         const Reference < XTextContent > & rTextContent,
    1167             :         sal_Bool bAutoStyles, sal_Bool _bProgress )
    1168             : {
    1169           0 :     sal_Bool bOldShowProgress = ((SwXMLExport&)GetExport()).IsShowProgress();
    1170           0 :     ((SwXMLExport&)GetExport()).SetShowProgress( _bProgress );
    1171             : 
    1172           0 :     Reference < XTextTable > xTxtTbl( rTextContent, UNO_QUERY );
    1173             :     OSL_ENSURE( xTxtTbl.is(), "text table missing" );
    1174           0 :     if( xTxtTbl.is() )
    1175             :     {
    1176           0 :         const SwXTextTable *pXTable = 0;
    1177           0 :         Reference<XUnoTunnel> xTableTunnel( rTextContent, UNO_QUERY);
    1178           0 :         if( xTableTunnel.is() )
    1179             :         {
    1180             :             pXTable = reinterpret_cast< SwXTextTable * >(
    1181           0 :                     sal::static_int_cast< sal_IntPtr >( xTableTunnel->getSomething( SwXTextTable::getUnoTunnelId() )));
    1182             :             OSL_ENSURE( pXTable, "SwXTextTable missing" );
    1183             :         }
    1184           0 :         if( pXTable )
    1185             :         {
    1186           0 :             SwFrmFmt *pFmt = pXTable->GetFrmFmt();
    1187             :             OSL_ENSURE( pFmt, "table format missing" );
    1188           0 :             const SwTable *pTbl = SwTable::FindTable( pFmt );
    1189             :             OSL_ENSURE( pTbl, "table missing" );
    1190           0 :             const SwTableNode *pTblNd = pTbl->GetTableNode();
    1191             :             OSL_ENSURE( pTblNd, "table node missing" );
    1192           0 :             if( bAutoStyles )
    1193             :             {
    1194           0 :                 SwNodeIndex aIdx( *pTblNd );
    1195             :                 // AUTOSTYLES: Optimization: Do not export table autostyle if
    1196             :                 // we are currently exporting the content.xml stuff and
    1197             :                 // the table is located in header/footer:
    1198             :                 // During the flat XML export (used e.g. by .sdw-export)
    1199             :                 // ALL flags are set at the same time.
    1200           0 :                 const bool bExportStyles = ( GetExport().getExportFlags() & EXPORT_STYLES ) != 0;
    1201           0 :                 if ( bExportStyles || !pFmt->GetDoc()->IsInHeaderFooter( aIdx ) )
    1202           0 :                     ((SwXMLExport&)GetExport()).ExportTableAutoStyles( *pTblNd );
    1203             :             }
    1204             :             else
    1205             :             {
    1206           0 :                 ((SwXMLExport&)GetExport()).ExportTable( *pTblNd );
    1207             :             }
    1208           0 :         }
    1209             :     }
    1210             : 
    1211           0 :     ((SwXMLExport&)GetExport()).SetShowProgress( bOldShowProgress );
    1212           0 : }
    1213             : 
    1214          68 : void SwXMLExport::DeleteTableLines()
    1215             : {
    1216          68 :     if ( pTableLines )
    1217             :     {
    1218           0 :         for ( size_t i = 0, n = pTableLines->size(); i < n; ++i )
    1219           0 :             delete pTableLines->at( i );
    1220           0 :         pTableLines->clear();
    1221           0 :         delete pTableLines;
    1222             :     }
    1223         167 : }
    1224             : 
    1225             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10