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>
105 pStartNode( nullptr ),
111 , m_bHasStringValue(false)
114 inline void Set(
const OUString& rStyleName,
115 sal_uInt32 nRSpan, sal_uInt32 nCSpan,
118 const OUString* pFormula,
122 OUString
const*
const pStringValue);
124 bool IsUsed()
const {
return pStartNode!=
nullptr ||
138 return m_bHasStringValue ? &m_StringValue :
nullptr;
150 sal_uInt32 nRSpan, sal_uInt32 nCSpan,
154 const OUString* pFormula,
158 OUString
const*
const pStringValue )
176 if (pFormula !=
nullptr)
203 std::vector<std::unique_ptr<SwXMLTableCell_Impl>>
m_Cells;
209 const OUString *pDfltCellStyleName =
nullptr );
213 inline void Set(
const OUString& rStyleName,
214 const OUString& rDfltCellStyleName );
216 void Expand( sal_uInt32 nCells,
bool bOneCell );
229 const OUString *pDfltCellStyleName ) :
230 aStyleName( rStyleName ),
233 if( pDfltCellStyleName )
236 "SwXMLTableRow_Impl::SwXMLTableRow_Impl: too many cells" );
240 for( sal_uInt32
i=0U;
i<nCells; ++
i )
242 m_Cells.push_back(std::make_unique<SwXMLTableCell_Impl>());
249 "SwXMLTableRow_Impl::GetCell: column number is too big" );
251 OSL_ENSURE( nCol <
m_Cells.size(),
252 "SwXMLTableRow_Impl::GetCell: column number is out of bound" );
259 "SwXMLTableRow_Impl::Expand: too many cells" );
263 sal_uInt32 nColSpan = nCells -
m_Cells.size();
264 for (
size_t i =
m_Cells.size();
i < nCells; ++
i)
266 m_Cells.push_back(std::make_unique<SwXMLTableCell_Impl>(
267 1UL, bOneCell ? nColSpan : 1UL));
271 OSL_ENSURE( nCells <=
m_Cells.size(),
272 "SwXMLTableRow_Impl::Expand: wrong number of cells" );
276 const OUString& rDfltCellStyleName )
294 OUString m_aStyleName;
296 OUString m_sSaveParaDefault;
297 OUString m_StringValue;
303 bool m_bHasStringValue;
304 bool m_bValueTypeIsString;
307 sal_uInt32 m_nRowSpan;
308 sal_uInt32 m_nColSpan;
309 sal_uInt32 m_nColRepeat;
311 bool m_bHasTextContent : 1;
312 bool m_bHasTableContent : 1;
316 bool HasContent()
const {
return m_bHasTextContent || m_bHasTableContent; }
317 inline void InsertContent_();
318 inline void InsertContent();
323 SwXMLTableCellContext_Impl(
325 const Reference< xml::sax::XFastAttributeList > & xAttrList,
330 const Reference< xml::sax::XFastAttributeList > & xAttrList )
override;
331 virtual void SAL_CALL
endFastElement(sal_Int32 nElement)
override;
338 SwXMLTableCellContext_Impl::SwXMLTableCellContext_Impl(
340 const Reference< xml::sax::XFastAttributeList > & xAttrList,
344 m_xMyTable( pTable ),
346 m_bHasValue( false ),
347 m_bHasStringValue(false),
348 m_bValueTypeIsString(false),
353 m_bHasTextContent( false ),
354 m_bHasTableContent( false )
356 m_sSaveParaDefault = GetImport().GetTextImport()->GetCellParaStyleDefault();
359 switch( aIter.getToken() )
363 GetImport().GetTextImport()->SetCellParaStyleDefault(m_aStyleName);
365 case XML_ELEMENT(TABLE, XML_NUMBER_COLUMNS_SPANNED):
366 m_nColSpan = static_cast<sal_uInt32>(
std::
max<sal_Int32>(1, aIter.
toInt32()));
367 if (m_nColSpan > 256)
369 SAL_INFO(
"sw.xml",
"ignoring huge table:number-columns-spanned " << m_nColSpan);
374 m_nRowSpan = static_cast<sal_uInt32>(
std::
max<sal_Int32>(1, aIter.
toInt32()));
377 SAL_INFO(
"sw.xml",
"ignoring huge table:number-rows-spanned " << m_nRowSpan);
381 case XML_ELEMENT(TABLE, XML_NUMBER_COLUMNS_REPEATED):
382 m_nColRepeat = static_cast<sal_uInt32>(
std::
max<sal_Int32>(1, aIter.
toInt32()));
383 if (m_nColRepeat > 256)
385 SAL_INFO(
"sw.xml",
"ignoring huge table:number-columns-repeated " << m_nColRepeat);
392 const sal_uInt16 nPrefix2 = GetImport().GetNamespaceMap().
393 GetKeyByAttrValueQName(aIter.toString(), &sTmp);
422 if (GetImport().GetMM100UnitConverter().convertDateTime(fTmp,
435 m_fValue = (bTmp ? 1.0 : 0.0);
452 m_StringValue = aIter.toString();
453 m_bHasStringValue =
true;
458 if (
"string" == aIter.toString())
460 m_bValueTypeIsString =
true;
473 inline void SwXMLTableCellContext_Impl::InsertContent_()
475 SwStartNode const*
const pStartNode( GetTable()->InsertTableSection(
nullptr,
476 (m_bHasStringValue && m_bValueTypeIsString &&
477 !m_aStyleName.isEmpty()) ? & m_aStyleName :
nullptr) );
478 GetTable()->InsertCell( m_aStyleName, m_nRowSpan, m_nColSpan,
480 nullptr, m_bProtect, &m_sFormula, m_bHasValue, m_fValue,
481 (m_bHasStringValue && m_bValueTypeIsString) ? &m_StringValue :
nullptr);
484 inline void SwXMLTableCellContext_Impl::InsertContent()
486 OSL_ENSURE( !HasContent(),
"content already there" );
487 m_bHasTextContent =
true;
491 inline void SwXMLTableCellContext_Impl::InsertContent(
494 GetTable()->InsertCell( m_aStyleName, m_nRowSpan, m_nColSpan,
nullptr, pTable, m_bProtect );
495 m_bHasTableContent =
true;
498 css::uno::Reference<css::xml::sax::XFastContextHandler> SwXMLTableCellContext_Impl::createFastChildContext(
500 const Reference< xml::sax::XFastAttributeList > & xAttrList )
504 bool bSubTable =
false;
509 if( aIter.getToken() ==
XML_ELEMENT(TABLE, XML_IS_SUB_TABLE) )
526 pContext = pTableContext;
527 if( GetTable()->IsValid() )
528 InsertContent( pTableContext );
530 GetTable()->SetHasSubTables(
true );
535 if( GetTable()->IsValid() && !HasContent() )
538 if (!(m_bValueTypeIsString && m_bHasStringValue))
540 pContext = GetImport().GetTextImport()->CreateTextChildContext(
541 GetImport(), nElement, xAttrList,
549 void SwXMLTableCellContext_Impl::endFastElement(sal_Int32 )
551 if( GetTable()->IsValid() )
553 if( m_bHasTextContent )
555 GetImport().GetTextImport()->DeleteParagraph();
556 if( m_nColRepeat > 1 && m_nColSpan == 1 )
560 Reference < XTextCursor > xSrcTextCursor =
561 GetImport().GetTextImport()->GetText()->createTextCursor();
562 xSrcTextCursor->gotoEnd(
true );
565 Reference<XUnoTunnel> xSrcCursorTunnel( xSrcTextCursor, UNO_QUERY);
566 assert(xSrcCursorTunnel.is() &&
"missing XUnoTunnel for Cursor");
569 assert(pSrcTextCursor &&
"SwXTextCursor missing");
570 SwDoc *pDoc = pSrcTextCursor->GetDoc();
571 const SwPaM *pSrcPaM = pSrcTextCursor->GetPaM();
573 while( m_nColRepeat > 1 && GetTable()->IsInsertCellPossible() )
577 Reference<XUnoTunnel> xDstCursorTunnel(
578 GetImport().GetTextImport()->GetCursor(), UNO_QUERY);
579 assert(xDstCursorTunnel.is() &&
"missing XUnoTunnel for Cursor");
582 assert(pDstTextCursor &&
"SwXTextCursor missing");
584 SwPosition aDstPos( *pDstTextCursor->GetPaM()->GetPoint() );
591 else if( !m_bHasTableContent )
594 if( m_nColRepeat > 1 && m_nColSpan == 1 )
596 while( m_nColRepeat > 1 && GetTable()->IsInsertCellPossible() )
604 GetImport().GetTextImport()->SetCellParaStyleDefault(m_sSaveParaDefault);
617 SwXMLTableColContext_Impl(
619 const Reference< xml::sax::XFastAttributeList > & xAttrList,
627 SwXMLTableColContext_Impl::SwXMLTableColContext_Impl(
629 const Reference< xml::sax::XFastAttributeList > & xAttrList,
634 sal_uInt32 nColRep = 1;
639 switch (aIter.getToken())
644 case XML_ELEMENT(TABLE, XML_NUMBER_COLUMNS_REPEATED):
646 nColRep =
static_cast<sal_uInt32
>(std::max<sal_Int32>(1, aIter.toInt32()));
649 SAL_INFO(
"sw.xml",
"ignoring huge table:number-columns-repeated " << nColRep);
654 case XML_ELEMENT(TABLE, XML_DEFAULT_CELL_STYLE_NAME):
655 aDfltCellStyleName = aIter.
toString();
667 sal_Int32 nWidth =
MINLAY;
668 bool bRelWidth =
true;
669 if( !aStyleName.isEmpty() )
673 if( GetSwImport().FindAutomaticStyle(
674 XmlStyleFamily::TABLE_COLUMN,
675 aStyleName, &pAutoItemSet ) &&
688 while( nColRep-- && GetTable()->IsInsertColPossible() )
689 GetTable()->InsertColumn( nWidth, bRelWidth, &aDfltCellStyleName );
703 SwXMLTableColsContext_Impl(
708 sal_Int32 Element,
const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList )
override;
715 SwXMLTableColsContext_Impl::SwXMLTableColsContext_Impl(
723 css::uno::Reference< css::xml::sax::XFastContextHandler > SwXMLTableColsContext_Impl::createFastChildContext(
724 sal_Int32 nElement,
const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList )
728 if( nElement ==
XML_ELEMENT(TABLE, XML_TABLE_COLUMN) &&
729 GetTable()->IsInsertColPossible() )
730 pContext =
new SwXMLTableColContext_Impl( GetSwImport(), xAttrList, GetTable() );
743 sal_uInt32 nRowRepeat;
749 SwXMLTableRowContext_Impl(
751 const Reference< xml::sax::XFastAttributeList > & xAttrList,
754 virtual css::uno::Reference<css::xml::sax::XFastContextHandler> SAL_CALL
createFastChildContext( sal_Int32 nElement,
755 const Reference< xml::sax::XFastAttributeList > & xAttrList )
override;
757 virtual void SAL_CALL
endFastElement(sal_Int32 nElement)
override;
764 SwXMLTableRowContext_Impl::SwXMLTableRowContext_Impl(
SwXMLImport& rImport,
766 const Reference< xml::sax::XFastAttributeList > & xAttrList,
778 switch(aIter.getToken())
785 nRowRepeat =
static_cast<sal_uInt32
>(std::max<sal_Int32>(1, aIter.toInt32()));
788 SAL_INFO(
"sw.xml",
"ignoring huge table:number-rows-repeated " << nRowRepeat);
793 case XML_ELEMENT(STYLE, XML_DEFAULT_CELL_STYLE_NAME):
794 aDfltCellStyleName = aIter.
toString();
803 if( GetTable()->IsValid() )
804 GetTable()->InsertRow( aStyleName, aDfltCellStyleName, bInHead );
807 void SwXMLTableRowContext_Impl::endFastElement(sal_Int32 )
809 if( GetTable()->IsValid() )
811 GetTable()->FinishRow();
814 GetTable()->InsertRepRows( nRowRepeat );
818 css::uno::Reference<css::xml::sax::XFastContextHandler> SwXMLTableRowContext_Impl::createFastChildContext(
820 const Reference< xml::sax::XFastAttributeList > & xAttrList )
824 if( nElement ==
XML_ELEMENT(TABLE, XML_TABLE_CELL) ||
827 if( !GetTable()->IsValid() || GetTable()->IsInsertCellPossible() )
828 pContext =
new SwXMLTableCellContext_Impl( GetSwImport(), nElement,
832 else if( nElement ==
XML_ELEMENT(TABLE, XML_COVERED_TABLE_CELL) ||
833 nElement ==
XML_ELEMENT(LO_EXT, XML_COVERED_TABLE_CELL) )
859 const Reference< xml::sax::XFastAttributeList > & xAttrList )
override;
866 SwXMLTableRowsContext_Impl::SwXMLTableRowsContext_Impl(
SwXMLImport& rImport,
875 css::uno::Reference<css::xml::sax::XFastContextHandler> SwXMLTableRowsContext_Impl::createFastChildContext(
877 const Reference< xml::sax::XFastAttributeList > & xAttrList )
879 if( nElement==
XML_ELEMENT(TABLE, XML_TABLE_ROW ) &&
880 GetTable()->IsInsertRowPossible() )
881 return new SwXMLTableRowContext_Impl( GetSwImport(), nElement,
904 const Reference<xml::sax::XFastAttributeList> & xAttrList)
override;
920 bIsAutomaticUpdate(false)
926 const Reference<xml::sax::XFastAttributeList> & xAttrList)
930 switch (aIter.getToken())
963 const OUString sPrefixStr(sPrefix.isEmpty() ? OUString(
"_") : sPrefix);
975 sName = sPrefixStr + OUString::number(nCount);
994 ? SfxLinkUpdateMode::ALWAYS
995 : SfxLinkUpdateMode::ONCALL;
1003 if (
sName.isEmpty())
1012 if (
nullptr != pOldType)
1015 if ( (pOldType->
GetCmd() == sCommand) &&
1016 (pOldType->
GetType() == nType) )
1032 if (
nullptr == pType)
1040 OSL_ENSURE(
nullptr != pType,
"We really want a SwDDEFieldType here!");
1055 mbProtected( bProtected )
1060 return (rArg.
mnWidth == mnWidth) &&
1076 sal_uInt32 nCol )
const
1078 return (*
m_pRows)[nRow]->GetCell( nCol );
1084 return (*
m_pRows)[nRow]->GetCell( nCol );
1089 const Reference< xml::sax::XFastAttributeList > & xAttrList ) :
1092 m_pTableNode( nullptr ),
1094 m_bOwnsBox1( false ),
1095 m_pSttNd1( nullptr ),
1096 m_pBoxFormat( nullptr ),
1097 m_pLineFormat( nullptr ),
1098 m_bFirstSection( true ),
1099 m_bRelWidth( true ),
1100 m_bHasSubTables( false ),
1114 const OUString sValue = aIter.toString();
1115 switch(aIter.getToken())
1123 case XML_ELEMENT(TABLE, XML_DEFAULT_CELL_STYLE_NAME):
1139 OUString sTableName;
1140 if( !aName.isEmpty() )
1146 if( sTableName.isEmpty() )
1150 ->GetRenameMap().Add( XML_TEXT_RENAME_TYPE_TABLE, aName, sTableName );
1153 Reference< XTextTable > xTable;
1157 OSL_ENSURE(
xFactory.is(),
"factory missing" );
1160 Reference<XInterface> xIfc =
xFactory->createInstance(
"com.sun.star.text.TextTable" );
1161 OSL_ENSURE( xIfc.is(),
"Couldn't create a table" );
1164 xTable.set( xIfc, UNO_QUERY );
1169 xTable->initialize( 1, 1 );
1176 catch( IllegalArgumentException& )
1188 Reference<XUnoTunnel> xTableTunnel( xTable, UNO_QUERY);
1189 if( xTableTunnel.is() )
1193 OSL_ENSURE( pXTable,
"SwXTextTable missing" );
1196 Reference < XCellRange > xCellRange( xTable, UNO_QUERY );
1197 Reference < XCell > xCell = xCellRange->getCellByPosition( 0, 0 );
1198 Reference < XText> xText( xCell, UNO_QUERY );
1209 OSL_ENSURE( pTableFrameFormat,
"table format missing" );
1211 OSL_ENSURE( pTable,
"table missing" );
1215 pTableFrameFormat->
SetName( sTableName );
1226 m_pTableNode( pTable->m_pTableNode ),
1228 m_bOwnsBox1( false ),
1229 m_pSttNd1( nullptr ),
1230 m_pBoxFormat( nullptr ),
1231 m_pLineFormat( nullptr ),
1232 m_xParentTable( pTable ),
1233 m_bFirstSection( false ),
1234 m_bRelWidth( true ),
1235 m_bHasSubTables( false ),
1257 const Reference< xml::sax::XFastAttributeList > & xAttrList )
1259 bool bHeader =
false;
1265 return new SwXMLTableRowContext_Impl(
GetSwImport(), nElement, xAttrList,
this );
1271 return new SwXMLTableRowsContext_Impl(
GetSwImport(),
this, bHeader );
1281 return new SwXMLTableColsContext_Impl(
GetSwImport(),
this );
1286 return new SwXMLTableColContext_Impl(
GetSwImport(), xAttrList,
1302 const OUString *pDfltCellStyleName )
1305 "SwXMLTableContext::InsertColumn: no space left" );
1314 if( !((pDfltCellStyleName && !pDfltCellStyleName->isEmpty()) ||
1326 if(pDfltCellStyleName)
1333 sal_uInt32 nColSpan )
const
1335 sal_uInt32 nLast = nCol+nColSpan;
1339 sal_Int32 nWidth2 = 0;
1340 for( sal_uInt32
i=nCol;
i < nLast; ++
i )
1355 sal_uInt32 nRowSpan, sal_uInt32 nColSpan,
1359 const OUString* pFormula,
1362 OUString
const*
const pStringValue )
1365 "SwXMLTableContext::InsertCell: row is full" );
1367 "SwXMLTableContext::InsertCell: table is full" );
1371 OSL_ENSURE( nRowSpan >=1,
"SwXMLTableContext::InsertCell: row span is 0" );
1374 OSL_ENSURE( nColSpan >=1,
"SwXMLTableContext::InsertCell: col span is 0" );
1379 sal_uInt32 nColsReq =
m_nCurCol + nColSpan;
1405 sal_uInt32 nRowsReq =
m_nCurRow + nRowSpan;
1426 if (
m_pRows->size() < nRowsReq)
1428 for (
size_t i =
m_pRows->size();
i < nRowsReq; ++
i)
1429 m_pRows->push_back(std::make_unique<SwXMLTableRow_Impl>(
1433 OUString sStyleName( rStyleName );
1434 if( sStyleName.isEmpty() )
1436 sStyleName = (*m_pRows)[
m_nCurRow]->GetDefaultCellStyleName();
1440 if( sStyleName.isEmpty() )
1446 for( sal_uInt32
i=nColSpan;
i>0; --
i )
1448 for( sal_uInt32 j=nRowSpan; j>0; --j )
1450 const bool bCovered =
i != nColSpan || j != nRowSpan;
1453 throw css::lang::IndexOutOfBoundsException();
1454 pCell->
Set( sStyleName, j,
i, pStartNode,
1455 pTable, bProtect, pFormula, bHasValue, bCovered, fValue,
1467 const OUString& rDfltCellStyleName,
1471 "SwXMLTableContext::InsertRow: no space left" );
1479 if (m_nCurRow < m_pRows->
size())
1484 rStyleName, rDfltCellStyleName );
1489 m_pRows->push_back(std::make_unique<SwXMLTableRow_Impl>(
1491 &rDfltCellStyleName));
1546 sal_uInt32 nCol )
const
1557 pPrevCell =
GetCell( nRow, nCol-1 );
1575 OSL_ENSURE( pSttNd !=
nullptr,
1583 sal_uInt32 nColSpan )
1585 sal_uInt32 nLastCol = nCol + nColSpan;
1586 for( sal_uInt32
i = nCol;
i < nLastCol;
i++ )
1588 sal_uInt32 j = nRow;
1589 sal_uInt32 nRowSpan = 1;
1594 pCell = j > 0 ?
GetCell( --j,
i ) :
nullptr;
1605 sal_uInt32 nLastRow = bRows ? nRow + pCell->
GetRowSpan() : nRow + 1;
1606 sal_uInt32 nLastCol = nCol + pCell->
GetColSpan();
1608 for( sal_uInt32
i=nRow;
i<nLastRow;
i++ )
1611 for( sal_uInt32 j=nCol; j<nLastCol; j++ )
1646 const OUString& rStyleName,
1647 sal_Int32 nColumnWidth,
1651 bool* pModifyLocked )
1674 (*m_pSharedBoxFormats)[ aKey ] = pBoxFormat2;
1679 pBoxFormat2 = aIter->second;
1689 if ( pModifyLocked !=
nullptr )
1700 sal_uInt32 nLeftCol,
1701 sal_uInt32 nBottomRow,
1702 sal_uInt32 nRightCol )
1707 sal_uInt32 nColSpan = nRightCol - nLeftCol;
1719 bool bSplitted =
false;
1723 sal_uInt32 nStartRow = nTopRow;
1726 for( i = nTopRow; i < nBottomRow; i++ )
1731 for( sal_uInt32 j=nLeftCol; j<nRightCol; j++ )
1737 if( bSplit && (nStartRow>nTopRow || i+1<nBottomRow) )
1754 nStartRow = nTopRow;
1755 while( nStartRow < nBottomRow )
1757 sal_uInt32 nMaxRowSpan = 0;
1760 for( i=nLeftCol; i<nRightCol; i++ )
1762 pCell = pStartRow->
GetCell(i);
1767 nStartRow += nMaxRowSpan;
1768 if( nStartRow<nBottomRow )
1772 while( i < nRightCol )
1778 const sal_uInt32 nColSpan2 = pCell2->
GetColSpan();
1799 sal_uInt32 nLeftCol, sal_uInt32 nRightCol )
1803 sal_uInt32 nColSpan = nRightCol - nLeftCol;
1823 pBox, sStyleName, nColWidth, pCell->
IsProtected(),
1826 bNew, &bModifyLocked );
1835 XmlStyleFamily::TABLE_CELL, sStyleName, &pAutoItemSet ) )
1848 SAL_WARN_IF(!pTextNode,
"sw",
"Should have a text node in cell?");
1851 SAL_WARN_IF(!pTextNode->GetText().isEmpty(),
"sw",
1865 bool bSuppressNumericContent =
false;
1868 !sStyleName.isEmpty() )
1873 == SfxItemState::SET )
1877 if( ( pNumFormat !=
nullptr ) && ( pNumFormat->
GetValue() == 0 ) )
1885 if( pTextNode !=
nullptr )
1888 const OUString& rText = pTextNode->
GetText();
1889 if( ( rText.getLength() > 10 ) ||
1890 ( rText.indexOf(
'0' ) == -1 ) )
1892 bSuppressNumericContent =
true;
1897 bSuppressNumericContent =
true;
1902 if( bSuppressNumericContent )
1913 const OUString& rFormula = pCell->
GetFormula();
1914 if (!rFormula.isEmpty())
1928 == SfxItemState::SET )
1935 if( pNumFormat !=
nullptr && pNumberFormatter &&
1961 if (! bModifyLocked)
1971 sal_uInt32 nLeftCol,
1972 sal_uInt32 nBottomRow,
1973 sal_uInt32 nRightCol )
1977 if( !pUpper && 0UL==nTopRow )
1993 const OUString& rStyleName = (*m_pRows)[nTopRow]->GetStyleName();
1994 if( 1 == (nBottomRow - nTopRow) &&
1995 !rStyleName.isEmpty() &&
1997 XmlStyleFamily::TABLE_ROW, rStyleName, &pAutoItemSet ) )
2005 sal_uInt32 nStartCol = nLeftCol;
2006 while( nStartCol < nRightCol )
2008 for( sal_uInt32 nRow=nTopRow; nRow<nBottomRow; nRow++ )
2009 (*
m_pRows)[nRow]->SetSplitable(
true );
2011 sal_uInt32 nCol = nStartCol;
2012 sal_uInt32 nSplitCol = nRightCol;
2013 bool bSplitted =
false;
2016 OSL_ENSURE( nCol < nRightCol,
"Ran too far" );
2022 bool bHoriSplitMayContinue =
false;
2023 bool bHoriSplitPossible =
false;
2028 for( sal_uInt32 nRow=nTopRow; nRow<nBottomRow; nRow++ )
2033 bool bHoriSplit = (*m_pRows)[nRow]->IsSplitable() &&
2034 nRow+1 < nBottomRow &&
2036 (*m_pRows)[nRow]->SetSplitable( bHoriSplit );
2043 bHoriSplitPossible |= bHoriSplit;
2047 bHoriSplit &= (nCol+1 < nRightCol &&
2049 bHoriSplitMayContinue |= bHoriSplit;
2059 if ( pCell ==
nullptr )
2061 OSL_FAIL(
"table seems to be corrupt." );
2070 #if OSL_DEBUG_LEVEL > 0
2071 if( nCol == nRightCol-1 )
2073 OSL_ENSURE( bSplit,
"Split-Flag wrong" );
2076 OSL_ENSURE( !bHoriSplitMayContinue,
2077 "HoriSplitMayContinue-Flag wrong" );
2079 OSL_ENSURE( pTmpCell->
GetRowSpan() != (nBottomRow-nTopRow) ||
2080 !bHoriSplitPossible,
"HoriSplitPossible-Flag wrong" );
2085 OSL_ENSURE( !
m_bHasSubTables || !bHoriSplitMayContinue || bHoriSplitPossible,
2086 "bHoriSplitMayContinue, but not bHoriSplitPossible" );
2098 sal_Int32 nBoxRowSpan = 1;
2104 nBoxRowSpan = -1 * nBoxRowSpan;
2111 nSplitCol = nCol + 1;
2113 pBox =
MakeTableBox( pLine, pCell, nStartCol, nSplitCol );
2115 if ( 1 != nBoxRowSpan )
2120 else if(
m_bHasSubTables && bHoriSplitPossible && bHoriSplitMayContinue )
2128 nSplitCol = nCol + 1;
2139 if( bHoriSplitPossible || nSplitCol > nCol+1 )
2141 OSL_ENSURE( !bHoriSplitMayContinue,
2142 "bHoriSplitMayContinue==true" );
2143 OSL_ENSURE( bHoriSplitPossible || nSplitCol == nRightCol,
2144 "bHoriSplitPossible flag should be set" );
2146 nSplitCol = nCol + 1;
2150 nBottomRow, nSplitCol );
2157 rBoxes.push_back( pBox );
2161 nStartCol = nSplitCol;
2170 std::vector<ColumnWidthInfo>::iterator colIter;
2199 sal_Int32 nAbsWidth = 0;
2200 sal_Int32 nMinAbsColWidth = 0;
2201 sal_Int32 nRelWidth = 0;
2202 sal_Int32 nMinRelColWidth = 0;
2203 sal_uInt32 nRelCols = 0;
2206 if( rCol.isRelative )
2208 nRelWidth += rCol.width;
2209 if( 0 == nMinRelColWidth || rCol.width < nMinRelColWidth )
2210 nMinRelColWidth = rCol.width;
2215 nAbsWidth += rCol.width;
2216 if( 0 == nMinAbsColWidth || rCol.width < nMinAbsColWidth )
2217 nMinAbsColWidth = rCol.width;
2220 sal_uInt32 nAbsCols = nCols - nRelCols;
2233 if( 0 == nMinRelColWidth )
2234 nMinRelColWidth = nMinAbsColWidth;
2236 for(
auto& rCol : m_aColumnWidths)
2238 if( !rCol.isRelative )
2240 if (nMinAbsColWidth == 0)
2243 if (o3tl::checked_multiply<sal_Int32>(rCol.width, nMinRelColWidth, nVal))
2244 throw std::overflow_error(
"overflow in multiply");
2245 sal_Int32 nRelCol = nVal / nMinAbsColWidth;
2246 rCol.width = nRelCol;
2247 rCol.isRelative =
true;
2248 nRelWidth += nRelCol;
2264 if( nRelWidth !=
m_nWidth && nRelWidth && nCols )
2266 double n =
static_cast<double>(
m_nWidth) / static_cast<double>(nRelWidth);
2268 for( colIter = m_aColumnWidths.begin(); colIter < m_aColumnWidths.end() - 1; ++colIter)
2270 sal_Int32 nW =
static_cast<sal_Int32
>( colIter->width * n);
2271 colIter->width =
static_cast<sal_uInt16
>(nW);
2274 m_aColumnWidths.back().width = (
m_nWidth-nRelWidth);
2285 sal_Int32 nAbsForRelWidth =
2290 sal_Int32 nExtraRel = nRelWidth - (nRelCols * nMinRelColWidth);
2294 sal_Int32 nMinAbs = nRelCols *
MINLAY;
2295 sal_Int32 nExtraAbs =
2296 nAbsForRelWidth > nMinAbs ? nAbsForRelWidth - nMinAbs : sal_Int32(0L);
2299 bool bMinExtra =
false;
2302 if( nAbsForRelWidth <= nMinAbs )
2306 nAbsForRelWidth = nMinAbs;
2309 else if( nAbsForRelWidth <= (nRelWidth * MINLAY) /
2322 for(
auto& rCol : m_aColumnWidths )
2324 if( rCol.isRelative )
2331 nAbsCol = nAbsForRelWidth;
2339 else if( bMinExtra )
2341 sal_Int32 nExtraRelCol = rCol.width - nMinRelColWidth;
2342 nAbsCol = MINLAY + (nExtraRelCol * nExtraAbs) /
2347 nAbsCol = ( rCol.width * nAbsForRelWidth) / nRelWidth;
2350 rCol.width = nAbsCol;
2351 rCol.isRelative =
false;
2352 nAbsForRelWidth -= nAbsCol;
2353 nAbsWidth += nAbsCol;
2361 if( nCols && nAbsWidth )
2367 sal_Int32 nExtraAbs =
m_nWidth - nAbsWidth;
2368 sal_Int32 nAbsLastCol = m_aColumnWidths.back().width + nExtraAbs;
2369 for( colIter = m_aColumnWidths.begin(); colIter < m_aColumnWidths.end()-1; ++colIter )
2371 sal_Int32 nAbsCol = colIter->width;
2372 sal_Int32 nExtraAbsCol = (nAbsCol * nExtraAbs) /
2374 nAbsCol += nExtraAbsCol;
2375 colIter->width = nAbsCol;
2376 nAbsLastCol -= nExtraAbsCol;
2378 m_aColumnWidths.back().width = nAbsLastCol;
2386 sal_Int32 nAbsLastCol =
MINLAY + nExtraAbs;
2387 for( colIter = m_aColumnWidths.begin(); colIter < m_aColumnWidths.end()-1; ++colIter )
2389 sal_Int32 nAbsCol = colIter->width;
2390 sal_Int32 nExtraAbsCol = (nAbsCol * nExtraAbs) /
2392 nAbsCol =
MINLAY + nExtraAbsCol;
2393 colIter->width = nAbsCol;
2394 nAbsLastCol -= nExtraAbsCol;
2396 m_aColumnWidths.back().width = nAbsLastCol;
2405 sal_uInt32 nStartRow = 0;
2406 sal_uInt32 nRows =
m_pRows->size();
2407 for(sal_uInt32
i=0;
i<nRows; ++
i )
2414 for( sal_uInt32 j=0; j<nCols; j++ )
2426 if( pBox || nStartRow>0 )
2443 OSL_FAIL(
"invalid table: no cells; deleting...");
2456 sal_Int16 eHoriOrient = text::HoriOrientation::FULL;
2457 bool bSetHoriOrient =
false;
2461 OUString sStyleName;
2470 XmlStyleFamily::TABLE_TABLE,
m_aStyleName, &pAutoItemSet ) &&
2477 pLRSpace = static_cast<const SvxLRSpaceItem *>(pItem);
2483 switch( eHoriOrient )
2485 case text::HoriOrientation::FULL:
2489 bSetHoriOrient =
true;
2492 case text::HoriOrientation::LEFT:
2495 eHoriOrient = text::HoriOrientation::LEFT_AND_WIDTH;
2496 bSetHoriOrient =
true;
2505 bSetHoriOrient =
true;
2511 pSize = static_cast<const SwFormatFrameSize *>(pItem);
2513 switch( eHoriOrient )
2515 case text::HoriOrientation::FULL:
2536 sal_Int32
const min =
static_cast<sal_Int32
>(
2551 eHoriOrient = text::HoriOrientation::LEFT_AND_WIDTH == eHoriOrient
2553 bSetHoriOrient =
true;
2563 bSetHoriOrient =
true;
2578 if( bSetHoriOrient )
2589 for (std::unique_ptr<SwXMLTableRow_Impl> & rRow : *
m_pRows)
2605 pFieldType, false ) );
2630 for (std::unique_ptr<SwXMLTableRow_Impl> & rpRow : *
m_pRows)
2639 OUString
const*
const pStringValueStyleName)
2648 Reference<XUnoTunnel> xCursorTunnel(
GetImport().GetTextImport()->GetCursor(),
2650 OSL_ENSURE( xCursorTunnel.is(),
"missing XUnoTunnel for Cursor" );
2653 OSL_ENSURE( pTextCursor,
"SwXTextCursor missing" );
2661 GetImport().GetTextImport()->GetCursor(),
"Standard",
true );
2669 OSL_ENSURE( pDoc,
"<SwXMLTableContext::InsertTableSection(..)> - no <pDoc> at <SwXTextCursor> instance - <SwXTextCurosr> doesn't seem to be registered at a <SwUnoCursor> instance." );
2674 sal_uInt32 nOffset = pPrevSttNd ? 1UL : 0UL;
2681 if( !pPrevSttNd &&
m_pBox1 !=
nullptr )
2690 const uno::Reference< text::XTextRange > xTextRange =
2692 Reference < XText > xText = xTextRange->getText();
2693 Reference < XTextCursor > xTextCursor =
2694 xText->createTextCursorByRange( xTextRange );
2699 if (pStringValueStyleName)
2702 GetImport().GetTextImport()->GetCursor(), *pStringValueStyleName,
2703 true,
false, -1,
false);
SwTableNode * m_pTableNode
const SwEndNode * EndOfSectionNode() const
Starts a section of nodes in the document model.
constexpr TypedWhichId< SvxProtectItem > RES_PROTECT(100)
tools::Long GetWidth() const
sal_uLong GetIndex() const
void SetRowsToRepeat(sal_uInt16 nNumOfRows)
Represents the style of a paragraph.
Marks a position in the document model.
std::unique_ptr< SwXMLTableRows_Impl > m_pRows
void Expand(sal_uInt32 nCells, bool bOneCell)
bool FindAutomaticStyle(XmlStyleFamily nFamily, const OUString &rName, const SfxItemSet **ppItemSet) const
sal_uInt32 GetColumnCount() const
sal_uLong StartOfSectionIndex() const
void DelFrames(SwRootFrame const *pLayout=nullptr)
Method deletes all views of document for the node.
constexpr TypedWhichId< SwTableBoxNumFormat > RES_BOXATR_FORMAT(RES_BOXATR_BEGIN)
OUString aDfltCellStyleName
const OUString & GetText() const
SvNumberFormatter * GetNumberFormatter(bool bCreate=true)
constexpr TypedWhichId< SwTableBoxValue > RES_BOXATR_VALUE(150)
static void FillUIName(const OUString &rName, OUString &rFillName, SwGetPoolIdFromName)
void InsertRow(const OUString &rStyleName, const OUString &rDfltCellStyleName, bool bInHead)
const SwStartNode * pStartNode
virtual SwFieldType * GetFieldType(SwFieldIds nResId, const OUString &rName, bool bDbFieldMatching) const =0
constexpr TypedWhichId< SwFormatFrameSize > RES_FRM_SIZE(89)
const SwStartNode * m_pSttNd1
sal_uInt32 GetRowSpan() const
const SwStartNode * InsertTableSection(const SwStartNode *pPrevSttNd=nullptr, OUString const *pStringValueStyleName=nullptr)
void SetStartNode(const SwStartNode *pSttNd)
const OUString & GetStyleName() const
OUString GetUniqueTableName() const
SwTableLine * MakeTableLine(SwTableBox *pUpper, sal_uInt32 nTopRow, sal_uInt32 nLeftCol, sal_uInt32 nBottomRow, sal_uInt32 nRightCol)
OUString GetColumnDefaultCellStyleName(sal_uInt32 nCol) const
const SwPosition * GetMark() const
const sal_Unicode cTokenSeparator
SwTableBoxFormat * m_pBoxFormat
SvXMLImport & GetImport()
sal_Int32 toInt32(OUString const &rStr)
SfxLinkUpdateMode GetType() const
SwFrameFormat * ClaimFrameFormat()
void MakeTable(SwTableBox *pBox, sal_Int32 nWidth)
void push_back(SwTableLine *pLine)
SwTableLine is one table row in the document model.
SwTableBox * NewTableBox(const SwStartNode *pStNd, SwTableLine *pUpper)
OUString m_aDfltCellStyleName
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
const OUString & GetFormula() const
rtl::Reference< XMLTextImportHelper > const & GetTextImport()
IDocumentContentOperations const & getIDocumentContentOperations() const
rtl::Reference< SwXMLDDETableContext_Impl > m_xDDESource
SwTableFormat * GetFrameFormat()
static void convertDouble(OUStringBuffer &rBuffer, double fNumber, bool bWriteUnits, sal_Int16 nSourceUnit, sal_Int16 nTargetUnit)
OUString const & GetCmd() const
IDocumentFieldsAccess const & getIDocumentFieldsAccess() const
const SwXMLTableCell_Impl * GetCell(sal_uInt32 nRow, sal_uInt32 nCol) const
void Set(const OUString &rStyleName, const OUString &rDfltCellStyleName)
OUString const * GetStringValue() const
std::unique_ptr< std::vector< OUString > > m_pColumnDefaultCellStyleNames
constexpr TypedWhichId< SwFormatHoriOrient > RES_HORI_ORIENT(103)
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
IDocumentStylePoolAccess const & getIDocumentStylePoolAccess() const
check if target position is in fly anchored at source range
void SetTableModel(bool bNew)
#define XMLOFF_WARN_UNKNOWN(area, rIter)
SwXMLTableContext * GetParentTable() const
css::uno::Reference< css::text::XTextCursor > m_xOldCursor
const SwTable & GetTable() const
virtual void DeleteSection(SwNode *pNode)=0
Delete section containing the node.
SvXMLImportContextRef xSubTable
static OUString getPrefixAndNameFromToken(sal_Int32 nToken)
void SetSplitable(bool bSet)
const SwStartNode * GetPrevStartNode(sal_uInt32 nRow, sal_uInt32 nCol) const
const IDocumentFieldsAccess & getIDocumentFieldsAccess() const
Provides access to the document fields administration interface.
const SwStartNode * m_pStartNode
SwXMLTableContext * GetSubTable() const
SwStartNode * MakeTextSection(const SwNodeIndex &rWhere, SwStartNodeType eSttNdTyp, SwTextFormatColl *pColl)
SvXMLImportContextRef m_xParentTable
PaM is Point and Mark: a selection of the document model.
static SwTable * FindTable(SwFrameFormat const *const pFormat)
void ReplaceWithEmptyCell(sal_uInt32 nRow, sal_uInt32 nCol, bool bRows)
void InsertRepRows(sal_uInt32 nCount)
css::uno::Reference< css::text::XTextContent > m_xTextContent
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
SwXMLTableContext(SwXMLImport &rImport, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
if set, call pBox->LockModify() and return old lock status
OUString & GetDDEApplication()
const SwPosition * GetPoint() const
virtual bool CopyRange(SwPaM &rPam, SwPosition &rPos, SwCopyFlags flags) const =0
Copy a selected content range to a position.
SwIndex & Assign(SwIndexReg *, sal_Int32)
void InsertColumn(sal_Int32 nWidth, bool bRelWidth, const OUString *pDfltCellStyleName=nullptr)
bool IsInsertRowPossible() const
bool HasStringValue() const
void MakeTable_(SwTableBox *pBox=nullptr)
Marks a character position inside a document model node.
bool IsInsertColPossible() const
OUString & GetConnectionName()
virtual ~SwXMLTableContext() override
const OUString & GetStyleName() const
SwXMLImport & GetSwImport()
SwFrameFormat * GetFrameFormat()
SwXMLTableCell_Impl(sal_uInt32 nRSpan=1, sal_uInt32 nCSpan=1)
bool operator==(const TableBoxIndex &rArg) const
void MakeOwnFrames(SwNodeIndex *pIdxBehind)
Creates the frms for the table node (i.e. the TabFrames).
static void convertDuration(OUStringBuffer &rBuffer, const double fTime)
Marks a node in the document model.
SwFrameFormat * GetFrameFormat()
std::vector< std::unique_ptr< SwXMLTableCell_Impl > > m_Cells
std::unique_ptr< map_BoxFormat > m_pSharedBoxFormats
SwTableLines & GetTabLines()
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
SwTable is one table in the document model, containing rows (which contain cells).
SwTableLines & GetTabLines()
static bool convertBool(bool &rBool, std::u16string_view rString)
SwTableFormat * FindTableFormatByName(std::u16string_view rName, bool bAll=false) const
void SetXmlId(css::uno::Reference< css::uno::XInterface > const &i_xIfc, OUString const &i_rXmlId)
SwTableBoxFormat * GetSharedBoxFormat(SwTableBox *pBox, const OUString &rStyleName, sal_Int32 nColumnWidth, bool bProtected, bool bMayShare, bool &bNew, bool *pModifyLocked)
sets the appropriate SwTableBoxFormat at pBox.
bool IsModifyLocked() const
sal_uLong EndOfSectionIndex() const
SwTextNode is a paragraph in the document model.
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)
SwTableBoxes & GetTabBoxes()
void FixRowSpan(sal_uInt32 nRow, sal_uInt32 nCol, sal_uInt32 nColSpan)
std::vector< SwTableBox * > SwTableBoxes
constexpr TypedWhichId< SwTableBoxFormula > RES_BOXATR_FORMULA(149)
const SwStartNode * GetSttNd() const
void ChgFrameFormat(SwTableBoxFormat *pNewFormat, bool bNeedToReregister=true)
const SwStartNode * GetLastStartNode() const
#define SAL_WARN_IF(condition, area, stream)
virtual const SwViewShell * GetCurrentViewShell() const =0
Returns the layout set at the document.
virtual SwFieldType * InsertFieldType(const SwFieldType &)=0
sal_Int32 GetColumnWidth(sal_uInt32 nCol, sal_uInt32 nColSpan) const
std::vector< ColumnWidthInfo > m_aColumnWidths
static OUString lcl_GenerateFieldTypeName(const OUString &sPrefix, SwTableNode *pTableNode)
virtual void SAL_CALL endFastElement(sal_Int32 Element) override
const o3tl::enumarray< SvxAdjust, unsigned short > aSvxToUnoAdjust USHRT_MAX
void SetTableStyleName(const OUString &rName)
Set the new table style name for this table.
#define SAL_INFO(area, stream)
virtual css::uno::Reference< XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
static constexpr sal_Int32 MAX_WIDTH
static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId()
virtual SwTextFormatColl * GetTextCollFromPool(sal_uInt16 nId, bool bRegardLanguage=true)=0
Return "Auto-Collection with ID.
sal_uInt32 GetColSpan() const
#define XML_ELEMENT(prefix, name)
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const Reference< xml::sax::XFastAttributeList > &xAttrList) override
SwTableBox is one table cell in the document model.
std::vector< std::unique_ptr< SwXMLTableRow_Impl > > SwXMLTableRows_Impl
SwTableBox * MakeTableBox(SwTableLine *pUpper, const SwXMLTableCell_Impl *pStartNode, sal_uInt32 nLeftCol, sal_uInt32 nRightCol)
constexpr TypedWhichId< SvxLRSpaceItem > RES_LR_SPACE(91)
static SwDDEFieldType * lcl_GetDDEFieldType(SwXMLDDETableContext_Impl *pContext, SwTableNode *pTableNode)
SwXMLTableRow_Impl(const OUString &rStyleName, sal_uInt32 nCells, const OUString *pDfltCellStyleName=nullptr)
SwFrameFormat * ClaimFrameFormat()
std::unordered_map< TableBoxIndex, SwTableBoxFormat *, TableBoxIndexHasher > map_BoxFormat
const SwStartNode * FindTableBoxStartNode() const
void SetUpper(SwTableLine *pNew)
sal_uInt32 GetValue() const
TableBoxIndex(const OUString &rName, sal_Int32 nWidth, bool bProtected)
#define SAL_WARN(area, stream)
Reference< XSingleServiceFactory > xFactory
#define XMLOFF_WARN_UNKNOWN_ELEMENT(area, token)
void setRowSpan(sal_Int32 nNewRowSpan)
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
void SetContentProtect(bool bNew)
Ends a section of nodes in the document model.
bool GetIsAutomaticUpdate() const
SwXMLTableCell_Impl * GetCell(sal_uInt32 nCol)
Frame is variable in Var-direction.
void SetNewTable(std::unique_ptr< SwTable >, bool bNewFrames=true)
SwDoc * GetDocFromXMLImport(SvXMLImport const &)
const SwStartNode * GetStartNode() const
SwTableLineFormat * m_pLineFormat
const OUString & GetDefaultCellStyleName() const
constexpr sal_uInt16 XML_NAMESPACE_OOOW
static SW_DLLPUBLIC const css::uno::Sequence< sal_Int8 > & getUnoTunnelId()
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)
SwXMLDDETableContext_Impl(SwXMLImport &rImport)
void SetRowSpan(sal_uInt32 nSet)
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
OUString toString(OptionInfo const *info)
SwTableNode * GetTableNode() const
size_t operator()(const TableBoxIndex &rArg) const
SW_DLLPUBLIC SwFrameFormat * GetFrameFormat()