1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_EMBEDDEDOBJ_SOURCE_INC_OLEEMBOBJ_HXX
21 #define INCLUDED_EMBEDDEDOBJ_SOURCE_INC_OLEEMBOBJ_HXX
23 #include <com/sun/star/uno/Sequence.hxx>
24 #include <com/sun/star/uno/Reference.hxx>
25 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
26 #include <com/sun/star/embed/XEmbeddedObject.hpp>
27 #include <com/sun/star/embed/XEmbeddedOleObject.hpp>
28 #include <com/sun/star/embed/XInplaceObject.hpp>
29 #include <com/sun/star/embed/XEmbedPersist.hpp>
30 #include <com/sun/star/embed/XLinkageSupport.hpp>
31 #include <com/sun/star/embed/VerbDescriptor.hpp>
32 #include <com/sun/star/container/XChild.hpp>
33 #include <com/sun/star/util/XCloseable.hpp>
34 #include <com/sun/star/util/XCloseListener.hpp>
35 #include <com/sun/star/io/XActiveDataStreamer.hpp>
36 #include <com/sun/star/lang/XInitialization.hpp>
37 #include <cppuhelper/implbase.hxx>
38 #include <rtl/ref.hxx>
40 #include <osl/thread.h>
44 class OMultiTypeInterfaceContainerHelper
;
47 class VerbExecutionController
49 // the following mutex is allowed to be locked only for variables initialization, so no deadlock can be caused
50 ::osl::Mutex m_aVerbExecutionMutex
;
52 sal_Int32 m_nNotificationLock
;
55 bool m_bWasEverActive
;
56 bool m_bVerbExecutionInProgress
;
57 oslThreadIdentifier m_nVerbExecutionThreadIdentifier
;
58 bool m_bChangedOnVerbExecution
;
63 VerbExecutionController()
64 : m_nNotificationLock( 0 )
66 , m_bWasEverActive( false )
67 , m_bVerbExecutionInProgress( false )
68 , m_nVerbExecutionThreadIdentifier( 0 )
69 , m_bChangedOnVerbExecution( false )
74 void StartControlExecution();
75 bool EndControlExecution_WasModified();
76 void ModificationNotificationIsDone();
77 // no need to lock anything to check the value of the numeric members
78 bool CanDoNotification() { return ( !m_bVerbExecutionInProgress
&& !m_bWasEverActive
&& !m_nNotificationLock
); }
79 // ... or to change it
80 void ObjectIsActive() { m_bWasEverActive
= true; }
82 void LockNotification();
83 void UnlockNotification();
86 class VerbExecutionControllerGuard
88 VerbExecutionController
& m_rController
;
91 VerbExecutionControllerGuard( VerbExecutionController
& rController
)
92 : m_rController( rController
)
94 m_rController
.LockNotification();
97 ~VerbExecutionControllerGuard()
99 m_rController
.UnlockNotification();
107 * Represents an OLE object that has native data and we try to let an external
108 * application handle that data.
110 class OleEmbeddedObject
: public ::cppu::WeakImplHelper
111 < css::embed::XEmbeddedObject
112 , css::embed::XEmbeddedOleObject
113 , css::embed::XEmbedPersist
114 , css::embed::XLinkageSupport
115 , css::embed::XInplaceObject
116 , css::container::XChild
117 , css::io::XActiveDataStreamer
118 , css::lang::XInitialization
>
120 friend class OleComponent
;
122 ::osl::Mutex m_aMutex
;
124 OleComponent
* m_pOleComponent
;
126 std::unique_ptr
<::cppu::OMultiTypeInterfaceContainerHelper
> m_pInterfaceContainer
;
131 sal_Int32 m_nObjectState
;
132 sal_Int32 m_nTargetState
;
133 sal_Int32 m_nUpdateMode
;
135 css::uno::Reference
< css::lang::XMultiServiceFactory
> m_xFactory
;
137 css::uno::Sequence
< sal_Int8
> m_aClassID
;
138 OUString m_aClassName
;
140 css::uno::Reference
< css::embed::XEmbeddedClient
> m_xClientSite
;
142 OUString m_aContainerName
;
144 css::uno::Reference
< css::util::XCloseListener
> m_xClosePreventer
;
146 bool m_bWaitSaveCompleted
;
147 bool m_bNewVisReplInStream
;
148 css::uno::Reference
< css::io::XStream
> m_xNewCachedVisRepl
;
149 OUString m_aNewEntryName
;
150 css::uno::Reference
< css::embed::XStorage
> m_xNewParentStorage
;
151 css::uno::Reference
< css::io::XStream
> m_xNewObjectStream
;
154 css::uno::Reference
< css::io::XStream
> m_xCachedVisualRepresentation
;
155 bool m_bVisReplInitialized
;
156 bool m_bVisReplInStream
;
157 bool m_bStoreVisRepl
;
161 // TODO/LATER: may need to cache more than one aspect in future
162 bool m_bHasCachedSize
; // the object has cached size
163 css::awt::Size m_aCachedSize
;
164 sal_Int64 m_nCachedAspect
;
166 bool m_bHasSizeToSet
; // the object has cached size that should be set to OLE component
167 css::awt::Size m_aSizeToSet
; // this size might be different from the cached one ( scaling is applied )
168 sal_Int64 m_nAspectToSet
;
171 // cache the status of the object
172 // TODO/LATER: may need to cache more than one aspect in future
175 sal_Int64 m_nStatusAspect
;
177 // embedded object related stuff
178 OUString m_aEntryName
;
179 css::uno::Reference
< css::embed::XStorage
> m_xParentStorage
;
180 css::uno::Reference
< css::io::XStream
> m_xObjectStream
;
182 // link related stuff
183 OUString m_aLinkURL
; // ???
185 // points to own view provider if the object has no server
186 rtl::Reference
<OwnView_Impl
> m_xOwnView
;
188 // whether the object should be initialized from clipboard in case of default initialization
189 bool m_bFromClipboard
;
193 OUString m_aTempDumpURL
;
196 // the following member is used during verb execution to detect whether the verb execution modifies the object
197 VerbExecutionController m_aVerbExecutionController
;
199 // if the following member is set, the object works in wrapper mode
200 css::uno::Reference
< css::embed::XEmbeddedObject
> m_xWrappedObject
;
201 bool m_bTriedConversion
;
202 OUString m_aFilterName
; // if m_bTriedConversion, then the filter detected by that
204 css::uno::Reference
< css::uno::XInterface
> m_xParent
;
206 /// If it is allowed to modify entries in the stream of the OLE storage.
207 bool m_bStreamReadOnly
= false;
210 /// @throws css::uno::Exception
211 css::uno::Reference
< css::io::XStream
> TryToGetAcceptableFormat_Impl(
212 const css::uno::Reference
< css::io::XStream
>& xStream
);
214 /// @throws css::io::IOException
215 /// @throws css::uno::RuntimeException
216 css::uno::Reference
< css::io::XStream
> GetNewFilledTempStream_Impl(
217 const css::uno::Reference
< css::io::XInputStream
>& xInStream
);
219 void SwitchComponentToRunningState_Impl();
221 void MakeEventListenerNotification_Impl( const OUString
& aEventName
);
223 void StateChangeNotification_Impl( bool bBeforeChange
, sal_Int32 nOldState
, sal_Int32 nNewState
);
224 css::uno::Reference
< css::io::XOutputStream
> GetStreamForSaving();
227 css::uno::Sequence
< sal_Int32
> GetIntermediateVerbsSequence_Impl( sal_Int32 nNewState
);
229 static css::uno::Sequence
< sal_Int32
> GetReachableStatesList_Impl(
230 const css::uno::Sequence
< css::embed::VerbDescriptor
>& aVerbList
);
235 void SwitchOwnPersistence(
236 const css::uno::Reference
< css::embed::XStorage
>& xNewParentStorage
,
237 const css::uno::Reference
< css::io::XStream
>& xNewObjectStream
,
238 const OUString
& aNewName
);
240 void SwitchOwnPersistence(
241 const css::uno::Reference
< css::embed::XStorage
>& xNewParentStorage
,
242 const OUString
& aNewName
);
244 void GetRidOfComponent();
246 /// @throws css::uno::Exception
247 void StoreToLocation_Impl(
248 const css::uno::Reference
< css::embed::XStorage
>& xStorage
,
249 const OUString
& sEntName
,
250 const css::uno::Sequence
< css::beans::PropertyValue
>& lObjArgs
,
253 /// @throws css::uno::Exception
254 void StoreObjectToStream( css::uno::Reference
< css::io::XOutputStream
> const & xOutStream
);
256 /// @throws css::uno::Exception
257 void InsertVisualCache_Impl(
258 const css::uno::Reference
< css::io::XStream
>& xTargetStream
,
259 const css::uno::Reference
< css::io::XStream
>& xCachedVisualRepresentation
);
261 /// @throws css::uno::Exception
262 void RemoveVisualCache_Impl( const css::uno::Reference
< css::io::XStream
>& xTargetStream
);
264 void SetVisReplInStream( bool bExists
);
265 bool HasVisReplInStream();
267 /// @throws css::uno::Exception
268 css::embed::VisualRepresentation
GetVisualRepresentationInNativeFormat_Impl(
269 const css::uno::Reference
< css::io::XStream
>& xCachedVisRepr
);
271 css::uno::Reference
< css::io::XStream
> TryToRetrieveCachedVisualRepresentation_Impl(
272 const css::uno::Reference
< css::io::XStream
>& xStream
,
273 bool bAllowRepair50
= false )
276 bool SaveObject_Impl();
277 bool OnShowWindow_Impl( bool bShow
);
278 void CreateOleComponent_Impl( OleComponent
* pOleComponent
= nullptr );
279 void CreateOleComponentAndLoad_Impl( OleComponent
* pOleComponent
= nullptr );
280 void CreateOleComponentFromClipboard_Impl( OleComponent
* pOleComponent
= nullptr );
281 OUString
CreateTempURLEmpty_Impl();
282 OUString
GetTempURL_Impl();
283 void SetObjectIsLink_Impl( bool bIsLink
) { m_bIsLink
= bIsLink
; }
286 // the following 4 methods are related to switch to wrapping mode
287 void MoveListeners();
288 css::uno::Reference
< css::embed::XStorage
> CreateTemporarySubstorage( OUString
& o_aStorageName
);
289 OUString
MoveToTemporarySubstream();
290 bool TryToConvertToOOo( const css::uno::Reference
< css::io::XStream
>& xStream
);
293 // in case a new object must be created the class ID must be specified
294 OleEmbeddedObject( const css::uno::Reference
< css::lang::XMultiServiceFactory
>& xFactory
,
295 const css::uno::Sequence
< sal_Int8
>& aClassID
,
296 const OUString
& aClassName
);
298 // in case object will be loaded from a persistent entry or from a file the class ID will be detected on loading
299 // factory can do it for OOo objects, but for OLE objects OS dependent code is required
300 OleEmbeddedObject( const css::uno::Reference
< css::lang::XMultiServiceFactory
>& xFactory
,
303 // this constructor let object be initialized from clipboard
304 OleEmbeddedObject( const css::uno::Reference
< css::lang::XMultiServiceFactory
>& xFactory
);
307 virtual ~OleEmbeddedObject() override
;
310 static void OnIconChanged_Impl();
311 void OnViewChanged_Impl();
312 void OnClosed_Impl();
317 virtual void SAL_CALL
changeState( sal_Int32 nNewState
) override
;
319 virtual css::uno::Sequence
< sal_Int32
> SAL_CALL
getReachableStates() override
;
321 virtual sal_Int32 SAL_CALL
getCurrentState() override
;
323 virtual void SAL_CALL
doVerb( sal_Int32 nVerbID
) override
;
325 virtual css::uno::Sequence
< css::embed::VerbDescriptor
> SAL_CALL
getSupportedVerbs() override
;
327 virtual void SAL_CALL
setClientSite(
328 const css::uno::Reference
< css::embed::XEmbeddedClient
>& xClient
) override
;
330 virtual css::uno::Reference
< css::embed::XEmbeddedClient
> SAL_CALL
getClientSite() override
;
332 virtual void SAL_CALL
update() override
;
334 virtual void SAL_CALL
setUpdateMode( sal_Int32 nMode
) override
;
336 virtual sal_Int64 SAL_CALL
getStatus( sal_Int64 nAspect
) override
;
338 virtual void SAL_CALL
setContainerName( const OUString
& sName
) override
;
343 virtual void SAL_CALL
setVisualAreaSize( sal_Int64 nAspect
, const css::awt::Size
& aSize
) override
;
345 virtual css::awt::Size SAL_CALL
getVisualAreaSize( sal_Int64 nAspect
) override
;
347 virtual css::embed::VisualRepresentation SAL_CALL
getPreferredVisualRepresentation( ::sal_Int64 nAspect
) override
;
349 virtual sal_Int32 SAL_CALL
getMapUnit( sal_Int64 nAspect
) override
;
354 virtual void SAL_CALL
setPersistentEntry(
355 const css::uno::Reference
< css::embed::XStorage
>& xStorage
,
356 const OUString
& sEntName
,
357 sal_Int32 nEntryConnectionMode
,
358 const css::uno::Sequence
< css::beans::PropertyValue
>& lArguments
,
359 const css::uno::Sequence
< css::beans::PropertyValue
>& lObjArgs
) override
;
361 virtual void SAL_CALL
storeToEntry( const css::uno::Reference
< css::embed::XStorage
>& xStorage
, const OUString
& sEntName
, const css::uno::Sequence
< css::beans::PropertyValue
>& lArguments
, const css::uno::Sequence
< css::beans::PropertyValue
>& lObjArgs
) override
;
363 virtual void SAL_CALL
storeAsEntry(
364 const css::uno::Reference
< css::embed::XStorage
>& xStorage
,
365 const OUString
& sEntName
,
366 const css::uno::Sequence
< css::beans::PropertyValue
>& lArguments
,
367 const css::uno::Sequence
< css::beans::PropertyValue
>& lObjArgs
) override
;
369 virtual void SAL_CALL
saveCompleted( sal_Bool bUseNew
) override
;
371 virtual sal_Bool SAL_CALL
hasEntry() override
;
373 virtual OUString SAL_CALL
getEntryName() override
;
377 virtual void SAL_CALL
breakLink( const css::uno::Reference
< css::embed::XStorage
>& xStorage
,
378 const OUString
& sEntName
) override
;
380 virtual sal_Bool SAL_CALL
isLink() override
;
382 virtual OUString SAL_CALL
getLinkURL() override
;
384 // XCommonEmbedPersist
385 virtual void SAL_CALL
storeOwn() override
;
387 virtual sal_Bool SAL_CALL
isReadonly() override
;
389 virtual void SAL_CALL
reload(
390 const css::uno::Sequence
< css::beans::PropertyValue
>& lArguments
,
391 const css::uno::Sequence
< css::beans::PropertyValue
>& lObjArgs
) override
;
395 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
getClassID() override
;
397 virtual OUString SAL_CALL
getClassName() override
;
399 virtual void SAL_CALL
setClassInfo(
400 const css::uno::Sequence
< sal_Int8
>& aClassID
, const OUString
& aClassName
) override
;
402 // XStateChangeBroadcaster
403 virtual void SAL_CALL
addStateChangeListener( const css::uno::Reference
< css::embed::XStateChangeListener
>& xListener
) override
;
404 virtual void SAL_CALL
removeStateChangeListener( const css::uno::Reference
< css::embed::XStateChangeListener
>& xListener
) override
;
407 // XComponentSupplier
409 virtual css::uno::Reference
< css::util::XCloseable
> SAL_CALL
getComponent() override
;
413 virtual void SAL_CALL
close( sal_Bool DeliverOwnership
) override
;
415 virtual void SAL_CALL
addCloseListener(
416 const css::uno::Reference
< css::util::XCloseListener
>& Listener
) override
;
418 virtual void SAL_CALL
removeCloseListener(
419 const css::uno::Reference
< css::util::XCloseListener
>& Listener
) override
;
422 virtual void SAL_CALL
addEventListener(
423 const css::uno::Reference
< css::document::XEventListener
>& Listener
) override
;
425 virtual void SAL_CALL
removeEventListener(
426 const css::uno::Reference
< css::document::XEventListener
>& Listener
) override
;
428 // XInplaceObject ( only for wrapping scenario here )
430 virtual void SAL_CALL
setObjectRectangles( const css::awt::Rectangle
& aPosRect
,
431 const css::awt::Rectangle
& aClipRect
) override
;
433 virtual void SAL_CALL
enableModeless( sal_Bool bEnable
) override
;
435 virtual void SAL_CALL
translateAccelerators(
436 const css::uno::Sequence
< css::awt::KeyEvent
>& aKeys
) override
;
438 // XChild ( only for wrapping scenario here )
439 virtual css::uno::Reference
< css::uno::XInterface
> SAL_CALL
getParent( ) override
;
440 virtual void SAL_CALL
setParent( const css::uno::Reference
< css::uno::XInterface
>& Parent
) override
;
442 // XActiveDataStreamer
443 void SAL_CALL
setStream(const css::uno::Reference
<css::io::XStream
>& xStream
) override
;
444 css::uno::Reference
<css::io::XStream
> SAL_CALL
getStream() override
;
447 void SAL_CALL
initialize(const css::uno::Sequence
<css::uno::Any
>& rArguments
) override
;
452 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */