sw/inc/strings.hrc | 1 sw/qa/extras/ooxmlexport/data/tdf125338.docm |binary sw/qa/extras/ooxmlexport/ooxmlexport9.cxx | 10 ++++++- sw/source/filter/ww8/docxexport.cxx | 3 +- sw/source/filter/ww8/docxexportfilter.cxx | 35 +++++++++++++++++++++++---- 5 files changed, 43 insertions(+), 6 deletions(-)
New commits: commit 39a09050d309de7ebcf4630cc12cdffa2ca4a654 Author: offtkp <parisop...@gmail.com> AuthorDate: Wed Dec 14 22:21:34 2022 +0200 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Sat Jan 7 16:05:58 2023 +0000 tdf#125338 Do not export macros when saving as .docx Docx files that have macros should be saved as .docm. Now displays a warning that macros won't be saved if exporting a .docm as a .docx and doesn't export them. Change-Id: I178855baa6c0a7d32fd9b00c83a817230b33a1a1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144197 Tested-by: Jenkins Reviewed-by: Justin Luth <jl...@mail.com> (cherry picked from commit cbca5617387aaa39c9ee86272166bb3df7874b25) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144811 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/sw/inc/strings.hrc b/sw/inc/strings.hrc index b4b03968a1eb..59fe112fecba 100644 --- a/sw/inc/strings.hrc +++ b/sw/inc/strings.hrc @@ -331,6 +331,7 @@ #define STR_SOUTH NC_("STR_SOUTH", "South") #define STR_SUM NC_("STR_SUM", "Sum") #define STR_INVALID_AUTOFORMAT_NAME NC_("STR_INVALID_AUTOFORMAT_NAME", "You have entered an invalid name.\nThe desired AutoFormat could not be created. \nTry again using a different name.") +#define STR_CANT_SAVE_MACROS NC_("STR_CANT_SAVE_MACROS", "This document has macros, but macros will not be saved in this file format.") #define STR_NUMERIC NC_("STR_NUMERIC", "Numeric") #define STR_ROW NC_("STR_ROW", "Rows") #define STR_COL NC_("STR_COL", "Column") diff --git a/sw/qa/extras/ooxmlexport/data/tdf125338.docm b/sw/qa/extras/ooxmlexport/data/tdf125338.docm new file mode 100644 index 000000000000..44e943531d30 Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf125338.docm differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx index 99d4b0112a60..1b97e846f1ef 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx @@ -139,7 +139,7 @@ DECLARE_OOXMLEXPORT_TEST(testTdf109063, "tdf109063.docx") CPPUNIT_ASSERT_EQUAL(0, getShapes()); } -CPPUNIT_TEST_FIXTURE(Test, testTdf108269) +CPPUNIT_TEST_FIXTURE(DocmTest, testTdf108269) { loadAndReload("tdf108269.docm"); uno::Reference<packages::zip::XZipFileAccess2> xNameAccess = packages::zip::ZipFileAccess::createWithURL(comphelper::getComponentContext(m_xSFactory), maTempFile.GetURL()); @@ -149,6 +149,14 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf108269) CPPUNIT_ASSERT(xNameAccess->hasByName("word/vbaData.xml")); } +CPPUNIT_TEST_FIXTURE(Test, testTdf125338) +{ + loadAndSave("tdf125338.docm"); + uno::Reference<packages::zip::XZipFileAccess2> xNameAccess = packages::zip::ZipFileAccess::createWithURL(comphelper::getComponentContext(m_xSFactory), maTempFile.GetURL()); + // docm files should not retain macros when saved as docx + CPPUNIT_ASSERT(!xNameAccess->hasByName("word/vbaProject.bin")); +} + DECLARE_OOXMLEXPORT_TEST(testTdf92045, "tdf92045.docx") { // This was true, <w:effect w:val="none"/> resulted in setting the blinking font effect. diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx index 74d081baf244..d5bc243d5c2e 100644 --- a/sw/source/filter/ww8/docxexport.cxx +++ b/sw/source/filter/ww8/docxexport.cxx @@ -538,7 +538,8 @@ ErrCode DocxExport::ExportDocument_Impl() WriteEmbeddings(); - WriteVBA(); + if (m_bDocm) + WriteVBA(); m_aLinkedTextboxesHelper.clear(); //final cleanup m_pStyles.reset(); diff --git a/sw/source/filter/ww8/docxexportfilter.cxx b/sw/source/filter/ww8/docxexportfilter.cxx index 08308ca9398c..5ffd32f4c25b 100644 --- a/sw/source/filter/ww8/docxexportfilter.cxx +++ b/sw/source/filter/ww8/docxexportfilter.cxx @@ -63,6 +63,37 @@ bool DocxExportFilter::exportDocument() pViewShell->GetPostItMgr()->UpdateDataOnActiveSidebarWin(); } + OUString aFilterName; + auto& rMediaDescriptor = getMediaDescriptor(); + rMediaDescriptor[utl::MediaDescriptor::PROP_FILTERNAME] >>= aFilterName; + bool bDocm = aFilterName.endsWith("VBA"); + + if (!bDocm) + { + // Check whether application is in headless mode + if (!Application::IsHeadlessModeEnabled()) + { + uno::Reference<document::XStorageBasedDocument> xStorageBasedDocument( + pDoc->GetDocShell()->GetBaseModel(), uno::UNO_QUERY); + if (xStorageBasedDocument.is()) + { + uno::Reference<embed::XStorage> xDocumentStorage = + xStorageBasedDocument->getDocumentStorage(); + if (xDocumentStorage.is() && xDocumentStorage->hasByName(u"_MS_VBA_Macros")) + { + // Let user know that macros won't be saved in this format + std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog( + nullptr, + VclMessageType::Warning, VclButtonsType::OkCancel, + SwResId(STR_CANT_SAVE_MACROS)) + ); + if (xBox->run() == RET_CANCEL) + return false; + } + } + } + } + // get SwPaM* // FIXME so far we get SwPaM for the entire document; probably we should // be able to output just the selection as well - though no idea how to @@ -75,10 +106,6 @@ bool DocxExportFilter::exportDocument() pCurPam->SetMark(); *pCurPam->GetPoint() = *aPam.Start(); - OUString aFilterName; - getMediaDescriptor()[utl::MediaDescriptor::PROP_FILTERNAME] >>= aFilterName; - bool bDocm = aFilterName.endsWith("VBA"); - // export the document // (in a separate block so that it's destructed before the commit) {