Avoid potential negative array index access to cached text.
[LibreOffice.git] / embedserv / source / inc / embeddoc.hxx
blob1ff0ed338cf453b133089e18c7284ce4b368468a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #pragma once
22 #include "common.h"
23 #include <oleidl.h>
24 #include <objidl.h>
26 #include <com/sun/star/uno/Reference.h>
27 #include <com/sun/star/uno/Sequence.h>
28 #include <rtl/ref.hxx>
29 #include <unordered_map>
31 #include "embeddocaccess.hxx"
32 #include "docholder.hxx"
34 typedef std::unordered_map< DWORD, IAdviseSink* > AdviseSinkHashMap;
36 class GDIMetaFile;
37 class CIIAObj;
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
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 );
56 HRESULT SaveTo_Impl( IStorage* pStg );
58 sal_uInt64 getMetaFileHandle_Impl( bool isEnhMeta );
60 public:
61 EmbedDocument_Impl( const css::uno::Reference< css::lang::XMultiServiceFactory >& smgr,
62 const GUID* guid );
63 virtual ~EmbedDocument_Impl();
65 /* IUnknown methods */
66 STDMETHOD(QueryInterface)(REFIID riid, LPVOID* ppvObj) override;
67 STDMETHOD_(ULONG, AddRef)() override;
68 STDMETHOD_(ULONG, Release)() override;
70 /* IPersistMethod */
71 STDMETHOD(GetClassID)(CLSID *pClassID) override;
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;
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;
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;
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;
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;
129 /* IDispatch methods */
130 STDMETHOD(GetTypeInfoCount)(unsigned int* pctinfo) override;
131 STDMETHOD(GetTypeInfo)(unsigned int iTInfo, LCID lcid, ITypeInfo** ppTInfo) override;
132 STDMETHOD(GetIDsOfNames)(REFIID riid, OLECHAR** rgszNames, unsigned int cNames, LCID lcid, DISPID* rgDispId) override;
133 STDMETHOD(Invoke)(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, unsigned int* puArgErr) override;
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;
139 // c++ - methods
141 void notify( bool bDataChanged = true );
142 HRESULT SaveObject();
143 HRESULT ShowObject();
144 GUID GetGUID() const { return m_guid; }
145 HRESULT OLENotifyClosing();
147 void Deactivate();
148 HRESULT OLENotifyDeactivation();
150 protected:
151 oslInterlockedCount m_refCount;
153 css::uno::Reference< css::lang::XMultiServiceFactory > m_xFactory;
155 rtl::Reference<DocumentHolder> m_pDocHolder;
156 OUString m_aFileName;
158 CComPtr< IStorage > m_pMasterStorage;
159 CComPtr< IStream > m_pOwnStream;
160 CComPtr< IStream > m_pExtStream;
161 GUID m_guid;
163 bool m_bIsDirty;
165 CComPtr< IOleClientSite > m_pClientSite;
166 CComPtr< IDataAdviseHolder > m_pDAdviseHolder;
168 AdviseSinkHashMap m_aAdviseHashMap;
169 DWORD m_nAdviseNum;
171 ::rtl::Reference< EmbeddedDocumentInstanceAccess_Impl > m_xOwnAccess;
173 bool m_bIsInVerbHandling;
176 class BooleanGuard_Impl
178 bool& m_bValue;
180 public:
181 BooleanGuard_Impl( bool& bValue )
182 : m_bValue( bValue )
184 m_bValue = true;
187 ~BooleanGuard_Impl()
189 m_bValue = false;
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */