Removed no longer necessary win.h include, added now necessary other
[wine] / dlls / comctl32 / animate.c
1 /*
2  * Animation control
3  *
4  * Copyright 1998, 1999 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
17 #include "winbase.h"
18 #include "commctrl.h"
19 #include "animate.h"
20 #include "debug.h"
21
22 #define ANIMATE_GetInfoPtr(hwnd) ((ANIMATE_INFO *)GetWindowLongA (hwnd, 0))
23
24
25 static BOOL
26 ANIMATE_LoadResA (ANIMATE_INFO *infoPtr, HINSTANCE hInst, LPSTR lpName)
27 {
28     HRSRC hrsrc;
29     HGLOBAL handle;
30
31     hrsrc = FindResourceA (hInst, lpName, "AVI");
32     if (!hrsrc)
33         return FALSE;
34
35     handle = LoadResource (hInst, hrsrc);
36     if (!handle)
37         return FALSE;
38
39     infoPtr->lpAvi = LockResource (handle);
40     if (!infoPtr->lpAvi)
41         return FALSE;
42
43     return TRUE;
44 }
45
46
47 static BOOL
48 ANIMATE_LoadFileA (ANIMATE_INFO *infoPtr, LPSTR lpName)
49 {
50     HANDLE handle;
51
52     infoPtr->hFile =
53         CreateFileA (lpName, GENERIC_READ, 0, NULL, OPEN_EXISTING,
54                        FILE_ATTRIBUTE_NORMAL, 0);
55     if (!infoPtr->hFile)
56         return FALSE;
57
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;
65     }
66
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;
72     }
73
74     return TRUE;
75 }
76
77
78 static VOID
79 ANIMATE_Free (ANIMATE_INFO *infoPtr)
80 {
81     if (infoPtr->hFile) {
82         UnmapViewOfFile (infoPtr->lpAvi);
83         CloseHandle (infoPtr->hFile);
84         infoPtr->lpAvi = NULL;
85     }
86     else {
87         GlobalFree ((HGLOBAL)infoPtr->lpAvi);
88         infoPtr->lpAvi = NULL;
89     }
90 }
91
92
93 static VOID
94 ANIMATE_GetAviInfo (infoPtr)
95 {
96
97
98 }
99
100
101 static LRESULT
102 ANIMATE_OpenA (HWND hwnd, WPARAM wParam, LPARAM lParam)
103 {
104     ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hwnd);
105     HINSTANCE hInstance = (HINSTANCE)wParam;
106
107     ANIMATE_Free (infoPtr);
108
109     if (!lParam) {
110         TRACE (animate, "closing avi!\n");
111         return TRUE;
112     }
113     
114     if (HIWORD(lParam)) {
115         FIXME (animate, "(\"%s\") empty stub!\n", (LPSTR)lParam);
116
117         if (ANIMATE_LoadResA (infoPtr, hInstance, (LPSTR)lParam)) {
118
119             FIXME (animate, "AVI resource found!\n");
120
121         }
122         else {
123             FIXME (animate, "No AVI resource found!\n");
124             if (ANIMATE_LoadFileA (infoPtr, (LPSTR)lParam)) {
125                 FIXME (animate, "AVI file found!\n");
126             }
127             else {
128                 FIXME (animate, "No AVI file found!\n");
129                 return FALSE;
130             }
131         }
132     }
133     else {
134         FIXME (animate, "(%u) empty stub!\n", (WORD)LOWORD(lParam));
135
136         if (ANIMATE_LoadResA (infoPtr, hInstance,
137                                 MAKEINTRESOURCEA((INT)lParam))) {
138             FIXME (animate, "AVI resource found!\n");
139         }
140         else {
141             FIXME (animate, "No AVI resource found!\n");
142             return FALSE;
143         }
144     }
145
146     ANIMATE_GetAviInfo (infoPtr);
147
148     return TRUE;
149 }
150
151
152 /* << ANIMATE_Open32W >> */
153
154
155 static LRESULT
156 ANIMATE_Play (HWND hwnd, WPARAM wParam, LPARAM lParam)
157 {
158     /* ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hwnd); */
159     INT nFrom   = (INT)LOWORD(lParam);
160     INT nTo     = (INT)HIWORD(lParam);
161     INT nRepeat = (INT)wParam;
162
163 #if 0
164     /* nothing opened */
165     if (...)
166         return FALSE;
167 #endif
168     
169     if (nRepeat == -1) {
170
171         FIXME (animate, "(loop from=%d to=%d) empty stub!\n",
172                nFrom, nTo);
173
174     }
175     else {
176
177         FIXME (animate, "(repeat=%d from=%d to=%d) empty stub!\n",
178                nRepeat, nFrom, nTo);
179
180     }
181
182
183     return TRUE;
184 }
185
186
187 static LRESULT
188 ANIMATE_Stop (HWND hwnd, WPARAM wParam, LPARAM lParam)
189 {
190     /* ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hwnd); */
191
192 #if 0
193     /* nothing opened */
194     if (...)
195         return FALSE;
196 #endif
197     
198     return TRUE;
199 }
200
201
202
203 static LRESULT
204 ANIMATE_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
205 {
206     ANIMATE_INFO *infoPtr;
207
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;
213     }
214
215     /* store pointer to info structure */
216     SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
217
218
219     /* set default settings */
220
221
222     return 0;
223 }
224
225
226 static LRESULT
227 ANIMATE_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
228 {
229     ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hwnd);
230
231
232     /* free avi data */
233     ANIMATE_Free (infoPtr);
234
235     /* free animate info data */
236     COMCTL32_Free (infoPtr);
237
238     return 0;
239 }
240
241
242 #if 0
243 static LRESULT
244 ANIMATE_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
245 {
246     ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hwnd);
247 /*
248     HBRUSH32 hBrush = CreateSolidBrush32 (infoPtr->clrBk);
249     RECT32 rect;
250
251     GetClientRect32 (wndPtr->hwndSelf, &rect);
252     FillRect32 ((HDC32)wParam, &rect, hBrush);
253     DeleteObject32 (hBrush);
254 */
255     return TRUE;
256 }
257 #endif
258
259
260
261 LRESULT WINAPI
262 ANIMATE_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
263 {
264     switch (uMsg)
265     {
266         case ACM_OPENA:
267             return ANIMATE_OpenA (hwnd, wParam, lParam);
268
269 /*      case ACM_OPEN32W: */
270 /*          return ANIMATE_Open32W (hwnd, wParam, lParam); */
271
272         case ACM_PLAY:
273             return ANIMATE_Play (hwnd, wParam, lParam);
274
275         case ACM_STOP:
276             return ANIMATE_Stop (hwnd, wParam, lParam);
277
278
279         case WM_CREATE:
280             return ANIMATE_Create (hwnd, wParam, lParam);
281
282         case WM_DESTROY:
283             return ANIMATE_Destroy (hwnd, wParam, lParam);
284
285 /*      case WM_ERASEBKGND: */
286 /*          return ANIMATE_EraseBackground (hwnd, wParam, lParam); */
287
288 /*      case WM_NCCREATE: */
289 /*      case WM_NCHITTEST: */
290 /*      case WM_PAINT: */
291 /*      case WM_SIZE: */
292 /*      case WM_STYLECHANGED: */
293 /*      case WM_TIMER: */
294
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);
300     }
301     return 0;
302 }
303
304
305 VOID
306 ANIMATE_Register (VOID)
307 {
308     WNDCLASSA wndClass;
309
310     if (GlobalFindAtomA (ANIMATE_CLASSA)) return;
311
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;
320  
321     RegisterClassA (&wndClass);
322 }
323
324
325 VOID
326 ANIMATE_Unregister (VOID)
327 {
328     if (GlobalFindAtomA (ANIMATE_CLASSA))
329         UnregisterClassA (ANIMATE_CLASSA, (HINSTANCE)NULL);
330 }
331