]> git.saurik.com Git - wxWidgets.git/blob - utils/wxMMedia2/lib/vidxanm.cpp
small corrections for dnd code and added wxFileDataObject demo to the sample
[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 Stop();
64 delete m_internal;
65
66 wxRemoveFile(m_filename);
67 }
68
69 bool wxVideoXANIM::Play()
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 // The movie starts with xanim
79 if (RestartXANIM()) {
80 m_paused = FALSE;
81 return TRUE;
82 }
83 return FALSE;
84 }
85
86 bool wxVideoXANIM::Pause()
87 {
88 if (!m_paused && SendCommand(" ")) {
89 m_paused = TRUE;
90 return TRUE;
91 }
92 return FALSE;
93 }
94
95 bool wxVideoXANIM::Resume()
96 {
97 if (m_paused && SendCommand(" ")) {
98 m_paused = FALSE;
99 return TRUE;
100 }
101 return FALSE;
102 }
103
104 bool wxVideoXANIM::Stop()
105 {
106 if (!m_xanim_started)
107 return FALSE;
108
109 SendCommand("q");
110
111 m_xanim_started = FALSE;
112 m_paused = FALSE;
113
114 return TRUE;
115 }
116
117 bool 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
126 bool 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
133 bool wxVideoXANIM::GetSize(wxSize& size) const
134 {
135 // Not implemented
136 return FALSE;
137 }
138
139 bool 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)
144 return TRUE;
145 else
146 return FALSE;
147 }
148
149 bool wxVideoXANIM::AttachOutput(wxVideoOutput& out)
150 {
151 if (!wxVideoBaseDriver::AttachOutput(out))
152 return FALSE;
153
154 return TRUE;
155 }
156
157 void wxVideoXANIM::DetachOutput()
158 {
159 SendCommand("q");
160 m_xanim_started = FALSE;
161 m_paused = FALSE;
162
163 wxVideoBaseDriver::DetachOutput();
164 }
165
166 bool wxVideoXANIM::SendCommand(const char *command, char **ret,
167 wxUint32 *size)
168 {
169 if (!m_xanim_started)
170 if (!RestartXANIM())
171 return FALSE;
172
173 // Send a command to XAnim through X11 Property
174 XChangeProperty(m_internal->xanim_dpy, m_internal->xanim_window,
175 m_internal->xanim_atom,
176 XA_STRING, 8, PropModeReplace, (unsigned char *)command,
177 strlen(command));
178 XFlush(m_internal->xanim_dpy);
179 if (ret) {
180 int prop_format;
181 Atom prop_type;
182 unsigned long extra;
183
184 XGetWindowProperty(m_internal->xanim_dpy, m_internal->xanim_window,
185 m_internal->xanim_ret, 0, 16, True, AnyPropertyType,
186 &prop_type, &prop_format, (unsigned long *)size,
187 &extra, (unsigned char **)ret);
188 }
189 return TRUE;
190 }
191
192 bool 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
203 if (!m_video_output || m_xanim_started)
204 return FALSE;
205
206 // Check if we can change the size of the window dynamicly
207 xanim_chg_size = m_video_output->DynamicSize();
208 // Get current display
209 #ifdef __WXGTK__
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;
215 #endif
216 // Get the XANIM atom
217 m_internal->xanim_atom = XInternAtom(m_internal->xanim_dpy,
218 "XANIM_PROPERTY", False);
219
220 // Build the command
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
226 // Execute it
227 if (!wxExecute(xanim_command, FALSE))
228 return FALSE;
229
230 // Wait for XAnim to be ready
231 nitems = 0;
232 while (nitems == 0) {
233 ret = XGetWindowProperty(m_internal->xanim_dpy, m_internal->xanim_window,
234 m_internal->xanim_atom,
235 0, 4, False, AnyPropertyType, &prop_type,
236 &prop_format, &nitems, &extra,
237 (unsigned char **)&prop);
238 // wxYield();
239 }
240
241 m_paused = FALSE;
242 m_xanim_started = TRUE;
243
244 return TRUE;
245 }