tdf#144694 In direct SQL dialog, activate options 'Run SQL command
[LibreOffice.git] / embeddedobj / source / inc / oleembobj.hxx
blob4a07d9420764c59405048f43c9200f5833118a42
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/embed/XEmbeddedObject.hpp>
25 #include <com/sun/star/embed/XEmbeddedOleObject.hpp>
26 #include <com/sun/star/embed/XInplaceObject.hpp>
27 #include <com/sun/star/embed/XEmbedPersist.hpp>
28 #include <com/sun/star/embed/XLinkageSupport.hpp>
29 #include <com/sun/star/embed/VerbDescriptor.hpp>
30 #include <com/sun/star/container/XChild.hpp>
31 #include <com/sun/star/util/XCloseable.hpp>
32 #include <com/sun/star/util/XCloseListener.hpp>
33 #include <com/sun/star/io/XActiveDataStreamer.hpp>
34 #include <com/sun/star/lang/XInitialization.hpp>
35 #include <com/sun/star/lang/XServiceInfo.hpp>
36 #include <com/sun/star/uno/XComponentContext.hpp>
37 #include <cppuhelper/implbase.hxx>
38 #include <rtl/ref.hxx>
40 #include <osl/thread.h>
41 #include <memory>
43 namespace comphelper {
44 class OMultiTypeInterfaceContainerHelper2;
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;
54 #ifdef _WIN32
55 bool m_bWasEverActive;
56 bool m_bVerbExecutionInProgress;
57 oslThreadIdentifier m_nVerbExecutionThreadIdentifier;
58 bool m_bChangedOnVerbExecution;
59 #endif
61 public:
63 VerbExecutionController()
64 : m_nNotificationLock( 0 )
65 #ifdef _WIN32
66 , m_bWasEverActive( false )
67 , m_bVerbExecutionInProgress( false )
68 , m_nVerbExecutionThreadIdentifier( 0 )
69 , m_bChangedOnVerbExecution( false )
70 #endif
73 #ifdef _WIN32
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; }
81 #endif
82 void LockNotification();
83 void UnlockNotification();
86 class VerbExecutionControllerGuard
88 VerbExecutionController& m_rController;
89 public:
91 VerbExecutionControllerGuard( VerbExecutionController& rController )
92 : m_rController( rController )
94 m_rController.LockNotification();
97 ~VerbExecutionControllerGuard()
99 m_rController.UnlockNotification();
104 class OleComponent;
105 class OwnView_Impl;
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
119 , css::lang::XServiceInfo >
121 friend class OleComponent;
123 ::osl::Mutex m_aMutex;
125 rtl::Reference<OleComponent> m_pOleComponent;
127 std::unique_ptr<::comphelper::OMultiTypeInterfaceContainerHelper2> m_pInterfaceContainer;
129 bool m_bReadOnly;
131 bool m_bDisposed;
132 sal_Int32 m_nObjectState;
133 sal_Int32 m_nTargetState;
134 sal_Int32 m_nUpdateMode;
136 css::uno::Reference< css::uno::XComponentContext > m_xContext;
138 css::uno::Sequence< sal_Int8 > m_aClassID;
139 OUString m_aClassName;
141 css::uno::Reference< css::embed::XEmbeddedClient > m_xClientSite;
143 OUString m_aContainerName;
145 css::uno::Reference< css::util::XCloseListener > m_xClosePreventer;
147 bool m_bWaitSaveCompleted;
148 bool m_bNewVisReplInStream;
149 css::uno::Reference< css::io::XStream > m_xNewCachedVisRepl;
150 OUString m_aNewEntryName;
151 css::uno::Reference< css::embed::XStorage > m_xNewParentStorage;
152 css::uno::Reference< css::io::XStream > m_xNewObjectStream;
153 bool m_bStoreLoaded;
155 css::uno::Reference< css::io::XStream > m_xCachedVisualRepresentation;
156 bool m_bVisReplInitialized;
157 bool m_bVisReplInStream;
158 bool m_bStoreVisRepl;
160 bool m_bIsLink;
162 // TODO/LATER: may need to cache more than one aspect in future
163 bool m_bHasCachedSize; // the object has cached size
164 css::awt::Size m_aCachedSize;
165 sal_Int64 m_nCachedAspect;
167 bool m_bHasSizeToSet; // the object has cached size that should be set to OLE component
168 css::awt::Size m_aSizeToSet; // this size might be different from the cached one ( scaling is applied )
169 sal_Int64 m_nAspectToSet;
172 // cache the status of the object
173 // TODO/LATER: may need to cache more than one aspect in future
174 bool m_bGotStatus;
175 sal_Int64 m_nStatus;
176 sal_Int64 m_nStatusAspect;
178 // embedded object related stuff
179 OUString m_aEntryName;
180 css::uno::Reference< css::embed::XStorage > m_xParentStorage;
181 css::uno::Reference< css::io::XStream > m_xObjectStream;
183 // link related stuff
184 OUString m_aLinkURL; // ???
186 // points to own view provider if the object has no server
187 rtl::Reference<OwnView_Impl> m_xOwnView;
189 // whether the object should be initialized from clipboard in case of default initialization
190 bool m_bFromClipboard;
192 OUString m_aTempURL;
194 OUString m_aTempDumpURL;
196 // STAMPIT solution
197 // the following member is used during verb execution to detect whether the verb execution modifies the object
198 VerbExecutionController m_aVerbExecutionController;
200 // if the following member is set, the object works in wrapper mode
201 css::uno::Reference< css::embed::XEmbeddedObject > m_xWrappedObject;
202 bool m_bTriedConversion;
203 OUString m_aFilterName; // if m_bTriedConversion, then the filter detected by that
205 css::uno::Reference< css::uno::XInterface > m_xParent;
207 /// If it is allowed to modify entries in the stream of the OLE storage.
208 bool m_bStreamReadOnly = false;
210 protected:
211 /// @throws css::uno::Exception
212 css::uno::Reference< css::io::XStream > TryToGetAcceptableFormat_Impl(
213 const css::uno::Reference< css::io::XStream >& xStream );
215 /// @throws css::io::IOException
216 /// @throws css::uno::RuntimeException
217 css::uno::Reference< css::io::XStream > GetNewFilledTempStream_Impl(
218 const css::uno::Reference< css::io::XInputStream >& xInStream );
219 #ifdef _WIN32
220 void SwitchComponentToRunningState_Impl(osl::ResettableMutexGuard& guard);
221 #endif
222 void MakeEventListenerNotification_Impl( const OUString& aEventName, osl::ResettableMutexGuard& guard );
223 #ifdef _WIN32
224 void StateChangeNotification_Impl( bool bBeforeChange, sal_Int32 nOldState, sal_Int32 nNewState, osl::ResettableMutexGuard& guard );
225 css::uno::Reference< css::io::XOutputStream > GetStreamForSaving();
228 css::uno::Sequence< sal_Int32 > GetIntermediateVerbsSequence_Impl( sal_Int32 nNewState );
230 static css::uno::Sequence< sal_Int32 > GetReachableStatesList_Impl(
231 const css::uno::Sequence< css::embed::VerbDescriptor >& aVerbList );
232 #endif
234 void Dispose(osl::ResettableMutexGuard* guard = nullptr);
236 void SwitchOwnPersistence(
237 const css::uno::Reference< css::embed::XStorage >& xNewParentStorage,
238 const css::uno::Reference< css::io::XStream >& xNewObjectStream,
239 const OUString& aNewName );
241 void SwitchOwnPersistence(
242 const css::uno::Reference< css::embed::XStorage >& xNewParentStorage,
243 const OUString& aNewName );
245 void GetRidOfComponent(osl::ResettableMutexGuard* guard);
247 /// @throws css::uno::Exception
248 void StoreToLocation_Impl(
249 const css::uno::Reference< css::embed::XStorage >& xStorage,
250 const OUString& sEntName,
251 const css::uno::Sequence< css::beans::PropertyValue >& lObjArgs,
252 bool bSaveAs,
253 osl::ResettableMutexGuard& rGuard);
254 #ifdef _WIN32
255 /// @throws css::uno::Exception
256 void StoreObjectToStream(css::uno::Reference<css::io::XOutputStream> const& xOutStream,
257 osl::ResettableMutexGuard& rGuard);
258 #endif
259 /// @throws css::uno::Exception
260 void InsertVisualCache_Impl(
261 const css::uno::Reference< css::io::XStream >& xTargetStream,
262 const css::uno::Reference< css::io::XStream >& xCachedVisualRepresentation,
263 osl::ResettableMutexGuard& rGuard);
265 /// @throws css::uno::Exception
266 void RemoveVisualCache_Impl( const css::uno::Reference< css::io::XStream >& xTargetStream );
268 void SetVisReplInStream( bool bExists );
269 bool HasVisReplInStream();
271 /// @throws css::uno::Exception
272 css::embed::VisualRepresentation GetVisualRepresentationInNativeFormat_Impl(
273 const css::uno::Reference< css::io::XStream >& xCachedVisRepr );
275 css::uno::Reference< css::io::XStream > TryToRetrieveCachedVisualRepresentation_Impl(
276 const css::uno::Reference< css::io::XStream >& xStream,
277 osl::ResettableMutexGuard& rGuard,
278 bool bAllowRepair50 = false )
279 noexcept;
280 #ifdef _WIN32
281 bool SaveObject_Impl();
282 bool OnShowWindow_Impl( bool bShow );
283 void CreateOleComponent_Impl( rtl::Reference<OleComponent> const & pOleComponent = {} );
284 void CreateOleComponentAndLoad_Impl( rtl::Reference<OleComponent> const & pOleComponent = {} );
285 void CreateOleComponentFromClipboard_Impl( OleComponent* pOleComponent = nullptr );
286 OUString CreateTempURLEmpty_Impl();
287 OUString GetTempURL_Impl();
288 void SetObjectIsLink_Impl( bool bIsLink ) { m_bIsLink = bIsLink; }
289 #endif
291 // the following 4 methods are related to switch to wrapping mode
292 void MoveListeners();
293 css::uno::Reference< css::embed::XStorage > CreateTemporarySubstorage( OUString& o_aStorageName );
294 OUString MoveToTemporarySubstream();
295 bool TryToConvertToOOo( const css::uno::Reference< css::io::XStream >& xStream );
297 public:
298 // in case a new object must be created the class ID must be specified
299 OleEmbeddedObject( css::uno::Reference< css::uno::XComponentContext > xContext,
300 const css::uno::Sequence< sal_Int8 >& aClassID,
301 OUString aClassName );
303 // in case object will be loaded from a persistent entry or from a file the class ID will be detected on loading
304 // factory can do it for OOo objects, but for OLE objects OS dependent code is required
305 OleEmbeddedObject( css::uno::Reference< css::uno::XComponentContext > xContext,
306 bool bLink );
307 #ifdef _WIN32
308 // this constructor let object be initialized from clipboard
309 OleEmbeddedObject( const css::uno::Reference< css::uno::XComponentContext >& xContext );
310 #endif
312 virtual ~OleEmbeddedObject() override;
314 #ifdef _WIN32
315 static void OnIconChanged_Impl();
316 void OnViewChanged_Impl();
317 void OnClosed_Impl();
318 #endif
320 // XEmbeddedObject
322 virtual void SAL_CALL changeState( sal_Int32 nNewState ) override;
324 virtual css::uno::Sequence< sal_Int32 > SAL_CALL getReachableStates() override;
326 virtual sal_Int32 SAL_CALL getCurrentState() override;
328 virtual void SAL_CALL doVerb( sal_Int32 nVerbID ) override;
330 virtual css::uno::Sequence< css::embed::VerbDescriptor > SAL_CALL getSupportedVerbs() override;
332 virtual void SAL_CALL setClientSite(
333 const css::uno::Reference< css::embed::XEmbeddedClient >& xClient ) override;
335 virtual css::uno::Reference< css::embed::XEmbeddedClient > SAL_CALL getClientSite() override;
337 virtual void SAL_CALL update() override;
339 virtual void SAL_CALL setUpdateMode( sal_Int32 nMode ) override;
341 virtual sal_Int64 SAL_CALL getStatus( sal_Int64 nAspect ) override;
343 virtual void SAL_CALL setContainerName( const OUString& sName ) override;
346 // XVisualObject
348 virtual void SAL_CALL setVisualAreaSize( sal_Int64 nAspect, const css::awt::Size& aSize ) override;
350 virtual css::awt::Size SAL_CALL getVisualAreaSize( sal_Int64 nAspect ) override;
352 virtual css::embed::VisualRepresentation SAL_CALL getPreferredVisualRepresentation( ::sal_Int64 nAspect ) override;
354 virtual sal_Int32 SAL_CALL getMapUnit( sal_Int64 nAspect ) override;
357 // XEmbedPersist
359 virtual void SAL_CALL setPersistentEntry(
360 const css::uno::Reference< css::embed::XStorage >& xStorage,
361 const OUString& sEntName,
362 sal_Int32 nEntryConnectionMode,
363 const css::uno::Sequence< css::beans::PropertyValue >& lArguments,
364 const css::uno::Sequence< css::beans::PropertyValue >& lObjArgs ) override;
366 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;
368 virtual void SAL_CALL storeAsEntry(
369 const css::uno::Reference< css::embed::XStorage >& xStorage,
370 const OUString& sEntName,
371 const css::uno::Sequence< css::beans::PropertyValue >& lArguments,
372 const css::uno::Sequence< css::beans::PropertyValue >& lObjArgs ) override;
374 virtual void SAL_CALL saveCompleted( sal_Bool bUseNew ) override;
376 virtual sal_Bool SAL_CALL hasEntry() override;
378 virtual OUString SAL_CALL getEntryName() override;
380 // XLinkageSupport
382 virtual void SAL_CALL breakLink( const css::uno::Reference< css::embed::XStorage >& xStorage,
383 const OUString& sEntName ) override;
385 virtual sal_Bool SAL_CALL isLink() override;
387 virtual OUString SAL_CALL getLinkURL() override;
389 // XCommonEmbedPersist
390 virtual void SAL_CALL storeOwn() override;
392 virtual sal_Bool SAL_CALL isReadonly() override;
394 virtual void SAL_CALL reload(
395 const css::uno::Sequence< css::beans::PropertyValue >& lArguments,
396 const css::uno::Sequence< css::beans::PropertyValue >& lObjArgs ) override;
398 // XClassifiedObject
400 virtual css::uno::Sequence< sal_Int8 > SAL_CALL getClassID() override;
402 virtual OUString SAL_CALL getClassName() override;
404 virtual void SAL_CALL setClassInfo(
405 const css::uno::Sequence< sal_Int8 >& aClassID, const OUString& aClassName ) override;
407 // XStateChangeBroadcaster
408 virtual void SAL_CALL addStateChangeListener( const css::uno::Reference< css::embed::XStateChangeListener >& xListener ) override;
409 virtual void SAL_CALL removeStateChangeListener( const css::uno::Reference< css::embed::XStateChangeListener >& xListener ) override;
412 // XComponentSupplier
414 virtual css::uno::Reference< css::util::XCloseable > SAL_CALL getComponent() override;
416 // XCloseable
418 virtual void SAL_CALL close( sal_Bool DeliverOwnership ) override;
420 virtual void SAL_CALL addCloseListener(
421 const css::uno::Reference< css::util::XCloseListener >& Listener ) override;
423 virtual void SAL_CALL removeCloseListener(
424 const css::uno::Reference< css::util::XCloseListener >& Listener ) override;
426 // XEventBroadcaster
427 virtual void SAL_CALL addEventListener(
428 const css::uno::Reference< css::document::XEventListener >& Listener ) override;
430 virtual void SAL_CALL removeEventListener(
431 const css::uno::Reference< css::document::XEventListener >& Listener ) override;
433 // XInplaceObject ( only for wrapping scenario here )
435 virtual void SAL_CALL setObjectRectangles( const css::awt::Rectangle& aPosRect,
436 const css::awt::Rectangle& aClipRect ) override;
438 virtual void SAL_CALL enableModeless( sal_Bool bEnable ) override;
440 virtual void SAL_CALL translateAccelerators(
441 const css::uno::Sequence< css::awt::KeyEvent >& aKeys ) override;
443 // XChild ( only for wrapping scenario here )
444 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getParent( ) override;
445 virtual void SAL_CALL setParent( const css::uno::Reference< css::uno::XInterface >& Parent ) override;
447 // XActiveDataStreamer
448 void SAL_CALL setStream(const css::uno::Reference<css::io::XStream>& xStream) override;
449 css::uno::Reference<css::io::XStream> SAL_CALL getStream() override;
451 // XInitialization
452 void SAL_CALL initialize(const css::uno::Sequence<css::uno::Any>& rArguments) override;
454 // XServiceInfo
455 OUString SAL_CALL getImplementationName() override;
456 sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
457 css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
459 private:
460 css::awt::Size getVisualAreaSize_impl(sal_Int64 nAspect, osl::ResettableMutexGuard& guard);
463 namespace
465 #if defined(_WIN32)
466 template <class Proc> auto ExecUnlocked(Proc proc, osl::ResettableMutexGuard& guard)
468 osl::ResettableMutexGuardScopedReleaser area(guard);
469 return proc();
471 #endif
474 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */