]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mediactrl.h
small fix
[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 #include "wx/defs.h"
30
31 // ----------------------------------------------------------------------------
32 // Compilation guard
33 // ----------------------------------------------------------------------------
34
35 #if wxUSE_MEDIACTRL
36
37 // ----------------------------------------------------------------------------
38 // Includes
39 // ----------------------------------------------------------------------------
40
41 #include "wx/control.h"
42 #include "wx/uri.h"
43
44 // ============================================================================
45 // Declarations
46 // ============================================================================
47
48 // ----------------------------------------------------------------------------
49 //
50 // Enumerations
51 //
52 // ----------------------------------------------------------------------------
53
54 enum wxMediaState
55 {
56 wxMEDIASTATE_STOPPED,
57 wxMEDIASTATE_PAUSED,
58 wxMEDIASTATE_PLAYING
59 };
60
61 #define wxMEDIABACKEND_DIRECTSHOW wxT("wxAMMediaBackend")
62 #define wxMEDIABACKEND_MCI wxT("wxMCIMediaBackend")
63 #define wxMEDIABACKEND_QUICKTIME wxT("wxQTMediaBackend")
64 #define wxMEDIABACKEND_GSTREAMER wxT("wxGStreamerMediaBackend")
65
66 // ----------------------------------------------------------------------------
67 //
68 // wxMediaEvent
69 //
70 // ----------------------------------------------------------------------------
71
72 class WXDLLIMPEXP_MEDIA wxMediaEvent : public wxNotifyEvent
73 {
74 public:
75 // ------------------------------------------------------------------------
76 // wxMediaEvent Constructor
77 //
78 // Normal constructor, much the same as wxNotifyEvent
79 // ------------------------------------------------------------------------
80 wxMediaEvent(wxEventType commandType = wxEVT_NULL, int winid = 0)
81 : wxNotifyEvent(commandType, winid)
82 { }
83
84 // ------------------------------------------------------------------------
85 // wxMediaEvent Copy Constructor
86 //
87 // Normal copy constructor, much the same as wxNotifyEvent
88 // ------------------------------------------------------------------------
89 wxMediaEvent(const wxMediaEvent &clone)
90 : wxNotifyEvent(clone)
91 { }
92
93 // ------------------------------------------------------------------------
94 // wxMediaEvent::Clone
95 //
96 // Allocates a copy of this object.
97 // Required for wxEvtHandler::AddPendingEvent
98 // ------------------------------------------------------------------------
99 virtual wxEvent *Clone() const
100 { return new wxMediaEvent(*this); }
101
102
103 // Put this class on wxWidget's RTTI table
104 DECLARE_DYNAMIC_CLASS(wxMediaEvent)
105 };
106
107 // ----------------------------------------------------------------------------
108 //
109 // wxMediaCtrl
110 //
111 // ----------------------------------------------------------------------------
112
113 class WXDLLIMPEXP_MEDIA wxMediaCtrl : public wxControl
114 {
115 public:
116 wxMediaCtrl() : m_imp(NULL), m_bLoaded(false)
117 { }
118
119 wxMediaCtrl(wxWindow* parent, wxWindowID winid,
120 const wxString& fileName = wxEmptyString,
121 const wxPoint& pos = wxDefaultPosition,
122 const wxSize& size = wxDefaultSize,
123 long style = 0,
124 const wxString& szBackend = wxEmptyString,
125 const wxValidator& validator = wxDefaultValidator,
126 const wxString& name = wxT("mediaCtrl"))
127 : m_imp(NULL), m_bLoaded(false)
128 { Create(parent, winid, fileName, pos, size, style,
129 szBackend, validator, name); }
130
131 wxMediaCtrl(wxWindow* parent, wxWindowID winid,
132 const wxURI& location,
133 const wxPoint& pos = wxDefaultPosition,
134 const wxSize& size = wxDefaultSize,
135 long style = 0,
136 const wxString& szBackend = wxEmptyString,
137 const wxValidator& validator = wxDefaultValidator,
138 const wxString& name = wxT("mediaCtrl"))
139 : m_imp(NULL), m_bLoaded(false)
140 { Create(parent, winid, location, pos, size, style,
141 szBackend, validator, name); }
142
143 ~wxMediaCtrl();
144
145 bool Create(wxWindow* parent, wxWindowID winid,
146 const wxString& fileName = wxEmptyString,
147 const wxPoint& pos = wxDefaultPosition,
148 const wxSize& size = wxDefaultSize,
149 long style = 0,
150 const wxString& szBackend = wxEmptyString,
151 const wxValidator& validator = wxDefaultValidator,
152 const wxString& name = wxT("mediaCtrl"));
153
154 bool Create(wxWindow* parent, wxWindowID winid,
155 const wxURI& location,
156 const wxPoint& pos = wxDefaultPosition,
157 const wxSize& size = wxDefaultSize,
158 long style = 0,
159 const wxString& szBackend = wxEmptyString,
160 const wxValidator& validator = wxDefaultValidator,
161 const wxString& name = wxT("mediaCtrl")); //DirectShow only
162
163 bool DoCreate(wxClassInfo* instance,
164 wxWindow* parent, wxWindowID winid,
165 const wxPoint& pos = wxDefaultPosition,
166 const wxSize& size = wxDefaultSize,
167 long style = 0,
168 const wxValidator& validator = wxDefaultValidator,
169 const wxString& name = wxT("mediaCtrl"));
170
171 bool Play();
172 bool Pause();
173 bool Stop();
174
175 bool Load(const wxString& fileName);
176
177
178 wxMediaState GetState();
179
180 wxFileOffset Seek(wxFileOffset where, wxSeekMode mode = wxFromStart);
181 wxFileOffset Tell(); //FIXME: This should be const
182 wxFileOffset Length(); //FIXME: This should be const
183
184 //
185 // Unofficial parts of API
186 //
187 //DirectShow/GStreamer only. Quicktime too, but somewhat buggy...
188 bool Load(const wxURI& location);
189
190 double GetPlaybackRate(); //All but MCI & GStreamer
191 bool SetPlaybackRate(double dRate); //All but MCI & GStreamer
192
193 double GetVolume(); //DirectShow only
194 bool SetVolume(double dVolume); //DirectShow only
195
196 protected:
197 static wxClassInfo* NextBackend();
198
199 void OnMediaFinished(wxMediaEvent& evt);
200 virtual void DoMoveWindow(int x, int y, int w, int h);
201 wxSize DoGetBestSize() const;
202
203 //FIXME: This is nasty... find a better way to work around
204 //inheritance issues
205 #ifdef __WXMAC__
206 friend class wxQTMediaBackend;
207 #endif
208 #ifdef __WXCOCOA__
209 friend class wxQTMediaBackend;
210 #endif
211 class wxMediaBackend* m_imp;
212 bool m_bLoaded;
213
214 DECLARE_DYNAMIC_CLASS(wxMediaCtrl)
215 };
216
217 // ----------------------------------------------------------------------------
218 //
219 // wxMediaBackend
220 //
221 // Currently an internal class - API stability not guaranteed.
222 //
223 // ----------------------------------------------------------------------------
224
225 class WXDLLIMPEXP_MEDIA wxMediaBackend : public wxObject
226 {
227 public:
228 wxMediaBackend()
229 { }
230
231 virtual ~wxMediaBackend();
232
233 virtual bool CreateControl(wxControl* WXUNUSED(ctrl),
234 wxWindow* WXUNUSED(parent),
235 wxWindowID WXUNUSED(winid),
236 const wxPoint& WXUNUSED(pos),
237 const wxSize& WXUNUSED(size),
238 long WXUNUSED(style),
239 const wxValidator& WXUNUSED(validator),
240 const wxString& WXUNUSED(name))
241 { return false; }
242
243 virtual bool Play()
244 { return false; }
245 virtual bool Pause()
246 { return false; }
247 virtual bool Stop()
248 { return false; }
249
250 virtual bool Load(const wxString& WXUNUSED(fileName))
251 { return false; }
252 virtual bool Load(const wxURI& WXUNUSED(location))
253 { return false; }
254
255 virtual bool SetPosition(wxLongLong WXUNUSED(where))
256 { return 0; }
257 virtual wxLongLong GetPosition()
258 { return 0; }
259 virtual wxLongLong GetDuration()
260 { return 0; }
261
262 virtual void Move(int WXUNUSED(x), int WXUNUSED(y),
263 int WXUNUSED(w), int WXUNUSED(h))
264 { }
265 virtual wxSize GetVideoSize() const
266 { return wxSize(0,0); }
267
268 virtual double GetPlaybackRate()
269 { return 0.0; }
270 virtual bool SetPlaybackRate(double WXUNUSED(dRate))
271 { return false; }
272
273 virtual wxMediaState GetState()
274 { return wxMEDIASTATE_STOPPED; }
275
276 virtual double GetVolume()
277 { return 0.0; }
278 virtual bool SetVolume(double WXUNUSED(dVolume))
279 { return false; }
280
281 virtual void RESERVED3() {}
282 virtual void RESERVED4() {}
283 virtual void RESERVED5() {}
284 virtual void RESERVED6() {}
285 virtual void RESERVED7() {}
286 virtual void RESERVED8() {}
287 virtual void RESERVED9() {}
288
289 DECLARE_DYNAMIC_CLASS(wxMediaBackend)
290 };
291
292 //Event ID to give to our events
293 #define wxMEDIA_FINISHED_ID 13000
294 #define wxMEDIA_STOP_ID 13001
295
296 //Define our event types - we need to call DEFINE_EVENT_TYPE(EVT) later
297 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_MEDIA, wxEVT_MEDIA_FINISHED, wxMEDIA_FINISHED_ID)
298 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_MEDIA, wxEVT_MEDIA_STOP, wxMEDIA_STOP_ID)
299
300 //Function type(s) our events need
301 typedef void (wxEvtHandler::*wxMediaEventFunction)(wxMediaEvent&);
302
303 #define wxMediaEventHandler(func) \
304 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxMediaEventFunction, &func)
305
306 //Macro for usage with message maps
307 #define EVT_MEDIA_FINISHED(winid, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_FINISHED, winid, wxID_ANY, wxMediaEventHandler(fn), (wxObject *) NULL ),
308 #define EVT_MEDIA_STOP(winid, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_STOP, winid, wxID_ANY, wxMediaEventHandler(fn), (wxObject *) NULL ),
309
310 // ----------------------------------------------------------------------------
311 // End compilation gaurd
312 // ----------------------------------------------------------------------------
313 #endif // wxUSE_MEDIACTRL
314
315 // ----------------------------------------------------------------------------
316 // End header guard and header itself
317 // ----------------------------------------------------------------------------
318 #endif // _WX_MEDIACTRL_H_
319
320