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