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