activex.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: msw/ole/activex.h
  3. // Purpose: interface of wxActiveXEvent
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. @class wxActiveXEvent
  9. An event class for handling ActiveX events passed from wxActiveXContainer.
  10. ActiveX events are basically a function call with the parameters passed
  11. through an array of wxVariants along with a return value that is a wxVariant
  12. itself. What type the parameters or return value are depends on the context
  13. (i.e. what the .idl specifies).
  14. @beginEventTable{wxActiveXEvent}
  15. @event{EVT_ACTIVEX(func)}
  16. Sent when the ActiveX control hosted by wxActiveXContainer receives an
  17. ActiveX event.
  18. @endEventTable
  19. ActiveX event parameters can get extremely complex and may be beyond the
  20. abilities of wxVariant. If 'operator[]' fails, prints an error messages or
  21. crashes the application, event handlers should use GetNativeParameters()
  22. instead to obtain the original event information.
  23. Calls to operator[] and GetNativeParmeters() can be mixed. It is valid
  24. to handle some parameters of an event with operator[] and others directly
  25. through GetNativeParameters(). It is \b not valid however to manipulate
  26. the same parameter using both approaches at the same time.
  27. @onlyfor{wxmsw}
  28. @library{wxcore}
  29. @category{events}
  30. */
  31. class wxActiveXEvent : public wxCommandEvent
  32. {
  33. public:
  34. /**
  35. Returns the dispatch id of this ActiveX event.
  36. This is the numeric value from the .idl file specified by the id().
  37. */
  38. DISPID GetDispatchId(int idx) const;
  39. /**
  40. Obtains the number of parameters passed through the ActiveX event.
  41. */
  42. size_t ParamCount() const;
  43. /**
  44. Obtains the param name of the param number idx specifies as a string.
  45. */
  46. wxString ParamName(size_t idx) const;
  47. /**
  48. Obtains the param type of the param number idx specifies as a string.
  49. */
  50. wxString ParamType(size_t idx) const;
  51. /**
  52. Obtains the actual parameter value specified by idx.
  53. */
  54. wxVariant operator[](size_t idx);
  55. /**
  56. Obtain the original MSW parameters for the event.
  57. Event handlers can use this information to handle complex event parameters
  58. that are beyond the scope of wxVariant.
  59. The information returned here is the information passed to the original
  60. 'Invoke' method call.
  61. \return a pointer to a struct containing the original MSW event parameters
  62. */
  63. wxActiveXEventNativeMSW *GetNativeParameters() const;
  64. };
  65. /**
  66. @class wxActiveXContainer
  67. wxActiveXContainer is a host for an ActiveX control on Windows (and as such
  68. is a platform-specific class).
  69. Note that the HWND that the class contains is the actual HWND of the ActiveX
  70. control so using dynamic events and connecting to @c wxEVT_SIZE, for example,
  71. will receive the actual size message sent to the control.
  72. It is somewhat similar to the ATL class CAxWindow in operation.
  73. The size of the ActiveX control's content is generally guaranteed to be that
  74. of the client size of the parent of this wxActiveXContainer.
  75. You can also process ActiveX events through wxActiveXEvent.
  76. @section activexcontainer_example Example
  77. This is an example of how to use the Adobe Acrobat Reader ActiveX control to
  78. read PDF files (requires Acrobat Reader 4 and up).
  79. Controls like this are typically found and dumped from OLEVIEW.exe that is
  80. distributed with Microsoft Visual C++.
  81. This example also demonstrates how to create a backend for wxMediaCtrl.
  82. @code
  83. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  84. //
  85. // wxPDFMediaBackend
  86. //
  87. // http://partners.adobe.com/public/developer/en/acrobat/sdk/pdf/iac/IACOverview.pdf
  88. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  89. #include "wx/mediactrl.h" // wxMediaBackendCommonBase
  90. #include "wx/msw/ole/activex.h" // wxActiveXContainer
  91. #include "wx/msw/ole/automtn.h" // wxAutomationObject
  92. const IID DIID__DPdf = {0xCA8A9781,0x280D,0x11CF,{0xA2,0x4D,0x44,0x45,0x53,0x54,0x00,0x00}};
  93. const IID DIID__DPdfEvents = {0xCA8A9782,0x280D,0x11CF,{0xA2,0x4D,0x44,0x45,0x53,0x54,0x00,0x00}};
  94. const CLSID CLSID_Pdf = {0xCA8A9780,0x280D,0x11CF,{0xA2,0x4D,0x44,0x45,0x53,0x54,0x00,0x00}};
  95. class WXDLLIMPEXP_MEDIA wxPDFMediaBackend : public wxMediaBackendCommonBase
  96. {
  97. public:
  98. wxPDFMediaBackend() : m_pAX(NULL) {}
  99. virtual ~wxPDFMediaBackend()
  100. {
  101. if(m_pAX)
  102. {
  103. m_pAX->DissociateHandle();
  104. delete m_pAX;
  105. }
  106. }
  107. virtual bool CreateControl(wxControl* ctrl, wxWindow* parent,
  108. wxWindowID id,
  109. const wxPoint& pos,
  110. const wxSize& size,
  111. long style,
  112. const wxValidator& validator,
  113. const wxString& name)
  114. {
  115. IDispatch* pDispatch;
  116. if( ::CoCreateInstance(CLSID_Pdf, NULL,
  117. CLSCTX_INPROC_SERVER,
  118. DIID__DPdf, (void**)&pDispatch) != 0 )
  119. return false;
  120. m_PDF.SetDispatchPtr(pDispatch); // wxAutomationObject will release itself
  121. if ( !ctrl->wxControl::Create(parent, id, pos, size,
  122. (style & ~wxBORDER_MASK) | wxBORDER_NONE,
  123. validator, name) )
  124. return false;
  125. m_ctrl = wxStaticCast(ctrl, wxMediaCtrl);
  126. m_pAX = new wxActiveXContainer(ctrl,
  127. DIID__DPdf,
  128. pDispatch);
  129. wxPDFMediaBackend::ShowPlayerControls(wxMEDIACTRLPLAYERCONTROLS_NONE);
  130. return true;
  131. }
  132. virtual bool Play()
  133. {
  134. return true;
  135. }
  136. virtual bool Pause()
  137. {
  138. return true;
  139. }
  140. virtual bool Stop()
  141. {
  142. return true;
  143. }
  144. virtual bool Load(const wxString& fileName)
  145. {
  146. if(m_PDF.CallMethod("LoadFile", fileName).GetBool())
  147. {
  148. m_PDF.CallMethod("setCurrentPage", wxVariant((long)0));
  149. NotifyMovieLoaded(); // initial refresh
  150. wxSizeEvent event;
  151. m_pAX->OnSize(event);
  152. return true;
  153. }
  154. return false;
  155. }
  156. virtual bool Load(const wxURI& location)
  157. {
  158. return m_PDF.CallMethod("LoadFile", location.BuildUnescapedURI()).GetBool();
  159. }
  160. virtual bool Load(const wxURI& WXUNUSED(location),
  161. const wxURI& WXUNUSED(proxy))
  162. {
  163. return false;
  164. }
  165. virtual wxMediaState GetState()
  166. {
  167. return wxMEDIASTATE_STOPPED;
  168. }
  169. virtual bool SetPosition(wxLongLong where)
  170. {
  171. m_PDF.CallMethod("setCurrentPage", wxVariant((long)where.GetValue()));
  172. return true;
  173. }
  174. virtual wxLongLong GetPosition()
  175. {
  176. return 0;
  177. }
  178. virtual wxLongLong GetDuration()
  179. {
  180. return 0;
  181. }
  182. virtual void Move(int WXUNUSED(x), int WXUNUSED(y),
  183. int WXUNUSED(w), int WXUNUSED(h))
  184. {
  185. }
  186. wxSize GetVideoSize() const
  187. {
  188. return wxDefaultSize;
  189. }
  190. virtual double GetPlaybackRate()
  191. {
  192. return 0;
  193. }
  194. virtual bool SetPlaybackRate(double)
  195. {
  196. return false;
  197. }
  198. virtual double GetVolume()
  199. {
  200. return 0;
  201. }
  202. virtual bool SetVolume(double)
  203. {
  204. return false;
  205. }
  206. virtual bool ShowPlayerControls(wxMediaCtrlPlayerControls flags)
  207. {
  208. if(flags)
  209. {
  210. m_PDF.CallMethod("setShowToolbar", true);
  211. m_PDF.CallMethod("setShowScrollbars", true);
  212. }
  213. else
  214. {
  215. m_PDF.CallMethod("setShowToolbar", false);
  216. m_PDF.CallMethod("setShowScrollbars", false);
  217. }
  218. return true;
  219. }
  220. wxActiveXContainer* m_pAX;
  221. wxAutomationObject m_PDF;
  222. wxDECLARE_DYNAMIC_CLASS(wxPDFMediaBackend)
  223. };
  224. wxIMPLEMENT_DYNAMIC_CLASS(wxPDFMediaBackend, wxMediaBackend);
  225. // Put this in one of your existing source files and then create a wxMediaCtrl with
  226. wxMediaCtrl* mymediactrl = new wxMediaCtrl(this, "myfile.pdf", wxID_ANY,
  227. wxDefaultPosition, wxSize(300,300),
  228. 0, "wxPDFMediaBackend");
  229. // [this] is the parent window, "myfile.pdf" is the PDF file to open
  230. @endcode
  231. @onlyfor{wxmsw}
  232. @library{wxcore}
  233. @category{ctrl,ipc}
  234. @see wxActiveXEvent, @ref page_samples_flash
  235. */
  236. class wxActiveXContainer : public wxControl
  237. {
  238. public:
  239. /**
  240. Creates this ActiveX container.
  241. @param parent
  242. parent of this control. Must not be @NULL.
  243. @param iid
  244. COM IID of pUnk to query. Must be a valid interface to an ActiveX control.
  245. @param pUnk
  246. Interface of ActiveX control.
  247. */
  248. wxActiveXContainer(wxWindow* parent, REFIID iid, IUnknown* pUnk);
  249. /**
  250. Queries host's site for interface.
  251. @param iid
  252. The iid of the required interface.
  253. @param _interface
  254. Double pointer to outgoing interface. Supply your own interface if desired.
  255. @param desc
  256. The description of the outgoing interface.
  257. @return bool
  258. Return true if interface supplied else return false.
  259. */
  260. virtual bool QueryClientSiteInterface(REFIID iid, void **_interface, const char *&desc);
  261. };