20#include <com/sun/star/lang/DisposedException.hpp>
21#include <com/sun/star/embed/EmbedStates.hpp>
22#include <com/sun/star/embed/EmbedMapUnits.hpp>
23#include <com/sun/star/embed/EmbedMisc.hpp>
24#include <com/sun/star/embed/Aspects.hpp>
25#include <com/sun/star/embed/WrongStateException.hpp>
26#include <com/sun/star/io/XSeekable.hpp>
27#include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
46 const uno::Reference< io::XStream >& xCachedVisRepr )
48 embed::VisualRepresentation aVisualRepr;
51 uno::Reference< io::XInputStream > xInStream = xCachedVisRepr->getInputStream();
52 if ( !xInStream.is() )
53 throw uno::RuntimeException();
54 uno::Reference< io::XSeekable > xSeekable( xCachedVisRepr, uno::UNO_QUERY_THROW );
56 uno::Sequence< sal_Int8 >
aSeq( 2 );
57 xInStream->readBytes(
aSeq, 2 );
59 if (
aSeq.getLength() == 2 &&
aSeq[0] ==
'B' &&
aSeq[1] ==
'M' )
62 aVisualRepr.Flavor = datatransfer::DataFlavor(
63 "application/x-openoffice-bitmap;windows_formatname=\"Bitmap\"",
70 aVisualRepr.Flavor = datatransfer::DataFlavor(
71 "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"",
76 sal_Int32 nStreamLength =
static_cast<sal_Int32
>(xSeekable->getLength());
77 uno::Sequence< sal_Int8 > aRepresent( nStreamLength );
78 xInStream->readBytes( aRepresent, nStreamLength );
79 aVisualRepr.Data <<= aRepresent;
88 if ( xWrappedObject.is() )
91 xWrappedObject->setVisualAreaSize( nAspect, aSize );
96 ::osl::ResettableMutexGuard aGuard(
m_aMutex );
98 throw lang::DisposedException();
100 SAL_WARN_IF( nAspect == embed::Aspects::MSOLE_ICON,
"embeddedobj.ole",
"For iconified objects no graphical replacement is required!" );
101 if ( nAspect == embed::Aspects::MSOLE_ICON )
103 throw embed::WrongStateException(
"Illegal call!",
107 throw embed::WrongStateException(
"The object is not loaded!",
115 bool bAllowToSetExtent =
116 ( (
getStatus( nAspect ) & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE )
120 if (
m_nObjectState == embed::EmbedStates::LOADED && bAllowToSetExtent )
126 catch(
const uno::Exception& )
128 SAL_WARN(
"embeddedobj.ole",
"The object should not be resized without activation!" );
135 awt::Size aSizeToSet = aSize;
141 catch(
const uno::Exception& )
162 if ( xWrappedObject.is() )
165 return xWrappedObject->getVisualAreaSize( nAspect );
169 ::osl::ResettableMutexGuard aGuard(
m_aMutex );
171 throw lang::DisposedException();
173 SAL_WARN_IF( nAspect == embed::Aspects::MSOLE_ICON,
"embeddedobj.ole",
"For iconified objects no graphical replacement is required!" );
174 if ( nAspect == embed::Aspects::MSOLE_ICON )
176 throw embed::WrongStateException(
"Illegal call!",
180 throw embed::WrongStateException(
"The object is not loaded!",
202 bool bBackToLoaded =
false;
204 bool bSuccess =
false;
207 SAL_WARN(
"embeddedobj.ole",
"Loaded object has no cached size!" );
214 bBackToLoaded =
true;
216 catch(
const uno::Exception& )
218 throw embed::NoVisualAreaSizeException(
219 "No size available!",
230 catch(
const uno::Exception& )
232 TOOLS_WARN_EXCEPTION(
"embeddedobj.ole",
"OleEmbeddedObject::getVisualAreaSize: GetExtent() failed:");
241 catch(
const uno::Exception& )
255 catch(
const uno::Exception& )
257 TOOLS_WARN_EXCEPTION(
"embeddedobj.ole",
"OleEmbeddedObject::getVisualAreaSize: GetCachedExtent() failed:");
269 catch(
const uno::Exception& )
271 TOOLS_WARN_EXCEPTION(
"embeddedobj.ole",
"OleEmbeddedObject::getVisualAreaSize: GetRecommendedExtent() failed:");
276 throw embed::NoVisualAreaSizeException(
277 "No size available!",
289 catch (
const embed::NoVisualAreaSizeException& )
293 catch (
const uno::Exception& )
295 throw embed::NoVisualAreaSizeException(
296 "No size available!",
306 throw embed::NoVisualAreaSizeException(
307 "No size available!",
321 if ( xWrappedObject.is() )
324 return xWrappedObject->getPreferredVisualRepresentation( nAspect );
328 ::osl::MutexGuard aGuard(
m_aMutex );
330 throw lang::DisposedException();
332 SAL_WARN_IF( nAspect == embed::Aspects::MSOLE_ICON,
"embeddedobj.ole",
"For iconified objects no graphical replacement is required!" );
333 if ( nAspect == embed::Aspects::MSOLE_ICON )
335 throw embed::WrongStateException(
"Illegal call!",
341 throw embed::WrongStateException(
"The object is not loaded!",
361 datatransfer::DataFlavor aDataFlavor(
362 "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"",
366 embed::VisualRepresentation aVisualRepr;
368 aVisualRepr.Flavor = aDataFlavor;
370 uno::Sequence< sal_Int8 > aVisReplSeq;
371 aVisualRepr.Data >>= aVisReplSeq;
372 if ( aVisReplSeq.getLength() )
375 uno::Reference< io::XInputStream >(
376 new ::comphelper::SequenceInputStream(aVisReplSeq)));
381 catch(
const uno::Exception& )
396 throw embed::WrongStateException(
"Illegal call!",
407 if ( xWrappedObject.is() )
410 return xWrappedObject->getMapUnit( nAspect );
414 ::osl::MutexGuard aGuard(
m_aMutex );
416 throw lang::DisposedException();
418 SAL_WARN_IF( nAspect == embed::Aspects::MSOLE_ICON,
"embeddedobj.ole",
"For iconified objects no graphical replacement is required!" );
419 if ( nAspect == embed::Aspects::MSOLE_ICON )
421 throw embed::WrongStateException(
"Illegal call!",
425 throw embed::WrongStateException(
"The object is not loaded!",
428 return embed::EmbedMapUnits::ONE_100TH_MM;
css::uno::Reference< css::io::XStream > m_xCachedVisualRepresentation
virtual css::awt::Size SAL_CALL getVisualAreaSize(sal_Int64 nAspect) override
css::uno::Reference< css::io::XStream > TryToRetrieveCachedVisualRepresentation_Impl(const css::uno::Reference< css::io::XStream > &xStream, bool bAllowRepair50=false) noexcept
css::uno::Reference< css::io::XStream > GetNewFilledTempStream_Impl(const css::uno::Reference< css::io::XInputStream > &xInStream)
virtual css::embed::VisualRepresentation SAL_CALL getPreferredVisualRepresentation(::sal_Int64 nAspect) override
css::awt::Size m_aCachedSize
virtual void SAL_CALL setVisualAreaSize(sal_Int64 nAspect, const css::awt::Size &aSize) override
css::uno::Sequence< sal_Int8 > m_aClassID
css::embed::VisualRepresentation GetVisualRepresentationInNativeFormat_Impl(const css::uno::Reference< css::io::XStream > &xCachedVisRepr)
void SetVisReplInStream(bool bExists)
virtual sal_Int64 SAL_CALL getStatus(sal_Int64 nAspect) override
virtual sal_Int32 SAL_CALL getCurrentState() override
rtl::Reference< OleComponent > m_pOleComponent
bool m_bVisReplInitialized
sal_Int64 m_nCachedAspect
css::uno::Reference< css::io::XStream > m_xObjectStream
css::awt::Size m_aSizeToSet
css::uno::Reference< css::embed::XEmbeddedObject > m_xWrappedObject
virtual sal_Int32 SAL_CALL getMapUnit(sal_Int64 nAspect) override
virtual void SAL_CALL changeState(sal_Int32 nNewState) override
#define TOOLS_WARN_EXCEPTION(area, stream)
Sequence< sal_Int8 > aSeq
#define SAL_WARN_IF(condition, area, stream)
#define SAL_WARN(area, stream)