]> git.saurik.com Git - wxWidgets.git/blame - utils/wxMMedia2/lib/vidxanm.cpp
fixed bug that caused assertion failure during HTML printing under wxGTK
[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)
b83290c3 63 Stop();
526ddb13
GL
64 delete m_internal;
65
66 wxRemoveFile(m_filename);
4d6306eb
GL
67}
68
b83290c3 69bool wxVideoXANIM::Play()
4d6306eb 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 77
b83290c3
GL
78 // The movie starts with xanim
79 if (RestartXANIM()) {
526ddb13
GL
80 m_paused = FALSE;
81 return TRUE;
4d6306eb 82 }
526ddb13 83 return FALSE;
4d6306eb
GL
84}
85
86bool wxVideoXANIM::Pause()
87{
526ddb13
GL
88 if (!m_paused && SendCommand(" ")) {
89 m_paused = TRUE;
4d6306eb
GL
90 return TRUE;
91 }
92 return FALSE;
93}
94
95bool wxVideoXANIM::Resume()
96{
526ddb13
GL
97 if (m_paused && SendCommand(" ")) {
98 m_paused = FALSE;
4d6306eb
GL
99 return TRUE;
100 }
101 return FALSE;
102}
103
b83290c3 104bool wxVideoXANIM::Stop()
4d6306eb 105{
526ddb13 106 if (!m_xanim_started)
b83290c3 107 return FALSE;
4d6306eb
GL
108
109 SendCommand("q");
110
526ddb13
GL
111 m_xanim_started = FALSE;
112 m_paused = FALSE;
b83290c3
GL
113
114 return TRUE;
4d6306eb
GL
115}
116
117bool wxVideoXANIM::SetVolume(wxUint8 vol)
118{
119 if (vol > 100)
120 vol = 100;
121
122 wxString str_vol("v%d", vol);
123 return SendCommand(str_vol.GetData());
124}
125
126bool wxVideoXANIM::Resize(wxUint16 WXUNUSED(w), wxUint16 WXUNUSED(h))
127{
128 // Not implemented
129 // Actually, I think that we just need to resize the output window ...
130 return FALSE;
131}
132
b83290c3
GL
133bool wxVideoXANIM::GetSize(wxSize& size) const
134{
135 // Not implemented
136 return FALSE;
137}
138
4d6306eb
GL
139bool wxVideoXANIM::IsCapable(wxVideoType v_type)
140{
141 if (v_type == wxVIDEO_MSAVI || v_type == wxVIDEO_MPEG ||
142 v_type == wxVIDEO_QT || v_type == wxVIDEO_GIF || v_type == wxVIDEO_JMOV ||
143 v_type == wxVIDEO_FLI || v_type == wxVIDEO_IFF || v_type == wxVIDEO_SGI)
526ddb13 144 return TRUE;
4d6306eb 145 else
526ddb13 146 return FALSE;
4d6306eb
GL
147}
148
149bool wxVideoXANIM::AttachOutput(wxVideoOutput& out)
150{
151 if (!wxVideoBaseDriver::AttachOutput(out))
526ddb13 152 return FALSE;
4d6306eb 153
b83290c3 154 return TRUE;
4d6306eb
GL
155}
156
157void wxVideoXANIM::DetachOutput()
158{
159 SendCommand("q");
526ddb13
GL
160 m_xanim_started = FALSE;
161 m_paused = FALSE;
4d6306eb
GL
162
163 wxVideoBaseDriver::DetachOutput();
164}
165
166bool wxVideoXANIM::SendCommand(const char *command, char **ret,
167 wxUint32 *size)
168{
526ddb13 169 if (!m_xanim_started)
4d6306eb 170 if (!RestartXANIM())
526ddb13 171 return FALSE;
4d6306eb
GL
172
173 // Send a command to XAnim through X11 Property
526ddb13
GL
174 XChangeProperty(m_internal->xanim_dpy, m_internal->xanim_window,
175 m_internal->xanim_atom,
4d6306eb
GL
176 XA_STRING, 8, PropModeReplace, (unsigned char *)command,
177 strlen(command));
526ddb13 178 XFlush(m_internal->xanim_dpy);
4d6306eb
GL
179 if (ret) {
180 int prop_format;
181 Atom prop_type;
182 unsigned long extra;
183
526ddb13
GL
184 XGetWindowProperty(m_internal->xanim_dpy, m_internal->xanim_window,
185 m_internal->xanim_ret, 0, 16, True, AnyPropertyType,
4d6306eb
GL
186 &prop_type, &prop_format, (unsigned long *)size,
187 &extra, (unsigned char **)ret);
188 }
526ddb13 189 return TRUE;
4d6306eb
GL
190}
191
192bool wxVideoXANIM::RestartXANIM()
193{
194 wxString xanim_command;
195 int ret;
196 Atom prop_type;
197 int prop_format;
198 unsigned long nitems;
199 unsigned long extra;
200 char prop[4];
201 bool xanim_chg_size;
202
526ddb13
GL
203 if (!m_video_output || m_xanim_started)
204 return FALSE;
4d6306eb
GL
205
206 // Check if we can change the size of the window dynamicly
526ddb13 207 xanim_chg_size = m_video_output->DynamicSize();
4d6306eb 208 // Get current display
4d6306eb 209#ifdef __WXGTK__
526ddb13
GL
210 m_internal->xanim_dpy = gdk_display;
211 // We absolutely need the window to be realized.
212 gtk_widget_realize(m_video_output->m_wxwindow);
213 m_internal->xanim_window =
214 ((GdkWindowPrivate *)m_video_output->m_wxwindow->window)->xwindow;
4d6306eb
GL
215#endif
216 // Get the XANIM atom
526ddb13 217 m_internal->xanim_atom = XInternAtom(m_internal->xanim_dpy,
4d6306eb
GL
218 "XANIM_PROPERTY", False);
219
220 // Build the command
526ddb13
GL
221 xanim_command.Printf(_T("xanim -Zr +Ze +Sr +f +W%d +f +q "
222 "+Av70 %s %s"), m_internal->xanim_window,
223 (xanim_chg_size) ? _T("") : _T(""),
224 WXSTRINGCAST m_filename);
225
4d6306eb 226 // Execute it
526ddb13
GL
227 if (!wxExecute(xanim_command, FALSE))
228 return FALSE;
4d6306eb
GL
229
230 // Wait for XAnim to be ready
231 nitems = 0;
232 while (nitems == 0) {
526ddb13
GL
233 ret = XGetWindowProperty(m_internal->xanim_dpy, m_internal->xanim_window,
234 m_internal->xanim_atom,
4d6306eb
GL
235 0, 4, False, AnyPropertyType, &prop_type,
236 &prop_format, &nitems, &extra,
237 (unsigned char **)&prop);
238// wxYield();
239 }
240
b83290c3 241 m_paused = FALSE;
526ddb13 242 m_xanim_started = TRUE;
4d6306eb 243
526ddb13 244 return TRUE;
4d6306eb 245}