]> git.saurik.com Git - wxWidgets.git/blob - include/wx/sound.h
changed to behave in same way as native win32 control and generic wxListCtrl when...
[wxWidgets.git] / include / wx / sound.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/sound.h
3 // Purpose: wxSoundBase class
4 // Author: Vaclav Slavik
5 // Modified by:
6 // Created: 2004/02/01
7 // RCS-ID: $Id$
8 // Copyright: (c) 2004, Vaclav Slavik
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_SOUND_H_BASE_
13 #define _WX_SOUND_H_BASE_
14
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "soundbase.h"
17 #endif
18
19 #include "wx/defs.h"
20
21 #if wxUSE_SOUND
22
23 #include "wx/object.h"
24
25 // ----------------------------------------------------------------------------
26 // wxSoundBase: common wxSound code and interface
27 // ----------------------------------------------------------------------------
28
29 // Flags for wxSound::Play
30
31 // NB: We can't use enum because there would be ambiguity between the
32 // two Play() prototypes when called without explicit parameters
33 // if WXWIN_COMPATIBILITY_2_4.
34 // We can't use enum with some compilers either, because they
35 // keep reporting nonexistent ambiguities between
36 // Play(unsigned) and static Play(const wxString&, unsigned).
37 #define wxSOUND_SYNC ((unsigned)0)
38 #define wxSOUND_ASYNC ((unsigned)1)
39 #define wxSOUND_LOOP ((unsigned)2)
40
41 // Base class for wxSound implementations
42 class WXDLLIMPEXP_ADV wxSoundBase : public wxObject
43 {
44 public:
45 // Play the sound:
46 bool Play(unsigned flags = wxSOUND_ASYNC) const
47 {
48 wxASSERT_MSG( (flags & wxSOUND_LOOP) == 0 ||
49 (flags & wxSOUND_ASYNC) != 0,
50 _T("sound can only be looped asynchronously") );
51 return DoPlay(flags);
52 }
53 #if WXWIN_COMPATIBILITY_2_4
54 wxDEPRECATED( bool Play(bool async, bool looped = false) const );
55 #endif
56
57 // Plays sound from filename:
58 static bool Play(const wxString& filename, unsigned flags = wxSOUND_ASYNC);
59
60 protected:
61 virtual bool DoPlay(unsigned flags) const = 0;
62 };
63
64 // ----------------------------------------------------------------------------
65 // wxSound class implementation
66 // ----------------------------------------------------------------------------
67
68 #if defined(__WXMSW__)
69 #include "wx/msw/sound.h"
70 #elif defined(__WXMAC__)
71 #include "wx/mac/sound.h"
72 #elif defined(__WXPM__)
73 #include "wx/os2/sound.h"
74 #elif defined(__UNIX__)
75 #include "wx/unix/sound.h"
76 #endif
77
78 // ----------------------------------------------------------------------------
79 // wxSoundBase methods
80 // ----------------------------------------------------------------------------
81
82 inline bool wxSoundBase::Play(const wxString& filename, unsigned flags)
83 {
84 wxSound snd(filename);
85 return snd.IsOk() ? snd.Play(flags) : false;
86 }
87
88 #if WXWIN_COMPATIBILITY_2_4
89 inline bool wxSoundBase::Play(bool async, bool looped) const
90 {
91 unsigned flags = 0;
92 if (async) flags |= wxSOUND_ASYNC;
93 if (looped) flags |= wxSOUND_LOOP | wxSOUND_ASYNC;
94 return DoPlay(flags);
95 }
96 #endif
97
98 #endif // wxUSE_SOUND
99
100 #endif // _WX_SOUND_H_BASE_