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