summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2015-12-03 19:05:03 +1000
committerMiklos Vajna <vmiklos@collabora.co.uk>2015-12-14 09:05:21 +0000
commit6381fe554aec600d13d0359903216811d644dd36 (patch)
tree4c3201d70533a241495320ccd0bbf6297bb0bb10
parent6f8deb4601816c750743048deaed22f01dda0a36 (diff)
tdf#96206: Avoid scaling objects while copying to clipboard
... to prevent duplicating masters on slide copy-paste. Also fixed a 10-year copy-paste error (pRefPage wasn't replaced with pNPage). Fixed argument evaluation order issue (aStream.GetEndOfData() depends on Flush() but doesn't call it, so will return incorrect result if called before aStream.GetBuffer()). Replaced compare of hashes with results of stringify(), because it removes useless overhead (hashes are calculated from stringify() anyway, and are not cached anywhere). Removed Flush() called from SvMemoryStream::GetBuffer(), because it calls GetData(), which calls Flush() itself. Thanks to Andras Timar for unit test framework. Change-Id: Ia46d4e9a017fc628d424949a9d229045a249a4ca Reviewed-on: https://gerrit.libreoffice.org/20367 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
-rw-r--r--sd/CppunitTest_sd_misc_tests.mk155
-rw-r--r--sd/Module_sd.mk1
-rw-r--r--sd/qa/unit/data/odp/tdf96206.odpbin0 -> 12545 bytes
-rw-r--r--sd/qa/unit/misc-tests.cxx103
-rw-r--r--sd/source/core/drawdoc3.cxx22
-rw-r--r--sd/source/ui/inc/SlideSorter.hxx4
-rw-r--r--sd/source/ui/inc/SlideSorterViewShell.hxx7
-rw-r--r--sd/source/ui/inc/ViewShell.hxx3
-rw-r--r--sd/source/ui/slidesorter/inc/controller/SlideSorterController.hxx5
-rw-r--r--sd/source/ui/slidesorter/inc/controller/SlsClipboard.hxx8
-rw-r--r--svx/source/svdraw/svdobj.cxx1
-rw-r--r--tools/source/stream/stream.cxx1
12 files changed, 296 insertions, 14 deletions
diff --git a/sd/CppunitTest_sd_misc_tests.mk b/sd/CppunitTest_sd_misc_tests.mk
new file mode 100644
index 000000000000..453ec355613f
--- /dev/null
+++ b/sd/CppunitTest_sd_misc_tests.mk
@@ -0,0 +1,155 @@
+# -*- 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,sd_misc_tests))
+
+$(eval $(call gb_CppunitTest_use_external,sd_misc_tests,boost_headers))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,sd_misc_tests, \
+ sd/qa/unit/misc-tests \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,sd_misc_tests, \
+ $(call gb_Helper_optional,AVMEDIA,avmedia) \
+ basegfx \
+ canvastools \
+ comphelper \
+ cppcanvas \
+ cppu \
+ cppuhelper \
+ drawinglayer \
+ editeng \
+ for \
+ forui \
+ i18nlangtag \
+ i18nutil \
+ msfilter \
+ oox \
+ sal \
+ salhelper \
+ sax \
+ sb \
+ sd \
+ sfx \
+ sot \
+ svl \
+ svt \
+ svx \
+ svxcore \
+ test \
+ tl \
+ tk \
+ ucbhelper \
+ unotest \
+ utl \
+ vcl \
+ xo \
+ $(gb_UWINAPI) \
+))
+
+$(eval $(call gb_CppunitTest_set_include,sd_misc_tests,\
+ -I$(SRCDIR)/sd/inc \
+ -I$(SRCDIR)/sd/source/ui/inc \
+ -I$(SRCDIR)/sd/source/ui/slidesorter/inc \
+ $$(INCLUDE) \
+))
+
+$(eval $(call gb_CppunitTest_use_api,sd_misc_tests,\
+ offapi \
+ udkapi \
+))
+
+ifeq ($(OS),WNT)
+$(eval $(call gb_CppunitTest_use_system_win32_libs,sd_misc_tests,\
+ uuid \
+ ws2_32 \
+))
+endif
+
+ifeq ($(OS),MACOSX)
+$(eval $(call gb_CppunitTest_add_libs,sd_uimpress,\
+ -lobjc \
+))
+
+$(eval $(call gb_CppunitTest_use_system_darwin_frameworks,sd_uimpress,\
+ Foundation \
+ IOBluetooth \
+))
+endif
+
+$(eval $(call gb_CppunitTest_use_externals,sd_misc_tests,\
+ boost_headers \
+ gtk \
+ dbus \
+ $(if $(ENABLE_AVAHI), \
+ avahi \
+ ) \
+ $(if $(filter WNT,$(OS)),mDNSResponder) \
+ libxml2 \
+))
+
+$(eval $(call gb_CppunitTest_use_ure,sd_misc_tests))
+$(eval $(call gb_CppunitTest_use_vcl,sd_misc_tests))
+
+$(eval $(call gb_CppunitTest_use_components,sd_misc_tests,\
+ animations/source/animcore/animcore \
+ basic/util/sb \
+ chart2/source/chartcore \
+ chart2/source/controller/chartcontroller \
+ comphelper/util/comphelp \
+ configmgr/source/configmgr \
+ dbaccess/util/dba \
+ desktop/source/deployment/deployment \
+ embeddedobj/util/embobj \
+ filter/source/config/cache/filterconfig1 \
+ filter/source/odfflatxml/odfflatxml \
+ filter/source/svg/svgfilter \
+ filter/source/xmlfilteradaptor/xmlfa \
+ filter/source/xmlfilterdetect/xmlfd \
+ forms/util/frm \
+ framework/util/fwk \
+ i18npool/util/i18npool \
+ linguistic/source/lng \
+ oox/util/oox \
+ package/source/xstor/xstor \
+ package/util/package2 \
+ sax/source/expatwrap/expwrap \
+ sd/util/sd \
+ sd/util/sdfilt \
+ sd/util/sdd \
+ sfx2/util/sfx \
+ sot/util/sot \
+ svl/source/fsstor/fsstorage \
+ svtools/util/svt \
+ toolkit/util/tk \
+ ucb/source/core/ucb1 \
+ ucb/source/ucp/expand/ucpexpand1 \
+ ucb/source/ucp/file/ucpfile1 \
+ ucb/source/ucp/package/ucppkg1 \
+ ucb/source/ucp/tdoc/ucptdoc1 \
+ unotools/util/utl \
+ unoxml/source/rdf/unordf \
+ unoxml/source/service/unoxml \
+ xmloff/util/xo \
+ xmlsecurity/util/xsec_fw \
+ xmlsecurity/util/xmlsecurity \
+))
+
+$(eval $(call gb_CppunitTest_use_configuration,sd_misc_tests))
+
+$(eval $(call gb_CppunitTest_use_packages,sd_misc_tests,\
+ oox_customshapes \
+))
+
+
+$(call gb_CppunitTest_get_target,sd_misc_tests) : $(call gb_AllLangResTarget_get_target,sd)
+
+# vim: set noet sw=4 ts=4:
diff --git a/sd/Module_sd.mk b/sd/Module_sd.mk
index ae1a83f49b37..d2584c9b3cff 100644
--- a/sd/Module_sd.mk
+++ b/sd/Module_sd.mk
@@ -32,6 +32,7 @@ $(eval $(call gb_Module_add_check_targets,sd,\
CppunitTest_sd_import_tests \
CppunitTest_sd_export_tests \
CppunitTest_sd_filters_test \
+ CppunitTest_sd_misc_tests \
CppunitTest_sd_html_export_tests \
CppunitTest_sd_tiledrendering \
))
diff --git a/sd/qa/unit/data/odp/tdf96206.odp b/sd/qa/unit/data/odp/tdf96206.odp
new file mode 100644
index 000000000000..faebfd15361e
--- /dev/null
+++ b/sd/qa/unit/data/odp/tdf96206.odp
Binary files differ
diff --git a/sd/qa/unit/misc-tests.cxx b/sd/qa/unit/misc-tests.cxx
new file mode 100644
index 000000000000..f36a671d10c5
--- /dev/null
+++ b/sd/qa/unit/misc-tests.cxx
@@ -0,0 +1,103 @@
+/* -*- 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 "sdmodeltestbase.hxx"
+
+#include <vcl/svapp.hxx>
+#include <sddll.hxx>
+
+#include <com/sun/star/uno/Reference.hxx>
+#include <com/sun/star/uno/Sequence.hxx>
+#include <com/sun/star/beans/PropertyValue.hpp>
+
+#include <comphelper/processfactory.hxx>
+#include <com/sun/star/frame/Desktop.hpp>
+#include <com/sun/star/frame/XModel2.hpp>
+
+#include <vcl/scheduler.hxx>
+#include <osl/thread.hxx>
+#include <FactoryIds.hxx>
+#include <sdmod.hxx>
+#include <tools/shl.hxx>
+#include <ImpressViewShellBase.hxx>
+#include <SlideSorterViewShell.hxx>
+#include <SlideSorter.hxx>
+#include <controller/SlideSorterController.hxx>
+#include <controller/SlsClipboard.hxx>
+
+using namespace ::com::sun::star;
+
+/// Impress miscellaneous tests.
+class SdMiscTest : public SdModelTestBase
+{
+public:
+ void testTdf96206();
+
+ CPPUNIT_TEST_SUITE(SdMiscTest);
+ CPPUNIT_TEST(testTdf96206);
+ CPPUNIT_TEST_SUITE_END();
+
+};
+
+void SdMiscTest::testTdf96206()
+{
+ // Copying/pasting slide referring to a non-default master with a text duplicated the master
+
+ uno::Reference< frame::XDesktop2 > xDesktop = frame::Desktop::create(::comphelper::getProcessComponentContext());
+ CPPUNIT_ASSERT(xDesktop.is());
+
+ // create a frame
+ uno::Reference< frame::XFrame > xTargetFrame = xDesktop->findFrame("_blank", 0);
+ CPPUNIT_ASSERT(xTargetFrame.is());
+
+ // 1. Open the document
+ sd::DrawDocShellRef xDocSh = loadURL(getURLFromSrc("/sd/qa/unit/data/odp/tdf96206.odp"), ODP);
+ CPPUNIT_ASSERT_MESSAGE("Failed to load tdf96206.odp.", xDocSh.Is());
+
+ uno::Reference< frame::XModel2 > xModel2(xDocSh->GetModel(), uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xModel2.is());
+
+ uno::Reference< frame::XController2 > xController(xModel2->createDefaultViewController(xTargetFrame), uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xController.is());
+
+ // introduce model/view/controller to each other
+ xController->attachModel(xModel2.get());
+ xModel2->connectController(xController.get());
+ xTargetFrame->setComponent(xController->getComponentWindow(), xController.get());
+ xController->attachFrame(xTargetFrame);
+ xModel2->setCurrentController(xController.get());
+
+ sd::ViewShell *pViewShell = xDocSh->GetViewShell();
+ CPPUNIT_ASSERT(pViewShell);
+ sd::slidesorter::SlideSorterViewShell* pSSVS = nullptr;
+ for (int i = 0; i < 1000; i++)
+ {
+ // Process all Tasks - slide sorter is created here
+ while (Scheduler::ProcessTaskScheduling(true));
+ if ((pSSVS = sd::slidesorter::SlideSorterViewShell::GetSlideSorter(pViewShell->GetViewShellBase())) != nullptr)
+ break;
+ TimeValue aSleep(0, 100*1000000); // 100 msec
+ osl::Thread::wait(aSleep);
+ }
+ CPPUNIT_ASSERT(pSSVS);
+ auto& xSSController = pSSVS->GetSlideSorter().GetController();
+ const sal_uInt16 nMasterPageCnt1 = xDocSh->GetDoc()->GetMasterSdPageCount(PageKind::PK_STANDARD);
+ xSSController.GetClipboard().DoCopy();
+ xSSController.GetClipboard().DoPaste();
+ const sal_uInt16 nMasterPageCnt2 = xDocSh->GetDoc()->GetMasterSdPageCount(PageKind::PK_STANDARD);
+ CPPUNIT_ASSERT_EQUAL(nMasterPageCnt1, nMasterPageCnt2);
+
+ xDocSh->DoClose();
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(SdMiscTest);
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sd/source/core/drawdoc3.cxx b/sd/source/core/drawdoc3.cxx
index 5fb0e789d816..f63295c7f410 100644
--- a/sd/source/core/drawdoc3.cxx
+++ b/sd/source/core/drawdoc3.cxx
@@ -51,6 +51,7 @@
#include "strmname.h"
#include "anminfo.hxx"
#include "customshowlist.hxx"
+#include "sdxfer.hxx"
#include "../ui/inc/unmovss.hxx"
#include "../ui/inc/unchss.hxx"
@@ -110,7 +111,7 @@ void InsertBookmarkAsPage_FindDuplicateLayouts::operator()( SdDrawDocument& rDoc
{
// Ignore Layouts with "Default" these seem to be special - in the sense that there are lot of assumption all over Impress
// about this
- if( bRenameDuplicates && aTest != OUString( SdResId( STR_LAYOUT_DEFAULT_NAME ) ) && pTestPage->getHash() != pBMMPage->getHash() )
+ if( bRenameDuplicates && aTest != OUString( SdResId( STR_LAYOUT_DEFAULT_NAME ) ) && pTestPage->stringify() != pBMMPage->stringify() )
{
pBookmarkDoc->RenameLayoutTemplate(
pBMMPage->GetLayoutName(), pBMMPage->GetName() + "_");
@@ -437,17 +438,26 @@ bool SdDrawDocument::InsertBookmarkAsPage(
sal_Int32 nNRight = pNPage->GetRgtBorder();
sal_Int32 nNUpper = pNPage->GetUppBorder();
sal_Int32 nNLower = pNPage->GetLwrBorder();
- Orientation eNOrient = pRefPage->GetOrientation();
+ Orientation eNOrient = pNPage->GetOrientation();
// Adapt page size and margins to those of the later pages?
pRefPage = GetSdPage(nSdPageCount - 1, PK_STANDARD);
if( bNoDialogs )
{
- if( rBookmarkList.empty() )
- bScaleObjects = pRefPage->IsScaleObjects();
- else
- bScaleObjects = true;
+ // If this is clipboard, then no need to scale objects:
+ // this will make copied masters to differ from the originals,
+ // and thus InsertBookmarkAsPage_FindDuplicateLayouts will
+ // duplicate masters on insert to same document
+ bool bIsClipBoard = (SD_MOD()->pTransferClip &&
+ SD_MOD()->pTransferClip->GetWorkDocument() == this);
+ if (!bIsClipBoard)
+ {
+ if (rBookmarkList.empty())
+ bScaleObjects = pRefPage->IsScaleObjects();
+ else
+ bScaleObjects = true;
+ }
}
else
{
diff --git a/sd/source/ui/inc/SlideSorter.hxx b/sd/source/ui/inc/SlideSorter.hxx
index 68901785b589..79eb9fee59eb 100644
--- a/sd/source/ui/inc/SlideSorter.hxx
+++ b/sd/source/ui/inc/SlideSorter.hxx
@@ -28,6 +28,7 @@
#include <boost/noncopyable.hpp>
#include <boost/current_function.hpp>
#include <vcl/scrbar.hxx>
+#include "sddllapi.h"
#include <memory>
class ScrollBar;
@@ -138,7 +139,8 @@ public:
view::SlideSorterView& GetView() const;
- controller::SlideSorterController& GetController() const;
+ // Exported for unit test
+ SD_DLLPUBLIC controller::SlideSorterController& GetController() const;
/** Return the view shell that was given at construction.
@return
diff --git a/sd/source/ui/inc/SlideSorterViewShell.hxx b/sd/source/ui/inc/SlideSorterViewShell.hxx
index c0b8e8008bd5..833821114f5a 100644
--- a/sd/source/ui/inc/SlideSorterViewShell.hxx
+++ b/sd/source/ui/inc/SlideSorterViewShell.hxx
@@ -24,6 +24,7 @@
#include "glob.hxx"
#include <sfx2/shell.hxx>
#include <sfx2/viewfac.hxx>
+#include "sddllapi.h"
#include <memory>
#include <vector>
@@ -69,7 +70,8 @@ public:
pane is returned. When no slidesorter is visible then NULL is
returned.
*/
- static SlideSorterViewShell* GetSlideSorter (ViewShellBase& rBase);
+ // Exported for unit test
+ SD_DLLPUBLIC static SlideSorterViewShell* GetSlideSorter(ViewShellBase& rBase);
virtual SdPage* GetActualPage() override;
@@ -185,7 +187,8 @@ public:
// handle SlideSorterView specially because AccessibleSlideSorterView doesn't inherit from AccessibleDocumentViewBase
virtual void SwitchViewFireFocus( css::uno::Reference< css::accessibility::XAccessible > xAcc ) override;
- SlideSorter& GetSlideSorter() const;
+ // Exported for unit test
+ SD_DLLPUBLIC SlideSorter& GetSlideSorter() const;
/** Try to relocate all toplevel window elements to the given parent
window.
diff --git a/sd/source/ui/inc/ViewShell.hxx b/sd/source/ui/inc/ViewShell.hxx
index c534b2fc52a0..7f097bcfd50b 100644
--- a/sd/source/ui/inc/ViewShell.hxx
+++ b/sd/source/ui/inc/ViewShell.hxx
@@ -360,7 +360,8 @@ public:
// virtual void OuterResizePixel(const Point &rPos, const Size &rSize);
// virtual void InnerResizePixel(const Point &rPos, const Size &rSize);
- ViewShellBase& GetViewShellBase() const;
+ // Exported for unit test
+ SD_DLLPUBLIC ViewShellBase& GetViewShellBase() const;
/** Return <TRUE/> when the called view shell is the main sub shell of
its ViewShellBase object, i.e. is display in the center pane. This
diff --git a/sd/source/ui/slidesorter/inc/controller/SlideSorterController.hxx b/sd/source/ui/slidesorter/inc/controller/SlideSorterController.hxx
index a33c304e95af..83d01eb4fe35 100644
--- a/sd/source/ui/slidesorter/inc/controller/SlideSorterController.hxx
+++ b/sd/source/ui/slidesorter/inc/controller/SlideSorterController.hxx
@@ -30,6 +30,8 @@
#include <tools/link.hxx>
#include <tools/gen.hxx>
+#include "sddllapi.h"
+
#include <memory>
namespace sd { namespace slidesorter {
@@ -110,7 +112,8 @@ public:
PageSelector& GetPageSelector();
FocusManager& GetFocusManager();
- controller::Clipboard& GetClipboard();
+ // Exported for unit test
+ SD_DLLPUBLIC controller::Clipboard& GetClipboard();
/** Return the object that manages the scroll bars.
*/
diff --git a/sd/source/ui/slidesorter/inc/controller/SlsClipboard.hxx b/sd/source/ui/slidesorter/inc/controller/SlsClipboard.hxx
index 2180f224fc17..01d4bb3795f0 100644
--- a/sd/source/ui/slidesorter/inc/controller/SlsClipboard.hxx
+++ b/sd/source/ui/slidesorter/inc/controller/SlsClipboard.hxx
@@ -28,6 +28,8 @@
#include <tools/solar.h>
#include <svx/svdpage.hxx>
+#include "sddllapi.h"
+
#include <set>
class SfxRequest;
@@ -71,8 +73,10 @@ public:
void HandleSlotCall (SfxRequest& rRequest);
void DoCut (vcl::Window* pWindow = nullptr);
- void DoCopy (vcl::Window* pWindow = nullptr);
- void DoPaste (vcl::Window* pWindow = nullptr);
+ // Exported for unit test
+ SD_DLLPUBLIC void DoCopy(vcl::Window* pWindow = nullptr);
+ // Exported for unit test
+ SD_DLLPUBLIC void DoPaste(vcl::Window* pWindow = nullptr);
void DoDelete (vcl::Window* pWindow = nullptr);
void StartDrag (
diff --git a/svx/source/svdraw/svdobj.cxx b/svx/source/svdraw/svdobj.cxx
index 872fef07cda9..7dd6799b97d0 100644
--- a/svx/source/svdraw/svdobj.cxx
+++ b/svx/source/svdraw/svdobj.cxx
@@ -1756,6 +1756,7 @@ OString SdrObject::stringify() const
SfxItemSet aSet(GetMergedItemSet());
aSet.InvalidateDefaultItems();
aSet.Store(aStream, true);
+ aStream.Flush(); // for correct results from aStream.GetEndOfData()
aString.append(static_cast<const char *>(aStream.GetBuffer()), aStream.GetEndOfData());
return aString.makeStringAndClear();
diff --git a/tools/source/stream/stream.cxx b/tools/source/stream/stream.cxx
index c0198046761c..479657ab1d57 100644
--- a/tools/source/stream/stream.cxx
+++ b/tools/source/stream/stream.cxx
@@ -1726,7 +1726,6 @@ SvMemoryStream::~SvMemoryStream()
const void* SvMemoryStream::GetBuffer()
{
- Flush();
return GetData();
}