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