Changeset 1100 for trunk/src/comctl32/animate.c
- Timestamp:
- Oct 1, 1999, 5:53:32 PM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/comctl32/animate.c
r496 r1100 1 /* $Id: animate.c,v 1. 4 1999-08-14 16:13:09cbratschi Exp $ */1 /* $Id: animate.c,v 1.5 1999-10-01 15:53:31 cbratschi Exp $ */ 2 2 /* 3 3 * Animation control … … 5 5 * Copyright 1998, 1999 Eric Kohl 6 6 * Copyright 1999 Achim Hasenmueller 7 * Copyright 1999 Christoph Bratschi 7 8 * 8 * NOTES 9 * This is just a dummy control. An author is needed! Any volunteers? 10 * I will only improve this control once in a while. 11 * Eric <ekohl@abo.rhein-zeitung.de> 12 * 13 * TODO: 14 * - All messages. 15 * - All notifications. 9 * Status: can't play videos through MCI -> WINMM stubs 10 * Version: 5.00 16 11 */ 17 12 … … 23 18 24 19 25 #define ANIMATE_GetInfoPtr(hwnd) ((ANIMATE_INFO *)GetWindowLongA (hwnd,0))26 20 #define ANIMATE_GetInfoPtr(hwnd) ((ANIMATE_INFO*)GetWindowLongA(hwnd,0)) 21 #define TIMER_ID 1 27 22 28 23 static BOOL 29 ANIMATE_LoadRes A (ANIMATE_INFO *infoPtr, HINSTANCE hInst, LPSTR lpName)24 ANIMATE_LoadRes(ANIMATE_INFO *infoPtr,HINSTANCE hInst,LPSTR lpName,BOOL unicode) 30 25 { 31 26 HRSRC hrsrc; 32 27 HGLOBAL handle; 33 34 hrsrc = FindResourceA (hInst, lpName, "AVI"); 35 if (!hrsrc) 36 return FALSE; 28 LPVOID lpAvi; 29 30 if (unicode) 31 { 32 WCHAR buf[4]; 33 34 lstrcpyAtoW(buf,"AVI"); 35 hrsrc = FindResourceW(hInst,(LPWSTR)lpName,buf); 36 } else hrsrc = FindResourceA(hInst,lpName,"AVI"); 37 if (!hrsrc) return FALSE; 37 38 38 39 handle = LoadResource (hInst, hrsrc); 40 if (!handle) return FALSE; 41 42 lpAvi = LockResource (handle); 43 if (!lpAvi) return FALSE; 44 45 infoPtr->lpAvi = lpAvi; 46 infoPtr->hRes = handle; 47 infoPtr->cSize = SizeofResource(hInst,hrsrc); 48 49 return TRUE; 50 } 51 52 static BOOL 53 ANIMATE_LoadFile(ANIMATE_INFO *infoPtr,LPSTR lpName,BOOL unicode) 54 { 55 HANDLE handle; 56 HFILE hFile; 57 LPVOID lpAvi; 58 59 if (unicode) 60 { 61 hFile = CreateFileW((LPWSTR)lpName,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0); 62 if (!hFile) return FALSE; 63 64 handle = CreateFileMappingW(hFile,NULL,PAGE_READONLY | SEC_COMMIT,0,0,NULL); 65 } else 66 { 67 hFile = CreateFileA (lpName,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0); 68 if (!hFile) return FALSE; 69 70 handle = CreateFileMappingA(hFile,NULL,PAGE_READONLY | SEC_COMMIT,0,0,NULL); 71 } 39 72 if (!handle) 40 return FALSE; 41 42 infoPtr->lpAvi = LockResource (handle); 43 if (!infoPtr->lpAvi) 44 return FALSE; 73 { 74 CloseHandle (hFile); 75 return FALSE; 76 } 77 78 lpAvi = MapViewOfFile (handle, FILE_MAP_READ, 0, 0, 0); 79 if (!lpAvi) 80 { 81 CloseHandle (hFile); 82 return FALSE; 83 } 84 85 infoPtr->lpAvi = lpAvi; 86 infoPtr->hFile = hFile; 87 infoPtr->cSize = GetFileSize(hFile,NULL); 45 88 46 89 return TRUE; 47 90 } 48 91 92 static VOID 93 ANIMATE_GetAviInfo (ANIMATE_INFO *infoPtr) 94 { 95 96 97 } 98 99 static VOID 100 ANIMATE_FreeResource(ANIMATE_INFO *infoPtr) 101 { 102 if (infoPtr->hFile) 103 { 104 UnmapViewOfFile (infoPtr->lpAvi); 105 CloseHandle (infoPtr->hFile); 106 infoPtr->lpAvi = NULL; 107 infoPtr->hFile = NULL; 108 } else if (infoPtr->hRes) 109 { 110 GlobalFree (infoPtr->hRes); 111 infoPtr->lpAvi = NULL; 112 infoPtr->hRes = NULL; 113 } 114 infoPtr->cSize = 0; 115 } 49 116 50 117 static BOOL 51 ANIMATE_LoadFileA (ANIMATE_INFO *infoPtr, LPSTR lpName) 52 { 53 HANDLE handle; 54 55 infoPtr->hFile = 56 CreateFileA (lpName, GENERIC_READ, 0, NULL, OPEN_EXISTING, 57 FILE_ATTRIBUTE_NORMAL, 0); 58 if (!infoPtr->hFile) 59 return FALSE; 60 61 handle = 62 CreateFileMappingA (infoPtr->hFile, NULL, PAGE_READONLY | SEC_COMMIT, 63 0, 0, NULL); 64 if (!handle) { 65 CloseHandle (infoPtr->hFile); 66 infoPtr->hFile = 0; 67 return FALSE; 68 } 69 70 infoPtr->lpAvi = MapViewOfFile (handle, FILE_MAP_READ, 0, 0, 0); 71 if (!infoPtr->lpAvi) { 72 CloseHandle (infoPtr->hFile); 73 infoPtr->hFile = 0; 74 return FALSE; 75 } 118 ANIMATE_IsLoaded(ANIMATE_INFO *infoPtr) 119 { 120 return (infoPtr->lpAvi != NULL); 121 } 122 123 static BOOL 124 ANIMATE_IsPlaying(ANIMATE_INFO *infoPtr) 125 { 126 return infoPtr->bPlaying; 127 } 128 129 /* Message handlers */ 130 131 static LRESULT 132 ANIMATE_Close(HWND hwnd,WPARAM wParam,LPARAM lParam) 133 { 134 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hwnd); 135 136 ANIMATE_FreeResource(infoPtr); 137 138 return DefWindowProcA(hwnd,WM_CLOSE,wParam,lParam); 139 } 140 141 static LRESULT 142 ANIMATE_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam) 143 { 144 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hwnd); 145 146 /* free avi data */ 147 ANIMATE_FreeResource(infoPtr); 148 149 /* free animate info data */ 150 COMCTL32_Free(infoPtr); 151 152 return DefWindowProcA(hwnd,WM_DESTROY,wParam,lParam); 153 } 154 155 static LRESULT 156 ANIMATE_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam) 157 { 158 ANIMATE_INFO *infoPtr; 159 160 /* allocate memory for info structure */ 161 infoPtr = (ANIMATE_INFO *)COMCTL32_Alloc (sizeof(ANIMATE_INFO)); 162 163 /* store pointer to info structure */ 164 SetWindowLongA (hwnd,0,(DWORD)infoPtr); 165 166 /* set default settings */ 167 infoPtr->lpAvi = NULL; 168 infoPtr->hFile = 0; 169 infoPtr->hRes = 0; 170 infoPtr->cSize = 0; 171 infoPtr->cRepeat = 0; 172 infoPtr->wFrom = 0; 173 infoPtr->wTo = 0; 174 infoPtr->wPos = 0; 175 infoPtr->bPlaying = FALSE; 176 infoPtr->cFrames = 0; 177 infoPtr->pos.x = 0; 178 infoPtr->pos.y = 0; 179 infoPtr->size.x = 0; 180 infoPtr->size.y = 0; 181 infoPtr->bThread = 0; 182 183 return DefWindowProcA(hwnd,WM_NCCREATE,wParam,lParam); 184 } 185 186 static LRESULT 187 ANIMATE_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam) 188 { 189 HBRUSH hBrush; 190 RECT rect; 191 HDC hdc = (HDC)wParam; 192 193 if (GetWindowLongA(hwnd,GWL_STYLE) & ACS_TRANSPARENT) 194 { 195 hBrush = SendMessageA(hwnd,WM_CTLCOLORSTATIC,hdc,hwnd); 196 } else hBrush = GetSysColorBrush(COLOR_WINDOW); 197 198 GetClientRect(hwnd,&rect); 199 FillRect((HDC)wParam,&rect,hBrush); 76 200 77 201 return TRUE; 78 202 } 79 203 204 static LRESULT 205 ANIMATE_NCHitTest(HWND hwnd,WPARAM wParam,LPARAM lParam) 206 { 207 return HTTRANSPARENT; 208 } 80 209 81 210 static VOID 82 ANIMATE_Free (ANIMATE_INFO *infoPtr) 83 { 84 if (infoPtr->hFile) { 85 UnmapViewOfFile (infoPtr->lpAvi); 86 CloseHandle (infoPtr->hFile); 87 infoPtr->lpAvi = NULL; 88 } 89 else { 90 GlobalFree ((HGLOBAL)infoPtr->lpAvi); 91 infoPtr->lpAvi = NULL; 92 } 93 } 94 95 96 static VOID 97 ANIMATE_GetAviInfo (infoPtr) 98 { 99 100 101 } 102 103 104 static LRESULT 105 ANIMATE_OpenA (HWND hwnd, WPARAM wParam, LPARAM lParam) 211 ANIMATE_DrawFrame(ANIMATE_INFO *infoPtr) 212 { 213 //CB: todo 214 //MCI_PUT 215 } 216 217 static LRESULT 218 ANIMATE_Paint(HWND hwnd,WPARAM wParam,LPARAM lParam) 219 { 220 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hwnd); 221 222 if (ANIMATE_IsLoaded(infoPtr)) ANIMATE_DrawFrame(infoPtr); 223 224 return 0; 225 } 226 227 static LRESULT 228 ANIMATE_Size(HWND hwnd,WPARAM wParam,LPARAM lParam) 229 { 230 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hwnd); 231 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE); 232 233 if (ANIMATE_IsPlaying(infoPtr) && dwStyle & ACS_CENTER) 234 { 235 infoPtr->pos.x = (LOWORD(lParam)-infoPtr->size.x)/2; 236 infoPtr->pos.y = (HIWORD(lParam)-infoPtr->size.y)/2; 237 } 238 239 return DefWindowProcA(hwnd,WM_SIZE,wParam,lParam); 240 } 241 242 static LRESULT 243 ANIMATE_StyleChanged(HWND hwnd,WPARAM wParam,LPARAM lParam) 244 { 245 //CB: todo 246 247 return 0; 248 } 249 250 static LRESULT 251 ANIMATE_Timer(HWND hwnd,WPARAM wParam,LPARAM lParam) 252 { 253 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hwnd); 254 INT newPos = infoPtr->wPos+1; 255 256 if (wParam != TIMER_ID) return 0; 257 258 if (newPos == infoPtr->wTo || (infoPtr->wTo == -1 && newPos == infoPtr->cFrames-1)) 259 { 260 if (infoPtr->cRepeat != -1) 261 { 262 infoPtr->cRepeat--; 263 if (infoPtr->cRepeat == 0) Animate_Stop(hwnd); 264 } 265 } else 266 { 267 infoPtr->wPos++; 268 ANIMATE_DrawFrame(infoPtr); 269 } 270 271 return 0; 272 } 273 274 /* Control messages */ 275 276 static LRESULT 277 ANIMATE_Open(HWND hwnd,WPARAM wParam,LPARAM lParam,BOOL unicode) 106 278 { 107 279 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hwnd); 108 280 HINSTANCE hInstance = (HINSTANCE)wParam; 109 281 110 ANIMATE_Free (infoPtr); 111 112 if (!lParam) { 113 // TRACE (animate, "closing avi!\n"); 114 return TRUE; 115 } 116 117 if (HIWORD(lParam)) { 118 // FIXME (animate, "(\"%s\") empty stub!\n", (LPSTR)lParam); 119 120 if (ANIMATE_LoadResA (infoPtr, hInstance, (LPSTR)lParam)) { 121 122 // FIXME (animate, "AVI resource found!\n"); 123 124 } 125 else { 126 // FIXME (animate, "No AVI resource found!\n"); 127 if (ANIMATE_LoadFileA (infoPtr, (LPSTR)lParam)) { 128 // FIXME (animate, "AVI file found!\n"); 129 } 130 else { 131 // FIXME (animate, "No AVI file found!\n"); 132 return FALSE; 133 } 134 } 135 } 136 else { 137 // FIXME (animate, "(%u) empty stub!\n", (WORD)LOWORD(lParam)); 138 139 if (ANIMATE_LoadResA (infoPtr, hInstance, 140 MAKEINTRESOURCEA((INT)lParam))) { 141 // FIXME (animate, "AVI resource found!\n"); 142 } 143 else { 144 // FIXME (animate, "No AVI resource found!\n"); 145 return FALSE; 146 } 147 } 148 149 ANIMATE_GetAviInfo (infoPtr); 282 ANIMATE_FreeResource(infoPtr); 283 284 MessageBoxA(hwnd,"open",NULL,MB_OK); 285 if (!lParam) return TRUE; 286 287 if (HIWORD(lParam)) 288 { 289 if (ANIMATE_LoadRes(infoPtr,hInstance,(LPSTR)lParam,unicode)); 290 else if (ANIMATE_LoadFile(infoPtr,(LPSTR)lParam,unicode)); 291 else return FALSE; 292 } else 293 { 294 if (!ANIMATE_LoadRes(infoPtr,hInstance,unicode ? (LPTSTR)MAKEINTRESOURCEW((INT)lParam):MAKEINTRESOURCEA((INT)lParam),unicode)) return FALSE; 295 } 296 297 ANIMATE_GetAviInfo(infoPtr); 298 299 if (GetWindowLongA(hwnd,GWL_STYLE) & ACS_AUTOPLAY) Animate_Play(hwnd,0,-1,1); 150 300 151 301 return TRUE; 152 302 } 153 303 154 155 /* << ANIMATE_Open32W >> */156 157 158 304 static LRESULT 159 305 ANIMATE_Play (HWND hwnd, WPARAM wParam, LPARAM lParam) 160 306 { 161 /* ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hwnd); */ 162 INT nFrom = (INT)LOWORD(lParam); 163 INT nTo = (INT)HIWORD(lParam); 164 INT nRepeat = (INT)wParam; 165 166 #if 0 167 /* nothing opened */ 168 if (...) 169 return FALSE; 170 #endif 171 172 if (nRepeat == -1) { 173 174 // FIXME (animate, "(loop from=%d to=%d) empty stub!\n", 175 // nFrom, nTo); 176 177 } 178 else { 179 180 // FIXME (animate, "(repeat=%d from=%d to=%d) empty stub!\n", 181 // nRepeat, nFrom, nTo); 182 183 } 184 307 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hwnd); 308 INT wFrom = (INT)LOWORD(lParam); 309 INT wTo = (INT)HIWORD(lParam); 310 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE); 311 312 if (!ANIMATE_IsLoaded(infoPtr)) return FALSE; 313 314 Animate_Stop(hwnd); 315 316 if (wFrom < 0) wFrom = 0; 317 if (wFrom > wTo && wTo != -1) return FALSE; 318 if (wFrom >= infoPtr->cFrames) wFrom = infoPtr->cFrames-1; 319 if (wTo >= infoPtr->cFrames) wTo = infoPtr->cFrames-1; 320 321 infoPtr->cRepeat = (INT)wParam; 322 infoPtr->wFrom = wFrom; 323 infoPtr->wTo = wTo; 324 infoPtr->wPos = infoPtr->wFrom; 325 326 if (dwStyle & ACS_CENTER) 327 { 328 RECT rect; 329 330 GetClientRect(hwnd,&rect); 331 infoPtr->pos.x = (rect.right-infoPtr->size.x)/2; 332 infoPtr->pos.y = (rect.bottom-infoPtr->size.y)/2; 333 } else 334 { 335 infoPtr->pos.x = 0; 336 infoPtr->pos.y = 0; 337 } 338 339 InvalidateRect(hwnd,NULL,FALSE); 340 341 if (wFrom == wTo) 342 { 343 SendMessageA(GetParent(hwnd),WM_COMMAND,MAKEWPARAM(GetWindowLongA(hwnd,GWL_ID),ACN_START),hwnd); 344 SendMessageA(GetParent(hwnd),WM_COMMAND,MAKEWPARAM(GetWindowLongA(hwnd,GWL_ID),ACN_STOP),hwnd); 345 346 return TRUE; 347 } 348 349 infoPtr->bPlaying = TRUE; 350 351 if (dwStyle & ACS_TIMER) 352 { 353 infoPtr->bThread = FALSE; 354 SetTimer(hwnd,TIMER_ID,infoPtr->msFrame,NULL); 355 } else 356 { 357 infoPtr->bThread = TRUE; 358 //CB:todo 359 } 360 361 SendMessageA(GetParent(hwnd),WM_COMMAND,MAKEWPARAM(GetWindowLongA(hwnd,GWL_ID),ACN_START),hwnd); 185 362 186 363 return TRUE; 187 364 } 188 365 189 190 366 static LRESULT 191 367 ANIMATE_Stop (HWND hwnd, WPARAM wParam, LPARAM lParam) 192 368 { 193 /* ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hwnd); */ 194 195 #if 0 196 /* nothing opened */ 197 if (...) 198 return FALSE; 199 #endif 200 201 return TRUE; 202 } 203 204 205 206 static LRESULT 207 ANIMATE_Create (HWND hwnd, WPARAM wParam, LPARAM lParam) 208 { 209 ANIMATE_INFO *infoPtr; 210 211 /* allocate memory for info structure */ 212 infoPtr = (ANIMATE_INFO *)COMCTL32_Alloc (sizeof(ANIMATE_INFO)); 213 if (!infoPtr) { 214 // ERR (animate, "could not allocate info memory!\n"); 215 return 0; 216 } 217 218 /* store pointer to info structure */ 219 SetWindowLongA (hwnd, 0, (DWORD)infoPtr); 220 221 222 /* set default settings */ 223 224 225 return 0; 226 } 227 228 229 static LRESULT 230 ANIMATE_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam) 231 { 232 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hwnd); 233 234 235 /* free avi data */ 236 ANIMATE_Free (infoPtr); 237 238 /* free animate info data */ 239 COMCTL32_Free (infoPtr); 240 241 return 0; 242 } 243 244 245 #if 0 246 static LRESULT 247 ANIMATE_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam) 248 { 249 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hwnd); 250 /* 251 HBRUSH32 hBrush = CreateSolidBrush32 (infoPtr->clrBk); 252 RECT32 rect; 253 254 GetClientRect32 (wndPtr->hwndSelf, &rect); 255 FillRect32 ((HDC32)wParam, &rect, hBrush); 256 DeleteObject32 (hBrush); 257 */ 258 return TRUE; 259 } 260 #endif 261 262 369 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hwnd); 370 371 if (!ANIMATE_IsLoaded(infoPtr)) return FALSE; 372 if (!ANIMATE_IsPlaying(infoPtr)) return TRUE; 373 374 if (infoPtr->bThread) 375 { 376 //CB:todo 377 } else 378 { 379 KillTimer(hwnd,TIMER_ID); 380 } 381 382 infoPtr->bPlaying = FALSE; 383 SendMessageA(GetParent(hwnd),WM_COMMAND,MAKEWPARAM(GetWindowLongA(hwnd,GWL_ID),ACN_STOP),hwnd); 384 385 return TRUE; 386 } 263 387 264 388 static LRESULT WINAPI … … 268 392 { 269 393 case ACM_OPENA: 270 return ANIMATE_OpenA (hwnd, wParam, lParam);271 272 /* case ACM_OPEN32W: */ 273 /* return ANIMATE_Open32W (hwnd, wParam, lParam); */ 394 return ANIMATE_Open(hwnd,wParam,lParam,FALSE); 395 396 case ACM_OPENW: 397 return ANIMATE_Open(hwnd,wParam,lParam,TRUE); 274 398 275 399 case ACM_PLAY: 276 400 return ANIMATE_Play (hwnd, wParam, lParam); 277 401 278 402 case ACM_STOP: 279 return ANIMATE_Stop (hwnd, wParam, lParam); 280 281 282 case WM_CREATE: 283 return ANIMATE_Create (hwnd, wParam, lParam); 403 return ANIMATE_Stop (hwnd, wParam, lParam); 404 405 case WM_CLOSE: 406 return ANIMATE_Close(hwnd,wParam,lParam); 407 408 case WM_NCCREATE: 409 return ANIMATE_NCCreate(hwnd,wParam,lParam); 284 410 285 411 case WM_DESTROY: 286 return ANIMATE_Destroy (hwnd, wParam, lParam); 287 288 /* case WM_ERASEBKGND: */ 289 /* return ANIMATE_EraseBackground (hwnd, wParam, lParam); */ 290 291 /* case WM_NCCREATE: */ 292 /* case WM_NCHITTEST: */ 293 /* case WM_PAINT: */ 294 /* case WM_SIZE: */ 295 /* case WM_STYLECHANGED: */ 296 /* case WM_TIMER: */ 412 return ANIMATE_Destroy (hwnd, wParam, lParam); 413 414 case WM_ERASEBKGND: 415 return ANIMATE_EraseBackground (hwnd, wParam, lParam); 416 417 case WM_NCHITTEST: 418 return ANIMATE_NCHitTest(hwnd,wParam,lParam); 419 420 case WM_PAINT: 421 return ANIMATE_Paint(hwnd,wParam,lParam); 422 423 case WM_SIZE: 424 return ANIMATE_Size(hwnd,wParam,lParam); 425 426 case WM_STYLECHANGED: 427 return ANIMATE_StyleChanged(hwnd,wParam,lParam); 428 429 case WM_TIMER: 430 return ANIMATE_Timer(hwnd,wParam,lParam); 297 431 298 432 default: … … 302 436 return DefWindowProcA (hwnd, uMsg, wParam, lParam); 303 437 } 438 304 439 return 0; 305 440 }
Note:
See TracChangeset
for help on using the changeset viewer.