Ryan's cumulative wxActiveX and media control patch (1427775)
[wxWidgets.git] / include / wx / mediactrl.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/mediactrl.h
3 // Purpose: wxMediaCtrl class
4 // Author: Ryan Norton <wxprojects@comcast.net>
5 // Modified by:
6 // Created: 11/07/04
7 // RCS-ID: $Id$
8 // Copyright: (c) Ryan Norton
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // Definitions
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // Header guard
18 // ----------------------------------------------------------------------------
19 #ifndef _WX_MEDIACTRL_H_
20 #define _WX_MEDIACTRL_H_
21
22 // ----------------------------------------------------------------------------
23 // Pre-compiled header stuff
24 // ----------------------------------------------------------------------------
25 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
26 #pragma interface "mediactrl.h"
27 #endif
28
29 #include "wx/defs.h"
30
31 // ----------------------------------------------------------------------------
32 // Compilation guard
33 // ----------------------------------------------------------------------------
34
35 #if wxUSE_MEDIACTRL
36
37 // ----------------------------------------------------------------------------
38 // Includes
39 // ----------------------------------------------------------------------------
40
41 #include "wx/control.h"
42 #include "wx/uri.h"
43
44 // ============================================================================
45 // Declarations
46 // ============================================================================
47
48 // ----------------------------------------------------------------------------
49 //
50 // Enumerations
51 //
52 // ----------------------------------------------------------------------------
53
54 enum wxMediaState
55 {
56 wxMEDIASTATE_STOPPED,
57 wxMEDIASTATE_PAUSED,
58 wxMEDIASTATE_PLAYING
59 };
60
61 enum wxMediaCtrlPlayerControls
62 {
63 wxMEDIACTRLPLAYERCONTROLS_NONE = 0,
64 //Step controls like fastfoward, step one frame etc.
65 wxMEDIACTRLPLAYERCONTROLS_STEP = 1 << 0,
66 //Volume controls like the speaker icon, volume slider, etc.
67 wxMEDIACTRLPLAYERCONTROLS_VOLUME = 1 << 1,
68 wxMEDIACTRLPLAYERCONTROLS_DEFAULT =
69 wxMEDIACTRLPLAYERCONTROLS_STEP |
70 wxMEDIACTRLPLAYERCONTROLS_VOLUME
71 };
72
73 #define wxMEDIABACKEND_DIRECTSHOW wxT("wxAMMediaBackend")
74 #define wxMEDIABACKEND_MCI wxT("wxMCIMediaBackend")
75 #define wxMEDIABACKEND_QUICKTIME wxT("wxQTMediaBackend")
76 #define wxMEDIABACKEND_GSTREAMER wxT("wxGStreamerMediaBackend")
77 #define wxMEDIABACKEND_REALPLAYER wxT("wxRealPlayerMediaBackend")
78 #define wxMEDIABACKEND_WMP10 wxT("wxWMP10MediaBackend")
79
80 // ----------------------------------------------------------------------------
81 //
82 // wxMediaEvent
83 //
84 // ----------------------------------------------------------------------------
85
86 class WXDLLIMPEXP_MEDIA wxMediaEvent : public wxNotifyEvent
87 {
88 public:
89 // ------------------------------------------------------------------------
90 // wxMediaEvent Constructor
91 //
92 // Normal constructor, much the same as wxNotifyEvent
93 // ------------------------------------------------------------------------
94 wxMediaEvent(wxEventType commandType = wxEVT_NULL, int winid = 0)
95 : wxNotifyEvent(commandType, winid)
96 { }
97
98 // ------------------------------------------------------------------------
99 // wxMediaEvent Copy Constructor
100 //
101 // Normal copy constructor, much the same as wxNotifyEvent
102 // ------------------------------------------------------------------------
103 wxMediaEvent(const wxMediaEvent &clone)
104 : wxNotifyEvent(clone)
105 { }
106
107 // ------------------------------------------------------------------------
108 // wxMediaEvent::Clone
109 //
110 // Allocates a copy of this object.
111 // Required for wxEvtHandler::AddPendingEvent
112 // ------------------------------------------------------------------------
113 virtual wxEvent *Clone() const
114 { return new wxMediaEvent(*this); }
115
116
117 // Put this class on wxWidget's RTTI table
118 DECLARE_DYNAMIC_CLASS(wxMediaEvent)
119 };
120
121 // ----------------------------------------------------------------------------
122 //
123 // wxMediaCtrl
124 //
125 // ----------------------------------------------------------------------------
126
127 class WXDLLIMPEXP_MEDIA wxMediaCtrl : public wxControl
128 {
129 public:
130 wxMediaCtrl() : m_imp(NULL), m_bLoaded(false)
131 { }
132
133 wxMediaCtrl(wxWindow* parent, wxWindowID winid,
134 const wxString& fileName = wxEmptyString,
135 const wxPoint& pos = wxDefaultPosition,
136 const wxSize& size = wxDefaultSize,
137 long style = 0,
138 const wxString& szBackend = wxEmptyString,
139 const wxValidator& validator = wxDefaultValidator,
140 const wxString& name = wxT("mediaCtrl"))
141 : m_imp(NULL), m_bLoaded(false)
142 { Create(parent, winid, fileName, pos, size, style,
143 szBackend, validator, name); }
144
145 wxMediaCtrl(wxWindow* parent, wxWindowID winid,
146 const wxURI& location,
147 const wxPoint& pos = wxDefaultPosition,
148 const wxSize& size = wxDefaultSize,
149 long style = 0,
150 const wxString& szBackend = wxEmptyString,
151 const wxValidator& validator = wxDefaultValidator,
152 const wxString& name = wxT("mediaCtrl"))
153 : m_imp(NULL), m_bLoaded(false)
154 { Create(parent, winid, location, pos, size, style,
155 szBackend, validator, name); }
156
157 ~wxMediaCtrl();
158
159 bool Create(wxWindow* parent, wxWindowID winid,
160 const wxString& fileName = wxEmptyString,
161 const wxPoint& pos = wxDefaultPosition,
162 const wxSize& size = wxDefaultSize,
163 long style = 0,
164 const wxString& szBackend = wxEmptyString,
165 const wxValidator& validator = wxDefaultValidator,
166 const wxString& name = wxT("mediaCtrl"));
167
168 bool Create(wxWindow* parent, wxWindowID winid,
169 const wxURI& location,
170 const wxPoint& pos = wxDefaultPosition,
171 const wxSize& size = wxDefaultSize,
172 long style = 0,
173 const wxString& szBackend = wxEmptyString,
174 const wxValidator& validator = wxDefaultValidator,
175 const wxString& name = wxT("mediaCtrl"));
176
177 bool DoCreate(wxClassInfo* instance,
178 wxWindow* parent, wxWindowID winid,
179 const wxPoint& pos = wxDefaultPosition,
180 const wxSize& size = wxDefaultSize,
181 long style = 0,
182 const wxValidator& validator = wxDefaultValidator,
183 const wxString& name = wxT("mediaCtrl"));
184
185 bool Play();
186 bool Pause();
187 bool Stop();
188
189 bool Load(const wxString& fileName);
190
191 wxMediaState GetState();
192
193 wxFileOffset Seek(wxFileOffset where, wxSeekMode mode = wxFromStart);
194 wxFileOffset Tell(); //FIXME: This should be const
195 wxFileOffset Length(); //FIXME: This should be const
196
197 #if wxABI_VERSION >= 20601 /* 2.6.1+ only */
198 double GetPlaybackRate(); //All but MCI & GStreamer
199 bool SetPlaybackRate(double dRate); //All but MCI & GStreamer
200 #endif
201
202 #if wxABI_VERSION >= 20602 /* 2.6.2+ only */
203 bool Load(const wxURI& location);
204 bool Load(const wxURI& location, const wxURI& proxy);
205
206 wxFileOffset GetDownloadProgress(); // DirectShow only
207 wxFileOffset GetDownloadTotal(); // DirectShow only
208
209 double GetVolume();
210 bool SetVolume(double dVolume);
211
212 bool ShowPlayerControls(
213 wxMediaCtrlPlayerControls flags = wxMEDIACTRLPLAYERCONTROLS_DEFAULT);
214
215 //helpers for the wxPython people
216 bool LoadURI(const wxString& fileName)
217 { return Load(wxURI(fileName)); }
218 bool LoadURIWithProxy(const wxString& fileName, const wxString& proxy)
219 { return Load(wxURI(fileName), wxURI(proxy)); }
220 #endif
221 protected:
222 static wxClassInfo* NextBackend();
223
224 void OnMediaFinished(wxMediaEvent& evt);
225 virtual void DoMoveWindow(int x, int y, int w, int h);
226 wxSize DoGetBestSize() const;
227
228 //FIXME: This is nasty... find a better way to work around
229 //inheritance issues
230 #if defined(__WXMAC__) || defined(__WXCOCOA__)
231 friend class wxQTMediaBackend;
232 #endif
233 class wxMediaBackend* m_imp;
234 bool m_bLoaded;
235
236 DECLARE_DYNAMIC_CLASS(wxMediaCtrl)
237 };
238
239 // ----------------------------------------------------------------------------
240 //
241 // wxMediaBackend
242 //
243 // Derive from this and use standard wxWidgets RTTI
244 // (DECLARE_DYNAMIC_CLASS and IMPLEMENT_CLASS) to make a backend
245 // for wxMediaCtrl. Backends are searched alphabetically -
246 // the one with the earliest letter is tried first.
247 //
248 // Note that this is currently not API or ABI compatable -
249 // so statically link or make the client compile on-site.
250 //
251 // ----------------------------------------------------------------------------
252
253 class WXDLLIMPEXP_MEDIA wxMediaBackend : public wxObject
254 {
255 public:
256 wxMediaBackend()
257 { }
258
259 virtual ~wxMediaBackend();
260
261 virtual bool CreateControl(wxControl* WXUNUSED(ctrl),
262 wxWindow* WXUNUSED(parent),
263 wxWindowID WXUNUSED(winid),
264 const wxPoint& WXUNUSED(pos),
265 const wxSize& WXUNUSED(size),
266 long WXUNUSED(style),
267 const wxValidator& WXUNUSED(validator),
268 const wxString& WXUNUSED(name))
269 { return false; }
270
271 virtual bool Play()
272 { return false; }
273 virtual bool Pause()
274 { return false; }
275 virtual bool Stop()
276 { return false; }
277
278 virtual bool Load(const wxString& WXUNUSED(fileName))
279 { return false; }
280 virtual bool Load(const wxURI& WXUNUSED(location))
281 { return false; }
282
283 virtual bool SetPosition(wxLongLong WXUNUSED(where))
284 { return 0; }
285 virtual wxLongLong GetPosition()
286 { return 0; }
287 virtual wxLongLong GetDuration()
288 { return 0; }
289
290 virtual void Move(int WXUNUSED(x), int WXUNUSED(y),
291 int WXUNUSED(w), int WXUNUSED(h))
292 { }
293 virtual wxSize GetVideoSize() const
294 { return wxSize(0,0); }
295
296 virtual double GetPlaybackRate()
297 { return 0.0; }
298 virtual bool SetPlaybackRate(double WXUNUSED(dRate))
299 { return false; }
300
301 virtual wxMediaState GetState()
302 { return wxMEDIASTATE_STOPPED; }
303
304 virtual double GetVolume()
305 { return 0.0; }
306 virtual bool SetVolume(double WXUNUSED(dVolume))
307 { return false; }
308
309 virtual bool Load(const wxURI& WXUNUSED(location),
310 const wxURI& WXUNUSED(proxy))
311 { return false; }
312
313 virtual bool ShowPlayerControls(
314 wxMediaCtrlPlayerControls WXUNUSED(flags))
315 { return false; }
316 virtual bool IsInterfaceShown()
317 { return false; }
318
319 virtual wxLongLong GetDownloadProgress()
320 { return 0; }
321 virtual wxLongLong GetDownloadTotal()
322 { return 0; }
323
324 virtual void RESERVED8() {}
325 virtual void RESERVED9() {}
326
327 DECLARE_DYNAMIC_CLASS(wxMediaBackend)
328 };
329
330
331 //Event ID to give to our events
332 #define wxMEDIA_FINISHED_ID 13000
333 #define wxMEDIA_STOP_ID 13001
334
335 //Define our event types - we need to call DEFINE_EVENT_TYPE(EVT) later
336 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_MEDIA, wxEVT_MEDIA_FINISHED, wxMEDIA_FINISHED_ID)
337 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_MEDIA, wxEVT_MEDIA_STOP, wxMEDIA_STOP_ID)
338
339 //Function type(s) our events need
340 typedef void (wxEvtHandler::*wxMediaEventFunction)(wxMediaEvent&);
341
342 #define wxMediaEventHandler(func) \
343 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxMediaEventFunction, &func)
344
345 //Macro for usage with message maps
346 #define EVT_MEDIA_FINISHED(winid, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_FINISHED, winid, wxID_ANY, wxMediaEventHandler(fn), (wxObject *) NULL ),
347 #define EVT_MEDIA_STOP(winid, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_STOP, winid, wxID_ANY, wxMediaEventHandler(fn), (wxObject *) NULL ),
348
349 #if wxABI_VERSION >= 20602 /* 2.6.2+ only */
350 # define wxMEDIA_LOADED_ID 13002
351 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_MEDIA, wxEVT_MEDIA_LOADED, wxMEDIA_LOADED_ID)
352 # define EVT_MEDIA_LOADED(winid, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_LOADED, winid, wxID_ANY, wxMediaEventHandler(fn), (wxObject *) NULL ),
353 #endif
354
355 #if wxABI_VERSION >= 20603 /* 2.6.3+ only */
356 # define wxMEDIA_STATECHANGED_ID 13003
357 # define wxMEDIA_PLAY_ID 13004
358 # define wxMEDIA_PAUSE_ID 13005
359 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_MEDIA, wxEVT_MEDIA_STATECHANGED, wxMEDIA_STATECHANGED_ID)
360 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_MEDIA, wxEVT_MEDIA_PLAY, wxMEDIA_PLAY_ID)
361 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_MEDIA, wxEVT_MEDIA_PAUSE, wxMEDIA_PAUSE_ID)
362 # define EVT_MEDIA_STATECHANGED(winid, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_STATECHANGED, winid, wxID_ANY, wxMediaEventHandler(fn), (wxObject *) NULL ),
363 # define EVT_MEDIA_PLAY(winid, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_PLAY, winid, wxID_ANY, wxMediaEventHandler(fn), (wxObject *) NULL ),
364 # define EVT_MEDIA_PAUSE(winid, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_PAUSE, winid, wxID_ANY, wxMediaEventHandler(fn), (wxObject *) NULL ),
365 #endif
366
367 // ----------------------------------------------------------------------------
368 // common backend base class used by many other backends
369 // ----------------------------------------------------------------------------
370
371 class WXDLLIMPEXP_MEDIA wxMediaBackendCommonBase : public wxMediaBackend
372 {
373 public:
374 // add a pending wxMediaEvent of the given type
375 void QueueEvent(wxEventType evtType);
376
377 // notify that the movie playback is finished
378 void QueueFinishEvent()
379 {
380 #if wxABI_VERSION >= 20603 /* 2.6.3+ only */
381 QueueEvent(wxEVT_MEDIA_STATECHANGED);
382 #endif
383 QueueEvent(wxEVT_MEDIA_FINISHED);
384 }
385
386 // send the stop event and return true if it hasn't been vetoed
387 bool SendStopEvent();
388
389 // Queue pause event
390 void QueuePlayEvent();
391
392 // Queue pause event
393 void QueuePauseEvent();
394
395 // Queue stop event (no veto)
396 void QueueStopEvent();
397
398 protected:
399 // call this when the movie size has changed but not because it has just
400 // been loaded (in this case, call NotifyMovieLoaded() below)
401 void NotifyMovieSizeChanged();
402
403 // call this when the movie is fully loaded
404 void NotifyMovieLoaded();
405
406
407 wxMediaCtrl *m_ctrl; // parent control
408 };
409
410 // ----------------------------------------------------------------------------
411 // End compilation gaurd
412 // ----------------------------------------------------------------------------
413 #endif // wxUSE_MEDIACTRL
414
415 // ----------------------------------------------------------------------------
416 // End header guard and header itself
417 // ----------------------------------------------------------------------------
418 #endif // _WX_MEDIACTRL_H_
419
420