Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / embeddedobj / source / inc / commonembobj.hxx
blobbbd2de63ec7091236f994b476723c1c931af5c02
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #pragma once
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>
41 #include <map>
42 #include <memory>
43 #include <svtools/filechangedchecker.hxx>
44 #include <unotools/resmgr.hxx>
46 namespace com::sun::star {
47 namespace embed {
48 class XStorage;
50 namespace lang {
51 class XMultiServiceFactory;
53 namespace util {
54 class XCloseListener;
56 namespace beans {
57 struct PropertyValue;
58 struct NamedValue;
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 class Interceptor;
77 /**
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
93 protected:
94 ::osl::Mutex m_aMutex;
96 rtl::Reference<DocumentHolder> m_xDocHolder;
98 std::unique_ptr<::comphelper::OMultiTypeInterfaceContainerHelper2> m_pInterfaceContainer;
100 bool m_bReadOnly;
102 bool m_bDisposed;
103 bool m_bClosed;
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;
144 bool m_bIsLinkURL;
145 bool m_bLinkTempFileChanged;
146 ::std::unique_ptr< FileChangedChecker > m_pLinkFile;
147 bool m_bOleUpdate;
148 bool m_bInHndFunc;
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
157 OUString m_aLinkURL;
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
172 private:
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 );
199 void Deactivate();
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
239 ) const;
241 void EmbedAndReparentDoc_Impl(
242 const css::uno::Reference< css::util::XCloseable >& i_rxDocument
243 ) const;
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 protected:
258 void SetInplaceActiveState();
260 public:
261 OCommonEmbeddedObject(
262 css::uno::Reference< css::uno::XComponentContext > xContext,
263 const css::uno::Sequence< css::beans::NamedValue >& aObjectProps );
265 // no persistence for linked objects, so the descriptors are provided in constructor
266 OCommonEmbeddedObject(
267 css::uno::Reference< css::uno::XComponentContext > xContext,
268 const css::uno::Sequence< css::beans::NamedValue >& aObjectProps,
269 const css::uno::Sequence< css::beans::PropertyValue >& aMediaDescr,
270 const css::uno::Sequence< css::beans::PropertyValue >& aObjectDescr );
272 virtual ~OCommonEmbeddedObject() override;
274 void SaveObject_Impl();
276 void requestPositioning( const css::awt::Rectangle& aRect );
278 // not a real listener and should not be
279 void PostEvent_Impl( const OUString& aEventName );
281 OUString const & getContainerName() const { return m_aContainerName; }
282 // XInterface
284 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& rType ) override ;
286 virtual void SAL_CALL acquire()
287 noexcept override;
289 virtual void SAL_CALL release()
290 noexcept override;
292 // XEmbeddedObject
294 virtual void SAL_CALL changeState( sal_Int32 nNewState ) override;
296 virtual css::uno::Sequence< sal_Int32 > SAL_CALL getReachableStates() override;
298 virtual sal_Int32 SAL_CALL getCurrentState() override;
300 virtual void SAL_CALL doVerb( sal_Int32 nVerbID ) override;
302 virtual css::uno::Sequence< css::embed::VerbDescriptor > SAL_CALL getSupportedVerbs() override;
304 virtual void SAL_CALL setClientSite(
305 const css::uno::Reference< css::embed::XEmbeddedClient >& xClient ) override;
307 virtual css::uno::Reference< css::embed::XEmbeddedClient > SAL_CALL getClientSite() override;
309 virtual void SAL_CALL update() override;
311 virtual void SAL_CALL setUpdateMode( sal_Int32 nMode ) override;
313 virtual sal_Int64 SAL_CALL getStatus( sal_Int64 nAspect ) override;
315 virtual void SAL_CALL setContainerName( const OUString& sName ) override;
317 // EmbeddedUpdate
319 virtual void SetOleState(bool bIsOleUpdate) override;
322 // XVisualObject
324 virtual void SAL_CALL setVisualAreaSize( sal_Int64 nAspect, const css::awt::Size& aSize ) override;
326 virtual css::awt::Size SAL_CALL getVisualAreaSize( sal_Int64 nAspect ) override;
328 virtual css::embed::VisualRepresentation SAL_CALL getPreferredVisualRepresentation( ::sal_Int64 nAspect ) override;
330 virtual sal_Int32 SAL_CALL getMapUnit( sal_Int64 nAspect ) override;
332 // XEmbedPersist
334 virtual void SAL_CALL setPersistentEntry(
335 const css::uno::Reference< css::embed::XStorage >& xStorage,
336 const OUString& sEntName,
337 sal_Int32 nEntryConnectionMode,
338 const css::uno::Sequence< css::beans::PropertyValue >& lArguments,
339 const css::uno::Sequence< css::beans::PropertyValue >& lObjArgs ) override;
341 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;
343 virtual void SAL_CALL storeAsEntry(
344 const css::uno::Reference< css::embed::XStorage >& xStorage,
345 const OUString& sEntName,
346 const css::uno::Sequence< css::beans::PropertyValue >& lArguments,
347 const css::uno::Sequence< css::beans::PropertyValue >& lObjArgs ) override;
349 virtual void SAL_CALL saveCompleted( sal_Bool bUseNew ) override;
351 virtual sal_Bool SAL_CALL hasEntry() override;
353 virtual OUString SAL_CALL getEntryName() override;
355 // XLinkageSupport
357 virtual void SAL_CALL breakLink( const css::uno::Reference< css::embed::XStorage >& xStorage,
358 const OUString& sEntName ) override;
360 virtual sal_Bool SAL_CALL isLink() override;
362 virtual OUString SAL_CALL getLinkURL() override;
365 // XCommonEmbedPersist
367 virtual void SAL_CALL storeOwn() override;
369 virtual sal_Bool SAL_CALL isReadonly() override;
371 virtual void SAL_CALL reload(
372 const css::uno::Sequence< css::beans::PropertyValue >& lArguments,
373 const css::uno::Sequence< css::beans::PropertyValue >& lObjArgs ) override;
375 // XEmbedPersist2
377 virtual sal_Bool SAL_CALL isStored() override;
379 // XInplaceObject
381 virtual void SAL_CALL setObjectRectangles( const css::awt::Rectangle& aPosRect,
382 const css::awt::Rectangle& aClipRect ) override;
384 virtual void SAL_CALL enableModeless( sal_Bool bEnable ) override;
386 virtual void SAL_CALL translateAccelerators(
387 const css::uno::Sequence< css::awt::KeyEvent >& aKeys ) override;
389 // XClassifiedObject
391 virtual css::uno::Sequence< sal_Int8 > SAL_CALL getClassID() override;
393 virtual OUString SAL_CALL getClassName() override;
395 virtual void SAL_CALL setClassInfo(
396 const css::uno::Sequence< sal_Int8 >& aClassID, const OUString& aClassName ) override;
399 // XComponentSupplier
401 virtual css::uno::Reference< css::util::XCloseable > SAL_CALL getComponent() override;
403 // XStateChangeBroadcaster
404 virtual void SAL_CALL addStateChangeListener( const css::uno::Reference< css::embed::XStateChangeListener >& xListener ) override;
405 virtual void SAL_CALL removeStateChangeListener( const css::uno::Reference< css::embed::XStateChangeListener >& xListener ) override;
407 // XCloseable
409 virtual void SAL_CALL close( sal_Bool DeliverOwnership ) override;
411 virtual void SAL_CALL addCloseListener(
412 const css::uno::Reference< css::util::XCloseListener >& Listener ) override;
414 virtual void SAL_CALL removeCloseListener(
415 const css::uno::Reference< css::util::XCloseListener >& Listener ) override;
417 // XEventBroadcaster
418 virtual void SAL_CALL addEventListener(
419 const css::uno::Reference< css::document::XEventListener >& Listener ) override;
421 virtual void SAL_CALL removeEventListener(
422 const css::uno::Reference< css::document::XEventListener >& Listener ) override;
424 // XChild
425 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getParent( ) override;
426 virtual void SAL_CALL setParent( const css::uno::Reference< css::uno::XInterface >& Parent ) override;
428 // XDefaultSizeTransmitter
429 //#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
430 virtual void SAL_CALL setDefaultSize( const css::awt::Size& rSize_100TH_MM ) override;
432 // XServiceInfo
433 OUString SAL_CALL getImplementationName() override;
434 sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
435 css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
437 // XInitialization
438 void SAL_CALL initialize(const css::uno::Sequence<css::uno::Any>& rArguments) override;
440 // XTypeProvider
441 css::uno::Sequence<css::uno::Type> SAL_CALL getTypes() override;
442 css::uno::Sequence<sal_Int8> SAL_CALL getImplementationId() override;
445 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */