summaryrefslogtreecommitdiff
path: root/sw/source
diff options
context:
space:
mode:
authorMichael Stahl <Michael.Stahl@cib.de>2020-11-24 15:33:44 +0100
committerMichael Stahl <michael.stahl@cib.de>2020-11-24 19:54:36 +0100
commitecc3c621fe5a7e962f0e40cb3709ad5772a5d744 (patch)
treea9bfc6c067c6f249262ea695e02b2e850c59b50f /sw/source
parenta4565b9361636c3f9b01755b2f467056d33e4e30 (diff)
sw: fix SwXTextRange::createEnumeration() inside table cell
This would set CursorType::SelectionInTable but leave m_pOwnTable and m_pOwnStartNode uninitialised, causing sw/source/core/unocore/unoobj2.cxx:399: SwXParagraphEnumeration: table type but no start node or table and then the enumeration would return the table it's in as the first element, which is quite annoying. Refactor the creation of SwXParagraphEnumeration to prevent this. Change-Id: I4e9e3456bdf66b9822d19ad985a20b094e6bbba4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/106532 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.stahl@cib.de>
Diffstat (limited to 'sw/source')
-rw-r--r--sw/source/core/unocore/unoobj.cxx7
-rw-r--r--sw/source/core/unocore/unoobj2.cxx32
-rw-r--r--sw/source/core/unocore/unotbl.cxx3
3 files changed, 28 insertions, 14 deletions
diff --git a/sw/source/core/unocore/unoobj.cxx b/sw/source/core/unocore/unoobj.cxx
index eb100abb6e54..38315904adb2 100644
--- a/sw/source/core/unocore/unoobj.cxx
+++ b/sw/source/core/unocore/unoobj.cxx
@@ -2909,12 +2909,7 @@ SwXTextCursor::createEnumeration()
}
const CursorType eSetType = (CursorType::TableText == m_pImpl->m_eType)
? CursorType::SelectionInTable : CursorType::Selection;
- SwTableNode const*const pStartNode( (CursorType::TableText == m_pImpl->m_eType)
- ? rUnoCursor.GetPoint()->nNode.GetNode().FindTableNode()
- : nullptr);
- SwTable const*const pTable(
- pStartNode ? & pStartNode->GetTable() : nullptr );
- return SwXParagraphEnumeration::Create(pParentText, pNewCursor, eSetType, pStartNode, pTable);
+ return SwXParagraphEnumeration::Create(pParentText, pNewCursor, eSetType);
}
uno::Type SAL_CALL
diff --git a/sw/source/core/unocore/unoobj2.cxx b/sw/source/core/unocore/unoobj2.cxx
index f88ee9b84a9f..a2b98d41d307 100644
--- a/sw/source/core/unocore/unoobj2.cxx
+++ b/sw/source/core/unocore/unoobj2.cxx
@@ -395,10 +395,9 @@ struct SwXParagraphEnumerationImpl final : public SwXParagraphEnumeration
, m_pCursor(pCursor)
{
OSL_ENSURE(m_xParentText.is(), "SwXParagraphEnumeration: no parent?");
- OSL_ENSURE( !((CursorType::SelectionInTable == eType) ||
- (CursorType::TableText == eType))
- || (m_pOwnTable && m_pOwnStartNode),
- "SwXParagraphEnumeration: table type but no start node or table?");
+ assert( !((CursorType::SelectionInTable == eType)
+ || (CursorType::TableText == eType))
+ || (m_pOwnTable && m_pOwnStartNode));
if ((CursorType::Selection == m_eCursorType) ||
(CursorType::SelectionInTable == m_eCursorType))
@@ -451,9 +450,30 @@ SwXParagraphEnumeration* SwXParagraphEnumeration::Create(
uno::Reference< text::XText > const& xParent,
const std::shared_ptr<SwUnoCursor>& pCursor,
const CursorType eType,
- SwStartNode const*const pStartNode,
- SwTable const*const pTable)
+ SwTableBox const*const pTableBox)
{
+ SwStartNode const* pStartNode(nullptr);
+ SwTable const* pTable(nullptr);
+ assert((eType == CursorType::TableText) == (pTableBox != nullptr));
+ switch (eType)
+ {
+ case CursorType::TableText:
+ {
+ pStartNode = pTableBox->GetSttNd();
+ pTable = & pStartNode->FindTableNode()->GetTable();
+ break;
+ }
+ case CursorType::SelectionInTable:
+ {
+ SwTableNode const*const pTableNode(
+ pCursor->GetPoint()->nNode.GetNode().FindTableNode());
+ pStartNode = pTableNode;
+ pTable = & pTableNode->GetTable();
+ break;
+ }
+ default:
+ break;
+ }
return new SwXParagraphEnumerationImpl(xParent, pCursor, eType, pStartNode, pTable);
}
diff --git a/sw/source/core/unocore/unotbl.cxx b/sw/source/core/unocore/unotbl.cxx
index 527b56099cb0..9731df22cd99 100644
--- a/sw/source/core/unocore/unotbl.cxx
+++ b/sw/source/core/unocore/unotbl.cxx
@@ -1113,8 +1113,7 @@ uno::Reference<container::XEnumeration> SwXCell::createEnumeration()
pUnoCursor->Move(fnMoveForward, GoInNode);
// remember table and start node for later travelling
// (used in export of tables in tables)
- SwTable const*const pTable(&pSttNd->FindTableNode()->GetTable());
- return SwXParagraphEnumeration::Create(this, pUnoCursor, CursorType::TableText, pSttNd, pTable);
+ return SwXParagraphEnumeration::Create(this, pUnoCursor, CursorType::TableText, m_pBox);
}
uno::Type SAL_CALL SwXCell::getElementType()