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