]> git.saurik.com Git - wxWidgets.git/blob - utils/wxMMedia2/lib/vidxanm.cpp
Removed wxMMedia
[wxWidgets.git] / utils / wxMMedia2 / lib / vidxanm.cpp
1 ////////////////////////////////////////////////////////////////////////////////
2 // Name: vidxanm.cpp
3 // Purpose: wxMMedia
4 // Author: Guilhem Lavaux
5 // Created: 1997
6 // Updated: 1998
7 // Copyright: (C) 1997, 1998, 1999 Guilhem Lavaux
8 // License: wxWindows license
9 ////////////////////////////////////////////////////////////////////////////////
10 #ifdef __GNUG__
11 #pragma implementation "vidxanm.h"
12 #endif
13 #ifdef WX_PRECOMP
14 #include <wx_prec.h>
15 #else
16 #include <wx/wx.h>
17 #endif
18 #include <X11/Xlib.h>
19 #include <X11/Intrinsic.h>
20 #ifdef __WXGTK__
21 #include <gtk/gtkwidget.h>
22 #include <gtk/gtkwindow.h>
23 #include <gdk/gdk.h>
24 #include <gdk/gdkprivate.h>
25 #endif
26
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
35 IMPLEMENT_DYNAMIC_CLASS(wxVideoXANIM, wxVideoBaseDriver)
36 #endif
37
38 wxVideoXANIM::wxVideoXANIM()
39 : wxVideoBaseDriver()
40 {
41 m_internal = new wxXANIMinternal;
42 m_xanim_started = FALSE;
43 m_paused = FALSE;
44 m_filename = "";
45 }
46
47 wxVideoXANIM::wxVideoXANIM(wxInputStream& str)
48 : wxVideoBaseDriver(str)
49 {
50 m_internal = new wxXANIMinternal;
51 m_xanim_started = FALSE;
52 m_paused = FALSE;
53
54 m_filename = wxGetTempFileName("vidxa");
55 wxFileOutputStream fout(m_filename);
56
57 fout << str;
58 }
59
60 wxVideoXANIM::~wxVideoXANIM()
61 {
62 if (m_xanim_started)
63 StopPlay();
64 delete m_internal;
65
66 wxRemoveFile(m_filename);
67 }
68
69 bool wxVideoXANIM::StartPlay()
70 {
71 if (!m_paused && m_xanim_started)
72 return TRUE;
73 if (!m_video_output) {
74 wxVideoCreateFrame(this);
75 return TRUE;
76 }
77
78 if (SendCommand(" ")) {
79 m_paused = FALSE;
80 return TRUE;
81 }
82 return FALSE;
83 }
84
85 bool wxVideoXANIM::Pause()
86 {
87 if (!m_paused && SendCommand(" ")) {
88 m_paused = TRUE;
89 return TRUE;
90 }
91 return FALSE;
92 }
93
94 bool wxVideoXANIM::Resume()
95 {
96 if (m_paused && SendCommand(" ")) {
97 m_paused = FALSE;
98 return TRUE;
99 }
100 return FALSE;
101 }
102
103 void wxVideoXANIM::StopPlay()
104 {
105 if (!m_xanim_started)
106 return;
107
108 SendCommand("q");
109
110 m_xanim_started = FALSE;
111 m_paused = FALSE;
112 }
113
114 bool 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
123 bool 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
130 bool 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)
135 return TRUE;
136 else
137 return FALSE;
138 }
139
140 bool wxVideoXANIM::AttachOutput(wxVideoOutput& out)
141 {
142 if (!wxVideoBaseDriver::AttachOutput(out))
143 return FALSE;
144
145 return RestartXANIM();
146 }
147
148 void wxVideoXANIM::DetachOutput()
149 {
150 SendCommand("q");
151 m_xanim_started = FALSE;
152 m_paused = FALSE;
153
154 wxVideoBaseDriver::DetachOutput();
155 }
156
157 bool wxVideoXANIM::SendCommand(const char *command, char **ret,
158 wxUint32 *size)
159 {
160 if (!m_xanim_started)
161 if (!RestartXANIM())
162 return FALSE;
163
164 // Send a command to XAnim through X11 Property
165 XChangeProperty(m_internal->xanim_dpy, m_internal->xanim_window,
166 m_internal->xanim_atom,
167 XA_STRING, 8, PropModeReplace, (unsigned char *)command,
168 strlen(command));
169 XFlush(m_internal->xanim_dpy);
170 if (ret) {
171 int prop_format;
172 Atom prop_type;
173 unsigned long extra;
174
175 XGetWindowProperty(m_internal->xanim_dpy, m_internal->xanim_window,
176 m_internal->xanim_ret, 0, 16, True, AnyPropertyType,
177 &prop_type, &prop_format, (unsigned long *)size,
178 &extra, (unsigned char **)ret);
179 }
180 return TRUE;
181 }
182
183 bool 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
194 if (!m_video_output || m_xanim_started)
195 return FALSE;
196
197 // Check if we can change the size of the window dynamicly
198 xanim_chg_size = m_video_output->DynamicSize();
199 // Get current display
200 #ifdef __WXGTK__
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;
206 #endif
207 // Get the XANIM atom
208 m_internal->xanim_atom = XInternAtom(m_internal->xanim_dpy,
209 "XANIM_PROPERTY", False);
210
211 // Build the command
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
217 // Execute it
218 if (!wxExecute(xanim_command, FALSE))
219 return FALSE;
220
221 // Wait for XAnim to be ready
222 nitems = 0;
223 while (nitems == 0) {
224 ret = XGetWindowProperty(m_internal->xanim_dpy, m_internal->xanim_window,
225 m_internal->xanim_atom,
226 0, 4, False, AnyPropertyType, &prop_type,
227 &prop_format, &nitems, &extra,
228 (unsigned char **)&prop);
229 // wxYield();
230 }
231
232 // m_paused = TRUE;
233 m_xanim_started = TRUE;
234
235 return TRUE;
236 }