activex.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/msw/ole/activex.h
  3. // Purpose: wxActiveXContainer class
  4. // Author: Ryan Norton <wxprojects@comcast.net>
  5. // Modified by:
  6. // Created: 8/18/05
  7. // Copyright: (c) Ryan Norton
  8. // Licence: wxWindows licence
  9. ///////////////////////////////////////////////////////////////////////////////
  10. // ============================================================================
  11. // Definitions
  12. // ============================================================================
  13. #ifndef _WX_MSW_OLE_ACTIVEXCONTAINER_H_
  14. #define _WX_MSW_OLE_ACTIVEXCONTAINER_H_
  15. #if wxUSE_ACTIVEX
  16. //---------------------------------------------------------------------------
  17. // wx includes
  18. //---------------------------------------------------------------------------
  19. #include "wx/msw/ole/oleutils.h" // wxBasicString &c
  20. #include "wx/msw/ole/uuid.h"
  21. #include "wx/window.h"
  22. #include "wx/variant.h"
  23. class FrameSite;
  24. //---------------------------------------------------------------------------
  25. // MSW COM includes
  26. //---------------------------------------------------------------------------
  27. #include <oleidl.h>
  28. #include <olectl.h>
  29. #if !defined(__WXWINCE__) || defined(__WINCE_STANDARDSDK__)
  30. #include <exdisp.h>
  31. #endif
  32. #include <docobj.h>
  33. #ifndef STDMETHOD
  34. #define STDMETHOD(funcname) virtual HRESULT wxSTDCALL funcname
  35. #endif
  36. //
  37. // These defines are from another ole header - but its not in the
  38. // latest sdk. Also the ifndef DISPID_READYSTATE is here because at
  39. // least on my machine with the latest sdk olectl.h defines these 3
  40. //
  41. #ifndef DISPID_READYSTATE
  42. #define DISPID_READYSTATE (-525)
  43. #define DISPID_READYSTATECHANGE (-609)
  44. #define DISPID_AMBIENT_TRANSFERPRIORITY (-728)
  45. #endif
  46. #define DISPID_AMBIENT_OFFLINEIFNOTCONNECTED (-5501)
  47. #define DISPID_AMBIENT_SILENT (-5502)
  48. #ifndef DISPID_AMBIENT_CODEPAGE
  49. #define DISPID_AMBIENT_CODEPAGE (-725)
  50. #define DISPID_AMBIENT_CHARSET (-727)
  51. #endif
  52. //---------------------------------------------------------------------------
  53. //
  54. // wxActiveXContainer
  55. //
  56. //---------------------------------------------------------------------------
  57. template<typename I>
  58. class wxAutoOleInterface
  59. {
  60. public:
  61. typedef I Interface;
  62. explicit wxAutoOleInterface(I *pInterface = NULL) : m_interface(pInterface)
  63. {}
  64. wxAutoOleInterface(REFIID riid, IUnknown *pUnk) : m_interface(NULL)
  65. { QueryInterface(riid, pUnk); }
  66. wxAutoOleInterface(REFIID riid, IDispatch *pDispatch) : m_interface(NULL)
  67. { QueryInterface(riid, pDispatch); }
  68. wxAutoOleInterface(REFCLSID clsid, REFIID riid) : m_interface(NULL)
  69. { CreateInstance(clsid, riid); }
  70. wxAutoOleInterface(const wxAutoOleInterface& ti) : m_interface(NULL)
  71. { operator=(ti); }
  72. wxAutoOleInterface& operator=(const wxAutoOleInterface& ti)
  73. {
  74. if ( ti.m_interface )
  75. ti.m_interface->AddRef();
  76. Free();
  77. m_interface = ti.m_interface;
  78. return *this;
  79. }
  80. wxAutoOleInterface& operator=(I*& ti)
  81. {
  82. Free();
  83. m_interface = ti;
  84. return *this;
  85. }
  86. ~wxAutoOleInterface() { Free(); }
  87. void Free()
  88. {
  89. if ( m_interface )
  90. m_interface->Release();
  91. m_interface = NULL;
  92. }
  93. HRESULT QueryInterface(REFIID riid, IUnknown *pUnk)
  94. {
  95. Free();
  96. wxASSERT(pUnk != NULL);
  97. return pUnk->QueryInterface(riid, (void **)&m_interface);
  98. }
  99. HRESULT CreateInstance(REFCLSID clsid, REFIID riid)
  100. {
  101. Free();
  102. return CoCreateInstance
  103. (
  104. clsid,
  105. NULL,
  106. CLSCTX_ALL,
  107. riid,
  108. (void **)&m_interface
  109. );
  110. }
  111. operator I*() const {return m_interface; }
  112. I* operator->() {return m_interface; }
  113. I** GetRef() {return &m_interface; }
  114. bool Ok() const { return IsOk(); }
  115. bool IsOk() const { return m_interface != NULL; }
  116. protected:
  117. I *m_interface;
  118. };
  119. #if WXWIN_COMPATIBILITY_2_8
  120. // this macro is kept for compatibility with older wx versions
  121. #define WX_DECLARE_AUTOOLE(wxAutoOleInterfaceType, I) \
  122. typedef wxAutoOleInterface<I> wxAutoOleInterfaceType;
  123. #endif // WXWIN_COMPATIBILITY_2_8
  124. typedef wxAutoOleInterface<IDispatch> wxAutoIDispatch;
  125. typedef wxAutoOleInterface<IOleClientSite> wxAutoIOleClientSite;
  126. typedef wxAutoOleInterface<IUnknown> wxAutoIUnknown;
  127. typedef wxAutoOleInterface<IOleObject> wxAutoIOleObject;
  128. typedef wxAutoOleInterface<IOleInPlaceObject> wxAutoIOleInPlaceObject;
  129. typedef wxAutoOleInterface<IOleInPlaceActiveObject> wxAutoIOleInPlaceActiveObject;
  130. typedef wxAutoOleInterface<IOleDocumentView> wxAutoIOleDocumentView;
  131. typedef wxAutoOleInterface<IViewObject> wxAutoIViewObject;
  132. class WXDLLIMPEXP_CORE wxActiveXContainer : public wxWindow
  133. {
  134. public:
  135. wxActiveXContainer(wxWindow * parent, REFIID iid, IUnknown* pUnk);
  136. virtual ~wxActiveXContainer();
  137. void OnSize(wxSizeEvent&);
  138. void OnPaint(wxPaintEvent&);
  139. void OnSetFocus(wxFocusEvent&);
  140. void OnKillFocus(wxFocusEvent&);
  141. virtual bool MSWTranslateMessage(WXMSG* pMsg);
  142. virtual bool QueryClientSiteInterface(REFIID iid, void **_interface, const char *&desc);
  143. protected:
  144. friend class FrameSite;
  145. friend class wxActiveXEvents;
  146. FrameSite *m_frameSite;
  147. wxAutoIDispatch m_Dispatch;
  148. wxAutoIOleClientSite m_clientSite;
  149. wxAutoIUnknown m_ActiveX;
  150. wxAutoIOleObject m_oleObject;
  151. wxAutoIOleInPlaceObject m_oleInPlaceObject;
  152. wxAutoIOleInPlaceActiveObject m_oleInPlaceActiveObject;
  153. wxAutoIOleDocumentView m_docView;
  154. wxAutoIViewObject m_viewObject;
  155. HWND m_oleObjectHWND;
  156. bool m_bAmbientUserMode;
  157. DWORD m_docAdviseCookie;
  158. wxWindow* m_realparent;
  159. void CreateActiveX(REFIID, IUnknown*);
  160. };
  161. ///\brief Store native event parameters.
  162. ///\detail Store OLE 'Invoke' parameters for event handlers that need to access them.
  163. /// These are the exact values for the event as they are passed to the wxActiveXContainer.
  164. struct wxActiveXEventNativeMSW
  165. {
  166. DISPID dispIdMember;
  167. REFIID riid;
  168. LCID lcid;
  169. WORD wFlags;
  170. DISPPARAMS *pDispParams;
  171. VARIANT *pVarResult;
  172. EXCEPINFO *pExcepInfo;
  173. unsigned int *puArgErr;
  174. wxActiveXEventNativeMSW
  175. (DISPID a_dispIdMember, REFIID a_riid, LCID a_lcid, WORD a_wFlags, DISPPARAMS *a_pDispParams,
  176. VARIANT *a_pVarResult, EXCEPINFO *a_pExcepInfo, unsigned int *a_puArgErr)
  177. :dispIdMember(a_dispIdMember), riid(a_riid), lcid(a_lcid), wFlags(a_wFlags), pDispParams(a_pDispParams),
  178. pVarResult(a_pVarResult), pExcepInfo(a_pExcepInfo), puArgErr(a_puArgErr)
  179. { }
  180. };
  181. // Events
  182. class WXDLLIMPEXP_CORE wxActiveXEvent : public wxCommandEvent
  183. {
  184. private:
  185. friend class wxActiveXEvents;
  186. wxVariant m_params;
  187. DISPID m_dispid;
  188. public:
  189. virtual wxEvent *Clone() const
  190. { return new wxActiveXEvent(*this); }
  191. size_t ParamCount() const;
  192. wxString ParamType(size_t idx) const
  193. {
  194. wxASSERT(idx < ParamCount());
  195. return m_params[idx].GetType();
  196. }
  197. wxString ParamName(size_t idx) const
  198. {
  199. wxASSERT(idx < ParamCount());
  200. return m_params[idx].GetName();
  201. }
  202. wxVariant& operator[] (size_t idx);
  203. DISPID GetDispatchId() const
  204. { return m_dispid; }
  205. wxActiveXEventNativeMSW *GetNativeParameters() const
  206. { return (wxActiveXEventNativeMSW*)GetClientData(); }
  207. };
  208. // #define wxACTIVEX_ID 14001
  209. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_ACTIVEX, wxActiveXEvent );
  210. typedef void (wxEvtHandler::*wxActiveXEventFunction)(wxActiveXEvent&);
  211. #define wxActiveXEventHandler(func) \
  212. wxEVENT_HANDLER_CAST( wxActiveXEventFunction, func )
  213. #define EVT_ACTIVEX(id, fn) wxDECLARE_EVENT_TABLE_ENTRY(wxEVT_ACTIVEX, id, -1, wxActiveXEventHandler( fn ), NULL ),
  214. #endif // wxUSE_ACTIVEX
  215. #endif // _WX_MSW_OLE_ACTIVEXCONTAINER_H_