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