Avoid potential negative array index access to cached text.
[LibreOffice.git] / embedserv / source / inprocserv / inprocembobj.h
blob8591a56c3e8704b8a9f9f99dcbec1f60cca5f432
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 #ifndef INCLUDED_EMBEDSERV_SOURCE_INPROCSERV_INPROCEMBOBJ_H
21 #define INCLUDED_EMBEDSERV_SOURCE_INPROCSERV_INPROCEMBOBJ_H
23 #if !defined WIN32_LEAN_AND_MEAN
24 # define WIN32_LEAN_AND_MEAN
25 #endif
26 #include <windows.h>
27 #include <oleidl.h>
29 #include <systools/win32/comtools.hxx>
30 #include "advisesink.hxx"
32 #define DEFAULT_ARRAY_LEN 256
34 namespace inprocserv {
36 enum InitModes {
37 NOINIT,
38 INIT_FROM_STORAGE,
39 LOAD_FROM_STORAGE,
40 LOAD_FROM_FILE
44 // this is a common baseclass that is used to count the objects
46 class InprocCountedObject_Impl
48 public:
49 InprocCountedObject_Impl();
50 ~InprocCountedObject_Impl();
54 // this is the inprocess embedded object implementation class
56 class InprocEmbedDocument_Impl : public InprocCountedObject_Impl
57 , public IOleObject
58 , public IDataObject
59 , public IPersistStorage
60 , public IPersistFile
61 , public IRunnableObject
62 , public IViewObject2
63 // , public IExternalConnection
64 , public IOleInPlaceObject
65 , public IDispatch
67 ULONG m_refCount;
68 BOOLEAN m_bDeleted;
70 GUID m_guid;
72 sal::systools::COMReference< IUnknown > m_pDefHandler;
73 InitModes m_nInitMode;
75 DWORD m_nFileOpenMode;
76 wchar_t* m_pFileName;
78 sal::systools::COMReference< IStorage > m_pStorage;
80 sal::systools::COMReference< IOleClientSite > m_pClientSite;
81 sal::systools::COMReference< IOleContainer > m_pOleContainer;
83 ULONG m_nCallsOnStack;
85 // the listeners have wrappers that are directly connected to the object and call the listeners,
86 // the wrappers will be reconnected correctly to the new default inprocess holder object
87 sal::systools::COMReference< OleWrapperAdviseSink > m_pOleAdvises[DEFAULT_ARRAY_LEN];
88 sal::systools::COMReference< OleWrapperAdviseSink > m_pDataAdvises[DEFAULT_ARRAY_LEN];
89 sal::systools::COMReference< OleWrapperAdviseSink > m_pViewAdvise;
91 class InternalCacheWrapper final: public IOleCache2
93 InprocEmbedDocument_Impl& m_rOwnDocument;
95 public:
96 explicit InternalCacheWrapper( InprocEmbedDocument_Impl& rOwnDocument )
97 : m_rOwnDocument( rOwnDocument )
100 virtual ~InternalCacheWrapper() {}
102 /* IUnknown methods */
103 STDMETHOD(QueryInterface)(REFIID riid, void ** ppvObj) override;
104 STDMETHOD_(ULONG, AddRef)() override;
105 STDMETHOD_(ULONG, Release)() override;
107 /* IOleCache2 methods */
108 STDMETHOD(Cache)( FORMATETC *pformatetc, DWORD advf, DWORD *pdwConnection) override;
109 STDMETHOD(Uncache)( DWORD dwConnection) override;
110 STDMETHOD(EnumCache)( IEnumSTATDATA **ppenumSTATDATA) override;
111 STDMETHOD(InitCache)( IDataObject *pDataObject) override;
112 STDMETHOD(SetData)( FORMATETC *pformatetc, STGMEDIUM *pmedium, BOOL fRelease) override;
113 STDMETHOD(UpdateCache)( LPDATAOBJECT pDataObject, DWORD grfUpdf, LPVOID pReserved) override;
114 STDMETHOD(DiscardCache)( DWORD dwDiscardOptions) override;
115 } m_aInternalCache;
117 void Clean();
120 public:
122 explicit InprocEmbedDocument_Impl( const GUID& guid )
123 : m_refCount( 0 )
124 , m_bDeleted( FALSE )
125 , m_guid( guid )
126 , m_nInitMode( NOINIT )
127 , m_nFileOpenMode( 0 )
128 , m_pFileName( nullptr )
129 , m_nCallsOnStack( 0 )
130 , m_aInternalCache( *this )
133 virtual ~InprocEmbedDocument_Impl()
136 BOOL CheckDefHandler();
137 sal::systools::COMReference< IUnknown >& GetDefHandler() { return m_pDefHandler; }
139 /* IUnknown methods */
140 STDMETHOD(QueryInterface)(REFIID riid, void ** ppvObj) override;
141 STDMETHOD_(ULONG, AddRef)() override;
142 STDMETHOD_(ULONG, Release)() override;
144 /* IOleObject methods */
145 STDMETHOD(SetClientSite) ( IOleClientSite* pSite ) override;
146 STDMETHOD(GetClientSite) ( IOleClientSite** pSite ) override;
147 STDMETHOD(SetHostNames) ( LPCOLESTR szContainerApp, LPCOLESTR szContainerObj ) override;
148 STDMETHOD(Close) ( DWORD dwSaveOption) override;
149 STDMETHOD(SetMoniker) ( DWORD dwWhichMoniker, IMoniker *pmk ) override;
150 STDMETHOD(GetMoniker) ( DWORD dwAssign, DWORD dwWhichMoniker, IMoniker **ppmk ) override;
151 STDMETHOD(InitFromData) ( IDataObject *pDataObject, BOOL fCreation, DWORD dwReserved ) override;
152 STDMETHOD(GetClipboardData) ( DWORD dwReserved, IDataObject **ppDataObject ) override;
153 STDMETHOD(DoVerb) ( LONG iVerb, LPMSG lpmsg, IOleClientSite *pActiveSite, LONG lindex, HWND hwndParent, LPCRECT lprcPosRect ) override;
154 STDMETHOD(EnumVerbs) ( IEnumOLEVERB **ppEnumOleVerb ) override;
155 STDMETHOD(Update) () override;
156 STDMETHOD(IsUpToDate) () override;
157 STDMETHOD(GetUserClassID) ( CLSID *pClsid ) override;
158 STDMETHOD(GetUserType) ( DWORD dwFormOfType, LPOLESTR *pszUserType ) override;
159 STDMETHOD(SetExtent) ( DWORD dwDrawAspect, SIZEL *psizel ) override;
160 STDMETHOD(GetExtent) ( DWORD dwDrawAspect, SIZEL *psizel ) override;
161 STDMETHOD(Advise) ( IAdviseSink *pAdvSink, DWORD *pdwConnection ) override;
162 STDMETHOD(Unadvise) ( DWORD dwConnection ) override;
163 STDMETHOD(EnumAdvise) ( IEnumSTATDATA **ppenumAdvise ) override;
164 STDMETHOD(GetMiscStatus) ( DWORD dwAspect, DWORD *pdwStatus ) override;
165 STDMETHOD(SetColorScheme) ( LOGPALETTE *pLogpal ) override;
167 /* IDataObject methods */
168 STDMETHOD(GetData) ( FORMATETC * pFormatetc, STGMEDIUM * pMedium ) override;
169 STDMETHOD(GetDataHere) ( FORMATETC * pFormatetc, STGMEDIUM * pMedium ) override;
170 STDMETHOD(QueryGetData) ( FORMATETC * pFormatetc ) override;
171 STDMETHOD(GetCanonicalFormatEtc) ( FORMATETC * pFormatetcIn, FORMATETC * pFormatetcOut ) override;
172 STDMETHOD(SetData) ( FORMATETC * pFormatetc, STGMEDIUM * pMedium, BOOL fRelease ) override;
173 STDMETHOD(EnumFormatEtc) ( DWORD dwDirection, IEnumFORMATETC ** ppFormatetc ) override;
174 STDMETHOD(DAdvise) ( FORMATETC * pFormatetc, DWORD advf, IAdviseSink * pAdvSink, DWORD * pdwConnection ) override;
175 STDMETHOD(DUnadvise) ( DWORD dwConnection ) override;
176 STDMETHOD(EnumDAdvise) ( IEnumSTATDATA ** ppenumAdvise ) override;
178 /* IPersistMethod */
179 STDMETHOD(GetClassID)(CLSID *pClassID) override;
181 /* IPersistStorage methods */
182 STDMETHOD(IsDirty) () override;
183 STDMETHOD(InitNew) ( IStorage *pStg ) override;
184 STDMETHOD(Load) ( IStorage* pStr ) override;
185 STDMETHOD(Save) ( IStorage *pStgSave, BOOL fSameAsLoad ) override;
186 STDMETHOD(SaveCompleted) ( IStorage *pStgNew ) override;
187 STDMETHOD(HandsOffStorage) (void) override;
189 /* IPersistFile methods */
190 STDMETHOD(Load) ( LPCOLESTR pszFileName, DWORD dwMode ) override;
191 STDMETHOD(Save) ( LPCOLESTR pszFileName, BOOL fRemember ) override;
192 STDMETHOD(SaveCompleted) ( LPCOLESTR pszFileName ) override;
193 STDMETHOD(GetCurFile) ( LPOLESTR *ppszFileName ) override;
195 /* IRunnableObject methods */
196 STDMETHOD(GetRunningClass) ( LPCLSID lpClsid) override;
197 STDMETHOD(Run) ( LPBINDCTX pbc) override;
198 virtual BOOL STDMETHODCALLTYPE IsRunning( void) override;
199 STDMETHOD(LockRunning) ( BOOL fLock, BOOL fLastUnlockCloses ) override;
200 STDMETHOD(SetContainedObject) ( BOOL fContained) override;
202 /* IViewObject2 methods */
203 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) override;
204 STDMETHOD(GetColorSet)( DWORD dwDrawAspect, LONG lindex, void *pvAspect, DVTARGETDEVICE *ptd, HDC hicTargetDev, LOGPALETTE **ppColorSet) override;
205 STDMETHOD(Freeze)( DWORD dwDrawAspect, LONG lindex, void *pvAspect, DWORD *pdwFreeze) override;
206 STDMETHOD(Unfreeze)( DWORD dwFreeze) override;
207 STDMETHOD(SetAdvise)( DWORD aspects, DWORD advf, IAdviseSink *pAdvSink) override;
208 STDMETHOD(GetAdvise)( DWORD *pAspects, DWORD *pAdvf, IAdviseSink **ppAdvSink) override;
209 STDMETHOD(GetExtent)( DWORD dwDrawAspect, LONG lindex, DVTARGETDEVICE *ptd, LPSIZEL lpsizel) override;
211 /* IOleWindow methods */
212 STDMETHOD(GetWindow)( HWND *phwnd) override;
213 STDMETHOD(ContextSensitiveHelp)( BOOL fEnterMode) override;
215 /* IOleInPlaceObject methods */
216 STDMETHOD(InPlaceDeactivate)( void) override;
217 STDMETHOD(UIDeactivate)( void) override;
218 STDMETHOD(SetObjectRects)( LPCRECT lprcPosRect, LPCRECT lprcClipRect) override;
219 STDMETHOD(ReactivateAndUndo)( void) override;
221 /*IDispatch methods*/
222 STDMETHOD(GetTypeInfoCount)( UINT *pctinfo) override;
223 STDMETHOD(GetTypeInfo)( UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo) override;
224 STDMETHOD(GetIDsOfNames)( REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId) override;
225 STDMETHOD(Invoke)( DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr) override;
229 } // namespace inprocserv
231 #endif
233 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */