]>
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 // wxMediaBackend Destructor
66 // This is here because the DARWIN gcc compiler badly screwed up and
67 // needs the destructor implementation in the source
68 //---------------------------------------------------------------------------
69 wxMediaBackend::~wxMediaBackend()
73 //---------------------------------------------------------------------------
74 // wxMediaCtrl::Create (file version)
75 // wxMediaCtrl::Create (URL version)
77 // Searches for a backend that is installed on the system (backends
78 // starting with lower characters in the alphabet are given priority),
79 // and creates the control from it
81 // This searches by searching the global RTTI hashtable, class by class,
82 // attempting to call CreateControl on each one found that is a derivative
83 // of wxMediaBackend - if it succeeded Create returns true, otherwise
84 // it keeps iterating through the hashmap.
85 //---------------------------------------------------------------------------
86 bool wxMediaCtrl::Create(wxWindow
* parent
, wxWindowID id
,
87 const wxString
& fileName
,
91 const wxString
& szBackend
,
92 const wxValidator
& validator
,
95 if(!szBackend
.empty())
97 wxClassInfo
* pClassInfo
= wxClassInfo::FindClass(szBackend
);
99 if(!pClassInfo
|| !DoCreate(pClassInfo
, parent
, id
,
100 pos
, size
, style
, validator
, name
))
106 if (!fileName
.empty())
116 SetBestFittingSize(size
);
121 wxClassInfo::sm_classTable
->BeginFind();
123 wxClassInfo
* classInfo
;
125 while((classInfo
= NextBackend()) != NULL
)
127 if(!DoCreate(classInfo
, parent
, id
,
128 pos
, size
, style
, validator
, name
))
131 if (!fileName
.empty())
135 SetBestFittingSize(size
);
143 SetBestFittingSize(size
);
153 bool wxMediaCtrl::Create(wxWindow
* parent
, wxWindowID id
,
154 const wxURI
& location
,
158 const wxString
& szBackend
,
159 const wxValidator
& validator
,
160 const wxString
& name
)
162 if(!szBackend
.empty())
164 wxClassInfo
* pClassInfo
= wxClassInfo::FindClass(szBackend
);
165 if(!pClassInfo
|| !DoCreate(pClassInfo
, parent
, id
,
166 pos
, size
, style
, validator
, name
))
179 SetBestFittingSize(size
);
184 wxClassInfo::sm_classTable
->BeginFind();
186 wxClassInfo
* classInfo
;
188 while((classInfo
= NextBackend()) != NULL
)
190 if(!DoCreate(classInfo
, parent
, id
,
191 pos
, size
, style
, validator
, name
))
196 SetBestFittingSize(size
);
208 //---------------------------------------------------------------------------
209 // wxMediaCtrl::DoCreate
211 // Attempts to create the control from a backend
212 //---------------------------------------------------------------------------
213 bool wxMediaCtrl::DoCreate(wxClassInfo
* classInfo
,
214 wxWindow
* parent
, wxWindowID id
,
218 const wxValidator
& validator
,
219 const wxString
& name
)
221 m_imp
= (wxMediaBackend
*)classInfo
->CreateObject();
223 if( m_imp
->CreateControl(this, parent
, id
, pos
, size
,
224 style
, validator
, name
) )
233 //---------------------------------------------------------------------------
234 // wxMediaCtrl::NextBackend
237 // Search through the RTTI hashmap one at a
238 // time, attempting to create each derivative
242 // STL isn't compatible with and will have a compilation error
243 // on a wxNode, however, wxHashTable::compatibility_iterator is
244 // incompatible with the old 2.4 stable version - but since
245 // we're in 2.5 only we don't need to worry about this
247 //---------------------------------------------------------------------------
248 wxClassInfo
* wxMediaCtrl::NextBackend()
250 wxHashTable::compatibility_iterator
251 node
= wxClassInfo::sm_classTable
->Next();
254 wxClassInfo
* classInfo
= (wxClassInfo
*)node
->GetData();
255 if ( classInfo
->IsKindOf(CLASSINFO(wxMediaBackend
)) &&
256 classInfo
!= CLASSINFO(wxMediaBackend
) )
260 node
= wxClassInfo::sm_classTable
->Next();
264 // Nope - couldn't successfully find one... fail
270 //---------------------------------------------------------------------------
271 // wxMediaCtrl Destructor
273 // Free up the backend if it exists
274 //---------------------------------------------------------------------------
275 wxMediaCtrl::~wxMediaCtrl()
281 //---------------------------------------------------------------------------
282 // wxMediaCtrl::Load (file version)
283 // wxMediaCtrl::Load (URL version)
285 // Here we call load of the backend - keeping
286 // track of whether it was successful or not - which
287 // will determine which later method calls work
288 //---------------------------------------------------------------------------
289 bool wxMediaCtrl::Load(const wxString
& fileName
)
292 return (m_bLoaded
= m_imp
->Load(fileName
));
296 bool wxMediaCtrl::Load(const wxURI
& location
)
299 return (m_bLoaded
= m_imp
->Load(location
));
303 //---------------------------------------------------------------------------
305 // wxMediaCtrl::Pause
307 // wxMediaCtrl::GetPlaybackRate
308 // wxMediaCtrl::SetPlaybackRate
309 // wxMediaCtrl::Seek --> SetPosition
310 // wxMediaCtrl::Tell --> GetPosition
311 // wxMediaCtrl::Length --> GetDuration
312 // wxMediaCtrl::GetState
313 // wxMediaCtrl::DoGetBestSize
315 // 1) Check to see whether the backend exists and is loading
316 // 2) Call the backend's version of the method, returning success
317 // if the backend's version succeeds
318 //---------------------------------------------------------------------------
319 bool wxMediaCtrl::Play()
321 if(m_imp
&& m_bLoaded
)
322 return m_imp
->Play();
326 bool wxMediaCtrl::Pause()
328 if(m_imp
&& m_bLoaded
)
329 return m_imp
->Pause();
333 bool wxMediaCtrl::Stop()
335 if(m_imp
&& m_bLoaded
)
336 return m_imp
->Stop();
340 double wxMediaCtrl::GetPlaybackRate()
342 if(m_imp
&& m_bLoaded
)
343 return m_imp
->GetPlaybackRate();
347 bool wxMediaCtrl::SetPlaybackRate(double dRate
)
349 if(m_imp
&& m_bLoaded
)
350 return m_imp
->SetPlaybackRate(dRate
);
354 wxFileOffset
wxMediaCtrl::Seek(wxFileOffset where
, wxSeekMode mode
)
364 offset
= Length() - where
;
366 // case wxFromCurrent:
368 offset
= Tell() + where
;
372 if(m_imp
&& m_bLoaded
&& m_imp
->SetPosition(offset
))
374 return wxInvalidOffset
;
377 wxFileOffset
wxMediaCtrl::Tell()
379 if(m_imp
&& m_bLoaded
)
380 return (wxFileOffset
) m_imp
->GetPosition().ToLong();
381 return wxInvalidOffset
;
384 wxFileOffset
wxMediaCtrl::Length()
386 if(m_imp
&& m_bLoaded
)
387 return (wxFileOffset
) m_imp
->GetDuration().ToLong();
388 return wxInvalidOffset
;
391 wxMediaState
wxMediaCtrl::GetState()
393 if(m_imp
&& m_bLoaded
)
394 return m_imp
->GetState();
395 return wxMEDIASTATE_STOPPED
;
398 wxSize
wxMediaCtrl::DoGetBestSize() const
401 return m_imp
->GetVideoSize();
405 //---------------------------------------------------------------------------
406 // wxMediaCtrl::DoMoveWindow
408 // 1) Call parent's version so that our control's window moves where
410 // 2) If the backend exists and is loaded, move the video
411 // of the media to where our control's window is now located
412 //---------------------------------------------------------------------------
413 void wxMediaCtrl::DoMoveWindow(int x
, int y
, int w
, int h
)
415 wxControl::DoMoveWindow(x
,y
,w
,h
);
418 m_imp
->Move(x
, y
, w
, h
);
421 #include "wx/html/forcelnk.h"
422 FORCE_LINK(basewxmediabackends
);
424 //---------------------------------------------------------------------------
425 // End of compilation guard and of file
426 //---------------------------------------------------------------------------
427 #endif //wxUSE_MEDIACTRL