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