summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2019-11-20 14:54:16 +0000
committerMichael Stahl <Michael.Stahl@cib.de>2019-11-22 16:26:18 +0100
commit7e9c5db6e01c0a8629f474cd0550cb470fdb4cb8 (patch)
tree0afd94aa7f4d9bbf3321d7657760f96e8a7078fb
parentpoppler: upgrade to release 0.82.0 (diff)
downloadcore-7e9c5db6e01c0a8629f474cd0550cb470fdb4cb8.tar.gz
core-7e9c5db6e01c0a8629f474cd0550cb470fdb4cb8.zip
If a SdrOle2Obj object is missing/broken show the preview set for it
if the object isn't valid, e.g. link to something that doesn't exist, set the fallback graphic as mxGraphic so SdrOle2Obj::GetGraphic will show the fallback, otherwise the failing mxObjRef.is test in SdrOle2Obj::GetGraphic means it doesn't get used Reviewed-on: https://gerrit.libreoffice.org/83329 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.stahl@cib.de> (cherry picked from commit 35300000346902db38f063b4427a07fdaf6240cd) Change-Id: I8f1aea6b25dc216e01a0f888a44d10876bb1bebd
-rw-r--r--sc/qa/unit/data/ods/keep-preview-missing-obj-link.odsbin0 -> 18464 bytes
-rw-r--r--sc/qa/unit/helper/qahelper.cxx17
-rw-r--r--sc/qa/unit/helper/qahelper.hxx2
-rw-r--r--sc/qa/unit/subsequent_filters-test.cxx19
-rw-r--r--svx/source/svdraw/svdoole2.cxx8
5 files changed, 42 insertions, 4 deletions
diff --git a/sc/qa/unit/data/ods/keep-preview-missing-obj-link.ods b/sc/qa/unit/data/ods/keep-preview-missing-obj-link.ods
new file mode 100644
index 000000000000..e7b15fd7688a
--- /dev/null
+++ b/sc/qa/unit/data/ods/keep-preview-missing-obj-link.ods
Binary files differ
diff --git a/sc/qa/unit/helper/qahelper.cxx b/sc/qa/unit/helper/qahelper.cxx
index 809fdbf4bbd0..481661e176a7 100644
--- a/sc/qa/unit/helper/qahelper.cxx
+++ b/sc/qa/unit/helper/qahelper.cxx
@@ -279,7 +279,7 @@ void testFormats(ScBootstrapFixture* pTest, ScDocument* pDoc, sal_Int32 nFormat)
CPPUNIT_ASSERT_EQUAL(ScRangeList(ScRange(1,1,2,3,1,2)), rRange3);
}
-const SdrOle2Obj* getSingleChartObject(ScDocument& rDoc, sal_uInt16 nPage)
+const SdrOle2Obj* getSingleOleObject(ScDocument& rDoc, sal_uInt16 nPage)
{
// Retrieve the chart object instance from the 2nd page (for the 2nd sheet).
ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer();
@@ -315,14 +315,23 @@ const SdrOle2Obj* getSingleChartObject(ScDocument& rDoc, sal_uInt16 nPage)
return nullptr;
}
- const SdrOle2Obj& rOleObj = static_cast<const SdrOle2Obj&>(*pObj);
- if (!rOleObj.IsChart())
+ return static_cast<const SdrOle2Obj*>(pObj);
+}
+
+const SdrOle2Obj* getSingleChartObject(ScDocument& rDoc, sal_uInt16 nPage)
+{
+ const SdrOle2Obj* pObj = getSingleOleObject(rDoc, nPage);
+
+ if (!pObj)
+ return pObj;
+
+ if (!pObj->IsChart())
{
cout << "This should be a chart object." << endl;
return nullptr;
}
- return &rOleObj;
+ return pObj;
}
std::vector<OUString> getChartRangeRepresentations(const SdrOle2Obj& rChartObj)
diff --git a/sc/qa/unit/helper/qahelper.hxx b/sc/qa/unit/helper/qahelper.hxx
index c31569068a30..3cc5acc5161e 100644
--- a/sc/qa/unit/helper/qahelper.hxx
+++ b/sc/qa/unit/helper/qahelper.hxx
@@ -127,6 +127,8 @@ SCQAHELPER_DLLPUBLIC void testFile(const OUString& aFileName, ScDocument& rDoc,
//need own handler because conditional formatting strings must be generated
SCQAHELPER_DLLPUBLIC void testCondFile(const OUString& aFileName, ScDocument* pDoc, SCTAB nTab);
+SCQAHELPER_DLLPUBLIC const SdrOle2Obj* getSingleOleObject(ScDocument& rDoc, sal_uInt16 nPage);
+
SCQAHELPER_DLLPUBLIC const SdrOle2Obj* getSingleChartObject(ScDocument& rDoc, sal_uInt16 nPage);
SCQAHELPER_DLLPUBLIC std::vector<OUString> getChartRangeRepresentations(const SdrOle2Obj& rChartObj);
diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx
index 326dc0608f29..6ac3e6dbd484 100644
--- a/sc/qa/unit/subsequent_filters-test.cxx
+++ b/sc/qa/unit/subsequent_filters-test.cxx
@@ -247,6 +247,7 @@ public:
void testHiddenRowsColumnsXLSXML();
void testColumnWidthRowHeightXLSXML();
void testTdf62268();
+ void testPreviewMissingObjLink();
CPPUNIT_TEST_SUITE(ScFiltersTest);
CPPUNIT_TEST(testBooleanFormatXLSX);
@@ -380,6 +381,7 @@ public:
CPPUNIT_TEST(testColumnWidthRowHeightXLSXML);
CPPUNIT_TEST(testCondFormatFormulaListenerXLSX);
CPPUNIT_TEST(testTdf62268);
+ CPPUNIT_TEST(testPreviewMissingObjLink);
CPPUNIT_TEST_SUITE_END();
@@ -4096,6 +4098,23 @@ void ScFiltersTest::testTdf62268()
xDocSh->DoClose();
}
+void ScFiltersTest::testPreviewMissingObjLink()
+{
+ ScDocShellRef xDocSh = loadDoc("keep-preview-missing-obj-link.", FORMAT_ODS);
+ CPPUNIT_ASSERT_MESSAGE("Failed to load keep-preview-missing-obj-link.ods.", xDocSh.is());
+
+ ScDocument& rDoc = xDocSh->GetDocument();
+
+ // Retrieve the ole object
+ const SdrOle2Obj* pOleObj = getSingleOleObject(rDoc, 0);
+ CPPUNIT_ASSERT_MESSAGE("Failed to retrieve an ole object from the 2nd sheet.", pOleObj);
+
+ const Graphic* pGraphic = pOleObj->GetGraphic();
+ CPPUNIT_ASSERT_MESSAGE("the ole object links to a missing file, but we should retain its preview", pGraphic);
+
+ xDocSh->DoClose();
+}
+
ScFiltersTest::ScFiltersTest()
: ScBootstrapFixture( "sc/qa/unit/data" )
{
diff --git a/svx/source/svdraw/svdoole2.cxx b/svx/source/svdraw/svdoole2.cxx
index cddbd3285444..ca65521bed0b 100644
--- a/svx/source/svdraw/svdoole2.cxx
+++ b/svx/source/svdraw/svdoole2.cxx
@@ -1864,11 +1864,19 @@ bool SdrOle2Obj::IsReal3DChart() const
void SdrOle2Obj::SetGraphicToObj( const Graphic& aGraphic, const OUString& aMediaType )
{
mpImpl->mxObjRef.SetGraphic( aGraphic, aMediaType );
+ // if the object isn't valid, e.g. link to something that doesn't exist, set the fallback
+ // graphic as mxGraphic so SdrOle2Obj::GetGraphic will show the fallback
+ if (const Graphic* pObjGraphic = mpImpl->mxObjRef.is() ? nullptr : mpImpl->mxObjRef.GetGraphic())
+ mpImpl->mxGraphic.reset(new Graphic(*pObjGraphic));
}
void SdrOle2Obj::SetGraphicToObj( const uno::Reference< io::XInputStream >& xGrStream, const OUString& aMediaType )
{
mpImpl->mxObjRef.SetGraphicStream( xGrStream, aMediaType );
+ // if the object isn't valid, e.g. link to something that doesn't exist, set the fallback
+ // graphic as mxGraphic so SdrOle2Obj::GetGraphic will show the fallback
+ if (const Graphic* pObjGraphic = mpImpl->mxObjRef.is() ? nullptr : mpImpl->mxObjRef.GetGraphic())
+ mpImpl->mxGraphic.reset(new Graphic(*pObjGraphic));
}
bool SdrOle2Obj::IsCalc() const