Massive reworking of wxMediaCtrl code - backend everything, search for backends via...
[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 // ----------------------------------------------------------------------------
30 // Compilation guard
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 wxMediaTimeFormat
59 {
60 wxMEDIATIMEFORMAT_TIME
61 };
62
63 #define wxMEDIABACKEND_DIRECTSHOW wxT("wxAMMediaBackend")
64 #define wxMEDIABACKEND_MCI wxT("wxMCIMediaBackend")
65 #define wxMEDIABACKEND_QUICKTIME wxT("wxQTMediaBackend")
66
67 // ----------------------------------------------------------------------------
68 //
69 // wxMediaCtrl
70 //
71 // ----------------------------------------------------------------------------
72
73 class wxMediaCtrl : public wxControl
74 {
75 public:
76 wxMediaCtrl() : m_imp(NULL), m_bLoaded(false), m_bLoop(false)
77 { }
78
79 wxMediaCtrl(wxWindow* parent, wxWindowID id,
80 const wxString& fileName = wxT(""),
81 const wxPoint& pos = wxDefaultPosition,
82 const wxSize& size = wxDefaultSize,
83 long style = 0,
84 const wxString& szBackend = wxT(""),
85 const wxValidator& validator = wxDefaultValidator,
86 const wxString& name = wxT("mediaCtrl"))
87 : m_imp(NULL), m_bLoaded(false), m_bLoop(false)
88 { Create(parent, id, fileName, pos, size, style,
89 szBackend, validator, name); }
90
91 wxMediaCtrl(wxWindow* parent, wxWindowID id,
92 const wxURI& location,
93 const wxPoint& pos = wxDefaultPosition,
94 const wxSize& size = wxDefaultSize,
95 long style = 0,
96 const wxString& szBackend = wxT(""),
97 const wxValidator& validator = wxDefaultValidator,
98 const wxString& name = wxT("mediaCtrl"))
99 : m_imp(NULL), m_bLoop(false)
100 { Create(parent, id, location, pos, size, style,
101 szBackend, validator, name); }
102
103 ~wxMediaCtrl();
104
105 bool Create(wxWindow* parent, wxWindowID id,
106 const wxString& fileName = wxT(""),
107 const wxPoint& pos = wxDefaultPosition,
108 const wxSize& size = wxDefaultSize,
109 long style = 0,
110 const wxString& szBackend = wxT(""),
111 const wxValidator& validator = wxDefaultValidator,
112 const wxString& name = wxT("mediaCtrl"));
113
114 bool Create(wxWindow* parent, wxWindowID id,
115 const wxURI& location,
116 const wxPoint& pos = wxDefaultPosition,
117 const wxSize& size = wxDefaultSize,
118 long style = 0,
119 const wxString& szBackend = wxT(""),
120 const wxValidator& validator = wxDefaultValidator,
121 const wxString& name = wxT("mediaCtrl"));
122
123 bool DoCreate(wxClassInfo* instance,
124 wxWindow* parent, wxWindowID id,
125 const wxPoint& pos = wxDefaultPosition,
126 const wxSize& size = wxDefaultSize,
127 long style = 0,
128 const wxValidator& validator = wxDefaultValidator,
129 const wxString& name = wxT("mediaCtrl"));
130
131 static wxClassInfo* NextBackend();
132
133
134 bool Play();
135 bool Pause();
136 bool Stop();
137
138 bool Load(const wxString& fileName);
139 bool Load(const wxURI& location);
140
141 void Loop(bool bLoop = true);
142 bool IsLooped();
143
144 wxMediaState GetState();
145
146 double GetPlaybackRate();
147 bool SetPlaybackRate(double dRate);
148
149 bool SetPosition(wxLongLong where);
150 wxLongLong GetPosition();
151 wxLongLong GetDuration();
152
153 protected:
154 void OnMediaFinished(const class wxMediaEvent& evt);
155 virtual void DoMoveWindow(int x, int y, int w, int h);
156 wxSize DoGetBestSize() const;
157
158 class wxMediaBackend* m_imp;
159 bool m_bLoaded;
160 bool m_bLoop;
161
162 DECLARE_DYNAMIC_CLASS(wxMediaCtrl);
163 };
164
165 // ----------------------------------------------------------------------------
166 //
167 // wxMediaBackend
168 //
169 // Currently an internal class - API stability not gauranteed.
170 //
171 // ----------------------------------------------------------------------------
172
173 class wxMediaBackend : public wxObject
174 {
175 public:
176 wxMediaBackend()
177 { }
178
179 virtual ~wxMediaBackend();
180
181 virtual bool CreateControl(wxControl* ctrl, wxWindow* parent,
182 wxWindowID id,
183 const wxPoint& pos, const wxSize& size,
184 long style,
185 const wxValidator& validator,
186 const wxString& name)
187 { return false; }
188
189 virtual bool Play()
190 { return false; }
191 virtual bool Pause()
192 { return false; }
193 virtual bool Stop()
194 { return false; }
195
196 virtual bool Load(const wxString& WXUNUSED(fileName))
197 { return false; }
198 virtual bool Load(const wxURI& WXUNUSED(location))
199 { return false; }
200
201 virtual bool SetPosition(wxLongLong WXUNUSED(where))
202 { return 0; }
203 virtual wxLongLong GetPosition()
204 { return 0; }
205 virtual wxLongLong GetDuration()
206 { return 0; }
207
208 virtual void Move(int WXUNUSED(x), int WXUNUSED(y),
209 int WXUNUSED(w), int WXUNUSED(h))
210 { }
211 virtual wxSize GetVideoSize() const
212 { return wxSize(0,0); }
213
214 virtual double GetPlaybackRate()
215 { return 0.0; }
216 virtual bool SetPlaybackRate(double WXUNUSED(dRate))
217 { return false; }
218
219 virtual wxMediaState GetState()
220 { return wxMEDIASTATE_STOPPED; }
221
222 DECLARE_CLASS(wxMediaBackend)
223 };
224
225 // ----------------------------------------------------------------------------
226 //
227 // wxMediaEvent
228 //
229 // ----------------------------------------------------------------------------
230
231 class WXDLLEXPORT wxMediaEvent : public wxNotifyEvent
232 {
233 public:
234 // ------------------------------------------------------------------------
235 // wxMediaEvent Constructor
236 //
237 // Normal constructor, much the same as wxNotifyEvent
238 // ------------------------------------------------------------------------
239 wxMediaEvent(wxEventType commandType = wxEVT_NULL, int id = 0)
240 : wxNotifyEvent(commandType, id)
241 { }
242
243 // ------------------------------------------------------------------------
244 // wxMediaEvent Copy Constructor
245 //
246 // Normal copy constructor, much the same as wxNotifyEvent
247 // ------------------------------------------------------------------------
248 wxMediaEvent(const wxMediaEvent &clone)
249 : wxNotifyEvent(clone)
250 { }
251
252 // ------------------------------------------------------------------------
253 // wxMediaEvent::Clone
254 //
255 // Allocates a copy of this object.
256 // Required for wxEvtHandler::AddPendingEvent
257 // ------------------------------------------------------------------------
258 virtual wxEvent *Clone() const
259 { return new wxMediaEvent(*this); }
260
261
262 // Put this class on wxWidget's RTTI table
263 DECLARE_DYNAMIC_CLASS(wxMediaEvent)
264 };
265
266 //Event ID to give to our events
267 #define wxMEDIA_FINISHED_ID 13000
268 #define wxMEDIA_STOP_ID 13001
269
270 //Define our event types - we need to call DEFINE_EVENT_TYPE(EVT) later
271 DECLARE_EVENT_TYPE(wxEVT_MEDIA_FINISHED, wxMEDIA_FINISHED_ID)
272 DECLARE_EVENT_TYPE(wxEVT_MEDIA_STOP, wxMEDIA_STOP_ID)
273
274 //Function type(s) our events need
275 typedef void (wxEvtHandler::*wxMediaEventFunction)(wxMediaEvent&);
276
277 //Macro for usage with message maps
278 #define EVT_MEDIA_FINISHED(winid, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_FINISHED, winid, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) (wxMediaEventFunction) & fn, (wxObject *) NULL ),
279 #define EVT_MEDIA_STOP(winid, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_STOP, winid, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) (wxMediaEventFunction) & fn, (wxObject *) NULL ),
280
281 // ----------------------------------------------------------------------------
282 // End compilation gaurd
283 // ----------------------------------------------------------------------------
284 #endif // wxUSE_MEDIACTRL
285
286 // ----------------------------------------------------------------------------
287 // End header guard and header itself
288 // ----------------------------------------------------------------------------
289 #endif // _WX_MEDIACTRL_H_
290
291