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