Replaced direct access to the WND structure by corresponding calls to
[wine/multimedia.git] / dlls / comctl32 / animate.c
blob23a3d95ef5e38a76a1a347b8b0cbc53589cbd5c0
1 /*
2 * Animation control
4 * Copyright 1998, 1999 Eric Kohl
6 * NOTES
7 * This is just a dummy control. An author is needed! Any volunteers?
8 * I will only improve this control once in a while.
9 * Eric <ekohl@abo.rhein-zeitung.de>
11 * TODO:
12 * - All messages.
13 * - All notifications.
17 #include "win.h"
18 #include "commctrl.h"
19 #include "animate.h"
20 #include "debug.h"
22 #define ANIMATE_GetInfoPtr(hwnd) ((ANIMATE_INFO *)GetWindowLongA (hwnd, 0))
25 static BOOL
26 ANIMATE_LoadResA (ANIMATE_INFO *infoPtr, HINSTANCE hInst, LPSTR lpName)
28 HRSRC hrsrc;
29 HGLOBAL handle;
31 hrsrc = FindResourceA (hInst, lpName, "AVI");
32 if (!hrsrc)
33 return FALSE;
35 handle = LoadResource (hInst, hrsrc);
36 if (!handle)
37 return FALSE;
39 infoPtr->lpAvi = LockResource (handle);
40 if (!infoPtr->lpAvi)
41 return FALSE;
43 return TRUE;
47 static BOOL
48 ANIMATE_LoadFileA (ANIMATE_INFO *infoPtr, LPSTR lpName)
50 HANDLE handle;
52 infoPtr->hFile =
53 CreateFileA (lpName, GENERIC_READ, 0, NULL, OPEN_EXISTING,
54 FILE_ATTRIBUTE_NORMAL, 0);
55 if (!infoPtr->hFile)
56 return FALSE;
58 handle =
59 CreateFileMappingA (infoPtr->hFile, NULL, PAGE_READONLY | SEC_COMMIT,
60 0, 0, NULL);
61 if (!handle) {
62 CloseHandle (infoPtr->hFile);
63 infoPtr->hFile = 0;
64 return FALSE;
67 infoPtr->lpAvi = MapViewOfFile (handle, FILE_MAP_READ, 0, 0, 0);
68 if (!infoPtr->lpAvi) {
69 CloseHandle (infoPtr->hFile);
70 infoPtr->hFile = 0;
71 return FALSE;
74 return TRUE;
78 static VOID
79 ANIMATE_Free (ANIMATE_INFO *infoPtr)
81 if (infoPtr->hFile) {
82 UnmapViewOfFile (infoPtr->lpAvi);
83 CloseHandle (infoPtr->hFile);
84 infoPtr->lpAvi = NULL;
86 else {
87 GlobalFree ((HGLOBAL)infoPtr->lpAvi);
88 infoPtr->lpAvi = NULL;
93 static VOID
94 ANIMATE_GetAviInfo (infoPtr)
101 static LRESULT
102 ANIMATE_OpenA (HWND hwnd, WPARAM wParam, LPARAM lParam)
104 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hwnd);
105 HINSTANCE hInstance = (HINSTANCE)wParam;
107 ANIMATE_Free (infoPtr);
109 if (!lParam) {
110 TRACE (animate, "closing avi!\n");
111 return TRUE;
114 if (HIWORD(lParam)) {
115 FIXME (animate, "(\"%s\") empty stub!\n", (LPSTR)lParam);
117 if (ANIMATE_LoadResA (infoPtr, hInstance, (LPSTR)lParam)) {
119 FIXME (animate, "AVI resource found!\n");
122 else {
123 FIXME (animate, "No AVI resource found!\n");
124 if (ANIMATE_LoadFileA (infoPtr, (LPSTR)lParam)) {
125 FIXME (animate, "AVI file found!\n");
127 else {
128 FIXME (animate, "No AVI file found!\n");
129 return FALSE;
133 else {
134 FIXME (animate, "(%u) empty stub!\n", (WORD)LOWORD(lParam));
136 if (ANIMATE_LoadResA (infoPtr, hInstance,
137 MAKEINTRESOURCEA((INT)lParam))) {
138 FIXME (animate, "AVI resource found!\n");
140 else {
141 FIXME (animate, "No AVI resource found!\n");
142 return FALSE;
146 ANIMATE_GetAviInfo (infoPtr);
148 return TRUE;
152 /* << ANIMATE_Open32W >> */
155 static LRESULT
156 ANIMATE_Play (HWND hwnd, WPARAM wParam, LPARAM lParam)
158 /* ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hwnd); */
159 INT nFrom = (INT)LOWORD(lParam);
160 INT nTo = (INT)HIWORD(lParam);
161 INT nRepeat = (INT)wParam;
163 #if 0
164 /* nothing opened */
165 if (...)
166 return FALSE;
167 #endif
169 if (nRepeat == -1) {
171 FIXME (animate, "(loop from=%d to=%d) empty stub!\n",
172 nFrom, nTo);
175 else {
177 FIXME (animate, "(repeat=%d from=%d to=%d) empty stub!\n",
178 nRepeat, nFrom, nTo);
183 return TRUE;
187 static LRESULT
188 ANIMATE_Stop (HWND hwnd, WPARAM wParam, LPARAM lParam)
190 /* ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hwnd); */
192 #if 0
193 /* nothing opened */
194 if (...)
195 return FALSE;
196 #endif
198 return TRUE;
203 static LRESULT
204 ANIMATE_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
206 ANIMATE_INFO *infoPtr;
208 /* allocate memory for info structure */
209 infoPtr = (ANIMATE_INFO *)COMCTL32_Alloc (sizeof(ANIMATE_INFO));
210 if (!infoPtr) {
211 ERR (animate, "could not allocate info memory!\n");
212 return 0;
215 /* store pointer to info structure */
216 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
219 /* set default settings */
222 return 0;
226 static LRESULT
227 ANIMATE_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
229 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hwnd);
232 /* free avi data */
233 ANIMATE_Free (infoPtr);
235 /* free animate info data */
236 COMCTL32_Free (infoPtr);
238 return 0;
242 #if 0
243 static LRESULT
244 ANIMATE_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
246 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hwnd);
248 HBRUSH32 hBrush = CreateSolidBrush32 (infoPtr->clrBk);
249 RECT32 rect;
251 GetClientRect32 (wndPtr->hwndSelf, &rect);
252 FillRect32 ((HDC32)wParam, &rect, hBrush);
253 DeleteObject32 (hBrush);
255 return TRUE;
257 #endif
261 LRESULT WINAPI
262 ANIMATE_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
264 switch (uMsg)
266 case ACM_OPENA:
267 return ANIMATE_OpenA (hwnd, wParam, lParam);
269 /* case ACM_OPEN32W: */
270 /* return ANIMATE_Open32W (hwnd, wParam, lParam); */
272 case ACM_PLAY:
273 return ANIMATE_Play (hwnd, wParam, lParam);
275 case ACM_STOP:
276 return ANIMATE_Stop (hwnd, wParam, lParam);
279 case WM_CREATE:
280 return ANIMATE_Create (hwnd, wParam, lParam);
282 case WM_DESTROY:
283 return ANIMATE_Destroy (hwnd, wParam, lParam);
285 /* case WM_ERASEBKGND: */
286 /* return ANIMATE_EraseBackground (hwnd, wParam, lParam); */
288 /* case WM_NCCREATE: */
289 /* case WM_NCHITTEST: */
290 /* case WM_PAINT: */
291 /* case WM_SIZE: */
292 /* case WM_STYLECHANGED: */
293 /* case WM_TIMER: */
295 default:
296 if (uMsg >= WM_USER)
297 ERR (animate, "unknown msg %04x wp=%08x lp=%08lx\n",
298 uMsg, wParam, lParam);
299 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
301 return 0;
305 VOID
306 ANIMATE_Register (VOID)
308 WNDCLASSA wndClass;
310 if (GlobalFindAtomA (ANIMATE_CLASSA)) return;
312 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
313 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
314 wndClass.lpfnWndProc = (WNDPROC)ANIMATE_WindowProc;
315 wndClass.cbClsExtra = 0;
316 wndClass.cbWndExtra = sizeof(ANIMATE_INFO *);
317 wndClass.hCursor = LoadCursorA (0, IDC_ARROWA);
318 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
319 wndClass.lpszClassName = ANIMATE_CLASSA;
321 RegisterClassA (&wndClass);
325 VOID
326 ANIMATE_Unregister (VOID)
328 if (GlobalFindAtomA (ANIMATE_CLASSA))
329 UnregisterClassA (ANIMATE_CLASSA, (HINSTANCE)NULL);