]> git.saurik.com Git - wxWidgets.git/blame - include/wx/mediactrl.h
Applied patch [ 1325207 ] Fixes unicode build using Solaris with Sun's SunPro compiler
[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
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// ----------------------------------------------------------------------------
72259e00 25
2ecf902b
WS
26#include "wx/defs.h"
27
ff4aedc5
RN
28// ----------------------------------------------------------------------------
29// Compilation guard
30// ----------------------------------------------------------------------------
2ecf902b 31
ff4aedc5
RN
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
51enum wxMediaState
52{
53 wxMEDIASTATE_STOPPED,
54 wxMEDIASTATE_PAUSED,
55 wxMEDIASTATE_PLAYING
56};
57
c5191fbd
VZ
58enum 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
ff4aedc5
RN
70#define wxMEDIABACKEND_DIRECTSHOW wxT("wxAMMediaBackend")
71#define wxMEDIABACKEND_MCI wxT("wxMCIMediaBackend")
72#define wxMEDIABACKEND_QUICKTIME wxT("wxQTMediaBackend")
ce756cb0 73#define wxMEDIABACKEND_GSTREAMER wxT("wxGStreamerMediaBackend")
ff4aedc5 74
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
153 ~wxMediaCtrl();
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
RN
172
173 bool DoCreate(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
199 wxFileOffset GetDownloadProgress();
200 wxFileOffset GetDownloadTotal();
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)); }
84006e65 213
ff4aedc5 214protected:
973dc0a8
RN
215 static wxClassInfo* NextBackend();
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
c5191fbd 223#if defined(__WXMAC__) || defined(__WXCOCOA__)
4fc81cbc 224 friend class wxQTMediaBackend;
3b5023b9 225#endif
ff4aedc5
RN
226 class wxMediaBackend* m_imp;
227 bool m_bLoaded;
ff4aedc5 228
3839f37e 229 DECLARE_DYNAMIC_CLASS(wxMediaCtrl)
ff4aedc5
RN
230};
231
232// ----------------------------------------------------------------------------
233//
234// wxMediaBackend
235//
c5191fbd
VZ
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.
ff4aedc5
RN
243//
244// ----------------------------------------------------------------------------
245
ff2b312f 246class WXDLLIMPEXP_MEDIA wxMediaBackend : public wxObject
ff4aedc5
RN
247{
248public:
249 wxMediaBackend()
250 { }
251
252 virtual ~wxMediaBackend();
253
226ec5a7
WS
254 virtual bool CreateControl(wxControl* WXUNUSED(ctrl),
255 wxWindow* WXUNUSED(parent),
4fc81cbc 256 wxWindowID WXUNUSED(winid),
226ec5a7 257 const wxPoint& WXUNUSED(pos),
78450975 258 const wxSize& WXUNUSED(size),
226ec5a7 259 long WXUNUSED(style),
78450975
RN
260 const wxValidator& WXUNUSED(validator),
261 const wxString& WXUNUSED(name))
ff4aedc5
RN
262 { return false; }
263
226ec5a7 264 virtual bool Play()
ff4aedc5 265 { return false; }
226ec5a7 266 virtual bool Pause()
ff4aedc5 267 { return false; }
226ec5a7 268 virtual bool Stop()
ff4aedc5
RN
269 { return false; }
270
226ec5a7 271 virtual bool Load(const wxString& WXUNUSED(fileName))
ff4aedc5 272 { return false; }
226ec5a7 273 virtual bool Load(const wxURI& WXUNUSED(location))
ff4aedc5
RN
274 { return false; }
275
226ec5a7 276 virtual bool SetPosition(wxLongLong WXUNUSED(where))
ff4aedc5 277 { return 0; }
226ec5a7 278 virtual wxLongLong GetPosition()
ff4aedc5 279 { return 0; }
226ec5a7 280 virtual wxLongLong GetDuration()
ff4aedc5
RN
281 { return 0; }
282
226ec5a7
WS
283 virtual void Move(int WXUNUSED(x), int WXUNUSED(y),
284 int WXUNUSED(w), int WXUNUSED(h))
ff4aedc5 285 { }
226ec5a7 286 virtual wxSize GetVideoSize() const
c47addef 287 { return wxSize(0,0); }
ff4aedc5 288
226ec5a7 289 virtual double GetPlaybackRate()
ff4aedc5 290 { return 0.0; }
226ec5a7 291 virtual bool SetPlaybackRate(double WXUNUSED(dRate))
ff4aedc5
RN
292 { return false; }
293
294 virtual wxMediaState GetState()
295 { return wxMEDIASTATE_STOPPED; }
296
6f8c67e7
JS
297 virtual double GetVolume()
298 { return 0.0; }
299 virtual bool SetVolume(double WXUNUSED(dVolume))
300 { return false; }
301
c5191fbd
VZ
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
07323ed6
RN
317 virtual void RESERVED8() {}
318 virtual void RESERVED9() {}
319
3839f37e 320 DECLARE_DYNAMIC_CLASS(wxMediaBackend)
ff4aedc5
RN
321};
322
bf354396 323
ff4aedc5
RN
324//Event ID to give to our events
325#define wxMEDIA_FINISHED_ID 13000
326#define wxMEDIA_STOP_ID 13001
84006e65 327#define wxMEDIA_LOADED_ID 13002
ff4aedc5
RN
328
329//Define our event types - we need to call DEFINE_EVENT_TYPE(EVT) later
c220a8ec
RD
330DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_MEDIA, wxEVT_MEDIA_FINISHED, wxMEDIA_FINISHED_ID)
331DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_MEDIA, wxEVT_MEDIA_STOP, wxMEDIA_STOP_ID)
84006e65 332DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_MEDIA, wxEVT_MEDIA_LOADED, wxMEDIA_LOADED_ID)
ff4aedc5
RN
333
334//Function type(s) our events need
335typedef void (wxEvtHandler::*wxMediaEventFunction)(wxMediaEvent&);
336
4153a503
RN
337#define wxMediaEventHandler(func) \
338 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxMediaEventFunction, &func)
339
ff4aedc5 340//Macro for usage with message maps
4153a503
RN
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 ),
84006e65 343#define EVT_MEDIA_LOADED(winid, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_LOADED, winid, wxID_ANY, wxMediaEventHandler(fn), (wxObject *) NULL ),
c5191fbd 344
bf354396
VZ
345// ----------------------------------------------------------------------------
346// common backend base class used by many other backends
347// ----------------------------------------------------------------------------
348
349class WXDLLIMPEXP_MEDIA wxMediaBackendCommonBase : public wxMediaBackend
350{
351public:
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
361protected:
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
ff4aedc5
RN
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