xref: /trunk/main/embeddedobj/source/inc/oleembobj.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _INC_OLEEMBOBJ_HXX_
25 #define _INC_OLEEMBOBJ_HXX_
26 
27 #include <com/sun/star/uno/Sequence.hxx>
28 #include <com/sun/star/uno/Reference.hxx>
29 #include <com/sun/star/uno/Any.hxx>
30 #include <com/sun/star/embed/XEmbeddedObject.hpp>
31 #include <com/sun/star/embed/XInplaceObject.hpp>
32 #include <com/sun/star/embed/XVisualObject.hpp>
33 #include <com/sun/star/embed/XEmbedPersist.hpp>
34 #include <com/sun/star/embed/XLinkageSupport.hpp>
35 #include <com/sun/star/embed/XClassifiedObject.hpp>
36 #include <com/sun/star/embed/XComponentSupplier.hpp>
37 #include <com/sun/star/embed/VerbDescriptor.hpp>
38 #include <com/sun/star/document/XEventBroadcaster.hpp>
39 #include <com/sun/star/container/XChild.hpp>
40 #include <com/sun/star/util/XCloseable.hpp>
41 #include <com/sun/star/util/XCloseListener.hpp>
42 #include <cppuhelper/implbase5.hxx>
43 
44 #include <osl/thread.h>
45 
46 namespace cppu {
47     class OMultiTypeInterfaceContainerHelper;
48 }
49 
50 class VerbExecutionController
51 {
52     // the following mutex is allowed to be locked only for variables initialization, so no deadlock can be caused
53     ::osl::Mutex    m_aVerbExecutionMutex;
54 
55     sal_Bool m_bVerbExecutionInProgress;
56     oslThreadIdentifier m_nVerbExecutionThreadIdentifier;
57     sal_Bool m_bChangedOnVerbExecution;
58 
59     sal_Bool m_bWasEverActive;
60     sal_Int32 m_nNotificationLock;
61 
62 public:
63 
VerbExecutionController()64     VerbExecutionController()
65     : m_bVerbExecutionInProgress( sal_False )
66     , m_nVerbExecutionThreadIdentifier( 0 )
67     , m_bChangedOnVerbExecution( sal_False )
68     , m_bWasEverActive( sal_False )
69     , m_nNotificationLock( 0 )
70     {}
71 #ifdef WNT
72     void StartControlExecution();
73     sal_Bool EndControlExecution_WasModified();
74     void ModificationNotificationIsDone();
75 #endif
76     void LockNotification();
77     void UnlockNotification();
78 
79     // no need to lock anything to check the value of the numeric members
CanDoNotification()80     sal_Bool CanDoNotification() { return ( !m_bVerbExecutionInProgress && !m_bWasEverActive && !m_nNotificationLock ); }
81     // ... or to change it
ObjectIsActive()82     void ObjectIsActive() { m_bWasEverActive = sal_True; }
83 };
84 
85 class VerbExecutionControllerGuard
86 {
87     VerbExecutionController& m_rController;
88 public:
89 
VerbExecutionControllerGuard(VerbExecutionController & rController)90     VerbExecutionControllerGuard( VerbExecutionController& rController )
91     : m_rController( rController )
92     {
93         m_rController.LockNotification();
94     }
95 
~VerbExecutionControllerGuard()96     ~VerbExecutionControllerGuard()
97     {
98         m_rController.UnlockNotification();
99     }
100 };
101 
102 
103 class OleComponent;
104 class OwnView_Impl;
105 class OleEmbeddedObject : public ::cppu::WeakImplHelper5
106                         < ::com::sun::star::embed::XEmbeddedObject
107                         , ::com::sun::star::embed::XEmbedPersist
108                         , ::com::sun::star::embed::XLinkageSupport
109                         , ::com::sun::star::embed::XInplaceObject
110                         , ::com::sun::star::container::XChild >
111 {
112     friend class OleComponent;
113 
114     ::osl::Mutex    m_aMutex;
115 
116     OleComponent*   m_pOleComponent;
117 
118     ::cppu::OMultiTypeInterfaceContainerHelper* m_pInterfaceContainer;
119 
120     sal_Bool m_bReadOnly;
121 
122     sal_Int32 m_bDisposed;
123     sal_Int32 m_nObjectState;
124     sal_Int32 m_nTargetState;
125     sal_Int32 m_nUpdateMode;
126 
127     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xFactory;
128 
129     ::com::sun::star::uno::Sequence< sal_Int8 > m_aClassID;
130     ::rtl::OUString m_aClassName;
131 
132     ::com::sun::star::uno::Reference< ::com::sun::star::embed::XEmbeddedClient > m_xClientSite;
133 
134     ::rtl::OUString m_aContainerName;
135 
136     ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloseListener > m_xClosePreventer;
137 
138     sal_Bool m_bWaitSaveCompleted;
139     sal_Bool m_bNewVisReplInStream;
140     ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > m_xNewCachedVisRepl;
141     ::rtl::OUString m_aNewEntryName;
142     ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > m_xNewParentStorage;
143     ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > m_xNewObjectStream;
144     sal_Bool m_bStoreLoaded;
145 
146     ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > m_xCachedVisualRepresentation;
147     sal_Bool m_bVisReplInitialized;
148     sal_Bool m_bVisReplInStream;
149     sal_Bool m_bStoreVisRepl;
150 
151     sal_Bool m_bIsLink;
152 
153     // TODO/LATER: may need to cache more than one aspect in future
154     sal_Bool m_bHasCachedSize; // the object has cached size
155     ::com::sun::star::awt::Size m_aCachedSize;
156     sal_Int64 m_nCachedAspect;
157 
158     sal_Bool m_bHasSizeToSet;  // the object has cached size that should be set to OLE component
159     ::com::sun::star::awt::Size m_aSizeToSet; // this size might be different from the cached one ( scaling is applied )
160     sal_Int64 m_nAspectToSet;
161 
162 
163     // cache the status of the object
164     // TODO/LATER: may need to cache more than one aspect in future
165     sal_Bool m_bGotStatus;
166     sal_Int64 m_nStatus;
167     sal_Int64 m_nStatusAspect;
168 
169     // embedded object related stuff
170     ::rtl::OUString m_aEntryName;
171     ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > m_xParentStorage;
172     ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > m_xObjectStream;
173 
174     // link related stuff
175     ::rtl::OUString m_aLinkURL; // ???
176 
177     // points to own view provider if the object has no server
178     OwnView_Impl*   m_pOwnView;
179 
180     // whether the object should be initialized from clipboard in case of default initialization
181     sal_Bool m_bFromClipboard;
182 
183     ::rtl::OUString m_aTempURL;
184 
185     ::rtl::OUString m_aTempDumpURL;
186 
187     // STAMPIT solution
188     // the following member is used during verb execution to detect whether the verb execution modifies the object
189     VerbExecutionController m_aVerbExecutionController;
190 
191     // if the following member is set, the object works in wrapper mode
192     ::com::sun::star::uno::Reference< ::com::sun::star::embed::XEmbeddedObject > m_xWrappedObject;
193     sal_Bool m_bTriedConversion;
194 
195     ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > m_xParent;
196 
197 protected:
198 
199     ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > TryToGetAcceptableFormat_Impl(
200                                     const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xStream );
201 
202     ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > GetNewFilledTempStream_Impl(
203                                     const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInStream );
204 #ifdef WNT
205     void SwitchComponentToRunningState_Impl();
206 #endif
207     void MakeEventListenerNotification_Impl( const ::rtl::OUString& aEventName );
208 #ifdef WNT
209     void StateChangeNotification_Impl( sal_Bool bBeforeChange, sal_Int32 nOldState, sal_Int32 nNewState );
210     ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > GetStreamForSaving();
211 
212 
213     ::com::sun::star::uno::Sequence< sal_Int32 > GetIntermediateVerbsSequence_Impl( sal_Int32 nNewState );
214 
215     ::com::sun::star::uno::Sequence< sal_Int32 > GetReachableStatesList_Impl(
216                         const ::com::sun::star::uno::Sequence< ::com::sun::star::embed::VerbDescriptor >& aVerbList );
217 #endif
218 
219     void CloseComponent();
220     void Dispose();
221 
222     void SwitchOwnPersistence(
223                 const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xNewParentStorage,
224                 const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xNewObjectStream,
225                 const ::rtl::OUString& aNewName );
226 
227     void SwitchOwnPersistence(
228                 const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xNewParentStorage,
229                 const ::rtl::OUString& aNewName );
230 
231     void GetRidOfComponent();
232 
233     void StoreToLocation_Impl(
234                             const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage,
235                             const ::rtl::OUString& sEntName,
236                             const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lArguments,
237                             const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lObjArgs,
238                             sal_Bool bSaveAs );
239 #ifdef WNT
240     void StoreObjectToStream( ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > xOutStream );
241 #endif
242     void InsertVisualCache_Impl(
243             const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xTargetStream,
244             const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xCachedVisualRepresentation );
245 
246     void RemoveVisualCache_Impl( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xTargetStream );
247 
248     void SetVisReplInStream( sal_Bool bExists );
249     sal_Bool HasVisReplInStream();
250 
251     ::com::sun::star::embed::VisualRepresentation GetVisualRepresentationInNativeFormat_Impl(
252                     const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > xCachedVisRepr );
253 
254     ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > TryToRetrieveCachedVisualRepresentation_Impl(
255                     const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xStream,
256                     sal_Bool bAllowRepair50 = sal_False )
257         throw ();
258 #ifdef WNT
259     sal_Bool SaveObject_Impl();
260     sal_Bool OnShowWindow_Impl( sal_Bool bShow );
261     void CreateOleComponent_Impl( OleComponent* pOleComponent = NULL );
262     void CreateOleComponentAndLoad_Impl( OleComponent* pOleComponent = NULL );
263     void CreateOleComponentFromClipboard_Impl( OleComponent* pOleComponent = NULL );
264 #endif
SetObjectIsLink_Impl(sal_Bool bIsLink)265     void SetObjectIsLink_Impl( sal_Bool bIsLink ) { m_bIsLink = bIsLink; }
266 
267 #ifdef WNT
268     ::rtl::OUString CreateTempURLEmpty_Impl();
269     ::rtl::OUString GetTempURL_Impl();
270 #endif
GetContainerName_Impl()271     ::rtl::OUString GetContainerName_Impl() { return m_aContainerName; }
272 
273     // the following 4 methods are related to switch to wrapping mode
274     void MoveListeners();
275     ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > CreateTemporarySubstorage( ::rtl::OUString& o_aStorageName );
276     ::rtl::OUString MoveToTemporarySubstream();
277     sal_Bool TryToConvertToOOo();
278 
279 public:
280     // in case a new object must be created the class ID must be specified
281     OleEmbeddedObject( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory,
282                         const ::com::sun::star::uno::Sequence< sal_Int8 >& aClassID,
283                         const ::rtl::OUString& aClassName );
284 
285     // in case object will be loaded from a persistent entry or from a file the class ID will be detected on loading
286     // factory can do it for OOo objects, but for OLE objects OS dependent code is required
287     OleEmbeddedObject( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory,
288                         sal_Bool bLink );
289 #ifdef WNT
290     // this constructor let object be initialized from clipboard
291     OleEmbeddedObject( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory );
292 #endif
293 
294     virtual ~OleEmbeddedObject();
295 
296 #ifdef WNT
297     void OnIconChanged_Impl();
298     void OnViewChanged_Impl();
299     void OnClosed_Impl();
300 #endif
301 
302 // XEmbeddedObject
303 
304     virtual void SAL_CALL changeState( sal_Int32 nNewState );
305 
306     virtual ::com::sun::star::uno::Sequence< sal_Int32 > SAL_CALL getReachableStates();
307 
308     virtual sal_Int32 SAL_CALL getCurrentState();
309 
310     virtual void SAL_CALL doVerb( sal_Int32 nVerbID );
311 
312     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::embed::VerbDescriptor > SAL_CALL getSupportedVerbs();
313 
314     virtual void SAL_CALL setClientSite(
315                 const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XEmbeddedClient >& xClient );
316 
317     virtual ::com::sun::star::uno::Reference< ::com::sun::star::embed::XEmbeddedClient > SAL_CALL getClientSite();
318 
319     virtual void SAL_CALL update();
320 
321     virtual void SAL_CALL setUpdateMode( sal_Int32 nMode );
322 
323     virtual sal_Int64 SAL_CALL getStatus( sal_Int64 nAspect );
324 
325     virtual void SAL_CALL setContainerName( const ::rtl::OUString& sName );
326 
327 
328 // XVisualObject
329 
330     virtual void SAL_CALL setVisualAreaSize( sal_Int64 nAspect, const ::com::sun::star::awt::Size& aSize );
331 
332     virtual ::com::sun::star::awt::Size SAL_CALL getVisualAreaSize( sal_Int64 nAspect );
333 
334     virtual ::com::sun::star::embed::VisualRepresentation SAL_CALL getPreferredVisualRepresentation( ::sal_Int64 nAspect );
335 
336     virtual sal_Int32 SAL_CALL getMapUnit( sal_Int64 nAspect );
337 
338 
339 // XEmbedPersist
340 
341     virtual void SAL_CALL setPersistentEntry(
342                     const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage,
343                     const ::rtl::OUString& sEntName,
344                     sal_Int32 nEntryConnectionMode,
345                     const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lArguments,
346                     const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lObjArgs );
347 
348     virtual void SAL_CALL storeToEntry( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage, const ::rtl::OUString& sEntName, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lArguments, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lObjArgs );
349 
350     virtual void SAL_CALL storeAsEntry(
351                 const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage,
352                 const ::rtl::OUString& sEntName,
353                 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lArguments,
354                 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lObjArgs );
355 
356     virtual void SAL_CALL saveCompleted( sal_Bool bUseNew );
357 
358     virtual sal_Bool SAL_CALL hasEntry();
359 
360     virtual ::rtl::OUString SAL_CALL getEntryName();
361 
362 // XLinkageSupport
363 
364     virtual void SAL_CALL breakLink( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage,
365                                      const ::rtl::OUString& sEntName );
366 
367     virtual sal_Bool SAL_CALL isLink();
368 
369     virtual ::rtl::OUString SAL_CALL getLinkURL();
370 
371 // XCommonEmbedPersist
372     virtual void SAL_CALL storeOwn();
373 
374     virtual sal_Bool SAL_CALL isReadonly();
375 
376     virtual void SAL_CALL reload(
377                 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lArguments,
378                 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lObjArgs );
379 
380 // XClassifiedObject
381 
382     virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getClassID();
383 
384     virtual ::rtl::OUString SAL_CALL getClassName();
385 
386     virtual void SAL_CALL setClassInfo(
387                 const ::com::sun::star::uno::Sequence< sal_Int8 >& aClassID, const ::rtl::OUString& aClassName );
388 
389 // XStateChangeBroadcaster
390     virtual void SAL_CALL addStateChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStateChangeListener >& xListener );
391     virtual void SAL_CALL removeStateChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStateChangeListener >& xListener );
392 
393 
394 // XComponentSupplier
395 
396     virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloseable > SAL_CALL getComponent();
397 
398 // XCloseable
399 
400     virtual void SAL_CALL close( sal_Bool DeliverOwnership );
401 
402     virtual void SAL_CALL addCloseListener(
403                 const ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloseListener >& Listener );
404 
405     virtual void SAL_CALL removeCloseListener(
406                 const ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloseListener >& Listener );
407 
408 // XEventBroadcaster
409     virtual void SAL_CALL addEventListener(
410                 const ::com::sun::star::uno::Reference< ::com::sun::star::document::XEventListener >& Listener );
411 
412     virtual void SAL_CALL removeEventListener(
413                 const ::com::sun::star::uno::Reference< ::com::sun::star::document::XEventListener >& Listener );
414 
415 // XInplaceObject ( only for wrapping scenario here )
416 
417     virtual void SAL_CALL setObjectRectangles( const ::com::sun::star::awt::Rectangle& aPosRect,
418                                           const ::com::sun::star::awt::Rectangle& aClipRect );
419 
420     virtual void SAL_CALL enableModeless( sal_Bool bEnable );
421 
422     virtual void SAL_CALL translateAccelerators(
423                     const ::com::sun::star::uno::Sequence< ::com::sun::star::awt::KeyEvent >& aKeys );
424 
425     // XChild ( only for wrapping scenario here )
426     virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getParent(  );
427     virtual void SAL_CALL setParent( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& Parent );
428 
429 };
430 
431 #endif
432