]> git.saurik.com Git - wxWidgets.git/blame - include/wx/mediactrl.h
wxMessageBox off the main thread lost result code.
[wxWidgets.git] / include / wx / mediactrl.h
CommitLineData
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 6// Created: 11/07/04
1a680109
RN
7// Copyright: (c) Ryan Norton
8// Licence: wxWindows licence
ff4aedc5 9///////////////////////////////////////////////////////////////////////////////
1a680109 10
ff4aedc5
RN
11// ============================================================================
12// Definitions
13// ============================================================================
14
15// ----------------------------------------------------------------------------
16// Header guard
17// ----------------------------------------------------------------------------
18#ifndef _WX_MEDIACTRL_H_
19#define _WX_MEDIACTRL_H_
20
21// ----------------------------------------------------------------------------
22// Pre-compiled header stuff
23// ----------------------------------------------------------------------------
72259e00 24
2ecf902b
WS
25#include "wx/defs.h"
26
ff4aedc5
RN
27// ----------------------------------------------------------------------------
28// Compilation guard
29// ----------------------------------------------------------------------------
2ecf902b 30
ff4aedc5
RN
31#if wxUSE_MEDIACTRL
32
33// ----------------------------------------------------------------------------
34// Includes
35// ----------------------------------------------------------------------------
36
37#include "wx/control.h"
38#include "wx/uri.h"
39
40// ============================================================================
41// Declarations
42// ============================================================================
43
44// ----------------------------------------------------------------------------
45//
46// Enumerations
47//
48// ----------------------------------------------------------------------------
49
50enum wxMediaState
51{
52 wxMEDIASTATE_STOPPED,
53 wxMEDIASTATE_PAUSED,
54 wxMEDIASTATE_PLAYING
55};
56
c5191fbd
VZ
57enum wxMediaCtrlPlayerControls
58{
59 wxMEDIACTRLPLAYERCONTROLS_NONE = 0,
4c51a665 60 //Step controls like fastforward, step one frame etc.
c5191fbd
VZ
61 wxMEDIACTRLPLAYERCONTROLS_STEP = 1 << 0,
62 //Volume controls like the speaker icon, volume slider, etc.
63 wxMEDIACTRLPLAYERCONTROLS_VOLUME = 1 << 1,
64 wxMEDIACTRLPLAYERCONTROLS_DEFAULT =
65 wxMEDIACTRLPLAYERCONTROLS_STEP |
66 wxMEDIACTRLPLAYERCONTROLS_VOLUME
67};
68
ff4aedc5
RN
69#define wxMEDIABACKEND_DIRECTSHOW wxT("wxAMMediaBackend")
70#define wxMEDIABACKEND_MCI wxT("wxMCIMediaBackend")
71#define wxMEDIABACKEND_QUICKTIME wxT("wxQTMediaBackend")
ce756cb0 72#define wxMEDIABACKEND_GSTREAMER wxT("wxGStreamerMediaBackend")
557002cf
VZ
73#define wxMEDIABACKEND_REALPLAYER wxT("wxRealPlayerMediaBackend")
74#define wxMEDIABACKEND_WMP10 wxT("wxWMP10MediaBackend")
c5191fbd 75
226ec5a7
WS
76// ----------------------------------------------------------------------------
77//
78// wxMediaEvent
79//
80// ----------------------------------------------------------------------------
81
ff2b312f 82class WXDLLIMPEXP_MEDIA wxMediaEvent : public wxNotifyEvent
226ec5a7
WS
83{
84public:
85 // ------------------------------------------------------------------------
86 // wxMediaEvent Constructor
87 //
88 // Normal constructor, much the same as wxNotifyEvent
89 // ------------------------------------------------------------------------
4fc81cbc
RN
90 wxMediaEvent(wxEventType commandType = wxEVT_NULL, int winid = 0)
91 : wxNotifyEvent(commandType, winid)
226ec5a7
WS
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
ff4aedc5
RN
117// ----------------------------------------------------------------------------
118//
119// wxMediaCtrl
120//
121// ----------------------------------------------------------------------------
122
ff2b312f 123class WXDLLIMPEXP_MEDIA wxMediaCtrl : public wxControl
ff4aedc5
RN
124{
125public:
bc036010 126 wxMediaCtrl() : m_imp(NULL), m_bLoaded(false)
ff4aedc5
RN
127 { }
128
4fc81cbc 129 wxMediaCtrl(wxWindow* parent, wxWindowID winid,
8b5d5223 130 const wxString& fileName = wxEmptyString,
226ec5a7 131 const wxPoint& pos = wxDefaultPosition,
ff4aedc5 132 const wxSize& size = wxDefaultSize,
226ec5a7 133 long style = 0,
8b5d5223 134 const wxString& szBackend = wxEmptyString,
ff4aedc5
RN
135 const wxValidator& validator = wxDefaultValidator,
136 const wxString& name = wxT("mediaCtrl"))
bc036010 137 : m_imp(NULL), m_bLoaded(false)
4fc81cbc 138 { Create(parent, winid, fileName, pos, size, style,
ff4aedc5
RN
139 szBackend, validator, name); }
140
4fc81cbc 141 wxMediaCtrl(wxWindow* parent, wxWindowID winid,
ff4aedc5 142 const wxURI& location,
226ec5a7 143 const wxPoint& pos = wxDefaultPosition,
ff4aedc5 144 const wxSize& size = wxDefaultSize,
226ec5a7 145 long style = 0,
8b5d5223 146 const wxString& szBackend = wxEmptyString,
ff4aedc5
RN
147 const wxValidator& validator = wxDefaultValidator,
148 const wxString& name = wxT("mediaCtrl"))
bc036010 149 : m_imp(NULL), m_bLoaded(false)
4fc81cbc 150 { Create(parent, winid, location, pos, size, style,
ff4aedc5
RN
151 szBackend, validator, name); }
152
d3c7fc99 153 virtual ~wxMediaCtrl();
ff4aedc5 154
4fc81cbc 155 bool Create(wxWindow* parent, wxWindowID winid,
8b5d5223 156 const wxString& fileName = wxEmptyString,
226ec5a7 157 const wxPoint& pos = wxDefaultPosition,
ff4aedc5 158 const wxSize& size = wxDefaultSize,
226ec5a7 159 long style = 0,
8b5d5223 160 const wxString& szBackend = wxEmptyString,
ff4aedc5
RN
161 const wxValidator& validator = wxDefaultValidator,
162 const wxString& name = wxT("mediaCtrl"));
163
4fc81cbc 164 bool Create(wxWindow* parent, wxWindowID winid,
ff4aedc5 165 const wxURI& location,
226ec5a7 166 const wxPoint& pos = wxDefaultPosition,
ff4aedc5 167 const wxSize& size = wxDefaultSize,
226ec5a7 168 long style = 0,
8b5d5223 169 const wxString& szBackend = wxEmptyString,
ff4aedc5 170 const wxValidator& validator = wxDefaultValidator,
c5191fbd 171 const wxString& name = wxT("mediaCtrl"));
ff4aedc5 172
644cb537 173 bool DoCreate(const wxClassInfo* instance,
4fc81cbc 174 wxWindow* parent, wxWindowID winid,
226ec5a7 175 const wxPoint& pos = wxDefaultPosition,
ff4aedc5 176 const wxSize& size = wxDefaultSize,
226ec5a7 177 long style = 0,
ff4aedc5
RN
178 const wxValidator& validator = wxDefaultValidator,
179 const wxString& name = wxT("mediaCtrl"));
180
ff4aedc5
RN
181 bool Play();
182 bool Pause();
183 bool Stop();
184
185 bool Load(const wxString& fileName);
ff4aedc5 186
ff4aedc5
RN
187 wxMediaState GetState();
188
9180b535
RN
189 wxFileOffset Seek(wxFileOffset where, wxSeekMode mode = wxFromStart);
190 wxFileOffset Tell(); //FIXME: This should be const
191 wxFileOffset Length(); //FIXME: This should be const
973dc0a8 192
bc036010
RN
193 double GetPlaybackRate(); //All but MCI & GStreamer
194 bool SetPlaybackRate(double dRate); //All but MCI & GStreamer
c5191fbd 195
c5191fbd
VZ
196 bool Load(const wxURI& location);
197 bool Load(const wxURI& location, const wxURI& proxy);
198
557002cf
VZ
199 wxFileOffset GetDownloadProgress(); // DirectShow only
200 wxFileOffset GetDownloadTotal(); // DirectShow only
bc036010 201
c5191fbd
VZ
202 double GetVolume();
203 bool SetVolume(double dVolume);
6f8c67e7 204
c5191fbd
VZ
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)); }
0c81ef7f 213
ff4aedc5 214protected:
644cb537 215 static const wxClassInfo* NextBackend(wxClassInfo::const_iterator* it);
973dc0a8 216
226ec5a7 217 void OnMediaFinished(wxMediaEvent& evt);
ff4aedc5
RN
218 virtual void DoMoveWindow(int x, int y, int w, int h);
219 wxSize DoGetBestSize() const;
220
bc036010
RN
221 //FIXME: This is nasty... find a better way to work around
222 //inheritance issues
4954ee50 223#if defined(__WXOSX_CARBON__)
0c81ef7f
SC
224 virtual void MacVisibilityChanged();
225#endif
4954ee50 226#if defined(__WXOSX_CARBON__) || defined(__WXCOCOA__)
4fc81cbc 227 friend class wxQTMediaBackend;
3b5023b9 228#endif
ff4aedc5
RN
229 class wxMediaBackend* m_imp;
230 bool m_bLoaded;
ff4aedc5 231
3839f37e 232 DECLARE_DYNAMIC_CLASS(wxMediaCtrl)
ff4aedc5
RN
233};
234
235// ----------------------------------------------------------------------------
236//
237// wxMediaBackend
238//
c5191fbd
VZ
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//
05e66a70 244// Note that this is currently not API or ABI compatible -
c5191fbd 245// so statically link or make the client compile on-site.
ff4aedc5
RN
246//
247// ----------------------------------------------------------------------------
248
ff2b312f 249class WXDLLIMPEXP_MEDIA wxMediaBackend : public wxObject
ff4aedc5
RN
250{
251public:
252 wxMediaBackend()
253 { }
254
255 virtual ~wxMediaBackend();
256
226ec5a7
WS
257 virtual bool CreateControl(wxControl* WXUNUSED(ctrl),
258 wxWindow* WXUNUSED(parent),
4fc81cbc 259 wxWindowID WXUNUSED(winid),
226ec5a7 260 const wxPoint& WXUNUSED(pos),
78450975 261 const wxSize& WXUNUSED(size),
226ec5a7 262 long WXUNUSED(style),
78450975
RN
263 const wxValidator& WXUNUSED(validator),
264 const wxString& WXUNUSED(name))
ff4aedc5
RN
265 { return false; }
266
226ec5a7 267 virtual bool Play()
ff4aedc5 268 { return false; }
226ec5a7 269 virtual bool Pause()
ff4aedc5 270 { return false; }
226ec5a7 271 virtual bool Stop()
ff4aedc5
RN
272 { return false; }
273
226ec5a7 274 virtual bool Load(const wxString& WXUNUSED(fileName))
ff4aedc5 275 { return false; }
226ec5a7 276 virtual bool Load(const wxURI& WXUNUSED(location))
ff4aedc5
RN
277 { return false; }
278
226ec5a7 279 virtual bool SetPosition(wxLongLong WXUNUSED(where))
ff4aedc5 280 { return 0; }
226ec5a7 281 virtual wxLongLong GetPosition()
ff4aedc5 282 { return 0; }
226ec5a7 283 virtual wxLongLong GetDuration()
ff4aedc5
RN
284 { return 0; }
285
226ec5a7
WS
286 virtual void Move(int WXUNUSED(x), int WXUNUSED(y),
287 int WXUNUSED(w), int WXUNUSED(h))
ff4aedc5 288 { }
226ec5a7 289 virtual wxSize GetVideoSize() const
c47addef 290 { return wxSize(0,0); }
ff4aedc5 291
226ec5a7 292 virtual double GetPlaybackRate()
ff4aedc5 293 { return 0.0; }
226ec5a7 294 virtual bool SetPlaybackRate(double WXUNUSED(dRate))
ff4aedc5
RN
295 { return false; }
296
297 virtual wxMediaState GetState()
298 { return wxMEDIASTATE_STOPPED; }
299
6f8c67e7
JS
300 virtual double GetVolume()
301 { return 0.0; }
302 virtual bool SetVolume(double WXUNUSED(dVolume))
303 { return false; }
304
c5191fbd
VZ
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
0c81ef7f
SC
320 virtual void MacVisibilityChanged()
321 { }
07323ed6
RN
322 virtual void RESERVED9() {}
323
3839f37e 324 DECLARE_DYNAMIC_CLASS(wxMediaBackend)
ff4aedc5
RN
325};
326
bf354396 327
c058cafa 328//Our events
9b11752c
VZ
329wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_MEDIA, wxEVT_MEDIA_FINISHED, wxMediaEvent );
330wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_MEDIA, wxEVT_MEDIA_STOP, wxMediaEvent );
ff4aedc5
RN
331
332//Function type(s) our events need
333typedef void (wxEvtHandler::*wxMediaEventFunction)(wxMediaEvent&);
334
4153a503 335#define wxMediaEventHandler(func) \
3c778901 336 wxEVENT_HANDLER_CAST(wxMediaEventFunction, func)
4153a503 337
ff4aedc5 338//Macro for usage with message maps
a0e9a5df
FM
339#define EVT_MEDIA_FINISHED(winid, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_FINISHED, winid, wxID_ANY, wxMediaEventHandler(fn), NULL ),
340#define EVT_MEDIA_STOP(winid, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_STOP, winid, wxID_ANY, wxMediaEventHandler(fn), NULL ),
557002cf 341
9b11752c 342wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_MEDIA, wxEVT_MEDIA_LOADED, wxMediaEvent );
a0e9a5df 343#define EVT_MEDIA_LOADED(winid, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_LOADED, winid, wxID_ANY, wxMediaEventHandler(fn), NULL ),
557002cf 344
9b11752c
VZ
345wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_MEDIA, wxEVT_MEDIA_STATECHANGED, wxMediaEvent );
346wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_MEDIA, wxEVT_MEDIA_PLAY, wxMediaEvent );
347wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_MEDIA, wxEVT_MEDIA_PAUSE, wxMediaEvent );
a0e9a5df
FM
348#define EVT_MEDIA_STATECHANGED(winid, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_STATECHANGED, winid, wxID_ANY, wxMediaEventHandler(fn), NULL ),
349#define EVT_MEDIA_PLAY(winid, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_PLAY, winid, wxID_ANY, wxMediaEventHandler(fn), NULL ),
350#define EVT_MEDIA_PAUSE(winid, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_PAUSE, winid, wxID_ANY, wxMediaEventHandler(fn), NULL ),
c5191fbd 351
bf354396
VZ
352// ----------------------------------------------------------------------------
353// common backend base class used by many other backends
354// ----------------------------------------------------------------------------
355
356class WXDLLIMPEXP_MEDIA wxMediaBackendCommonBase : public wxMediaBackend
357{
358public:
359 // add a pending wxMediaEvent of the given type
360 void QueueEvent(wxEventType evtType);
361
362 // notify that the movie playback is finished
557002cf
VZ
363 void QueueFinishEvent()
364 {
557002cf 365 QueueEvent(wxEVT_MEDIA_STATECHANGED);
557002cf
VZ
366 QueueEvent(wxEVT_MEDIA_FINISHED);
367 }
bf354396
VZ
368
369 // send the stop event and return true if it hasn't been vetoed
370 bool SendStopEvent();
371
557002cf
VZ
372 // Queue pause event
373 void QueuePlayEvent();
374
375 // Queue pause event
376 void QueuePauseEvent();
377
378 // Queue stop event (no veto)
379 void QueueStopEvent();
380
bf354396
VZ
381protected:
382 // call this when the movie size has changed but not because it has just
383 // been loaded (in this case, call NotifyMovieLoaded() below)
384 void NotifyMovieSizeChanged();
385
386 // call this when the movie is fully loaded
387 void NotifyMovieLoaded();
388
389
390 wxMediaCtrl *m_ctrl; // parent control
391};
392
ff4aedc5 393// ----------------------------------------------------------------------------
05e66a70 394// End compilation guard
ff4aedc5
RN
395// ----------------------------------------------------------------------------
396#endif // wxUSE_MEDIACTRL
397
398// ----------------------------------------------------------------------------
399// End header guard and header itself
400// ----------------------------------------------------------------------------
401#endif // _WX_MEDIACTRL_H_
402
403