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_OLECOMPONENT_HXX_
25 #define _INC_OLECOMPONENT_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/lang/XComponent.hpp>
31 #include <com/sun/star/util/XCloseable.hpp>
32 #include <com/sun/star/datatransfer/XTransferable.hpp>
33 #include <com/sun/star/io/XInputStream.hpp>
34 #include <com/sun/star/io/XOutputStream.hpp>
35 #include <com/sun/star/embed/XOptimizedStorage.hpp>
36 #include <com/sun/star/embed/VerbDescriptor.hpp>
37 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
38 #include <com/sun/star/awt/Size.hpp>
39 #include <com/sun/star/lang/XUnoTunnel.hpp>
40 #include <cppuhelper/implbase5.hxx>
41 #include <com/sun/star/util/XModifiable.hpp>
42 #include <com/sun/star/util/XModifyListener.hpp>
43 
44 #include <vector>
45 
46 
47 namespace com { namespace sun { namespace star {
48 }}}
49 
50 namespace cppu {
51 	class OMultiTypeInterfaceContainerHelper;
52 }
53 
54 class OleWrapperClientSite;
55 class OleWrapperAdviseSink;
56 class OleEmbeddedObject;
57 struct OleComponentNative_Impl;
58 
59 class OleComponent : public ::cppu::WeakImplHelper5< ::com::sun::star::util::XCloseable, ::com::sun::star::lang::XComponent,
60                                                      ::com::sun::star::lang::XUnoTunnel, ::com::sun::star::util::XModifiable,
61 													 ::com::sun::star::datatransfer::XTransferable >
62 {
63 	::osl::Mutex m_aMutex;
64 	::cppu::OMultiTypeInterfaceContainerHelper* m_pInterfaceContainer;
65 
66 	sal_Bool m_bDisposed;
67     sal_Bool m_bModified;
68 	OleComponentNative_Impl* m_pNativeImpl;
69 
70 	OleEmbeddedObject* m_pUnoOleObject;
71 	OleWrapperClientSite* m_pOleWrapClientSite;
72 	OleWrapperAdviseSink* m_pImplAdviseSink;
73 
74 	sal_Int32 m_nOLEMiscFlags;
75 	sal_Int32 m_nAdvConn;
76 
77 	::com::sun::star::uno::Sequence< ::com::sun::star::embed::VerbDescriptor > m_aVerbList;
78 	::com::sun::star::uno::Sequence< ::com::sun::star::datatransfer::DataFlavor > m_aDataFlavors;
79 
80 	::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xFactory;
81 
82 	sal_Bool m_bOleInitialized;
83 
84 	// specifies whether the workaround for some rare embedded objects is activated ( f.e. AcrobatReader 7.0.8 object )
85 	// such objects report the dirty state wrongly sometimes and do not allow to store them any time
86 	sal_Bool m_bWorkaroundActive;
87 
88 
89 	sal_Bool InitializeObject_Impl();
90 
91 	void CreateNewIStorage_Impl();
92 
93 	void RetrieveObjectDataFlavors_Impl();
94 
95 	void Dispose();
96 
97 
98 public:
99 	OleComponent( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& m_xFactory,
100 				  OleEmbeddedObject* pOleObj );
101 
102 	virtual ~OleComponent();
103 
104 	OleComponent* createEmbeddedCopyOfLink();
105 
106 	void disconnectEmbeddedObject();
107 
108 	static ::com::sun::star::awt::Size CalculateWithFactor( const ::com::sun::star::awt::Size& aSize,
109 															const ::com::sun::star::awt::Size& aMultiplier,
110 															const ::com::sun::star::awt::Size& aDivisor );
111 
112 	::com::sun::star::awt::Size CalculateTheRealSize( const ::com::sun::star::awt::Size& aContSize, sal_Bool bUpdate );
113 
114 	// ==== Initialization ==================================================
115 	void LoadEmbeddedObject( const ::rtl::OUString& aTempURL );
116 
117 	void CreateObjectFromClipboard();
118 
119 	void CreateNewEmbeddedObject( const ::com::sun::star::uno::Sequence< sal_Int8 >& aSeqCLSID );
120 
121 	void CreateObjectFromData(
122 						const ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable >& xTransfer );
123 
124 	void CreateObjectFromFile( const ::rtl::OUString& aFileName );
125 
126 	void CreateLinkFromFile( const ::rtl::OUString& aFileName );
127 
128 	void InitEmbeddedCopyOfLink( OleComponent* pOleLinkComponent );
129 
130 	// ======================================================================
131 
132 	void RunObject(); // switch OLE object to running state
133 
134 	void CloseObject(); // switch OLE object to loaded state
135 
136 	::com::sun::star::uno::Sequence< ::com::sun::star::embed::VerbDescriptor > GetVerbList();
137 
138 	void ExecuteVerb( sal_Int32 nVerbID );
139 
140 	void SetHostName( const ::rtl::OUString& aContName, const ::rtl::OUString& aEmbDocName );
141 
142 	void SetExtent( const ::com::sun::star::awt::Size& aVisAreaSize, sal_Int64 nAspect );
143 
144 	::com::sun::star::awt::Size GetExtent( sal_Int64 nAspect );
145 	::com::sun::star::awt::Size GetCachedExtent( sal_Int64 nAspect );
146 	::com::sun::star::awt::Size GetReccomendedExtent( sal_Int64 nAspect );
147 
148 	sal_Int64 GetMiscStatus( sal_Int64 nAspect );
149 
150 	::com::sun::star::uno::Sequence< sal_Int8 > GetCLSID();
151 
IsWorkaroundActive()152 	sal_Bool IsWorkaroundActive() { return m_bWorkaroundActive; }
153 
154 	sal_Bool IsDirty();
155 
156 	void StoreOwnTmpIfNecessary();
157 
158 	sal_Bool SaveObject_Impl();
159 	sal_Bool OnShowWindow_Impl( bool bShow );
160 	void OnViewChange_Impl( sal_uInt32 dwAspect );
161 	void OnClose_Impl();
162 
163 	// XCloseable
164     virtual void SAL_CALL close( sal_Bool DeliverOwnership ) throw (::com::sun::star::util::CloseVetoException, ::com::sun::star::uno::RuntimeException);
165     virtual void SAL_CALL addCloseListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloseListener >& Listener ) throw (::com::sun::star::uno::RuntimeException);
166     virtual void SAL_CALL removeCloseListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloseListener >& Listener ) throw (::com::sun::star::uno::RuntimeException);
167 
168 	// XTransferable
169     virtual ::com::sun::star::uno::Any SAL_CALL getTransferData( const ::com::sun::star::datatransfer::DataFlavor& aFlavor ) throw (::com::sun::star::datatransfer::UnsupportedFlavorException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
170     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::datatransfer::DataFlavor > SAL_CALL getTransferDataFlavors(  ) throw (::com::sun::star::uno::RuntimeException);
171     virtual sal_Bool SAL_CALL isDataFlavorSupported( const ::com::sun::star::datatransfer::DataFlavor& aFlavor ) throw (::com::sun::star::uno::RuntimeException);
172 
173     // XComponent
174     virtual void SAL_CALL dispose() throw (::com::sun::star::uno::RuntimeException);
175     virtual void SAL_CALL addEventListener(const com::sun::star::uno::Reference < com::sun::star::lang::XEventListener >& aListener) throw (::com::sun::star::uno::RuntimeException);
176     virtual void SAL_CALL removeEventListener(const com::sun::star::uno::Reference < com::sun::star::lang::XEventListener >& aListener) throw (::com::sun::star::uno::RuntimeException);
177 
178 	// XUnoTunnel
179     virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException) ;
180 
181     // XModifiable
182     virtual sal_Bool SAL_CALL isModified() throw (::com::sun::star::uno::RuntimeException);
183 	virtual void SAL_CALL setModified( sal_Bool bModified )
184         throw (::com::sun::star::beans::PropertyVetoException, ::com::sun::star::uno::RuntimeException);
185     virtual void SAL_CALL addModifyListener( const com::sun::star::uno::Reference < com::sun::star::util::XModifyListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);
186     virtual void SAL_CALL removeModifyListener( const com::sun::star::uno::Reference < com::sun::star::util::XModifyListener >& xListener) throw(::com::sun::star::uno::RuntimeException);
187 };
188 
189 #endif
190 
191