X11DRV_SetFocus: really don't mess with focus for managed windows.
[wine/multimedia.git] / dlls / comctl32 / animate.c
blob47f27a4c9aa63aeb67fe4840cd7b858026f4df09
1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
2 /*
3 * Animation control
5 * Copyright 1998, 1999 Eric Kohl
6 * 1999 Eric Pouech
8 * NOTES
9 * I will only improve this control once in a while.
10 * Eric <ekohl@abo.rhein-zeitung.de>
12 * TODO:
13 * - check for the 'rec ' list in some AVI files
14 * - implement some missing flags (ACS_TRANSPARENT and ACS_CENTER)
15 * - protection between service thread and wndproc messages handling
16 * concurrent access to infoPtr
20 #include "winbase.h"
21 #include "commctrl.h"
22 #include "driver.h"
23 #include "animate.h"
24 #include "mmsystem.h"
25 #include "services.h"
26 #include "debugtools.h"
28 DEFAULT_DEBUG_CHANNEL(animate);
30 #define ANIMATE_GetInfoPtr(hWnd) ((ANIMATE_INFO *)GetWindowLongA(hWnd, 0))
32 HMODULE hModWinmm;
34 static void ANIMATE_Notify(ANIMATE_INFO* infoPtr, UINT notif)
36 SendMessageA(GetParent(infoPtr->hWnd), WM_COMMAND,
37 MAKEWPARAM(GetDlgCtrlID(infoPtr->hWnd), notif),
38 (LPARAM)infoPtr->hWnd);
41 static BOOL ANIMATE_LoadResA(ANIMATE_INFO *infoPtr, HINSTANCE hInst, LPSTR lpName)
43 HRSRC hrsrc;
44 MMIOINFO mminfo;
45 LPVOID lpAvi;
47 hrsrc = FindResourceA(hInst, lpName, "AVI");
48 if (!hrsrc)
49 return FALSE;
51 infoPtr->hRes = LoadResource(hInst, hrsrc);
52 if (!infoPtr->hRes)
53 return FALSE;
55 lpAvi = LockResource(infoPtr->hRes);
56 if (!lpAvi)
57 return FALSE;
59 memset(&mminfo, 0, sizeof(mminfo));
60 mminfo.fccIOProc = FOURCC_MEM;
61 mminfo.pchBuffer = (LPSTR)lpAvi;
62 mminfo.cchBuffer = SizeofResource(hInst, hrsrc);
63 infoPtr->hMMio = infoPtr->fnmmioOpenA(NULL, &mminfo, MMIO_READ);
65 if (!infoPtr->hMMio) {
66 GlobalFree((HGLOBAL)lpAvi);
67 return FALSE;
70 return TRUE;
74 static BOOL ANIMATE_LoadFileA(ANIMATE_INFO *infoPtr, LPSTR lpName)
76 infoPtr->hMMio = infoPtr->fnmmioOpenA((LPSTR)lpName, NULL,
77 MMIO_ALLOCBUF | MMIO_READ | MMIO_DENYWRITE);
79 if (!infoPtr->hMMio)
80 return FALSE;
82 return TRUE;
86 static LRESULT ANIMATE_DoStop(ANIMATE_INFO *infoPtr)
88 EnterCriticalSection(&infoPtr->cs);
90 /* should stop playing */
91 if (infoPtr->hService) {
92 SERVICE_Delete(infoPtr->hService);
93 infoPtr->hService = 0;
95 if (infoPtr->uTimer) {
96 KillTimer(infoPtr->hWnd, infoPtr->uTimer);
97 infoPtr->uTimer = 0;
100 LeaveCriticalSection(&infoPtr->cs);
102 ANIMATE_Notify(infoPtr, ACN_STOP);
104 return TRUE;
108 static void ANIMATE_Free(ANIMATE_INFO *infoPtr)
110 if (infoPtr->hMMio) {
111 ANIMATE_DoStop(infoPtr);
112 infoPtr->fnmmioClose(infoPtr->hMMio, 0);
113 if (infoPtr->hRes) {
114 FreeResource(infoPtr->hRes);
115 infoPtr->hRes = 0;
117 if (infoPtr->lpIndex) {
118 HeapFree(GetProcessHeap(), 0, infoPtr->lpIndex);
119 infoPtr->lpIndex = NULL;
121 if (infoPtr->hic) {
122 (infoPtr->fnICClose)(infoPtr->hic);
123 infoPtr->hic = 0;
125 if (infoPtr->inbih) {
126 HeapFree(GetProcessHeap(), 0, infoPtr->inbih);
127 infoPtr->inbih = NULL;
129 if (infoPtr->outbih) {
130 HeapFree(GetProcessHeap(), 0, infoPtr->outbih);
131 infoPtr->outbih = NULL;
133 HeapFree(GetProcessHeap(), 0, infoPtr->indata);
134 HeapFree(GetProcessHeap(), 0, infoPtr->outdata);
135 infoPtr->indata = infoPtr->outdata = NULL;
136 infoPtr->hWnd = 0;
137 infoPtr->hMMio = 0;
138 memset(&infoPtr->mah, 0, sizeof(infoPtr->mah));
139 memset(&infoPtr->ash, 0, sizeof(infoPtr->ash));
140 infoPtr->nFromFrame = infoPtr->nToFrame = infoPtr->nLoop = infoPtr->currFrame = 0;
145 static LRESULT ANIMATE_PaintFrame(ANIMATE_INFO* infoPtr, HDC hDC)
147 if (!hDC || !infoPtr->inbih)
148 return TRUE;
149 if (infoPtr->hic)
150 StretchDIBits(hDC, 0, 0, infoPtr->outbih->biWidth, infoPtr->outbih->biHeight,
151 0, 0, infoPtr->outbih->biWidth, infoPtr->outbih->biHeight,
152 infoPtr->outdata, (LPBITMAPINFO)infoPtr->outbih, DIB_RGB_COLORS,
153 SRCCOPY);
154 else
155 StretchDIBits(hDC, 0, 0, infoPtr->inbih->biWidth, infoPtr->inbih->biHeight,
156 0, 0, infoPtr->inbih->biWidth, infoPtr->inbih->biHeight,
157 infoPtr->indata, (LPBITMAPINFO)infoPtr->inbih, DIB_RGB_COLORS,
158 SRCCOPY);
160 return TRUE;
163 static LRESULT ANIMATE_DrawFrame(ANIMATE_INFO* infoPtr)
165 HDC hDC;
167 TRACE("Drawing frame %d (loop %d)\n", infoPtr->currFrame, infoPtr->nLoop);
169 EnterCriticalSection(&infoPtr->cs);
171 infoPtr->fnmmioSeek(infoPtr->hMMio, infoPtr->lpIndex[infoPtr->currFrame], SEEK_SET);
172 infoPtr->fnmmioRead(infoPtr->hMMio, infoPtr->indata, infoPtr->ash.dwSuggestedBufferSize);
174 if (infoPtr->hic &&
175 (infoPtr->fnICDecompress)(infoPtr->hic, 0, infoPtr->inbih, infoPtr->indata,
176 infoPtr->outbih, infoPtr->outdata) != ICERR_OK) {
177 LeaveCriticalSection(&infoPtr->cs);
178 WARN("Decompression error\n");
179 return FALSE;
182 if ((hDC = GetDC(infoPtr->hWnd)) != 0) {
183 ANIMATE_PaintFrame(infoPtr, hDC);
184 ReleaseDC(infoPtr->hWnd, hDC);
187 if (infoPtr->currFrame++ >= infoPtr->nToFrame) {
188 infoPtr->currFrame = infoPtr->nFromFrame;
189 if (infoPtr->nLoop != -1) {
190 if (--infoPtr->nLoop == 0) {
191 ANIMATE_DoStop(infoPtr);
195 LeaveCriticalSection(&infoPtr->cs);
197 return TRUE;
200 static void CALLBACK ANIMATE_ServiceCallback(ULONG_PTR ptr_)
202 ANIMATE_INFO* infoPtr = (ANIMATE_INFO*)ptr_;
204 EnterCriticalSection(&infoPtr->cs);
205 ANIMATE_DrawFrame(infoPtr);
206 LeaveCriticalSection(&infoPtr->cs);
209 static LRESULT ANIMATE_Play(HWND hWnd, WPARAM wParam, LPARAM lParam)
211 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
213 /* nothing opened */
214 if (!infoPtr->hMMio)
215 return FALSE;
217 if (infoPtr->hService || infoPtr->uTimer) {
218 FIXME("Already playing ? what should I do ??\n");
219 ANIMATE_DoStop(infoPtr);
222 infoPtr->nFromFrame = (INT)LOWORD(lParam);
223 infoPtr->nToFrame = (INT)HIWORD(lParam);
224 infoPtr->nLoop = (INT)wParam;
226 if (infoPtr->nToFrame == 0xFFFF)
227 infoPtr->nToFrame = infoPtr->mah.dwTotalFrames - 1;
229 TRACE("(repeat=%d from=%d to=%d);\n",
230 infoPtr->nLoop, infoPtr->nFromFrame, infoPtr->nToFrame);
232 if (infoPtr->nFromFrame >= infoPtr->nToFrame ||
233 infoPtr->nToFrame >= infoPtr->mah.dwTotalFrames)
234 return FALSE;
236 infoPtr->currFrame = infoPtr->nFromFrame;
238 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_TIMER) {
239 TRACE("Using a timer\n");
240 /* create a timer to display AVI */
241 infoPtr->uTimer = SetTimer(hWnd, 1, infoPtr->mah.dwMicroSecPerFrame / 1000, NULL);
242 } else {
243 TRACE("Using the service thread\n");
244 /* time is in µs */
245 infoPtr->hService = SERVICE_AddTimer(infoPtr->mah.dwMicroSecPerFrame,
246 ANIMATE_ServiceCallback, (DWORD)infoPtr);
249 ANIMATE_Notify(infoPtr, ACN_START);
251 return TRUE;
255 static BOOL ANIMATE_GetAviInfo(ANIMATE_INFO *infoPtr)
257 MMCKINFO ckMainRIFF;
258 MMCKINFO mmckHead;
259 MMCKINFO mmckList;
260 MMCKINFO mmckInfo;
261 DWORD numFrame;
262 DWORD insize;
264 if (infoPtr->fnmmioDescend(infoPtr->hMMio, &ckMainRIFF, NULL, 0) != 0) {
265 WARN("Can't find 'RIFF' chunk\n");
266 return FALSE;
269 if ((ckMainRIFF.ckid != FOURCC_RIFF) ||
270 (ckMainRIFF.fccType != mmioFOURCC('A', 'V', 'I', ' '))) {
271 WARN("Can't find 'AVI ' chunk\n");
272 return FALSE;
275 mmckHead.fccType = mmioFOURCC('h', 'd', 'r', 'l');
276 if (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckHead, &ckMainRIFF, MMIO_FINDLIST) != 0) {
277 WARN("Can't find 'hdrl' list\n");
278 return FALSE;
281 mmckInfo.ckid = mmioFOURCC('a', 'v', 'i', 'h');
282 if (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckInfo, &mmckHead, MMIO_FINDCHUNK) != 0) {
283 WARN("Can't find 'avih' chunk\n");
284 return FALSE;
287 infoPtr->fnmmioRead(infoPtr->hMMio, (LPSTR)&infoPtr->mah, sizeof(infoPtr->mah));
288 TRACE("mah.dwMicroSecPerFrame=%ld\n", infoPtr->mah.dwMicroSecPerFrame);
289 TRACE("mah.dwMaxBytesPerSec=%ld\n", infoPtr->mah.dwMaxBytesPerSec);
290 TRACE("mah.dwPaddingGranularity=%ld\n", infoPtr->mah.dwPaddingGranularity);
291 TRACE("mah.dwFlags=%ld\n", infoPtr->mah.dwFlags);
292 TRACE("mah.dwTotalFrames=%ld\n", infoPtr->mah.dwTotalFrames);
293 TRACE("mah.dwInitialFrames=%ld\n", infoPtr->mah.dwInitialFrames);
294 TRACE("mah.dwStreams=%ld\n", infoPtr->mah.dwStreams);
295 TRACE("mah.dwSuggestedBufferSize=%ld\n", infoPtr->mah.dwSuggestedBufferSize);
296 TRACE("mah.dwWidth=%ld\n", infoPtr->mah.dwWidth);
297 TRACE("mah.dwHeight=%ld\n", infoPtr->mah.dwHeight);
298 infoPtr->fnmmioAscend(infoPtr->hMMio, &mmckInfo, 0);
300 mmckList.fccType = mmioFOURCC('s', 't', 'r', 'l');
301 if (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckList, &mmckHead, MMIO_FINDLIST) != 0) {
302 WARN("Can't find 'strl' list\n");
303 return FALSE;
306 mmckInfo.ckid = mmioFOURCC('s', 't', 'r', 'h');
307 if (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, MMIO_FINDCHUNK) != 0) {
308 WARN("Can't find 'strh' chunk\n");
309 return FALSE;
312 infoPtr->fnmmioRead(infoPtr->hMMio, (LPSTR)&infoPtr->ash, sizeof(infoPtr->ash));
313 TRACE("ash.fccType='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr->ash.fccType)),
314 HIBYTE(LOWORD(infoPtr->ash.fccType)),
315 LOBYTE(HIWORD(infoPtr->ash.fccType)),
316 HIBYTE(HIWORD(infoPtr->ash.fccType)));
317 TRACE("ash.fccHandler='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr->ash.fccHandler)),
318 HIBYTE(LOWORD(infoPtr->ash.fccHandler)),
319 LOBYTE(HIWORD(infoPtr->ash.fccHandler)),
320 HIBYTE(HIWORD(infoPtr->ash.fccHandler)));
321 TRACE("ash.dwFlags=%ld\n", infoPtr->ash.dwFlags);
322 TRACE("ash.wPriority=%d\n", infoPtr->ash.wPriority);
323 TRACE("ash.wLanguage=%d\n", infoPtr->ash.wLanguage);
324 TRACE("ash.dwInitialFrames=%ld\n", infoPtr->ash.dwInitialFrames);
325 TRACE("ash.dwScale=%ld\n", infoPtr->ash.dwScale);
326 TRACE("ash.dwRate=%ld\n", infoPtr->ash.dwRate);
327 TRACE("ash.dwStart=%ld\n", infoPtr->ash.dwStart);
328 TRACE("ash.dwLength=%ld\n", infoPtr->ash.dwLength);
329 TRACE("ash.dwSuggestedBufferSize=%ld\n", infoPtr->ash.dwSuggestedBufferSize);
330 TRACE("ash.dwQuality=%ld\n", infoPtr->ash.dwQuality);
331 TRACE("ash.dwSampleSize=%ld\n", infoPtr->ash.dwSampleSize);
332 TRACE("ash.rcFrame=(%d,%d,%d,%d)\n", infoPtr->ash.rcFrame.top, infoPtr->ash.rcFrame.left,
333 infoPtr->ash.rcFrame.bottom, infoPtr->ash.rcFrame.right);
334 infoPtr->fnmmioAscend(infoPtr->hMMio, &mmckInfo, 0);
336 mmckInfo.ckid = mmioFOURCC('s', 't', 'r', 'f');
337 if (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, MMIO_FINDCHUNK) != 0) {
338 WARN("Can't find 'strh' chunk\n");
339 return FALSE;
342 infoPtr->inbih = HeapAlloc(GetProcessHeap(), 0, mmckInfo.cksize);
343 if (!infoPtr->inbih) {
344 WARN("Can't alloc input BIH\n");
345 return FALSE;
348 infoPtr->fnmmioRead(infoPtr->hMMio, (LPSTR)infoPtr->inbih, mmckInfo.cksize);
349 TRACE("bih.biSize=%ld\n", infoPtr->inbih->biSize);
350 TRACE("bih.biWidth=%ld\n", infoPtr->inbih->biWidth);
351 TRACE("bih.biHeight=%ld\n", infoPtr->inbih->biHeight);
352 TRACE("bih.biPlanes=%d\n", infoPtr->inbih->biPlanes);
353 TRACE("bih.biBitCount=%d\n", infoPtr->inbih->biBitCount);
354 TRACE("bih.biCompression=%ld\n", infoPtr->inbih->biCompression);
355 TRACE("bih.biSizeImage=%ld\n", infoPtr->inbih->biSizeImage);
356 TRACE("bih.biXPelsPerMeter=%ld\n", infoPtr->inbih->biXPelsPerMeter);
357 TRACE("bih.biYPelsPerMeter=%ld\n", infoPtr->inbih->biYPelsPerMeter);
358 TRACE("bih.biClrUsed=%ld\n", infoPtr->inbih->biClrUsed);
359 TRACE("bih.biClrImportant=%ld\n", infoPtr->inbih->biClrImportant);
360 infoPtr->fnmmioAscend(infoPtr->hMMio, &mmckInfo, 0);
362 infoPtr->fnmmioAscend(infoPtr->hMMio, &mmckList, 0);
364 #if 0
365 /* an AVI has 0 or 1 video stream, and to be animated should not contain
366 * an audio stream, so only one strl is allowed
368 mmckList.fccType = mmioFOURCC('s', 't', 'r', 'l');
369 if (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckList, &mmckHead, MMIO_FINDLIST) == 0) {
370 WARN("There should be a single 'strl' list\n");
371 return FALSE;
373 #endif
375 infoPtr->fnmmioAscend(infoPtr->hMMio, &mmckHead, 0);
377 /* no need to read optional JUNK chunk */
379 mmckList.fccType = mmioFOURCC('m', 'o', 'v', 'i');
380 if (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckList, &ckMainRIFF, MMIO_FINDLIST) != 0) {
381 WARN("Can't find 'movi' list\n");
382 return FALSE;
385 /* FIXME: should handle the 'rec ' LIST when present */
387 infoPtr->lpIndex = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
388 infoPtr->mah.dwTotalFrames * sizeof(DWORD));
389 if (!infoPtr->lpIndex) {
390 WARN("Can't alloc index array\n");
391 return FALSE;
394 numFrame = insize = 0;
395 while (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, 0) == 0 &&
396 numFrame < infoPtr->mah.dwTotalFrames) {
397 infoPtr->lpIndex[numFrame] = mmckInfo.dwDataOffset;
398 if (insize < mmckInfo.cksize)
399 insize = mmckInfo.cksize;
400 numFrame++;
401 infoPtr->fnmmioAscend(infoPtr->hMMio, &mmckInfo, 0);
403 if (numFrame != infoPtr->mah.dwTotalFrames) {
404 WARN("Found %ld frames (/%ld)\n", numFrame, infoPtr->mah.dwTotalFrames);
405 return FALSE;
407 if (insize > infoPtr->ash.dwSuggestedBufferSize) {
408 WARN("insize=%ld suggestedSize=%ld\n", insize, infoPtr->ash.dwSuggestedBufferSize);
409 infoPtr->ash.dwSuggestedBufferSize = insize;
412 infoPtr->indata = HeapAlloc(GetProcessHeap(), 0, infoPtr->ash.dwSuggestedBufferSize);
413 if (!infoPtr->indata) {
414 WARN("Can't alloc input buffer\n");
415 return FALSE;
418 return TRUE;
422 static BOOL ANIMATE_GetAviCodec(ANIMATE_INFO *infoPtr)
424 DWORD outSize;
426 /* check uncompressed AVI */
427 if (infoPtr->ash.fccHandler == mmioFOURCC('D', 'I', 'B', ' ')) {
428 infoPtr->hic = 0;
429 return TRUE;
432 /* try to get a decompressor for that type */
433 infoPtr->hic = (infoPtr->fnICOpen)(ICTYPE_VIDEO,
434 infoPtr->ash.fccHandler,
435 ICMODE_DECOMPRESS);
436 if (!infoPtr->hic) {
437 WARN("Can't load codec for the file\n");
438 return FALSE;
441 outSize = (infoPtr->fnICSendMessage)(infoPtr->hic,
442 ICM_DECOMPRESS_GET_FORMAT,
443 (DWORD)infoPtr->inbih, 0L);
444 infoPtr->outbih = HeapAlloc(GetProcessHeap(), 0, outSize);
445 if (!infoPtr->outbih) {
446 WARN("Can't alloc output BIH\n");
447 return FALSE;
450 if ((infoPtr->fnICSendMessage)(infoPtr->hic, ICM_DECOMPRESS_GET_FORMAT,
451 (DWORD)infoPtr->inbih,
452 (DWORD)infoPtr->outbih) != ICERR_OK) {
453 WARN("Can't get output BIH\n");
454 return FALSE;
457 infoPtr->outdata = HeapAlloc(GetProcessHeap(), 0, infoPtr->outbih->biSizeImage);
458 if (!infoPtr->outdata) {
459 WARN("Can't alloc output buffer\n");
460 return FALSE;
463 if ((infoPtr->fnICSendMessage)(infoPtr->hic, ICM_DECOMPRESS_BEGIN,
464 (DWORD)infoPtr->inbih,
465 (DWORD)infoPtr->outbih) != ICERR_OK) {
466 WARN("Can't begin decompression\n");
467 return FALSE;
470 return TRUE;
473 static LRESULT ANIMATE_OpenA(HWND hWnd, WPARAM wParam, LPARAM lParam)
475 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
476 HINSTANCE hInstance = (HINSTANCE)wParam;
478 ANIMATE_Free(infoPtr);
480 if (!lParam) {
481 TRACE("Closing avi!\n");
482 return TRUE;
485 if (!hInstance)
486 hInstance = GetWindowLongA(hWnd, GWL_HINSTANCE);
488 if (HIWORD(lParam)) {
489 TRACE("(\"%s\");\n", (LPSTR)lParam);
491 if (!ANIMATE_LoadResA(infoPtr, hInstance, (LPSTR)lParam)) {
492 TRACE("No AVI resource found!\n");
493 if (!ANIMATE_LoadFileA(infoPtr, (LPSTR)lParam)) {
494 WARN("No AVI file found!\n");
495 return FALSE;
498 } else {
499 TRACE("(%u);\n", (WORD)LOWORD(lParam));
501 if (!ANIMATE_LoadResA(infoPtr, hInstance,
502 MAKEINTRESOURCEA((INT)lParam))) {
503 WARN("No AVI resource found!\n");
504 return FALSE;
508 if (!ANIMATE_GetAviInfo(infoPtr)) {
509 WARN("Can't get AVI information\n");
510 ANIMATE_Free(infoPtr);
511 return FALSE;
514 if (!ANIMATE_GetAviCodec(infoPtr)) {
515 WARN("Can't get AVI Codec\n");
516 ANIMATE_Free(infoPtr);
517 return FALSE;
520 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_CENTER) {
521 FIXME("ACS_CENTER: NIY\n");
522 } else {
523 /* MoveWindow(hWnd, 0, 0, infoPtr->mah.dwWidth, infoPtr->mah.dwHeight, FALSE);*/
524 SetWindowPos(hWnd, 0, 0, 0, infoPtr->mah.dwWidth, infoPtr->mah.dwHeight,
525 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER);
528 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_TRANSPARENT) {
529 FIXME("ACS_TRANSPARENT: NIY\n");
532 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_AUTOPLAY) {
533 return ANIMATE_Play(hWnd, -1, (LPARAM)MAKELONG(0, infoPtr->mah.dwTotalFrames-1));
536 return TRUE;
540 /* << ANIMATE_Open32W >> */
542 static LRESULT ANIMATE_Stop(HWND hWnd, WPARAM wParam, LPARAM lParam)
544 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
546 /* nothing opened */
547 if (!infoPtr->hMMio)
548 return FALSE;
550 ANIMATE_DoStop(infoPtr);
551 return TRUE;
555 static LRESULT ANIMATE_Create(HWND hWnd, WPARAM wParam, LPARAM lParam)
557 ANIMATE_INFO* infoPtr;
558 HMODULE hModule = LoadLibraryA("msvfw32.dll");
560 if (!hModule)
561 return FALSE;
563 /* allocate memory for info structure */
564 infoPtr = (ANIMATE_INFO *)COMCTL32_Alloc(sizeof(ANIMATE_INFO));
565 if (!infoPtr) {
566 ERR("could not allocate info memory!\n");
567 return 0;
570 /* Temporary hack until we get dllglue up and running */
571 infoPtr->fnICOpen = (void*)GetProcAddress(hModule, "ICOpen");
572 infoPtr->fnICClose = (void*)GetProcAddress(hModule, "ICClose");
573 infoPtr->fnICSendMessage = (void*)GetProcAddress(hModule, "ICSendMessage");
574 infoPtr->fnICDecompress = (void*)GetProcAddress(hModule, "ICDecompress");
576 TRACE("Animate style=0x%08lx, parent=%08lx\n", GetWindowLongA(hWnd, GWL_STYLE), (DWORD)GetParent(hWnd));
578 /* store crossref hWnd <-> info structure */
579 SetWindowLongA(hWnd, 0, (DWORD)infoPtr);
580 infoPtr->hWnd = hWnd;
582 hModWinmm = LoadLibraryA("WINMM");
584 infoPtr->fnmmioOpenA = (void*)GetProcAddress(hModWinmm, "mmioOpenA");
585 infoPtr->fnmmioClose = (void*)GetProcAddress(hModWinmm, "mmioClose");
586 infoPtr->fnmmioAscend = (void*)GetProcAddress(hModWinmm, "mmioAscend");
587 infoPtr->fnmmioDescend = (void*)GetProcAddress(hModWinmm, "mmioDescend");
588 infoPtr->fnmmioSeek = (void*)GetProcAddress(hModWinmm, "mmioSeek");
589 infoPtr->fnmmioRead = (void*)GetProcAddress(hModWinmm, "mmioRead");
591 InitializeCriticalSection(&infoPtr->cs);
593 return 0;
597 static LRESULT ANIMATE_Destroy(HWND hWnd, WPARAM wParam, LPARAM lParam)
599 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
602 /* free avi data */
603 ANIMATE_Free(infoPtr);
605 /* free animate info data */
606 COMCTL32_Free(infoPtr);
608 FreeLibrary(hModWinmm);
609 return 0;
613 static LRESULT ANIMATE_EraseBackground(HWND hWnd, WPARAM wParam, LPARAM lParam)
615 RECT rect;
617 GetClientRect(hWnd, &rect);
618 #if 0
619 HBRUSH hBrush = CreateSolidBrush(infoPtr->clrBk);
621 FillRect((HDC)wParam, &rect, hBrush);
622 DeleteObject(hBrush);
623 #else
624 FillRect((HDC)wParam, &rect, GetSysColorBrush(COLOR_WINDOW));
625 #endif
626 return TRUE;
629 static LRESULT WINAPI ANIMATE_Size(HWND hWnd, WPARAM wParam, LPARAM lParam)
631 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
633 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_CENTER) {
634 FIXME("NIY\n");
635 if (infoPtr->hMMio) {
636 /* centers the animation in the control, invalidates the control
639 InvalidateRect(hWnd, NULL, TRUE);
641 return TRUE;
644 static LRESULT WINAPI ANIMATE_WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
646 switch (uMsg)
648 case ACM_OPENA:
649 return ANIMATE_OpenA(hWnd, wParam, lParam);
651 /* case ACM_OPEN32W: FIXME!! */
652 /* return ANIMATE_Open32W(hWnd, wParam, lParam); */
654 case ACM_PLAY:
655 return ANIMATE_Play(hWnd, wParam, lParam);
657 case ACM_STOP:
658 return ANIMATE_Stop(hWnd, wParam, lParam);
660 case WM_NCCREATE:
661 ANIMATE_Create(hWnd, wParam, lParam);
662 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
664 case WM_NCHITTEST:
665 return HTTRANSPARENT;
667 case WM_DESTROY:
668 ANIMATE_Destroy(hWnd, wParam, lParam);
669 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
671 case WM_ERASEBKGND:
672 ANIMATE_EraseBackground(hWnd, wParam, lParam);
673 break;
675 /* case WM_STYLECHANGED: FIXME shall we do something ?? */
677 case WM_TIMER:
678 return ANIMATE_DrawFrame(ANIMATE_GetInfoPtr(hWnd));
680 case WM_CLOSE:
681 ANIMATE_Free(ANIMATE_GetInfoPtr(hWnd));
682 return TRUE;
684 case WM_PAINT:
685 if (wParam) {
686 ANIMATE_PaintFrame(ANIMATE_GetInfoPtr(hWnd), (HDC)wParam);
687 } else {
688 PAINTSTRUCT ps;
689 HDC hDC = BeginPaint(hWnd, &ps);
690 ANIMATE_PaintFrame(ANIMATE_GetInfoPtr(hWnd), hDC);
691 EndPaint(hWnd, &ps);
693 break;
695 case WM_SIZE:
696 ANIMATE_Size(hWnd, wParam, lParam);
697 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
699 default:
700 if (uMsg >= WM_USER)
701 ERR("unknown msg %04x wp=%08x lp=%08lx\n", uMsg, wParam, lParam);
703 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
705 return 0;
709 void ANIMATE_Register(void)
711 WNDCLASSA wndClass;
713 ZeroMemory(&wndClass, sizeof(WNDCLASSA));
714 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
715 wndClass.lpfnWndProc = (WNDPROC)ANIMATE_WindowProc;
716 wndClass.cbClsExtra = 0;
717 wndClass.cbWndExtra = sizeof(ANIMATE_INFO *);
718 wndClass.hCursor = LoadCursorA(0, IDC_ARROWA);
719 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
720 wndClass.lpszClassName = ANIMATE_CLASSA;
722 RegisterClassA(&wndClass);
726 void ANIMATE_Unregister(void)
728 UnregisterClassA(ANIMATE_CLASSA, (HINSTANCE)NULL);