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