]> git.saurik.com Git - wxWidgets.git/blame - utils/wxMMedia2/lib/vidxanm.cpp
makefile typo
[wxWidgets.git] / utils / wxMMedia2 / lib / vidxanm.cpp
CommitLineData
4d6306eb
GL
1////////////////////////////////////////////////////////////////////////////////
2// Name: vidxanm.cpp
3// Purpose: wxMMedia
4// Author: Guilhem Lavaux
5// Created: 1997
6// Updated: 1998
526ddb13 7// Copyright: (C) 1997, 1998, 1999 Guilhem Lavaux
4d6306eb
GL
8// License: wxWindows license
9////////////////////////////////////////////////////////////////////////////////
10#ifdef __GNUG__
11#pragma implementation "vidxanm.h"
12#endif
4d6306eb 13#ifdef WX_PRECOMP
526ddb13 14#include <wx_prec.h>
4d6306eb 15#else
526ddb13 16#include <wx/wx.h>
4d6306eb
GL
17#endif
18#include <X11/Xlib.h>
19#include <X11/Intrinsic.h>
20#ifdef __WXGTK__
8a7c9dcc 21#include <gtk/gtkwidget.h>
526ddb13 22#include <gtk/gtkwindow.h>
4d6306eb
GL
23#include <gdk/gdk.h>
24#include <gdk/gdkprivate.h>
25#endif
26
526ddb13
GL
27#include <wx/filefn.h>
28#include <wx/wfstream.h>
29
30#define WXMMEDIA_INTERNAL
31#include "vidbase.h"
32#include "vidxanm.h"
33
34#if !USE_SHARED_LIBRARY
35IMPLEMENT_DYNAMIC_CLASS(wxVideoXANIM, wxVideoBaseDriver)
36#endif
37
4d6306eb
GL
38wxVideoXANIM::wxVideoXANIM()
39 : wxVideoBaseDriver()
40{
526ddb13
GL
41 m_internal = new wxXANIMinternal;
42 m_xanim_started = FALSE;
43 m_paused = FALSE;
44 m_filename = "";
4d6306eb
GL
45}
46
47wxVideoXANIM::wxVideoXANIM(wxInputStream& str)
526ddb13 48 : wxVideoBaseDriver(str)
4d6306eb 49{
526ddb13
GL
50 m_internal = new wxXANIMinternal;
51 m_xanim_started = FALSE;
52 m_paused = FALSE;
4d6306eb 53
526ddb13
GL
54 m_filename = wxGetTempFileName("vidxa");
55 wxFileOutputStream fout(m_filename);
56
57 fout << str;
4d6306eb
GL
58}
59
60wxVideoXANIM::~wxVideoXANIM()
61{
526ddb13 62 if (m_xanim_started)
4d6306eb 63 StopPlay();
526ddb13
GL
64 delete m_internal;
65
66 wxRemoveFile(m_filename);
4d6306eb
GL
67}
68
69bool wxVideoXANIM::StartPlay()
70{
526ddb13
GL
71 if (!m_paused && m_xanim_started)
72 return TRUE;
73 if (!m_video_output) {
4d6306eb 74 wxVideoCreateFrame(this);
526ddb13
GL
75 return TRUE;
76 }
4d6306eb
GL
77
78 if (SendCommand(" ")) {
526ddb13
GL
79 m_paused = FALSE;
80 return TRUE;
4d6306eb 81 }
526ddb13 82 return FALSE;
4d6306eb
GL
83}
84
85bool wxVideoXANIM::Pause()
86{
526ddb13
GL
87 if (!m_paused && SendCommand(" ")) {
88 m_paused = TRUE;
4d6306eb
GL
89 return TRUE;
90 }
91 return FALSE;
92}
93
94bool wxVideoXANIM::Resume()
95{
526ddb13
GL
96 if (m_paused && SendCommand(" ")) {
97 m_paused = FALSE;
4d6306eb
GL
98 return TRUE;
99 }
100 return FALSE;
101}
102
103void wxVideoXANIM::StopPlay()
104{
526ddb13 105 if (!m_xanim_started)
4d6306eb
GL
106 return;
107
108 SendCommand("q");
109
526ddb13
GL
110 m_xanim_started = FALSE;
111 m_paused = FALSE;
4d6306eb
GL
112}
113
114bool wxVideoXANIM::SetVolume(wxUint8 vol)
115{
116 if (vol > 100)
117 vol = 100;
118
119 wxString str_vol("v%d", vol);
120 return SendCommand(str_vol.GetData());
121}
122
123bool wxVideoXANIM::Resize(wxUint16 WXUNUSED(w), wxUint16 WXUNUSED(h))
124{
125 // Not implemented
126 // Actually, I think that we just need to resize the output window ...
127 return FALSE;
128}
129
130bool wxVideoXANIM::IsCapable(wxVideoType v_type)
131{
132 if (v_type == wxVIDEO_MSAVI || v_type == wxVIDEO_MPEG ||
133 v_type == wxVIDEO_QT || v_type == wxVIDEO_GIF || v_type == wxVIDEO_JMOV ||
134 v_type == wxVIDEO_FLI || v_type == wxVIDEO_IFF || v_type == wxVIDEO_SGI)
526ddb13 135 return TRUE;
4d6306eb 136 else
526ddb13 137 return FALSE;
4d6306eb
GL
138}
139
140bool wxVideoXANIM::AttachOutput(wxVideoOutput& out)
141{
142 if (!wxVideoBaseDriver::AttachOutput(out))
526ddb13 143 return FALSE;
4d6306eb
GL
144
145 return RestartXANIM();
146}
147
148void wxVideoXANIM::DetachOutput()
149{
150 SendCommand("q");
526ddb13
GL
151 m_xanim_started = FALSE;
152 m_paused = FALSE;
4d6306eb
GL
153
154 wxVideoBaseDriver::DetachOutput();
155}
156
157bool wxVideoXANIM::SendCommand(const char *command, char **ret,
158 wxUint32 *size)
159{
526ddb13 160 if (!m_xanim_started)
4d6306eb 161 if (!RestartXANIM())
526ddb13 162 return FALSE;
4d6306eb
GL
163
164 // Send a command to XAnim through X11 Property
526ddb13
GL
165 XChangeProperty(m_internal->xanim_dpy, m_internal->xanim_window,
166 m_internal->xanim_atom,
4d6306eb
GL
167 XA_STRING, 8, PropModeReplace, (unsigned char *)command,
168 strlen(command));
526ddb13 169 XFlush(m_internal->xanim_dpy);
4d6306eb
GL
170 if (ret) {
171 int prop_format;
172 Atom prop_type;
173 unsigned long extra;
174
526ddb13
GL
175 XGetWindowProperty(m_internal->xanim_dpy, m_internal->xanim_window,
176 m_internal->xanim_ret, 0, 16, True, AnyPropertyType,
4d6306eb
GL
177 &prop_type, &prop_format, (unsigned long *)size,
178 &extra, (unsigned char **)ret);
179 }
526ddb13 180 return TRUE;
4d6306eb
GL
181}
182
183bool wxVideoXANIM::RestartXANIM()
184{
185 wxString xanim_command;
186 int ret;
187 Atom prop_type;
188 int prop_format;
189 unsigned long nitems;
190 unsigned long extra;
191 char prop[4];
192 bool xanim_chg_size;
193
526ddb13
GL
194 if (!m_video_output || m_xanim_started)
195 return FALSE;
4d6306eb
GL
196
197 // Check if we can change the size of the window dynamicly
526ddb13 198 xanim_chg_size = m_video_output->DynamicSize();
4d6306eb 199 // Get current display
4d6306eb 200#ifdef __WXGTK__
526ddb13
GL
201 m_internal->xanim_dpy = gdk_display;
202 // We absolutely need the window to be realized.
203 gtk_widget_realize(m_video_output->m_wxwindow);
204 m_internal->xanim_window =
205 ((GdkWindowPrivate *)m_video_output->m_wxwindow->window)->xwindow;
4d6306eb
GL
206#endif
207 // Get the XANIM atom
526ddb13 208 m_internal->xanim_atom = XInternAtom(m_internal->xanim_dpy,
4d6306eb
GL
209 "XANIM_PROPERTY", False);
210
211 // Build the command
526ddb13
GL
212 xanim_command.Printf(_T("xanim -Zr +Ze +Sr +f +W%d +f +q "
213 "+Av70 %s %s"), m_internal->xanim_window,
214 (xanim_chg_size) ? _T("") : _T(""),
215 WXSTRINGCAST m_filename);
216
4d6306eb 217 // Execute it
526ddb13
GL
218 if (!wxExecute(xanim_command, FALSE))
219 return FALSE;
4d6306eb
GL
220
221 // Wait for XAnim to be ready
222 nitems = 0;
223 while (nitems == 0) {
526ddb13
GL
224 ret = XGetWindowProperty(m_internal->xanim_dpy, m_internal->xanim_window,
225 m_internal->xanim_atom,
4d6306eb
GL
226 0, 4, False, AnyPropertyType, &prop_type,
227 &prop_format, &nitems, &extra,
228 (unsigned char **)&prop);
229// wxYield();
230 }
231
526ddb13
GL
232// m_paused = TRUE;
233 m_xanim_started = TRUE;
4d6306eb 234
526ddb13 235 return TRUE;
4d6306eb 236}