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 // SOActiveX.h : Declaration of the CSOActiveX
21 
22 #pragma once
23 
24 #include "resource.h"
25 
26 #include <ExDispID.h>
27 #include <ExDisp.h>
28 #include <shlguid.h>
29 
30 #include <atlctl.h>
31 
32 #if defined __clang__
33 #pragma clang diagnostic push
34 #pragma clang diagnostic ignored "-Wnon-virtual-dtor"
35 #endif
36 #include <so_activex.h>
37 #if defined __clang__
38 #pragma clang diagnostic pop
39 #endif
40 
41 class SODispatchInterceptor;
42 
43 enum SOVersion {
44     SO_NOT_DETECTED = 0,
45     SO_52,
46     SO_60,
47     SO_61,
48     SO_UNKNOWN,
49     OO_10,
50     OO_11,
51     OO_UNKNOWN
52 };
53 
54 
55 // CSOActiveX
56 class ATL_NO_VTABLE CSOActiveX :
57     public CComObjectRootEx<CComSingleThreadModel>,
58     public IDispatchImpl<ISOActiveX, &IID_ISOActiveX, &LIBID_SO_ACTIVEXLib>,
59     public CComControl<CSOActiveX>,
60     public IPersistStreamInitImpl<CSOActiveX>,
61     public IOleControlImpl<CSOActiveX>,
62     public IOleObjectImpl<CSOActiveX>,
63     public IOleInPlaceActiveObjectImpl<CSOActiveX>,
64     public IViewObjectExImpl<CSOActiveX>,
65     public IOleInPlaceObjectWindowlessImpl<CSOActiveX>,
66 //  public IConnectionPointContainerImpl<CSOActiveX>,
67     public CComCoClass<CSOActiveX, &CLSID_SOActiveX>,
68 //  public CProxy_ItryPluginEvents< CSOActiveX >,
69     public IPersistPropertyBagImpl< CSOActiveX >,
70     public IProvideClassInfo2Impl<  &CLSID_SOActiveX,
71                                     &DIID__ISOActiveXEvents,
72                                     &LIBID_SO_ACTIVEXLib >,
73     public IObjectSafetyImpl< CSOActiveX,
74                               INTERFACESAFE_FOR_UNTRUSTED_DATA >
75 {
76 protected:
77     CComPtr<IWebBrowser2>   mWebBrowser2;
78     DWORD                   mCookie;
79 
80     CComPtr<IDispatch>      mpDispFactory;
81     CComPtr<IDispatch>      mpDispFrame;
82     CComPtr<IDispatch>      mpInstanceLocker;
83     CComPtr<IDispatch>      mpDispWin;
84     OLECHAR const *         mCurFileUrl;
85     BOOL                    mbLoad;
86     BOOL                    mbViewOnly;
87     WNDCLASSW               mPWinClass;
88     HWND                    mParentWin;
89     HWND                    mOffWin;
90 
91     SODispatchInterceptor*  mpDispatchInterceptor;
92     SOVersion               mnVersion;
93 
94     BOOL                    mbReadyForActivation;
95     CComPtr<IDispatch>      mpDispTempFile;
96 
97     bool                    mbDrawLocked;
98 
99 public:
100     CSOActiveX();
101     ~CSOActiveX() override;
102 
103 DECLARE_REGISTRY_RESOURCEID(IDR_SOACTIVEX)
104 
105 DECLARE_PROTECT_FINAL_CONSTRUCT()
106 
107 BEGIN_COM_MAP(CSOActiveX)
108     COM_INTERFACE_ENTRY(ISOActiveX)
109     COM_INTERFACE_ENTRY(IDispatch)
110     COM_INTERFACE_ENTRY(IViewObjectEx)
111     COM_INTERFACE_ENTRY(IViewObject2)
112     COM_INTERFACE_ENTRY(IViewObject)
113     COM_INTERFACE_ENTRY(IOleInPlaceObjectWindowless)
114     COM_INTERFACE_ENTRY(IOleInPlaceObject)
115     COM_INTERFACE_ENTRY2(IOleWindow, IOleInPlaceObjectWindowless)
116     COM_INTERFACE_ENTRY(IOleInPlaceActiveObject)
117     COM_INTERFACE_ENTRY(IOleControl)
118     COM_INTERFACE_ENTRY(IOleObject)
119     COM_INTERFACE_ENTRY(IPersistStreamInit)
120     COM_INTERFACE_ENTRY2(IPersist, IPersistStreamInit)
121 //  COM_INTERFACE_ENTRY(IConnectionPointContainer)
122     COM_INTERFACE_ENTRY(IProvideClassInfo)
123     COM_INTERFACE_ENTRY(IProvideClassInfo2)
124     COM_INTERFACE_ENTRY(IPersistPropertyBag)
125     COM_INTERFACE_ENTRY(IObjectSafety)
126 #if defined __clang__
127 #pragma clang diagnostic push
128 #pragma clang diagnostic ignored "-Winconsistent-missing-override"
129 #endif
130 END_COM_MAP()
131 #if defined __clang__
132 #pragma clang diagnostic pop
133 #endif
134 
135 #if defined __clang__
136 #pragma clang diagnostic push
137 #pragma clang diagnostic ignored "-Winvalid-offsetof"
138     // offset of on non-standard-layout type '_PropMapClass' (aka 'CSOActiveX'),
139     // expanded from macro 'PROP_DATA_ENTRY'
140 #endif
141 BEGIN_PROP_MAP(CSOActiveX)
142     PROP_DATA_ENTRY("_cx", m_sizeExtent.cx, VT_UI4)
143     PROP_DATA_ENTRY("_cy", m_sizeExtent.cy, VT_UI4)
144     // Example entries
145     // PROP_ENTRY("Property Description", dispid, clsid)
146     // PROP_PAGE(CLSID_StockColorPage)
147 END_PROP_MAP()
148 #if defined __clang__
149 #pragma clang diagnostic pop
150 #endif
151 
152 BEGIN_CONNECTION_POINT_MAP(CSOActiveX)
153 END_CONNECTION_POINT_MAP()
154 
155 #if defined __clang__
156 #pragma clang diagnostic push
157 #pragma clang diagnostic ignored "-Winconsistent-missing-override"
158 #endif
159 BEGIN_MSG_MAP(CSOActiveX)
160 #if defined __clang__
161 #pragma clang diagnostic pop
162 #endif
163     CHAIN_MSG_MAP(CComControl<CSOActiveX>)
164     DEFAULT_REFLECTION_HANDLER()
165 END_MSG_MAP()
166 // Handler prototypes:
167 //  LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
168 //  LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
169 //  LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);
170 
171 
172 
173 // IViewObjectEx
174     static DECLARE_VIEW_STATUS(VIEWSTATUS_SOLIDBKGND | VIEWSTATUS_OPAQUE)
175 
176 // ISOActiveX
177 public:
178 
179     STDMETHOD(SetClientSite)( IOleClientSite* aClientSite ) override;
180     STDMETHOD(Invoke)(  DISPID dispidMember,
181                         REFIID riid,
182                         LCID lcid,
183                         WORD wFlags,
184                         DISPPARAMS* pDispParams,
185                         VARIANT* pvarResult,
186                         EXCEPINFO* pExcepInfo,
187                         UINT* puArgErr) override;
188     STDMETHOD(Load) ( LPPROPERTYBAG pPropBag, LPERRORLOG pErrorLog ) override;
189     STDMETHOD(Load) ( LPSTREAM pStm ) override;
190     STDMETHOD(InitNew) () override;
191     HRESULT OnDrawAdvanced(ATL_DRAWINFO& di) override;
192     HRESULT OnDraw(ATL_DRAWINFO& di) override;
193 
194     HRESULT SetLayoutManagerProps();
195     HRESULT CreateFrameOldWay( HWND hwnd, int width, int height );
196     HRESULT GetUnoStruct( OLECHAR const * sStructName, CComPtr<IDispatch>& pdispResult );
197     HRESULT LoadURLToFrame();
198     HRESULT CallDispatchMethod( OLECHAR const * sUrl, CComVariant* sArgNames, CComVariant* sArgVal, unsigned int count );
199     HRESULT CallLoadComponentFromURL1PBool( OLECHAR const * sUrl, OLECHAR const * sArgName, BOOL sArgVal );
200     HRESULT GetUrlStruct( OLECHAR const * sUrl, CComPtr<IDispatch>& pdispUrl );
201     HRESULT Cleanup();
202     HRESULT TerminateOffice();
203     HRESULT GetURL( const OLECHAR* url,
204                                 const OLECHAR* target );
205 
206     void CallbackCreateXInputStream( CBindStatusCallback<CSOActiveX>* pbsc, BYTE* pBytes, DWORD dwSize );
207 
208 
209     SOVersion GetVersionConnected();
210 };
211 
212 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
213