summaryrefslogtreecommitdiff
path: root/svx
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2011-12-02 23:43:23 +0100
committerMichael Stahl <mstahl@redhat.com>2011-12-03 00:48:15 +0100
commitfd95f1ab6220c6a530fd2e4e727417f504a5db51 (patch)
treeb378d6e72698a8329f41d7919016574a301016e2 /svx
parentaa59ee85a8e902aa4dc956822e9169093de6c454 (diff)
refactor SdrModel::GetDocumentStream
Remove 3 ~identical implementations of GetDocumentStream and the associated struct SdrDocumentStreamInfo.
Diffstat (limited to 'svx')
-rw-r--r--svx/inc/svx/svdmodel.hxx21
-rw-r--r--svx/source/svdraw/svdmodel.cxx48
-rw-r--r--svx/source/svdraw/svdograf.cxx38
3 files changed, 67 insertions, 40 deletions
diff --git a/svx/inc/svx/svdmodel.hxx b/svx/inc/svx/svdmodel.hxx
index 3cf998fec409..567c821e5f4e 100644
--- a/svx/inc/svx/svdmodel.hxx
+++ b/svx/inc/svx/svdmodel.hxx
@@ -91,10 +91,13 @@ class SotStorage;
class SdrOutlinerCache;
class SotStorageRef;
class SdrUndoFactory;
-namespace comphelper{
+namespace comphelper
+{
class IEmbeddedHelper;
+ class LifecycleProxy;
}
-namespace sfx2{
+namespace sfx2
+{
class LinkManager;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -156,13 +159,6 @@ public:
// neu zu bestimmen und unbenutztes wegzuwerfen). sal_False == aktiv
#define LOADREFCOUNTS (false)
-struct SdrDocumentStreamInfo
-{
- bool mbDeleteAfterUse;
- String maUserData;
- com::sun::star::uno::Reference < com::sun::star::embed::XStorage > mxStorageRef;
-};
-
struct SdrModelImpl;
class SVX_DLLPUBLIC SdrModel : public SfxBroadcaster, public tools::WeakBase< SdrModel >
@@ -330,7 +326,12 @@ public:
// Datei angelegt.
// Geliefert werden muss der Stream, aus dem das Model geladen wurde
// bzw. in den es zuletzt gespeichert wurde.
- virtual SvStream* GetDocumentStream( SdrDocumentStreamInfo& rStreamInfo ) const;
+ virtual ::com::sun::star::uno::Reference<
+ ::com::sun::star::embed::XStorage> GetDocumentStorage() const;
+ ::com::sun::star::uno::Reference<
+ ::com::sun::star::io::XInputStream >
+ GetDocumentStream(::rtl::OUString const& rURL,
+ ::comphelper::LifecycleProxy & rProxy) const;
// Die Vorlagenattribute der Zeichenobjekte in harte Attribute verwandeln.
void BurnInStyleSheetAttributes();
// Wer sich von SdrPage ableitet muss sich auch von SdrModel ableiten
diff --git a/svx/source/svdraw/svdmodel.cxx b/svx/source/svdraw/svdmodel.cxx
index cb24ca2c3768..df94366e8b31 100644
--- a/svx/source/svdraw/svdmodel.cxx
+++ b/svx/source/svdraw/svdmodel.cxx
@@ -29,11 +29,16 @@
#include <svx/svdmodel.hxx>
-#include <com/sun/star/lang/XComponent.hpp>
+#include <math.h>
+
#include <osl/endian.h>
#include <rtl/logfile.hxx>
#include <rtl/strbuf.hxx>
-#include <math.h>
+
+#include <com/sun/star/lang/XComponent.hpp>
+#include <com/sun/star/document/XStorageBasedDocument.hpp>
+#include <com/sun/star/embed/ElementModes.hpp>
+
#include <tools/urlobj.hxx>
#include <unotools/ucbstreamhelper.hxx>
@@ -82,6 +87,7 @@
#include <svl/zforlist.hxx>
#include <comphelper/processfactory.hxx>
#include <comphelper/servicehelper.hxx>
+#include <comphelper/storagehelper.hxx>
#include <tools/tenccvt.hxx>
#include <unotools/syslocale.hxx>
@@ -886,9 +892,43 @@ void SdrModel::ImpReformatAllEdgeObjects()
}
}
-SvStream* SdrModel::GetDocumentStream(SdrDocumentStreamInfo& /*rStreamInfo*/) const
+uno::Reference<embed::XStorage> SdrModel::GetDocumentStorage() const
{
- return NULL;
+ uno::Reference<document::XStorageBasedDocument> const xSBD(
+ const_cast<SdrModel*>(this)->getUnoModel(), uno::UNO_QUERY);
+ if (!xSBD.is())
+ {
+ SAL_WARN("svx", "no UNO model");
+ return 0;
+ }
+ return xSBD->getDocumentStorage();
+}
+
+uno::Reference<io::XInputStream>
+SdrModel::GetDocumentStream( ::rtl::OUString const& rURL,
+ ::comphelper::LifecycleProxy & rProxy) const
+{
+ uno::Reference<embed::XStorage> const xStorage(GetDocumentStorage());
+ if (!xStorage.is())
+ {
+ SAL_WARN("svx", "no storage?");
+ return 0;
+ }
+ try {
+ uno::Reference<io::XStream> const xStream(
+ ::comphelper::OStorageHelper::GetStreamAtPackageURL(
+ xStorage, rURL, embed::ElementModes::READ, rProxy));
+ return (xStream.is()) ? xStream->getInputStream() : 0;
+ }
+ catch (container::NoSuchElementException const&)
+ {
+ SAL_INFO("svx", "not found");
+ }
+ catch (uno::Exception const&)
+ {
+ SAL_WARN("svx", "exception");
+ }
+ return 0;
}
// convert template attributes from the string into "hard" attributes
diff --git a/svx/source/svdraw/svdograf.cxx b/svx/source/svdraw/svdograf.cxx
index a587ab0b512a..151878a1bb27 100644
--- a/svx/source/svdraw/svdograf.cxx
+++ b/svx/source/svdraw/svdograf.cxx
@@ -35,6 +35,7 @@
#include <vcl/salbtype.hxx>
#include <sot/formats.hxx>
#include <sot/storage.hxx>
+#include <comphelper/storagehelper.hxx>
#include <unotools/ucbstreamhelper.hxx>
#include <unotools/localfilehelper.hxx>
#include <svl/style.hxx>
@@ -71,6 +72,7 @@
#include <basegfx/polygon/b2dpolygontools.hxx>
#include <osl/thread.hxx>
+using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::io;
@@ -1220,12 +1222,13 @@ IMPL_LINK( SdrGrafObj, ImpSwapHdl, GraphicObject*, pO )
{
if( pGraphic->HasUserData() )
{
- SdrDocumentStreamInfo aStreamInfo;
+ ::comphelper::LifecycleProxy proxy;
+ uno::Reference<io::XInputStream> const xStream(
+ pModel->GetDocumentStream(pGraphic->GetUserData(), proxy));
- aStreamInfo.mbDeleteAfterUse = sal_False;
- aStreamInfo.maUserData = pGraphic->GetUserData();
-
- SvStream* pStream = pModel->GetDocumentStream( aStreamInfo );
+ ::boost::scoped_ptr<SvStream> const pStream( (xStream.is())
+ ? ::utl::UcbStreamHelper::CreateStream(xStream)
+ : 0 );
if( pStream != NULL )
{
@@ -1251,7 +1254,7 @@ IMPL_LINK( SdrGrafObj, ImpSwapHdl, GraphicObject*, pO )
}
if( !GraphicFilter::GetGraphicFilter().ImportGraphic( aGraphic,
- aStreamInfo.maUserData,
+ pGraphic->GetUserData(),
*pStream,
GRFILTER_FORMAT_DONTKNOW,
NULL, 0, pFilterData ) )
@@ -1267,17 +1270,6 @@ IMPL_LINK( SdrGrafObj, ImpSwapHdl, GraphicObject*, pO )
delete pFilterData;
pStream->ResetError();
-
- if( aStreamInfo.mbDeleteAfterUse || aStreamInfo.mxStorageRef.is() )
- {
- if ( aStreamInfo.mxStorageRef.is() )
- {
- aStreamInfo.mxStorageRef->dispose();
- aStreamInfo.mxStorageRef = 0;
- }
-
- delete pStream;
- }
}
}
else if( !ImpUpdateGraphicLink( sal_False ) )
@@ -1316,15 +1308,9 @@ Reference< XInputStream > SdrGrafObj::getInputStream()
// kann aus dem original Doc-Stream nachgeladen werden...
if( pGraphic->HasUserData() )
{
- SdrDocumentStreamInfo aStreamInfo;
-
- aStreamInfo.mbDeleteAfterUse = sal_False;
- aStreamInfo.maUserData = pGraphic->GetUserData();
-
- SvStream* pStream = pModel->GetDocumentStream( aStreamInfo );
-
- if( pStream )
- xStream.set( new utl::OInputStreamWrapper( pStream, sal_True ) );
+ ::comphelper::LifecycleProxy proxy;
+ xStream.set(
+ pModel->GetDocumentStream(pGraphic->GetUserData(), proxy));
}
else if( pGraphic && GetGraphic().IsLink() )
{