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>
56#include <unoprnms.hxx>
118 inline void Set(
const OUString& rStyleName,
119 sal_uInt32 nRSpan, sal_uInt32 nCSpan,
122 const OUString* pFormula,
126 OUString
const*
const pStringValue);
155 sal_uInt32 nRSpan, sal_uInt32 nCSpan,
159 const OUString* pFormula,
163 OUString
const*
const pStringValue )
181 if (pFormula !=
nullptr)
208 std::vector<std::unique_ptr<SwXMLTableCell_Impl>>
m_Cells;
214 const OUString *pDfltCellStyleName =
nullptr );
218 inline void Set(
const OUString& rStyleName,
219 const OUString& rDfltCellStyleName );
221 void Expand( sal_uInt32 nCells,
bool bOneCell );
234 const OUString *pDfltCellStyleName ) :
235 m_aStyleName(
std::move( aStyleName )),
236 m_bSplitable( false )
238 if( pDfltCellStyleName )
240 OSL_ENSURE( nCells <= USHRT_MAX,
241 "SwXMLTableRow_Impl::SwXMLTableRow_Impl: too many cells" );
242 if( nCells > USHRT_MAX )
245 for( sal_uInt32
i=0
U;
i<nCells; ++
i )
247 m_Cells.push_back(std::make_unique<SwXMLTableCell_Impl>());
253 OSL_ENSURE( nCol < USHRT_MAX,
254 "SwXMLTableRow_Impl::GetCell: column number is too big" );
256 OSL_ENSURE( nCol <
m_Cells.size(),
257 "SwXMLTableRow_Impl::GetCell: column number is out of bound" );
263 OSL_ENSURE( nCells <= USHRT_MAX,
264 "SwXMLTableRow_Impl::Expand: too many cells" );
265 if( nCells > USHRT_MAX )
268 sal_uInt32 nColSpan = nCells -
m_Cells.size();
269 for (
size_t i =
m_Cells.size();
i < nCells; ++
i)
271 m_Cells.push_back(std::make_unique<SwXMLTableCell_Impl>(
272 1UL, bOneCell ? nColSpan : 1UL));
276 OSL_ENSURE( nCells <=
m_Cells.size(),
277 "SwXMLTableRow_Impl::Expand: wrong number of cells" );
281 const OUString& rDfltCellStyleName )
299 OUString m_aStyleName;
301 OUString m_sSaveParaDefault;
302 OUString m_StringValue;
308 bool m_bHasStringValue;
309 bool m_bValueTypeIsString;
312 sal_uInt32 m_nRowSpan;
313 sal_uInt32 m_nColSpan;
314 sal_uInt32 m_nColRepeat;
316 bool m_bHasTextContent : 1;
317 bool m_bHasTableContent : 1;
321 bool HasContent()
const {
return m_bHasTextContent || m_bHasTableContent; }
322 inline void InsertContent_();
323 inline void InsertContent();
328 SwXMLTableCellContext_Impl(
330 const Reference< xml::sax::XFastAttributeList > & xAttrList,
335 const Reference< xml::sax::XFastAttributeList > & xAttrList )
override;
336 virtual void SAL_CALL
endFastElement(sal_Int32 nElement)
override;
346 const Reference<xml::sax::XFastAttributeList>& xAttrList,
350SwXMLCoveredTableCellContext::SwXMLCoveredTableCellContext(
351 SwXMLImport& rImport,
const Reference<xml::sax::XFastAttributeList>& xAttrList,
358 switch (rIter.getToken())
366 if (!aStyleName.isEmpty())
373SwXMLTableCellContext_Impl::SwXMLTableCellContext_Impl(
375 const Reference< xml::sax::XFastAttributeList > & xAttrList,
378 m_xMyTable( pTable ),
380 m_bHasValue( false ),
381 m_bHasStringValue(false),
382 m_bValueTypeIsString(false),
387 m_bHasTextContent( false ),
388 m_bHasTableContent( false )
390 m_sSaveParaDefault = GetImport().GetTextImport()->GetCellParaStyleDefault();
393 switch( aIter.getToken() )
397 GetImport().GetTextImport()->SetCellParaStyleDefault(
m_aStyleName);
399 case XML_ELEMENT(TABLE, XML_NUMBER_COLUMNS_SPANNED):
400 m_nColSpan = static_cast<sal_uInt32>(
std::
max<sal_Int32>(1, aIter.
toInt32()));
401 if (m_nColSpan > 256)
403 SAL_INFO(
"sw.xml",
"ignoring huge table:number-columns-spanned " << m_nColSpan);
408 m_nRowSpan = static_cast<sal_uInt32>(
std::
max<sal_Int32>(1, aIter.
toInt32()));
411 SAL_INFO(
"sw.xml",
"ignoring huge table:number-rows-spanned " << m_nRowSpan);
415 case XML_ELEMENT(TABLE, XML_NUMBER_COLUMNS_REPEATED):
416 m_nColRepeat = static_cast<sal_uInt32>(
std::
max<sal_Int32>(1, aIter.
toInt32()));
417 if (m_nColRepeat > 256)
419 SAL_INFO(
"sw.xml",
"ignoring huge table:number-columns-repeated " << m_nColRepeat);
426 const sal_uInt16 nPrefix2 = GetImport().GetNamespaceMap().
427 GetKeyByAttrValueQName(aIter.toString(), &sTmp);
456 if (GetImport().GetMM100UnitConverter().convertDateTime(fTmp,
469 m_fValue = (bTmp ? 1.0 : 0.0);
486 m_StringValue = aIter.toString();
487 m_bHasStringValue =
true;
492 if (
"string" == aIter.toView())
494 m_bValueTypeIsString =
true;
502 SAL_WARN(
"sw",
"unknown attribute " << SvXMLImport::getPrefixAndNameFromToken(aIter.getToken()) <<
"=" << aIter.toString());
507inline void SwXMLTableCellContext_Impl::InsertContent_()
509 SwStartNode const*
const pStartNode( GetTable()->InsertTableSection(
nullptr,
510 (m_bHasStringValue && m_bValueTypeIsString &&
511 !m_aStyleName.isEmpty()) ? & m_aStyleName :
nullptr) );
512 GetTable()->InsertCell( m_aStyleName, m_nRowSpan, m_nColSpan,
514 nullptr, m_bProtect, &m_sFormula, m_bHasValue, m_fValue,
515 (m_bHasStringValue && m_bValueTypeIsString) ? &m_StringValue :
nullptr);
518inline void SwXMLTableCellContext_Impl::InsertContent()
520 OSL_ENSURE( !HasContent(),
"content already there" );
521 m_bHasTextContent =
true;
525inline void SwXMLTableCellContext_Impl::InsertContent(
528 GetTable()->InsertCell( m_aStyleName, m_nRowSpan, m_nColSpan,
nullptr, pTable, m_bProtect );
529 m_bHasTableContent =
true;
532css::uno::Reference<css::xml::sax::XFastContextHandler> SwXMLTableCellContext_Impl::createFastChildContext(
534 const Reference< xml::sax::XFastAttributeList > & xAttrList )
538 bool bSubTable =
false;
543 if( aIter.getToken() ==
XML_ELEMENT(TABLE, XML_IS_SUB_TABLE) )
560 pContext = pTableContext;
561 if( GetTable()->IsValid() )
562 InsertContent( pTableContext );
564 GetTable()->SetHasSubTables(
true );
569 if( GetTable()->IsValid() && !HasContent() )
572 if (!(m_bValueTypeIsString && m_bHasStringValue))
574 pContext = GetImport().GetTextImport()->CreateTextChildContext(
575 GetImport(), nElement, xAttrList,
583void SwXMLTableCellContext_Impl::endFastElement(sal_Int32 )
585 if( GetTable()->IsValid() )
587 if( m_bHasTextContent )
589 GetImport().GetTextImport()->DeleteParagraph();
590 if( m_nColRepeat > 1 && m_nColSpan == 1 )
594 Reference < XTextCursor > xSrcTextCursor =
595 GetImport().GetTextImport()->GetText()->createTextCursor();
596 xSrcTextCursor->gotoEnd(
true );
599 OTextCursorHelper *pSrcTextCursor =
dynamic_cast<OTextCursorHelper*
>(xSrcTextCursor.get());
600 assert(pSrcTextCursor &&
"SwXTextCursor missing");
601 SwDoc *pDoc = pSrcTextCursor->GetDoc();
602 const SwPaM *pSrcPaM = pSrcTextCursor->GetPaM();
604 while( m_nColRepeat > 1 && GetTable()->IsInsertCellPossible() )
608 OTextCursorHelper *pDstTextCursor =
dynamic_cast<OTextCursorHelper*
>(GetImport().GetTextImport()->GetCursor().get());
609 assert(pDstTextCursor &&
"SwXTextCursor missing");
611 SwPosition aDstPos( *pDstTextCursor->GetPaM()->GetPoint() );
618 else if( !m_bHasTableContent )
621 if( m_nColRepeat > 1 && m_nColSpan == 1 )
623 while( m_nColRepeat > 1 && GetTable()->IsInsertCellPossible() )
631 GetImport().GetTextImport()->SetCellParaStyleDefault(m_sSaveParaDefault);
644 SwXMLTableColContext_Impl(
646 const Reference< xml::sax::XFastAttributeList > & xAttrList,
654SwXMLTableColContext_Impl::SwXMLTableColContext_Impl(
656 const Reference< xml::sax::XFastAttributeList > & xAttrList,
661 sal_uInt32 nColRep = 1;
662 OUString aStyleName, aDfltCellStyleName;
666 switch (aIter.getToken())
671 case XML_ELEMENT(TABLE, XML_NUMBER_COLUMNS_REPEATED):
673 nColRep =
static_cast<sal_uInt32
>(std::max<sal_Int32>(1, aIter.toInt32()));
676 SAL_INFO(
"sw.xml",
"ignoring huge table:number-columns-repeated " << nColRep);
681 case XML_ELEMENT(TABLE, XML_DEFAULT_CELL_STYLE_NAME):
682 aDfltCellStyleName = aIter.
toString();
694 sal_Int32 nWidth =
MINLAY;
695 bool bRelWidth =
true;
696 if( !aStyleName.isEmpty() )
700 if( GetSwImport().FindAutomaticStyle(
701 XmlStyleFamily::TABLE_COLUMN,
702 aStyleName, &pAutoItemSet ) &&
713 while( nColRep-- && GetTable()->IsInsertColPossible() )
714 GetTable()->InsertColumn( nWidth, bRelWidth, &aDfltCellStyleName );
728 SwXMLTableColsContext_Impl(
733 sal_Int32 Element,
const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList )
override;
740SwXMLTableColsContext_Impl::SwXMLTableColsContext_Impl(
748css::uno::Reference< css::xml::sax::XFastContextHandler > SwXMLTableColsContext_Impl::createFastChildContext(
749 sal_Int32 nElement,
const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList )
753 if( nElement ==
XML_ELEMENT(TABLE, XML_TABLE_COLUMN) &&
754 GetTable()->IsInsertColPossible() )
755 pContext =
new SwXMLTableColContext_Impl( GetSwImport(), xAttrList, GetTable() );
768 sal_uInt32 m_nRowRepeat;
774 SwXMLTableRowContext_Impl(
776 const Reference< xml::sax::XFastAttributeList > & xAttrList,
779 virtual css::uno::Reference<css::xml::sax::XFastContextHandler> SAL_CALL
createFastChildContext( sal_Int32 nElement,
780 const Reference< xml::sax::XFastAttributeList > & xAttrList )
override;
782 virtual void SAL_CALL
endFastElement(sal_Int32 nElement)
override;
789SwXMLTableRowContext_Impl::SwXMLTableRowContext_Impl(
SwXMLImport& rImport,
791 const Reference< xml::sax::XFastAttributeList > & xAttrList,
795 m_xMyTable( pTable ),
798 OUString aStyleName, aDfltCellStyleName;
802 switch(aIter.getToken())
809 m_nRowRepeat =
static_cast<sal_uInt32
>(std::max<sal_Int32>(1, aIter.toInt32()));
812 SAL_INFO(
"sw.xml",
"ignoring huge table:number-rows-repeated " << m_nRowRepeat);
817 case XML_ELEMENT(STYLE, XML_DEFAULT_CELL_STYLE_NAME):
818 aDfltCellStyleName = aIter.
toString();
826 if( GetTable()->IsValid() )
827 GetTable()->InsertRow( aStyleName, aDfltCellStyleName, bInHead );
830void SwXMLTableRowContext_Impl::endFastElement(sal_Int32 )
832 if( GetTable()->IsValid() )
834 GetTable()->FinishRow();
836 if( m_nRowRepeat > 1 )
837 GetTable()->InsertRepRows( m_nRowRepeat );
841css::uno::Reference<css::xml::sax::XFastContextHandler> SwXMLTableRowContext_Impl::createFastChildContext(
843 const Reference< xml::sax::XFastAttributeList > & xAttrList )
847 if( nElement ==
XML_ELEMENT(TABLE, XML_TABLE_CELL) ||
850 if( !GetTable()->IsValid() || GetTable()->IsInsertCellPossible() )
851 pContext =
new SwXMLTableCellContext_Impl( GetSwImport(), nElement,
855 else if( nElement ==
XML_ELEMENT(TABLE, XML_COVERED_TABLE_CELL) ||
856 nElement ==
XML_ELEMENT(LO_EXT, XML_COVERED_TABLE_CELL) )
858 if (GetTable()->IsValid() && GetTable()->IsInsertCoveredCellPossible())
860 pContext =
new SwXMLCoveredTableCellContext(GetSwImport(), xAttrList, *GetTable());
868 SAL_WARN(
"sw",
"unknown element " << SvXMLImport::getPrefixAndNameFromToken(nElement));
891 const Reference< xml::sax::XFastAttributeList > & xAttrList )
override;
898SwXMLTableRowsContext_Impl::SwXMLTableRowsContext_Impl(
SwXMLImport& rImport,
902 m_xMyTable( pTable ),
907css::uno::Reference<css::xml::sax::XFastContextHandler> SwXMLTableRowsContext_Impl::createFastChildContext(
909 const Reference< xml::sax::XFastAttributeList > & xAttrList )
911 if( nElement==
XML_ELEMENT(TABLE, XML_TABLE_ROW ) &&
912 GetTable()->IsInsertRowPossible() )
913 return new SwXMLTableRowContext_Impl( GetSwImport(), nElement,
917 SAL_WARN(
"sw",
"unknown element " << SvXMLImport::getPrefixAndNameFromToken(nElement));
936 const Reference<xml::sax::XFastAttributeList> & xAttrList)
override;
948 m_bIsAutomaticUpdate(false)
954 const Reference<xml::sax::XFastAttributeList> & xAttrList)
958 switch (aIter.getToken())
991 const OUString sPrefixStr(
sPrefix.isEmpty() ? OUString(
"_") :
sPrefix);
1022 ? SfxLinkUpdateMode::ALWAYS
1023 : SfxLinkUpdateMode::ONCALL;
1031 if (
sName.isEmpty())
1040 if (
nullptr != pOldType)
1043 if ( (pOldType->
GetCmd() == sCommand) &&
1060 if (
nullptr == pType)
1068 OSL_ENSURE(
nullptr != pType,
"We really want a SwDDEFieldType here!");
1104 sal_uInt32 nCol )
const
1106 return (*
m_pRows)[nRow]->GetCell( nCol );
1112 return (*
m_pRows)[nRow]->GetCell( nCol );
1117 const Reference< xml::sax::XFastAttributeList > & xAttrList ) :
1120 m_pTableNode( nullptr ),
1122 m_bOwnsBox1( false ),
1123 m_pSttNd1( nullptr ),
1124 m_pBoxFormat( nullptr ),
1125 m_pLineFormat( nullptr ),
1126 m_bFirstSection( true ),
1127 m_bRelWidth( true ),
1128 m_bHasSubTables( false ),
1132 m_nNonMergedCurCol( 0 ),
1143 const OUString sValue = aIter.toString();
1144 switch(aIter.getToken())
1152 case XML_ELEMENT(TABLE, XML_DEFAULT_CELL_STYLE_NAME):
1168 OUString sTableName;
1169 if( !
aName.isEmpty() )
1175 if( sTableName.isEmpty() )
1182 sal_Int32 nextIx = ++tableNameMap[
aName];
1185 : OUString(
aName +
"_" + OUString::number(nextIx));
1191 ->GetRenameMap().Add( XML_TEXT_RENAME_TYPE_TABLE, aName, sTableName );
1194 Reference< XTextTable > xTable;
1198 OSL_ENSURE(
xFactory.is(),
"factory missing" );
1201 Reference<XInterface> xIfc =
xFactory->createInstance(
"com.sun.star.text.TextTable" );
1202 OSL_ENSURE( xIfc.is(),
"Couldn't create a table" );
1205 xTable.set( xIfc, UNO_QUERY );
1210 xTable->initialize( 1, 1 );
1211 if (
auto xPropSet = xTable.query<css::beans::XPropertySet>())
1219 catch( IllegalArgumentException& )
1233 Reference < XCellRange > xCellRange( xTable, UNO_QUERY );
1234 Reference < XCell > xCell = xCellRange->getCellByPosition( 0, 0 );
1235 Reference < XText> xText( xCell, UNO_QUERY );
1237 GetImport().GetTextImport()->SetCursor( xText->createTextCursor() );
1240 GetImport().GetTextImport()->RedlineAdjustStartNodeCursor();
1246 OSL_ENSURE( pTableFrameFormat,
"table format missing" );
1248 OSL_ENSURE( pTable,
"table missing" );
1261 m_pTableNode( pTable->m_pTableNode ),
1263 m_bOwnsBox1( false ),
1264 m_pSttNd1( nullptr ),
1265 m_pBoxFormat( nullptr ),
1266 m_pLineFormat( nullptr ),
1267 m_xParentTable( pTable ),
1268 m_bFirstSection( false ),
1269 m_bRelWidth( true ),
1270 m_bHasSubTables( false ),
1274 m_nNonMergedCurCol( 0 ),
1288 GetImport().GetTextImport()->RedlineAdjustStartNodeCursor();
1293 const Reference< xml::sax::XFastAttributeList > & xAttrList )
1295 bool bHeader =
false;
1301 return new SwXMLTableRowContext_Impl(
GetSwImport(), nElement, xAttrList,
this );
1307 return new SwXMLTableRowsContext_Impl(
GetSwImport(),
this, bHeader );
1317 return new SwXMLTableColsContext_Impl(
GetSwImport(),
this );
1322 return new SwXMLTableColContext_Impl(
GetSwImport(), xAttrList,
1338 const OUString *pDfltCellStyleName )
1341 "SwXMLTableContext::InsertColumn: no space left" );
1350 if( !((pDfltCellStyleName && !pDfltCellStyleName->isEmpty()) ||
1362 if(pDfltCellStyleName)
1369 sal_uInt32 nColSpan )
const
1371 sal_uInt32 nLast = nCol+nColSpan;
1375 sal_Int32 nWidth2 = 0;
1376 for( sal_uInt32
i=nCol;
i < nLast; ++
i )
1391 sal_uInt32 nRowSpan, sal_uInt32 nColSpan,
1395 const OUString* pFormula,
1398 OUString
const*
const pStringValue )
1401 "SwXMLTableContext::InsertCell: row is full" );
1403 "SwXMLTableContext::InsertCell: table is full" );
1407 OSL_ENSURE( nRowSpan >=1,
"SwXMLTableContext::InsertCell: row span is 0" );
1410 OSL_ENSURE( nColSpan >=1,
"SwXMLTableContext::InsertCell: col span is 0" );
1415 sal_uInt32 nColsReq =
m_nCurCol + nColSpan;
1441 sal_uInt32 nRowsReq =
m_nCurRow + nRowSpan;
1442 if( nRowsReq > USHRT_MAX )
1445 nRowsReq = USHRT_MAX;
1462 if (
m_pRows->size() < nRowsReq)
1464 for (
size_t i =
m_pRows->size();
i < nRowsReq; ++
i)
1465 m_pRows->push_back(std::make_unique<SwXMLTableRow_Impl>(
1469 OUString sStyleName( rStyleName );
1470 if( sStyleName.isEmpty() )
1472 sStyleName = (*m_pRows)[
m_nCurRow]->GetDefaultCellStyleName();
1476 if( sStyleName.isEmpty() )
1482 for( sal_uInt32
i=nColSpan;
i>0; --
i )
1484 for( sal_uInt32 j=nRowSpan; j>0; --j )
1486 const bool bCovered =
i != nColSpan || j != nRowSpan;
1489 throw css::lang::IndexOutOfBoundsException();
1490 pCell->
Set( sStyleName, j,
i, pStartNode,
1491 pTable, bProtect, pFormula, bHasValue, bCovered, fValue,
1516 const OUString& rDfltCellStyleName,
1520 "SwXMLTableContext::InsertRow: no space left" );
1528 if (m_nCurRow < m_pRows->
size())
1533 rStyleName, rDfltCellStyleName );
1538 m_pRows->push_back(std::make_unique<SwXMLTableRow_Impl>(
1540 &rDfltCellStyleName));
1596 sal_uInt32 nCol )
const
1607 pPrevCell =
GetCell( nRow, nCol-1 );
1625 OSL_ENSURE( pSttNd !=
nullptr,
1633 sal_uInt32 nColSpan )
1635 sal_uInt32 nLastCol = nCol + nColSpan;
1636 for( sal_uInt32
i = nCol;
i < nLastCol;
i++ )
1638 sal_uInt32 j = nRow;
1639 sal_uInt32 nRowSpan = 1;
1644 pCell = j > 0 ?
GetCell( --j,
i ) :
nullptr;
1655 sal_uInt32 nLastRow = bRows ? nRow + pCell->
GetRowSpan() : nRow + 1;
1656 sal_uInt32 nLastCol = nCol + pCell->
GetColSpan();
1658 for( sal_uInt32
i=nRow;
i<nLastRow;
i++ )
1661 for( sal_uInt32 j=nCol; j<nLastCol; j++ )
1696 const OUString& rStyleName,
1697 sal_Int32 nColumnWidth,
1701 bool* pModifyLocked )
1724 (*m_pSharedBoxFormats)[ aKey ] = pBoxFormat2;
1729 pBoxFormat2 = aIter->second;
1739 if ( pModifyLocked !=
nullptr )
1741 (*pModifyLocked) = pBoxFormat2->IsModifyLocked();
1742 pBoxFormat2->LockModify();
1750 sal_uInt32 nLeftCol,
1751 sal_uInt32 nBottomRow,
1752 sal_uInt32 nRightCol )
1757 sal_uInt32 nColSpan = nRightCol - nLeftCol;
1769 bool bSplitted =
false;
1773 sal_uInt32 nStartRow = nTopRow;
1776 for(
i = nTopRow;
i < nBottomRow;
i++ )
1781 for( sal_uInt32 j=nLeftCol; j<nRightCol; j++ )
1787 if( bSplit && (nStartRow>nTopRow ||
i+1<nBottomRow) )
1804 nStartRow = nTopRow;
1805 while( nStartRow < nBottomRow )
1807 sal_uInt32 nMaxRowSpan = 0;
1810 for(
i=nLeftCol;
i<nRightCol;
i++ )
1817 nStartRow += nMaxRowSpan;
1818 if( nStartRow<nBottomRow )
1822 while(
i < nRightCol )
1828 const sal_uInt32 nColSpan2 = pCell2->
GetColSpan();
1849 sal_uInt32 nLeftCol, sal_uInt32 nRightCol )
1853 sal_uInt32 nColSpan = nRightCol - nLeftCol;
1873 pBox, sStyleName, nColWidth, pCell->
IsProtected(),
1876 bNew, &bModifyLocked );
1885 XmlStyleFamily::TABLE_CELL, sStyleName, &pAutoItemSet ) )
1898 SAL_WARN_IF(!pTextNode,
"sw",
"Should have a text node in cell?");
1915 bool bSuppressNumericContent =
false;
1918 !sStyleName.isEmpty() )
1931 if( pTextNode !=
nullptr )
1934 const OUString& rText = pTextNode->
GetText();
1935 if( ( rText.getLength() > 10 ) ||
1936 ( rText.indexOf(
'0' ) == -1 ) )
1938 bSuppressNumericContent =
true;
1943 bSuppressNumericContent =
true;
1948 if( bSuppressNumericContent )
1959 const OUString& rFormula = pCell->
GetFormula();
1960 if (!rFormula.isEmpty())
1977 if( pNumFormat !=
nullptr && pNumberFormatter &&
2003 if (! bModifyLocked)
2004 pBoxFormat2->UnlockModify();
2013 sal_uInt32 nLeftCol,
2014 sal_uInt32 nBottomRow,
2015 sal_uInt32 nRightCol )
2019 if( !pUpper && 0
UL==nTopRow )
2035 const OUString& rStyleName = (*m_pRows)[nTopRow]->GetStyleName();
2036 if( 1 == (nBottomRow - nTopRow) &&
2037 !rStyleName.isEmpty() &&
2039 XmlStyleFamily::TABLE_ROW, rStyleName, &pAutoItemSet ) )
2047 sal_uInt32 nStartCol = nLeftCol;
2048 while( nStartCol < nRightCol )
2050 for( sal_uInt32 nRow=nTopRow; nRow<nBottomRow; nRow++ )
2051 (*
m_pRows)[nRow]->SetSplitable(
true );
2053 sal_uInt32 nCol = nStartCol;
2054 sal_uInt32 nSplitCol = nRightCol;
2055 bool bSplitted =
false;
2058 OSL_ENSURE( nCol < nRightCol,
"Ran too far" );
2064 bool bHoriSplitMayContinue =
false;
2065 bool bHoriSplitPossible =
false;
2070 for( sal_uInt32 nRow=nTopRow; nRow<nBottomRow; nRow++ )
2075 bool bHoriSplit = (*m_pRows)[nRow]->IsSplitable() &&
2076 nRow+1 < nBottomRow &&
2078 (*m_pRows)[nRow]->SetSplitable( bHoriSplit );
2085 bHoriSplitPossible |= bHoriSplit;
2089 bHoriSplit &= (nCol+1 < nRightCol &&
2091 bHoriSplitMayContinue |= bHoriSplit;
2101 if ( pCell ==
nullptr )
2103 OSL_FAIL(
"table seems to be corrupt." );
2112#if OSL_DEBUG_LEVEL > 0
2113 if( nCol == nRightCol-1 )
2115 OSL_ENSURE( bSplit,
"Split-Flag wrong" );
2118 OSL_ENSURE( !bHoriSplitMayContinue,
2119 "HoriSplitMayContinue-Flag wrong" );
2121 OSL_ENSURE( pTmpCell->
GetRowSpan() != (nBottomRow-nTopRow) ||
2122 !bHoriSplitPossible,
"HoriSplitPossible-Flag wrong" );
2127 OSL_ENSURE( !
m_bHasSubTables || !bHoriSplitMayContinue || bHoriSplitPossible,
2128 "bHoriSplitMayContinue, but not bHoriSplitPossible" );
2140 sal_Int32 nBoxRowSpan = 1;
2146 nBoxRowSpan = -1 * nBoxRowSpan;
2153 nSplitCol = nCol + 1;
2155 pBox =
MakeTableBox( pLine, pCell, nStartCol, nSplitCol );
2157 if ( 1 != nBoxRowSpan )
2162 else if(
m_bHasSubTables && bHoriSplitPossible && bHoriSplitMayContinue )
2170 nSplitCol = nCol + 1;
2181 if( bHoriSplitPossible || nSplitCol > nCol+1 )
2183 OSL_ENSURE( !bHoriSplitMayContinue,
2184 "bHoriSplitMayContinue==true" );
2185 OSL_ENSURE( bHoriSplitPossible || nSplitCol == nRightCol,
2186 "bHoriSplitPossible flag should be set" );
2188 nSplitCol = nCol + 1;
2192 nBottomRow, nSplitCol );
2199 rBoxes.push_back( pBox );
2203 nStartCol = nSplitCol;
2212 std::vector<ColumnWidthInfo>::iterator colIter;
2241 sal_Int32 nAbsWidth = 0;
2242 sal_Int32 nMinAbsColWidth = 0;
2243 sal_Int32 nRelWidth = 0;
2244 sal_Int32 nMinRelColWidth = 0;
2245 sal_uInt32 nRelCols = 0;
2248 if( rCol.isRelative )
2250 nRelWidth += rCol.width;
2251 if( 0 == nMinRelColWidth || rCol.width < nMinRelColWidth )
2252 nMinRelColWidth = rCol.width;
2257 nAbsWidth += rCol.width;
2258 if( 0 == nMinAbsColWidth || rCol.width < nMinAbsColWidth )
2259 nMinAbsColWidth = rCol.width;
2262 sal_uInt32 nAbsCols = nCols - nRelCols;
2275 if( 0 == nMinRelColWidth )
2276 nMinRelColWidth = nMinAbsColWidth;
2280 if( !rCol.isRelative )
2282 if (nMinAbsColWidth == 0)
2285 if (o3tl::checked_multiply<sal_Int32>(rCol.width, nMinRelColWidth, nVal))
2286 throw std::overflow_error(
"overflow in multiply");
2287 sal_Int32 nRelCol = nVal / nMinAbsColWidth;
2288 rCol.width = nRelCol;
2289 rCol.isRelative =
true;
2290 nRelWidth += nRelCol;
2306 if( nRelWidth !=
m_nWidth && nRelWidth && nCols )
2308 double n =
static_cast<double>(
m_nWidth) /
static_cast<double>(nRelWidth);
2312 sal_Int32 nW =
static_cast<sal_Int32
>( colIter->width *
n);
2313 colIter->width = o3tl::narrowing<sal_uInt16>(nW);
2327 sal_Int32 nAbsForRelWidth =
2332 sal_Int32 nExtraRel = nRelWidth - (nRelCols * nMinRelColWidth);
2336 sal_Int32 nMinAbs = nRelCols *
MINLAY;
2337 sal_Int32 nExtraAbs =
2338 nAbsForRelWidth > nMinAbs ? nAbsForRelWidth - nMinAbs : sal_Int32(0L);
2341 bool bMinExtra =
false;
2344 if( nAbsForRelWidth <= nMinAbs )
2348 nAbsForRelWidth = nMinAbs;
2351 else if( nAbsForRelWidth <= (nRelWidth *
MINLAY) /
2366 if( rCol.isRelative )
2373 nAbsCol = nAbsForRelWidth;
2381 else if( bMinExtra )
2383 sal_Int32 nExtraRelCol = rCol.width - nMinRelColWidth;
2384 nAbsCol =
MINLAY + (nExtraRelCol * nExtraAbs) /
2389 nAbsCol = ( rCol.width * nAbsForRelWidth) / nRelWidth;
2392 rCol.width = nAbsCol;
2393 rCol.isRelative =
false;
2394 nAbsForRelWidth -= nAbsCol;
2395 nAbsWidth += nAbsCol;
2403 if( nCols && nAbsWidth )
2409 sal_Int32 nExtraAbs =
m_nWidth - nAbsWidth;
2413 sal_Int32 nAbsCol = colIter->width;
2414 sal_Int32 nExtraAbsCol = (nAbsCol * nExtraAbs) /
2416 nAbsCol += nExtraAbsCol;
2417 colIter->width = nAbsCol;
2418 nAbsLastCol -= nExtraAbsCol;
2428 sal_Int32 nAbsLastCol =
MINLAY + nExtraAbs;
2431 sal_Int32 nAbsCol = colIter->width;
2432 sal_Int32 nExtraAbsCol = (nAbsCol * nExtraAbs) /
2434 nAbsCol =
MINLAY + nExtraAbsCol;
2435 colIter->width = nAbsCol;
2436 nAbsLastCol -= nExtraAbsCol;
2447 sal_uInt32 nStartRow = 0;
2448 sal_uInt32 nRows =
m_pRows->size();
2449 for(sal_uInt32
i=0;
i<nRows; ++
i )
2456 for( sal_uInt32 j=0; j<nCols; j++ )
2468 if( pBox || nStartRow>0 )
2485 OSL_FAIL(
"invalid table: no cells; deleting...");
2498 sal_Int16 eHoriOrient = text::HoriOrientation::FULL;
2499 bool bSetHoriOrient =
false;
2503 OUString sStyleName;
2512 XmlStyleFamily::TABLE_TABLE,
m_aStyleName, &pAutoItemSet ) &&
2520 eHoriOrient = pItem->GetHoriOrient();
2521 switch( eHoriOrient )
2523 case text::HoriOrientation::FULL:
2527 bSetHoriOrient =
true;
2530 case text::HoriOrientation::LEFT:
2533 eHoriOrient = text::HoriOrientation::LEFT_AND_WIDTH;
2534 bSetHoriOrient =
true;
2543 bSetHoriOrient =
true;
2549 switch( eHoriOrient )
2551 case text::HoriOrientation::FULL:
2572 sal_Int32
const min =
static_cast<sal_Int32
>(
2587 eHoriOrient = text::HoriOrientation::LEFT_AND_WIDTH == eHoriOrient
2589 bSetHoriOrient =
true;
2599 bSetHoriOrient =
true;
2614 if( bSetHoriOrient )
2619 pFrameFormat->LockModify();
2623 pFrameFormat->UnlockModify();
2625 for (std::unique_ptr<SwXMLTableRow_Impl> & rRow : *
m_pRows)
2641 pFieldType,
false ) );
2665 for (std::unique_ptr<SwXMLTableRow_Impl> & rpRow : *
m_pRows)
2674 OUString
const*
const pStringValueStyleName)
2686 Reference<XInterface> xCursorTunnel(
GetImport().GetTextImport()->GetCursor(),
2688 OSL_ENSURE( xCursorTunnel.is(),
"missing XUnoTunnel for Cursor" );
2689 OTextCursorHelper *pTextCursor =
dynamic_cast<OTextCursorHelper*
>(xCursorTunnel.get());
2690 assert(pTextCursor &&
"SwXTextCursor missing");
2696 GetImport().GetTextImport()->GetCursor(),
"Standard",
true );
2704 OSL_ENSURE( pDoc,
"<SwXMLTableContext::InsertTableSection(..)> - no <pDoc> at <SwXTextCursor> instance - <SwXTextCurosr> doesn't seem to be registered at a <SwUnoCursor> instance." );
2716 if( !pPrevSttNd &&
m_pBox1 !=
nullptr )
2724 SwPaM aPam(*pCNd, *pCNd);
2728 GetImport().GetTextImport()->SetCursor(
static_cast<XWordCursor*
>(xTextCursor.get()) );
2732 if (pStringValueStyleName)
2735 GetImport().GetTextImport()->GetCursor(), *pStringValueStyleName,
2736 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
std::map< OUString, sal_uInt32 > & GetTableNameMap()
const SwDoc * getDoc() const
const OUString & GetDefTableName()
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
constexpr OUStringLiteral UNO_NAME_TABLE_NAME
#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