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 _INPROCEMBOBJ_HXX_ 25 #define _INPROCEMBOBJ_HXX_ 26 27 #pragma warning(disable : 4668) 28 29 #include <windows.h> 30 #include <oleidl.h> 31 32 #include "smartpointer.hxx" 33 #include "advisesink.hxx" 34 35 #define DEFAULT_ARRAY_LEN 256 36 37 namespace inprocserv { 38 39 enum InitModes { 40 NOINIT, 41 INIT_FROM_STORAGE, 42 LOAD_FROM_STORAGE, 43 LOAD_FROM_FILE 44 }; 45 46 // ================================== 47 // this is a common baseclass that is used to count the objects 48 // ================================== 49 class InprocCountedObject_Impl 50 { 51 public: 52 InprocCountedObject_Impl(); 53 ~InprocCountedObject_Impl(); 54 }; 55 56 // ================================== 57 // this is the inprocess embedded object implementation class 58 // ================================== 59 class InprocEmbedDocument_Impl : public InprocCountedObject_Impl 60 , public IOleObject 61 , public IDataObject 62 , public IPersistStorage 63 , public IPersistFile 64 , public IRunnableObject 65 , public IViewObject2 66 // , public IExternalConnection 67 , public IOleInPlaceObject 68 , public IDispatch 69 { 70 ULONG m_refCount; 71 BOOLEAN m_bDeleted; 72 73 GUID m_guid; 74 75 ComSmart< IUnknown > m_pDefHandler; 76 InitModes m_nInitMode; 77 78 DWORD m_nFileOpenMode; 79 wchar_t* m_pFileName; 80 81 ComSmart< IStorage > m_pStorage; 82 83 ComSmart< IOleClientSite > m_pClientSite; 84 ComSmart< IOleContainer > m_pOleContainer; 85 86 ULONG m_nCallsOnStack; 87 88 // the listeners have wrappers that are directly connected to the object and call the listeners, 89 // the wrappers will be reconnected correctly to the new default inprocess holder object 90 ComSmart< OleWrapperAdviseSink > m_pOleAdvises[DEFAULT_ARRAY_LEN]; 91 ComSmart< OleWrapperAdviseSink > m_pDataAdvises[DEFAULT_ARRAY_LEN]; 92 ComSmart< OleWrapperAdviseSink > m_pViewAdvise; 93 94 class InternalCacheWrapper : public IOleCache2 95 { 96 InprocEmbedDocument_Impl& m_rOwnDocument; 97 98 public: InternalCacheWrapper(InprocEmbedDocument_Impl & rOwnDocument)99 InternalCacheWrapper( InprocEmbedDocument_Impl& rOwnDocument ) 100 : m_rOwnDocument( rOwnDocument ) 101 {} 102 103 /* IUnknown methods */ 104 STDMETHOD(QueryInterface)(REFIID riid, LPVOID FAR * ppvObj); 105 STDMETHOD_(ULONG, AddRef)(); 106 STDMETHOD_(ULONG, Release)(); 107 108 /* IOleCache2 methods */ 109 STDMETHOD(Cache)( FORMATETC *pformatetc, DWORD advf, DWORD *pdwConnection); 110 STDMETHOD(Uncache)( DWORD dwConnection); 111 STDMETHOD(EnumCache)( IEnumSTATDATA **ppenumSTATDATA); 112 STDMETHOD(InitCache)( IDataObject *pDataObject); 113 STDMETHOD(SetData)( FORMATETC *pformatetc, STGMEDIUM *pmedium, BOOL fRelease); 114 STDMETHOD(UpdateCache)( LPDATAOBJECT pDataObject, DWORD grfUpdf, LPVOID pReserved); 115 STDMETHOD(DiscardCache)( DWORD dwDiscardOptions); 116 } m_aInternalCache; 117 118 119 DWORD InsertAdviseLinkToList( const ComSmart<OleWrapperAdviseSink>& pOwnAdvise, ComSmart< OleWrapperAdviseSink > pAdvises[] ); 120 void Clean(); 121 122 123 public: 124 InprocEmbedDocument_Impl(const GUID & guid)125 InprocEmbedDocument_Impl( const GUID& guid ) 126 : m_refCount( 0 ) 127 , m_bDeleted( FALSE ) 128 , m_guid( guid ) 129 , m_nInitMode( NOINIT ) 130 , m_nFileOpenMode( 0 ) 131 , m_pFileName( NULL ) 132 , m_nCallsOnStack( 0 ) 133 , m_aInternalCache( *this ) 134 {} 135 ~InprocEmbedDocument_Impl()136 virtual ~InprocEmbedDocument_Impl() 137 {} 138 139 HRESULT Init(); 140 void SetName( LPCOLESTR pszNameFromOutside, wchar_t*& pOwnName ); 141 142 BOOL CheckDefHandler(); GetDefHandler()143 ComSmart< IUnknown >& GetDefHandler() { return m_pDefHandler; } 144 145 /* IUnknown methods */ 146 STDMETHOD(QueryInterface)(REFIID riid, LPVOID FAR * ppvObj); 147 STDMETHOD_(ULONG, AddRef)(); 148 STDMETHOD_(ULONG, Release)(); 149 150 /* IOleObject methods */ 151 STDMETHOD(SetClientSite) ( IOleClientSite* pSite ); 152 STDMETHOD(GetClientSite) ( IOleClientSite** pSite ); 153 STDMETHOD(SetHostNames) ( LPCOLESTR szContainerApp, LPCOLESTR szContainerObj ); 154 STDMETHOD(Close) ( DWORD dwSaveOption); 155 STDMETHOD(SetMoniker) ( DWORD dwWhichMoniker, IMoniker *pmk ); 156 STDMETHOD(GetMoniker) ( DWORD dwAssign, DWORD dwWhichMoniker, IMoniker **ppmk ); 157 STDMETHOD(InitFromData) ( IDataObject *pDataObject, BOOL fCreation, DWORD dwReserved ); 158 STDMETHOD(GetClipboardData) ( DWORD dwReserved, IDataObject **ppDataObject ); 159 STDMETHOD(DoVerb) ( LONG iVerb, LPMSG lpmsg, IOleClientSite *pActiveSite, LONG lindex, HWND hwndParent, LPCRECT lprcPosRect ); 160 STDMETHOD(EnumVerbs) ( IEnumOLEVERB **ppEnumOleVerb ); 161 STDMETHOD(Update) (); 162 STDMETHOD(IsUpToDate) (); 163 STDMETHOD(GetUserClassID) ( CLSID *pClsid ); 164 STDMETHOD(GetUserType) ( DWORD dwFormOfType, LPOLESTR *pszUserType ); 165 STDMETHOD(SetExtent) ( DWORD dwDrawAspect, SIZEL *psizel ); 166 STDMETHOD(GetExtent) ( DWORD dwDrawAspect, SIZEL *psizel ); 167 STDMETHOD(Advise) ( IAdviseSink *pAdvSink, DWORD *pdwConnection ); 168 STDMETHOD(Unadvise) ( DWORD dwConnection ); 169 STDMETHOD(EnumAdvise) ( IEnumSTATDATA **ppenumAdvise ); 170 STDMETHOD(GetMiscStatus) ( DWORD dwAspect, DWORD *pdwStatus ); 171 STDMETHOD(SetColorScheme) ( LOGPALETTE *pLogpal ); 172 173 /* IDataObject methods */ 174 STDMETHOD(GetData) ( FORMATETC * pFormatetc, STGMEDIUM * pMedium ); 175 STDMETHOD(GetDataHere) ( FORMATETC * pFormatetc, STGMEDIUM * pMedium ); 176 STDMETHOD(QueryGetData) ( FORMATETC * pFormatetc ); 177 STDMETHOD(GetCanonicalFormatEtc) ( FORMATETC * pFormatetcIn, FORMATETC * pFormatetcOut ); 178 STDMETHOD(SetData) ( FORMATETC * pFormatetc, STGMEDIUM * pMedium, BOOL fRelease ); 179 STDMETHOD(EnumFormatEtc) ( DWORD dwDirection, IEnumFORMATETC ** ppFormatetc ); 180 STDMETHOD(DAdvise) ( FORMATETC * pFormatetc, DWORD advf, IAdviseSink * pAdvSink, DWORD * pdwConnection ); 181 STDMETHOD(DUnadvise) ( DWORD dwConnection ); 182 STDMETHOD(EnumDAdvise) ( IEnumSTATDATA ** ppenumAdvise ); 183 184 /* IPersistMethod */ 185 STDMETHOD(GetClassID)(CLSID *pClassID); 186 187 /* IPersistStorage methods */ 188 STDMETHOD(IsDirty) (); 189 STDMETHOD(InitNew) ( IStorage *pStg ); 190 STDMETHOD(Load) ( IStorage* pStr ); 191 STDMETHOD(Save) ( IStorage *pStgSave, BOOL fSameAsLoad ); 192 STDMETHOD(SaveCompleted) ( IStorage *pStgNew ); 193 STDMETHOD(HandsOffStorage) (void); 194 195 /* IPersistFile methods */ 196 STDMETHOD(Load) ( LPCOLESTR pszFileName, DWORD dwMode ); 197 STDMETHOD(Save) ( LPCOLESTR pszFileName, BOOL fRemember ); 198 STDMETHOD(SaveCompleted) ( LPCOLESTR pszFileName ); 199 STDMETHOD(GetCurFile) ( LPOLESTR *ppszFileName ); 200 201 /* IRunnableObject methods */ 202 STDMETHOD(GetRunningClass) ( LPCLSID lpClsid); 203 STDMETHOD(Run) ( LPBINDCTX pbc); 204 virtual BOOL STDMETHODCALLTYPE IsRunning( void); 205 STDMETHOD(LockRunning) ( BOOL fLock, BOOL fLastUnlockCloses ); 206 STDMETHOD(SetContainedObject) ( BOOL fContained); 207 208 /* IViewObject2 methods */ 209 STDMETHOD(Draw)( DWORD dwDrawAspect, LONG lindex, void *pvAspect, DVTARGETDEVICE *ptd, HDC hdcTargetDev, HDC hdcDraw, LPCRECTL lprcBounds, LPCRECTL lprcWBounds, BOOL ( STDMETHODCALLTYPE *pfnContinue )( ULONG_PTR dwContinue ), ULONG_PTR dwContinue); 210 STDMETHOD(GetColorSet)( DWORD dwDrawAspect, LONG lindex, void *pvAspect, DVTARGETDEVICE *ptd, HDC hicTargetDev, LOGPALETTE **ppColorSet); 211 STDMETHOD(Freeze)( DWORD dwDrawAspect, LONG lindex, void *pvAspect, DWORD *pdwFreeze); 212 STDMETHOD(Unfreeze)( DWORD dwFreeze); 213 STDMETHOD(SetAdvise)( DWORD aspects, DWORD advf, IAdviseSink *pAdvSink); 214 STDMETHOD(GetAdvise)( DWORD *pAspects, DWORD *pAdvf, IAdviseSink **ppAdvSink); 215 STDMETHOD(GetExtent)( DWORD dwDrawAspect, LONG lindex, DVTARGETDEVICE *ptd, LPSIZEL lpsizel); 216 217 /* IOleWindow methods */ 218 STDMETHOD(GetWindow)( HWND *phwnd); 219 STDMETHOD(ContextSensitiveHelp)( BOOL fEnterMode); 220 221 /* IOleInPlaceObject methods */ 222 STDMETHOD(InPlaceDeactivate)( void); 223 STDMETHOD(UIDeactivate)( void); 224 STDMETHOD(SetObjectRects)( LPCRECT lprcPosRect, LPCRECT lprcClipRect); 225 STDMETHOD(ReactivateAndUndo)( void); 226 227 /*IDispatch methods*/ 228 STDMETHOD(GetTypeInfoCount)( UINT *pctinfo); 229 STDMETHOD(GetTypeInfo)( UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo); 230 STDMETHOD(GetIDsOfNames)( REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId); 231 STDMETHOD(Invoke)( DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr); 232 233 }; 234 235 } // namespace inprocserv 236 237 #endif 238 239