1 | /* -*- tab-width: 8; c-basic-offset: 4 -*- */
|
---|
2 | /*
|
---|
3 | * Animation control
|
---|
4 | *
|
---|
5 | * Copyright 1998, 1999 Eric Kohl
|
---|
6 | * 1999 Eric Pouech
|
---|
7 | *
|
---|
8 | * NOTES
|
---|
9 | * I will only improve this control once in a while.
|
---|
10 | * Eric <ekohl@abo.rhein-zeitung.de>
|
---|
11 | *
|
---|
12 | * TODO:
|
---|
13 | * - check for the 'rec ' list in some AVI files
|
---|
14 | * - concurrent access to infoPtr
|
---|
15 | */
|
---|
16 |
|
---|
17 |
|
---|
18 | #include "winbase.h"
|
---|
19 | #include "commctrl.h"
|
---|
20 | #include "vfw.h"
|
---|
21 | #include "mmsystem.h"
|
---|
22 | #include "services.h"
|
---|
23 | #include "debugtools.h"
|
---|
24 | #ifdef __WIN32OS2__
|
---|
25 | #include "ccbase.h"
|
---|
26 | #endif
|
---|
27 |
|
---|
28 | DEFAULT_DEBUG_CHANNEL(animate);
|
---|
29 |
|
---|
30 | typedef struct
|
---|
31 | {
|
---|
32 | #ifdef __WIN32OS2__
|
---|
33 | COMCTL32_HEADER header;
|
---|
34 | #endif
|
---|
35 |
|
---|
36 | /* pointer to msvideo functions. it's easier to put them here.
|
---|
37 | * to be correct, they should be defined on a per process basis, but
|
---|
38 | * this would required a per process storage. We're using a per object
|
---|
39 | * storage instead, which is not efficient on memory usage, but
|
---|
40 | * will lead to less bugs in the future
|
---|
41 | */
|
---|
42 | #ifdef __WIN32OS2__
|
---|
43 | HIC (* WINAPI fnICOpen)(DWORD, DWORD, UINT);
|
---|
44 | LRESULT (* WINAPI fnICClose)(HIC);
|
---|
45 | LRESULT (* WINAPI fnICSendMessage)(HIC, UINT, DWORD, DWORD);
|
---|
46 | DWORD (* WINAPIV fnICDecompress)(HIC,DWORD,LPBITMAPINFOHEADER,LPVOID,LPBITMAPINFOHEADER,LPVOID);
|
---|
47 |
|
---|
48 | HMMIO (* WINAPI fnmmioOpenA)(LPSTR,MMIOINFO*,DWORD);
|
---|
49 | HMMIO (* WINAPI fnmmioOpenW)(LPSTR,MMIOINFO*,DWORD);
|
---|
50 | MMRESULT (* WINAPI fnmmioClose)(HMMIO,UINT);
|
---|
51 | UINT (* WINAPI fnmmioAscend)(HMMIO,MMCKINFO*,UINT);
|
---|
52 | UINT (* WINAPI fnmmioDescend)(HMMIO,MMCKINFO*,const MMCKINFO*,UINT);
|
---|
53 | LONG (* WINAPI fnmmioSeek)(HMMIO,LONG,INT);
|
---|
54 | LONG (* WINAPI fnmmioRead)(HMMIO,HPSTR,LONG);
|
---|
55 | #else
|
---|
56 | HIC WINAPI (*fnICOpen)(DWORD, DWORD, UINT);
|
---|
57 | LRESULT WINAPI (*fnICClose)(HIC);
|
---|
58 | LRESULT WINAPI (*fnICSendMessage)(HIC, UINT, DWORD, DWORD);
|
---|
59 | DWORD WINAPIV (*fnICDecompress)(HIC,DWORD,LPBITMAPINFOHEADER,LPVOID,LPBITMAPINFOHEADER,LPVOID);
|
---|
60 |
|
---|
61 | HMMIO WINAPI (*fnmmioOpenA)(LPSTR,MMIOINFO*,DWORD);
|
---|
62 | MMRESULT WINAPI (*fnmmioClose)(HMMIO,UINT);
|
---|
63 | UINT WINAPI (*fnmmioAscend)(HMMIO,MMCKINFO*,UINT);
|
---|
64 | UINT WINAPI (*fnmmioDescend)(HMMIO,MMCKINFO*,const MMCKINFO*,UINT);
|
---|
65 | LONG WINAPI (*fnmmioSeek)(HMMIO,LONG,INT);
|
---|
66 | LONG WINAPI (*fnmmioRead)(HMMIO,HPSTR,LONG);
|
---|
67 | #endif
|
---|
68 |
|
---|
69 | /* reference to input stream (file or resource) */
|
---|
70 | HGLOBAL hRes;
|
---|
71 | HMMIO hMMio; /* handle to mmio stream */
|
---|
72 | HWND hWnd;
|
---|
73 | /* information on the loaded AVI file */
|
---|
74 | MainAVIHeader mah;
|
---|
75 | AVIStreamHeader ash;
|
---|
76 | LPBITMAPINFOHEADER inbih;
|
---|
77 | LPDWORD lpIndex;
|
---|
78 | /* data for the decompressor */
|
---|
79 | HIC hic;
|
---|
80 | LPBITMAPINFOHEADER outbih;
|
---|
81 | LPVOID indata;
|
---|
82 | LPVOID outdata;
|
---|
83 | /* data for the background mechanism */
|
---|
84 | CRITICAL_SECTION cs;
|
---|
85 | HANDLE hThread;
|
---|
86 | UINT uTimer;
|
---|
87 | /* data for playing the file */
|
---|
88 | int nFromFrame;
|
---|
89 | int nToFrame;
|
---|
90 | int nLoop;
|
---|
91 | int currFrame;
|
---|
92 | /* tranparency info*/
|
---|
93 | COLORREF transparentColor;
|
---|
94 | HBRUSH hbrushBG;
|
---|
95 | HBITMAP hbmPrevFrame;
|
---|
96 | } ANIMATE_INFO;
|
---|
97 |
|
---|
98 | #define ANIMATE_GetInfoPtr(hWnd) ((ANIMATE_INFO *)GetWindowLongA(hWnd, 0))
|
---|
99 | #define ANIMATE_COLOR_NONE 0xffffffff
|
---|
100 |
|
---|
101 | HMODULE hModWinmm;
|
---|
102 |
|
---|
103 | static void ANIMATE_Notify(ANIMATE_INFO* infoPtr, UINT notif)
|
---|
104 | {
|
---|
105 | SendMessageA(GetParent(infoPtr->hWnd), WM_COMMAND,
|
---|
106 | MAKEWPARAM(GetDlgCtrlID(infoPtr->hWnd), notif),
|
---|
107 | (LPARAM)infoPtr->hWnd);
|
---|
108 | }
|
---|
109 |
|
---|
110 | #ifdef __WIN32OS2__
|
---|
111 | static BOOL ANIMATE_LoadRes(ANIMATE_INFO *infoPtr,HINSTANCE hInst,LPWSTR lpName,BOOL unicode)
|
---|
112 | #else
|
---|
113 | static BOOL ANIMATE_LoadResA(ANIMATE_INFO *infoPtr, HINSTANCE hInst, LPSTR lpName)
|
---|
114 | #endif
|
---|
115 | {
|
---|
116 | HRSRC hrsrc;
|
---|
117 | MMIOINFO mminfo;
|
---|
118 | LPVOID lpAvi;
|
---|
119 |
|
---|
120 | #ifdef __WIN32OS2__
|
---|
121 | if (unicode)
|
---|
122 | hrsrc = FindResourceW(hInst,lpName,(LPWSTR)L"AVI");
|
---|
123 | else
|
---|
124 | hrsrc = FindResourceA(hInst,(LPCSTR)lpName,"AVI");
|
---|
125 | #else
|
---|
126 | hrsrc = FindResourceA(hInst, lpName, "AVI");
|
---|
127 | #endif
|
---|
128 | if (!hrsrc)
|
---|
129 | return FALSE;
|
---|
130 |
|
---|
131 | infoPtr->hRes = LoadResource(hInst, hrsrc);
|
---|
132 | if (!infoPtr->hRes)
|
---|
133 | return FALSE;
|
---|
134 |
|
---|
135 | lpAvi = LockResource(infoPtr->hRes);
|
---|
136 | if (!lpAvi)
|
---|
137 | return FALSE;
|
---|
138 |
|
---|
139 | memset(&mminfo, 0, sizeof(mminfo));
|
---|
140 | mminfo.fccIOProc = FOURCC_MEM;
|
---|
141 | mminfo.pchBuffer = (LPSTR)lpAvi;
|
---|
142 | mminfo.cchBuffer = SizeofResource(hInst, hrsrc);
|
---|
143 | infoPtr->hMMio = infoPtr->fnmmioOpenA(NULL, &mminfo, MMIO_READ);
|
---|
144 |
|
---|
145 | if (!infoPtr->hMMio) {
|
---|
146 | GlobalFree((HGLOBAL)lpAvi);
|
---|
147 | return FALSE;
|
---|
148 | }
|
---|
149 |
|
---|
150 | return TRUE;
|
---|
151 | }
|
---|
152 |
|
---|
153 |
|
---|
154 | #ifdef __WIN32OS2__
|
---|
155 | static BOOL ANIMATE_LoadFile(ANIMATE_INFO *infoPtr,LPWSTR lpName,BOOL unicode)
|
---|
156 | #else
|
---|
157 | static BOOL ANIMATE_LoadFileA(ANIMATE_INFO *infoPtr, LPSTR lpName)
|
---|
158 | #endif
|
---|
159 | {
|
---|
160 | #ifdef __WIN32OS2__
|
---|
161 | if (unicode)
|
---|
162 | infoPtr->hMMio = infoPtr->fnmmioOpenW(lpName,NULL,MMIO_ALLOCBUF | MMIO_READ | MMIO_DENYWRITE);
|
---|
163 | else
|
---|
164 | infoPtr->hMMio = infoPtr->fnmmioOpenA((LPSTR)lpName,NULL,MMIO_ALLOCBUF | MMIO_READ | MMIO_DENYWRITE);
|
---|
165 | #else
|
---|
166 | infoPtr->hMMio = infoPtr->fnmmioOpenA((LPSTR)lpName, NULL,
|
---|
167 | MMIO_ALLOCBUF | MMIO_READ | MMIO_DENYWRITE);
|
---|
168 | #endif
|
---|
169 |
|
---|
170 | if (!infoPtr->hMMio)
|
---|
171 | return FALSE;
|
---|
172 |
|
---|
173 | return TRUE;
|
---|
174 | }
|
---|
175 |
|
---|
176 |
|
---|
177 | static LRESULT ANIMATE_DoStop(ANIMATE_INFO *infoPtr)
|
---|
178 | {
|
---|
179 | EnterCriticalSection(&infoPtr->cs);
|
---|
180 |
|
---|
181 | /* should stop playing */
|
---|
182 | if (infoPtr->hThread)
|
---|
183 | {
|
---|
184 | if (!TerminateThread(infoPtr->hThread,0))
|
---|
185 | WARN("could not destroy animation thread!\n");
|
---|
186 | infoPtr->hThread = 0;
|
---|
187 | }
|
---|
188 | if (infoPtr->uTimer) {
|
---|
189 | KillTimer(infoPtr->hWnd, infoPtr->uTimer);
|
---|
190 | infoPtr->uTimer = 0;
|
---|
191 | }
|
---|
192 |
|
---|
193 | LeaveCriticalSection(&infoPtr->cs);
|
---|
194 |
|
---|
195 | ANIMATE_Notify(infoPtr, ACN_STOP);
|
---|
196 |
|
---|
197 | return TRUE;
|
---|
198 | }
|
---|
199 |
|
---|
200 |
|
---|
201 | static void ANIMATE_Free(ANIMATE_INFO *infoPtr)
|
---|
202 | {
|
---|
203 | if (infoPtr->hMMio) {
|
---|
204 | ANIMATE_DoStop(infoPtr);
|
---|
205 | infoPtr->fnmmioClose(infoPtr->hMMio, 0);
|
---|
206 | if (infoPtr->hRes) {
|
---|
207 | FreeResource(infoPtr->hRes);
|
---|
208 | infoPtr->hRes = 0;
|
---|
209 | }
|
---|
210 | if (infoPtr->lpIndex) {
|
---|
211 | HeapFree(GetProcessHeap(), 0, infoPtr->lpIndex);
|
---|
212 | infoPtr->lpIndex = NULL;
|
---|
213 | }
|
---|
214 | if (infoPtr->hic) {
|
---|
215 | (infoPtr->fnICClose)(infoPtr->hic);
|
---|
216 | infoPtr->hic = 0;
|
---|
217 | }
|
---|
218 | if (infoPtr->inbih) {
|
---|
219 | HeapFree(GetProcessHeap(), 0, infoPtr->inbih);
|
---|
220 | infoPtr->inbih = NULL;
|
---|
221 | }
|
---|
222 | if (infoPtr->outbih) {
|
---|
223 | HeapFree(GetProcessHeap(), 0, infoPtr->outbih);
|
---|
224 | infoPtr->outbih = NULL;
|
---|
225 | }
|
---|
226 | if( infoPtr->indata )
|
---|
227 | {
|
---|
228 | HeapFree(GetProcessHeap(), 0, infoPtr->indata);
|
---|
229 | infoPtr->indata = NULL;
|
---|
230 | }
|
---|
231 | if( infoPtr->outdata )
|
---|
232 | {
|
---|
233 | HeapFree(GetProcessHeap(), 0, infoPtr->outdata);
|
---|
234 | infoPtr->outdata = NULL;
|
---|
235 | }
|
---|
236 | if( infoPtr->hbmPrevFrame )
|
---|
237 | {
|
---|
238 | DeleteObject(infoPtr->hbmPrevFrame);
|
---|
239 | infoPtr->hbmPrevFrame = 0;
|
---|
240 | }
|
---|
241 | infoPtr->indata = infoPtr->outdata = NULL;
|
---|
242 | infoPtr->hWnd = 0;
|
---|
243 | infoPtr->hMMio = 0;
|
---|
244 |
|
---|
245 | memset(&infoPtr->mah, 0, sizeof(infoPtr->mah));
|
---|
246 | memset(&infoPtr->ash, 0, sizeof(infoPtr->ash));
|
---|
247 | infoPtr->nFromFrame = infoPtr->nToFrame = infoPtr->nLoop = infoPtr->currFrame = 0;
|
---|
248 | }
|
---|
249 | infoPtr->transparentColor = ANIMATE_COLOR_NONE;
|
---|
250 | }
|
---|
251 |
|
---|
252 | static void ANIMATE_TransparentBlt(ANIMATE_INFO* infoPtr, HDC hdcDest, HDC hdcSource)
|
---|
253 | {
|
---|
254 | HDC hdcMask;
|
---|
255 | HBITMAP hbmMask;
|
---|
256 | HBITMAP hbmOld;
|
---|
257 |
|
---|
258 | /* create a transparency mask */
|
---|
259 | hdcMask = CreateCompatibleDC(hdcDest);
|
---|
260 | hbmMask = CreateBitmap(infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, 1,1,NULL);
|
---|
261 | hbmOld = SelectObject(hdcMask, hbmMask);
|
---|
262 |
|
---|
263 | SetBkColor(hdcSource,infoPtr->transparentColor);
|
---|
264 | BitBlt(hdcMask,0,0,infoPtr->inbih->biWidth, infoPtr->inbih->biHeight,hdcSource,0,0,SRCCOPY);
|
---|
265 |
|
---|
266 | /* mask the source bitmap */
|
---|
267 | SetBkColor(hdcSource, RGB(0,0,0));
|
---|
268 | SetTextColor(hdcSource, RGB(255,255,255));
|
---|
269 | BitBlt(hdcSource, 0, 0, infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, hdcMask, 0, 0, SRCAND);
|
---|
270 |
|
---|
271 | /* mask the destination bitmap */
|
---|
272 | SetBkColor(hdcDest, RGB(255,255,255));
|
---|
273 | SetTextColor(hdcDest, RGB(0,0,0));
|
---|
274 | BitBlt(hdcDest, 0, 0, infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, hdcMask, 0, 0, SRCAND);
|
---|
275 |
|
---|
276 | /* combine source and destination */
|
---|
277 | BitBlt(hdcDest,0,0,infoPtr->inbih->biWidth, infoPtr->inbih->biHeight,hdcSource,0,0,SRCPAINT);
|
---|
278 |
|
---|
279 | SelectObject(hdcMask, hbmOld);
|
---|
280 | DeleteObject(hbmMask);
|
---|
281 | DeleteDC(hdcMask);
|
---|
282 | }
|
---|
283 |
|
---|
284 | static LRESULT ANIMATE_PaintFrame(ANIMATE_INFO* infoPtr, HDC hDC)
|
---|
285 | {
|
---|
286 | void* pBitmapData = NULL;
|
---|
287 | LPBITMAPINFO pBitmapInfo = NULL;
|
---|
288 |
|
---|
289 | HDC hdcMem;
|
---|
290 | HBITMAP hbmOld;
|
---|
291 |
|
---|
292 | int nOffsetX = 0;
|
---|
293 | int nOffsetY = 0;
|
---|
294 |
|
---|
295 | int nWidth;
|
---|
296 | int nHeight;
|
---|
297 |
|
---|
298 | if (!hDC || !infoPtr->inbih)
|
---|
299 | return TRUE;
|
---|
300 |
|
---|
301 | if (infoPtr->hic )
|
---|
302 | {
|
---|
303 | pBitmapData = infoPtr->outdata;
|
---|
304 | pBitmapInfo = (LPBITMAPINFO)infoPtr->outbih;
|
---|
305 |
|
---|
306 | nWidth = infoPtr->outbih->biWidth;
|
---|
307 | nHeight = infoPtr->outbih->biHeight;
|
---|
308 | } else
|
---|
309 | {
|
---|
310 | pBitmapData = infoPtr->indata;
|
---|
311 | pBitmapInfo = (LPBITMAPINFO)infoPtr->inbih;
|
---|
312 |
|
---|
313 | nWidth = infoPtr->inbih->biWidth;
|
---|
314 | nHeight = infoPtr->inbih->biHeight;
|
---|
315 | }
|
---|
316 |
|
---|
317 | if(!infoPtr->hbmPrevFrame)
|
---|
318 | {
|
---|
319 | infoPtr->hbmPrevFrame=CreateCompatibleBitmap(hDC, nWidth,nHeight );
|
---|
320 | }
|
---|
321 |
|
---|
322 | SetDIBits(hDC, infoPtr->hbmPrevFrame, 0, nHeight, pBitmapData, (LPBITMAPINFO)pBitmapInfo, DIB_RGB_COLORS);
|
---|
323 |
|
---|
324 | hdcMem = CreateCompatibleDC(hDC);
|
---|
325 | hbmOld = SelectObject(hdcMem, infoPtr->hbmPrevFrame);
|
---|
326 |
|
---|
327 | /*
|
---|
328 | * we need to get the transparent color even without ACS_TRANSPARENT,
|
---|
329 | * because the style can be changed later on and the color should always
|
---|
330 | * be obtained in the first frame
|
---|
331 | */
|
---|
332 | if(infoPtr->transparentColor == ANIMATE_COLOR_NONE)
|
---|
333 | {
|
---|
334 | infoPtr->transparentColor = GetPixel(hdcMem,0,0);
|
---|
335 | }
|
---|
336 |
|
---|
337 | if(GetWindowLongA(infoPtr->hWnd, GWL_STYLE) & ACS_TRANSPARENT)
|
---|
338 | {
|
---|
339 | HDC hdcFinal = CreateCompatibleDC(hDC);
|
---|
340 | HBITMAP hbmFinal = CreateCompatibleBitmap(hDC,nWidth, nHeight);
|
---|
341 | HBITMAP hbmOld2 = SelectObject(hdcFinal, hbmFinal);
|
---|
342 | RECT rect;
|
---|
343 |
|
---|
344 | rect.left = 0;
|
---|
345 | rect.top = 0;
|
---|
346 | rect.right = nWidth;
|
---|
347 | rect.bottom = nHeight;
|
---|
348 |
|
---|
349 | if(!infoPtr->hbrushBG)
|
---|
350 | infoPtr->hbrushBG = GetCurrentObject(hDC, OBJ_BRUSH);
|
---|
351 |
|
---|
352 | FillRect(hdcFinal, &rect, infoPtr->hbrushBG);
|
---|
353 | ANIMATE_TransparentBlt(infoPtr, hdcFinal, hdcMem);
|
---|
354 |
|
---|
355 | SelectObject(hdcFinal, hbmOld2);
|
---|
356 | SelectObject(hdcMem, hbmFinal);
|
---|
357 | DeleteDC(hdcFinal);
|
---|
358 | DeleteObject(infoPtr->hbmPrevFrame);
|
---|
359 | infoPtr->hbmPrevFrame = hbmFinal;
|
---|
360 | }
|
---|
361 |
|
---|
362 | if (GetWindowLongA(infoPtr->hWnd, GWL_STYLE) & ACS_CENTER)
|
---|
363 | {
|
---|
364 | RECT rect;
|
---|
365 |
|
---|
366 | GetWindowRect(infoPtr->hWnd, &rect);
|
---|
367 | nOffsetX = ((rect.right - rect.left) - nWidth)/2;
|
---|
368 | nOffsetY = ((rect.bottom - rect.top) - nHeight)/2;
|
---|
369 | }
|
---|
370 | BitBlt(hDC, nOffsetX, nOffsetY, nWidth, nHeight, hdcMem, 0, 0, SRCCOPY);
|
---|
371 |
|
---|
372 | SelectObject(hdcMem, hbmOld);
|
---|
373 | DeleteDC(hdcMem);
|
---|
374 | return TRUE;
|
---|
375 | }
|
---|
376 |
|
---|
377 | static LRESULT ANIMATE_DrawFrame(ANIMATE_INFO* infoPtr)
|
---|
378 | {
|
---|
379 | HDC hDC;
|
---|
380 |
|
---|
381 | TRACE("Drawing frame %d (loop %d)\n", infoPtr->currFrame, infoPtr->nLoop);
|
---|
382 |
|
---|
383 | EnterCriticalSection(&infoPtr->cs);
|
---|
384 |
|
---|
385 | infoPtr->fnmmioSeek(infoPtr->hMMio, infoPtr->lpIndex[infoPtr->currFrame], SEEK_SET);
|
---|
386 | infoPtr->fnmmioRead(infoPtr->hMMio, infoPtr->indata, infoPtr->ash.dwSuggestedBufferSize);
|
---|
387 |
|
---|
388 | if (infoPtr->hic &&
|
---|
389 | (infoPtr->fnICDecompress)(infoPtr->hic, 0, infoPtr->inbih, infoPtr->indata,
|
---|
390 | infoPtr->outbih, infoPtr->outdata) != ICERR_OK) {
|
---|
391 | LeaveCriticalSection(&infoPtr->cs);
|
---|
392 | WARN("Decompression error\n");
|
---|
393 | return FALSE;
|
---|
394 | }
|
---|
395 |
|
---|
396 | if ((hDC = GetDC(infoPtr->hWnd)) != 0) {
|
---|
397 | ANIMATE_PaintFrame(infoPtr, hDC);
|
---|
398 | ReleaseDC(infoPtr->hWnd, hDC);
|
---|
399 | }
|
---|
400 |
|
---|
401 | if (infoPtr->currFrame++ >= infoPtr->nToFrame) {
|
---|
402 | infoPtr->currFrame = infoPtr->nFromFrame;
|
---|
403 | if (infoPtr->nLoop != -1) {
|
---|
404 | if (--infoPtr->nLoop == 0) {
|
---|
405 | ANIMATE_DoStop(infoPtr);
|
---|
406 | }
|
---|
407 | }
|
---|
408 | }
|
---|
409 | LeaveCriticalSection(&infoPtr->cs);
|
---|
410 |
|
---|
411 | return TRUE;
|
---|
412 | }
|
---|
413 |
|
---|
414 | static DWORD CALLBACK ANIMATE_AnimationThread(LPVOID ptr_)
|
---|
415 | {
|
---|
416 | ANIMATE_INFO* infoPtr = (ANIMATE_INFO*)ptr_;
|
---|
417 | HDC hDC;
|
---|
418 |
|
---|
419 | if(!infoPtr)
|
---|
420 | {
|
---|
421 | WARN("animation structure undefined!\n");
|
---|
422 | return FALSE;
|
---|
423 | }
|
---|
424 |
|
---|
425 | while(1)
|
---|
426 | {
|
---|
427 | if(GetWindowLongA(infoPtr->hWnd, GWL_STYLE) & ACS_TRANSPARENT)
|
---|
428 | {
|
---|
429 | hDC = GetDC(infoPtr->hWnd);
|
---|
430 | infoPtr->hbrushBG = SendMessageA(GetParent(infoPtr->hWnd),WM_CTLCOLORSTATIC,hDC, infoPtr->hWnd);
|
---|
431 | ReleaseDC(infoPtr->hWnd,hDC);
|
---|
432 | }
|
---|
433 |
|
---|
434 | EnterCriticalSection(&infoPtr->cs);
|
---|
435 | ANIMATE_DrawFrame(infoPtr);
|
---|
436 | LeaveCriticalSection(&infoPtr->cs);
|
---|
437 |
|
---|
438 | /* time is in microseconds, we should convert it to milliseconds */
|
---|
439 | Sleep((infoPtr->mah.dwMicroSecPerFrame+500)/1000);
|
---|
440 | }
|
---|
441 | return TRUE;
|
---|
442 | }
|
---|
443 |
|
---|
444 | static LRESULT ANIMATE_Play(HWND hWnd, WPARAM wParam, LPARAM lParam)
|
---|
445 | {
|
---|
446 | ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
|
---|
447 |
|
---|
448 | /* nothing opened */
|
---|
449 | if (!infoPtr->hMMio)
|
---|
450 | return FALSE;
|
---|
451 |
|
---|
452 | if (infoPtr->hThread || infoPtr->uTimer) {
|
---|
453 | FIXME("Already playing ? what should I do ??\n");
|
---|
454 | ANIMATE_DoStop(infoPtr);
|
---|
455 | }
|
---|
456 |
|
---|
457 | infoPtr->nFromFrame = (INT)LOWORD(lParam);
|
---|
458 | infoPtr->nToFrame = (INT)HIWORD(lParam);
|
---|
459 | infoPtr->nLoop = (INT)wParam;
|
---|
460 |
|
---|
461 | if (infoPtr->nToFrame == 0xFFFF)
|
---|
462 | infoPtr->nToFrame = infoPtr->mah.dwTotalFrames - 1;
|
---|
463 |
|
---|
464 | TRACE("(repeat=%d from=%d to=%d);\n",
|
---|
465 | infoPtr->nLoop, infoPtr->nFromFrame, infoPtr->nToFrame);
|
---|
466 |
|
---|
467 | if (infoPtr->nFromFrame >= infoPtr->nToFrame ||
|
---|
468 | infoPtr->nToFrame >= infoPtr->mah.dwTotalFrames)
|
---|
469 | return FALSE;
|
---|
470 |
|
---|
471 | infoPtr->currFrame = infoPtr->nFromFrame;
|
---|
472 |
|
---|
473 | if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_TIMER) {
|
---|
474 | TRACE("Using a timer\n");
|
---|
475 | /* create a timer to display AVI */
|
---|
476 | infoPtr->uTimer = SetTimer(hWnd, 1, infoPtr->mah.dwMicroSecPerFrame / 1000, NULL);
|
---|
477 | } else {
|
---|
478 | DWORD threadID;
|
---|
479 |
|
---|
480 | TRACE("Using an animation thread\n");
|
---|
481 | infoPtr->hThread = CreateThread(0,0,ANIMATE_AnimationThread,(LPVOID)infoPtr,0,0 &threadID);
|
---|
482 | if(!infoPtr->hThread)
|
---|
483 | {
|
---|
484 | ERR("Could not create animation thread!\n");
|
---|
485 | return FALSE;
|
---|
486 | }
|
---|
487 |
|
---|
488 | }
|
---|
489 |
|
---|
490 | ANIMATE_Notify(infoPtr, ACN_START);
|
---|
491 |
|
---|
492 | return TRUE;
|
---|
493 | }
|
---|
494 |
|
---|
495 |
|
---|
496 | static BOOL ANIMATE_GetAviInfo(ANIMATE_INFO *infoPtr)
|
---|
497 | {
|
---|
498 | MMCKINFO ckMainRIFF;
|
---|
499 | MMCKINFO mmckHead;
|
---|
500 | MMCKINFO mmckList;
|
---|
501 | MMCKINFO mmckInfo;
|
---|
502 | DWORD numFrame;
|
---|
503 | DWORD insize;
|
---|
504 |
|
---|
505 | if (infoPtr->fnmmioDescend(infoPtr->hMMio, &ckMainRIFF, NULL, 0) != 0) {
|
---|
506 | WARN("Can't find 'RIFF' chunk\n");
|
---|
507 | return FALSE;
|
---|
508 | }
|
---|
509 |
|
---|
510 | if ((ckMainRIFF.ckid != FOURCC_RIFF) ||
|
---|
511 | (ckMainRIFF.fccType != mmioFOURCC('A', 'V', 'I', ' '))) {
|
---|
512 | WARN("Can't find 'AVI ' chunk\n");
|
---|
513 | return FALSE;
|
---|
514 | }
|
---|
515 |
|
---|
516 | mmckHead.fccType = mmioFOURCC('h', 'd', 'r', 'l');
|
---|
517 | if (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckHead, &ckMainRIFF, MMIO_FINDLIST) != 0) {
|
---|
518 | WARN("Can't find 'hdrl' list\n");
|
---|
519 | return FALSE;
|
---|
520 | }
|
---|
521 |
|
---|
522 | mmckInfo.ckid = mmioFOURCC('a', 'v', 'i', 'h');
|
---|
523 | if (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckInfo, &mmckHead, MMIO_FINDCHUNK) != 0) {
|
---|
524 | WARN("Can't find 'avih' chunk\n");
|
---|
525 | return FALSE;
|
---|
526 | }
|
---|
527 |
|
---|
528 | infoPtr->fnmmioRead(infoPtr->hMMio, (LPSTR)&infoPtr->mah, sizeof(infoPtr->mah));
|
---|
529 | TRACE("mah.dwMicroSecPerFrame=%ld\n", infoPtr->mah.dwMicroSecPerFrame);
|
---|
530 | TRACE("mah.dwMaxBytesPerSec=%ld\n", infoPtr->mah.dwMaxBytesPerSec);
|
---|
531 | TRACE("mah.dwPaddingGranularity=%ld\n", infoPtr->mah.dwPaddingGranularity);
|
---|
532 | TRACE("mah.dwFlags=%ld\n", infoPtr->mah.dwFlags);
|
---|
533 | TRACE("mah.dwTotalFrames=%ld\n", infoPtr->mah.dwTotalFrames);
|
---|
534 | TRACE("mah.dwInitialFrames=%ld\n", infoPtr->mah.dwInitialFrames);
|
---|
535 | TRACE("mah.dwStreams=%ld\n", infoPtr->mah.dwStreams);
|
---|
536 | TRACE("mah.dwSuggestedBufferSize=%ld\n", infoPtr->mah.dwSuggestedBufferSize);
|
---|
537 | TRACE("mah.dwWidth=%ld\n", infoPtr->mah.dwWidth);
|
---|
538 | TRACE("mah.dwHeight=%ld\n", infoPtr->mah.dwHeight);
|
---|
539 | infoPtr->fnmmioAscend(infoPtr->hMMio, &mmckInfo, 0);
|
---|
540 |
|
---|
541 | mmckList.fccType = mmioFOURCC('s', 't', 'r', 'l');
|
---|
542 | if (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckList, &mmckHead, MMIO_FINDLIST) != 0) {
|
---|
543 | WARN("Can't find 'strl' list\n");
|
---|
544 | return FALSE;
|
---|
545 | }
|
---|
546 |
|
---|
547 | mmckInfo.ckid = mmioFOURCC('s', 't', 'r', 'h');
|
---|
548 | if (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, MMIO_FINDCHUNK) != 0) {
|
---|
549 | WARN("Can't find 'strh' chunk\n");
|
---|
550 | return FALSE;
|
---|
551 | }
|
---|
552 |
|
---|
553 | infoPtr->fnmmioRead(infoPtr->hMMio, (LPSTR)&infoPtr->ash, sizeof(infoPtr->ash));
|
---|
554 | TRACE("ash.fccType='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr->ash.fccType)),
|
---|
555 | HIBYTE(LOWORD(infoPtr->ash.fccType)),
|
---|
556 | LOBYTE(HIWORD(infoPtr->ash.fccType)),
|
---|
557 | HIBYTE(HIWORD(infoPtr->ash.fccType)));
|
---|
558 | TRACE("ash.fccHandler='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr->ash.fccHandler)),
|
---|
559 | HIBYTE(LOWORD(infoPtr->ash.fccHandler)),
|
---|
560 | LOBYTE(HIWORD(infoPtr->ash.fccHandler)),
|
---|
561 | HIBYTE(HIWORD(infoPtr->ash.fccHandler)));
|
---|
562 | TRACE("ash.dwFlags=%ld\n", infoPtr->ash.dwFlags);
|
---|
563 | TRACE("ash.wPriority=%d\n", infoPtr->ash.wPriority);
|
---|
564 | TRACE("ash.wLanguage=%d\n", infoPtr->ash.wLanguage);
|
---|
565 | TRACE("ash.dwInitialFrames=%ld\n", infoPtr->ash.dwInitialFrames);
|
---|
566 | TRACE("ash.dwScale=%ld\n", infoPtr->ash.dwScale);
|
---|
567 | TRACE("ash.dwRate=%ld\n", infoPtr->ash.dwRate);
|
---|
568 | TRACE("ash.dwStart=%ld\n", infoPtr->ash.dwStart);
|
---|
569 | TRACE("ash.dwLength=%ld\n", infoPtr->ash.dwLength);
|
---|
570 | TRACE("ash.dwSuggestedBufferSize=%ld\n", infoPtr->ash.dwSuggestedBufferSize);
|
---|
571 | TRACE("ash.dwQuality=%ld\n", infoPtr->ash.dwQuality);
|
---|
572 | TRACE("ash.dwSampleSize=%ld\n", infoPtr->ash.dwSampleSize);
|
---|
573 | TRACE("ash.rcFrame=(%d,%d,%d,%d)\n", infoPtr->ash.rcFrame.top, infoPtr->ash.rcFrame.left,
|
---|
574 | infoPtr->ash.rcFrame.bottom, infoPtr->ash.rcFrame.right);
|
---|
575 | infoPtr->fnmmioAscend(infoPtr->hMMio, &mmckInfo, 0);
|
---|
576 |
|
---|
577 | mmckInfo.ckid = mmioFOURCC('s', 't', 'r', 'f');
|
---|
578 | if (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, MMIO_FINDCHUNK) != 0) {
|
---|
579 | WARN("Can't find 'strh' chunk\n");
|
---|
580 | return FALSE;
|
---|
581 | }
|
---|
582 |
|
---|
583 | infoPtr->inbih = HeapAlloc(GetProcessHeap(), 0, mmckInfo.cksize);
|
---|
584 | if (!infoPtr->inbih) {
|
---|
585 | WARN("Can't alloc input BIH\n");
|
---|
586 | return FALSE;
|
---|
587 | }
|
---|
588 |
|
---|
589 | infoPtr->fnmmioRead(infoPtr->hMMio, (LPSTR)infoPtr->inbih, mmckInfo.cksize);
|
---|
590 | TRACE("bih.biSize=%ld\n", infoPtr->inbih->biSize);
|
---|
591 | TRACE("bih.biWidth=%ld\n", infoPtr->inbih->biWidth);
|
---|
592 | TRACE("bih.biHeight=%ld\n", infoPtr->inbih->biHeight);
|
---|
593 | TRACE("bih.biPlanes=%d\n", infoPtr->inbih->biPlanes);
|
---|
594 | TRACE("bih.biBitCount=%d\n", infoPtr->inbih->biBitCount);
|
---|
595 | TRACE("bih.biCompression=%ld\n", infoPtr->inbih->biCompression);
|
---|
596 | TRACE("bih.biSizeImage=%ld\n", infoPtr->inbih->biSizeImage);
|
---|
597 | TRACE("bih.biXPelsPerMeter=%ld\n", infoPtr->inbih->biXPelsPerMeter);
|
---|
598 | TRACE("bih.biYPelsPerMeter=%ld\n", infoPtr->inbih->biYPelsPerMeter);
|
---|
599 | TRACE("bih.biClrUsed=%ld\n", infoPtr->inbih->biClrUsed);
|
---|
600 | TRACE("bih.biClrImportant=%ld\n", infoPtr->inbih->biClrImportant);
|
---|
601 | infoPtr->fnmmioAscend(infoPtr->hMMio, &mmckInfo, 0);
|
---|
602 |
|
---|
603 | infoPtr->fnmmioAscend(infoPtr->hMMio, &mmckList, 0);
|
---|
604 |
|
---|
605 | #if 0
|
---|
606 | /* an AVI has 0 or 1 video stream, and to be animated should not contain
|
---|
607 | * an audio stream, so only one strl is allowed
|
---|
608 | */
|
---|
609 | mmckList.fccType = mmioFOURCC('s', 't', 'r', 'l');
|
---|
610 | if (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckList, &mmckHead, MMIO_FINDLIST) == 0) {
|
---|
611 | WARN("There should be a single 'strl' list\n");
|
---|
612 | return FALSE;
|
---|
613 | }
|
---|
614 | #endif
|
---|
615 |
|
---|
616 | infoPtr->fnmmioAscend(infoPtr->hMMio, &mmckHead, 0);
|
---|
617 |
|
---|
618 | /* no need to read optional JUNK chunk */
|
---|
619 |
|
---|
620 | mmckList.fccType = mmioFOURCC('m', 'o', 'v', 'i');
|
---|
621 | if (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckList, &ckMainRIFF, MMIO_FINDLIST) != 0) {
|
---|
622 | WARN("Can't find 'movi' list\n");
|
---|
623 | return FALSE;
|
---|
624 | }
|
---|
625 |
|
---|
626 | /* FIXME: should handle the 'rec ' LIST when present */
|
---|
627 |
|
---|
628 | infoPtr->lpIndex = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
---|
629 | infoPtr->mah.dwTotalFrames * sizeof(DWORD));
|
---|
630 | if (!infoPtr->lpIndex) {
|
---|
631 | WARN("Can't alloc index array\n");
|
---|
632 | return FALSE;
|
---|
633 | }
|
---|
634 |
|
---|
635 | numFrame = insize = 0;
|
---|
636 | while (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, 0) == 0 &&
|
---|
637 | numFrame < infoPtr->mah.dwTotalFrames) {
|
---|
638 | infoPtr->lpIndex[numFrame] = mmckInfo.dwDataOffset;
|
---|
639 | if (insize < mmckInfo.cksize)
|
---|
640 | insize = mmckInfo.cksize;
|
---|
641 | numFrame++;
|
---|
642 | infoPtr->fnmmioAscend(infoPtr->hMMio, &mmckInfo, 0);
|
---|
643 | }
|
---|
644 | if (numFrame != infoPtr->mah.dwTotalFrames) {
|
---|
645 | WARN("Found %ld frames (/%ld)\n", numFrame, infoPtr->mah.dwTotalFrames);
|
---|
646 | return FALSE;
|
---|
647 | }
|
---|
648 | if (insize > infoPtr->ash.dwSuggestedBufferSize) {
|
---|
649 | WARN("insize=%ld suggestedSize=%ld\n", insize, infoPtr->ash.dwSuggestedBufferSize);
|
---|
650 | infoPtr->ash.dwSuggestedBufferSize = insize;
|
---|
651 | }
|
---|
652 |
|
---|
653 | infoPtr->indata = HeapAlloc(GetProcessHeap(), 0, infoPtr->ash.dwSuggestedBufferSize);
|
---|
654 | if (!infoPtr->indata) {
|
---|
655 | WARN("Can't alloc input buffer\n");
|
---|
656 | return FALSE;
|
---|
657 | }
|
---|
658 |
|
---|
659 | return TRUE;
|
---|
660 | }
|
---|
661 |
|
---|
662 |
|
---|
663 | static BOOL ANIMATE_GetAviCodec(ANIMATE_INFO *infoPtr)
|
---|
664 | {
|
---|
665 | DWORD outSize;
|
---|
666 |
|
---|
667 | /* check uncompressed AVI */
|
---|
668 | if ((infoPtr->ash.fccHandler == mmioFOURCC('D', 'I', 'B', ' ')) ||
|
---|
669 | (infoPtr->ash.fccHandler == mmioFOURCC('R', 'L', 'E', ' ')))
|
---|
670 | {
|
---|
671 | infoPtr->hic = 0;
|
---|
672 | return TRUE;
|
---|
673 | }
|
---|
674 |
|
---|
675 | /* try to get a decompressor for that type */
|
---|
676 | infoPtr->hic = (infoPtr->fnICOpen)(ICTYPE_VIDEO,
|
---|
677 | infoPtr->ash.fccHandler,
|
---|
678 | ICMODE_DECOMPRESS);
|
---|
679 | if (!infoPtr->hic) {
|
---|
680 | WARN("Can't load codec for the file\n");
|
---|
681 | return FALSE;
|
---|
682 | }
|
---|
683 |
|
---|
684 | outSize = (infoPtr->fnICSendMessage)(infoPtr->hic,
|
---|
685 | ICM_DECOMPRESS_GET_FORMAT,
|
---|
686 | (DWORD)infoPtr->inbih, 0L);
|
---|
687 | infoPtr->outbih = HeapAlloc(GetProcessHeap(), 0, outSize);
|
---|
688 | if (!infoPtr->outbih) {
|
---|
689 | WARN("Can't alloc output BIH\n");
|
---|
690 | return FALSE;
|
---|
691 | }
|
---|
692 |
|
---|
693 | if ((infoPtr->fnICSendMessage)(infoPtr->hic, ICM_DECOMPRESS_GET_FORMAT,
|
---|
694 | (DWORD)infoPtr->inbih,
|
---|
695 | (DWORD)infoPtr->outbih) != ICERR_OK) {
|
---|
696 | WARN("Can't get output BIH\n");
|
---|
697 | return FALSE;
|
---|
698 | }
|
---|
699 |
|
---|
700 | infoPtr->outdata = HeapAlloc(GetProcessHeap(), 0, infoPtr->outbih->biSizeImage);
|
---|
701 | if (!infoPtr->outdata) {
|
---|
702 | WARN("Can't alloc output buffer\n");
|
---|
703 | return FALSE;
|
---|
704 | }
|
---|
705 |
|
---|
706 | if ((infoPtr->fnICSendMessage)(infoPtr->hic, ICM_DECOMPRESS_BEGIN,
|
---|
707 | (DWORD)infoPtr->inbih,
|
---|
708 | (DWORD)infoPtr->outbih) != ICERR_OK) {
|
---|
709 | WARN("Can't begin decompression\n");
|
---|
710 | return FALSE;
|
---|
711 | }
|
---|
712 |
|
---|
713 | return TRUE;
|
---|
714 | }
|
---|
715 |
|
---|
716 | #ifdef __WIN32OS2__
|
---|
717 | static LRESULT ANIMATE_Open(HWND hWnd, WPARAM wParam, LPARAM lParam,BOOL unicode)
|
---|
718 | #else
|
---|
719 | static LRESULT ANIMATE_OpenA(HWND hWnd, WPARAM wParam, LPARAM lParam)
|
---|
720 | #endif
|
---|
721 | {
|
---|
722 | ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
|
---|
723 | HINSTANCE hInstance = (HINSTANCE)wParam;
|
---|
724 |
|
---|
725 | ANIMATE_Free(infoPtr);
|
---|
726 |
|
---|
727 | if (!lParam) {
|
---|
728 | TRACE("Closing avi!\n");
|
---|
729 | return TRUE;
|
---|
730 | }
|
---|
731 |
|
---|
732 | if (!hInstance)
|
---|
733 | hInstance = GetWindowLongA(hWnd, GWL_HINSTANCE);
|
---|
734 |
|
---|
735 | if (HIWORD(lParam)) {
|
---|
736 | TRACE("(\"%s\");\n", (LPSTR)lParam);
|
---|
737 |
|
---|
738 | #ifdef __WIN32OS2__
|
---|
739 | if (HIWORD(lParam)) {
|
---|
740 | //TRACE("(\"%s\");\n", (LPSTR)lParam);
|
---|
741 |
|
---|
742 | if (!ANIMATE_LoadRes(infoPtr, hInstance, (LPWSTR)lParam,unicode)) {
|
---|
743 | //TRACE("No AVI resource found!\n");
|
---|
744 | if (!ANIMATE_LoadFile(infoPtr, (LPWSTR)lParam,unicode)) {
|
---|
745 | //WARN("No AVI file found!\n");
|
---|
746 | return FALSE;
|
---|
747 | }
|
---|
748 | }
|
---|
749 | } else {
|
---|
750 | //TRACE("(%u);\n", (WORD)LOWORD(lParam));
|
---|
751 |
|
---|
752 | if (!ANIMATE_LoadRes(infoPtr,hInstance,unicode ? MAKEINTRESOURCEW((INT)lParam):(LPWSTR)MAKEINTRESOURCEA((INT)lParam),unicode)) {
|
---|
753 | //WARN("No AVI resource found!\n");
|
---|
754 | return FALSE;
|
---|
755 | }
|
---|
756 | }
|
---|
757 | #else
|
---|
758 | if (!ANIMATE_LoadResA(infoPtr, hInstance, (LPSTR)lParam)) {
|
---|
759 | TRACE("No AVI resource found!\n");
|
---|
760 | if (!ANIMATE_LoadFileA(infoPtr, (LPSTR)lParam)) {
|
---|
761 | WARN("No AVI file found!\n");
|
---|
762 | return FALSE;
|
---|
763 | }
|
---|
764 | }
|
---|
765 | } else {
|
---|
766 | TRACE("(%u);\n", (WORD)LOWORD(lParam));
|
---|
767 |
|
---|
768 | if (!ANIMATE_LoadResA(infoPtr, hInstance,
|
---|
769 | MAKEINTRESOURCEA((INT)lParam))) {
|
---|
770 | WARN("No AVI resource found!\n");
|
---|
771 | return FALSE;
|
---|
772 | }
|
---|
773 | #endif
|
---|
774 | }
|
---|
775 |
|
---|
776 | if (!ANIMATE_GetAviInfo(infoPtr)) {
|
---|
777 | WARN("Can't get AVI information\n");
|
---|
778 | ANIMATE_Free(infoPtr);
|
---|
779 | return FALSE;
|
---|
780 | }
|
---|
781 |
|
---|
782 | if (!ANIMATE_GetAviCodec(infoPtr)) {
|
---|
783 | WARN("Can't get AVI Codec\n");
|
---|
784 | ANIMATE_Free(infoPtr);
|
---|
785 | return FALSE;
|
---|
786 | }
|
---|
787 |
|
---|
788 | if (!GetWindowLongA(hWnd, GWL_STYLE) & ACS_CENTER) {
|
---|
789 | SetWindowPos(hWnd, 0, 0, 0, infoPtr->mah.dwWidth, infoPtr->mah.dwHeight,
|
---|
790 | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER);
|
---|
791 | }
|
---|
792 |
|
---|
793 | if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_AUTOPLAY) {
|
---|
794 | return ANIMATE_Play(hWnd, -1, (LPARAM)MAKELONG(0, infoPtr->mah.dwTotalFrames-1));
|
---|
795 | }
|
---|
796 |
|
---|
797 | return TRUE;
|
---|
798 | }
|
---|
799 |
|
---|
800 |
|
---|
801 | /* << ANIMATE_Open32W >> */
|
---|
802 |
|
---|
803 | static LRESULT ANIMATE_Stop(HWND hWnd, WPARAM wParam, LPARAM lParam)
|
---|
804 | {
|
---|
805 | ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
|
---|
806 |
|
---|
807 | /* nothing opened */
|
---|
808 | if (!infoPtr->hMMio)
|
---|
809 | return FALSE;
|
---|
810 |
|
---|
811 | ANIMATE_DoStop(infoPtr);
|
---|
812 | return TRUE;
|
---|
813 | }
|
---|
814 |
|
---|
815 |
|
---|
816 | static LRESULT ANIMATE_Create(HWND hWnd, WPARAM wParam, LPARAM lParam)
|
---|
817 | {
|
---|
818 | ANIMATE_INFO* infoPtr;
|
---|
819 | HMODULE hModule = LoadLibraryA("msvfw32.dll");
|
---|
820 |
|
---|
821 | if (!hModule)
|
---|
822 | return FALSE;
|
---|
823 |
|
---|
824 | /* allocate memory for info structure */
|
---|
825 | #ifdef __WIN32OS2__
|
---|
826 | infoPtr = (ANIMATE_INFO*)initControl(hWnd,sizeof(ANIMATE_INFO));
|
---|
827 | #else
|
---|
828 | infoPtr = (ANIMATE_INFO *)COMCTL32_Alloc(sizeof(ANIMATE_INFO));
|
---|
829 | #endif
|
---|
830 | if (!infoPtr) {
|
---|
831 | ERR("could not allocate info memory!\n");
|
---|
832 | return 0;
|
---|
833 | }
|
---|
834 |
|
---|
835 | /* Temporary hack until we get dllglue up and running */
|
---|
836 | infoPtr->fnICOpen = (void*)GetProcAddress(hModule, "ICOpen");
|
---|
837 | infoPtr->fnICClose = (void*)GetProcAddress(hModule, "ICClose");
|
---|
838 | infoPtr->fnICSendMessage = (void*)GetProcAddress(hModule, "ICSendMessage");
|
---|
839 | infoPtr->fnICDecompress = (void*)GetProcAddress(hModule, "ICDecompress");
|
---|
840 |
|
---|
841 | TRACE("Animate style=0x%08lx, parent=%08lx\n", GetWindowLongA(hWnd, GWL_STYLE), (DWORD)GetParent(hWnd));
|
---|
842 |
|
---|
843 | /* store crossref hWnd <-> info structure */
|
---|
844 | SetWindowLongA(hWnd, 0, (DWORD)infoPtr);
|
---|
845 | infoPtr->hWnd = hWnd;
|
---|
846 | infoPtr->transparentColor = ANIMATE_COLOR_NONE;
|
---|
847 | infoPtr->hbmPrevFrame = 0;
|
---|
848 | hModWinmm = LoadLibraryA("WINMM");
|
---|
849 |
|
---|
850 | infoPtr->fnmmioOpenA = (void*)GetProcAddress(hModWinmm, "mmioOpenA");
|
---|
851 | #ifdef __WIN32OS2__
|
---|
852 | infoPtr->fnmmioOpenW = (void*)GetProcAddress(hModWinmm, "mmioOpenW");
|
---|
853 | #endif
|
---|
854 | infoPtr->fnmmioClose = (void*)GetProcAddress(hModWinmm, "mmioClose");
|
---|
855 | infoPtr->fnmmioAscend = (void*)GetProcAddress(hModWinmm, "mmioAscend");
|
---|
856 | infoPtr->fnmmioDescend = (void*)GetProcAddress(hModWinmm, "mmioDescend");
|
---|
857 | infoPtr->fnmmioSeek = (void*)GetProcAddress(hModWinmm, "mmioSeek");
|
---|
858 | infoPtr->fnmmioRead = (void*)GetProcAddress(hModWinmm, "mmioRead");
|
---|
859 |
|
---|
860 | InitializeCriticalSection(&infoPtr->cs);
|
---|
861 |
|
---|
862 | return 0;
|
---|
863 | }
|
---|
864 |
|
---|
865 |
|
---|
866 | static LRESULT ANIMATE_Destroy(HWND hWnd, WPARAM wParam, LPARAM lParam)
|
---|
867 | {
|
---|
868 | ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
|
---|
869 |
|
---|
870 |
|
---|
871 | /* free avi data */
|
---|
872 | ANIMATE_Free(infoPtr);
|
---|
873 |
|
---|
874 | /* free animate info data */
|
---|
875 | COMCTL32_Free(infoPtr);
|
---|
876 | SetWindowLongA(hWnd, 0, 0);
|
---|
877 |
|
---|
878 | FreeLibrary(hModWinmm);
|
---|
879 | return 0;
|
---|
880 | }
|
---|
881 |
|
---|
882 |
|
---|
883 | static LRESULT ANIMATE_EraseBackground(HWND hWnd, WPARAM wParam, LPARAM lParam)
|
---|
884 | {
|
---|
885 | RECT rect;
|
---|
886 | HBRUSH hBrush = 0;
|
---|
887 |
|
---|
888 | if(GetWindowLongA(hWnd, GWL_STYLE) & ACS_TRANSPARENT)
|
---|
889 | {
|
---|
890 | hBrush = SendMessageA(GetParent(hWnd),WM_CTLCOLORSTATIC,(HDC)wParam, hWnd);
|
---|
891 | }
|
---|
892 |
|
---|
893 | GetClientRect(hWnd, &rect);
|
---|
894 | FillRect((HDC)wParam, &rect, hBrush ? hBrush : GetCurrentObject((HDC)wParam, OBJ_BRUSH));
|
---|
895 |
|
---|
896 | return TRUE;
|
---|
897 | }
|
---|
898 |
|
---|
899 | static LRESULT WINAPI ANIMATE_Size(HWND hWnd, WPARAM wParam, LPARAM lParam)
|
---|
900 | {
|
---|
901 | if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_CENTER) {
|
---|
902 | InvalidateRect(hWnd, NULL, TRUE);
|
---|
903 | }
|
---|
904 | return TRUE;
|
---|
905 | }
|
---|
906 |
|
---|
907 | static LRESULT WINAPI ANIMATE_WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
---|
908 | {
|
---|
909 | TRACE("hwnd=%x msg=%x wparam=%x lparam=%lx\n", hWnd, uMsg, wParam, lParam);
|
---|
910 | if (!ANIMATE_GetInfoPtr(hWnd) && (uMsg != WM_NCCREATE))
|
---|
911 | return DefWindowProcA(hWnd, uMsg, wParam, lParam);
|
---|
912 | switch (uMsg)
|
---|
913 | {
|
---|
914 | #ifdef __WIN32OS2__
|
---|
915 | case ACM_OPENA:
|
---|
916 | return ANIMATE_Open(hWnd,wParam,lParam,FALSE);
|
---|
917 |
|
---|
918 | case ACM_OPENW:
|
---|
919 | return ANIMATE_Open(hWnd,wParam,lParam,TRUE);
|
---|
920 | #else
|
---|
921 | case ACM_OPENA:
|
---|
922 | return ANIMATE_OpenA(hWnd, wParam, lParam);
|
---|
923 |
|
---|
924 | /* case ACM_OPEN32W: FIXME!! */
|
---|
925 | /* return ANIMATE_Open32W(hWnd, wParam, lParam); */
|
---|
926 | #endif
|
---|
927 |
|
---|
928 | case ACM_PLAY:
|
---|
929 | return ANIMATE_Play(hWnd, wParam, lParam);
|
---|
930 |
|
---|
931 | case ACM_STOP:
|
---|
932 | return ANIMATE_Stop(hWnd, wParam, lParam);
|
---|
933 |
|
---|
934 | case WM_NCCREATE:
|
---|
935 | ANIMATE_Create(hWnd, wParam, lParam);
|
---|
936 | return DefWindowProcA(hWnd, uMsg, wParam, lParam);
|
---|
937 |
|
---|
938 | case WM_NCHITTEST:
|
---|
939 | return HTTRANSPARENT;
|
---|
940 |
|
---|
941 | case WM_DESTROY:
|
---|
942 | ANIMATE_Destroy(hWnd, wParam, lParam);
|
---|
943 | return DefWindowProcA(hWnd, uMsg, wParam, lParam);
|
---|
944 |
|
---|
945 | case WM_ERASEBKGND:
|
---|
946 | ANIMATE_EraseBackground(hWnd, wParam, lParam);
|
---|
947 | break;
|
---|
948 |
|
---|
949 | /* case WM_STYLECHANGED: FIXME shall we do something ?? */
|
---|
950 |
|
---|
951 | case WM_TIMER:
|
---|
952 | if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_TRANSPARENT)
|
---|
953 | {
|
---|
954 | ANIMATE_INFO* infoPtr = ANIMATE_GetInfoPtr(hWnd);
|
---|
955 | infoPtr->hbrushBG = SendMessageA(GetParent(hWnd),WM_CTLCOLORSTATIC,(HDC)wParam, hWnd);
|
---|
956 | }
|
---|
957 | return ANIMATE_DrawFrame(ANIMATE_GetInfoPtr(hWnd));
|
---|
958 |
|
---|
959 | case WM_CLOSE:
|
---|
960 | ANIMATE_Free(ANIMATE_GetInfoPtr(hWnd));
|
---|
961 | return TRUE;
|
---|
962 |
|
---|
963 | case WM_PAINT:
|
---|
964 | {
|
---|
965 | ANIMATE_INFO* infoPtr = ANIMATE_GetInfoPtr(hWnd);
|
---|
966 |
|
---|
967 | /* the animation isn't playing, don't paint */
|
---|
968 | if(!infoPtr->uTimer && !infoPtr->hThread)
|
---|
969 | /* default paint handling */
|
---|
970 | return DefWindowProcA(hWnd, uMsg, wParam, lParam);
|
---|
971 |
|
---|
972 | if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_TRANSPARENT)
|
---|
973 | infoPtr->hbrushBG = SendMessageA(GetParent(hWnd), WM_CTLCOLORSTATIC,
|
---|
974 | (HDC)wParam, hWnd);
|
---|
975 |
|
---|
976 | if (wParam)
|
---|
977 | {
|
---|
978 | EnterCriticalSection(&infoPtr->cs);
|
---|
979 | ANIMATE_PaintFrame(infoPtr, (HDC)wParam);
|
---|
980 | LeaveCriticalSection(&infoPtr->cs);
|
---|
981 | }
|
---|
982 | else
|
---|
983 | {
|
---|
984 | PAINTSTRUCT ps;
|
---|
985 | HDC hDC = BeginPaint(hWnd, &ps);
|
---|
986 |
|
---|
987 | EnterCriticalSection(&infoPtr->cs);
|
---|
988 | ANIMATE_PaintFrame(infoPtr, hDC);
|
---|
989 | LeaveCriticalSection(&infoPtr->cs);
|
---|
990 |
|
---|
991 | EndPaint(hWnd, &ps);
|
---|
992 | }
|
---|
993 | }
|
---|
994 | break;
|
---|
995 |
|
---|
996 | case WM_SIZE:
|
---|
997 | ANIMATE_Size(hWnd, wParam, lParam);
|
---|
998 | return DefWindowProcA(hWnd, uMsg, wParam, lParam);
|
---|
999 |
|
---|
1000 | default:
|
---|
1001 | if (uMsg >= WM_USER)
|
---|
1002 | ERR("unknown msg %04x wp=%08x lp=%08lx\n", uMsg, wParam, lParam);
|
---|
1003 |
|
---|
1004 | #ifdef __WIN32OS2__
|
---|
1005 | return defComCtl32ProcA (hWnd, uMsg, wParam, lParam);
|
---|
1006 | #else
|
---|
1007 | return DefWindowProcA(hWnd, uMsg, wParam, lParam);
|
---|
1008 | #endif
|
---|
1009 | }
|
---|
1010 | return 0;
|
---|
1011 | }
|
---|
1012 |
|
---|
1013 |
|
---|
1014 | void ANIMATE_Register(void)
|
---|
1015 | {
|
---|
1016 | WNDCLASSA wndClass;
|
---|
1017 |
|
---|
1018 | ZeroMemory(&wndClass, sizeof(WNDCLASSA));
|
---|
1019 | wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
|
---|
1020 | wndClass.lpfnWndProc = (WNDPROC)ANIMATE_WindowProc;
|
---|
1021 | wndClass.cbClsExtra = 0;
|
---|
1022 | wndClass.cbWndExtra = sizeof(ANIMATE_INFO *);
|
---|
1023 | wndClass.hCursor = LoadCursorA(0, IDC_ARROWA);
|
---|
1024 | wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
|
---|
1025 | wndClass.lpszClassName = ANIMATE_CLASSA;
|
---|
1026 |
|
---|
1027 | RegisterClassA(&wndClass);
|
---|
1028 | }
|
---|
1029 |
|
---|
1030 |
|
---|
1031 | void ANIMATE_Unregister(void)
|
---|
1032 | {
|
---|
1033 | UnregisterClassA(ANIMATE_CLASSA, (HINSTANCE)NULL);
|
---|
1034 | }
|
---|
1035 |
|
---|