]> git.saurik.com Git - wxWidgets.git/blame - src/os2/sound.cpp
Remove DoSetSizeHints() call from Create()
[wxWidgets.git] / src / os2 / sound.cpp
CommitLineData
0e320a79 1/////////////////////////////////////////////////////////////////////////////
80fdcdb9 2// Name: src/os2/sound.cpp
315ebf68 3// Purpose: wxSound class implementation: optional
d90895ac 4// Author: David Webster
0e320a79 5// Modified by:
d90895ac 6// Created: 10/17/99
d90895ac 7// Copyright: (c) David Webster
65571936 8// Licence: wxWindows licence
0e320a79
DW
9/////////////////////////////////////////////////////////////////////////////
10
d90895ac
DW
11// For compilers that support precompilation, includes "wx.h".
12#include "wx/wxprec.h"
13
14#ifndef WX_PRECOMP
15#include "wx/wx.h"
0e320a79
DW
16#endif
17
d90895ac 18#include "wx/file.h"
315ebf68 19#include "wx/sound.h"
9dea36ef
DW
20#define INCL_32 /* force 32 bit compile */
21#define INCL_GPIBITMAPS
22#define INCL_DOSFILEMGR
23#define INCL_WIN
24#define INCL_GPI
7e99520b 25#define INCL_PM
9dea36ef
DW
26#include <os2.h>
27#include <stdio.h>
28#include <string.h>
29#include <stdlib.h>
30#include <os2medef.h>
31#include <mmioos2.h>
0e320a79 32
315ebf68 33wxSound::wxSound()
0e320a79
DW
34 : m_waveData(NULL), m_waveLength(0), m_isResource(FALSE)
35{
36}
37
315ebf68 38wxSound::wxSound(const wxString& sFileName, bool isResource)
d90895ac 39 : m_waveData(NULL), m_waveLength(0), m_isResource(isResource)
0e320a79 40{
d90895ac 41 Create(sFileName, isResource);
0e320a79
DW
42}
43
c559c4b3 44wxSound::wxSound(size_t size, const void* data)
d90895ac
DW
45 : m_waveData(NULL), m_waveLength(0), m_isResource(FALSE)
46{
47 Create(size, data);
48}
0e320a79 49
315ebf68 50wxSound::~wxSound()
0e320a79 51{
d90895ac 52 Free();
0e320a79
DW
53}
54
315ebf68 55bool wxSound::Create(const wxString& fileName, bool isResource)
0e320a79 56{
d90895ac 57 Free();
0e320a79 58
d90895ac
DW
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 }
0e320a79 80
d90895ac
DW
81 return (m_waveData ? TRUE : FALSE);
82*/
0e320a79 83 return FALSE;
d90895ac
DW
84 }
85 else
86 {
87 m_isResource = FALSE;
7e99520b 88#if wxUSE_FILE
d90895ac
DW
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;
7e99520b
DW
104#else
105 return FALSE;
106#endif //wxUSE_FILE
d90895ac 107 }
0e320a79
DW
108}
109
c559c4b3 110bool wxSound::Create(size_t size, const void* data)
0e320a79 111{
d90895ac
DW
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;
0e320a79 118
c559c4b3 119 memcpy(m_waveData, data, size);
d90895ac 120 return TRUE;
0e320a79
DW
121}
122
6670f564 123bool wxSound::DoPlay(unsigned WXUNUSED(flags)) const
0e320a79 124{
6670f564
WS
125 if (!IsOk())
126 return false;
127
d90895ac
DW
128// TODO:
129/*
6670f564
WS
130 return ( ::PlaySound((LPCTSTR)m_waveData, NULL, SND_MEMORY |
131 SND_NODEFAULT | (async ? SND_ASYNC : SND_SYNC) | (looped ? (SND_LOOP | SND_ASYNC) : 0)) != 0 );
d90895ac 132*/
6670f564 133 return false;
0e320a79
DW
134}
135
315ebf68 136bool wxSound::Free()
d90895ac 137{
6670f564
WS
138 if (m_waveData)
139 {
d90895ac
DW
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*/
6670f564
WS
159 }
160 return false;
d90895ac 161}