]> git.saurik.com Git - wxWidgets.git/blob - interface/wx/msw/ole/activex.h
remove usage of wxT() macro; it makes example code a bit harder to read
[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 license
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 recieves an
22 ActiveX event.
23 @endEventTable
24
25 @onlyfor{wxmsw}
26
27 @library{wxcore}
28 @category{events}
29 */
30 class wxActiveXEvent : public wxCommandEvent
31 {
32 public:
33 /**
34 Returns the dispatch id of this ActiveX event.
35 This is the numeric value from the .idl file specified by the id().
36 */
37 DISPID GetDispatchId(int idx) const;
38
39 /**
40 Obtains the number of parameters passed through the ActiveX event.
41 */
42 size_t ParamCount() const;
43
44 /**
45 Obtains the param name of the param number idx specifies as a string.
46 */
47 wxString ParamName(size_t idx) const;
48
49 /**
50 Obtains the param type of the param number idx specifies as a string.
51 */
52 wxString ParamType(size_t idx) const;
53
54 /**
55 Obtains the actual parameter value specified by idx.
56 */
57 wxVariant operator[](size_t idx);
58 };
59
60
61
62 /**
63 @class wxActiveXContainer
64
65 wxActiveXContainer is a host for an ActiveX control on Windows (and as such
66 is a platform-specific class).
67
68 Note that the HWND that the class contains is the actual HWND of the ActiveX
69 control so using dynamic events and connecting to wxEVT_SIZE, for example,
70 will receive the actual size message sent to the control.
71
72 It is somewhat similar to the ATL class CAxWindow in operation.
73
74 The size of the ActiveX control's content is generally guaranteed to be that
75 of the client size of the parent of this wxActiveXContainer.
76
77 You can also process ActiveX events through wxActiveXEvent.
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 {
161 if(m_PDF.CallMethod("LoadFile", fileName).GetBool())
162 {
163 m_PDF.CallMethod("setCurrentPage", wxVariant((long)0));
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 {
174 return m_PDF.CallMethod("LoadFile", location.BuildUnescapedURI()).GetBool();
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 {
189 m_PDF.CallMethod("setCurrentPage", wxVariant((long)where.GetValue()));
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 {
232 m_PDF.CallMethod("setShowToolbar", true);
233 m_PDF.CallMethod("setShowScrollbars", true);
234 }
235 else
236 {
237 m_PDF.CallMethod("setShowToolbar", false);
238 m_PDF.CallMethod("setShowScrollbars", false);
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
254 wxMediaCtrl* mymediactrl = new wxMediaCtrl(this, "myfile.pdf", wxID_ANY,
255 wxDefaultPosition, wxSize(300,300),
256 0, "wxPDFMediaBackend");
257 @endcode
258
259
260 @onlyfor{wxmsw}
261
262 @library{wxbase}
263 @category{misc,ipc}
264
265 @see wxActiveXEvent, @ref page_samples_flash
266 */
267 class wxActiveXContainer : public wxControl
268 {
269 public:
270 /**
271 Creates this ActiveX container.
272
273 @param parent
274 parent of this control. Must not be @NULL.
275 @param iid
276 COM IID of pUnk to query. Must be a valid interface to an ActiveX control.
277 @param pUnk
278 Interface of ActiveX control.
279 */
280 wxActiveXContainer(wxWindow* parent, REFIID iid, IUnknown* pUnk);
281 };
282