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