Lots of new defines and stubs.
[wine] / dlls / comctl32 / animate.c
1 /*
2  * Animation control
3  *
4  * Copyright 1998 Eric Kohl
5  *
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>
10  *
11  * TODO:
12  *   - All messages.
13  *   - All notifications.
14  */
15
16 #include "windows.h"
17 #include "winnt.h"
18 #include "winbase.h"
19 #include "commctrl.h"
20 #include "animate.h"
21 #include "win.h"
22 #include "debug.h"
23
24
25 #define ANIMATE_GetInfoPtr(wndPtr) ((ANIMATE_INFO *)wndPtr->wExtra[0])
26
27
28 static BOOL32
29 ANIMATE_LoadRes32A (ANIMATE_INFO *infoPtr, HINSTANCE32 hInst, LPSTR lpName)
30 {
31     HRSRC32 hrsrc;
32     HGLOBAL32 handle;
33
34     hrsrc = FindResource32A (hInst, lpName, "AVI");
35     if (!hrsrc)
36         return FALSE;
37
38     handle = LoadResource32 (hInst, hrsrc);
39     if (!handle)
40         return FALSE;
41
42     infoPtr->lpAvi = LockResource32 (handle);
43     if (!infoPtr->lpAvi)
44         return FALSE;
45
46     return TRUE;
47 }
48
49
50 static BOOL32
51 ANIMATE_LoadFile32A (ANIMATE_INFO *infoPtr, LPSTR lpName)
52 {
53     HANDLE32 handle;
54
55     infoPtr->hFile =
56         CreateFile32A (lpName, GENERIC_READ, 0, NULL, OPEN_EXISTING,
57                        FILE_ATTRIBUTE_NORMAL, 0);
58     if (!infoPtr->hFile)
59         return FALSE;
60
61     handle =
62         CreateFileMapping32A (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     }
76
77     return TRUE;
78 }
79
80
81 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         GlobalFree32 ((HGLOBAL32)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_Open32A (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
106 {
107     ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(wndPtr);
108     HINSTANCE32 hInstance = (HINSTANCE32)wParam;
109
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_LoadRes32A (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_LoadFile32A (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_LoadRes32A (infoPtr, hInstance,
140                                 MAKEINTRESOURCE32A((INT32)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);
150
151     return TRUE;
152 }
153
154
155 // << ANIMATE_Open32W >>
156
157
158 static LRESULT
159 ANIMATE_Play (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
160 {
161     ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(wndPtr);
162     INT32 nFrom   = (INT32)LOWORD(lParam);
163     INT32 nTo     = (INT32)HIWORD(lParam);
164     INT32 nRepeat = (INT32)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
185
186     return TRUE;
187 }
188
189
190 static LRESULT
191 ANIMATE_Stop (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
192 {
193     ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(wndPtr);
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 (WND *wndPtr, WPARAM32 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     wndPtr->wExtra[0] = (DWORD)infoPtr;
214
215     if (infoPtr == NULL) {
216         ERR (animate, "could not allocate info memory!\n");
217         return 0;
218     }
219
220     if ((ANIMATE_INFO*)wndPtr->wExtra[0] != infoPtr) {
221         ERR (animate, "pointer assignment error!\n");
222         return 0;
223     }
224
225     /* set default settings */
226
227
228     return 0;
229 }
230
231
232 static LRESULT
233 ANIMATE_Destroy (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
234 {
235     ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(wndPtr);
236
237
238     /* free avi data */
239     ANIMATE_Free (infoPtr);
240
241     /* free animate info data */
242     COMCTL32_Free (infoPtr);
243
244     return 0;
245 }
246
247
248 #if 0
249 static LRESULT
250 ANIMATE_EraseBackground (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
251 {
252     ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(wndPtr);
253 /*
254     HBRUSH32 hBrush = CreateSolidBrush32 (infoPtr->clrBk);
255     RECT32 rect;
256
257     GetClientRect32 (wndPtr->hwndSelf, &rect);
258     FillRect32 ((HDC32)wParam, &rect, hBrush);
259     DeleteObject32 (hBrush);
260 */
261     return TRUE;
262 }
263 #endif
264
265
266
267 LRESULT WINAPI
268 ANIMATE_WindowProc (HWND32 hwnd, UINT32 uMsg, WPARAM32 wParam, LPARAM lParam)
269 {
270     WND *wndPtr = WIN_FindWndPtr(hwnd);
271
272     switch (uMsg)
273     {
274         case ACM_OPEN32A:
275             return ANIMATE_Open32A (wndPtr, wParam, lParam);
276
277 //      case ACM_OPEN32W:
278 //          return ANIMATE_Open32W (wndPtr, wParam, lParam);
279
280         case ACM_PLAY:
281             return ANIMATE_Play (wndPtr, wParam, lParam);
282
283         case ACM_STOP:
284             return ANIMATE_Stop (wndPtr, wParam, lParam);
285
286
287         case WM_CREATE:
288             return ANIMATE_Create (wndPtr, wParam, lParam);
289
290         case WM_DESTROY:
291             return ANIMATE_Destroy (wndPtr, wParam, lParam);
292
293 //      case WM_ERASEBKGND:
294 //          return ANIMATE_EraseBackground (wndPtr, wParam, lParam);
295
296 //      case WM_NCCREATE:
297 //      case WM_NCHITTEST:
298 //      case WM_PAINT:
299 //      case WM_SIZE:
300 //      case WM_STYLECHANGED:
301 //      case WM_TIMER:
302
303         default:
304             if (uMsg >= WM_USER)
305                 ERR (animate, "unknown msg %04x wp=%08x lp=%08lx\n",
306                      uMsg, wParam, lParam);
307             return DefWindowProc32A (hwnd, uMsg, wParam, lParam);
308     }
309     return 0;
310 }
311
312
313 VOID
314 ANIMATE_Register (VOID)
315 {
316     WNDCLASS32A wndClass;
317
318     if (GlobalFindAtom32A (ANIMATE_CLASS32A)) return;
319
320     ZeroMemory (&wndClass, sizeof(WNDCLASS32A));
321     wndClass.style         = CS_GLOBALCLASS | CS_DBLCLKS;
322     wndClass.lpfnWndProc   = (WNDPROC32)ANIMATE_WindowProc;
323     wndClass.cbClsExtra    = 0;
324     wndClass.cbWndExtra    = sizeof(ANIMATE_INFO *);
325     wndClass.hCursor       = LoadCursor32A (0, IDC_ARROW32A);
326     wndClass.hbrBackground = (HBRUSH32)(COLOR_BTNFACE + 1);
327     wndClass.lpszClassName = ANIMATE_CLASS32A;
328  
329     RegisterClass32A (&wndClass);
330 }
331
332
333 VOID
334 ANIMATE_Unregister (VOID)
335 {
336     if (GlobalFindAtom32A (ANIMATE_CLASS32A))
337         UnregisterClass32A (ANIMATE_CLASS32A, (HINSTANCE32)NULL);
338 }
339