tdf#136740: reimplement the fix using existing m_bIsNewDoc

This reimplements the fix from commit d7c4d0d4ea83481693af3645a03b03b53e456f60.
The unit test from commit a90a324aa590a94a4091fbfadea67e0b0203767c still passes.

Change-Id: I84c61fa68b9bee679a8e82ef7b8f164297bacb5a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113665
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
(cherry picked from commit 7fc2cafbba36db25e7d0083cea162d2df08611b5)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113646
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
diff --git a/sw/source/uibase/dochdl/swdtflvr.cxx b/sw/source/uibase/dochdl/swdtflvr.cxx
index 8caa6c5..894d9049 100644
--- a/sw/source/uibase/dochdl/swdtflvr.cxx
+++ b/sw/source/uibase/dochdl/swdtflvr.cxx
@@ -32,7 +32,6 @@
#include <comphelper/fileformat.h>
#include <comphelper/processfactory.hxx>
#include <comphelper/servicehelper.hxx>
#include <comphelper/SetFlagContextHelper.hxx>
#include <comphelper/storagehelper.hxx>
#include <comphelper/string.hxx>
#include <o3tl/deleter.hxx>
@@ -2101,11 +2100,6 @@ bool SwTransferable::PasteFileContent( TransferableDataHelper& rData,
        rSh.SetChgLnk( Link<LinkParamNone*,void>() );

        const SwPosition& rInsPos = *rSh.GetCursor()->Start();

        // Reader might need to know if we are pasting into an existing document, or initializing
        // a new document; e.g. initializing document setting could be skipped when pasting.
        css::uno::ContextLayer layer(comphelper::NewFlagContext("InPasteFromClipboard"));

        SwReader aReader(*pStream, OUString(), OUString(), *rSh.GetCursor());
        rSh.SaveTableBoxContent( &rInsPos );

diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 3cc8950..a6bca50 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -22,7 +22,6 @@
#include <com/sun/star/drawing/XDrawPageSupplier.hpp>
#include <filter/msfilter/util.hxx>
#include <filter/msfilter/rtfutil.hxx>
#include <comphelper/SetFlagContextHelper.hxx>
#include <comphelper/string.hxx>
#include <tools/diagnose_ex.h>
#include <tools/globname.hxx>
@@ -267,7 +266,7 @@ RTFDocumentImpl::RTFDocumentImpl(uno::Reference<uno::XComponentContext> const& x
    , m_pMapperStream(nullptr)
    , m_aDefaultState(this)
    , m_bSkipUnknown(false)
    , m_bFirstRun(!comphelper::IsContextFlagActive("InPasteFromClipboard"))
    , m_bFirstRun(true)
    , m_bFirstRunException(false)
    , m_bNeedPap(true)
    , m_bNeedCr(false)
@@ -372,6 +371,9 @@ void RTFDocumentImpl::resolveSubstream(std::size_t nPos, Id nId, OUString const&

void RTFDocumentImpl::outputSettingsTable()
{
    // tdf#136740: do not change trarget document settings when pasting
    if (!m_bIsNewDoc)
        return;
    writerfilter::Reference<Properties>::Pointer_t pProp
        = new RTFReferenceProperties(m_aSettingsTableAttributes, m_aSettingsTableSprms);
    RTFReferenceTable::Entries_t aSettingsTableEntries;