]>
git.saurik.com Git - wxWidgets.git/blob - src/common/mediactrlcmn.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: common/mediactrl.cpp
3 // Purpose: wxMediaCtrl common code
4 // Author: Ryan Norton <wxprojects@comcast.net>
8 // Copyright: (c) Ryan Norton
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 //===========================================================================
14 //===========================================================================
16 //---------------------------------------------------------------------------
17 // Pre-compiled header stuff
18 //---------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "mediactrl.h"
24 #include "wx/wxprec.h"
30 //---------------------------------------------------------------------------
32 //---------------------------------------------------------------------------
33 #include "wx/mediactrl.h"
36 //---------------------------------------------------------------------------
38 //---------------------------------------------------------------------------
41 //===========================================================================
45 //===========================================================================
47 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
48 // RTTI and Event implementations
49 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
51 IMPLEMENT_CLASS(wxMediaCtrl
, wxControl
);
52 IMPLEMENT_CLASS(wxMediaBackend
, wxObject
);
53 IMPLEMENT_DYNAMIC_CLASS(wxMediaEvent
, wxEvent
);
54 DEFINE_EVENT_TYPE(wxEVT_MEDIA_FINISHED
);
55 DEFINE_EVENT_TYPE(wxEVT_MEDIA_STOP
);
57 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
61 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
63 //---------------------------------------------------------------------------
64 // wxMediaCtrl::Create (file version)
65 // wxMediaCtrl::Create (URL version)
67 // Searches for a backend that is installed on the system (backends
68 // starting with lower characters in the alphabet are given priority),
69 // and creates the control from it
71 // This searches by searching the global RTTI hashtable, class by class,
72 // attempting to call CreateControl on each one found that is a derivative
73 // of wxMediaBackend - if it succeededs Create returns true, otherwise
74 // it keeps iterating through the hashmap.
75 //---------------------------------------------------------------------------
76 bool wxMediaCtrl::Create(wxWindow
* parent
, wxWindowID id
,
77 const wxString
& fileName
,
81 const wxString
& szBackend
,
82 const wxValidator
& validator
,
85 if(!szBackend
.empty())
87 if(!DoCreate(wxClassInfo::FindClass(szBackend
), parent
, id
,
88 pos
, size
, style
, validator
, name
))
94 if (!fileName
.empty())
96 if (!m_imp
->Load(fileName
))
108 wxClassInfo::sm_classTable
->BeginFind();
110 wxClassInfo
* classInfo
= NextBackend();
114 if(!DoCreate(classInfo
, parent
, id
,
115 pos
, size
, style
, validator
, name
))
118 if (!fileName
.empty())
120 if (m_imp
->Load(fileName
))
128 classInfo
= NextBackend();
136 bool wxMediaCtrl::Create(wxWindow
* parent
, wxWindowID id
,
137 const wxURI
& location
,
141 const wxString
& szBackend
,
142 const wxValidator
& validator
,
143 const wxString
& name
)
145 if(!szBackend
.empty())
147 if(!DoCreate(wxClassInfo::FindClass(szBackend
), parent
, id
,
148 pos
, size
, style
, validator
, name
))
154 if (!m_imp
->Load(location
))
165 wxClassInfo::sm_classTable
->BeginFind();
167 wxClassInfo
* classInfo
= NextBackend();
171 if(!DoCreate(classInfo
, parent
, id
,
172 pos
, size
, style
, validator
, name
))
175 if (m_imp
->Load(location
))
180 classInfo
= NextBackend();
188 //---------------------------------------------------------------------------
189 // wxMediaCtrl::DoCreate
191 // Attempts to create the control from a backend
192 //---------------------------------------------------------------------------
193 bool wxMediaCtrl::DoCreate(wxClassInfo
* classInfo
,
194 wxWindow
* parent
, wxWindowID id
,
198 const wxValidator
& validator
,
199 const wxString
& name
)
201 m_imp
= (wxMediaBackend
*)classInfo
->CreateObject();
203 if( m_imp
->CreateControl(this, parent
, id
, pos
, size
,
204 style
, validator
, name
) )
206 this->Connect(GetId(), wxEVT_MEDIA_FINISHED
,
207 (wxObjectEventFunction
) (wxEventFunction
)
208 (wxMediaEventFunction
)
209 &wxMediaCtrl::OnMediaFinished
);
217 //---------------------------------------------------------------------------
218 // wxMediaCtrl::NextBackend
221 // Search through the RTTI hashmap one at a
222 // time, attempting to create each derivative
226 // STL isn't compatable with and will have a compilation error
227 // on a wxNode, however, wxHashTable::compatibility_iterator is
228 // incompatible with the old 2.4 stable version - but since
229 // we're in 2.5 only we don't need to worry about this
231 //---------------------------------------------------------------------------
232 wxClassInfo
* wxMediaCtrl::NextBackend()
234 wxHashTable::compatibility_iterator
235 node
= wxClassInfo::sm_classTable
->Next();
238 wxClassInfo
* classInfo
= (wxClassInfo
*)node
->GetData();
239 if ( classInfo
->IsKindOf(CLASSINFO(wxMediaBackend
)) &&
240 classInfo
!= CLASSINFO(wxMediaBackend
) )
244 node
= wxClassInfo::sm_classTable
->Next();
248 // Nope - couldn't successfully find one... fail
254 //---------------------------------------------------------------------------
255 // wxMediaCtrl Destructor
257 // Free up the backend if it exists
258 //---------------------------------------------------------------------------
259 wxMediaCtrl::~wxMediaCtrl()
265 //---------------------------------------------------------------------------
266 // wxMediaCtrl::Load (file version)
267 // wxMediaCtrl::Load (URL version)
269 // Here we call load of the backend - keeping
270 // track of whether it was successful or not - which
271 // will determine which later method calls work
272 //---------------------------------------------------------------------------
273 bool wxMediaCtrl::Load(const wxString
& fileName
)
276 return (m_bLoaded
= m_imp
->Load(fileName
));
280 bool wxMediaCtrl::Load(const wxURI
& location
)
283 return (m_bLoaded
= m_imp
->Load(location
));
287 //---------------------------------------------------------------------------
289 // wxMediaCtrl::Pause
291 // wxMediaCtrl::GetPlaybackRate
292 // wxMediaCtrl::SetPlaybackRate
293 // wxMediaCtrl::SetPosition
294 // wxMediaCtrl::GetPosition
295 // wxMediaCtrl::GetDuration
296 // wxMediaCtrl::GetState
297 // wxMediaCtrl::DoGetBestSize
299 // 1) Check to see whether the backend exists and is loading
300 // 2) Call the backend's version of the method, returning success
301 // if the backend's version succeeds
302 //---------------------------------------------------------------------------
303 bool wxMediaCtrl::Play()
305 if(m_imp
&& m_bLoaded
)
306 return m_imp
->Play();
310 bool wxMediaCtrl::Pause()
312 if(m_imp
&& m_bLoaded
)
313 return m_imp
->Pause();
317 bool wxMediaCtrl::Stop()
319 if(m_imp
&& m_bLoaded
)
320 return m_imp
->Stop();
324 double wxMediaCtrl::GetPlaybackRate()
326 if(m_imp
&& m_bLoaded
)
327 return m_imp
->GetPlaybackRate();
331 bool wxMediaCtrl::SetPlaybackRate(double dRate
)
333 if(m_imp
&& m_bLoaded
)
334 return m_imp
->SetPlaybackRate(dRate
);
338 bool wxMediaCtrl::SetPosition(wxLongLong where
)
340 if(m_imp
&& m_bLoaded
)
341 return m_imp
->SetPosition(where
);
345 wxLongLong
wxMediaCtrl::GetPosition()
347 if(m_imp
&& m_bLoaded
)
348 return m_imp
->GetPosition();
352 wxLongLong
wxMediaCtrl::GetDuration()
354 if(m_imp
&& m_bLoaded
)
355 return m_imp
->GetDuration();
359 wxMediaState
wxMediaCtrl::GetState()
361 if(m_imp
&& m_bLoaded
)
362 return m_imp
->GetState();
363 return wxMEDIASTATE_STOPPED
;
366 wxSize
wxMediaCtrl::DoGetBestSize() const
369 return m_imp
->GetVideoSize();
373 //---------------------------------------------------------------------------
374 // wxMediaCtrl::DoMoveWindow
376 // 1) Call parent's version so that our control's window moves where
378 // 2) If the backend exists and is loaded, move the video
379 // of the media to where our control's window is now located
380 //---------------------------------------------------------------------------
381 void wxMediaCtrl::DoMoveWindow(int x
, int y
, int w
, int h
)
383 wxControl::DoMoveWindow(x
,y
,w
,h
);
386 m_imp
->Move(x
, y
, w
, h
);
389 void wxMediaCtrl::Loop(bool bLoop
)
394 bool wxMediaCtrl::IsLooped()
399 void wxMediaCtrl::OnMediaFinished(const wxMediaEvent
& WXUNUSED(evt
))
411 //DARWIN gcc compiler badly screwed up - needs destructor impl in source
412 wxMediaBackend::~wxMediaBackend()
414 #include <wx/html/forcelnk.h>
415 FORCE_LINK(basewxmediabackends
);
417 //---------------------------------------------------------------------------
418 // End of compilation guard and of file
419 //---------------------------------------------------------------------------
420 #endif //wxUSE_MEDIACTRL