1*bfd08df8SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*bfd08df8SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*bfd08df8SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*bfd08df8SAndrew Rist * distributed with this work for additional information
6*bfd08df8SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*bfd08df8SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*bfd08df8SAndrew Rist * "License"); you may not use this file except in compliance
9*bfd08df8SAndrew Rist * with the License. You may obtain a copy of the License at
10*bfd08df8SAndrew Rist *
11*bfd08df8SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*bfd08df8SAndrew Rist *
13*bfd08df8SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*bfd08df8SAndrew Rist * software distributed under the License is distributed on an
15*bfd08df8SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*bfd08df8SAndrew Rist * KIND, either express or implied. See the License for the
17*bfd08df8SAndrew Rist * specific language governing permissions and limitations
18*bfd08df8SAndrew Rist * under the License.
19*bfd08df8SAndrew Rist *
20*bfd08df8SAndrew Rist *************************************************************/
21*bfd08df8SAndrew Rist
22*bfd08df8SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_embeddedobj.hxx"
26cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
27cdf0e10cSrcweir #include <com/sun/star/embed/EmbedStates.hpp>
28cdf0e10cSrcweir #include <com/sun/star/embed/EmbedMapUnits.hpp>
29cdf0e10cSrcweir #include <com/sun/star/embed/EmbedMisc.hpp>
30cdf0e10cSrcweir #include <com/sun/star/embed/Aspects.hpp>
31cdf0e10cSrcweir #include <com/sun/star/io/XSeekable.hpp>
32cdf0e10cSrcweir #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
33cdf0e10cSrcweir
34cdf0e10cSrcweir #include <rtl/logfile.hxx>
35cdf0e10cSrcweir
36cdf0e10cSrcweir #include <oleembobj.hxx>
37cdf0e10cSrcweir #include <olecomponent.hxx>
38cdf0e10cSrcweir #include <comphelper/mimeconfighelper.hxx>
39cdf0e10cSrcweir #include <comphelper/seqstream.hxx>
40cdf0e10cSrcweir
41cdf0e10cSrcweir using namespace ::com::sun::star;
42cdf0e10cSrcweir using namespace ::comphelper;
43cdf0e10cSrcweir
GetVisualRepresentationInNativeFormat_Impl(const uno::Reference<io::XStream> xCachedVisRepr)44cdf0e10cSrcweir embed::VisualRepresentation OleEmbeddedObject::GetVisualRepresentationInNativeFormat_Impl(
45cdf0e10cSrcweir const uno::Reference< io::XStream > xCachedVisRepr )
46cdf0e10cSrcweir throw ( uno::Exception )
47cdf0e10cSrcweir {
48cdf0e10cSrcweir embed::VisualRepresentation aVisualRepr;
49cdf0e10cSrcweir
50cdf0e10cSrcweir // TODO: detect the format in the future for now use workaround
51cdf0e10cSrcweir uno::Reference< io::XInputStream > xInStream = xCachedVisRepr->getInputStream();
52cdf0e10cSrcweir uno::Reference< io::XSeekable > xSeekable( xCachedVisRepr, uno::UNO_QUERY );
53cdf0e10cSrcweir if ( !xInStream.is() || !xSeekable.is() )
54cdf0e10cSrcweir throw uno::RuntimeException();
55cdf0e10cSrcweir
56cdf0e10cSrcweir uno::Sequence< sal_Int8 > aSeq( 2 );
57cdf0e10cSrcweir xInStream->readBytes( aSeq, 2 );
58cdf0e10cSrcweir xSeekable->seek( 0 );
59cdf0e10cSrcweir if ( aSeq.getLength() == 2 && aSeq[0] == 'B' && aSeq[1] == 'M' )
60cdf0e10cSrcweir {
61cdf0e10cSrcweir // it's a bitmap
62cdf0e10cSrcweir aVisualRepr.Flavor = datatransfer::DataFlavor(
63cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "application/x-openoffice-bitmap;windows_formatname=\"Bitmap\"" ),
64cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "Bitmap" ),
65cdf0e10cSrcweir ::getCppuType( (const uno::Sequence< sal_Int8 >*) NULL ) );
66cdf0e10cSrcweir }
67cdf0e10cSrcweir else
68cdf0e10cSrcweir {
69cdf0e10cSrcweir // it's a metafile
70cdf0e10cSrcweir aVisualRepr.Flavor = datatransfer::DataFlavor(
71cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"" ),
72cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "Windows Metafile" ),
73cdf0e10cSrcweir ::getCppuType( (const uno::Sequence< sal_Int8 >*) NULL ) );
74cdf0e10cSrcweir }
75cdf0e10cSrcweir
76cdf0e10cSrcweir sal_Int32 nStreamLength = (sal_Int32)xSeekable->getLength();
77cdf0e10cSrcweir uno::Sequence< sal_Int8 > aRepresent( nStreamLength );
78cdf0e10cSrcweir xInStream->readBytes( aRepresent, nStreamLength );
79cdf0e10cSrcweir aVisualRepr.Data <<= aRepresent;
80cdf0e10cSrcweir
81cdf0e10cSrcweir return aVisualRepr;
82cdf0e10cSrcweir }
83cdf0e10cSrcweir
setVisualAreaSize(sal_Int64 nAspect,const awt::Size & aSize)84cdf0e10cSrcweir void SAL_CALL OleEmbeddedObject::setVisualAreaSize( sal_Int64 nAspect, const awt::Size& aSize )
85cdf0e10cSrcweir throw ( lang::IllegalArgumentException,
86cdf0e10cSrcweir embed::WrongStateException,
87cdf0e10cSrcweir uno::Exception,
88cdf0e10cSrcweir uno::RuntimeException )
89cdf0e10cSrcweir {
90cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObject::setVisualAreaSize" );
91cdf0e10cSrcweir
92cdf0e10cSrcweir // begin wrapping related part ====================
93cdf0e10cSrcweir uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject;
94cdf0e10cSrcweir if ( xWrappedObject.is() )
95cdf0e10cSrcweir {
96cdf0e10cSrcweir // the object was converted to OOo embedded object, the current implementation is now only a wrapper
97cdf0e10cSrcweir xWrappedObject->setVisualAreaSize( nAspect, aSize );
98cdf0e10cSrcweir return;
99cdf0e10cSrcweir }
100cdf0e10cSrcweir // end wrapping related part ====================
101cdf0e10cSrcweir
102cdf0e10cSrcweir ::osl::ResettableMutexGuard aGuard( m_aMutex );
103cdf0e10cSrcweir if ( m_bDisposed )
104cdf0e10cSrcweir throw lang::DisposedException(); // TODO
105cdf0e10cSrcweir
106cdf0e10cSrcweir OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" );
107cdf0e10cSrcweir if ( nAspect == embed::Aspects::MSOLE_ICON )
108cdf0e10cSrcweir // no representation can be retrieved
109cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ),
110cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
111cdf0e10cSrcweir
112cdf0e10cSrcweir if ( m_nObjectState == -1 )
113cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object is not loaded!\n" ),
114cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
115cdf0e10cSrcweir
116cdf0e10cSrcweir #ifdef WNT
117cdf0e10cSrcweir // RECOMPOSE_ON_RESIZE misc flag means that the object has to be switched to running state on resize.
118cdf0e10cSrcweir // SetExtent() is called only for objects that require it,
119cdf0e10cSrcweir // it should not be called for MSWord documents to workaround problem i49369
120cdf0e10cSrcweir // If cached size is not set, that means that this is the size initialization, so there is no need to set the real size
121cdf0e10cSrcweir sal_Bool bAllowToSetExtent =
122cdf0e10cSrcweir ( ( getStatus( nAspect ) & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE )
123cdf0e10cSrcweir && !MimeConfigurationHelper::ClassIDsEqual( m_aClassID, MimeConfigurationHelper::GetSequenceClassID( 0x00020906L, 0x0000, 0x0000,
124cdf0e10cSrcweir 0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46 ) )
125cdf0e10cSrcweir && m_bHasCachedSize );
126cdf0e10cSrcweir
127cdf0e10cSrcweir if ( m_nObjectState == embed::EmbedStates::LOADED && bAllowToSetExtent )
128cdf0e10cSrcweir {
129cdf0e10cSrcweir aGuard.clear();
130cdf0e10cSrcweir try {
131cdf0e10cSrcweir changeState( embed::EmbedStates::RUNNING );
132cdf0e10cSrcweir }
133cdf0e10cSrcweir catch( uno::Exception& )
134cdf0e10cSrcweir {
135cdf0e10cSrcweir OSL_ENSURE( sal_False, "The object should not be resized without activation!\n" );
136cdf0e10cSrcweir }
137cdf0e10cSrcweir aGuard.reset();
138cdf0e10cSrcweir }
139cdf0e10cSrcweir
140cdf0e10cSrcweir if ( m_pOleComponent && m_nObjectState != embed::EmbedStates::LOADED && bAllowToSetExtent )
141cdf0e10cSrcweir {
142cdf0e10cSrcweir awt::Size aSizeToSet = aSize;
143cdf0e10cSrcweir aGuard.clear();
144cdf0e10cSrcweir try {
145cdf0e10cSrcweir m_pOleComponent->SetExtent( aSizeToSet, nAspect ); // will throw an exception in case of failure
146cdf0e10cSrcweir m_bHasSizeToSet = sal_False;
147cdf0e10cSrcweir }
148cdf0e10cSrcweir catch( uno::Exception& )
149cdf0e10cSrcweir {
150cdf0e10cSrcweir // some objects do not allow to set the size even in running state
151cdf0e10cSrcweir m_bHasSizeToSet = sal_True;
152cdf0e10cSrcweir m_aSizeToSet = aSizeToSet;
153cdf0e10cSrcweir m_nAspectToSet = nAspect;
154cdf0e10cSrcweir }
155cdf0e10cSrcweir aGuard.reset();
156cdf0e10cSrcweir }
157cdf0e10cSrcweir #endif
158cdf0e10cSrcweir
159cdf0e10cSrcweir // cache the values
160cdf0e10cSrcweir m_bHasCachedSize = sal_True;
161cdf0e10cSrcweir m_aCachedSize = aSize;
162cdf0e10cSrcweir m_nCachedAspect = nAspect;
163cdf0e10cSrcweir }
164cdf0e10cSrcweir
getVisualAreaSize(sal_Int64 nAspect)165cdf0e10cSrcweir awt::Size SAL_CALL OleEmbeddedObject::getVisualAreaSize( sal_Int64 nAspect )
166cdf0e10cSrcweir throw ( lang::IllegalArgumentException,
167cdf0e10cSrcweir embed::WrongStateException,
168cdf0e10cSrcweir uno::Exception,
169cdf0e10cSrcweir uno::RuntimeException )
170cdf0e10cSrcweir {
171cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObject::getVisualAreaSize" );
172cdf0e10cSrcweir
173cdf0e10cSrcweir // begin wrapping related part ====================
174cdf0e10cSrcweir uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject;
175cdf0e10cSrcweir if ( xWrappedObject.is() )
176cdf0e10cSrcweir {
177cdf0e10cSrcweir // the object was converted to OOo embedded object, the current implementation is now only a wrapper
178cdf0e10cSrcweir return xWrappedObject->getVisualAreaSize( nAspect );
179cdf0e10cSrcweir }
180cdf0e10cSrcweir // end wrapping related part ====================
181cdf0e10cSrcweir
182cdf0e10cSrcweir ::osl::ResettableMutexGuard aGuard( m_aMutex );
183cdf0e10cSrcweir if ( m_bDisposed )
184cdf0e10cSrcweir throw lang::DisposedException(); // TODO
185cdf0e10cSrcweir
186cdf0e10cSrcweir OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" );
187cdf0e10cSrcweir if ( nAspect == embed::Aspects::MSOLE_ICON )
188cdf0e10cSrcweir // no representation can be retrieved
189cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ),
190cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
191cdf0e10cSrcweir
192cdf0e10cSrcweir if ( m_nObjectState == -1 )
193cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object is not loaded!\n" ),
194cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
195cdf0e10cSrcweir
196cdf0e10cSrcweir awt::Size aResult;
197cdf0e10cSrcweir
198cdf0e10cSrcweir #ifdef WNT
199cdf0e10cSrcweir // TODO/LATER: Support different aspects
200cdf0e10cSrcweir if ( m_pOleComponent && !m_bHasSizeToSet && nAspect == embed::Aspects::MSOLE_CONTENT )
201cdf0e10cSrcweir {
202cdf0e10cSrcweir try
203cdf0e10cSrcweir {
204cdf0e10cSrcweir // the cached size updated every time the object is stored
205cdf0e10cSrcweir if ( m_bHasCachedSize )
206cdf0e10cSrcweir {
207cdf0e10cSrcweir aResult = m_aCachedSize;
208cdf0e10cSrcweir }
209cdf0e10cSrcweir else
210cdf0e10cSrcweir {
211cdf0e10cSrcweir // there is no internal cache
212cdf0e10cSrcweir awt::Size aSize;
213cdf0e10cSrcweir aGuard.clear();
214cdf0e10cSrcweir
215cdf0e10cSrcweir sal_Bool bSuccess = sal_False;
216cdf0e10cSrcweir if ( getCurrentState() == embed::EmbedStates::LOADED )
217cdf0e10cSrcweir {
218cdf0e10cSrcweir OSL_ENSURE( sal_False, "Loaded object has no cached size!\n" );
219cdf0e10cSrcweir
220cdf0e10cSrcweir // try to switch the object to RUNNING state and request the value again
221cdf0e10cSrcweir try {
222cdf0e10cSrcweir changeState( embed::EmbedStates::RUNNING );
223cdf0e10cSrcweir }
224cdf0e10cSrcweir catch( uno::Exception )
225cdf0e10cSrcweir {
226cdf0e10cSrcweir throw embed::NoVisualAreaSizeException(
227cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "No size available!\n" ) ),
228cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
229cdf0e10cSrcweir }
230cdf0e10cSrcweir }
231cdf0e10cSrcweir
232cdf0e10cSrcweir try
233cdf0e10cSrcweir {
234cdf0e10cSrcweir // first try to get size using replacement image
235cdf0e10cSrcweir aSize = m_pOleComponent->GetExtent( nAspect ); // will throw an exception in case of failure
236cdf0e10cSrcweir bSuccess = sal_True;
237cdf0e10cSrcweir }
238cdf0e10cSrcweir catch( uno::Exception& )
239cdf0e10cSrcweir {
240cdf0e10cSrcweir }
241cdf0e10cSrcweir
242cdf0e10cSrcweir if ( !bSuccess )
243cdf0e10cSrcweir {
244cdf0e10cSrcweir try
245cdf0e10cSrcweir {
246cdf0e10cSrcweir // second try the cached replacement image
247cdf0e10cSrcweir aSize = m_pOleComponent->GetCachedExtent( nAspect ); // will throw an exception in case of failure
248cdf0e10cSrcweir bSuccess = sal_True;
249cdf0e10cSrcweir }
250cdf0e10cSrcweir catch( uno::Exception& )
251cdf0e10cSrcweir {
252cdf0e10cSrcweir }
253cdf0e10cSrcweir }
254cdf0e10cSrcweir
255cdf0e10cSrcweir if ( !bSuccess )
256cdf0e10cSrcweir {
257cdf0e10cSrcweir try
258cdf0e10cSrcweir {
259cdf0e10cSrcweir // third try the size reported by the object
260cdf0e10cSrcweir aSize = m_pOleComponent->GetReccomendedExtent( nAspect ); // will throw an exception in case of failure
261cdf0e10cSrcweir bSuccess = sal_True;
262cdf0e10cSrcweir }
263cdf0e10cSrcweir catch( uno::Exception& )
264cdf0e10cSrcweir {
265cdf0e10cSrcweir }
266cdf0e10cSrcweir }
267cdf0e10cSrcweir
268cdf0e10cSrcweir if ( !bSuccess )
269cdf0e10cSrcweir throw embed::NoVisualAreaSizeException(
270cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "No size available!\n" ) ),
271cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
272cdf0e10cSrcweir
273cdf0e10cSrcweir aGuard.reset();
274cdf0e10cSrcweir
275cdf0e10cSrcweir m_aCachedSize = aSize;
276cdf0e10cSrcweir m_nCachedAspect = nAspect;
277cdf0e10cSrcweir m_bHasCachedSize = sal_True;
278cdf0e10cSrcweir
279cdf0e10cSrcweir aResult = m_aCachedSize;
280cdf0e10cSrcweir }
281cdf0e10cSrcweir }
282cdf0e10cSrcweir catch ( embed::NoVisualAreaSizeException& )
283cdf0e10cSrcweir {
284cdf0e10cSrcweir throw;
285cdf0e10cSrcweir }
286cdf0e10cSrcweir catch ( uno::Exception& )
287cdf0e10cSrcweir {
288cdf0e10cSrcweir throw embed::NoVisualAreaSizeException(
289cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "No size available!\n" ) ),
290cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
291cdf0e10cSrcweir }
292cdf0e10cSrcweir }
293cdf0e10cSrcweir else
294cdf0e10cSrcweir #endif
295cdf0e10cSrcweir {
296cdf0e10cSrcweir // return cached value
297cdf0e10cSrcweir if ( m_bHasCachedSize )
298cdf0e10cSrcweir {
299cdf0e10cSrcweir OSL_ENSURE( nAspect == m_nCachedAspect, "Unexpected aspect is requested!\n" );
300cdf0e10cSrcweir aResult = m_aCachedSize;
301cdf0e10cSrcweir }
302cdf0e10cSrcweir else
303cdf0e10cSrcweir {
304cdf0e10cSrcweir throw embed::NoVisualAreaSizeException(
305cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "No size available!\n" ) ),
306cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
307cdf0e10cSrcweir }
308cdf0e10cSrcweir }
309cdf0e10cSrcweir
310cdf0e10cSrcweir return aResult;
311cdf0e10cSrcweir }
312cdf0e10cSrcweir
getPreferredVisualRepresentation(sal_Int64 nAspect)313cdf0e10cSrcweir embed::VisualRepresentation SAL_CALL OleEmbeddedObject::getPreferredVisualRepresentation( sal_Int64 nAspect )
314cdf0e10cSrcweir throw ( lang::IllegalArgumentException,
315cdf0e10cSrcweir embed::WrongStateException,
316cdf0e10cSrcweir uno::Exception,
317cdf0e10cSrcweir uno::RuntimeException )
318cdf0e10cSrcweir {
319cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObject::getPreferredVisualRepresentation" );
320cdf0e10cSrcweir
321cdf0e10cSrcweir // begin wrapping related part ====================
322cdf0e10cSrcweir uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject;
323cdf0e10cSrcweir if ( xWrappedObject.is() )
324cdf0e10cSrcweir {
325cdf0e10cSrcweir // the object was converted to OOo embedded object, the current implementation is now only a wrapper
326cdf0e10cSrcweir return xWrappedObject->getPreferredVisualRepresentation( nAspect );
327cdf0e10cSrcweir }
328cdf0e10cSrcweir // end wrapping related part ====================
329cdf0e10cSrcweir
330cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
331cdf0e10cSrcweir if ( m_bDisposed )
332cdf0e10cSrcweir throw lang::DisposedException(); // TODO
333cdf0e10cSrcweir
334cdf0e10cSrcweir OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" );
335cdf0e10cSrcweir if ( nAspect == embed::Aspects::MSOLE_ICON )
336cdf0e10cSrcweir // no representation can be retrieved
337cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ),
338cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
339cdf0e10cSrcweir
340cdf0e10cSrcweir // TODO: if the object has cached representation then it should be returned
341cdf0e10cSrcweir // TODO: if the object has no cached representation and is in loaded state it should switch itself to the running state
342cdf0e10cSrcweir if ( m_nObjectState == -1 )
343cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object is not loaded!\n" ),
344cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
345cdf0e10cSrcweir
346cdf0e10cSrcweir embed::VisualRepresentation aVisualRepr;
347cdf0e10cSrcweir
348cdf0e10cSrcweir // TODO: in case of different aspects they must be applied to the mediatype and XTransferable must be used
349cdf0e10cSrcweir // the cache is used only as a fallback if object is not in loaded state
350cdf0e10cSrcweir if ( !m_xCachedVisualRepresentation.is() && ( !m_bVisReplInitialized || m_bVisReplInStream )
351cdf0e10cSrcweir && m_nObjectState == embed::EmbedStates::LOADED )
352cdf0e10cSrcweir {
353cdf0e10cSrcweir m_xCachedVisualRepresentation = TryToRetrieveCachedVisualRepresentation_Impl( m_xObjectStream, sal_True );
354cdf0e10cSrcweir SetVisReplInStream( m_xCachedVisualRepresentation.is() );
355cdf0e10cSrcweir }
356cdf0e10cSrcweir
357cdf0e10cSrcweir if ( m_xCachedVisualRepresentation.is() )
358cdf0e10cSrcweir {
359cdf0e10cSrcweir return GetVisualRepresentationInNativeFormat_Impl( m_xCachedVisualRepresentation );
360cdf0e10cSrcweir }
361cdf0e10cSrcweir #ifdef WNT
362cdf0e10cSrcweir else if ( m_pOleComponent )
363cdf0e10cSrcweir {
364cdf0e10cSrcweir try
365cdf0e10cSrcweir {
366cdf0e10cSrcweir if ( m_nObjectState == embed::EmbedStates::LOADED )
367cdf0e10cSrcweir changeState( embed::EmbedStates::RUNNING );
368cdf0e10cSrcweir
369cdf0e10cSrcweir datatransfer::DataFlavor aDataFlavor(
370cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"" ),
371cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "Windows Metafile" ),
372cdf0e10cSrcweir ::getCppuType( (const uno::Sequence< sal_Int8 >*) NULL ) );
373cdf0e10cSrcweir
374cdf0e10cSrcweir aVisualRepr.Data = m_pOleComponent->getTransferData( aDataFlavor );
375cdf0e10cSrcweir aVisualRepr.Flavor = aDataFlavor;
376cdf0e10cSrcweir
377cdf0e10cSrcweir uno::Sequence< sal_Int8 > aVisReplSeq;
378cdf0e10cSrcweir aVisualRepr.Data >>= aVisReplSeq;
379cdf0e10cSrcweir if ( aVisReplSeq.getLength() )
380cdf0e10cSrcweir {
381cdf0e10cSrcweir m_xCachedVisualRepresentation = GetNewFilledTempStream_Impl(
382cdf0e10cSrcweir uno::Reference< io::XInputStream > ( static_cast< io::XInputStream* > (
383cdf0e10cSrcweir new ::comphelper::SequenceInputStream( aVisReplSeq ) ) ) );
384cdf0e10cSrcweir }
385cdf0e10cSrcweir
386cdf0e10cSrcweir return aVisualRepr;
387cdf0e10cSrcweir }
388cdf0e10cSrcweir catch( uno::Exception& )
389cdf0e10cSrcweir {}
390cdf0e10cSrcweir }
391cdf0e10cSrcweir #endif
392cdf0e10cSrcweir
393cdf0e10cSrcweir // the cache is used only as a fallback if object is not in loaded state
394cdf0e10cSrcweir if ( !m_xCachedVisualRepresentation.is() && ( !m_bVisReplInitialized || m_bVisReplInStream ) )
395cdf0e10cSrcweir {
396cdf0e10cSrcweir m_xCachedVisualRepresentation = TryToRetrieveCachedVisualRepresentation_Impl( m_xObjectStream );
397cdf0e10cSrcweir SetVisReplInStream( m_xCachedVisualRepresentation.is() );
398cdf0e10cSrcweir }
399cdf0e10cSrcweir
400cdf0e10cSrcweir if ( !m_xCachedVisualRepresentation.is() )
401cdf0e10cSrcweir {
402cdf0e10cSrcweir // no representation can be retrieved
403cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ),
404cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
405cdf0e10cSrcweir }
406cdf0e10cSrcweir
407cdf0e10cSrcweir return GetVisualRepresentationInNativeFormat_Impl( m_xCachedVisualRepresentation );
408cdf0e10cSrcweir }
409cdf0e10cSrcweir
getMapUnit(sal_Int64 nAspect)410cdf0e10cSrcweir sal_Int32 SAL_CALL OleEmbeddedObject::getMapUnit( sal_Int64 nAspect )
411cdf0e10cSrcweir throw ( uno::Exception,
412cdf0e10cSrcweir uno::RuntimeException)
413cdf0e10cSrcweir {
414cdf0e10cSrcweir // begin wrapping related part ====================
415cdf0e10cSrcweir uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject;
416cdf0e10cSrcweir if ( xWrappedObject.is() )
417cdf0e10cSrcweir {
418cdf0e10cSrcweir // the object was converted to OOo embedded object, the current implementation is now only a wrapper
419cdf0e10cSrcweir return xWrappedObject->getMapUnit( nAspect );
420cdf0e10cSrcweir }
421cdf0e10cSrcweir // end wrapping related part ====================
422cdf0e10cSrcweir
423cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
424cdf0e10cSrcweir if ( m_bDisposed )
425cdf0e10cSrcweir throw lang::DisposedException(); // TODO
426cdf0e10cSrcweir
427cdf0e10cSrcweir OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" );
428cdf0e10cSrcweir if ( nAspect == embed::Aspects::MSOLE_ICON )
429cdf0e10cSrcweir // no representation can be retrieved
430cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ),
431cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
432cdf0e10cSrcweir
433cdf0e10cSrcweir if ( m_nObjectState == -1 )
434cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object is not loaded!\n" ),
435cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
436cdf0e10cSrcweir
437cdf0e10cSrcweir return embed::EmbedMapUnits::ONE_100TH_MM;
438cdf0e10cSrcweir }
439cdf0e10cSrcweir
440cdf0e10cSrcweir
441