]>
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
;
113 while((classInfo
= NextBackend()) != NULL
)
115 if(!DoCreate(classInfo
, parent
, id
,
116 pos
, size
, style
, validator
, name
))
119 if (!fileName
.empty())
123 SetBestFittingSize(size
);
131 SetBestFittingSize(size
);
141 bool wxMediaCtrl::Create(wxWindow
* parent
, wxWindowID id
,
142 const wxURI
& location
,
146 const wxString
& szBackend
,
147 const wxValidator
& validator
,
148 const wxString
& name
)
150 if(!szBackend
.empty())
152 if(!DoCreate(wxClassInfo::FindClass(szBackend
), parent
, id
,
153 pos
, size
, style
, validator
, name
))
166 SetBestFittingSize(size
);
171 wxClassInfo::sm_classTable
->BeginFind();
173 wxClassInfo
* classInfo
;
175 while((classInfo
= NextBackend()) != NULL
)
177 if(!DoCreate(classInfo
, parent
, id
,
178 pos
, size
, style
, validator
, name
))
183 SetBestFittingSize(size
);
195 //---------------------------------------------------------------------------
196 // wxMediaCtrl::DoCreate
198 // Attempts to create the control from a backend
199 //---------------------------------------------------------------------------
200 bool wxMediaCtrl::DoCreate(wxClassInfo
* classInfo
,
201 wxWindow
* parent
, wxWindowID id
,
205 const wxValidator
& validator
,
206 const wxString
& name
)
208 m_imp
= (wxMediaBackend
*)classInfo
->CreateObject();
210 if( m_imp
->CreateControl(this, parent
, id
, pos
, size
,
211 style
, validator
, name
) )
220 //---------------------------------------------------------------------------
221 // wxMediaCtrl::NextBackend
224 // Search through the RTTI hashmap one at a
225 // time, attempting to create each derivative
229 // STL isn't compatable with and will have a compilation error
230 // on a wxNode, however, wxHashTable::compatibility_iterator is
231 // incompatible with the old 2.4 stable version - but since
232 // we're in 2.5 only we don't need to worry about this
234 //---------------------------------------------------------------------------
235 wxClassInfo
* wxMediaCtrl::NextBackend()
237 wxHashTable::compatibility_iterator
238 node
= wxClassInfo::sm_classTable
->Next();
241 wxClassInfo
* classInfo
= (wxClassInfo
*)node
->GetData();
242 if ( classInfo
->IsKindOf(CLASSINFO(wxMediaBackend
)) &&
243 classInfo
!= CLASSINFO(wxMediaBackend
) )
247 node
= wxClassInfo::sm_classTable
->Next();
251 // Nope - couldn't successfully find one... fail
257 //---------------------------------------------------------------------------
258 // wxMediaCtrl Destructor
260 // Free up the backend if it exists
261 //---------------------------------------------------------------------------
262 wxMediaCtrl::~wxMediaCtrl()
268 //---------------------------------------------------------------------------
269 // wxMediaCtrl::Load (file version)
270 // wxMediaCtrl::Load (URL version)
272 // Here we call load of the backend - keeping
273 // track of whether it was successful or not - which
274 // will determine which later method calls work
275 //---------------------------------------------------------------------------
276 bool wxMediaCtrl::Load(const wxString
& fileName
)
279 return (m_bLoaded
= m_imp
->Load(fileName
));
283 bool wxMediaCtrl::Load(const wxURI
& location
)
286 return (m_bLoaded
= m_imp
->Load(location
));
290 //---------------------------------------------------------------------------
292 // wxMediaCtrl::Pause
294 // wxMediaCtrl::GetPlaybackRate
295 // wxMediaCtrl::SetPlaybackRate
296 // wxMediaCtrl::Seek --> SetPosition
297 // wxMediaCtrl::Tell --> GetPosition
298 // wxMediaCtrl::Length --> GetDuration
299 // wxMediaCtrl::GetState
300 // wxMediaCtrl::DoGetBestSize
302 // 1) Check to see whether the backend exists and is loading
303 // 2) Call the backend's version of the method, returning success
304 // if the backend's version succeeds
305 //---------------------------------------------------------------------------
306 bool wxMediaCtrl::Play()
308 if(m_imp
&& m_bLoaded
)
309 return m_imp
->Play();
313 bool wxMediaCtrl::Pause()
315 if(m_imp
&& m_bLoaded
)
316 return m_imp
->Pause();
320 bool wxMediaCtrl::Stop()
322 if(m_imp
&& m_bLoaded
)
323 return m_imp
->Stop();
327 double wxMediaCtrl::GetPlaybackRate()
329 if(m_imp
&& m_bLoaded
)
330 return m_imp
->GetPlaybackRate();
334 bool wxMediaCtrl::SetPlaybackRate(double dRate
)
336 if(m_imp
&& m_bLoaded
)
337 return m_imp
->SetPlaybackRate(dRate
);
341 wxFileOffset
wxMediaCtrl::Seek(wxFileOffset where
, wxSeekMode mode
)
351 offset
= Length() - where
;
353 // case wxFromCurrent:
355 offset
= Tell() + where
;
359 if(m_imp
&& m_bLoaded
&& m_imp
->SetPosition(offset
))
361 return wxInvalidOffset
;
364 wxFileOffset
wxMediaCtrl::Tell()
367 if(m_imp
&& m_bLoaded
)
368 return (wxFileOffset
) m_imp
->GetPosition().ToLong();
369 return wxInvalidOffset
;
372 wxFileOffset
wxMediaCtrl::Length()
375 if(m_imp
&& m_bLoaded
)
376 return (wxFileOffset
) m_imp
->GetDuration().ToLong();
377 return wxInvalidOffset
;
380 wxMediaState
wxMediaCtrl::GetState()
382 if(m_imp
&& m_bLoaded
)
383 return m_imp
->GetState();
384 return wxMEDIASTATE_STOPPED
;
387 wxSize
wxMediaCtrl::DoGetBestSize() const
390 return m_imp
->GetVideoSize();
394 //---------------------------------------------------------------------------
395 // wxMediaCtrl::DoMoveWindow
397 // 1) Call parent's version so that our control's window moves where
399 // 2) If the backend exists and is loaded, move the video
400 // of the media to where our control's window is now located
401 //---------------------------------------------------------------------------
402 void wxMediaCtrl::DoMoveWindow(int x
, int y
, int w
, int h
)
404 wxControl::DoMoveWindow(x
,y
,w
,h
);
407 m_imp
->Move(x
, y
, w
, h
);
410 //DARWIN gcc compiler badly screwed up - needs destructor impl in source
411 wxMediaBackend::~wxMediaBackend()
413 #include "wx/html/forcelnk.h"
414 FORCE_LINK(basewxmediabackends
);
416 //---------------------------------------------------------------------------
417 // End of compilation guard and of file
418 //---------------------------------------------------------------------------
419 #endif //wxUSE_MEDIACTRL