From 43816e78744afdddd5116d8d598fcdd2f3e8767c Mon Sep 17 00:00:00 2001 From: László Németh Date: Mon, 30 Jul 2018 21:22:23 +0200 Subject: tdf#37223 insert OLE tables in text tables as native text tables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit to solve the long-standing problem of Calc/Writer integration, ie. now Calc table data are inserted cell by cell in Writer text tables instead of putting an unwanted second table over the original, as an OLE object. First insert the OLE table as a nested native table using paste special as RTF, and cut and paste that to get a native table insertion, removing also the temporary nested table. This fix has got correct undo, but unfortunately, also a small flash during insertion by the temporary nested table. I've tried to fix that by LockView and LockModify, but it seems, they don't help. Note: the planned solution mentioned in the original OOo issue (reported in 2004) suggested to use a hidden temporary document, but that has got poblems with clipboard usage. Change-Id: I49253239f1878bce5fc4c93494f997ed37101a1c Reviewed-on: https://gerrit.libreoffice.org/58346 Tested-by: Jenkins Reviewed-by: László Németh (cherry picked from commit 80d3d1044a1ad921bff990e2c4bb4dbf7c0a35c6) --- sw/source/uibase/dochdl/swdtflvr.cxx | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'sw/source/uibase/dochdl') diff --git a/sw/source/uibase/dochdl/swdtflvr.cxx b/sw/source/uibase/dochdl/swdtflvr.cxx index e82f6d95cb70..a89182f0f8ee 100644 --- a/sw/source/uibase/dochdl/swdtflvr.cxx +++ b/sw/source/uibase/dochdl/swdtflvr.cxx @@ -1154,9 +1154,11 @@ bool SwTransferable::Paste(SwWrtShell& rSh, TransferableDataHelper& rData, RndSt &nActionFlags ); } + bool bInsertOleTable = ( EXCHG_OUT_ACTION_INSERT_OLE == nAction && ( rData.HasFormat( SotClipboardFormatId::SYLK ) || + rData.HasFormat( SotClipboardFormatId::SYLK_BIGCAPS ) ) ); + // content of 1-cell tables is inserted as simple text - if( EXCHG_OUT_ACTION_INSERT_OLE == nAction && ( rData.HasFormat( SotClipboardFormatId::SYLK ) || - rData.HasFormat( SotClipboardFormatId::SYLK_BIGCAPS ) ) ) + if (bInsertOleTable) { OUString aExpand; if( rData.GetString( SotClipboardFormatId::STRING, aExpand )) @@ -1172,8 +1174,11 @@ bool SwTransferable::Paste(SwWrtShell& rSh, TransferableDataHelper& rData, RndSt } } + bool bInsertOleTableInTable = (bInsertOleTable && !bSingleCellTable && + (rSh.GetDoc()->IsIdxInTable(rSh.GetCursor()->GetNode()) != nullptr)); + // special case for tables from draw application or 1-cell tables - if( EXCHG_OUT_ACTION_INSERT_DRAWOBJ == nAction || bSingleCellTable ) + if( EXCHG_OUT_ACTION_INSERT_DRAWOBJ == nAction || bSingleCellTable || bInsertOleTableInTable ) { if( rData.HasFormat( SotClipboardFormatId::RTF ) ) { @@ -1187,6 +1192,26 @@ bool SwTransferable::Paste(SwWrtShell& rSh, TransferableDataHelper& rData, RndSt } } + // tdf#37223 insert OLE table in text tables as a native text table + // (first as an RTF nested table, and cut and paste that to get a + // native table insertion, removing also the temporary nested table) + // TODO set a working view lock to avoid of showing the temporary nested table for a moment + if (bInsertOleTableInTable && EXCHG_OUT_ACTION_INSERT_STRING == nAction) + { + bool bPasted = SwTransferable::PasteData( rData, rSh, nAction, nActionFlags, nFormat, + nDestination, false, false, nullptr, 0, false, nAnchorType ); + if (bPasted && rSh.DoesUndo()) + { + SfxDispatcher* pDispatch = rSh.GetView().GetViewFrame()->GetDispatcher(); + pDispatch->Execute(FN_PREV_TABLE, SfxCallMode::SYNCHRON); + pDispatch->Execute(FN_TABLE_SELECT_ALL, SfxCallMode::SYNCHRON); + pDispatch->Execute(SID_COPY, SfxCallMode::SYNCHRON); + pDispatch->Execute(SID_UNDO, SfxCallMode::SYNCHRON); + pDispatch->Execute(SID_PASTE, SfxCallMode::SYNCHRON); + } + return bPasted; + } + return EXCHG_INOUT_ACTION_NONE != nAction && SwTransferable::PasteData( rData, rSh, nAction, nActionFlags, nFormat, nDestination, false, false, nullptr, 0, false, nAnchorType ); -- cgit v1.2.3