]> git.saurik.com Git - wxWidgets.git/blob - utils/wxMMedia/mmfile.cpp
Removed GetSize from wxToolBar95
[wxWidgets.git] / utils / wxMMedia / mmfile.cpp
1 ////////////////////////////////////////////////////////////////////////////////
2 // Name: mmfile.cpp
3 // Purpose: wxMMedia
4 // Author: Guilhem Lavaux
5 // Created: 1997
6 // Updated: 1998
7 // Copyright: (C) 1997, 1998, Guilhem Lavaux
8 // License: wxWindows license
9 ////////////////////////////////////////////////////////////////////////////////
10 #ifdef __GNUG__
11 #pragma implementation
12 #endif
13 #ifdef WX_PRECOMP
14 #include "wx_prec.h"
15 #else
16 #include "wx/wx.h"
17 #endif
18 #include <wx/stream.h>
19 #include <wx/wfstream.h>
20
21 #include "mmfile.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 wxMMediaFile::wxMMediaFile()
28 : m_istream(NULL), m_i_temp(NULL), m_ostream(NULL), m_o_temp(NULL),
29 m_tmpfname((char *)NULL), m_mfname((char *)NULL),
30 m_seekable(FALSE)
31 {
32 }
33
34 wxMMediaFile::wxMMediaFile(wxOutputStream& os, bool seekable)
35 : m_istream(NULL), m_i_temp(NULL), m_ostream(&os), m_o_temp(NULL),
36 m_tmpfname((char *)NULL), m_mfname((char *)NULL),
37 m_seekable(seekable)
38 {
39 }
40
41 wxMMediaFile::wxMMediaFile(wxInputStream& is, bool preload, bool seekable)
42 : m_istream(&is), m_i_temp(NULL), m_ostream(NULL), m_o_temp(NULL),
43 m_tmpfname((char *)NULL), m_mfname((char *)NULL),
44 m_seekable(seekable)
45 {
46 if (preload) {
47 wxStreamBuffer *streamb = new wxStreamBuffer(wxStreamBuffer::read_write);
48
49 streamb->Fixed(FALSE);
50 streamb->Flushable(FALSE);
51
52 m_o_temp = new wxOutputStream(streamb);
53 m_i_temp = new wxInputStream(streamb);
54
55 m_o_temp->Write(is);
56 streamb->ResetBuffer();
57 }
58 }
59
60 wxMMediaFile::wxMMediaFile(const wxString& fname)
61 : m_istream(NULL), m_i_temp(NULL), m_ostream(NULL), m_o_temp(NULL),
62 m_tmpfname((char *)NULL), m_mfname(fname),
63 m_seekable(TRUE)
64 {
65 wxFileStream *s = new wxFileStream(fname);
66
67 m_mfname = fname;
68 m_istream = s;
69 m_ostream = s;
70 }
71
72 void wxMMediaFile::SetFile(wxInputStream& str, bool preload, bool seekable)
73 {
74 CleanUpPrevious();
75 m_istream = &str;
76 m_ostream = NULL;
77 m_seekable = seekable;
78
79 if (preload) {
80 wxStreamBuffer *streamb = new wxStreamBuffer(wxStreamBuffer::read_write);
81
82 streamb->Fixed(FALSE);
83 streamb->Flushable(FALSE);
84
85 m_o_temp = new wxOutputStream(streamb);
86 m_i_temp = new wxInputStream(streamb);
87
88 m_o_temp->Write(str);
89 streamb->ResetBuffer();
90 }
91 }
92
93 void wxMMediaFile::SetFile(wxOutputStream& str, bool seekable)
94 {
95 CleanUpPrevious();
96 m_ostream = &str;
97 m_istream = NULL;
98 m_seekable = seekable;
99 }
100
101 void wxMMediaFile::SetFile(const wxString& fname)
102 {
103 CleanUpPrevious();
104
105 m_mfname = fname;
106 wxFileStream *f = new wxFileStream(fname);
107
108 SetFile(*f, FALSE, TRUE);
109 }
110
111 void wxMMediaFile::CleanUpPrevious()
112 {
113 if (m_i_temp) {
114 m_i_temp->SeekI(0);
115
116 if (m_ostream)
117 m_ostream->Write(*m_i_temp);
118
119 delete (m_i_temp->InputStreamBuffer());
120 delete m_i_temp;
121 delete m_o_temp;
122
123 if (m_tmpfname)
124 wxRemoveFile(m_tmpfname);
125 }
126
127 if (!m_mfname.IsNull() && m_mfname != "")
128 delete m_istream;
129
130 m_i_temp = NULL;
131 m_o_temp = NULL;
132 m_istream = NULL;
133 m_ostream = NULL;
134 }
135
136 wxMMediaFile::~wxMMediaFile()
137 {
138 CleanUpPrevious();
139 }
140
141 wxMMtime wxMMediaFile::GetLength()
142 {
143 wxMMtime mm_time = {-1, 0, 0};
144 return mm_time;
145 }
146
147 wxMMtime wxMMediaFile::GetPosition()
148 {
149 wxMMtime mm_time = {0, 0, 0};
150 return mm_time;
151 }
152
153 wxInputStream *wxMMediaFile::GetIRawData()
154 {
155 if (!m_istream)
156 return NULL;
157
158 if (!m_seekable && !m_i_temp)
159 CacheIO();
160
161 return (m_i_temp) ? m_i_temp : m_istream;
162 }
163
164 wxOutputStream *wxMMediaFile::GetORawData()
165 {
166 if (!m_ostream)
167 return NULL;
168
169 if (!m_seekable && !m_i_temp)
170 CacheIO();
171
172 return (m_o_temp) ? m_o_temp : m_ostream;
173 }
174
175 wxString wxMMediaFile::GetCurrentFile()
176 {
177 if (!m_istream && !m_ostream)
178 return wxString((char *)NULL);
179
180 if (!m_mfname && !m_i_temp)
181 CacheIO();
182
183 return (!m_tmpfname.IsEmpty()) ? m_tmpfname : m_mfname;
184 }
185
186 void wxMMediaFile::CacheIO()
187 {
188 if ((!m_istream && !m_ostream) || m_i_temp)
189 return;
190
191 m_tmpfname = wxGetTempFileName("mmd");
192
193 wxFileStream *tmpstream = new wxFileStream(m_tmpfname);
194 m_i_temp = tmpstream;
195 m_o_temp = tmpstream;
196
197 if (m_istream)
198 tmpstream->wxOutputStream::Write(*m_istream);
199 }