tdf#89991 DOCX: import/export Show changes mode

handled by the optional w:revisionView OOXML setting.

Using disabled Show Changes mode, exported DOCX contains

<w:revisionView w:insDel="0" w:formatting="0"/>

as the documents exported from MSO with disabled Show Changes
and disabled Options -> Trust Center -> Trust Center Settings ->
Privacy Options -> Make hidden markup visible when opening or saving
(Note: this last setting needs also for opening the documents
really with disabled Show Changes in MSO).

Change-Id: I9f2c7df572f33838ae63185de21431102a7e139e
Reviewed-on: https://gerrit.libreoffice.org/73885
Tested-by: Jenkins
Reviewed-by: Justin Luth <justin_luth@sil.org>
Reviewed-by: László Németh <nemeth@numbertext.org>
Tested-by: László Németh <nemeth@numbertext.org>
(cherry picked from commit 0e27158c4f6a6a7676a77afb6b37dd30b3f6d100)
Reviewed-on: https://gerrit.libreoffice.org/74254
Reviewed-by: Xisco Faulí <xiscofauli@libreoffice.org>
diff --git a/sw/qa/extras/ooxmlexport/data/tdf89991.docx b/sw/qa/extras/ooxmlexport/data/tdf89991.docx
new file mode 100644
index 0000000..a074d96
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/tdf89991.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx
index 8e96d055..fde09e1 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx
@@ -1012,6 +1012,16 @@
    CPPUNIT_ASSERT(xBookmarksByName->hasByName("permission-for-group:267014232:everyone"));
}

DECLARE_OOXMLEXPORT_TEST(tdf89991_revisionView, "tdf89991.docx")
{
    // check revisionView (Show Changes) import and export
    if (xmlDocPtr pXmlSettings = parseExport("word/settings.xml"))
    {
        assertXPath(pXmlSettings, "/w:settings/w:revisionView", "insDel",     "0");
        assertXPath(pXmlSettings, "/w:settings/w:revisionView", "formatting", "0");
    }
}

DECLARE_OOXMLEXPORT_TEST(tdf122201_editUnprotectedText, "tdf122201_editUnprotectedText.odt")
{
    // get the document
diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx
index f0db640..6d6dd78 100644
--- a/sw/source/filter/ww8/docxexport.cxx
+++ b/sw/source/filter/ww8/docxexport.cxx
@@ -508,7 +508,8 @@

ErrCode DocxExport::ExportDocument_Impl()
{
    // Set the 'Track Revisions' flag in the settings structure
    // Set the 'Reviewing' flags in the settings structure
    m_aSettings.revisionView = m_bOrigShowChanges;
    m_aSettings.trackRevisions = bool( RedlineFlags::On & m_nOrigRedlineFlags );

    InitStyles();
@@ -955,6 +956,11 @@
    }

    // Track Changes
    if ( !m_aSettings.revisionView )
        pFS->singleElementNS( XML_w, XML_revisionView,
            FSNS( XML_w, XML_insDel ), "0",
            FSNS( XML_w, XML_formatting ), "0" );

    if ( m_aSettings.trackRevisions )
        pFS->singleElementNS(XML_w, XML_trackRevisions);

@@ -1662,6 +1668,7 @@
DocxSettingsData::DocxSettingsData()
: evenAndOddHeaders( false )
, defaultTabStop( 0 )
, revisionView( true )
, trackRevisions( false )
{
}
@@ -1672,6 +1679,8 @@
        return true;
    if( defaultTabStop != 0 )
        return true;
    if ( !revisionView )
        return true;
    if ( trackRevisions )
        return true;

diff --git a/sw/source/filter/ww8/docxexport.hxx b/sw/source/filter/ww8/docxexport.hxx
index 5b906de..1de037f 100644
--- a/sw/source/filter/ww8/docxexport.hxx
+++ b/sw/source/filter/ww8/docxexport.hxx
@@ -60,6 +60,7 @@
    bool hasData() const; /// returns true if there are any non-default settings (i.e. something to write)
    bool evenAndOddHeaders;
    int defaultTabStop;
    bool revisionView;      // don't show tracked changes
    bool trackRevisions;    // Should 'Track Revisions' be set
};

diff --git a/sw/source/filter/ww8/wrtww8.cxx b/sw/source/filter/ww8/wrtww8.cxx
index 09bf616..bf8fb46 100644
--- a/sw/source/filter/ww8/wrtww8.cxx
+++ b/sw/source/filter/ww8/wrtww8.cxx
@@ -3198,6 +3198,10 @@
    m_aFrames = GetFrames( *m_pDoc, bWriteAll? nullptr : m_pOrigPam );

    m_nOrigRedlineFlags = m_pDoc->getIDocumentRedlineAccess().GetRedlineFlags();

    SwRootFrame const*const pLayout(m_pDoc->getIDocumentLayoutAccess().GetCurrentLayout());
    m_bOrigShowChanges = pLayout == nullptr || !pLayout->IsHideRedlines();

    if ( !m_pDoc->getIDocumentRedlineAccess().GetRedlineTable().empty() )
    {
        //restored to original state by SwWriter::Write
@@ -3595,6 +3599,7 @@
    , m_nUniqueList(0)
    , m_nHdFtIndex(0)
    , m_nOrigRedlineFlags(RedlineFlags::NONE)
    , m_bOrigShowChanges(true)
    , m_pCurrentPageDesc(nullptr)
    , m_bPrevTextNodeIsEmpty(false)
    , m_bFirstTOCNodeWithSection(false)
diff --git a/sw/source/filter/ww8/wrtww8.hxx b/sw/source/filter/ww8/wrtww8.hxx
index 1be7099..f72302f 100644
--- a/sw/source/filter/ww8/wrtww8.hxx
+++ b/sw/source/filter/ww8/wrtww8.hxx
@@ -480,6 +480,7 @@
    unsigned int m_nHdFtIndex;

    RedlineFlags m_nOrigRedlineFlags;   ///< Remember the original redline mode
    bool m_bOrigShowChanges;            ///< Remember the original Show Changes mode

public:
    /* implicit bookmark vector containing pairs of node indexes and bookmark names */
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx
index 2885188..149648c 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -180,6 +180,7 @@
#include <memory>
#include <fchrfmt.hxx>
#include <redline.hxx>
#include <DocumentRedlineManager.hxx>

#define TWIPS_PER_PIXEL 15

@@ -1877,10 +1878,9 @@
            RedlineFlags eMode = pDocShell->GetDoc()->getIDocumentRedlineAccess().GetRedlineFlags();
            if(WID_DOC_CHANGES_SHOW == pEntry->nWID)
            {
                eMode &= ~RedlineFlags(RedlineFlags::ShowInsert | RedlineFlags::ShowDelete);
                eMode |= RedlineFlags::ShowInsert;
                if( bSet )
                    eMode |= RedlineFlags::ShowDelete;
                eMode |= RedlineFlags(RedlineFlags::ShowInsert | RedlineFlags::ShowDelete);
                if( !bSet )
                    pDocShell->GetDoc()->GetDocumentRedlineManager().SetHideRedlines(true);
            }
            else if(WID_DOC_CHANGES_RECORD == pEntry->nWID)
            {
diff --git a/writerfilter/source/dmapper/SettingsTable.cxx b/writerfilter/source/dmapper/SettingsTable.cxx
index 76601e4..609173e 100644
--- a/writerfilter/source/dmapper/SettingsTable.cxx
+++ b/writerfilter/source/dmapper/SettingsTable.cxx
@@ -234,6 +234,8 @@
    int                 m_nDefaultTabStop;

    bool                m_bRecordChanges;
    bool                m_bShowInsDelChanges;
    bool                m_bShowFormattingChanges;
    bool                m_bLinkStyles;
    sal_Int16           m_nZoomFactor;
    sal_Int16 m_nZoomType = 0;
@@ -263,6 +265,8 @@
    SettingsTable_Impl() :
      m_nDefaultTabStop( 720 ) //default is 1/2 in
    , m_bRecordChanges(false)
    , m_bShowInsDelChanges(true)
    , m_bShowFormattingChanges(true)
    , m_bLinkStyles(false)
    , m_nZoomFactor(0)
    , m_nView(0)
@@ -373,6 +377,12 @@
    case NS_ooxml::LN_AG_Password_salt: // 92036
        m_pImpl->m_DocumentProtection.m_sSalt = sStringValue;
        break;
    case NS_ooxml::LN_CT_TrackChangesView_insDel:
        m_pImpl->m_bShowInsDelChanges = (nIntValue != 0);
        break;
    case NS_ooxml::LN_CT_TrackChangesView_formatting:
        m_pImpl->m_bShowFormattingChanges = (nIntValue != 0);
        break;
    default:
    {
#ifdef DBG_UTIL
@@ -440,6 +450,9 @@
        m_pImpl->m_bRecordChanges = bool(rSprm.getValue( )->getInt( ) );
    }
    break;
    case NS_ooxml::LN_CT_Settings_revisionView:
        resolveSprmProps(*this, rSprm);
        break;
    case NS_ooxml::LN_CT_Settings_documentProtection:
        resolveSprmProps(*this, rSprm);
        break;
@@ -633,6 +646,10 @@
{
    uno::Reference< beans::XPropertySet> xDocProps( xDoc, uno::UNO_QUERY );

    // Show changes value
    if (xDocProps.is())
        xDocProps->setPropertyValue("ShowChanges", uno::makeAny( m_pImpl->m_bShowInsDelChanges || m_pImpl->m_bShowFormattingChanges ) );

    // Record changes value
    if (xDocProps.is())
        xDocProps->setPropertyValue("RecordChanges", uno::makeAny( m_pImpl->m_bRecordChanges ) );