]> git.saurik.com Git - wxWidgets.git/blob - src/os2/sound.cpp
Fix wxHtmlHelpData::SetTempDir() to behave correctly without trailing slash.
[wxWidgets.git] / src / os2 / sound.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/sound.cpp
3 // Purpose: wxSound class implementation: optional
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/17/99
7 // Copyright: (c) David Webster
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
13
14 #ifndef WX_PRECOMP
15 #include "wx/wx.h"
16 #endif
17
18 #include "wx/file.h"
19 #include "wx/sound.h"
20 #define INCL_32 /* force 32 bit compile */
21 #define INCL_GPIBITMAPS
22 #define INCL_DOSFILEMGR
23 #define INCL_WIN
24 #define INCL_GPI
25 #define INCL_PM
26 #include <os2.h>
27 #include <stdio.h>
28 #include <string.h>
29 #include <stdlib.h>
30 #include <os2medef.h>
31 #include <mmioos2.h>
32
33 wxSound::wxSound()
34 : m_waveData(NULL), m_waveLength(0), m_isResource(FALSE)
35 {
36 }
37
38 wxSound::wxSound(const wxString& sFileName, bool isResource)
39 : m_waveData(NULL), m_waveLength(0), m_isResource(isResource)
40 {
41 Create(sFileName, isResource);
42 }
43
44 wxSound::wxSound(size_t size, const void* data)
45 : m_waveData(NULL), m_waveLength(0), m_isResource(FALSE)
46 {
47 Create(size, data);
48 }
49
50 wxSound::~wxSound()
51 {
52 Free();
53 }
54
55 bool wxSound::Create(const wxString& fileName, bool isResource)
56 {
57 Free();
58
59 if (isResource)
60 {
61 m_isResource = TRUE;
62 // TODO:
63 /*
64 HRSRC hresInfo;
65 #ifdef _UNICODE
66 hresInfo = ::FindResourceW((HMODULE) wxhInstance, fileName, wxT("WAVE"));
67 #else
68 hresInfo = ::FindResourceA((HMODULE) wxhInstance, fileName, wxT("WAVE"));
69 #endif
70 if (!hresInfo)
71 return FALSE;
72
73 HGLOBAL waveData = ::LoadResource((HMODULE) wxhInstance, hresInfo);
74
75 if (waveData)
76 {
77 m_waveData= (wxByte*)::LockResource(waveData);
78 m_waveLength = (int) ::SizeofResource((HMODULE) wxhInstance, hresInfo);
79 }
80
81 return (m_waveData ? TRUE : FALSE);
82 */
83 return FALSE;
84 }
85 else
86 {
87 m_isResource = FALSE;
88 #if wxUSE_FILE
89
90 wxFile fileWave;
91 if (!fileWave.Open(fileName, wxFile::read))
92 return FALSE;
93
94 m_waveLength = (int) fileWave.Length();
95 // TODO:
96 /*
97 m_waveData = (wxByte*)::GlobalLock(::GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, m_waveLength));
98 if (!m_waveData)
99 return FALSE;
100
101 fileWave.Read(m_waveData, m_waveLength);
102 */
103 return TRUE;
104 #else
105 return FALSE;
106 #endif //wxUSE_FILE
107 }
108 }
109
110 bool wxSound::Create(size_t size, const void* data)
111 {
112 Free();
113 m_isResource = FALSE;
114 m_waveLength=size;
115 m_waveData = NULL; // (wxByte*)::GlobalLock(::GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, m_waveLength));
116 if (!m_waveData)
117 return FALSE;
118
119 memcpy(m_waveData, data, size);
120 return TRUE;
121 }
122
123 bool wxSound::DoPlay(unsigned WXUNUSED(flags)) const
124 {
125 if (!IsOk())
126 return false;
127
128 // TODO:
129 /*
130 return ( ::PlaySound((LPCTSTR)m_waveData, NULL, SND_MEMORY |
131 SND_NODEFAULT | (async ? SND_ASYNC : SND_SYNC) | (looped ? (SND_LOOP | SND_ASYNC) : 0)) != 0 );
132 */
133 return false;
134 }
135
136 bool wxSound::Free()
137 {
138 if (m_waveData)
139 {
140 // HGLOBAL waveData = ::GlobalHandle(m_waveData);
141
142 // TODO:
143 /*
144 if (waveData)
145 {
146 if (m_isResource)
147 ::FreeResource(waveData);
148 else
149 {
150 ::GlobalUnlock(waveData);
151 ::GlobalFree(waveData);
152 }
153
154 m_waveData = NULL;
155 m_waveLength = 0;
156 return TRUE;
157 }
158 */
159 }
160 return false;
161 }