cui/source/inc/cuires.hrc | 4 cui/source/options/optfltr.cxx | 55 ++++ cui/source/options/optfltr.hxx | 4 cui/source/options/optfltr.src | 8 embeddedobj/CppunitTest_embeddedobj_general.mk | 44 +++ embeddedobj/Library_embobj.mk | 4 embeddedobj/Module_embeddedobj.mk | 6 embeddedobj/qa/cppunit/data/insert-file-config.doc |binary embeddedobj/qa/cppunit/data/insert-file-config.pdf |binary embeddedobj/qa/cppunit/data/insert-file-config.vsdx |binary embeddedobj/qa/cppunit/general.cxx | 156 +++++++++++++ embeddedobj/source/general/xcreator.cxx | 53 ++++ include/unotest/bootstrapfixturebase.hxx | 15 + include/unotools/fltrcfg.hxx | 3 officecfg/registry/schema/org/openoffice/Office/Common.xcs | 24 ++ sw/inc/ndole.hxx | 4 sw/source/core/docnode/node.cxx | 4 sw/source/core/ole/ndole.cxx | 26 ++ unotools/source/config/fltrcfg.cxx | 21 + 19 files changed, 422 insertions(+), 9 deletions(-)
New commits: commit e810ec9a3ac8825f42ec7276de01a210e82c717f Author: Miklos Vajna <[email protected]> AuthorDate: Thu Aug 15 15:47:42 2019 +0200 Commit: Miklos Vajna <[email protected]> CommitDate: Fri Aug 16 13:53:06 2019 +0200 embeddedobj: allow controlling if PDF documents are converted to Draw or not This is a bit custom, since it's not a Microsoft filter. At the moment this affects only Insert -> Object -> OLE Object -> from file. Reviewed-on: https://gerrit.libreoffice.org/77520 Reviewed-by: Miklos Vajna <[email protected]> Tested-by: Jenkins (cherry picked from commit bdfa6b678bc0cc22f983a0c23187a8ba9d2e6730) Conflicts: cui/inc/strings.hrc cui/source/options/optfltr.cxx cui/source/options/optfltr.hxx Change-Id: If79602742a533db1b04e11a90890f8768186046d diff --git a/cui/source/inc/cuires.hrc b/cui/source/inc/cuires.hrc index 891468779f3f..2f105444aa60 100644 --- a/cui/source/inc/cuires.hrc +++ b/cui/source/inc/cuires.hrc @@ -363,6 +363,8 @@ #define RID_SVXSTR_CHG_VISIO (RID_SVX_START + 1257) +#define RID_SVXSTR_CHG_PDF (RID_SVX_START + 1273) + #define RID_SVXSTR_PPI (RID_SVX_START + 1252) #define RID_SVXSTR_SPELL (RID_SVX_START + 1253) #define RID_SVXSTR_HYPH (RID_SVX_START + 1254) diff --git a/cui/source/options/optfltr.cxx b/cui/source/options/optfltr.cxx index 8f0da2dbbcaf..e09d6c41dd0e 100644 --- a/cui/source/options/optfltr.cxx +++ b/cui/source/options/optfltr.cxx @@ -20,6 +20,7 @@ #include <o3tl/make_unique.hxx> #include <unotools/moduleoptions.hxx> #include <unotools/fltrcfg.hxx> +#include <officecfg/Office/Common.hxx> #include "optfltr.hxx" #include <cuires.hrc> #include "helpid.hrc" @@ -35,6 +36,7 @@ enum MSFltrPg2_CheckBoxEntries { Impress, SmartArt, Visio, + PDF, InvalidCBEntry }; @@ -152,6 +154,7 @@ OfaMSFilterTabPage2::OfaMSFilterTabPage2( vcl::Window* pParent, const SfxItemSet sChgToFromImpress(CuiResId(RID_SVXSTR_CHG_IMPRESS)), sChgToFromSmartArt(CuiResId(RID_SVXSTR_CHG_SMARTART)), sChgToFromVisio(CuiResId(RID_SVXSTR_CHG_VISIO)), + sChgToFromPDF(CuiResId(RID_SVXSTR_CHG_PDF)), pCheckButtonData(nullptr) { get(m_pCheckLBContainer, "checklbcontainer"); @@ -255,6 +258,24 @@ bool OfaMSFilterTabPage2::FillItemSet( SfxItemSet* ) } } } + SvTreeListEntry* pPDFEntry = GetEntry4Type(MSFltrPg2_CheckBoxEntries::PDF); + bool bPDFCheck = false; + if (pPDFEntry) + { + SvLBoxButton& rItem = static_cast<SvLBoxButton&>(pPDFEntry->GetItem( 1 )); + if (rItem.GetType() == SvLBoxItemType::Button) + { + SvItemStateFlags nButtonFlags = rItem.GetButtonFlags(); + bPDFCheck = SvButtonState::Checked == SvLBoxButtonData::ConvertToButtonState( nButtonFlags ); + } + } + if (bPDFCheck != officecfg::Office::Common::Filter::Adobe::Import::PDFToDraw::get()) + { + std::shared_ptr<comphelper::ConfigurationChanges> pBatch( + comphelper::ConfigurationChanges::create()); + officecfg::Office::Common::Filter::Adobe::Import::PDFToDraw::set(bPDFCheck, pBatch); + pBatch->commit(); + } if( aHighlightingRB->IsValueChangedFromSaved() ) { @@ -287,7 +308,10 @@ void OfaMSFilterTabPage2::Reset( const SfxItemSet* ) InsertEntry( sChgToFromImpress, static_cast< sal_IntPtr >( Impress ) ); InsertEntry( sChgToFromSmartArt, static_cast< sal_IntPtr >( SmartArt ), false ); if (aModuleOpt.IsModuleInstalled(SvtModuleOptions::EModule::DRAW)) + { InsertEntry(sChgToFromVisio, static_cast< sal_IntPtr >( Visio ), false); + InsertEntry(sChgToFromPDF, static_cast< sal_IntPtr >(PDF), false); + } static struct ChkCBoxEntries{ MSFltrPg2_CheckBoxEntries eType; @@ -303,6 +327,7 @@ void OfaMSFilterTabPage2::Reset( const SfxItemSet* ) { Impress, &SvtFilterOptions::IsImpress2PowerPoint }, { SmartArt, &SvtFilterOptions::IsSmartArt2Shape }, { Visio, &SvtFilterOptions::IsVisio2Draw }, + { PDF, nullptr }, { InvalidCBEntry, nullptr } }; @@ -314,10 +339,23 @@ void OfaMSFilterTabPage2::Reset( const SfxItemSet* ) SvTreeListEntry* pEntry = GetEntry4Type( static_cast< sal_IntPtr >( pArr->eType ) ); if( pEntry ) { + if (pArr->eType == MSFltrPg2_CheckBoxEntries::PDF) + { + nCol = 1; + } SvLBoxButton& rItem = static_cast<SvLBoxButton&>(pEntry->GetItem( nCol )); if (rItem.GetType() == SvLBoxItemType::Button) { - if( (rOpt.*pArr->FnIs)() ) + bool bCheck = false; + if (pArr->eType != MSFltrPg2_CheckBoxEntries::PDF) + { + bCheck = (rOpt.*pArr->FnIs)(); + } + else + { + bCheck = officecfg::Office::Common::Filter::Adobe::Import::PDFToDraw::get(); + } + if( bCheck ) rItem.SetStateChecked(); else rItem.SetStateUnchecked(); diff --git a/cui/source/options/optfltr.hxx b/cui/source/options/optfltr.hxx index 1349863d03d0..18aca2f8c9bc 100644 --- a/cui/source/options/optfltr.hxx +++ b/cui/source/options/optfltr.hxx @@ -82,7 +82,8 @@ class OfaMSFilterTabPage2 : public SfxTabPage sChgToFromCalc, sChgToFromImpress, sChgToFromSmartArt, - sChgToFromVisio; + sChgToFromVisio, + sChgToFromPDF; SvLBoxButtonData* pCheckButtonData; VclPtr<RadioButton> aHighlightingRB; diff --git a/cui/source/options/optfltr.src b/cui/source/options/optfltr.src index 8f64efbad667..2795fd4c5fa0 100644 --- a/cui/source/options/optfltr.src +++ b/cui/source/options/optfltr.src @@ -51,5 +51,9 @@ String RID_SVXSTR_CHG_VISIO { Text [ en-US ] = "Visio to %PRODUCTNAME Draw or reverse"; }; +String RID_SVXSTR_CHG_PDF +{ + Text [ en-US ] = "PDF to %PRODUCTNAME Draw or reverse"; +}; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/embeddedobj/qa/cppunit/data/insert-file-config.pdf b/embeddedobj/qa/cppunit/data/insert-file-config.pdf new file mode 100644 index 000000000000..6302457402fe Binary files /dev/null and b/embeddedobj/qa/cppunit/data/insert-file-config.pdf differ diff --git a/embeddedobj/qa/cppunit/general.cxx b/embeddedobj/qa/cppunit/general.cxx index bbab17440fe3..ba862d3a86f0 100644 --- a/embeddedobj/qa/cppunit/general.cxx +++ b/embeddedobj/qa/cppunit/general.cxx @@ -118,6 +118,39 @@ CPPUNIT_TEST_FIXTURE(EmbeddedobjGeneralTest, testInsertFileConfigVsdx) CPPUNIT_ASSERT(!xObject.is()); } +CPPUNIT_TEST_FIXTURE(EmbeddedobjGeneralTest, testInsertFileConfigPdf) +{ + // Explicitly disable Word->Writer mapping for this test. + std::shared_ptr<comphelper::ConfigurationChanges> pBatch( + comphelper::ConfigurationChanges::create()); + officecfg::Office::Common::Filter::Adobe::Import::PDFToDraw::set(false, pBatch); + pBatch->commit(); + comphelper::ScopeGuard g([]() { + std::shared_ptr<comphelper::ConfigurationChanges> pBatchReset( + comphelper::ConfigurationChanges::create()); + officecfg::Office::Common::Filter::Adobe::Import::PDFToDraw::set(true, pBatchReset); + pBatchReset->commit(); + }); + getComponent().set( + loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument")); + + // Insert a PDF file as an embedded object. + uno::Reference<embed::XStorage> xStorage = comphelper::OStorageHelper::GetTemporaryStorage(); + comphelper::EmbeddedObjectContainer aContainer(xStorage); + OUString aFileName + = m_directories.getURLFromSrc("embeddedobj/qa/cppunit/data/insert-file-config.pdf"); + uno::Sequence<beans::PropertyValue> aMedium{ comphelper::makePropertyValue("URL", aFileName) }; + OUString aName("Object 1"); + uno::Reference<embed::XEmbeddedObject> xObject + = aContainer.InsertEmbeddedObject(aMedium, aName); + + // Make sure that the insertion fails: + // 1) the user explicitly requested that the data is not loaded into Writer + // 2) this is non-Windows, so OLE embedding is not an option + // so silently still loading the data into Writer would be bad. + CPPUNIT_ASSERT(!xObject.is()); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/embeddedobj/source/general/xcreator.cxx b/embeddedobj/source/general/xcreator.cxx index ccb014e3de56..88cd774a9e30 100644 --- a/embeddedobj/source/general/xcreator.cxx +++ b/embeddedobj/source/general/xcreator.cxx @@ -250,6 +250,13 @@ static OUString HandleFilter(const uno::Reference<uno::XComponentContext>& xComp aRet.clear(); } } + if (!officecfg::Office::Common::Filter::Adobe::Import::PDFToDraw::get(xComponentContext)) + { + if (rFilter == "draw_pdf_import") + { + aRet.clear(); + } + } return aRet; } diff --git a/officecfg/registry/schema/org/openoffice/Office/Common.xcs b/officecfg/registry/schema/org/openoffice/Office/Common.xcs index 83437812f9c0..950016363dae 100644 --- a/officecfg/registry/schema/org/openoffice/Office/Common.xcs +++ b/officecfg/registry/schema/org/openoffice/Office/Common.xcs @@ -4006,6 +4006,23 @@ <desc>Specifies default settings of Microsoft-, Graphic- and HTML filters.</desc> </info> + <group oor:name="Adobe"> + <info> + <desc>Specifies default settings of Adobe filters.</desc> + </info> + <group oor:name="Import"> + <info> + <desc>Specifies default settings of Adobe import filters.</desc> + </info> + <prop oor:name="PDFToDraw" oor:type="xs:boolean" oor:nillable="false"> + <info> + <desc>Specifies if convertible PDF OLE objects are converted + into Draw objects.</desc> + </info> + <value>true</value> + </prop> + </group> + </group> <group oor:name="Microsoft"> <info> <desc>Specifies default settings of Microsoft filters.</desc> commit 17de3c3b91f70cf9381ac36f6933f178ae0891eb Author: Miklos Vajna <[email protected]> AuthorDate: Thu Aug 15 10:55:53 2019 +0200 Commit: Miklos Vajna <[email protected]> CommitDate: Fri Aug 16 12:23:02 2019 +0200 embeddedobj: allow controlling if Visio documents are converted to Draw or not At the moment this affects only Insert -> Object -> OLE Object -> from file. Reviewed-on: https://gerrit.libreoffice.org/77489 Reviewed-by: Miklos Vajna <[email protected]> Tested-by: Jenkins (cherry picked from commit 5827e30109b683cb74efa21d154e5219fe9e2a0c) Conflicts: cui/inc/strings.hrc cui/source/options/optfltr.cxx cui/source/options/optfltr.hxx include/unotools/fltrcfg.hxx officecfg/registry/schema/org/openoffice/Office/Common.xcs unotools/source/config/fltrcfg.cxx Change-Id: I8d1c6456481610491916e3be3766b0bb04dfa296 diff --git a/cui/source/inc/cuires.hrc b/cui/source/inc/cuires.hrc index 599063cbca62..891468779f3f 100644 --- a/cui/source/inc/cuires.hrc +++ b/cui/source/inc/cuires.hrc @@ -361,6 +361,8 @@ #define RID_SVXSTR_CHG_SMARTART (RID_SVX_START + 1251) +#define RID_SVXSTR_CHG_VISIO (RID_SVX_START + 1257) + #define RID_SVXSTR_PPI (RID_SVX_START + 1252) #define RID_SVXSTR_SPELL (RID_SVX_START + 1253) #define RID_SVXSTR_HYPH (RID_SVX_START + 1254) diff --git a/cui/source/options/optfltr.cxx b/cui/source/options/optfltr.cxx index 8723c18e77be..8f0da2dbbcaf 100644 --- a/cui/source/options/optfltr.cxx +++ b/cui/source/options/optfltr.cxx @@ -34,6 +34,7 @@ enum MSFltrPg2_CheckBoxEntries { Calc, Impress, SmartArt, + Visio, InvalidCBEntry }; @@ -150,6 +151,7 @@ OfaMSFilterTabPage2::OfaMSFilterTabPage2( vcl::Window* pParent, const SfxItemSet sChgToFromCalc(CuiResId(RID_SVXSTR_CHG_CALC)), sChgToFromImpress(CuiResId(RID_SVXSTR_CHG_IMPRESS)), sChgToFromSmartArt(CuiResId(RID_SVXSTR_CHG_SMARTART)), + sChgToFromVisio(CuiResId(RID_SVXSTR_CHG_VISIO)), pCheckButtonData(nullptr) { get(m_pCheckLBContainer, "checklbcontainer"); @@ -224,6 +226,8 @@ bool OfaMSFilterTabPage2::FillItemSet( SfxItemSet* ) &SvtFilterOptions::SetImpress2PowerPoint }, { SmartArt, &SvtFilterOptions::IsSmartArt2Shape, &SvtFilterOptions::SetSmartArt2Shape }, + { MSFltrPg2_CheckBoxEntries::Visio, &SvtFilterOptions::IsVisio2Draw, + &SvtFilterOptions::SetVisio2Draw }, { InvalidCBEntry, nullptr, nullptr } }; @@ -245,6 +249,10 @@ bool OfaMSFilterTabPage2::FillItemSet( SfxItemSet* ) if( bCheck != (rOpt.*pArr->FnIs)() ) (rOpt.*pArr->FnSet)( bCheck ); } + if (pArr->eType == MSFltrPg2_CheckBoxEntries::SmartArt) + { + bFirst = !bFirst; + } } } @@ -278,6 +286,8 @@ void OfaMSFilterTabPage2::Reset( const SfxItemSet* ) if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::EModule::IMPRESS ) ) InsertEntry( sChgToFromImpress, static_cast< sal_IntPtr >( Impress ) ); InsertEntry( sChgToFromSmartArt, static_cast< sal_IntPtr >( SmartArt ), false ); + if (aModuleOpt.IsModuleInstalled(SvtModuleOptions::EModule::DRAW)) + InsertEntry(sChgToFromVisio, static_cast< sal_IntPtr >( Visio ), false); static struct ChkCBoxEntries{ MSFltrPg2_CheckBoxEntries eType; @@ -292,6 +302,7 @@ void OfaMSFilterTabPage2::Reset( const SfxItemSet* ) { Impress, &SvtFilterOptions::IsPowerPoint2Impress }, { Impress, &SvtFilterOptions::IsImpress2PowerPoint }, { SmartArt, &SvtFilterOptions::IsSmartArt2Shape }, + { Visio, &SvtFilterOptions::IsVisio2Draw }, { InvalidCBEntry, nullptr } }; @@ -312,6 +323,10 @@ void OfaMSFilterTabPage2::Reset( const SfxItemSet* ) rItem.SetStateUnchecked(); m_pCheckLB->InvalidateEntry( pEntry ); } + if (pArr->eType == MSFltrPg2_CheckBoxEntries::SmartArt) + { + bFirst = !bFirst; + } } } m_pCheckLB->SetUpdateMode( true ); diff --git a/cui/source/options/optfltr.hxx b/cui/source/options/optfltr.hxx index 4e28a04ad883..1349863d03d0 100644 --- a/cui/source/options/optfltr.hxx +++ b/cui/source/options/optfltr.hxx @@ -81,7 +81,8 @@ class OfaMSFilterTabPage2 : public SfxTabPage sChgToFromWriter, sChgToFromCalc, sChgToFromImpress, - sChgToFromSmartArt; + sChgToFromSmartArt, + sChgToFromVisio; SvLBoxButtonData* pCheckButtonData; VclPtr<RadioButton> aHighlightingRB; diff --git a/cui/source/options/optfltr.src b/cui/source/options/optfltr.src index 41b378c05342..8f64efbad667 100644 --- a/cui/source/options/optfltr.src +++ b/cui/source/options/optfltr.src @@ -47,5 +47,9 @@ String RID_SVXSTR_CHG_SMARTART { Text [ en-US ] = "SmartArt to %PRODUCTNAME shapes or reverse"; }; +String RID_SVXSTR_CHG_VISIO +{ + Text [ en-US ] = "Visio to %PRODUCTNAME Draw or reverse"; +}; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/embeddedobj/qa/cppunit/data/insert-file-config.vsdx b/embeddedobj/qa/cppunit/data/insert-file-config.vsdx new file mode 100644 index 000000000000..bb3a129cfa7b Binary files /dev/null and b/embeddedobj/qa/cppunit/data/insert-file-config.vsdx differ diff --git a/embeddedobj/qa/cppunit/general.cxx b/embeddedobj/qa/cppunit/general.cxx index 43b8dd9f4c1b..bbab17440fe3 100644 --- a/embeddedobj/qa/cppunit/general.cxx +++ b/embeddedobj/qa/cppunit/general.cxx @@ -85,6 +85,39 @@ CPPUNIT_TEST_FIXTURE(EmbeddedobjGeneralTest, testInsertFileConfig) CPPUNIT_ASSERT(!xObject.is()); } +CPPUNIT_TEST_FIXTURE(EmbeddedobjGeneralTest, testInsertFileConfigVsdx) +{ + // Explicitly disable Word->Writer mapping for this test. + std::shared_ptr<comphelper::ConfigurationChanges> pBatch( + comphelper::ConfigurationChanges::create()); + officecfg::Office::Common::Filter::Microsoft::Import::VisioToDraw::set(false, pBatch); + pBatch->commit(); + comphelper::ScopeGuard g([]() { + std::shared_ptr<comphelper::ConfigurationChanges> pBatchReset( + comphelper::ConfigurationChanges::create()); + officecfg::Office::Common::Filter::Microsoft::Import::VisioToDraw::set(true, pBatchReset); + pBatchReset->commit(); + }); + getComponent().set( + loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument")); + + // Insert a file as an embedded object. + uno::Reference<embed::XStorage> xStorage = comphelper::OStorageHelper::GetTemporaryStorage(); + comphelper::EmbeddedObjectContainer aContainer(xStorage); + OUString aFileName + = m_directories.getURLFromSrc("embeddedobj/qa/cppunit/data/insert-file-config.vsdx"); + uno::Sequence<beans::PropertyValue> aMedium{ comphelper::makePropertyValue("URL", aFileName) }; + OUString aName("Object 1"); + uno::Reference<embed::XEmbeddedObject> xObject + = aContainer.InsertEmbeddedObject(aMedium, aName); + + // Make sure that the insertion fails: + // 1) the user explicitly requested that the data is not loaded into Writer + // 2) this is non-Windows, so OLE embedding is not an option + // so silently still loading the data into Writer would be bad. + CPPUNIT_ASSERT(!xObject.is()); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/embeddedobj/source/general/xcreator.cxx b/embeddedobj/source/general/xcreator.cxx index d9bc8d7869c0..ccb014e3de56 100644 --- a/embeddedobj/source/general/xcreator.cxx +++ b/embeddedobj/source/general/xcreator.cxx @@ -243,6 +243,13 @@ static OUString HandleFilter(const uno::Reference<uno::XComponentContext>& xComp aRet.clear(); } } + if (!officecfg::Office::Common::Filter::Microsoft::Import::VisioToDraw::get(xComponentContext)) + { + if (rFilter == "Visio Document") + { + aRet.clear(); + } + } return aRet; } diff --git a/include/unotools/fltrcfg.hxx b/include/unotools/fltrcfg.hxx index ab0eb1364e81..23bbced79080 100644 --- a/include/unotools/fltrcfg.hxx +++ b/include/unotools/fltrcfg.hxx @@ -91,6 +91,9 @@ public: void SetCharBackground2Highlighting(); void SetCharBackground2Shading(); + bool IsVisio2Draw() const; + void SetVisio2Draw(bool bFlag); + static SvtFilterOptions& Get(); }; diff --git a/officecfg/registry/schema/org/openoffice/Office/Common.xcs b/officecfg/registry/schema/org/openoffice/Office/Common.xcs index 990b9f007073..83437812f9c0 100644 --- a/officecfg/registry/schema/org/openoffice/Office/Common.xcs +++ b/officecfg/registry/schema/org/openoffice/Office/Common.xcs @@ -4054,6 +4054,13 @@ </info> <value>true</value> </prop> + <prop oor:name="VisioToDraw" oor:type="xs:boolean" oor:nillable="false"> + <info> + <desc>Specifies if convertible Visio OLE objects are converted + into Draw objects.</desc> + </info> + <value>true</value> + </prop> </group> <group oor:name="Export"> <info> diff --git a/unotools/source/config/fltrcfg.cxx b/unotools/source/config/fltrcfg.cxx index 32a61fdae8a1..a8313b09ea8c 100644 --- a/unotools/source/config/fltrcfg.cxx +++ b/unotools/source/config/fltrcfg.cxx @@ -54,10 +54,11 @@ enum class ConfigFlags { UseEnhancedFields = 0x0100000, WordWbctbl = 0x0200000, SmartArtShapeLoad = 0x0400000, - CharBackgroundToHighlighting = 0x8000000 + CharBackgroundToHighlighting = 0x8000000, + VisioLoad = 0x4000000, }; namespace o3tl { - template<> struct typed_flags<ConfigFlags> : is_typed_flags<ConfigFlags, 0x87fff3f> {}; + template<> struct typed_flags<ConfigFlags> : is_typed_flags<ConfigFlags, 0xc7fff3f> {}; } class SvtAppFilterOptions_Impl : public utl::ConfigItem @@ -306,7 +307,7 @@ const Sequence<OUString>& GetPropertyNames() static Sequence<OUString> aNames; if(!aNames.getLength()) { - int nCount = 14; + int nCount = 15; aNames.realloc(nCount); static const char* aPropNames[] = { @@ -323,7 +324,8 @@ const Sequence<OUString>& GetPropertyNames() "Export/EnableWordPreview", // 10 "Import/ImportWWFieldsAsEnhancedFields", // 11 "Import/SmartArtToShapes", // 12 - "Export/CharBackgroundToHighlighting" // 13 + "Export/CharBackgroundToHighlighting", // 13 + "Import/VisioToDraw" // 14 }; OUString* pNames = aNames.getArray(); for(int i = 0; i < nCount; i++) @@ -365,6 +367,9 @@ static ConfigFlags lcl_GetFlag(sal_Int32 nProp) case 11: nFlag = ConfigFlags::UseEnhancedFields; break; case 12: nFlag = ConfigFlags::SmartArtShapeLoad; break; case 13: nFlag = ConfigFlags::CharBackgroundToHighlighting; break; + case 14: + nFlag = ConfigFlags::VisioLoad; + break; default: OSL_FAIL("illegal value"); } @@ -604,6 +609,14 @@ void SvtFilterOptions::SetSmartArt2Shape( bool bFlag ) SetModified(); } +bool SvtFilterOptions::IsVisio2Draw() const { return pImpl->IsFlag(ConfigFlags::VisioLoad); } + +void SvtFilterOptions::SetVisio2Draw(bool bFlag) +{ + pImpl->SetFlag(ConfigFlags::VisioLoad, bFlag); + SetModified(); +} + namespace { class theFilterOptions commit 29355af7b89fb2825a712c7d79cef56cc4f25610 Author: Miklos Vajna <[email protected]> AuthorDate: Wed Aug 14 15:09:47 2019 +0200 Commit: Miklos Vajna <[email protected]> CommitDate: Fri Aug 16 11:15:19 2019 +0200 embeddedobj: add initial CppunitTest_embeddedobj_general Fails with commit 88afec70112c95a016e92e26c1d06d7dd002e4e8 (embeddedobj: respect config for Insert -> Object -> OLE Object -> from file, 2019-08-14) reverted. Change-Id: I64f81642260f6eab5a86219d94553f09b67b3555 Reviewed-on: https://gerrit.libreoffice.org/77461 Reviewed-by: Miklos Vajna <[email protected]> Tested-by: Jenkins (cherry picked from commit 85a7bc13fed5020441d772816d73a932f67ad377) diff --git a/embeddedobj/CppunitTest_embeddedobj_general.mk b/embeddedobj/CppunitTest_embeddedobj_general.mk new file mode 100644 index 000000000000..32fea16fb2b2 --- /dev/null +++ b/embeddedobj/CppunitTest_embeddedobj_general.mk @@ -0,0 +1,44 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +#************************************************************************* +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +#************************************************************************* + +$(eval $(call gb_CppunitTest_CppunitTest,embeddedobj_general)) + +$(eval $(call gb_CppunitTest_use_externals,embeddedobj_general,\ + boost_headers \ +)) + +$(eval $(call gb_CppunitTest_add_exception_objects,embeddedobj_general, \ + embeddedobj/qa/cppunit/general \ +)) + +$(eval $(call gb_CppunitTest_use_libraries,embeddedobj_general, \ + comphelper \ + cppu \ + embobj \ + sal \ + test \ + unotest \ +)) + +$(eval $(call gb_CppunitTest_use_sdk_api,embeddedobj_general)) + +$(eval $(call gb_CppunitTest_use_ure,embeddedobj_general)) +$(eval $(call gb_CppunitTest_use_vcl,embeddedobj_general)) + +$(eval $(call gb_CppunitTest_use_rdb,embeddedobj_general,services)) + +$(eval $(call gb_CppunitTest_use_custom_headers,embeddedobj_general,\ + officecfg/registry \ +)) + +$(eval $(call gb_CppunitTest_use_configuration,embeddedobj_general)) + +# vim: set noet sw=4 ts=4: diff --git a/embeddedobj/Module_embeddedobj.mk b/embeddedobj/Module_embeddedobj.mk index 68b38e80e909..808506bb8809 100644 --- a/embeddedobj/Module_embeddedobj.mk +++ b/embeddedobj/Module_embeddedobj.mk @@ -15,4 +15,10 @@ $(eval $(call gb_Module_add_targets,embeddedobj,\ $(if $(filter WNT-TRUE,$(OS)-$(DISABLE_ATL)),,Library_emboleobj) \ )) +ifeq ($(OS),LINUX) +$(eval $(call gb_Module_add_slowcheck_targets,embeddedobj,\ + CppunitTest_embeddedobj_general \ +)) +endif + # vim: set noet sw=4 ts=4: diff --git a/embeddedobj/qa/cppunit/data/insert-file-config.doc b/embeddedobj/qa/cppunit/data/insert-file-config.doc new file mode 100644 index 000000000000..182a70c34265 Binary files /dev/null and b/embeddedobj/qa/cppunit/data/insert-file-config.doc differ diff --git a/embeddedobj/qa/cppunit/general.cxx b/embeddedobj/qa/cppunit/general.cxx new file mode 100644 index 000000000000..43b8dd9f4c1b --- /dev/null +++ b/embeddedobj/qa/cppunit/general.cxx @@ -0,0 +1,90 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <test/bootstrapfixture.hxx> +#include <unotest/macros_test.hxx> + +#include <com/sun/star/frame/Desktop.hpp> +#include <com/sun/star/embed/XStorage.hpp> + +#include <comphelper/embeddedobjectcontainer.hxx> +#include <comphelper/processfactory.hxx> +#include <comphelper/propertyvalue.hxx> +#include <comphelper/scopeguard.hxx> +#include <comphelper/storagehelper.hxx> +#include <officecfg/Office/Common.hxx> + +using namespace ::com::sun::star; + +/// embeddedobj general tests. +class EmbeddedobjGeneralTest : public test::BootstrapFixture, public unotest::MacrosTest +{ +private: + uno::Reference<uno::XComponentContext> mxComponentContext; + uno::Reference<lang::XComponent> mxComponent; + +public: + void setUp() override; + void tearDown() override; + uno::Reference<lang::XComponent>& getComponent() { return mxComponent; } +}; + +void EmbeddedobjGeneralTest::setUp() +{ + test::BootstrapFixture::setUp(); + + mxComponentContext.set(comphelper::getComponentContext(getMultiServiceFactory())); + mxDesktop.set(frame::Desktop::create(mxComponentContext)); +} + +void EmbeddedobjGeneralTest::tearDown() +{ + if (mxComponent.is()) + mxComponent->dispose(); + + test::BootstrapFixture::tearDown(); +} + +CPPUNIT_TEST_FIXTURE(EmbeddedobjGeneralTest, testInsertFileConfig) +{ + // Explicitly disable Word->Writer mapping for this test. + std::shared_ptr<comphelper::ConfigurationChanges> pBatch( + comphelper::ConfigurationChanges::create()); + officecfg::Office::Common::Filter::Microsoft::Import::WinWordToWriter::set(false, pBatch); + pBatch->commit(); + comphelper::ScopeGuard g([]() { + std::shared_ptr<comphelper::ConfigurationChanges> pBatchReset( + comphelper::ConfigurationChanges::create()); + officecfg::Office::Common::Filter::Microsoft::Import::WinWordToWriter::set(true, + pBatchReset); + pBatchReset->commit(); + }); + getComponent().set( + loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument")); + + // Insert a file as an embedded object. + uno::Reference<embed::XStorage> xStorage = comphelper::OStorageHelper::GetTemporaryStorage(); + comphelper::EmbeddedObjectContainer aContainer(xStorage); + OUString aFileName + = m_directories.getURLFromSrc("embeddedobj/qa/cppunit/data/insert-file-config.doc"); + uno::Sequence<beans::PropertyValue> aMedium{ comphelper::makePropertyValue("URL", aFileName) }; + OUString aName("Object 1"); + uno::Reference<embed::XEmbeddedObject> xObject + = aContainer.InsertEmbeddedObject(aMedium, aName); + + // Make sure that the insertion fails: + // 1) the user explicitly requested that the data is not loaded into Writer + // 2) this is non-Windows, so OLE embedding is not an option + // so silently still loading the data into Writer would be bad. + CPPUNIT_ASSERT(!xObject.is()); +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ commit 943a3267cbf1160a20f1ea4b3faf3f6227725d9c Author: Miklos Vajna <[email protected]> AuthorDate: Tue Nov 6 21:45:36 2018 +0100 Commit: Miklos Vajna <[email protected]> CommitDate: Fri Aug 16 11:15:19 2019 +0200 unotest: backport CPPUNIT_TEST_FIXTURE macro from cppunit.git Added upstream as <https://cgit.freedesktop.org/libreoffice/cppunit/commit/?id=48145587c4c2dc4f1e07d83073e136336c81ce79>. Reviewed-on: https://gerrit.libreoffice.org/62975 Tested-by: Jenkins Reviewed-by: Miklos Vajna <[email protected]> (cherry picked from commit 20f84aa139e122733f215fc539dcbcdcfce18c81) Change-Id: If3adbad3187e3d2b4319be7b295b41d5b7e9c08d diff --git a/include/unotest/bootstrapfixturebase.hxx b/include/unotest/bootstrapfixturebase.hxx index 67be3b5f4ea7..0a967d34d736 100644 --- a/include/unotest/bootstrapfixturebase.hxx +++ b/include/unotest/bootstrapfixturebase.hxx @@ -22,6 +22,21 @@ #include <unotest/detail/unotestdllapi.hxx> #include <unotest/directories.hxx> +// For cppunit < 1.15.0. +#ifndef CPPUNIT_TEST_FIXTURE +#define CPPUNIT_TEST_FIXTURE(TestClass, TestName) \ + class TestName : public TestClass \ + { \ + public: \ + void TestBody(); \ + CPPUNIT_TEST_SUITE(TestName); \ + CPPUNIT_TEST(TestBody); \ + CPPUNIT_TEST_SUITE_END(); \ + }; \ + CPPUNIT_TEST_SUITE_REGISTRATION(TestName); \ + void TestName::TestBody() +#endif + namespace test { // Class to do lots of heavy-lifting UNO & environment commit 475de9ce84ff56b93e2b2de2500dc77fe08d83bb Author: Miklos Vajna <[email protected]> AuthorDate: Wed Aug 14 12:21:11 2019 +0200 Commit: Miklos Vajna <[email protected]> CommitDate: Fri Aug 16 11:12:54 2019 +0200 embeddedobj: respect config for Insert -> Object -> OLE Object -> from file Tools -> Options -> Load/Save -> Microsoft Office has config options to decide that Word/Excel/PowerPoint formats are loaded into our doc models (default) or handled via external OLE applications instead. This is used in the MSO import/export filters, but in case the UI is used to insert a new file as an embedded object, then we ignored this setting, and the embedding type depended on if we found an import filter for the data or not (if yes, load it; handle externally otherwise). Fix this inconsistency by checking for the usual MSO import filter names and respect the existing configuration in those cases, so the user can choose to not handle these formats internally if wanted. Reviewed-on: https://gerrit.libreoffice.org/77449 Reviewed-by: Miklos Vajna <[email protected]> Tested-by: Jenkins (cherry picked from commit 88afec70112c95a016e92e26c1d06d7dd002e4e8) Change-Id: I6bce8b5467768ef3f21d97b4e0fe3f4d18d9466b diff --git a/embeddedobj/Library_embobj.mk b/embeddedobj/Library_embobj.mk index 87c33c893d6f..80660adc0e35 100644 --- a/embeddedobj/Library_embobj.mk +++ b/embeddedobj/Library_embobj.mk @@ -10,6 +10,10 @@ $(eval $(call gb_Library_Library,embobj)) +$(eval $(call gb_Library_use_custom_headers,embobj,\ + officecfg/registry \ +)) + $(eval $(call gb_Library_set_componentfile,embobj,embeddedobj/util/embobj)) $(eval $(call gb_Library_set_include,embobj,\ diff --git a/embeddedobj/source/general/xcreator.cxx b/embeddedobj/source/general/xcreator.cxx index 492e02b4a7b4..d9bc8d7869c0 100644 --- a/embeddedobj/source/general/xcreator.cxx +++ b/embeddedobj/source/general/xcreator.cxx @@ -32,6 +32,7 @@ #include <comphelper/processfactory.hxx> #include <cppuhelper/supportsservice.hxx> #include <comphelper/documentconstants.hxx> +#include <officecfg/Office/Common.hxx> #include <xcreator.hxx> #include <dummyobject.hxx> @@ -209,6 +210,42 @@ uno::Reference< uno::XInterface > SAL_CALL UNOEmbeddedObjectCreator::createInsta return xResult; } +/** + * Decides if rFilter should be used to load data into a doc model or real OLE embedding should + * happen. Empty return value means the later. + */ +static OUString HandleFilter(const uno::Reference<uno::XComponentContext>& xComponentContext, + const OUString& rFilter) +{ + OUString aRet = rFilter; + + if (!officecfg::Office::Common::Filter::Microsoft::Import::WinWordToWriter::get( + xComponentContext)) + { + if (rFilter == "MS Word 97" || rFilter == "MS Word 2007 XML") + { + aRet.clear(); + } + } + + if (!officecfg::Office::Common::Filter::Microsoft::Import::ExcelToCalc::get(xComponentContext)) + { + if (rFilter == "MS Excel 97" || rFilter == "Calc MS Excel 2007 XML") + { + aRet.clear(); + } + } + if (!officecfg::Office::Common::Filter::Microsoft::Import::PowerPointToImpress::get( + xComponentContext)) + { + if (rFilter == "MS PowerPoint 97" || rFilter == "Impress MS PowerPoint 2007 XML") + { + aRet.clear(); + } + } + + return aRet; +} uno::Reference< uno::XInterface > SAL_CALL UNOEmbeddedObjectCreator::createInstanceInitFromMediaDescriptor( const uno::Reference< embed::XStorage >& xStorage, @@ -234,6 +271,8 @@ uno::Reference< uno::XInterface > SAL_CALL UNOEmbeddedObjectCreator::createInsta // check if there is FilterName OUString aFilterName = m_aConfigHelper.UpdateMediaDescriptorWithFilterName( aTempMedDescr, false ); + aFilterName = HandleFilter(m_xContext, aFilterName); + if ( !aFilterName.isEmpty() ) { // the object can be loaded by one of the office application commit db41142bc4c0d44a999ed570e7e6d102277b9cb4 Author: Miklos Vajna <[email protected]> AuthorDate: Tue Aug 13 12:28:06 2019 +0200 Commit: Miklos Vajna <[email protected]> CommitDate: Fri Aug 16 10:58:01 2019 +0200 sw doc model xml dump: improve OLE node handling So it's possible to see if we have a dummy, common or OLE embedding. Reviewed-on: https://gerrit.libreoffice.org/77403 Reviewed-by: Miklos Vajna <[email protected]> Tested-by: Jenkins (cherry picked from commit abf05ba7fc625d87190759d927f8776594840ea1) Change-Id: I8c241211a149ca5261fdf8171cd2814fced8de79 diff --git a/sw/inc/ndole.hxx b/sw/inc/ndole.hxx index c878689b78eb..2960aa2f1cb4 100644 --- a/sw/inc/ndole.hxx +++ b/sw/inc/ndole.hxx @@ -75,6 +75,8 @@ public: basegfx::B2DRange& rRange, bool bSynchron); void resetBufferedData(); + + void dumpAsXml(xmlTextWriterPtr pWriter) const; }; // SwOLENode @@ -124,6 +126,8 @@ public: virtual bool SavePersistentData() override; virtual bool RestorePersistentData() override; + virtual void dumpAsXml(xmlTextWriterPtr pWriter) const override; + bool IsInGlobalDocSection() const; bool IsOLEObjectDeleted() const; diff --git a/sw/source/core/docnode/node.cxx b/sw/source/core/docnode/node.cxx index 578e1a98e2ff..52536da95acd 100644 --- a/sw/source/core/docnode/node.cxx +++ b/sw/source/core/docnode/node.cxx @@ -857,6 +857,7 @@ void SwNode::dumpAsXml(xmlTextWriterPtr pWriter) const break; case SwNodeType::Start: case SwNodeType::Text: + case SwNodeType::Ole: abort(); // overridden case SwNodeType::Table: pName = "table"; @@ -864,9 +865,6 @@ void SwNode::dumpAsXml(xmlTextWriterPtr pWriter) const case SwNodeType::Grf: pName = "grf"; break; - case SwNodeType::Ole: - pName = "ole"; - break; default: break; } xmlTextWriterStartElement(pWriter, BAD_CAST(pName)); diff --git a/sw/source/core/ole/ndole.cxx b/sw/source/core/ole/ndole.cxx index aa7449a6a1ec..44373a25df50 100644 --- a/sw/source/core/ole/ndole.cxx +++ b/sw/source/core/ole/ndole.cxx @@ -56,6 +56,7 @@ #include <comphelper/threadpool.hxx> #include <atomic> #include <deque> +#include <libxml/xmlwriter.h> using namespace utl; using namespace com::sun::star::uno; @@ -291,6 +292,18 @@ bool SwOLENode::RestorePersistentData() return true; } +void SwOLENode::dumpAsXml(xmlTextWriterPtr pWriter) const +{ + xmlTextWriterStartElement(pWriter, BAD_CAST("SwOLENode")); + xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this); + xmlTextWriterWriteAttribute(pWriter, BAD_CAST("index"), + BAD_CAST(OString::number(GetIndex()).getStr())); + + GetOLEObj().dumpAsXml(pWriter); + + xmlTextWriterEndElement(pWriter); +} + /** * OLE object is transported into UNDO area */ @@ -1086,6 +1099,19 @@ void SwOLEObj::resetBufferedData() } } +void SwOLEObj::dumpAsXml(xmlTextWriterPtr pWriter) const +{ + xmlTextWriterStartElement(pWriter, BAD_CAST("SwOLEObj")); + xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this); + + xmlTextWriterStartElement(pWriter, BAD_CAST("xOLERef")); + xmlTextWriterWriteAttribute(pWriter, BAD_CAST("symbol"), + BAD_CAST(typeid(*xOLERef.GetObject().get()).name())); + xmlTextWriterEndElement(pWriter); + + xmlTextWriterEndElement(pWriter); +} + SwOLELRUCache::SwOLELRUCache() : utl::ConfigItem("Office.Common/Cache") , m_nLRU_InitSize( 20 ) _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
