Changed DllOverrides so we use builtin rpcrt4, ole32, oleaut32.
[wine/testsucceed.git] / dlls / comctl32 / animate.c
blob74e0458bd959f964f93da1e90e12feb08fbb2e41
1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
2 /*
3 * Animation control
5 * Copyright 1998, 1999 Eric Kohl
6 * 1999 Eric Pouech
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * NOTES
23 * I will only improve this control once in a while.
24 * Eric <ekohl@abo.rhein-zeitung.de>
26 * TODO:
27 * - check for the 'rec ' list in some AVI files
28 * - concurrent access to infoPtr
31 #include <string.h>
32 #include "winbase.h"
33 #include "commctrl.h"
34 #include "vfw.h"
35 #include "mmsystem.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(animate);
40 static struct {
41 HMODULE hModule;
42 HIC (WINAPI *fnICOpen)(DWORD, DWORD, UINT);
43 LRESULT (WINAPI *fnICClose)(HIC);
44 LRESULT (WINAPI *fnICSendMessage)(HIC, UINT, DWORD, DWORD);
45 DWORD (WINAPIV *fnICDecompress)(HIC,DWORD,LPBITMAPINFOHEADER,LPVOID,LPBITMAPINFOHEADER,LPVOID);
46 } fnIC;
48 typedef struct
50 /* reference to input stream (file or resource) */
51 HGLOBAL hRes;
52 HMMIO hMMio; /* handle to mmio stream */
53 HWND hWnd;
54 /* information on the loaded AVI file */
55 MainAVIHeader mah;
56 AVIStreamHeader ash;
57 LPBITMAPINFOHEADER inbih;
58 LPDWORD lpIndex;
59 /* data for the decompressor */
60 HIC hic;
61 LPBITMAPINFOHEADER outbih;
62 LPVOID indata;
63 LPVOID outdata;
64 /* data for the background mechanism */
65 CRITICAL_SECTION cs;
66 HANDLE hThread;
67 UINT uTimer;
68 /* data for playing the file */
69 int nFromFrame;
70 int nToFrame;
71 int nLoop;
72 int currFrame;
73 /* tranparency info*/
74 COLORREF transparentColor;
75 HBRUSH hbrushBG;
76 HBITMAP hbmPrevFrame;
77 } ANIMATE_INFO;
79 #define ANIMATE_GetInfoPtr(hWnd) ((ANIMATE_INFO *)GetWindowLongA(hWnd, 0))
80 #define ANIMATE_COLOR_NONE 0xffffffff
82 static void ANIMATE_Notify(ANIMATE_INFO* infoPtr, UINT notif)
84 SendMessageA(GetParent(infoPtr->hWnd), WM_COMMAND,
85 MAKEWPARAM(GetDlgCtrlID(infoPtr->hWnd), notif),
86 (LPARAM)infoPtr->hWnd);
89 static BOOL ANIMATE_LoadResA(ANIMATE_INFO *infoPtr, HINSTANCE hInst, LPSTR lpName)
91 HRSRC hrsrc;
92 MMIOINFO mminfo;
93 LPVOID lpAvi;
95 hrsrc = FindResourceA(hInst, lpName, "AVI");
96 if (!hrsrc)
97 return FALSE;
99 infoPtr->hRes = LoadResource(hInst, hrsrc);
100 if (!infoPtr->hRes)
101 return FALSE;
103 lpAvi = LockResource(infoPtr->hRes);
104 if (!lpAvi)
105 return FALSE;
107 memset(&mminfo, 0, sizeof(mminfo));
108 mminfo.fccIOProc = FOURCC_MEM;
109 mminfo.pchBuffer = (LPSTR)lpAvi;
110 mminfo.cchBuffer = SizeofResource(hInst, hrsrc);
111 infoPtr->hMMio = mmioOpenA(NULL, &mminfo, MMIO_READ);
112 if (!infoPtr->hMMio) {
113 GlobalFree((HGLOBAL)lpAvi);
114 return FALSE;
117 return TRUE;
121 static BOOL ANIMATE_LoadFileA(ANIMATE_INFO *infoPtr, LPSTR lpName)
123 infoPtr->hMMio = mmioOpenA((LPSTR)lpName, NULL,
124 MMIO_ALLOCBUF | MMIO_READ | MMIO_DENYWRITE);
126 if (!infoPtr->hMMio)
127 return FALSE;
129 return TRUE;
133 static LRESULT ANIMATE_DoStop(ANIMATE_INFO *infoPtr)
135 EnterCriticalSection(&infoPtr->cs);
137 /* should stop playing */
138 if (infoPtr->hThread)
140 if (!TerminateThread(infoPtr->hThread,0))
141 WARN("could not destroy animation thread!\n");
142 infoPtr->hThread = 0;
144 if (infoPtr->uTimer) {
145 KillTimer(infoPtr->hWnd, infoPtr->uTimer);
146 infoPtr->uTimer = 0;
149 LeaveCriticalSection(&infoPtr->cs);
151 ANIMATE_Notify(infoPtr, ACN_STOP);
153 return TRUE;
157 static void ANIMATE_Free(ANIMATE_INFO *infoPtr)
159 if (infoPtr->hMMio) {
160 ANIMATE_DoStop(infoPtr);
161 mmioClose(infoPtr->hMMio, 0);
162 if (infoPtr->hRes) {
163 FreeResource(infoPtr->hRes);
164 infoPtr->hRes = 0;
166 if (infoPtr->lpIndex) {
167 HeapFree(GetProcessHeap(), 0, infoPtr->lpIndex);
168 infoPtr->lpIndex = NULL;
170 if (infoPtr->hic) {
171 fnIC.fnICClose(infoPtr->hic);
172 infoPtr->hic = 0;
174 if (infoPtr->inbih) {
175 HeapFree(GetProcessHeap(), 0, infoPtr->inbih);
176 infoPtr->inbih = NULL;
178 if (infoPtr->outbih) {
179 HeapFree(GetProcessHeap(), 0, infoPtr->outbih);
180 infoPtr->outbih = NULL;
182 if( infoPtr->indata )
184 HeapFree(GetProcessHeap(), 0, infoPtr->indata);
185 infoPtr->indata = NULL;
187 if( infoPtr->outdata )
189 HeapFree(GetProcessHeap(), 0, infoPtr->outdata);
190 infoPtr->outdata = NULL;
192 if( infoPtr->hbmPrevFrame )
194 DeleteObject(infoPtr->hbmPrevFrame);
195 infoPtr->hbmPrevFrame = 0;
197 infoPtr->indata = infoPtr->outdata = NULL;
198 infoPtr->hWnd = 0;
199 infoPtr->hMMio = 0;
201 memset(&infoPtr->mah, 0, sizeof(infoPtr->mah));
202 memset(&infoPtr->ash, 0, sizeof(infoPtr->ash));
203 infoPtr->nFromFrame = infoPtr->nToFrame = infoPtr->nLoop = infoPtr->currFrame = 0;
205 infoPtr->transparentColor = ANIMATE_COLOR_NONE;
208 static void ANIMATE_TransparentBlt(ANIMATE_INFO* infoPtr, HDC hdcDest, HDC hdcSource)
210 HDC hdcMask;
211 HBITMAP hbmMask;
212 HBITMAP hbmOld;
214 /* create a transparency mask */
215 hdcMask = CreateCompatibleDC(hdcDest);
216 hbmMask = CreateBitmap(infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, 1,1,NULL);
217 hbmOld = SelectObject(hdcMask, hbmMask);
219 SetBkColor(hdcSource,infoPtr->transparentColor);
220 BitBlt(hdcMask,0,0,infoPtr->inbih->biWidth, infoPtr->inbih->biHeight,hdcSource,0,0,SRCCOPY);
222 /* mask the source bitmap */
223 SetBkColor(hdcSource, RGB(0,0,0));
224 SetTextColor(hdcSource, RGB(255,255,255));
225 BitBlt(hdcSource, 0, 0, infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, hdcMask, 0, 0, SRCAND);
227 /* mask the destination bitmap */
228 SetBkColor(hdcDest, RGB(255,255,255));
229 SetTextColor(hdcDest, RGB(0,0,0));
230 BitBlt(hdcDest, 0, 0, infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, hdcMask, 0, 0, SRCAND);
232 /* combine source and destination */
233 BitBlt(hdcDest,0,0,infoPtr->inbih->biWidth, infoPtr->inbih->biHeight,hdcSource,0,0,SRCPAINT);
235 SelectObject(hdcMask, hbmOld);
236 DeleteObject(hbmMask);
237 DeleteDC(hdcMask);
240 static LRESULT ANIMATE_PaintFrame(ANIMATE_INFO* infoPtr, HDC hDC)
242 void* pBitmapData = NULL;
243 LPBITMAPINFO pBitmapInfo = NULL;
245 HDC hdcMem;
246 HBITMAP hbmOld;
248 int nOffsetX = 0;
249 int nOffsetY = 0;
251 int nWidth;
252 int nHeight;
254 if (!hDC || !infoPtr->inbih)
255 return TRUE;
257 if (infoPtr->hic )
259 pBitmapData = infoPtr->outdata;
260 pBitmapInfo = (LPBITMAPINFO)infoPtr->outbih;
262 nWidth = infoPtr->outbih->biWidth;
263 nHeight = infoPtr->outbih->biHeight;
264 } else
266 pBitmapData = infoPtr->indata;
267 pBitmapInfo = (LPBITMAPINFO)infoPtr->inbih;
269 nWidth = infoPtr->inbih->biWidth;
270 nHeight = infoPtr->inbih->biHeight;
273 if(!infoPtr->hbmPrevFrame)
275 infoPtr->hbmPrevFrame=CreateCompatibleBitmap(hDC, nWidth,nHeight );
278 SetDIBits(hDC, infoPtr->hbmPrevFrame, 0, nHeight, pBitmapData, (LPBITMAPINFO)pBitmapInfo, DIB_RGB_COLORS);
280 hdcMem = CreateCompatibleDC(hDC);
281 hbmOld = SelectObject(hdcMem, infoPtr->hbmPrevFrame);
284 * we need to get the transparent color even without ACS_TRANSPARENT,
285 * because the style can be changed later on and the color should always
286 * be obtained in the first frame
288 if(infoPtr->transparentColor == ANIMATE_COLOR_NONE)
290 infoPtr->transparentColor = GetPixel(hdcMem,0,0);
293 if(GetWindowLongA(infoPtr->hWnd, GWL_STYLE) & ACS_TRANSPARENT)
295 HDC hdcFinal = CreateCompatibleDC(hDC);
296 HBITMAP hbmFinal = CreateCompatibleBitmap(hDC,nWidth, nHeight);
297 HBITMAP hbmOld2 = SelectObject(hdcFinal, hbmFinal);
298 RECT rect;
300 rect.left = 0;
301 rect.top = 0;
302 rect.right = nWidth;
303 rect.bottom = nHeight;
305 if(!infoPtr->hbrushBG)
306 infoPtr->hbrushBG = GetCurrentObject(hDC, OBJ_BRUSH);
308 FillRect(hdcFinal, &rect, infoPtr->hbrushBG);
309 ANIMATE_TransparentBlt(infoPtr, hdcFinal, hdcMem);
311 SelectObject(hdcFinal, hbmOld2);
312 SelectObject(hdcMem, hbmFinal);
313 DeleteDC(hdcFinal);
314 DeleteObject(infoPtr->hbmPrevFrame);
315 infoPtr->hbmPrevFrame = hbmFinal;
318 if (GetWindowLongA(infoPtr->hWnd, GWL_STYLE) & ACS_CENTER)
320 RECT rect;
322 GetWindowRect(infoPtr->hWnd, &rect);
323 nOffsetX = ((rect.right - rect.left) - nWidth)/2;
324 nOffsetY = ((rect.bottom - rect.top) - nHeight)/2;
326 BitBlt(hDC, nOffsetX, nOffsetY, nWidth, nHeight, hdcMem, 0, 0, SRCCOPY);
328 SelectObject(hdcMem, hbmOld);
329 DeleteDC(hdcMem);
330 return TRUE;
333 static LRESULT ANIMATE_DrawFrame(ANIMATE_INFO* infoPtr)
335 HDC hDC;
337 TRACE("Drawing frame %d (loop %d)\n", infoPtr->currFrame, infoPtr->nLoop);
339 EnterCriticalSection(&infoPtr->cs);
341 mmioSeek(infoPtr->hMMio, infoPtr->lpIndex[infoPtr->currFrame], SEEK_SET);
342 mmioRead(infoPtr->hMMio, infoPtr->indata, infoPtr->ash.dwSuggestedBufferSize);
344 if (infoPtr->hic &&
345 fnIC.fnICDecompress(infoPtr->hic, 0, infoPtr->inbih, infoPtr->indata,
346 infoPtr->outbih, infoPtr->outdata) != ICERR_OK) {
347 LeaveCriticalSection(&infoPtr->cs);
348 WARN("Decompression error\n");
349 return FALSE;
352 if ((hDC = GetDC(infoPtr->hWnd)) != 0) {
353 ANIMATE_PaintFrame(infoPtr, hDC);
354 ReleaseDC(infoPtr->hWnd, hDC);
357 if (infoPtr->currFrame++ >= infoPtr->nToFrame) {
358 infoPtr->currFrame = infoPtr->nFromFrame;
359 if (infoPtr->nLoop != -1) {
360 if (--infoPtr->nLoop == 0) {
361 ANIMATE_DoStop(infoPtr);
365 LeaveCriticalSection(&infoPtr->cs);
367 return TRUE;
370 static DWORD CALLBACK ANIMATE_AnimationThread(LPVOID ptr_)
372 ANIMATE_INFO* infoPtr = (ANIMATE_INFO*)ptr_;
373 HDC hDC;
375 if(!infoPtr)
377 WARN("animation structure undefined!\n");
378 return FALSE;
381 while(1)
383 if(GetWindowLongA(infoPtr->hWnd, GWL_STYLE) & ACS_TRANSPARENT)
385 hDC = GetDC(infoPtr->hWnd);
386 /* sometimes the animation window will be destroyed in between
387 * by the main program, so a ReleaseDC() error msg is possible */
388 infoPtr->hbrushBG = SendMessageA(GetParent(infoPtr->hWnd),WM_CTLCOLORSTATIC,hDC, infoPtr->hWnd);
389 ReleaseDC(infoPtr->hWnd,hDC);
392 EnterCriticalSection(&infoPtr->cs);
393 ANIMATE_DrawFrame(infoPtr);
394 LeaveCriticalSection(&infoPtr->cs);
396 /* time is in microseconds, we should convert it to milliseconds */
397 Sleep((infoPtr->mah.dwMicroSecPerFrame+500)/1000);
399 return TRUE;
402 static LRESULT ANIMATE_Play(HWND hWnd, WPARAM wParam, LPARAM lParam)
404 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
406 /* nothing opened */
407 if (!infoPtr->hMMio)
408 return FALSE;
410 if (infoPtr->hThread || infoPtr->uTimer) {
411 FIXME("Already playing ? what should I do ??\n");
412 ANIMATE_DoStop(infoPtr);
415 infoPtr->nFromFrame = (INT)LOWORD(lParam);
416 infoPtr->nToFrame = (INT)HIWORD(lParam);
417 infoPtr->nLoop = (INT)wParam;
419 if (infoPtr->nToFrame == 0xFFFF)
420 infoPtr->nToFrame = infoPtr->mah.dwTotalFrames - 1;
422 TRACE("(repeat=%d from=%d to=%d);\n",
423 infoPtr->nLoop, infoPtr->nFromFrame, infoPtr->nToFrame);
425 if (infoPtr->nFromFrame >= infoPtr->nToFrame ||
426 infoPtr->nToFrame >= infoPtr->mah.dwTotalFrames)
427 return FALSE;
429 infoPtr->currFrame = infoPtr->nFromFrame;
431 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_TIMER) {
432 TRACE("Using a timer\n");
433 /* create a timer to display AVI */
434 infoPtr->uTimer = SetTimer(hWnd, 1, infoPtr->mah.dwMicroSecPerFrame / 1000, NULL);
435 } else {
436 DWORD threadID;
438 TRACE("Using an animation thread\n");
439 infoPtr->hThread = CreateThread(0,0,ANIMATE_AnimationThread,(LPVOID)infoPtr,0,0 &threadID);
440 if(!infoPtr->hThread)
442 ERR("Could not create animation thread!\n");
443 return FALSE;
448 ANIMATE_Notify(infoPtr, ACN_START);
450 return TRUE;
454 static BOOL ANIMATE_GetAviInfo(ANIMATE_INFO *infoPtr)
456 MMCKINFO ckMainRIFF;
457 MMCKINFO mmckHead;
458 MMCKINFO mmckList;
459 MMCKINFO mmckInfo;
460 DWORD numFrame;
461 DWORD insize;
463 if (mmioDescend(infoPtr->hMMio, &ckMainRIFF, NULL, 0) != 0) {
464 WARN("Can't find 'RIFF' chunk\n");
465 return FALSE;
468 if ((ckMainRIFF.ckid != FOURCC_RIFF) ||
469 (ckMainRIFF.fccType != mmioFOURCC('A', 'V', 'I', ' '))) {
470 WARN("Can't find 'AVI ' chunk\n");
471 return FALSE;
474 mmckHead.fccType = mmioFOURCC('h', 'd', 'r', 'l');
475 if (mmioDescend(infoPtr->hMMio, &mmckHead, &ckMainRIFF, MMIO_FINDLIST) != 0) {
476 WARN("Can't find 'hdrl' list\n");
477 return FALSE;
480 mmckInfo.ckid = mmioFOURCC('a', 'v', 'i', 'h');
481 if (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckHead, MMIO_FINDCHUNK) != 0) {
482 WARN("Can't find 'avih' chunk\n");
483 return FALSE;
486 mmioRead(infoPtr->hMMio, (LPSTR)&infoPtr->mah, sizeof(infoPtr->mah));
488 TRACE("mah.dwMicroSecPerFrame=%ld\n", infoPtr->mah.dwMicroSecPerFrame);
489 TRACE("mah.dwMaxBytesPerSec=%ld\n", infoPtr->mah.dwMaxBytesPerSec);
490 TRACE("mah.dwPaddingGranularity=%ld\n", infoPtr->mah.dwPaddingGranularity);
491 TRACE("mah.dwFlags=%ld\n", infoPtr->mah.dwFlags);
492 TRACE("mah.dwTotalFrames=%ld\n", infoPtr->mah.dwTotalFrames);
493 TRACE("mah.dwInitialFrames=%ld\n", infoPtr->mah.dwInitialFrames);
494 TRACE("mah.dwStreams=%ld\n", infoPtr->mah.dwStreams);
495 TRACE("mah.dwSuggestedBufferSize=%ld\n", infoPtr->mah.dwSuggestedBufferSize);
496 TRACE("mah.dwWidth=%ld\n", infoPtr->mah.dwWidth);
497 TRACE("mah.dwHeight=%ld\n", infoPtr->mah.dwHeight);
499 mmioAscend(infoPtr->hMMio, &mmckInfo, 0);
501 mmckList.fccType = mmioFOURCC('s', 't', 'r', 'l');
502 if (mmioDescend(infoPtr->hMMio, &mmckList, &mmckHead, MMIO_FINDLIST) != 0) {
503 WARN("Can't find 'strl' list\n");
504 return FALSE;
507 mmckInfo.ckid = mmioFOURCC('s', 't', 'r', 'h');
508 if (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, MMIO_FINDCHUNK) != 0) {
509 WARN("Can't find 'strh' chunk\n");
510 return FALSE;
513 mmioRead(infoPtr->hMMio, (LPSTR)&infoPtr->ash, sizeof(infoPtr->ash));
515 TRACE("ash.fccType='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr->ash.fccType)),
516 HIBYTE(LOWORD(infoPtr->ash.fccType)),
517 LOBYTE(HIWORD(infoPtr->ash.fccType)),
518 HIBYTE(HIWORD(infoPtr->ash.fccType)));
519 TRACE("ash.fccHandler='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr->ash.fccHandler)),
520 HIBYTE(LOWORD(infoPtr->ash.fccHandler)),
521 LOBYTE(HIWORD(infoPtr->ash.fccHandler)),
522 HIBYTE(HIWORD(infoPtr->ash.fccHandler)));
523 TRACE("ash.dwFlags=%ld\n", infoPtr->ash.dwFlags);
524 TRACE("ash.wPriority=%d\n", infoPtr->ash.wPriority);
525 TRACE("ash.wLanguage=%d\n", infoPtr->ash.wLanguage);
526 TRACE("ash.dwInitialFrames=%ld\n", infoPtr->ash.dwInitialFrames);
527 TRACE("ash.dwScale=%ld\n", infoPtr->ash.dwScale);
528 TRACE("ash.dwRate=%ld\n", infoPtr->ash.dwRate);
529 TRACE("ash.dwStart=%ld\n", infoPtr->ash.dwStart);
530 TRACE("ash.dwLength=%ld\n", infoPtr->ash.dwLength);
531 TRACE("ash.dwSuggestedBufferSize=%ld\n", infoPtr->ash.dwSuggestedBufferSize);
532 TRACE("ash.dwQuality=%ld\n", infoPtr->ash.dwQuality);
533 TRACE("ash.dwSampleSize=%ld\n", infoPtr->ash.dwSampleSize);
534 TRACE("ash.rcFrame=(%d,%d,%d,%d)\n", infoPtr->ash.rcFrame.top, infoPtr->ash.rcFrame.left,
535 infoPtr->ash.rcFrame.bottom, infoPtr->ash.rcFrame.right);
537 mmioAscend(infoPtr->hMMio, &mmckInfo, 0);
539 mmckInfo.ckid = mmioFOURCC('s', 't', 'r', 'f');
540 if (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, MMIO_FINDCHUNK) != 0) {
541 WARN("Can't find 'strh' chunk\n");
542 return FALSE;
545 infoPtr->inbih = HeapAlloc(GetProcessHeap(), 0, mmckInfo.cksize);
546 if (!infoPtr->inbih) {
547 WARN("Can't alloc input BIH\n");
548 return FALSE;
551 mmioRead(infoPtr->hMMio, (LPSTR)infoPtr->inbih, mmckInfo.cksize);
553 TRACE("bih.biSize=%ld\n", infoPtr->inbih->biSize);
554 TRACE("bih.biWidth=%ld\n", infoPtr->inbih->biWidth);
555 TRACE("bih.biHeight=%ld\n", infoPtr->inbih->biHeight);
556 TRACE("bih.biPlanes=%d\n", infoPtr->inbih->biPlanes);
557 TRACE("bih.biBitCount=%d\n", infoPtr->inbih->biBitCount);
558 TRACE("bih.biCompression=%ld\n", infoPtr->inbih->biCompression);
559 TRACE("bih.biSizeImage=%ld\n", infoPtr->inbih->biSizeImage);
560 TRACE("bih.biXPelsPerMeter=%ld\n", infoPtr->inbih->biXPelsPerMeter);
561 TRACE("bih.biYPelsPerMeter=%ld\n", infoPtr->inbih->biYPelsPerMeter);
562 TRACE("bih.biClrUsed=%ld\n", infoPtr->inbih->biClrUsed);
563 TRACE("bih.biClrImportant=%ld\n", infoPtr->inbih->biClrImportant);
565 mmioAscend(infoPtr->hMMio, &mmckInfo, 0);
567 mmioAscend(infoPtr->hMMio, &mmckList, 0);
569 #if 0
570 /* an AVI has 0 or 1 video stream, and to be animated should not contain
571 * an audio stream, so only one strl is allowed
573 mmckList.fccType = mmioFOURCC('s', 't', 'r', 'l');
574 if (mmioDescend(infoPtr->hMMio, &mmckList, &mmckHead, MMIO_FINDLIST) == 0) {
575 WARN("There should be a single 'strl' list\n");
576 return FALSE;
578 #endif
580 mmioAscend(infoPtr->hMMio, &mmckHead, 0);
582 /* no need to read optional JUNK chunk */
584 mmckList.fccType = mmioFOURCC('m', 'o', 'v', 'i');
585 if (mmioDescend(infoPtr->hMMio, &mmckList, &ckMainRIFF, MMIO_FINDLIST) != 0) {
586 WARN("Can't find 'movi' list\n");
587 return FALSE;
590 /* FIXME: should handle the 'rec ' LIST when present */
592 infoPtr->lpIndex = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
593 infoPtr->mah.dwTotalFrames * sizeof(DWORD));
594 if (!infoPtr->lpIndex) {
595 WARN("Can't alloc index array\n");
596 return FALSE;
599 numFrame = insize = 0;
600 while (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, 0) == 0 &&
601 numFrame < infoPtr->mah.dwTotalFrames) {
602 infoPtr->lpIndex[numFrame] = mmckInfo.dwDataOffset;
603 if (insize < mmckInfo.cksize)
604 insize = mmckInfo.cksize;
605 numFrame++;
606 mmioAscend(infoPtr->hMMio, &mmckInfo, 0);
608 if (numFrame != infoPtr->mah.dwTotalFrames) {
609 WARN("Found %ld frames (/%ld)\n", numFrame, infoPtr->mah.dwTotalFrames);
610 return FALSE;
612 if (insize > infoPtr->ash.dwSuggestedBufferSize) {
613 WARN("insize=%ld suggestedSize=%ld\n", insize, infoPtr->ash.dwSuggestedBufferSize);
614 infoPtr->ash.dwSuggestedBufferSize = insize;
617 infoPtr->indata = HeapAlloc(GetProcessHeap(), 0, infoPtr->ash.dwSuggestedBufferSize);
618 if (!infoPtr->indata) {
619 WARN("Can't alloc input buffer\n");
620 return FALSE;
623 return TRUE;
627 static BOOL ANIMATE_GetAviCodec(ANIMATE_INFO *infoPtr)
629 DWORD outSize;
631 /* check uncompressed AVI */
632 if ((infoPtr->ash.fccHandler == mmioFOURCC('D', 'I', 'B', ' ')) ||
633 (infoPtr->ash.fccHandler == mmioFOURCC('R', 'L', 'E', ' ')) ||
634 (infoPtr->ash.fccHandler == mmioFOURCC(0, 0, 0, 0)))
636 infoPtr->hic = 0;
637 return TRUE;
640 /* try to get a decompressor for that type */
641 infoPtr->hic = fnIC.fnICOpen(ICTYPE_VIDEO, infoPtr->ash.fccHandler, ICMODE_DECOMPRESS);
642 if (!infoPtr->hic) {
643 WARN("Can't load codec for the file\n");
644 return FALSE;
647 outSize = fnIC.fnICSendMessage(infoPtr->hic, ICM_DECOMPRESS_GET_FORMAT,
648 (DWORD)infoPtr->inbih, 0L);
650 infoPtr->outbih = HeapAlloc(GetProcessHeap(), 0, outSize);
651 if (!infoPtr->outbih) {
652 WARN("Can't alloc output BIH\n");
653 return FALSE;
656 if (fnIC.fnICSendMessage(infoPtr->hic, ICM_DECOMPRESS_GET_FORMAT,
657 (DWORD)infoPtr->inbih, (DWORD)infoPtr->outbih) != ICERR_OK) {
658 WARN("Can't get output BIH\n");
659 return FALSE;
662 infoPtr->outdata = HeapAlloc(GetProcessHeap(), 0, infoPtr->outbih->biSizeImage);
663 if (!infoPtr->outdata) {
664 WARN("Can't alloc output buffer\n");
665 return FALSE;
668 if (fnIC.fnICSendMessage(infoPtr->hic, ICM_DECOMPRESS_BEGIN,
669 (DWORD)infoPtr->inbih, (DWORD)infoPtr->outbih) != ICERR_OK) {
670 WARN("Can't begin decompression\n");
671 return FALSE;
674 return TRUE;
677 static LRESULT ANIMATE_OpenA(HWND hWnd, WPARAM wParam, LPARAM lParam)
679 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
680 HINSTANCE hInstance = (HINSTANCE)wParam;
682 ANIMATE_Free(infoPtr);
683 infoPtr->hWnd = hWnd;
685 if (!lParam) {
686 TRACE("Closing avi!\n");
687 return TRUE;
690 if (!hInstance)
691 hInstance = GetWindowLongA(hWnd, GWL_HINSTANCE);
693 if (HIWORD(lParam)) {
694 TRACE("(\"%s\");\n", (LPSTR)lParam);
696 if (!ANIMATE_LoadResA(infoPtr, hInstance, (LPSTR)lParam)) {
697 TRACE("No AVI resource found!\n");
698 if (!ANIMATE_LoadFileA(infoPtr, (LPSTR)lParam)) {
699 WARN("No AVI file found!\n");
700 return FALSE;
703 } else {
704 TRACE("(%u);\n", (WORD)LOWORD(lParam));
706 if (!ANIMATE_LoadResA(infoPtr, hInstance,
707 MAKEINTRESOURCEA((INT)lParam))) {
708 WARN("No AVI resource found!\n");
709 return FALSE;
713 if (!ANIMATE_GetAviInfo(infoPtr)) {
714 WARN("Can't get AVI information\n");
715 ANIMATE_Free(infoPtr);
716 return FALSE;
719 if (!ANIMATE_GetAviCodec(infoPtr)) {
720 WARN("Can't get AVI Codec\n");
721 ANIMATE_Free(infoPtr);
722 return FALSE;
725 if (!GetWindowLongA(hWnd, GWL_STYLE) & ACS_CENTER) {
726 SetWindowPos(hWnd, 0, 0, 0, infoPtr->mah.dwWidth, infoPtr->mah.dwHeight,
727 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER);
730 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_AUTOPLAY) {
731 return ANIMATE_Play(hWnd, -1, (LPARAM)MAKELONG(0, infoPtr->mah.dwTotalFrames-1));
734 return TRUE;
738 /* << ANIMATE_Open32W >> */
740 static LRESULT ANIMATE_Stop(HWND hWnd, WPARAM wParam, LPARAM lParam)
742 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
744 /* nothing opened */
745 if (!infoPtr->hMMio)
746 return FALSE;
748 ANIMATE_DoStop(infoPtr);
749 return TRUE;
753 static LRESULT ANIMATE_Create(HWND hWnd, WPARAM wParam, LPARAM lParam)
755 ANIMATE_INFO* infoPtr;
757 if (!fnIC.hModule) /* FIXME: not thread safe */
759 /* since there's a circular dep between msvfw32 and comctl32, we could either:
760 * - fix the build chain to allow this circular dep
761 * - handle it by hand
762 * AJ wants the latter :-(
764 fnIC.hModule = LoadLibraryA("msvfw32.dll");
765 if (!fnIC.hModule) return FALSE;
767 fnIC.fnICOpen = (void*)GetProcAddress(fnIC.hModule, "ICOpen");
768 fnIC.fnICClose = (void*)GetProcAddress(fnIC.hModule, "ICClose");
769 fnIC.fnICSendMessage = (void*)GetProcAddress(fnIC.hModule, "ICSendMessage");
770 fnIC.fnICDecompress = (void*)GetProcAddress(fnIC.hModule, "ICDecompress");
773 /* allocate memory for info structure */
774 infoPtr = (ANIMATE_INFO *)COMCTL32_Alloc(sizeof(ANIMATE_INFO));
775 if (!infoPtr) {
776 ERR("could not allocate info memory!\n");
777 return 0;
780 TRACE("Animate style=0x%08lx, parent=%08lx\n", GetWindowLongA(hWnd, GWL_STYLE), (DWORD)GetParent(hWnd));
782 /* store crossref hWnd <-> info structure */
783 SetWindowLongA(hWnd, 0, (DWORD)infoPtr);
784 infoPtr->hWnd = hWnd;
785 infoPtr->transparentColor = ANIMATE_COLOR_NONE;
786 infoPtr->hbmPrevFrame = 0;
788 InitializeCriticalSection(&infoPtr->cs);
790 return 0;
794 static LRESULT ANIMATE_Destroy(HWND hWnd, WPARAM wParam, LPARAM lParam)
796 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
799 /* free avi data */
800 ANIMATE_Free(infoPtr);
802 /* free animate info data */
803 COMCTL32_Free(infoPtr);
804 SetWindowLongA(hWnd, 0, 0);
806 return 0;
810 static LRESULT ANIMATE_EraseBackground(HWND hWnd, WPARAM wParam, LPARAM lParam)
812 RECT rect;
813 HBRUSH hBrush = 0;
815 if(GetWindowLongA(hWnd, GWL_STYLE) & ACS_TRANSPARENT)
817 hBrush = SendMessageA(GetParent(hWnd),WM_CTLCOLORSTATIC,(HDC)wParam, hWnd);
820 GetClientRect(hWnd, &rect);
821 FillRect((HDC)wParam, &rect, hBrush ? hBrush : GetCurrentObject((HDC)wParam, OBJ_BRUSH));
823 return TRUE;
826 static LRESULT WINAPI ANIMATE_Size(HWND hWnd, WPARAM wParam, LPARAM lParam)
828 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_CENTER) {
829 InvalidateRect(hWnd, NULL, TRUE);
831 return TRUE;
834 static LRESULT WINAPI ANIMATE_WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
836 TRACE("hwnd=%x msg=%x wparam=%x lparam=%lx\n", hWnd, uMsg, wParam, lParam);
837 if (!ANIMATE_GetInfoPtr(hWnd) && (uMsg != WM_NCCREATE))
838 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
839 switch (uMsg)
841 case ACM_OPENA:
842 return ANIMATE_OpenA(hWnd, wParam, lParam);
844 /* case ACM_OPEN32W: FIXME!! */
845 /* return ANIMATE_Open32W(hWnd, wParam, lParam); */
847 case ACM_PLAY:
848 return ANIMATE_Play(hWnd, wParam, lParam);
850 case ACM_STOP:
851 return ANIMATE_Stop(hWnd, wParam, lParam);
853 case WM_NCCREATE:
854 ANIMATE_Create(hWnd, wParam, lParam);
855 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
857 case WM_NCHITTEST:
858 return HTTRANSPARENT;
860 case WM_DESTROY:
861 ANIMATE_Destroy(hWnd, wParam, lParam);
862 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
864 case WM_ERASEBKGND:
865 ANIMATE_EraseBackground(hWnd, wParam, lParam);
866 break;
868 /* case WM_STYLECHANGED: FIXME shall we do something ?? */
870 case WM_TIMER:
871 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_TRANSPARENT)
873 ANIMATE_INFO* infoPtr = ANIMATE_GetInfoPtr(hWnd);
874 infoPtr->hbrushBG = SendMessageA(GetParent(hWnd),WM_CTLCOLORSTATIC,(HDC)wParam, hWnd);
876 return ANIMATE_DrawFrame(ANIMATE_GetInfoPtr(hWnd));
878 case WM_CLOSE:
879 ANIMATE_Free(ANIMATE_GetInfoPtr(hWnd));
880 return TRUE;
882 case WM_PAINT:
884 ANIMATE_INFO* infoPtr = ANIMATE_GetInfoPtr(hWnd);
886 /* the animation isn't playing, don't paint */
887 if(!infoPtr->uTimer && !infoPtr->hThread)
888 /* default paint handling */
889 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
891 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_TRANSPARENT)
892 infoPtr->hbrushBG = SendMessageA(GetParent(hWnd), WM_CTLCOLORSTATIC,
893 (HDC)wParam, hWnd);
895 if (wParam)
897 EnterCriticalSection(&infoPtr->cs);
898 ANIMATE_PaintFrame(infoPtr, (HDC)wParam);
899 LeaveCriticalSection(&infoPtr->cs);
901 else
903 PAINTSTRUCT ps;
904 HDC hDC = BeginPaint(hWnd, &ps);
906 EnterCriticalSection(&infoPtr->cs);
907 ANIMATE_PaintFrame(infoPtr, hDC);
908 LeaveCriticalSection(&infoPtr->cs);
910 EndPaint(hWnd, &ps);
913 break;
915 case WM_SIZE:
916 ANIMATE_Size(hWnd, wParam, lParam);
917 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
919 default:
920 if (uMsg >= WM_USER)
921 ERR("unknown msg %04x wp=%08x lp=%08lx\n", uMsg, wParam, lParam);
923 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
925 return 0;
928 void ANIMATE_Register(void)
930 WNDCLASSA wndClass;
932 ZeroMemory(&wndClass, sizeof(WNDCLASSA));
933 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
934 wndClass.lpfnWndProc = (WNDPROC)ANIMATE_WindowProc;
935 wndClass.cbClsExtra = 0;
936 wndClass.cbWndExtra = sizeof(ANIMATE_INFO *);
937 wndClass.hCursor = LoadCursorA(0, IDC_ARROWA);
938 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
939 wndClass.lpszClassName = ANIMATE_CLASSA;
941 RegisterClassA(&wndClass);
945 void ANIMATE_Unregister(void)
947 UnregisterClassA(ANIMATE_CLASSA, (HINSTANCE)NULL);