diff options
author | Michael Stahl <mstahl@redhat.com> | 2011-12-06 04:36:21 +0100 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2011-12-06 04:36:21 +0100 |
commit | f3c19f8263f3352ce4efff0965f8000d8347f6a5 (patch) | |
tree | 1e27af45e075128cbea1f4258d07eee543c6e643 | |
parent | f014ea59e9e6e24ffead1961e8b689237b3927f0 (diff) |
SdrMediaObj: copy/paste support
This only works properly in Impress, because Calc and Writer lack
a SfxBaseModel on their clipboard document.
-rw-r--r-- | avmedia/source/framework/mediaitem.cxx | 5 | ||||
-rw-r--r-- | svx/inc/svx/svdomedia.hxx | 2 | ||||
-rw-r--r-- | svx/source/svdraw/svdmodel.cxx | 5 | ||||
-rw-r--r-- | svx/source/svdraw/svdomedia.cxx | 62 |
4 files changed, 67 insertions, 7 deletions
diff --git a/avmedia/source/framework/mediaitem.cxx b/avmedia/source/framework/mediaitem.cxx index cb296375594a..f5150f659b79 100644 --- a/avmedia/source/framework/mediaitem.cxx +++ b/avmedia/source/framework/mediaitem.cxx @@ -250,10 +250,7 @@ void MediaItem::setURL( const ::rtl::OUString& rURL, { m_pImpl->m_URL = rURL; m_pImpl->m_nMaskSet |= AVMEDIA_SETMASK_URL; - if (xModel.is()) - { - m_pImpl->m_wModel = xModel; - } + m_pImpl->m_wModel = xModel; } //------------------------------------------------------------------------ diff --git a/svx/inc/svx/svdomedia.hxx b/svx/inc/svx/svdomedia.hxx index ffb2d9b8ec9b..bc832c0de11e 100644 --- a/svx/inc/svx/svdomedia.hxx +++ b/svx/inc/svx/svdomedia.hxx @@ -54,6 +54,8 @@ public: virtual ~SdrMediaObj(); + virtual void SetModel(SdrModel* pNewModel); + virtual bool HasTextEdit() const; virtual void TakeObjInfo(SdrObjTransformInfoRec& rInfo) const; diff --git a/svx/source/svdraw/svdmodel.cxx b/svx/source/svdraw/svdmodel.cxx index df94366e8b31..20f19d5427be 100644 --- a/svx/source/svdraw/svdmodel.cxx +++ b/svx/source/svdraw/svdmodel.cxx @@ -34,6 +34,7 @@ #include <osl/endian.h> #include <rtl/logfile.hxx> #include <rtl/strbuf.hxx> +#include <rtl/oustringostreaminserter.hxx> #include <com/sun/star/lang/XComponent.hpp> #include <com/sun/star/document/XStorageBasedDocument.hpp> @@ -924,9 +925,9 @@ SdrModel::GetDocumentStream( ::rtl::OUString const& rURL, { SAL_INFO("svx", "not found"); } - catch (uno::Exception const&) + catch (uno::Exception const& e) { - SAL_WARN("svx", "exception"); + SAL_WARN("svx", "exception: '" << e.Message << "'"); } return 0; } diff --git a/svx/source/svdraw/svdomedia.cxx b/svx/source/svdraw/svdomedia.cxx index 526d30fdd25e..c40d130ac8e7 100644 --- a/svx/source/svdraw/svdomedia.cxx +++ b/svx/source/svdraw/svdomedia.cxx @@ -27,15 +27,25 @@ ************************************************************************/ +#include <svx/svdomedia.hxx> + +#include <rtl/oustringostreaminserter.hxx> + +#include <com/sun/star/document/XStorageBasedDocument.hpp> +#include <com/sun/star/embed/XStorage.hpp> + +#include <comphelper/storagehelper.hxx> + #include <vcl/svapp.hxx> -#include <svx/svdomedia.hxx> +#include <svx/svdmodel.hxx> #include "svx/svdglob.hxx" #include "svx/svdstr.hrc" #include <svx/sdr/contact/viewcontactofsdrmediaobj.hxx> #include <avmedia/mediawindow.hxx> + using namespace ::com::sun::star; // --------------- @@ -79,6 +89,56 @@ sdr::contact::ViewContact* SdrMediaObj::CreateObjectSpecificViewContact() // ------------------------------------------------------------------------------ +void SdrMediaObj::SetModel(SdrModel *const pNewModel) +{ + SdrModel *const pOldModel(GetModel()); + SdrRectObj::SetModel(pNewModel); + if (pOldModel && pNewModel && (pNewModel != pOldModel)) // copy/paste + { + try + { + ::rtl::OUString const& url(getURL()); + // overwrite the model reference: it should point to the target doc + uno::Reference<frame::XModel> const xTarget( + pNewModel->getUnoModel(), uno::UNO_QUERY); + setURL(url, xTarget); + // try to copy the media to target document + uno::Reference<embed::XStorage> const xTargetStorage( + pNewModel->GetDocumentStorage()); + if (!xTargetStorage.is()) + { + SAL_INFO("svx", "no target storage"); + return; + } + ::comphelper::LifecycleProxy sourceProxy; + uno::Reference<io::XInputStream> const xInStream( + pOldModel->GetDocumentStream(url, sourceProxy)); + if (!xInStream.is()) + { + SAL_INFO("svx", "no stream"); + return; // for linked media we should return here + } + ::comphelper::LifecycleProxy targetProxy; + uno::Reference<io::XStream> const xStream( + ::comphelper::OStorageHelper::GetStreamAtPackageURL( + xTargetStorage, url, embed::ElementModes::WRITE, + targetProxy)); + uno::Reference<io::XOutputStream> const xOutStream( + (xStream.is()) ? xStream->getOutputStream() : 0); + ::comphelper::OStorageHelper::CopyInputToOutput( + xInStream, xOutStream); + xOutStream->closeOutput(); + targetProxy.commitStorages(); + } + catch (uno::Exception const& e) + { + SAL_WARN("svx", "exception: '" << e.Message << "'"); + } + } +} + +// ------------------------------------------------------------------------------ + void SdrMediaObj::TakeObjInfo( SdrObjTransformInfoRec& rInfo ) const { rInfo.bSelectAllowed = true; |