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 _EMBEDDOC_HXX_ 25 #define _EMBEDDOC_HXX_ 26 #if defined(_MSC_VER) && (_MSC_VER >= 1300) 27 #undef _DEBUG 28 #endif 29 #if defined(_MSC_VER) && (_MSC_VER > 1310) 30 #pragma warning(disable : 4917 4555) 31 #endif 32 33 #include "common.h" 34 #include <oleidl.h> 35 #include <objidl.h> 36 37 #include <hash_map> 38 #include <com/sun/star/uno/Reference.h> 39 #ifndef _COM_SUN_STAR_UNO_SEQUENCE_H_ 40 #include <com/sun/star/uno/SEQUENCE.h> 41 #endif 42 43 #include "embeddocaccess.hxx" 44 #include "docholder.hxx" 45 46 typedef ::std::hash_map< DWORD, IAdviseSink* > AdviseSinkHashMap; 47 typedef ::std::hash_map< DWORD, IAdviseSink* >::iterator AdviseSinkHashMapIterator; 48 49 class GDIMetaFile; 50 class CIIAObj; 51 52 class EmbedDocument_Impl 53 : public IPersistStorage, 54 public IDataObject, 55 public IOleObject, 56 public IOleInPlaceObject, 57 public IPersistFile, 58 public IDispatch, 59 public IExternalConnection 60 { 61 protected: 62 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > 63 fillArgsForLoading_Impl( ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > xStream, 64 DWORD nStreamMode, 65 LPCOLESTR pFilePath = NULL ); 66 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > 67 fillArgsForStoring_Impl( ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > xStream ); 68 69 HRESULT SaveTo_Impl( IStorage* pStg ); 70 71 sal_uInt64 getMetaFileHandle_Impl( sal_Bool isEnhMeta ); 72 73 public: 74 EmbedDocument_Impl( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& smgr, 75 const GUID* guid ); 76 virtual ~EmbedDocument_Impl(); 77 78 /* IUnknown methods */ 79 STDMETHOD(QueryInterface)(REFIID riid, LPVOID FAR * ppvObj); 80 STDMETHOD_(ULONG, AddRef)(); 81 STDMETHOD_(ULONG, Release)(); 82 83 /* IPersistMethod */ 84 STDMETHOD(GetClassID)(CLSID *pClassID); 85 86 /* IPersistStorage methods */ 87 STDMETHOD(IsDirty) (); 88 STDMETHOD(InitNew) ( IStorage *pStg ); 89 STDMETHOD(Load) ( IStorage* pStr ); 90 STDMETHOD(Save) ( IStorage *pStgSave, BOOL fSameAsLoad ); 91 STDMETHOD(SaveCompleted) ( IStorage *pStgNew ); 92 STDMETHOD(HandsOffStorage) (void); 93 94 /* IDataObject methods */ 95 STDMETHOD(GetData) ( FORMATETC * pFormatetc, STGMEDIUM * pMedium ); 96 STDMETHOD(GetDataHere) ( FORMATETC * pFormatetc, STGMEDIUM * pMedium ); 97 STDMETHOD(QueryGetData) ( FORMATETC * pFormatetc ); 98 STDMETHOD(GetCanonicalFormatEtc) ( FORMATETC * pFormatetcIn, FORMATETC * pFormatetcOut ); 99 STDMETHOD(SetData) ( FORMATETC * pFormatetc, STGMEDIUM * pMedium, BOOL fRelease ); 100 STDMETHOD(EnumFormatEtc) ( DWORD dwDirection, IEnumFORMATETC ** ppFormatetc ); 101 STDMETHOD(DAdvise) ( FORMATETC * pFormatetc, DWORD advf, IAdviseSink * pAdvSink, DWORD * pdwConnection ); 102 STDMETHOD(DUnadvise) ( DWORD dwConnection ); 103 STDMETHOD(EnumDAdvise) ( IEnumSTATDATA ** ppenumAdvise ); 104 105 /* IOleObject methods */ 106 STDMETHOD(SetClientSite) ( IOleClientSite* pSite ); 107 STDMETHOD(GetClientSite) ( IOleClientSite** pSite ); 108 STDMETHOD(SetHostNames) ( LPCOLESTR szContainerApp, LPCOLESTR szContainerObj ); 109 STDMETHOD(Close) ( DWORD dwSaveOption); 110 STDMETHOD(SetMoniker) ( DWORD dwWhichMoniker, IMoniker *pmk ); 111 STDMETHOD(GetMoniker) ( DWORD dwAssign, DWORD dwWhichMoniker, IMoniker **ppmk ); 112 STDMETHOD(InitFromData) ( IDataObject *pDataObject, BOOL fCreation, DWORD dwReserved ); 113 STDMETHOD(GetClipboardData) ( DWORD dwReserved, IDataObject **ppDataObject ); 114 STDMETHOD(DoVerb) ( LONG iVerb, LPMSG lpmsg, IOleClientSite *pActiveSite, LONG lindex, HWND hwndParent, LPCRECT lprcPosRect ); 115 STDMETHOD(EnumVerbs) ( IEnumOLEVERB **ppEnumOleVerb ); 116 STDMETHOD(Update) (); 117 STDMETHOD(IsUpToDate) (); 118 STDMETHOD(GetUserClassID) ( CLSID *pClsid ); 119 STDMETHOD(GetUserType) ( DWORD dwFormOfType, LPOLESTR *pszUserType ); 120 STDMETHOD(SetExtent) ( DWORD dwDrawAspect, SIZEL *psizel ); 121 STDMETHOD(GetExtent) ( DWORD dwDrawAspect, SIZEL *psizel ); 122 STDMETHOD(Advise) ( IAdviseSink *pAdvSink, DWORD *pdwConnection ); 123 STDMETHOD(Unadvise) ( DWORD dwConnection ); 124 STDMETHOD(EnumAdvise) ( IEnumSTATDATA **ppenumAdvise ); 125 STDMETHOD(GetMiscStatus) ( DWORD dwAspect, DWORD *pdwStatus ); 126 STDMETHOD(SetColorScheme) ( LOGPALETTE *pLogpal ); 127 128 /* IOleInPlaceObject methods */ 129 STDMETHOD(GetWindow)(HWND *); 130 STDMETHOD(ContextSensitiveHelp)(BOOL); 131 STDMETHOD(InPlaceDeactivate)(); 132 STDMETHOD(UIDeactivate)(); 133 STDMETHOD(SetObjectRects)(LPCRECT, LPCRECT); 134 STDMETHOD(ReactivateAndUndo)(); 135 136 /* IPersistFile methods */ 137 STDMETHOD(Load) ( LPCOLESTR pszFileName, DWORD dwMode ); 138 STDMETHOD(Save) ( LPCOLESTR pszFileName, BOOL fRemember ); 139 STDMETHOD(SaveCompleted) ( LPCOLESTR pszFileName ); 140 STDMETHOD(GetCurFile) ( LPOLESTR *ppszFileName ); 141 142 /* IDispatch methods */ 143 STDMETHOD(GetTypeInfoCount) ( unsigned int FAR* pctinfo ); 144 STDMETHOD(GetTypeInfo) ( unsigned int iTInfo, LCID lcid, ITypeInfo FAR* FAR* ppTInfo ); 145 STDMETHOD(GetIDsOfNames) ( REFIID riid, OLECHAR FAR* FAR* rgszNames, unsigned int cNames, LCID lcid, DISPID FAR* rgDispId ); 146 STDMETHOD(Invoke) ( DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS FAR* pDispParams, VARIANT FAR* pVarResult, EXCEPINFO FAR* pExcepInfo, unsigned int FAR* puArgErr ); 147 148 /* IExternalConnection methods */ 149 virtual DWORD STDMETHODCALLTYPE AddConnection( DWORD extconn, DWORD reserved); 150 virtual DWORD STDMETHODCALLTYPE ReleaseConnection( DWORD extconn, DWORD reserved, BOOL fLastReleaseCloses); 151 152 // c++ - methods 153 154 void notify( bool bDataChanged = true ); 155 HRESULT SaveObject(); 156 HRESULT ShowObject(); 157 GUID GetGUID() const { return m_guid; } 158 HRESULT OLENotifyClosing(); 159 160 void Deactivate(); 161 HRESULT OLENotifyDeactivation(); 162 163 protected: 164 oslInterlockedCount m_refCount; 165 166 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xFactory; 167 168 DocumentHolder* m_pDocHolder; 169 ::rtl::OUString m_aFileName; 170 171 CComPtr< IStorage > m_pMasterStorage; 172 CComPtr< IStream > m_pOwnStream; 173 CComPtr< IStream > m_pExtStream; 174 GUID m_guid; 175 176 sal_Bool m_bIsDirty; 177 178 CComPtr< IOleClientSite > m_pClientSite; 179 CComPtr< IDataAdviseHolder > m_pDAdviseHolder; 180 181 AdviseSinkHashMap m_aAdviseHashMap; 182 DWORD m_nAdviseNum; 183 184 ::rtl::Reference< EmbeddedDocumentInstanceAccess_Impl > m_xOwnAccess; 185 186 sal_Bool m_bIsInVerbHandling; 187 }; 188 189 class BooleanGuard_Impl 190 { 191 sal_Bool& m_bValue; 192 193 public: 194 BooleanGuard_Impl( sal_Bool& bValue ) 195 : m_bValue( bValue ) 196 { 197 m_bValue = sal_True; 198 } 199 200 ~BooleanGuard_Impl() 201 { 202 m_bValue = sal_False; 203 } 204 }; 205 206 #endif //_EMBEDDOC_HXX_ 207