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 .
22 #include <com/sun/star/uno/Sequence.hxx>
23 #include <com/sun/star/uno/Reference.hxx>
24 #include <com/sun/star/uno/Any.hxx>
25 #include <com/sun/star/container/XChild.hpp>
26 #include <com/sun/star/document/XStorageBasedDocument.hpp>
27 #include <com/sun/star/embed/XEmbeddedObject.hpp>
28 #include <com/sun/star/embed/XEmbedPersist2.hpp>
29 #include <com/sun/star/embed/XLinkageSupport.hpp>
30 #include <com/sun/star/embed/XInplaceObject.hpp>
31 #include <com/sun/star/awt/XWindow.hpp>
32 #include <com/sun/star/awt/Rectangle.hpp>
33 #include <com/sun/star/util/XCloseable.hpp>
34 #include <com/sun/star/chart2/XDefaultSizeTransmitter.hpp>
35 #include <com/sun/star/io/XTempFile.hpp>
36 #include <com/sun/star/lang/XServiceInfo.hpp>
37 #include <com/sun/star/lang/XInitialization.hpp>
38 #include <cppuhelper/weak.hxx>
39 #include <embeddedobj/embeddedupdate.hxx>
40 #include <rtl/ref.hxx>
43 #include <svtools/filechangedchecker.hxx>
44 #include <unotools/resmgr.hxx>
46 namespace com::sun::star
{
51 class XMultiServiceFactory
;
62 namespace comphelper
{
63 class OMultiTypeInterfaceContainerHelper2
;
66 namespace comphelper
{
67 class NamedValueCollection
;
70 #define NUM_SUPPORTED_STATES 5
71 // #define NUM_SUPPORTED_VERBS 5
73 #include "docholder.hxx"
75 namespace embeddedobj
{ class Interceptor
; }
78 * Represents an OLE object that has native data and we loaded that data into a
79 * document model successfully.
81 class OCommonEmbeddedObject
: public css::embed::XEmbeddedObject
82 , public css::embed::EmbeddedUpdate
83 , public css::embed::XEmbedPersist2
84 , public css::embed::XLinkageSupport
85 , public css::embed::XInplaceObject
86 , public css::container::XChild
87 , public css::chart2::XDefaultSizeTransmitter
88 , public css::lang::XServiceInfo
89 , public css::lang::XInitialization
90 , public css::lang::XTypeProvider
91 , public ::cppu::OWeakObject
94 ::osl::Mutex m_aMutex
;
96 rtl::Reference
<embeddedobj::DocumentHolder
> m_xDocHolder
;
98 std::unique_ptr
<::comphelper::OMultiTypeInterfaceContainerHelper2
> m_pInterfaceContainer
;
105 sal_Int32 m_nObjectState
;
106 sal_Int32 m_nTargetState
; // should be -1 except during state changing
107 sal_Int32 m_nUpdateMode
;
109 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
111 css::uno::Sequence
< css::beans::PropertyValue
> m_aDocMediaDescriptor
;
113 css::uno::Sequence
< sal_Int8
> m_aClassID
;
114 OUString m_aClassName
;
116 OUString m_aDocServiceName
;
117 OUString m_aPresetFilterName
;
119 sal_Int64 m_nMiscStatus
;
121 css::uno::Sequence
< css::embed::VerbDescriptor
> m_aObjectVerbs
;
123 std::map
< sal_Int32
, sal_Int32
> m_aVerbTable
;
125 css::uno::Reference
< css::embed::XEmbeddedClient
> m_xClientSite
;
127 OUString m_aContainerName
;
128 OUString m_aDefaultParentBaseURL
;
129 OUString m_aModuleName
;
130 bool m_bEmbeddedScriptSupport
;
131 bool m_bDocumentRecoverySupport
;
133 // following information will be used between SaveAs and SaveCompleted
134 bool m_bWaitSaveCompleted
;
135 OUString m_aNewEntryName
;
136 css::uno::Reference
< css::embed::XStorage
> m_xNewParentStorage
;
137 css::uno::Reference
< css::embed::XStorage
> m_xNewObjectStorage
;
138 css::uno::Sequence
< css::beans::PropertyValue
> m_aNewDocMediaDescriptor
;
140 css::uno::Reference
< css::awt::XWindow
> m_xClientWindow
; // ???
141 css::awt::Rectangle m_aOwnRectangle
;
142 css::awt::Rectangle m_aClipRectangle
;
145 bool m_bLinkTempFileChanged
;
146 ::std::unique_ptr
< FileChangedChecker
> m_pLinkFile
;
150 // embedded object related stuff
151 OUString m_aEntryName
;
152 css::uno::Reference
< css::embed::XStorage
> m_xParentStorage
;
153 css::uno::Reference
< css::embed::XStorage
> m_xObjectStorage
;
154 css::uno::Reference
< css::embed::XStorage
> m_xRecoveryStorage
;
156 // link related stuff
158 OUString m_aLinkFilterName
;
159 bool m_bLinkHasPassword
;
160 OUString m_aLinkPassword
;
162 // tdf#141529 hold a cc of a linked OLE
163 css::uno::Reference
< css::io::XTempFile
> m_aLinkTempFile
;
165 css::uno::Reference
< css::uno::XInterface
> m_xParent
;
167 bool m_bHasClonedSize
; // the object has cached size
168 css::awt::Size m_aClonedSize
;
169 sal_Int32 m_nClonedMapUnit
;
170 css::awt::Size m_aDefaultSizeForChart_In_100TH_MM
;//#i103460# charts do not necessarily have an own size within ODF files, in this case they need to use the size settings from the surrounding frame, which is made available with this member
173 void CommonInit_Impl( const css::uno::Sequence
< css::beans::NamedValue
>& aObjectProps
);
175 void LinkInit_Impl( const css::uno::Sequence
< css::beans::NamedValue
>& aObjectProps
,
176 const css::uno::Sequence
< css::beans::PropertyValue
>& aMediaDescr
,
177 const css::uno::Sequence
< css::beans::PropertyValue
>& aObjectDescr
);
180 void SwitchOwnPersistence(
181 const css::uno::Reference
< css::embed::XStorage
>& xNewParentStorage
,
182 const css::uno::Reference
< css::embed::XStorage
>& xNewObjectStorage
,
183 const OUString
& aNewName
);
185 void SwitchOwnPersistence(
186 const css::uno::Reference
< css::embed::XStorage
>& xNewParentStorage
,
187 const OUString
& aNewName
);
189 const OUString
& GetDocumentServiceName() const { return m_aDocServiceName
; }
190 const OUString
& GetPresetFilterName() const { return m_aPresetFilterName
; }
192 css::uno::Reference
< css::io::XInputStream
>
193 StoreDocumentToTempStream_Impl( sal_Int32 nStorageFormat
,
194 const OUString
& aBaseURL
,
195 const OUString
& aHierarchName
);
197 sal_Int32
ConvertVerbToState_Impl( sal_Int32 nVerb
);
201 // when State = CopyTempToLink -> the user pressed the save button
202 // when change in embedded part then copy to the linked-file
203 // CopyLinkToTemp -> the user pressed the refresh button
204 // when change in linked-file then copy to the embedded part (temp-file)
205 // CopyLinkToTempInit -> create the temp file
206 // CopyLinkToTempRefresh -> when save and Link change but not temp then update temp
207 enum class CopyBackToOLELink
{NoCopy
, CopyTempToLink
, CopyLinkToTemp
, CopyLinkToTempInit
, CopyLinkToTempRefresh
};
209 void handleLinkedOLE( CopyBackToOLELink eState
);
211 void StateChangeNotification_Impl( bool bBeforeChange
, sal_Int32 nOldState
, sal_Int32 nNewState
,::osl::ResettableMutexGuard
& _rGuard
);
213 void SwitchStateTo_Impl( sal_Int32 nNextState
);
215 css::uno::Sequence
< sal_Int32
> const & GetIntermediateStatesSequence_Impl( sal_Int32 nNewState
);
217 OUString
GetFilterName( sal_Int32 nVersion
) const;
218 css::uno::Reference
< css::util::XCloseable
> LoadDocumentFromStorage_Impl();
220 css::uno::Reference
< css::util::XCloseable
> LoadLink_Impl();
222 css::uno::Reference
< css::util::XCloseable
> InitNewDocument_Impl();
224 void StoreDocToStorage_Impl(
225 const css::uno::Reference
<css::embed::XStorage
>& xStorage
,
226 const css::uno::Sequence
<css::beans::PropertyValue
>& rMediaArgs
,
227 const css::uno::Sequence
<css::beans::PropertyValue
>& rObjArgs
,
228 sal_Int32 nStorageVersion
,
229 const OUString
& aHierarchName
,
230 bool bAttachToStorage
);
232 void SwitchDocToStorage_Impl(
233 const css::uno::Reference
< css::document::XStorageBasedDocument
>& xDoc
,
234 const css::uno::Reference
< css::embed::XStorage
>& xStorage
);
236 void FillDefaultLoadArgs_Impl(
237 const css::uno::Reference
< css::embed::XStorage
>& i_rxStorage
,
238 ::comphelper::NamedValueCollection
& o_rLoadArgs
241 void EmbedAndReparentDoc_Impl(
242 const css::uno::Reference
< css::util::XCloseable
>& i_rxDocument
245 css::uno::Reference
< css::util::XCloseable
> CreateDocFromMediaDescr_Impl(
246 const css::uno::Sequence
< css::beans::PropertyValue
>& aMedDescr
);
248 css::uno::Reference
< css::util::XCloseable
> CreateTempDocFromLink_Impl();
250 OUString
GetBaseURL_Impl() const;
251 static OUString
GetBaseURLFrom_Impl(
252 const css::uno::Sequence
< css::beans::PropertyValue
>& lArguments
,
253 const css::uno::Sequence
< css::beans::PropertyValue
>& lObjArgs
);
255 int ShowMsgDialog(TranslateId Msg
, const OUString
& sFileName
);
257 bool getAllowLinkUpdate() const;
260 void SetInplaceActiveState();
263 OCommonEmbeddedObject(
264 css::uno::Reference
< css::uno::XComponentContext
> xContext
,
265 const css::uno::Sequence
< css::beans::NamedValue
>& aObjectProps
);
267 // no persistence for linked objects, so the descriptors are provided in constructor
268 OCommonEmbeddedObject(
269 css::uno::Reference
< css::uno::XComponentContext
> xContext
,
270 const css::uno::Sequence
< css::beans::NamedValue
>& aObjectProps
,
271 const css::uno::Sequence
< css::beans::PropertyValue
>& aMediaDescr
,
272 const css::uno::Sequence
< css::beans::PropertyValue
>& aObjectDescr
);
274 virtual ~OCommonEmbeddedObject() override
;
276 void SaveObject_Impl();
278 void requestPositioning( const css::awt::Rectangle
& aRect
);
280 // not a real listener and should not be
281 void PostEvent_Impl( const OUString
& aEventName
);
283 OUString
const & getContainerName() const { return m_aContainerName
; }
286 virtual css::uno::Any SAL_CALL
queryInterface( const css::uno::Type
& rType
) override
;
288 virtual void SAL_CALL
acquire()
291 virtual void SAL_CALL
release()
296 virtual void SAL_CALL
changeState( sal_Int32 nNewState
) override
;
298 virtual css::uno::Sequence
< sal_Int32
> SAL_CALL
getReachableStates() override
;
300 virtual sal_Int32 SAL_CALL
getCurrentState() override
;
302 virtual void SAL_CALL
doVerb( sal_Int32 nVerbID
) override
;
304 virtual css::uno::Sequence
< css::embed::VerbDescriptor
> SAL_CALL
getSupportedVerbs() override
;
306 virtual void SAL_CALL
setClientSite(
307 const css::uno::Reference
< css::embed::XEmbeddedClient
>& xClient
) override
;
309 virtual css::uno::Reference
< css::embed::XEmbeddedClient
> SAL_CALL
getClientSite() override
;
311 virtual void SAL_CALL
update() override
;
313 virtual void SAL_CALL
setUpdateMode( sal_Int32 nMode
) override
;
315 virtual sal_Int64 SAL_CALL
getStatus( sal_Int64 nAspect
) override
;
317 virtual void SAL_CALL
setContainerName( const OUString
& sName
) override
;
321 virtual void SetOleState(bool bIsOleUpdate
) override
;
326 virtual void SAL_CALL
setVisualAreaSize( sal_Int64 nAspect
, const css::awt::Size
& aSize
) override
;
328 virtual css::awt::Size SAL_CALL
getVisualAreaSize( sal_Int64 nAspect
) override
;
330 virtual css::embed::VisualRepresentation SAL_CALL
getPreferredVisualRepresentation( ::sal_Int64 nAspect
) override
;
332 virtual sal_Int32 SAL_CALL
getMapUnit( sal_Int64 nAspect
) override
;
336 virtual void SAL_CALL
setPersistentEntry(
337 const css::uno::Reference
< css::embed::XStorage
>& xStorage
,
338 const OUString
& sEntName
,
339 sal_Int32 nEntryConnectionMode
,
340 const css::uno::Sequence
< css::beans::PropertyValue
>& lArguments
,
341 const css::uno::Sequence
< css::beans::PropertyValue
>& lObjArgs
) override
;
343 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
;
345 virtual void SAL_CALL
storeAsEntry(
346 const css::uno::Reference
< css::embed::XStorage
>& xStorage
,
347 const OUString
& sEntName
,
348 const css::uno::Sequence
< css::beans::PropertyValue
>& lArguments
,
349 const css::uno::Sequence
< css::beans::PropertyValue
>& lObjArgs
) override
;
351 virtual void SAL_CALL
saveCompleted( sal_Bool bUseNew
) override
;
353 virtual sal_Bool SAL_CALL
hasEntry() override
;
355 virtual OUString SAL_CALL
getEntryName() override
;
359 virtual void SAL_CALL
breakLink( const css::uno::Reference
< css::embed::XStorage
>& xStorage
,
360 const OUString
& sEntName
) override
;
362 virtual sal_Bool SAL_CALL
isLink() override
;
364 virtual OUString SAL_CALL
getLinkURL() override
;
367 // XCommonEmbedPersist
369 virtual void SAL_CALL
storeOwn() override
;
371 virtual sal_Bool SAL_CALL
isReadonly() override
;
373 virtual void SAL_CALL
reload(
374 const css::uno::Sequence
< css::beans::PropertyValue
>& lArguments
,
375 const css::uno::Sequence
< css::beans::PropertyValue
>& lObjArgs
) override
;
379 virtual sal_Bool SAL_CALL
isStored() override
;
383 virtual void SAL_CALL
setObjectRectangles( const css::awt::Rectangle
& aPosRect
,
384 const css::awt::Rectangle
& aClipRect
) override
;
386 virtual void SAL_CALL
enableModeless( sal_Bool bEnable
) override
;
388 virtual void SAL_CALL
translateAccelerators(
389 const css::uno::Sequence
< css::awt::KeyEvent
>& aKeys
) override
;
393 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
getClassID() override
;
395 virtual OUString SAL_CALL
getClassName() override
;
397 virtual void SAL_CALL
setClassInfo(
398 const css::uno::Sequence
< sal_Int8
>& aClassID
, const OUString
& aClassName
) override
;
401 // XComponentSupplier
403 virtual css::uno::Reference
< css::util::XCloseable
> SAL_CALL
getComponent() override
;
405 // XStateChangeBroadcaster
406 virtual void SAL_CALL
addStateChangeListener( const css::uno::Reference
< css::embed::XStateChangeListener
>& xListener
) override
;
407 virtual void SAL_CALL
removeStateChangeListener( const css::uno::Reference
< css::embed::XStateChangeListener
>& xListener
) override
;
411 virtual void SAL_CALL
close( sal_Bool DeliverOwnership
) override
;
413 virtual void SAL_CALL
addCloseListener(
414 const css::uno::Reference
< css::util::XCloseListener
>& Listener
) override
;
416 virtual void SAL_CALL
removeCloseListener(
417 const css::uno::Reference
< css::util::XCloseListener
>& Listener
) override
;
420 virtual void SAL_CALL
addEventListener(
421 const css::uno::Reference
< css::document::XEventListener
>& Listener
) override
;
423 virtual void SAL_CALL
removeEventListener(
424 const css::uno::Reference
< css::document::XEventListener
>& Listener
) override
;
427 virtual css::uno::Reference
< css::uno::XInterface
> SAL_CALL
getParent( ) override
;
428 virtual void SAL_CALL
setParent( const css::uno::Reference
< css::uno::XInterface
>& Parent
) override
;
430 // XDefaultSizeTransmitter
431 //#i103460# charts do not necessarily have an own size within ODF files, in this case they need to use the size settings from the surrounding frame, which is made available with this method
432 virtual void SAL_CALL
setDefaultSize( const css::awt::Size
& rSize_100TH_MM
) override
;
435 OUString SAL_CALL
getImplementationName() override
;
436 sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
437 css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
440 void SAL_CALL
initialize(const css::uno::Sequence
<css::uno::Any
>& rArguments
) override
;
443 css::uno::Sequence
<css::uno::Type
> SAL_CALL
getTypes() override
;
444 css::uno::Sequence
<sal_Int8
> SAL_CALL
getImplementationId() override
;
447 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */