]>
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 succeeded 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())
104 SetBestFittingSize(size
);
109 wxClassInfo::sm_classTable
->BeginFind();
111 wxClassInfo
* classInfo
= NextBackend();
115 if(!DoCreate(classInfo
, parent
, id
,
116 pos
, size
, style
, validator
, name
))
119 if (!fileName
.empty())
123 SetBestFittingSize(size
);
131 SetBestFittingSize(size
);
135 classInfo
= NextBackend();
143 bool wxMediaCtrl::Create(wxWindow
* parent
, wxWindowID id
,
144 const wxURI
& location
,
148 const wxString
& szBackend
,
149 const wxValidator
& validator
,
150 const wxString
& name
)
152 if(!szBackend
.empty())
154 if(!DoCreate(wxClassInfo::FindClass(szBackend
), parent
, id
,
155 pos
, size
, style
, validator
, name
))
168 SetBestFittingSize(size
);
173 wxClassInfo::sm_classTable
->BeginFind();
175 wxClassInfo
* classInfo
= NextBackend();
179 if(!DoCreate(classInfo
, parent
, id
,
180 pos
, size
, style
, validator
, name
))
185 SetBestFittingSize(size
);
191 classInfo
= NextBackend();
199 //---------------------------------------------------------------------------
200 // wxMediaCtrl::DoCreate
202 // Attempts to create the control from a backend
203 //---------------------------------------------------------------------------
204 bool wxMediaCtrl::DoCreate(wxClassInfo
* classInfo
,
205 wxWindow
* parent
, wxWindowID id
,
209 const wxValidator
& validator
,
210 const wxString
& name
)
212 m_imp
= (wxMediaBackend
*)classInfo
->CreateObject();
214 if( m_imp
->CreateControl(this, parent
, id
, pos
, size
,
215 style
, validator
, name
) )
217 this->Connect(GetId(), wxEVT_MEDIA_FINISHED
,
218 (wxObjectEventFunction
) (wxEventFunction
)
219 (wxMediaEventFunction
)
220 &wxMediaCtrl::OnMediaFinished
);
228 //---------------------------------------------------------------------------
229 // wxMediaCtrl::NextBackend
232 // Search through the RTTI hashmap one at a
233 // time, attempting to create each derivative
237 // STL isn't compatable with and will have a compilation error
238 // on a wxNode, however, wxHashTable::compatibility_iterator is
239 // incompatible with the old 2.4 stable version - but since
240 // we're in 2.5 only we don't need to worry about this
242 //---------------------------------------------------------------------------
243 wxClassInfo
* wxMediaCtrl::NextBackend()
245 wxHashTable::compatibility_iterator
246 node
= wxClassInfo::sm_classTable
->Next();
249 wxClassInfo
* classInfo
= (wxClassInfo
*)node
->GetData();
250 if ( classInfo
->IsKindOf(CLASSINFO(wxMediaBackend
)) &&
251 classInfo
!= CLASSINFO(wxMediaBackend
) )
255 node
= wxClassInfo::sm_classTable
->Next();
259 // Nope - couldn't successfully find one... fail
265 //---------------------------------------------------------------------------
266 // wxMediaCtrl Destructor
268 // Free up the backend if it exists
269 //---------------------------------------------------------------------------
270 wxMediaCtrl::~wxMediaCtrl()
276 //---------------------------------------------------------------------------
277 // wxMediaCtrl::Load (file version)
278 // wxMediaCtrl::Load (URL version)
280 // Here we call load of the backend - keeping
281 // track of whether it was successful or not - which
282 // will determine which later method calls work
283 //---------------------------------------------------------------------------
284 bool wxMediaCtrl::Load(const wxString
& fileName
)
287 return (m_bLoaded
= m_imp
->Load(fileName
));
291 bool wxMediaCtrl::Load(const wxURI
& location
)
294 return (m_bLoaded
= m_imp
->Load(location
));
298 //---------------------------------------------------------------------------
300 // wxMediaCtrl::Pause
302 // wxMediaCtrl::GetPlaybackRate
303 // wxMediaCtrl::SetPlaybackRate
304 // wxMediaCtrl::Seek --> SetPosition
305 // wxMediaCtrl::Tell --> GetPosition
306 // wxMediaCtrl::Length --> GetDuration
307 // wxMediaCtrl::GetState
308 // wxMediaCtrl::DoGetBestSize
310 // 1) Check to see whether the backend exists and is loading
311 // 2) Call the backend's version of the method, returning success
312 // if the backend's version succeeds
313 //---------------------------------------------------------------------------
314 bool wxMediaCtrl::Play()
316 if(m_imp
&& m_bLoaded
)
317 return m_imp
->Play();
321 bool wxMediaCtrl::Pause()
323 if(m_imp
&& m_bLoaded
)
324 return m_imp
->Pause();
328 bool wxMediaCtrl::Stop()
330 if(m_imp
&& m_bLoaded
)
331 return m_imp
->Stop();
335 double wxMediaCtrl::GetPlaybackRate()
337 if(m_imp
&& m_bLoaded
)
338 return m_imp
->GetPlaybackRate();
342 bool wxMediaCtrl::SetPlaybackRate(double dRate
)
344 if(m_imp
&& m_bLoaded
)
345 return m_imp
->SetPlaybackRate(dRate
);
349 wxFileOffset
wxMediaCtrl::Seek(wxFileOffset where
, wxSeekMode mode
)
359 offset
= Length() - where
;
361 // case wxFromCurrent:
363 offset
= Tell() + where
;
367 if(m_imp
&& m_bLoaded
&& m_imp
->SetPosition(offset
))
369 return wxInvalidOffset
;
372 wxFileOffset
wxMediaCtrl::Tell()
375 if(m_imp
&& m_bLoaded
)
376 return (wxFileOffset
) m_imp
->GetPosition().ToLong();
377 return wxInvalidOffset
;
380 wxFileOffset
wxMediaCtrl::Length()
383 if(m_imp
&& m_bLoaded
)
384 return (wxFileOffset
) m_imp
->GetDuration().ToLong();
385 return wxInvalidOffset
;
388 wxMediaState
wxMediaCtrl::GetState()
390 if(m_imp
&& m_bLoaded
)
391 return m_imp
->GetState();
392 return wxMEDIASTATE_STOPPED
;
395 wxSize
wxMediaCtrl::DoGetBestSize() const
398 return m_imp
->GetVideoSize();
402 //---------------------------------------------------------------------------
403 // wxMediaCtrl::DoMoveWindow
405 // 1) Call parent's version so that our control's window moves where
407 // 2) If the backend exists and is loaded, move the video
408 // of the media to where our control's window is now located
409 //---------------------------------------------------------------------------
410 void wxMediaCtrl::DoMoveWindow(int x
, int y
, int w
, int h
)
412 wxControl::DoMoveWindow(x
,y
,w
,h
);
415 m_imp
->Move(x
, y
, w
, h
);
418 void wxMediaCtrl::Loop(bool bLoop
)
423 bool wxMediaCtrl::IsLooped()
428 void wxMediaCtrl::OnMediaFinished(wxMediaEvent
& WXUNUSED(evt
))
440 //DARWIN gcc compiler badly screwed up - needs destructor impl in source
441 wxMediaBackend::~wxMediaBackend()
443 #include "wx/html/forcelnk.h"
444 FORCE_LINK(basewxmediabackends
);
446 //---------------------------------------------------------------------------
447 // End of compilation guard and of file
448 //---------------------------------------------------------------------------
449 #endif //wxUSE_MEDIACTRL