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