22#include <com/sun/star/frame/XModel.hpp>
23#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
24#include <com/sun/star/lang/XMultiServiceFactory.hpp>
25#include <com/sun/star/text/XTextTable.hpp>
26#include <com/sun/star/table/XCellRange.hpp>
117 inline void Set(
const OUString& rStyleName,
118 sal_uInt32 nRSpan, sal_uInt32 nCSpan,
121 const OUString* pFormula,
125 OUString
const*
const pStringValue);
154 sal_uInt32 nRSpan, sal_uInt32 nCSpan,
158 const OUString* pFormula,
162 OUString
const*
const pStringValue )
180 if (pFormula !=
nullptr)
207 std::vector<std::unique_ptr<SwXMLTableCell_Impl>>
m_Cells;
213 const OUString *pDfltCellStyleName =
nullptr );
217 inline void Set(
const OUString& rStyleName,
218 const OUString& rDfltCellStyleName );
220 void Expand( sal_uInt32 nCells,
bool bOneCell );
233 const OUString *pDfltCellStyleName ) :
234 m_aStyleName(
std::move( aStyleName )),
235 m_bSplitable( false )
237 if( pDfltCellStyleName )
239 OSL_ENSURE( nCells <= USHRT_MAX,
240 "SwXMLTableRow_Impl::SwXMLTableRow_Impl: too many cells" );
241 if( nCells > USHRT_MAX )
244 for( sal_uInt32
i=0
U;
i<nCells; ++
i )
246 m_Cells.push_back(std::make_unique<SwXMLTableCell_Impl>());
252 OSL_ENSURE( nCol < USHRT_MAX,
253 "SwXMLTableRow_Impl::GetCell: column number is too big" );
255 OSL_ENSURE( nCol <
m_Cells.size(),
256 "SwXMLTableRow_Impl::GetCell: column number is out of bound" );
262 OSL_ENSURE( nCells <= USHRT_MAX,
263 "SwXMLTableRow_Impl::Expand: too many cells" );
264 if( nCells > USHRT_MAX )
267 sal_uInt32 nColSpan = nCells -
m_Cells.size();
268 for (
size_t i =
m_Cells.size();
i < nCells; ++
i)
270 m_Cells.push_back(std::make_unique<SwXMLTableCell_Impl>(
271 1UL, bOneCell ? nColSpan : 1UL));
275 OSL_ENSURE( nCells <=
m_Cells.size(),
276 "SwXMLTableRow_Impl::Expand: wrong number of cells" );
280 const OUString& rDfltCellStyleName )
298 OUString m_aStyleName;
300 OUString m_sSaveParaDefault;
301 OUString m_StringValue;
307 bool m_bHasStringValue;
308 bool m_bValueTypeIsString;
311 sal_uInt32 m_nRowSpan;
312 sal_uInt32 m_nColSpan;
313 sal_uInt32 m_nColRepeat;
315 bool m_bHasTextContent : 1;
316 bool m_bHasTableContent : 1;
320 bool HasContent()
const {
return m_bHasTextContent || m_bHasTableContent; }
321 inline void InsertContent_();
322 inline void InsertContent();
327 SwXMLTableCellContext_Impl(
329 const Reference< xml::sax::XFastAttributeList > & xAttrList,
334 const Reference< xml::sax::XFastAttributeList > & xAttrList )
override;
335 virtual void SAL_CALL
endFastElement(sal_Int32 nElement)
override;
345 const Reference<xml::sax::XFastAttributeList>& xAttrList,
349SwXMLCoveredTableCellContext::SwXMLCoveredTableCellContext(
350 SwXMLImport& rImport,
const Reference<xml::sax::XFastAttributeList>& xAttrList,
357 switch (rIter.getToken())
365 if (!aStyleName.isEmpty())
372SwXMLTableCellContext_Impl::SwXMLTableCellContext_Impl(
374 const Reference< xml::sax::XFastAttributeList > & xAttrList,
377 m_xMyTable( pTable ),
379 m_bHasValue( false ),
380 m_bHasStringValue(false),
381 m_bValueTypeIsString(false),
386 m_bHasTextContent( false ),
387 m_bHasTableContent( false )
389 m_sSaveParaDefault = GetImport().GetTextImport()->GetCellParaStyleDefault();
392 switch( aIter.getToken() )
396 GetImport().GetTextImport()->SetCellParaStyleDefault(
m_aStyleName);
398 case XML_ELEMENT(TABLE, XML_NUMBER_COLUMNS_SPANNED):
399 m_nColSpan = static_cast<sal_uInt32>(
std::
max<sal_Int32>(1, aIter.
toInt32()));
400 if (m_nColSpan > 256)
402 SAL_INFO(
"sw.xml",
"ignoring huge table:number-columns-spanned " << m_nColSpan);
407 m_nRowSpan = static_cast<sal_uInt32>(
std::
max<sal_Int32>(1, aIter.
toInt32()));
410 SAL_INFO(
"sw.xml",
"ignoring huge table:number-rows-spanned " << m_nRowSpan);
414 case XML_ELEMENT(TABLE, XML_NUMBER_COLUMNS_REPEATED):
415 m_nColRepeat = static_cast<sal_uInt32>(
std::
max<sal_Int32>(1, aIter.
toInt32()));
416 if (m_nColRepeat > 256)
418 SAL_INFO(
"sw.xml",
"ignoring huge table:number-columns-repeated " << m_nColRepeat);
425 const sal_uInt16 nPrefix2 = GetImport().GetNamespaceMap().
426 GetKeyByAttrValueQName(aIter.toString(), &sTmp);
455 if (GetImport().GetMM100UnitConverter().convertDateTime(fTmp,
468 m_fValue = (bTmp ? 1.0 : 0.0);
485 m_StringValue = aIter.toString();
486 m_bHasStringValue =
true;
491 if (
"string" == aIter.toView())
493 m_bValueTypeIsString =
true;
501 SAL_WARN(
"sw",
"unknown attribute " << SvXMLImport::getPrefixAndNameFromToken(aIter.getToken()) <<
"=" << aIter.toString());
506inline void SwXMLTableCellContext_Impl::InsertContent_()
508 SwStartNode const*
const pStartNode( GetTable()->InsertTableSection(
nullptr,
509 (m_bHasStringValue && m_bValueTypeIsString &&
510 !m_aStyleName.isEmpty()) ? & m_aStyleName :
nullptr) );
511 GetTable()->InsertCell( m_aStyleName, m_nRowSpan, m_nColSpan,
513 nullptr, m_bProtect, &m_sFormula, m_bHasValue, m_fValue,
514 (m_bHasStringValue && m_bValueTypeIsString) ? &m_StringValue :
nullptr);
517inline void SwXMLTableCellContext_Impl::InsertContent()
519 OSL_ENSURE( !HasContent(),
"content already there" );
520 m_bHasTextContent =
true;
524inline void SwXMLTableCellContext_Impl::InsertContent(
527 GetTable()->InsertCell( m_aStyleName, m_nRowSpan, m_nColSpan,
nullptr, pTable, m_bProtect );
528 m_bHasTableContent =
true;
531css::uno::Reference<css::xml::sax::XFastContextHandler> SwXMLTableCellContext_Impl::createFastChildContext(
533 const Reference< xml::sax::XFastAttributeList > & xAttrList )
537 bool bSubTable =
false;
542 if( aIter.getToken() ==
XML_ELEMENT(TABLE, XML_IS_SUB_TABLE) )
559 pContext = pTableContext;
560 if( GetTable()->IsValid() )
561 InsertContent( pTableContext );
563 GetTable()->SetHasSubTables(
true );
568 if( GetTable()->IsValid() && !HasContent() )
571 if (!(m_bValueTypeIsString && m_bHasStringValue))
573 pContext = GetImport().GetTextImport()->CreateTextChildContext(
574 GetImport(), nElement, xAttrList,
582void SwXMLTableCellContext_Impl::endFastElement(sal_Int32 )
584 if( GetTable()->IsValid() )
586 if( m_bHasTextContent )
588 GetImport().GetTextImport()->DeleteParagraph();
589 if( m_nColRepeat > 1 && m_nColSpan == 1 )
593 Reference < XTextCursor > xSrcTextCursor =
594 GetImport().GetTextImport()->GetText()->createTextCursor();
595 xSrcTextCursor->gotoEnd(
true );
598 OTextCursorHelper *pSrcTextCursor =
dynamic_cast<OTextCursorHelper*
>(xSrcTextCursor.get());
599 assert(pSrcTextCursor &&
"SwXTextCursor missing");
600 SwDoc *pDoc = pSrcTextCursor->GetDoc();
601 const SwPaM *pSrcPaM = pSrcTextCursor->GetPaM();
603 while( m_nColRepeat > 1 && GetTable()->IsInsertCellPossible() )
607 OTextCursorHelper *pDstTextCursor =
dynamic_cast<OTextCursorHelper*
>(GetImport().GetTextImport()->GetCursor().get());
608 assert(pDstTextCursor &&
"SwXTextCursor missing");
610 SwPosition aDstPos( *pDstTextCursor->GetPaM()->GetPoint() );
617 else if( !m_bHasTableContent )
620 if( m_nColRepeat > 1 && m_nColSpan == 1 )
622 while( m_nColRepeat > 1 && GetTable()->IsInsertCellPossible() )
630 GetImport().GetTextImport()->SetCellParaStyleDefault(m_sSaveParaDefault);
643 SwXMLTableColContext_Impl(
645 const Reference< xml::sax::XFastAttributeList > & xAttrList,
653SwXMLTableColContext_Impl::SwXMLTableColContext_Impl(
655 const Reference< xml::sax::XFastAttributeList > & xAttrList,
660 sal_uInt32 nColRep = 1;
661 OUString aStyleName, aDfltCellStyleName;
665 switch (aIter.getToken())
670 case XML_ELEMENT(TABLE, XML_NUMBER_COLUMNS_REPEATED):
672 nColRep =
static_cast<sal_uInt32
>(std::max<sal_Int32>(1, aIter.toInt32()));
675 SAL_INFO(
"sw.xml",
"ignoring huge table:number-columns-repeated " << nColRep);
680 case XML_ELEMENT(TABLE, XML_DEFAULT_CELL_STYLE_NAME):
681 aDfltCellStyleName = aIter.
toString();
693 sal_Int32 nWidth =
MINLAY;
694 bool bRelWidth =
true;
695 if( !aStyleName.isEmpty() )
699 if( GetSwImport().FindAutomaticStyle(
700 XmlStyleFamily::TABLE_COLUMN,
701 aStyleName, &pAutoItemSet ) &&
712 while( nColRep-- && GetTable()->IsInsertColPossible() )
713 GetTable()->InsertColumn( nWidth, bRelWidth, &aDfltCellStyleName );
727 SwXMLTableColsContext_Impl(
732 sal_Int32 Element,
const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList )
override;
739SwXMLTableColsContext_Impl::SwXMLTableColsContext_Impl(
747css::uno::Reference< css::xml::sax::XFastContextHandler > SwXMLTableColsContext_Impl::createFastChildContext(
748 sal_Int32 nElement,
const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList )
752 if( nElement ==
XML_ELEMENT(TABLE, XML_TABLE_COLUMN) &&
753 GetTable()->IsInsertColPossible() )
754 pContext =
new SwXMLTableColContext_Impl( GetSwImport(), xAttrList, GetTable() );
767 sal_uInt32 m_nRowRepeat;
773 SwXMLTableRowContext_Impl(
775 const Reference< xml::sax::XFastAttributeList > & xAttrList,
778 virtual css::uno::Reference<css::xml::sax::XFastContextHandler> SAL_CALL
createFastChildContext( sal_Int32 nElement,
779 const Reference< xml::sax::XFastAttributeList > & xAttrList )
override;
781 virtual void SAL_CALL
endFastElement(sal_Int32 nElement)
override;
788SwXMLTableRowContext_Impl::SwXMLTableRowContext_Impl(
SwXMLImport& rImport,
790 const Reference< xml::sax::XFastAttributeList > & xAttrList,
794 m_xMyTable( pTable ),
797 OUString aStyleName, aDfltCellStyleName;
801 switch(aIter.getToken())
808 m_nRowRepeat =
static_cast<sal_uInt32
>(std::max<sal_Int32>(1, aIter.toInt32()));
811 SAL_INFO(
"sw.xml",
"ignoring huge table:number-rows-repeated " << m_nRowRepeat);
816 case XML_ELEMENT(STYLE, XML_DEFAULT_CELL_STYLE_NAME):
817 aDfltCellStyleName = aIter.
toString();
825 if( GetTable()->IsValid() )
826 GetTable()->InsertRow( aStyleName, aDfltCellStyleName, bInHead );
829void SwXMLTableRowContext_Impl::endFastElement(sal_Int32 )
831 if( GetTable()->IsValid() )
833 GetTable()->FinishRow();
835 if( m_nRowRepeat > 1 )
836 GetTable()->InsertRepRows( m_nRowRepeat );
840css::uno::Reference<css::xml::sax::XFastContextHandler> SwXMLTableRowContext_Impl::createFastChildContext(
842 const Reference< xml::sax::XFastAttributeList > & xAttrList )
846 if( nElement ==
XML_ELEMENT(TABLE, XML_TABLE_CELL) ||
849 if( !GetTable()->IsValid() || GetTable()->IsInsertCellPossible() )
850 pContext =
new SwXMLTableCellContext_Impl( GetSwImport(), nElement,
854 else if( nElement ==
XML_ELEMENT(TABLE, XML_COVERED_TABLE_CELL) ||
855 nElement ==
XML_ELEMENT(LO_EXT, XML_COVERED_TABLE_CELL) )
857 if (GetTable()->IsValid() && GetTable()->IsInsertCoveredCellPossible())
859 pContext =
new SwXMLCoveredTableCellContext(GetSwImport(), xAttrList, *GetTable());
867 SAL_WARN(
"sw",
"unknown element " << SvXMLImport::getPrefixAndNameFromToken(nElement));
890 const Reference< xml::sax::XFastAttributeList > & xAttrList )
override;
897SwXMLTableRowsContext_Impl::SwXMLTableRowsContext_Impl(
SwXMLImport& rImport,
901 m_xMyTable( pTable ),
906css::uno::Reference<css::xml::sax::XFastContextHandler> SwXMLTableRowsContext_Impl::createFastChildContext(
908 const Reference< xml::sax::XFastAttributeList > & xAttrList )
910 if( nElement==
XML_ELEMENT(TABLE, XML_TABLE_ROW ) &&
911 GetTable()->IsInsertRowPossible() )
912 return new SwXMLTableRowContext_Impl( GetSwImport(), nElement,
916 SAL_WARN(
"sw",
"unknown element " << SvXMLImport::getPrefixAndNameFromToken(nElement));
935 const Reference<xml::sax::XFastAttributeList> & xAttrList)
override;
947 m_bIsAutomaticUpdate(false)
953 const Reference<xml::sax::XFastAttributeList> & xAttrList)
957 switch (aIter.getToken())
990 const OUString sPrefixStr(
sPrefix.isEmpty() ? OUString(
"_") :
sPrefix);
1021 ? SfxLinkUpdateMode::ALWAYS
1022 : SfxLinkUpdateMode::ONCALL;
1030 if (
sName.isEmpty())
1039 if (
nullptr != pOldType)
1042 if ( (pOldType->
GetCmd() == sCommand) &&
1059 if (
nullptr == pType)
1067 OSL_ENSURE(
nullptr != pType,
"We really want a SwDDEFieldType here!");
1103 sal_uInt32 nCol )
const
1105 return (*
m_pRows)[nRow]->GetCell( nCol );
1111 return (*
m_pRows)[nRow]->GetCell( nCol );
1116 const Reference< xml::sax::XFastAttributeList > & xAttrList ) :
1119 m_pTableNode( nullptr ),
1121 m_bOwnsBox1( false ),
1122 m_pSttNd1( nullptr ),
1123 m_pBoxFormat( nullptr ),
1124 m_pLineFormat( nullptr ),
1125 m_bFirstSection( true ),
1126 m_bRelWidth( true ),
1127 m_bHasSubTables( false ),
1131 m_nNonMergedCurCol( 0 ),
1142 const OUString sValue = aIter.toString();
1143 switch(aIter.getToken())
1151 case XML_ELEMENT(TABLE, XML_DEFAULT_CELL_STYLE_NAME):
1167 OUString sTableName;
1168 if( !
aName.isEmpty() )
1174 if( sTableName.isEmpty() )
1178 ->GetRenameMap().Add( XML_TEXT_RENAME_TYPE_TABLE, aName, sTableName );
1181 Reference< XTextTable > xTable;
1185 OSL_ENSURE(
xFactory.is(),
"factory missing" );
1188 Reference<XInterface> xIfc =
xFactory->createInstance(
"com.sun.star.text.TextTable" );
1189 OSL_ENSURE( xIfc.is(),
"Couldn't create a table" );
1192 xTable.set( xIfc, UNO_QUERY );
1197 xTable->initialize( 1, 1 );
1204 catch( IllegalArgumentException& )
1218 Reference < XCellRange > xCellRange( xTable, UNO_QUERY );
1219 Reference < XCell > xCell = xCellRange->getCellByPosition( 0, 0 );
1220 Reference < XText> xText( xCell, UNO_QUERY );
1222 GetImport().GetTextImport()->SetCursor( xText->createTextCursor() );
1225 GetImport().GetTextImport()->RedlineAdjustStartNodeCursor();
1231 OSL_ENSURE( pTableFrameFormat,
"table format missing" );
1233 OSL_ENSURE( pTable,
"table missing" );
1248 m_pTableNode( pTable->m_pTableNode ),
1250 m_bOwnsBox1( false ),
1251 m_pSttNd1( nullptr ),
1252 m_pBoxFormat( nullptr ),
1253 m_pLineFormat( nullptr ),
1254 m_xParentTable( pTable ),
1255 m_bFirstSection( false ),
1256 m_bRelWidth( true ),
1257 m_bHasSubTables( false ),
1261 m_nNonMergedCurCol( 0 ),
1275 GetImport().GetTextImport()->RedlineAdjustStartNodeCursor();
1280 const Reference< xml::sax::XFastAttributeList > & xAttrList )
1282 bool bHeader =
false;
1288 return new SwXMLTableRowContext_Impl(
GetSwImport(), nElement, xAttrList,
this );
1294 return new SwXMLTableRowsContext_Impl(
GetSwImport(),
this, bHeader );
1304 return new SwXMLTableColsContext_Impl(
GetSwImport(),
this );
1309 return new SwXMLTableColContext_Impl(
GetSwImport(), xAttrList,
1325 const OUString *pDfltCellStyleName )
1328 "SwXMLTableContext::InsertColumn: no space left" );
1337 if( !((pDfltCellStyleName && !pDfltCellStyleName->isEmpty()) ||
1349 if(pDfltCellStyleName)
1356 sal_uInt32 nColSpan )
const
1358 sal_uInt32 nLast = nCol+nColSpan;
1362 sal_Int32 nWidth2 = 0;
1363 for( sal_uInt32
i=nCol;
i < nLast; ++
i )
1378 sal_uInt32 nRowSpan, sal_uInt32 nColSpan,
1382 const OUString* pFormula,
1385 OUString
const*
const pStringValue )
1388 "SwXMLTableContext::InsertCell: row is full" );
1390 "SwXMLTableContext::InsertCell: table is full" );
1394 OSL_ENSURE( nRowSpan >=1,
"SwXMLTableContext::InsertCell: row span is 0" );
1397 OSL_ENSURE( nColSpan >=1,
"SwXMLTableContext::InsertCell: col span is 0" );
1402 sal_uInt32 nColsReq =
m_nCurCol + nColSpan;
1428 sal_uInt32 nRowsReq =
m_nCurRow + nRowSpan;
1429 if( nRowsReq > USHRT_MAX )
1432 nRowsReq = USHRT_MAX;
1449 if (
m_pRows->size() < nRowsReq)
1451 for (
size_t i =
m_pRows->size();
i < nRowsReq; ++
i)
1452 m_pRows->push_back(std::make_unique<SwXMLTableRow_Impl>(
1456 OUString sStyleName( rStyleName );
1457 if( sStyleName.isEmpty() )
1459 sStyleName = (*m_pRows)[
m_nCurRow]->GetDefaultCellStyleName();
1463 if( sStyleName.isEmpty() )
1469 for( sal_uInt32
i=nColSpan;
i>0; --
i )
1471 for( sal_uInt32 j=nRowSpan; j>0; --j )
1473 const bool bCovered =
i != nColSpan || j != nRowSpan;
1476 throw css::lang::IndexOutOfBoundsException();
1477 pCell->
Set( sStyleName, j,
i, pStartNode,
1478 pTable, bProtect, pFormula, bHasValue, bCovered, fValue,
1503 const OUString& rDfltCellStyleName,
1507 "SwXMLTableContext::InsertRow: no space left" );
1515 if (m_nCurRow < m_pRows->
size())
1520 rStyleName, rDfltCellStyleName );
1525 m_pRows->push_back(std::make_unique<SwXMLTableRow_Impl>(
1527 &rDfltCellStyleName));
1583 sal_uInt32 nCol )
const
1594 pPrevCell =
GetCell( nRow, nCol-1 );
1612 OSL_ENSURE( pSttNd !=
nullptr,
1620 sal_uInt32 nColSpan )
1622 sal_uInt32 nLastCol = nCol + nColSpan;
1623 for( sal_uInt32
i = nCol;
i < nLastCol;
i++ )
1625 sal_uInt32 j = nRow;
1626 sal_uInt32 nRowSpan = 1;
1631 pCell = j > 0 ?
GetCell( --j,
i ) :
nullptr;
1642 sal_uInt32 nLastRow = bRows ? nRow + pCell->
GetRowSpan() : nRow + 1;
1643 sal_uInt32 nLastCol = nCol + pCell->
GetColSpan();
1645 for( sal_uInt32
i=nRow;
i<nLastRow;
i++ )
1648 for( sal_uInt32 j=nCol; j<nLastCol; j++ )
1683 const OUString& rStyleName,
1684 sal_Int32 nColumnWidth,
1688 bool* pModifyLocked )
1711 (*m_pSharedBoxFormats)[ aKey ] = pBoxFormat2;
1716 pBoxFormat2 = aIter->second;
1726 if ( pModifyLocked !=
nullptr )
1728 (*pModifyLocked) = pBoxFormat2->IsModifyLocked();
1729 pBoxFormat2->LockModify();
1737 sal_uInt32 nLeftCol,
1738 sal_uInt32 nBottomRow,
1739 sal_uInt32 nRightCol )
1744 sal_uInt32 nColSpan = nRightCol - nLeftCol;
1756 bool bSplitted =
false;
1760 sal_uInt32 nStartRow = nTopRow;
1763 for(
i = nTopRow;
i < nBottomRow;
i++ )
1768 for( sal_uInt32 j=nLeftCol; j<nRightCol; j++ )
1774 if( bSplit && (nStartRow>nTopRow ||
i+1<nBottomRow) )
1791 nStartRow = nTopRow;
1792 while( nStartRow < nBottomRow )
1794 sal_uInt32 nMaxRowSpan = 0;
1797 for(
i=nLeftCol;
i<nRightCol;
i++ )
1804 nStartRow += nMaxRowSpan;
1805 if( nStartRow<nBottomRow )
1809 while(
i < nRightCol )
1815 const sal_uInt32 nColSpan2 = pCell2->
GetColSpan();
1836 sal_uInt32 nLeftCol, sal_uInt32 nRightCol )
1840 sal_uInt32 nColSpan = nRightCol - nLeftCol;
1860 pBox, sStyleName, nColWidth, pCell->
IsProtected(),
1863 bNew, &bModifyLocked );
1872 XmlStyleFamily::TABLE_CELL, sStyleName, &pAutoItemSet ) )
1885 SAL_WARN_IF(!pTextNode,
"sw",
"Should have a text node in cell?");
1902 bool bSuppressNumericContent =
false;
1905 !sStyleName.isEmpty() )
1918 if( pTextNode !=
nullptr )
1921 const OUString& rText = pTextNode->
GetText();
1922 if( ( rText.getLength() > 10 ) ||
1923 ( rText.indexOf(
'0' ) == -1 ) )
1925 bSuppressNumericContent =
true;
1930 bSuppressNumericContent =
true;
1935 if( bSuppressNumericContent )
1946 const OUString& rFormula = pCell->
GetFormula();
1947 if (!rFormula.isEmpty())
1964 if( pNumFormat !=
nullptr && pNumberFormatter &&
1990 if (! bModifyLocked)
1991 pBoxFormat2->UnlockModify();
2000 sal_uInt32 nLeftCol,
2001 sal_uInt32 nBottomRow,
2002 sal_uInt32 nRightCol )
2006 if( !pUpper && 0
UL==nTopRow )
2022 const OUString& rStyleName = (*m_pRows)[nTopRow]->GetStyleName();
2023 if( 1 == (nBottomRow - nTopRow) &&
2024 !rStyleName.isEmpty() &&
2026 XmlStyleFamily::TABLE_ROW, rStyleName, &pAutoItemSet ) )
2034 sal_uInt32 nStartCol = nLeftCol;
2035 while( nStartCol < nRightCol )
2037 for( sal_uInt32 nRow=nTopRow; nRow<nBottomRow; nRow++ )
2038 (*
m_pRows)[nRow]->SetSplitable(
true );
2040 sal_uInt32 nCol = nStartCol;
2041 sal_uInt32 nSplitCol = nRightCol;
2042 bool bSplitted =
false;
2045 OSL_ENSURE( nCol < nRightCol,
"Ran too far" );
2051 bool bHoriSplitMayContinue =
false;
2052 bool bHoriSplitPossible =
false;
2057 for( sal_uInt32 nRow=nTopRow; nRow<nBottomRow; nRow++ )
2062 bool bHoriSplit = (*m_pRows)[nRow]->IsSplitable() &&
2063 nRow+1 < nBottomRow &&
2065 (*m_pRows)[nRow]->SetSplitable( bHoriSplit );
2072 bHoriSplitPossible |= bHoriSplit;
2076 bHoriSplit &= (nCol+1 < nRightCol &&
2078 bHoriSplitMayContinue |= bHoriSplit;
2088 if ( pCell ==
nullptr )
2090 OSL_FAIL(
"table seems to be corrupt." );
2099#if OSL_DEBUG_LEVEL > 0
2100 if( nCol == nRightCol-1 )
2102 OSL_ENSURE( bSplit,
"Split-Flag wrong" );
2105 OSL_ENSURE( !bHoriSplitMayContinue,
2106 "HoriSplitMayContinue-Flag wrong" );
2108 OSL_ENSURE( pTmpCell->
GetRowSpan() != (nBottomRow-nTopRow) ||
2109 !bHoriSplitPossible,
"HoriSplitPossible-Flag wrong" );
2114 OSL_ENSURE( !
m_bHasSubTables || !bHoriSplitMayContinue || bHoriSplitPossible,
2115 "bHoriSplitMayContinue, but not bHoriSplitPossible" );
2127 sal_Int32 nBoxRowSpan = 1;
2133 nBoxRowSpan = -1 * nBoxRowSpan;
2140 nSplitCol = nCol + 1;
2142 pBox =
MakeTableBox( pLine, pCell, nStartCol, nSplitCol );
2144 if ( 1 != nBoxRowSpan )
2149 else if(
m_bHasSubTables && bHoriSplitPossible && bHoriSplitMayContinue )
2157 nSplitCol = nCol + 1;
2168 if( bHoriSplitPossible || nSplitCol > nCol+1 )
2170 OSL_ENSURE( !bHoriSplitMayContinue,
2171 "bHoriSplitMayContinue==true" );
2172 OSL_ENSURE( bHoriSplitPossible || nSplitCol == nRightCol,
2173 "bHoriSplitPossible flag should be set" );
2175 nSplitCol = nCol + 1;
2179 nBottomRow, nSplitCol );
2186 rBoxes.push_back( pBox );
2190 nStartCol = nSplitCol;
2199 std::vector<ColumnWidthInfo>::iterator colIter;
2228 sal_Int32 nAbsWidth = 0;
2229 sal_Int32 nMinAbsColWidth = 0;
2230 sal_Int32 nRelWidth = 0;
2231 sal_Int32 nMinRelColWidth = 0;
2232 sal_uInt32 nRelCols = 0;
2235 if( rCol.isRelative )
2237 nRelWidth += rCol.width;
2238 if( 0 == nMinRelColWidth || rCol.width < nMinRelColWidth )
2239 nMinRelColWidth = rCol.width;
2244 nAbsWidth += rCol.width;
2245 if( 0 == nMinAbsColWidth || rCol.width < nMinAbsColWidth )
2246 nMinAbsColWidth = rCol.width;
2249 sal_uInt32 nAbsCols = nCols - nRelCols;
2262 if( 0 == nMinRelColWidth )
2263 nMinRelColWidth = nMinAbsColWidth;
2267 if( !rCol.isRelative )
2269 if (nMinAbsColWidth == 0)
2272 if (o3tl::checked_multiply<sal_Int32>(rCol.width, nMinRelColWidth, nVal))
2273 throw std::overflow_error(
"overflow in multiply");
2274 sal_Int32 nRelCol = nVal / nMinAbsColWidth;
2275 rCol.width = nRelCol;
2276 rCol.isRelative =
true;
2277 nRelWidth += nRelCol;
2293 if( nRelWidth !=
m_nWidth && nRelWidth && nCols )
2295 double n =
static_cast<double>(
m_nWidth) /
static_cast<double>(nRelWidth);
2299 sal_Int32 nW =
static_cast<sal_Int32
>( colIter->width *
n);
2300 colIter->width = o3tl::narrowing<sal_uInt16>(nW);
2314 sal_Int32 nAbsForRelWidth =
2319 sal_Int32 nExtraRel = nRelWidth - (nRelCols * nMinRelColWidth);
2323 sal_Int32 nMinAbs = nRelCols *
MINLAY;
2324 sal_Int32 nExtraAbs =
2325 nAbsForRelWidth > nMinAbs ? nAbsForRelWidth - nMinAbs : sal_Int32(0L);
2328 bool bMinExtra =
false;
2331 if( nAbsForRelWidth <= nMinAbs )
2335 nAbsForRelWidth = nMinAbs;
2338 else if( nAbsForRelWidth <= (nRelWidth *
MINLAY) /
2353 if( rCol.isRelative )
2360 nAbsCol = nAbsForRelWidth;
2368 else if( bMinExtra )
2370 sal_Int32 nExtraRelCol = rCol.width - nMinRelColWidth;
2371 nAbsCol =
MINLAY + (nExtraRelCol * nExtraAbs) /
2376 nAbsCol = ( rCol.width * nAbsForRelWidth) / nRelWidth;
2379 rCol.width = nAbsCol;
2380 rCol.isRelative =
false;
2381 nAbsForRelWidth -= nAbsCol;
2382 nAbsWidth += nAbsCol;
2390 if( nCols && nAbsWidth )
2396 sal_Int32 nExtraAbs =
m_nWidth - nAbsWidth;
2400 sal_Int32 nAbsCol = colIter->width;
2401 sal_Int32 nExtraAbsCol = (nAbsCol * nExtraAbs) /
2403 nAbsCol += nExtraAbsCol;
2404 colIter->width = nAbsCol;
2405 nAbsLastCol -= nExtraAbsCol;
2415 sal_Int32 nAbsLastCol =
MINLAY + nExtraAbs;
2418 sal_Int32 nAbsCol = colIter->width;
2419 sal_Int32 nExtraAbsCol = (nAbsCol * nExtraAbs) /
2421 nAbsCol =
MINLAY + nExtraAbsCol;
2422 colIter->width = nAbsCol;
2423 nAbsLastCol -= nExtraAbsCol;
2434 sal_uInt32 nStartRow = 0;
2435 sal_uInt32 nRows =
m_pRows->size();
2436 for(sal_uInt32
i=0;
i<nRows; ++
i )
2443 for( sal_uInt32 j=0; j<nCols; j++ )
2455 if( pBox || nStartRow>0 )
2472 OSL_FAIL(
"invalid table: no cells; deleting...");
2485 sal_Int16 eHoriOrient = text::HoriOrientation::FULL;
2486 bool bSetHoriOrient =
false;
2490 OUString sStyleName;
2499 XmlStyleFamily::TABLE_TABLE,
m_aStyleName, &pAutoItemSet ) &&
2507 eHoriOrient = pItem->GetHoriOrient();
2508 switch( eHoriOrient )
2510 case text::HoriOrientation::FULL:
2514 bSetHoriOrient =
true;
2517 case text::HoriOrientation::LEFT:
2520 eHoriOrient = text::HoriOrientation::LEFT_AND_WIDTH;
2521 bSetHoriOrient =
true;
2530 bSetHoriOrient =
true;
2536 switch( eHoriOrient )
2538 case text::HoriOrientation::FULL:
2559 sal_Int32
const min =
static_cast<sal_Int32
>(
2574 eHoriOrient = text::HoriOrientation::LEFT_AND_WIDTH == eHoriOrient
2576 bSetHoriOrient =
true;
2586 bSetHoriOrient =
true;
2601 if( bSetHoriOrient )
2606 pFrameFormat->LockModify();
2610 pFrameFormat->UnlockModify();
2612 for (std::unique_ptr<SwXMLTableRow_Impl> & rRow : *
m_pRows)
2628 pFieldType,
false ) );
2652 for (std::unique_ptr<SwXMLTableRow_Impl> & rpRow : *
m_pRows)
2661 OUString
const*
const pStringValueStyleName)
2673 Reference<XInterface> xCursorTunnel(
GetImport().GetTextImport()->GetCursor(),
2675 OSL_ENSURE( xCursorTunnel.is(),
"missing XUnoTunnel for Cursor" );
2676 OTextCursorHelper *pTextCursor =
dynamic_cast<OTextCursorHelper*
>(xCursorTunnel.get());
2677 assert(pTextCursor &&
"SwXTextCursor missing");
2683 GetImport().GetTextImport()->GetCursor(),
"Standard",
true );
2691 OSL_ENSURE( pDoc,
"<SwXMLTableContext::InsertTableSection(..)> - no <pDoc> at <SwXTextCursor> instance - <SwXTextCurosr> doesn't seem to be registered at a <SwUnoCursor> instance." );
2703 if( !pPrevSttNd &&
m_pBox1 !=
nullptr )
2711 SwPaM aPam(*pCNd, *pCNd);
2715 GetImport().GetTextImport()->SetCursor(
static_cast<XWordCursor*
>(xTextCursor.get()) );
2719 if (pStringValueStyleName)
2722 GetImport().GetTextImport()->GetCursor(), *pStringValueStyleName,
2723 true,
false, -1,
false);
@ CheckPosInFly
check if target position is in fly anchored at source range
virtual bool CopyRange(SwPaM &rPam, SwPosition &rPos, SwCopyFlags flags) const =0
Copy a selected content range to a position.
virtual void DeleteSection(SwNode *pNode)=0
Delete section containing the node.
virtual SwFieldType * GetFieldType(SwFieldIds nResId, const OUString &rName, bool bDbFieldMatching) const =0
virtual SwFieldType * InsertFieldType(const SwFieldType &)=0
virtual const SwViewShell * GetCurrentViewShell() const =0
Returns the layout set at the document.
virtual SwTextFormatColl * GetTextCollFromPool(sal_uInt16 nId, bool bRegardLanguage=true)=0
Return "Auto-Collection with ID.
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
virtual void SAL_CALL endFastElement(sal_Int32 Element) override
SvXMLImport & GetImport()
virtual css::uno::Reference< XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
void SetContentProtect(bool bNew)
tools::Long GetWidth() const
Marks a character position inside a document model content node (SwContentNode)
OUString const & GetCmd() const
SfxLinkUpdateMode GetType() const
IDocumentContentOperations const & getIDocumentContentOperations() const
IDocumentFieldsAccess const & getIDocumentFieldsAccess() const
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
SwTableFormat * FindTableFormatByName(const OUString &rName, bool bAll=false) const
OUString GetUniqueTableName() const
IDocumentStylePoolAccess const & getIDocumentStylePoolAccess() const
SvNumberFormatter * GetNumberFormatter(bool bCreate=true)
Ends a section of nodes in the document model.
Marks a node in the document model.
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
SwNodeOffset GetIndex() const
const SwStartNode * FindTableBoxStartNode() const
SwNodeOffset StartOfSectionIndex() const
SwNodeOffset EndOfSectionIndex() const
const IDocumentFieldsAccess & getIDocumentFieldsAccess() const
Provides access to the document fields administration interface.
const SwEndNode * EndOfSectionNode() const
SwStartNode * MakeTextSection(const SwNode &rWhere, SwStartNodeType eSttNdTyp, SwTextFormatColl *pColl)
PaM is Point and Mark: a selection of the document model.
const SwPosition * GetMark() const
const SwPosition * GetPoint() const
Starts a section of nodes in the document model.
static void FillUIName(const OUString &rName, OUString &rFillName, SwGetPoolIdFromName)
SwTableBox is one table cell in the document model.
void SetUpper(SwTableLine *pNew)
void setRowSpan(sal_Int32 nNewRowSpan)
const SwStartNode * m_pStartNode
SwFrameFormat * GetFrameFormat()
SwTableLines & GetTabLines()
const SwStartNode * GetSttNd() const
void ChgFrameFormat(SwTableBoxFormat *pNewFormat, bool bNeedToReregister=true)
SwFrameFormat * ClaimFrameFormat()
SwTableLine is one table row in the document model.
SwFrameFormat * GetFrameFormat()
SwFrameFormat * ClaimFrameFormat()
SwTableBoxes & GetTabBoxes()
void push_back(SwTableLine *pLine)
void SetNewTable(std::unique_ptr< SwTable >, bool bNewFrames=true)
const SwTable & GetTable() const
void MakeOwnFrames(SwPosition *pIdxBehind=nullptr)
Creates the frms for the table node (i.e.
void DelFrames(SwRootFrame const *pLayout=nullptr)
Method deletes all views of document for the node.
SwTable is one table in the document model, containing rows (which contain cells).
SwTableNode * GetTableNode() const
void SetTableModel(bool bNew)
void SetRowsToRepeat(sal_uInt16 nNumOfRows)
SwTableLines & GetTabLines()
SwTableFormat * GetFrameFormat()
void SetTableStyleName(const OUString &rName)
Set the new table style name for this table.
static SwTable * FindTable(SwFrameFormat const *const pFormat)
Represents the style of a paragraph.
SwTextNode is a paragraph in the document model.
OUString InsertText(const OUString &rStr, const SwContentIndex &rIdx, const SwInsertFlags nMode=SwInsertFlags::DEFAULT)
insert text content
const OUString & GetText() const
static rtl::Reference< SwXCell > CreateXCell(SwFrameFormat *pTableFormat, SwTableBox *pBox, SwTable *pTable=nullptr)
OUString m_sConnectionName
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const Reference< xml::sax::XFastAttributeList > &xAttrList) override
SwXMLDDETableContext_Impl(SwXMLImport &rImport)
bool m_bIsAutomaticUpdate
bool GetIsAutomaticUpdate() const
OUString & GetDDEApplication()
OUString & GetConnectionName()
OUString m_sDDEApplication
const SwDoc * getDoc() const
bool FindAutomaticStyle(XmlStyleFamily nFamily, const OUString &rName, const SfxItemSet **ppItemSet) const
void SetRowSpan(sal_uInt32 nSet)
void SetStyleName(const OUString &rStyleName)
bool HasStringValue() const
const SwStartNode * m_pStartNode
sal_uInt32 GetColSpan() const
void SetStartNode(const SwStartNode *pSttNd)
sal_uInt32 GetRowSpan() const
SwXMLTableCell_Impl(sal_uInt32 nRSpan=1, sal_uInt32 nCSpan=1)
SwXMLTableContext * GetSubTable() const
const OUString & GetStyleName() const
OUString const * GetStringValue() const
const SwStartNode * GetStartNode() const
void Set(const OUString &rStyleName, sal_uInt32 nRSpan, sal_uInt32 nCSpan, const SwStartNode *pStNd, SwXMLTableContext *pTable, bool bProtect, const OUString *pFormula, bool bHasValue, bool bCovered, double dVal, OUString const *const pStringValue)
const OUString & GetFormula() const
SvXMLImportContextRef m_xSubTable
std::unique_ptr< SwXMLTableRows_Impl > m_pRows
const SwXMLTableCell_Impl * GetCell(sal_uInt32 nRow, sal_uInt32 nCol) const
sal_uInt32 GetColumnCount() const
std::unique_ptr< map_BoxFormat > m_pSharedBoxFormats
std::vector< ColumnWidthInfo > m_aColumnWidths
void InsertCoveredCell(const OUString &rStyleName)
Sets formatting of an already created covered cell.
void FixRowSpan(sal_uInt32 nRow, sal_uInt32 nCol, sal_uInt32 nColSpan)
SwTableBoxFormat * m_pBoxFormat
void InsertColumn(sal_Int32 nWidth, bool bRelWidth, const OUString *pDfltCellStyleName=nullptr)
sal_uInt32 m_nNonMergedCurCol
Same as m_nCurCol, but not incremented multiple times for table cells with row span.
SwTableBox * NewTableBox(const SwStartNode *pStNd, SwTableLine *pUpper)
void InsertCell(const OUString &rStyleName, sal_uInt32 nRowSpan, sal_uInt32 nColSpan, const SwStartNode *pStNd, SwXMLTableContext *pTable=nullptr, bool bIsProtected=false, const OUString *pFormula=nullptr, bool bHasValue=false, double fValue=0.0, OUString const *const pStringValue=nullptr)
std::optional< std::vector< OUString > > m_xColumnDefaultCellStyleNames
const SwStartNode * GetPrevStartNode(sal_uInt32 nRow, sal_uInt32 nCol) const
css::uno::Reference< css::text::XTextContent > m_xTextContent
SwTableBoxFormat * GetSharedBoxFormat(SwTableBox *pBox, const OUString &rStyleName, sal_Int32 nColumnWidth, bool bProtected, bool bMayShare, bool &bNew, bool *pModifyLocked)
sets the appropriate SwTableBoxFormat at pBox.
const SwStartNode * InsertTableSection(const SwStartNode *pPrevSttNd=nullptr, OUString const *pStringValueStyleName=nullptr)
void ReplaceWithEmptyCell(sal_uInt32 nRow, sal_uInt32 nCol, bool bRows)
const SwStartNode * GetLastStartNode() const
SwXMLImport & GetSwImport()
void MakeTable(SwTableBox *pBox, sal_Int32 nWidth)
void MakeTable_(SwTableBox *pBox=nullptr)
SvXMLImportContextRef m_xParentTable
std::unordered_map< TableBoxIndex, SwTableBoxFormat *, TableBoxIndexHasher > map_BoxFormat
virtual ~SwXMLTableContext() override
rtl::Reference< SwXMLDDETableContext_Impl > m_xDDESource
SwXMLTableContext * GetParentTable() const
css::uno::Reference< css::text::XTextCursor > m_xOldCursor
bool IsInsertColPossible() const
SwTableLine * MakeTableLine(SwTableBox *pUpper, sal_uInt32 nTopRow, sal_uInt32 nLeftCol, sal_uInt32 nBottomRow, sal_uInt32 nRightCol)
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
sal_Int32 GetColumnWidth(sal_uInt32 nCol, sal_uInt32 nColSpan) const
bool IsInsertRowPossible() const
SwTableNode * m_pTableNode
void InsertRepRows(sal_uInt32 nCount)
const SwStartNode * m_pSttNd1
OUString m_aDfltCellStyleName
void InsertRow(const OUString &rStyleName, const OUString &rDfltCellStyleName, bool bInHead)
SwXMLTableContext(SwXMLImport &rImport, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
if set, call pBox->LockModify() and return old lock status
SwTableLineFormat * m_pLineFormat
OUString GetColumnDefaultCellStyleName(sal_uInt32 nCol) const
static constexpr sal_Int32 MAX_WIDTH
SwTableBox * MakeTableBox(SwTableLine *pUpper, const SwXMLTableCell_Impl *pStartNode, sal_uInt32 nLeftCol, sal_uInt32 nRightCol)
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
std::vector< std::unique_ptr< SwXMLTableCell_Impl > > m_Cells
const OUString & GetStyleName() const
OUString m_aDefaultCellStyleName
void Set(const OUString &rStyleName, const OUString &rDfltCellStyleName)
SwXMLTableCell_Impl * GetCell(sal_uInt32 nCol)
const OUString & GetDefaultCellStyleName() const
void Expand(sal_uInt32 nCells, bool bOneCell)
SwXMLTableRow_Impl(OUString aStyleName, sal_uInt32 nCells, const OUString *pDfltCellStyleName=nullptr)
void SetSplitable(bool bSet)
SwFrameFormat * GetFrameFormat()
size_t operator()(const TableBoxIndex &rArg) const
TableBoxIndex(OUString aName, sal_Int32 nWidth, bool bProtected)
bool operator==(const TableBoxIndex &rArg) const
static void convertDouble(OUStringBuffer &rBuffer, double fNumber, bool bWriteUnits, sal_Int16 nSourceUnit, sal_Int16 nTargetUnit)
static void convertDuration(OUStringBuffer &rBuffer, const double fTime)
static bool convertBool(bool &rBool, std::u16string_view rString)
#define DBG_TESTSOLARMUTEX()
Reference< XSingleServiceFactory > xFactory
@ Variable
Frame is variable in Var-direction.
constexpr TypedWhichId< SwTableBoxValue > RES_BOXATR_VALUE(158)
constexpr TypedWhichId< SwFormatFrameSize > RES_FRM_SIZE(89)
constexpr TypedWhichId< SwFormatHoriOrient > RES_HORI_ORIENT(109)
constexpr TypedWhichId< SwTableBoxFormula > RES_BOXATR_FORMULA(157)
constexpr TypedWhichId< SvxProtectItem > RES_PROTECT(106)
constexpr TypedWhichId< SwTableBoxNumFormat > RES_BOXATR_FORMAT(RES_BOXATR_BEGIN)
constexpr TypedWhichId< SvxLRSpaceItem > RES_LR_SPACE(97)
#define SAL_WARN_IF(condition, area, stream)
#define SAL_WARN(area, stream)
#define SAL_INFO(area, stream)
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
const sal_Unicode cTokenSeparator
OUString toString(OptionInfo const *info)
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
sal_Int32 toInt32(std::u16string_view rStr)
SwNodeOffset min(const SwNodeOffset &a, const SwNodeOffset &b)
@ RES_POOLCOLL_STANDARD
Standard.
Marks a position in the document model.
std::vector< SwTableBox * > SwTableBoxes
#define XMLOFF_WARN_UNKNOWN_ELEMENT(area, token)
#define XMLOFF_WARN_UNKNOWN(area, rIter)
#define XML_ELEMENT(prefix, name)
constexpr sal_uInt16 XML_NAMESPACE_OOOW
static OUString lcl_GenerateFieldTypeName(const OUString &sPrefix, SwTableNode *pTableNode)
static SwDDEFieldType * lcl_GetDDEFieldType(SwXMLDDETableContext_Impl *pContext, SwTableNode *pTableNode)
std::vector< std::unique_ptr< SwXMLTableRow_Impl > > SwXMLTableRows_Impl
#define SV_COUNTRY_LANGUAGE_OFFSET