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