/************************************************************************* * * $RCSfile: xmltble.cxx,v $ * * $Revision: 1.20 $ * * last change: $Author: mib $ $Date: 2001-11-01 13:49:08 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses * * - GNU Lesser General Public License Version 2.1 * - Sun Industry Standards Source License Version 1.1 * * Sun Microsystems Inc., October, 2000 * * GNU Lesser General Public License Version 2.1 * ============================================= * Copyright 2000 by Sun Microsystems, Inc. * 901 San Antonio Road, Palo Alto, CA 94303, USA * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * * * Sun Industry Standards Source License Version 1.1 * ================================================= * The contents of this file are subject to the Sun Industry Standards * Source License Version 1.1 (the "License"); You may not use this file * except in compliance with the License. You may obtain a copy of the * License at http://www.openoffice.org/license.html. * * Software provided under this License is provided on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. * See the License for the specific provisions governing your rights and * obligations concerning the Software. * * The Initial Developer of the Original Code is: Sun Microsystems, Inc. * * Copyright: 2000 by Sun Microsystems, Inc. * * All Rights Reserved. * * Contributor(s): _______________________________________ * * ************************************************************************/ #ifdef PRECOMPILED #include "filt_pch.hxx" #endif #pragma hdrstop #include #ifndef _RTL_USTRBUF_HXX_ #include #endif #ifndef _COM_SUN_STAR_TEXT_XTEXTTABLE_HPP_ #include #endif #ifndef _COM_SUN_STAR_TABLE_XCELL_HPP_ #include #endif #ifndef _XMLOFF_XMLNMSPE_HXX #include #endif #ifndef _XMLOFF_XMLTOKEN_HXX #include #endif #ifndef _XMLOFF_XMLUCONV_HXX #include #endif #ifndef XMLOFF_NUMEHELP_HXX #include #endif #ifndef _CNTRSRT_HXX #include #endif #ifndef _ZFORLIST_HXX #include #endif #ifndef _SVX_BRSHITEM_HXX #include #endif #ifndef _SVX_BOXITEM_HXX #include #endif #ifndef __SGI_STL_LIST #include #endif #ifndef __SGI_STL_HASH_MAP #include #endif #ifndef _SWTABLE_HXX #include "swtable.hxx" #endif #ifndef _DOC_HXX #include "doc.hxx" #endif #ifndef _PAM_HXX #include "pam.hxx" #endif #ifndef _FRMFMT_HXX #include "frmfmt.hxx" #endif #ifndef _WRTSWTBL_HXX #include "wrtswtbl.hxx" #endif #ifndef _FMTFSIZE_HXX #include "fmtfsize.hxx" #endif #ifndef _FMTORNT_HXX #include "fmtornt.hxx" #endif #ifndef _CELLATR_HXX #include "cellatr.hxx" #endif #ifndef _DDEFLD_HXX #include "ddefld.hxx" #endif #ifndef _SWDDETBL_HXX #include "swddetbl.hxx" #endif #ifndef _NDOLE_HXX #include #endif #ifndef _LINKMGR_HXX #include // for cTokenSeperator #endif #ifndef _UNOOBJ_HXX #include "unoobj.hxx" #endif #ifndef _UNOTBL_HXX #include "unotbl.hxx" #endif #ifndef _XMLTEXTE_HXX #include "xmltexte.hxx" #endif #ifndef _XMLEXP_HXX #include "xmlexp.hxx" #endif using namespace ::rtl; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::text; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::lang; using namespace ::com::sun::star::container; using namespace ::xmloff::token; using ::com::sun::star::table::XCell; class SwXMLTableColumn_Impl : public SwWriteTableCol { OUString sStyleName; sal_uInt32 nRelWidth; public: SwXMLTableColumn_Impl( sal_uInt16 nPosition ) : SwWriteTableCol( nPosition ), nRelWidth( 0UL ) {}; void SetStyleName( const OUString& rName ) { sStyleName = rName; } const OUString& GetStyleName() const { return sStyleName; } void SetRelWidth( sal_uInt32 nSet ) { nRelWidth = nSet; } sal_uInt32 GetRelWidth() const { return nRelWidth; } }; sal_Int32 SwXMLTableColumnCmpWidth_Impl( const SwXMLTableColumn_Impl& r1, const SwXMLTableColumn_Impl& r2 ) { sal_Int32 n = (sal_Int32)r1.GetWidthOpt() - (sal_Int32)r2.GetWidthOpt(); if( !n ) n = (sal_Int32)r1.GetRelWidth() - (sal_Int32)r2.GetRelWidth(); return n; } // --------------------------------------------------------------------- typedef SwXMLTableColumn_Impl *SwXMLTableColumnPtr; SV_DECL_PTRARR_SORT_DEL( SwXMLTableColumns_Impl, SwXMLTableColumnPtr, 5, 5 ) SV_IMPL_OP_PTRARR_SORT( SwXMLTableColumns_Impl, SwXMLTableColumnPtr ) DECLARE_CONTAINER_SORT( SwXMLTableColumnsSortByWidth_Impl, SwXMLTableColumn_Impl ) IMPL_CONTAINER_SORT( SwXMLTableColumnsSortByWidth_Impl, SwXMLTableColumn_Impl, SwXMLTableColumnCmpWidth_Impl ) class SwXMLTableLines_Impl { SwXMLTableColumns_Impl aCols; const SwTableLines *pLines; sal_uInt32 nWidth; public: SwXMLTableLines_Impl( const SwTableLines& rLines ); ~SwXMLTableLines_Impl() {} sal_uInt32 GetWidth() const { return nWidth; } const SwTableLines *GetLines() const { return pLines; } const SwXMLTableColumns_Impl& GetColumns() const { return aCols; } }; SwXMLTableLines_Impl::SwXMLTableLines_Impl( const SwTableLines& rLines ) : pLines( &rLines ), nWidth( 0UL ) { #ifndef PRODUCT sal_uInt16 nEndCPos = 0U; #endif sal_uInt16 nLines = rLines.Count(); sal_uInt16 nLine; for( nLine=0U; nLineGetTabBoxes(); sal_uInt16 nBoxes = rBoxes.Count(); sal_uInt16 nCPos = 0U; for( sal_uInt16 nBox=0U; nBoxGetAttrSet(); if( SFX_ITEM_SET == rTestSet.GetItemState( RES_FRM_SIZE, sal_False, &pItem ) ) { if( !pFrmSize ) break; pTestFrmSize = (const SwFmtFrmSize *)pItem; } else { if( pFrmSize ) continue; } if( SFX_ITEM_SET == rTestSet.GetItemState( RES_BACKGROUND, sal_False, &pItem ) ) { if( !pBrush ) break; pTestBrush = (const SvxBrushItem *)pItem; } else { if( pBrush ) continue; } if( pFrmSize && ( pFrmSize->GetSizeType() != pTestFrmSize->GetSizeType() || pFrmSize->GetHeight() != pTestFrmSize->GetHeight() ) ) continue; if( pBrush && (*pBrush != *pTestBrush) ) continue; // found! const String& rFmtName = pTestFmt->GetName(); rFrmFmt.SetName( rFmtName ); bInsert = sal_False; break; } if( bInsert ) { OUStringBuffer sBuffer( rNamePrefix.getLength() + 4UL ); sBuffer.append( rNamePrefix ); sBuffer.append( (sal_Unicode)'.' ); sBuffer.append( (sal_Int32)(nLine+1UL) ); rFrmFmt.SetName( sBuffer.makeStringAndClear() ); Insert( &rFrmFmt, i ); } return bInsert; } void lcl_GetTblBoxColStr( sal_uInt16 nCol, String& rNm ); void lcl_xmltble_appendBoxPrefix( OUStringBuffer& rBuffer, const OUString& rNamePrefix, sal_uInt32 nCol, sal_uInt32 nRow, sal_Bool bTop ) { rBuffer.append( rNamePrefix ); rBuffer.append( (sal_Unicode)'.' ); if( bTop ) { String sTmp; lcl_GetTblBoxColStr( (sal_uInt16)nCol, sTmp ); rBuffer.append( sTmp ); } else { rBuffer.append( (sal_Int32)(nCol + 1)); rBuffer.append( (sal_Unicode)'.' ); } rBuffer.append( (sal_Int32)(nRow + 1)); } sal_Bool SwXMLTableFrmFmtsSort_Impl::AddCell( SwFrmFmt& rFrmFmt, const OUString& rNamePrefix, sal_uInt32 nCol, sal_uInt32 nRow, sal_Bool bTop ) { const SwFmtVertOrient *pVertOrient = 0; const SvxBrushItem *pBrush = 0; const SvxBoxItem *pBox = 0; sal_uInt32 nNumFormat = 0; // compare number formats by their number const SfxItemSet& rItemSet = rFrmFmt.GetAttrSet(); const SfxPoolItem *pItem; if( SFX_ITEM_SET == rItemSet.GetItemState( RES_VERT_ORIENT, sal_False, &pItem ) ) pVertOrient = (const SwFmtVertOrient *)pItem; if( SFX_ITEM_SET == rItemSet.GetItemState( RES_BACKGROUND, sal_False, &pItem ) ) pBrush = (const SvxBrushItem *)pItem; if( SFX_ITEM_SET == rItemSet.GetItemState( RES_BOX, sal_False, &pItem ) ) pBox = (const SvxBoxItem *)pItem; if ( SFX_ITEM_SET == rItemSet.GetItemState( RES_BOXATR_FORMAT, sal_False, &pItem ) ) nNumFormat = ((const SwTblBoxNumFormat *)pItem)->GetValue(); // empty styles have not to be exported if( !pVertOrient && !pBrush && !pBox ) return sal_False; // order is: -/-/box, -/brush/-, -/brush/box, // vert/-/-, vert/-/box, vert/brush/-, vert/brush/box sal_uInt32 nCount = Count(); sal_Bool bInsert = sal_True; sal_uInt32 i; for( i=0; iGetAttrSet(); if( SFX_ITEM_SET == rTestSet.GetItemState( RES_VERT_ORIENT, sal_False, &pItem ) ) { if( !pVertOrient ) break; pTestVertOrient = (const SwFmtVertOrient *)pItem; } else { if( pVertOrient ) continue; } if( SFX_ITEM_SET == rTestSet.GetItemState( RES_BACKGROUND, sal_False, &pItem ) ) { if( !pBrush ) break; pTestBrush = (const SvxBrushItem *)pItem; } else { if( pBrush ) continue; } if( SFX_ITEM_SET == rTestSet.GetItemState( RES_BOX, sal_False, &pItem ) ) { if( !pBox ) break; pTestBox = (const SvxBoxItem *)pItem; } else { if( pBox ) continue; } if ( SFX_ITEM_SET == rTestSet.GetItemState( RES_BOXATR_FORMAT, sal_False, &pItem ) ) nTestNumFormat = ((const SwTblBoxNumFormat *)pItem)->GetValue(); if( pVertOrient && pVertOrient->GetVertOrient() != pTestVertOrient->GetVertOrient() ) continue; if( pBrush && ( *pBrush != *pTestBrush ) ) continue; if( pBox && ( *pBox != *pTestBox ) ) continue; // compare formats based on value (rather than presentation) if( nNumFormat != nTestNumFormat ) continue; // found! const String& rFmtName = pTestFmt->GetName(); rFrmFmt.SetName( rFmtName ); bInsert = sal_False; break; } if( bInsert ) { OUStringBuffer sBuffer( rNamePrefix.getLength() + 8UL ); lcl_xmltble_appendBoxPrefix( sBuffer, rNamePrefix, nCol, nRow, bTop ); rFrmFmt.SetName( sBuffer.makeStringAndClear() ); Insert( &rFrmFmt, i ); } return bInsert; } // --------------------------------------------------------------------- class SwXMLTableInfo_Impl { const SwTable *pTable; Reference < XTextSection > xBaseSection; sal_Bool bBaseSectionValid; public: inline SwXMLTableInfo_Impl( const SwTable *pTbl ); const SwTable *GetTable() const { return pTable; } const SwFrmFmt *GetTblFmt() const { return pTable->GetFrmFmt(); } sal_Bool IsBaseSectionValid() const { return bBaseSectionValid; } const Reference < XTextSection >& GetBaseSection() const { return xBaseSection; } inline void SetBaseSection( const Reference < XTextSection >& rBase ); }; inline SwXMLTableInfo_Impl::SwXMLTableInfo_Impl( const SwTable *pTbl ) : pTable( pTbl ), bBaseSectionValid( sal_False ) { } inline void SwXMLTableInfo_Impl::SetBaseSection( const Reference < XTextSection >& rBaseSection ) { xBaseSection = rBaseSection; bBaseSectionValid = sal_True; } // --------------------------------------------------------------------- void SwXMLExport::ExportTableColumnStyle( const SwXMLTableColumn_Impl& rCol ) { // CheckAttrList(); // style:name="..." AddAttribute( XML_NAMESPACE_STYLE, XML_NAME, rCol.GetStyleName() ); // style:family="table-column" AddAttribute( XML_NAMESPACE_STYLE, XML_FAMILY, XML_TABLE_COLUMN ); { SvXMLElementExport aElem( *this, XML_NAMESPACE_STYLE, XML_STYLE, sal_True, sal_True ); OUStringBuffer sValue; if( rCol.GetWidthOpt() ) { GetTwipUnitConverter().convertMeasure( sValue, rCol.GetWidthOpt() ); AddAttribute( XML_NAMESPACE_STYLE, XML_COLUMN_WIDTH, sValue.makeStringAndClear() ); } if( rCol.GetRelWidth() ) { sValue.append( (sal_Int32)rCol.GetRelWidth() ); sValue.append( (sal_Unicode)'*' ); AddAttribute( XML_NAMESPACE_STYLE, XML_REL_COLUMN_WIDTH, sValue.makeStringAndClear() ); } { SvXMLElementExport aElem( *this, XML_NAMESPACE_STYLE, XML_PROPERTIES, sal_True, sal_True ); } } } void SwXMLExport::ExportTableLinesAutoStyles( const SwTableLines& rLines, sal_uInt32 nAbsWidth, sal_uInt32 nBaseWidth, const OUString& rNamePrefix, SwXMLTableColumnsSortByWidth_Impl& rExpCols, SwXMLTableFrmFmtsSort_Impl& rExpRows, SwXMLTableFrmFmtsSort_Impl& rExpCells, SwXMLTableInfo_Impl& rTblInfo, sal_Bool bTop ) { // pass 1: calculate columns SwXMLTableLines_Impl *pLines = new SwXMLTableLines_Impl( rLines ); if( !pTableLines ) pTableLines = new SwXMLTableLinesCache_Impl( 5, 5 ); pTableLines->Insert( pLines, pTableLines->Count() ); OUStringBuffer sBuffer( rNamePrefix.getLength() + 8L ); // pass 2: export column styles { const SwXMLTableColumns_Impl& rCols = pLines->GetColumns(); sal_uInt16 nCPos = 0U; sal_uInt16 nColumns = rCols.Count(); for( sal_uInt16 nColumn=0U; nColumnGetPos(); sal_uInt32 nWidth = nCPos - nOldCPos; // If a base width is given, the table has either an automatic // or margin alignment, or an percentage width. In either case, // relative widths should be exported. if( nBaseWidth ) { pColumn->SetRelWidth( nWidth ); } // If an absolute width is given, the table either has a fixed // width, or the current width is known from the layout. In the // later case, a base width is set in addition and must be used // to "absoultize" the relative column width. if( nAbsWidth ) { sal_uInt32 nColAbsWidth = nWidth; if( nBaseWidth ) { nColAbsWidth *= nAbsWidth; nColAbsWidth += (nBaseWidth/2UL); nColAbsWidth /= nBaseWidth; } pColumn->SetWidthOpt( (sal_uInt16)nColAbsWidth, sal_False ); } sal_uInt32 nExpPos = 0; if( rExpCols.Seek_Entry( pColumn, &nExpPos ) ) { pColumn->SetStyleName( rExpCols.GetObject(nExpPos)->GetStyleName() ); } else { sBuffer.append( rNamePrefix ); sBuffer.append( (sal_Unicode)'.' ); if( bTop ) { String sTmp; lcl_GetTblBoxColStr( nColumn, sTmp ); sBuffer.append( sTmp ); } else { sBuffer.append( (sal_Int32)(nColumn + 1U) ); } pColumn->SetStyleName( sBuffer.makeStringAndClear() ); ExportTableColumnStyle( *pColumn ); rExpCols.Insert( pColumn ); } } } // pass 3: export line/rows sal_uInt16 nLines = rLines.Count(); for( sal_uInt16 nLine=0U; nLineGetFrmFmt(); if( rExpRows.AddRow( *pFrmFmt, rNamePrefix, nLine ) ) ExportFmt( *pFrmFmt, XML_TABLE_ROW ); const SwTableBoxes& rBoxes = pLine->GetTabBoxes(); sal_uInt16 nBoxes = rBoxes.Count(); sal_uInt16 nCPos = 0U; sal_uInt16 nCol = 0U; for( sal_uInt16 nBox=0U; nBoxGetWidth(); // Und ihren Index sal_uInt16 nOldCol = nCol; SwXMLTableColumn_Impl aCol( nCPos ); sal_Bool bFound = pLines->GetColumns().Seek_Entry( &aCol, &nCol ); ASSERT( bFound, "couldn't find column" ); const SwStartNode *pBoxSttNd = pBox->GetSttNd(); if( pBoxSttNd ) { SwFrmFmt *pFrmFmt = pBox->GetFrmFmt(); if( rExpCells.AddCell( *pFrmFmt, rNamePrefix, nOldCol, nLine, bTop) ) ExportFmt( *pFrmFmt, XML_TABLE_CELL ); Reference < XCell > xCell = SwXCell::CreateXCell( (SwFrmFmt *)rTblInfo.GetTblFmt(), pBox, 0, (SwTable *)rTblInfo.GetTable() ); Reference < XText > xText( xCell, UNO_QUERY ); if( !rTblInfo.IsBaseSectionValid() ) { Reference xCellPropertySet( xCell, UNO_QUERY ); OUString sTextSection( RTL_CONSTASCII_USTRINGPARAM("TextSection") ); Any aAny = xCellPropertySet->getPropertyValue(sTextSection); Reference < XTextSection > xTextSection; aAny >>= xTextSection; rTblInfo.SetBaseSection( xTextSection ); } GetTextParagraphExport()->collectTextAutoStyles( xText, rTblInfo.GetBaseSection(), IsShowProgress() ); } else { lcl_xmltble_appendBoxPrefix( sBuffer, rNamePrefix, nOldCol, nLine, bTop ); ExportTableLinesAutoStyles( pBox->GetTabLines(), nAbsWidth, nBaseWidth, sBuffer.makeStringAndClear(), rExpCols, rExpRows, rExpCells, rTblInfo ); } nCol++; } } } void SwXMLExport::ExportTableAutoStyles( const SwTableNode& rTblNd ) { const SwTable& rTbl = rTblNd.GetTable(); const SwFrmFmt *pTblFmt = rTbl.GetFrmFmt(); if( pTblFmt ) { SwHoriOrient eTabHoriOri = pTblFmt->GetHoriOrient().GetHoriOrient(); const SwFmtFrmSize& rFrmSize = pTblFmt->GetFrmSize(); sal_uInt32 nAbsWidth = rFrmSize.GetSize().Width(); sal_uInt32 nBaseWidth = 0UL; sal_Int8 nPrcWidth = rFrmSize.GetWidthPercent(); sal_Bool bFixAbsWidth = nPrcWidth != 0 || HORI_NONE == eTabHoriOri || HORI_FULL == eTabHoriOri; if( bFixAbsWidth ) { nBaseWidth = nAbsWidth; nAbsWidth = pTblFmt->FindLayoutRect(sal_True).Width(); if( !nAbsWidth ) { // TODO??? } } ExportTableFmt( *pTblFmt, nAbsWidth ); OUString sName( pTblFmt->GetName() ); SwXMLTableColumnsSortByWidth_Impl aExpCols( 10, 10 ); SwXMLTableFrmFmtsSort_Impl aExpRows( 10, 10 ); SwXMLTableFrmFmtsSort_Impl aExpCells( 10, 10 ); SwXMLTableInfo_Impl aTblInfo( &rTbl ); ExportTableLinesAutoStyles( rTbl.GetTabLines(), nAbsWidth, nBaseWidth, sName, aExpCols, aExpRows, aExpCells, aTblInfo, sal_True); } } // --------------------------------------------------------------------- void SwXMLExport::ExportTableBox( const SwTableBox& rBox, sal_uInt16 nColSpan, SwXMLTableInfo_Impl& rTblInfo ) { const SwStartNode *pBoxSttNd = rBox.GetSttNd(); if( pBoxSttNd ) { const SwFrmFmt *pFrmFmt = rBox.GetFrmFmt(); if( pFrmFmt ) { const String& rName = pFrmFmt->GetName(); if( rName.Len() ) { AddAttribute( XML_NAMESPACE_TABLE, XML_STYLE_NAME, rName ); } } } if( nColSpan != 1 ) { OUStringBuffer sTmp; sTmp.append( (sal_Int32)nColSpan ); AddAttribute( XML_NAMESPACE_TABLE, XML_NUMBER_COLUMNS_SPANNED, sTmp.makeStringAndClear() ); } { if( pBoxSttNd ) { // start node -> normal cell // get cell range for table Reference xCell = SwXCell::CreateXCell( (SwFrmFmt *)rTblInfo.GetTblFmt(), (SwTableBox *)&rBox, 0, (SwTable *)rTblInfo.GetTable() ); Reference xText( xCell, UNO_QUERY ); // get formula (and protection) OUString sCellFormula = xCell->getFormula(); // if this cell has a formula, export it // (with value and number format) if (sCellFormula.getLength()>0) { // formula AddAttribute(XML_NAMESPACE_TABLE, XML_FORMULA, sCellFormula); } // value and format (if NumberFormat != -1) Reference xCellPropertySet(xCell, UNO_QUERY); if (xCellPropertySet.is()) { sal_Int32 nNumberFormat; Any aAny = xCellPropertySet->getPropertyValue(sNumberFormat); aAny >>= nNumberFormat; if (NUMBERFORMAT_TEXT == nNumberFormat) { // text format AddAttribute( XML_NAMESPACE_TABLE, XML_VALUE_TYPE, XML_STRING ); } else if (-1 != nNumberFormat) { // number format key: // (export values only if cell contains text; // cf. #83755#) XMLNumberFormatAttributesExportHelper:: SetNumberFormatAttributes( *this, nNumberFormat, xCell->getValue(), XML_NAMESPACE_TABLE, (xText->getString().getLength() > 0) ); } // else: invalid key; ignore // cell protection aAny = xCellPropertySet->getPropertyValue(sIsProtected); if (*(sal_Bool*)aAny.getValue()) { AddAttribute( XML_NAMESPACE_TABLE, XML_PROTECTED, XML_TRUE ); } if( !rTblInfo.IsBaseSectionValid() ) { OUString sTextSection( RTL_CONSTASCII_USTRINGPARAM("TextSection") ); aAny = xCellPropertySet->getPropertyValue(sTextSection); Reference < XTextSection > xTextSection; aAny >>= xTextSection; rTblInfo.SetBaseSection( xTextSection ); } } // export cell element SvXMLElementExport aElem( *this, XML_NAMESPACE_TABLE, XML_TABLE_CELL, sal_True, sal_True ); // export cell content GetTextParagraphExport()->exportText( xText, rTblInfo.GetBaseSection(), IsShowProgress() ); } else { // no start node -> merged cells: export subtable in cell SvXMLElementExport aElem( *this, XML_NAMESPACE_TABLE, XML_TABLE_CELL, sal_True, sal_True ); { SvXMLElementExport aElem( *this, XML_NAMESPACE_TABLE, XML_SUB_TABLE, sal_True, sal_True ); ExportTableLines( rBox.GetTabLines(), rTblInfo ); } } } } void SwXMLExport::ExportTableLine( const SwTableLine& rLine, const SwXMLTableLines_Impl& rLines, SwXMLTableInfo_Impl& rTblInfo ) { const SwFrmFmt *pFrmFmt = rLine.GetFrmFmt(); if( pFrmFmt ) { const String& rName = pFrmFmt->GetName(); if( rName.Len() ) { AddAttribute( XML_NAMESPACE_TABLE, XML_STYLE_NAME, rName ); } } { SvXMLElementExport aElem( *this, XML_NAMESPACE_TABLE, XML_TABLE_ROW, sal_True, sal_True ); const SwTableBoxes& rBoxes = rLine.GetTabBoxes(); sal_uInt16 nBoxes = rBoxes.Count(); sal_uInt16 nCPos = 0U; sal_uInt16 nCol = 0U; for( sal_uInt16 nBox=0U; nBoxCount(), "SwXMLExport::ExportTableLines: table columns infos missing" ); if( !pTableLines || 0 == pTableLines->Count() ) return; SwXMLTableLines_Impl *pLines = 0; sal_uInt16 nInfoPos; for( nInfoPos=0; nInfoPos < pTableLines->Count(); nInfoPos++ ) { if( pTableLines->GetObject( nInfoPos )->GetLines() == &rLines ) { pLines = pTableLines->GetObject( nInfoPos ); break; } } ASSERT( pLines, "SwXMLExport::ExportTableLines: table columns info missing" ); ASSERT( 0==nInfoPos, "SwXMLExport::ExportTableLines: table columns infos are unsorted" ); if( !pLines ) return; pTableLines->Remove( nInfoPos ); if( 0 == pTableLines->Count() ) { delete pTableLines ; pTableLines = 0; } // pass 2: export columns const SwXMLTableColumns_Impl& rCols = pLines->GetColumns(); sal_uInt16 nColumn = 0U; sal_uInt16 nColumns = rCols.Count(); sal_uInt16 nColRep = 1U; SwXMLTableColumn_Impl *pColumn = (nColumns > 0) ? rCols[0U] : 0; while( pColumn ) { nColumn++; SwXMLTableColumn_Impl *pNextColumn = (nColumn < nColumns) ? rCols[nColumn] : 0; if( pNextColumn && pNextColumn->GetStyleName() == pColumn->GetStyleName() ) { nColRep++; } else { AddAttribute( XML_NAMESPACE_TABLE, XML_STYLE_NAME, pColumn->GetStyleName() ); if( nColRep > 1U ) { OUStringBuffer sTmp(4); sTmp.append( (sal_Int32)nColRep ); AddAttribute( XML_NAMESPACE_TABLE, XML_NUMBER_COLUMNS_REPEATED, sTmp.makeStringAndClear() ); } { SvXMLElementExport aElem( *this, XML_NAMESPACE_TABLE, XML_TABLE_COLUMN, sal_True, sal_True ); } nColRep = 1U; } pColumn = pNextColumn; } // pass 3: export line/rows sal_uInt16 nLines = rLines.Count(); for( sal_uInt16 nLine=0U; nLineGetSttNd() ) { ((SwTableBox *)rpBox)->GetTabLines().ForEach( &lcl_xmltble_ClearName_Line, 0 ); } else { SwFrmFmt *pFrmFmt = ((SwTableBox *)rpBox)->GetFrmFmt(); if( pFrmFmt && pFrmFmt->GetName().Len() ) pFrmFmt->SetName( aEmptyStr ); } return sal_True; } sal_Bool lcl_xmltble_ClearName_Line( const SwTableLine*& rpLine, void* ) { ((SwTableLine *)rpLine)->GetTabBoxes().ForEach( &lcl_xmltble_ClearName_Box, 0 ); return sal_True; } void SwXMLExport::ExportTable( const SwTableNode& rTblNd ) { const SwTable& rTbl = rTblNd.GetTable(); const SwFrmFmt *pTblFmt = rTbl.GetFrmFmt(); if( pTblFmt && pTblFmt->GetName().Len() ) { AddAttribute( XML_NAMESPACE_TABLE, XML_NAME, pTblFmt->GetName() ); AddAttribute( XML_NAMESPACE_TABLE, XML_STYLE_NAME, pTblFmt->GetName() ); } { SvXMLElementExport aElem( *this, XML_NAMESPACE_TABLE, XML_TABLE, sal_True, sal_True ); // export DDE source (if this is a DDE table) if ( IS_TYPE(SwDDETable, &rTbl) ) { // get DDE Field Type (contains the DDE connection) const SwDDEFieldType* pDDEFldType = ((SwDDETable&)rTbl).GetDDEFldType(); // connection name AddAttribute( XML_NAMESPACE_OFFICE, XML_NAME, pDDEFldType->GetName() ); // DDE command const String sCmd = pDDEFldType->GetCmd(); AddAttribute( XML_NAMESPACE_OFFICE, XML_DDE_APPLICATION, sCmd.GetToken(0, so3::cTokenSeperator) ); AddAttribute( XML_NAMESPACE_OFFICE, XML_DDE_ITEM, sCmd.GetToken(1, so3::cTokenSeperator) ); AddAttribute( XML_NAMESPACE_OFFICE, XML_DDE_TOPIC, sCmd.GetToken(2, so3::cTokenSeperator) ); // auto update if (pDDEFldType->GetType() == so3::LINKUPDATE_ALWAYS) { AddAttribute( XML_NAMESPACE_OFFICE, XML_AUTOMATIC_UPDATE, XML_TRUE ); } // DDE source element (always empty) SvXMLElementExport aSource(*this, XML_NAMESPACE_OFFICE, XML_DDE_SOURCE, sal_True, sal_False); } SwXMLTableInfo_Impl aTblInfo( &rTbl ); ExportTableLines( rTbl.GetTabLines(), aTblInfo, rTbl.IsHeadlineRepeat() ); ((SwTable &)rTbl).GetTabLines().ForEach( &lcl_xmltble_ClearName_Line, 0 ); } } void SwXMLTextParagraphExport::exportTable( const Reference < XTextContent > & rTextContent, sal_Bool bAutoStyles, sal_Bool bProgress ) { sal_Bool bOldShowProgress = ((SwXMLExport&)GetExport()).IsShowProgress(); ((SwXMLExport&)GetExport()).SetShowProgress( bProgress ); Reference < XTextTable > xTxtTbl( rTextContent, UNO_QUERY ); DBG_ASSERT( xTxtTbl.is(), "text table missing" ); if( xTxtTbl.is() ) { const SwXTextTable *pXTable = 0; Reference xTableTunnel( rTextContent, UNO_QUERY); if( xTableTunnel.is() ) { pXTable = (SwXTextTable*)xTableTunnel->getSomething( SwXTextTable::getUnoTunnelId() ); ASSERT( pXTable, "SwXTextTable missing" ); } if( pXTable ) { SwFrmFmt *pFmt = pXTable->GetFrmFmt(); ASSERT( pFmt, "table format missing" ); const SwTable *pTbl = SwTable::FindTable( pFmt ); ASSERT( pTbl, "table missing" ); const SwTableNode *pTblNd = pTbl->GetTableNode(); ASSERT( pTblNd, "table node missing" ); if( bAutoStyles ) { ((SwXMLExport&)GetExport()).ExportTableAutoStyles( *pTblNd ); } else { ((SwXMLExport&)GetExport()).ExportTable( *pTblNd ); } } } ((SwXMLExport&)GetExport()).SetShowProgress( bOldShowProgress ); }