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