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