summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <michael.stahl@allotropia.de>2024-03-13 18:57:21 +0100
committerMichael Stahl <michael.stahl@allotropia.de>2024-04-03 14:33:14 +0200
commitaf27d5f7b5007ee39775ef0ad4c8c3548f44f369 (patch)
tree8cbea52617e977746d2e998e4d17d649ff5e9b5e
parent403d76ad70d2f3ea5f10b11aa8881db9f32b192b (diff)
tdf#157241 sw: fix crash on RTF paste or insert of nested tables
The problem is that there are tables with only empty cell frames in the layout, which causes a crash in IsAllHiddenCell() added in commit ab7893544dc6be6dc192dffefd57cd5ddd421c35. This happens because first inner tables are created, with layout frames because the layout already exists. Then when SwNodes::TextToTable() is called for the outer table, it deletes the SwTextFrames, but not the SwTabFrames/SwCellFrames, so they remain uselessly in the layout. Delete these too, they will be recreated when the frame for the outer table is created. Also the transfer of any existing break to the outer table was missing. Change-Id: Idc2bc1d4c6572702510ae4355e4015c42770eb3e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164788 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.stahl@allotropia.de> (cherry picked from commit 62cb3b8b8d6106c6aeb073b12d84973a107182ef) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164814 Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org> (cherry picked from commit 56676a8cb6899f376d9893392700e096ad589bed)
-rw-r--r--sw/source/core/docnode/ndtbl.cxx37
1 files changed, 36 insertions, 1 deletions
diff --git a/sw/source/core/docnode/ndtbl.cxx b/sw/source/core/docnode/ndtbl.cxx
index 71874cd24a0d..62ae90129297 100644
--- a/sw/source/core/docnode/ndtbl.cxx
+++ b/sw/source/core/docnode/ndtbl.cxx
@@ -880,6 +880,35 @@ const SwTable* SwDoc::TextToTable( const SwInsertTableOptions& rInsTableOpts,
return &rNdTable;
}
+static void lcl_RemoveBreaksTable(SwTableNode & rNode, SwTableFormat *const pTableFormat)
+{
+ // delete old layout frames, new ones need to be created...
+ rNode.DelFrames(nullptr);
+
+ // remove PageBreaks/PageDesc/ColBreak
+ SwFrameFormat & rFormat(*rNode.GetTable().GetFrameFormat());
+
+ const SfxPoolItem* pItem;
+ if (SfxItemState::SET == rFormat.GetItemState(RES_BREAK, false, &pItem))
+ {
+ if (pTableFormat)
+ {
+ pTableFormat->SetFormatAttr(*pItem);
+ }
+ rFormat.ResetFormatAttr(RES_BREAK);
+ }
+
+ if (SfxItemState::SET == rFormat.GetItemState(RES_PAGEDESC, false, &pItem)
+ && static_cast<SwFormatPageDesc const*>(pItem)->GetPageDesc())
+ {
+ if (pTableFormat)
+ {
+ pTableFormat->SetFormatAttr(*pItem);
+ }
+ rFormat.ResetFormatAttr(RES_PAGEDESC);
+ }
+}
+
static void lcl_RemoveBreaks(SwContentNode & rNode, SwTableFormat *const pTableFormat)
{
// delete old layout frames, new ones need to be created...
@@ -1387,7 +1416,13 @@ SwTableNode* SwNodes::TextToTable( const SwNodes::TableRanges_t & rTableNodes,
for( nLines = 0; aNodeIndex <= rTableNodes.rbegin()->rbegin()->aEnd; ++aNodeIndex,++nLines )
{
SwNode& rNode = aNodeIndex.GetNode();
- if( rNode.IsContentNode() )
+ assert(!rNode.IsSectionNode()); // not possible in writerfilter import
+ if (rNode.IsTableNode())
+ {
+ lcl_RemoveBreaksTable(static_cast<SwTableNode&>(rNode),
+ (0 == nLines) ? pTableFormat : nullptr);
+ }
+ else if (rNode.IsContentNode())
{
lcl_RemoveBreaks(static_cast<SwContentNode&>(rNode),
(0 == nLines) ? pTableFormat : nullptr);