]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mediactrl.h
fix printf() argument type in GetOsInfo()
[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 ~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(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 #if wxABI_VERSION >= 20601 /* 2.6.1+ only */
195 double GetPlaybackRate(); //All but MCI & GStreamer
196 bool SetPlaybackRate(double dRate); //All but MCI & GStreamer
197 #endif
198
199 #if wxABI_VERSION >= 20602 /* 2.6.2+ only */
200 bool Load(const wxURI& location);
201 bool Load(const wxURI& location, const wxURI& proxy);
202
203 wxFileOffset GetDownloadProgress(); // DirectShow only
204 wxFileOffset GetDownloadTotal(); // DirectShow only
205
206 double GetVolume();
207 bool SetVolume(double dVolume);
208
209 bool ShowPlayerControls(
210 wxMediaCtrlPlayerControls flags = wxMEDIACTRLPLAYERCONTROLS_DEFAULT);
211
212 //helpers for the wxPython people
213 bool LoadURI(const wxString& fileName)
214 { return Load(wxURI(fileName)); }
215 bool LoadURIWithProxy(const wxString& fileName, const wxString& proxy)
216 { return Load(wxURI(fileName), wxURI(proxy)); }
217 #endif
218
219 protected:
220 static wxClassInfo* NextBackend();
221
222 void OnMediaFinished(wxMediaEvent& evt);
223 virtual void DoMoveWindow(int x, int y, int w, int h);
224 wxSize DoGetBestSize() const;
225
226 //FIXME: This is nasty... find a better way to work around
227 //inheritance issues
228 #if defined(__WXMAC__)
229 virtual void MacVisibilityChanged();
230 #endif
231 #if defined(__WXMAC__) || defined(__WXCOCOA__)
232 friend class wxQTMediaBackend;
233 #endif
234 class wxMediaBackend* m_imp;
235 bool m_bLoaded;
236
237 DECLARE_DYNAMIC_CLASS(wxMediaCtrl)
238 };
239
240 // ----------------------------------------------------------------------------
241 //
242 // wxMediaBackend
243 //
244 // Derive from this and use standard wxWidgets RTTI
245 // (DECLARE_DYNAMIC_CLASS and IMPLEMENT_CLASS) to make a backend
246 // for wxMediaCtrl. Backends are searched alphabetically -
247 // the one with the earliest letter is tried first.
248 //
249 // Note that this is currently not API or ABI compatable -
250 // so statically link or make the client compile on-site.
251 //
252 // ----------------------------------------------------------------------------
253
254 class WXDLLIMPEXP_MEDIA wxMediaBackend : public wxObject
255 {
256 public:
257 wxMediaBackend()
258 { }
259
260 virtual ~wxMediaBackend();
261
262 virtual bool CreateControl(wxControl* WXUNUSED(ctrl),
263 wxWindow* WXUNUSED(parent),
264 wxWindowID WXUNUSED(winid),
265 const wxPoint& WXUNUSED(pos),
266 const wxSize& WXUNUSED(size),
267 long WXUNUSED(style),
268 const wxValidator& WXUNUSED(validator),
269 const wxString& WXUNUSED(name))
270 { return false; }
271
272 virtual bool Play()
273 { return false; }
274 virtual bool Pause()
275 { return false; }
276 virtual bool Stop()
277 { return false; }
278
279 virtual bool Load(const wxString& WXUNUSED(fileName))
280 { return false; }
281 virtual bool Load(const wxURI& WXUNUSED(location))
282 { return false; }
283
284 virtual bool SetPosition(wxLongLong WXUNUSED(where))
285 { return 0; }
286 virtual wxLongLong GetPosition()
287 { return 0; }
288 virtual wxLongLong GetDuration()
289 { return 0; }
290
291 virtual void Move(int WXUNUSED(x), int WXUNUSED(y),
292 int WXUNUSED(w), int WXUNUSED(h))
293 { }
294 virtual wxSize GetVideoSize() const
295 { return wxSize(0,0); }
296
297 virtual double GetPlaybackRate()
298 { return 0.0; }
299 virtual bool SetPlaybackRate(double WXUNUSED(dRate))
300 { return false; }
301
302 virtual wxMediaState GetState()
303 { return wxMEDIASTATE_STOPPED; }
304
305 virtual double GetVolume()
306 { return 0.0; }
307 virtual bool SetVolume(double WXUNUSED(dVolume))
308 { return false; }
309
310 virtual bool Load(const wxURI& WXUNUSED(location),
311 const wxURI& WXUNUSED(proxy))
312 { return false; }
313
314 virtual bool ShowPlayerControls(
315 wxMediaCtrlPlayerControls WXUNUSED(flags))
316 { return false; }
317 virtual bool IsInterfaceShown()
318 { return false; }
319
320 virtual wxLongLong GetDownloadProgress()
321 { return 0; }
322 virtual wxLongLong GetDownloadTotal()
323 { return 0; }
324
325 virtual void MacVisibilityChanged()
326 { }
327 virtual void RESERVED9() {}
328
329 DECLARE_DYNAMIC_CLASS(wxMediaBackend)
330 };
331
332
333 //Event ID to give to our events
334 #define wxMEDIA_FINISHED_ID 13000
335 #define wxMEDIA_STOP_ID 13001
336
337 //Define our event types - we need to call DEFINE_EVENT_TYPE(EVT) later
338 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_MEDIA, wxEVT_MEDIA_FINISHED, wxMEDIA_FINISHED_ID)
339 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_MEDIA, wxEVT_MEDIA_STOP, wxMEDIA_STOP_ID)
340
341 //Function type(s) our events need
342 typedef void (wxEvtHandler::*wxMediaEventFunction)(wxMediaEvent&);
343
344 #define wxMediaEventHandler(func) \
345 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxMediaEventFunction, &func)
346
347 //Macro for usage with message maps
348 #define EVT_MEDIA_FINISHED(winid, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_FINISHED, winid, wxID_ANY, wxMediaEventHandler(fn), (wxObject *) NULL ),
349 #define EVT_MEDIA_STOP(winid, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_STOP, winid, wxID_ANY, wxMediaEventHandler(fn), (wxObject *) NULL ),
350
351 #if wxABI_VERSION >= 20602 /* 2.6.2+ only */
352 # define wxMEDIA_LOADED_ID 13002
353 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_MEDIA, wxEVT_MEDIA_LOADED, wxMEDIA_LOADED_ID)
354 # define EVT_MEDIA_LOADED(winid, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_LOADED, winid, wxID_ANY, wxMediaEventHandler(fn), (wxObject *) NULL ),
355 #endif
356
357 #if wxABI_VERSION >= 20603 /* 2.6.3+ only */
358 # define wxMEDIA_STATECHANGED_ID 13003
359 # define wxMEDIA_PLAY_ID 13004
360 # define wxMEDIA_PAUSE_ID 13005
361 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_MEDIA, wxEVT_MEDIA_STATECHANGED, wxMEDIA_STATECHANGED_ID)
362 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_MEDIA, wxEVT_MEDIA_PLAY, wxMEDIA_PLAY_ID)
363 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_MEDIA, wxEVT_MEDIA_PAUSE, wxMEDIA_PAUSE_ID)
364 # define EVT_MEDIA_STATECHANGED(winid, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_STATECHANGED, winid, wxID_ANY, wxMediaEventHandler(fn), (wxObject *) NULL ),
365 # define EVT_MEDIA_PLAY(winid, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_PLAY, winid, wxID_ANY, wxMediaEventHandler(fn), (wxObject *) NULL ),
366 # define EVT_MEDIA_PAUSE(winid, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_PAUSE, winid, wxID_ANY, wxMediaEventHandler(fn), (wxObject *) NULL ),
367 #endif
368
369 // ----------------------------------------------------------------------------
370 // common backend base class used by many other backends
371 // ----------------------------------------------------------------------------
372
373 class WXDLLIMPEXP_MEDIA wxMediaBackendCommonBase : public wxMediaBackend
374 {
375 public:
376 // add a pending wxMediaEvent of the given type
377 void QueueEvent(wxEventType evtType);
378
379 // notify that the movie playback is finished
380 void QueueFinishEvent()
381 {
382 #if wxABI_VERSION >= 20603 /* 2.6.3+ only */
383 QueueEvent(wxEVT_MEDIA_STATECHANGED);
384 #endif
385 QueueEvent(wxEVT_MEDIA_FINISHED);
386 }
387
388 // send the stop event and return true if it hasn't been vetoed
389 bool SendStopEvent();
390
391 // Queue pause event
392 void QueuePlayEvent();
393
394 // Queue pause event
395 void QueuePauseEvent();
396
397 // Queue stop event (no veto)
398 void QueueStopEvent();
399
400 protected:
401 // call this when the movie size has changed but not because it has just
402 // been loaded (in this case, call NotifyMovieLoaded() below)
403 void NotifyMovieSizeChanged();
404
405 // call this when the movie is fully loaded
406 void NotifyMovieLoaded();
407
408
409 wxMediaCtrl *m_ctrl; // parent control
410 };
411
412 // ----------------------------------------------------------------------------
413 // End compilation gaurd
414 // ----------------------------------------------------------------------------
415 #endif // wxUSE_MEDIACTRL
416
417 // ----------------------------------------------------------------------------
418 // End header guard and header itself
419 // ----------------------------------------------------------------------------
420 #endif // _WX_MEDIACTRL_H_
421
422