Fix some gcc 4.0 warnings.
[wine] / dlls / winmm / mciavi / wnd.c
1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
2
3 /*
4  * Digital video MCI Wine Driver
5  *
6  * Copyright 1999, 2000 Eric POUECH
7  * Copyright 2003 Dmitry Timoshkov
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23
24 #include <string.h>
25 #include "private_mciavi.h"
26 #include "wine/debug.h"
27
28 WINE_DEFAULT_DEBUG_CHANNEL(mciavi);
29
30 static const WCHAR mciaviW[] = {'M','C','I','A','V','I',0};
31
32 static LRESULT WINAPI MCIAVI_WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
33 {
34     TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n", hWnd, uMsg, wParam, lParam);
35
36     switch (uMsg) {
37     case WM_CREATE:
38         SetWindowLongW(hWnd, 0, (LPARAM)((CREATESTRUCTW *)lParam)->lpCreateParams);
39         return DefWindowProcW(hWnd, uMsg, wParam, lParam);
40
41     case WM_DESTROY:
42         MCIAVI_mciClose(GetWindowLongW(hWnd, 0), MCI_WAIT, NULL);
43         SetWindowLongW(hWnd, 0, 0);
44         return DefWindowProcW(hWnd, uMsg, wParam, lParam);
45
46     case WM_ERASEBKGND:
47         {
48             RECT        rect;
49             GetClientRect(hWnd, &rect);
50             FillRect((HDC)wParam, &rect, GetStockObject(BLACK_BRUSH));
51         }
52        return 1;
53
54     case WM_PAINT:
55         {
56             WINE_MCIAVI *wma = (WINE_MCIAVI *)mciGetDriverData(GetWindowLongW(hWnd, 0));
57
58             if (!wma)
59                 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
60             
61             EnterCriticalSection(&wma->cs);
62
63             /* the animation isn't playing, don't paint */
64             if (wma->dwStatus == MCI_MODE_NOT_READY)
65             {
66                 LeaveCriticalSection(&wma->cs);
67                 /* default paint handling */
68                 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
69             }
70
71             if (wParam)
72                 MCIAVI_PaintFrame(wma, (HDC)wParam);
73             else
74             {
75                 PAINTSTRUCT ps;
76                 BeginPaint(hWnd, &ps);
77                 MCIAVI_PaintFrame(wma, ps.hdc);
78                 EndPaint(hWnd, &ps);
79             }
80
81             LeaveCriticalSection(&wma->cs);
82         }
83        return 1;
84
85     default:
86         return DefWindowProcW(hWnd, uMsg, wParam, lParam);
87     }
88 }
89
90 BOOL MCIAVI_UnregisterClass(void)
91 {
92     return UnregisterClassW(mciaviW, MCIAVI_hInstance);
93 }
94
95 BOOL MCIAVI_RegisterClass(void)
96 {
97     WNDCLASSW wndClass;
98
99     ZeroMemory(&wndClass, sizeof(WNDCLASSW));
100     wndClass.style         = CS_DBLCLKS;
101     wndClass.lpfnWndProc   = MCIAVI_WindowProc;
102     wndClass.cbWndExtra    = sizeof(MCIDEVICEID);
103     wndClass.hInstance     = MCIAVI_hInstance;
104     wndClass.hCursor       = LoadCursorW(0, (LPCWSTR)IDC_ARROW);
105     wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
106     wndClass.lpszClassName = mciaviW;
107
108     if (RegisterClassW(&wndClass)) return TRUE;
109     if (GetLastError() == ERROR_CLASS_ALREADY_EXISTS) return TRUE;
110
111     return FALSE;
112 }
113
114 BOOL    MCIAVI_CreateWindow(WINE_MCIAVI* wma, DWORD dwFlags, LPMCI_DGV_OPEN_PARMSW lpOpenParms)
115 {
116     static const WCHAR captionW[] = {'W','i','n','e',' ','M','C','I','-','A','V','I',' ','p','l','a','y','e','r',0};
117     HWND        hParent = 0;
118     DWORD       dwStyle = WS_OVERLAPPEDWINDOW;
119     RECT        rc;
120
121     /* what should be done ? */
122     if (wma->hWnd) return TRUE;
123
124     if (dwFlags & MCI_DGV_OPEN_PARENT)  hParent = lpOpenParms->hWndParent;
125     if (dwFlags & MCI_DGV_OPEN_WS)      dwStyle = lpOpenParms->dwStyle;
126
127     rc.left = rc.top = 0;
128     rc.right = (wma->hic ? wma->outbih : wma->inbih)->biWidth;
129     rc.bottom = (wma->hic ? wma->outbih : wma->inbih)->biHeight;
130     AdjustWindowRect(&rc, dwStyle, FALSE);
131     if (!(dwStyle & (WS_CHILD|WS_POPUP))) /* overlapped window ? */
132     {
133         rc.right -= rc.left;
134         rc.bottom -= rc.top;
135         rc.left = rc.top = CW_USEDEFAULT;
136     }
137
138     wma->hWnd = CreateWindowW(mciaviW, captionW,
139                               dwStyle, rc.left, rc.top,
140                               rc.right, rc.bottom,
141                               hParent, 0, MCIAVI_hInstance,
142                               (LPVOID)wma->wDevID);
143     wma->hWndPaint = wma->hWnd;
144     return (BOOL)wma->hWnd;
145 }
146
147 /***************************************************************************
148  *                              MCIAVI_mciPut                   [internal]
149  */
150 DWORD   MCIAVI_mciPut(UINT wDevID, DWORD dwFlags, LPMCI_DGV_PUT_PARMS lpParms)
151 {
152     WINE_MCIAVI*        wma = MCIAVI_mciGetOpenDev(wDevID);
153     RECT                rc;
154
155     TRACE("(%04x, %08lX, %p)\n", wDevID, dwFlags, lpParms);
156
157     if (lpParms == NULL)        return MCIERR_NULL_PARAMETER_BLOCK;
158     if (wma == NULL)            return MCIERR_INVALID_DEVICE_ID;
159
160     EnterCriticalSection(&wma->cs);
161
162     if (dwFlags & MCI_DGV_RECT) {
163         rc = lpParms->rc;
164     } else {
165         GetClientRect(wma->hWndPaint, &rc);
166     }
167
168     if (dwFlags & MCI_DGV_PUT_CLIENT) {
169         FIXME("PUT_CLIENT %s\n", wine_dbgstr_rect(&rc));
170         LeaveCriticalSection(&wma->cs);
171         return MCIERR_UNRECOGNIZED_COMMAND;
172     }
173     if (dwFlags & MCI_DGV_PUT_DESTINATION) {
174         TRACE("PUT_DESTINATION %s\n", wine_dbgstr_rect(&rc));
175         wma->dest = rc;
176     }
177     if (dwFlags & MCI_DGV_PUT_FRAME) {
178         FIXME("PUT_FRAME %s\n", wine_dbgstr_rect(&rc));
179         LeaveCriticalSection(&wma->cs);
180         return MCIERR_UNRECOGNIZED_COMMAND;
181     }
182     if (dwFlags & MCI_DGV_PUT_SOURCE) {
183         TRACE("PUT_SOURCE %s\n", wine_dbgstr_rect(&rc));
184         wma->source = rc;
185     }
186     if (dwFlags & MCI_DGV_PUT_VIDEO) {
187         FIXME("PUT_VIDEO %s\n", wine_dbgstr_rect(&rc));
188         LeaveCriticalSection(&wma->cs);
189         return MCIERR_UNRECOGNIZED_COMMAND;
190     }
191     if (dwFlags & MCI_DGV_PUT_WINDOW) {
192         FIXME("PUT_WINDOW %s\n", wine_dbgstr_rect(&rc));
193         LeaveCriticalSection(&wma->cs);
194         return MCIERR_UNRECOGNIZED_COMMAND;
195     }
196     LeaveCriticalSection(&wma->cs);
197     return 0;
198 }
199
200 /******************************************************************************
201  *                              MCIAVI_mciWhere                 [internal]
202  */
203 DWORD   MCIAVI_mciWhere(UINT wDevID, DWORD dwFlags, LPMCI_DGV_RECT_PARMS lpParms)
204 {
205     WINE_MCIAVI*        wma = MCIAVI_mciGetOpenDev(wDevID);
206
207     TRACE("(%04x, %08lx, %p)\n", wDevID, dwFlags, lpParms);
208
209     if (lpParms == NULL)        return MCIERR_NULL_PARAMETER_BLOCK;
210     if (wma == NULL)            return MCIERR_INVALID_DEVICE_ID;
211
212     EnterCriticalSection(&wma->cs);
213
214     if (dwFlags & MCI_DGV_WHERE_DESTINATION) {
215         if (dwFlags & MCI_DGV_WHERE_MAX) {
216             GetClientRect(wma->hWndPaint, &lpParms->rc);
217             TRACE("WHERE_DESTINATION_MAX %s\n", wine_dbgstr_rect(&lpParms->rc));
218         } else {
219             TRACE("WHERE_DESTINATION %s\n", wine_dbgstr_rect(&wma->dest));
220             lpParms->rc = wma->dest;
221         }
222     }
223     if (dwFlags & MCI_DGV_WHERE_FRAME) {
224         if (dwFlags & MCI_DGV_WHERE_MAX)
225             FIXME("MCI_DGV_WHERE_FRAME_MAX\n");
226         else
227             FIXME("MCI_DGV_WHERE_FRAME\n");
228         LeaveCriticalSection(&wma->cs);
229         return MCIERR_UNRECOGNIZED_COMMAND;
230     }
231     if (dwFlags & MCI_DGV_WHERE_SOURCE) {
232         if (dwFlags & MCI_DGV_WHERE_MAX) {
233             RECT rect;
234             rect.left = 0;
235             rect.top = 0;
236             rect.right = wma->inbih->biWidth; 
237             rect.bottom = wma->inbih->biHeight; 
238             TRACE("WHERE_SOURCE_MAX %s\n", wine_dbgstr_rect(&rect));
239             lpParms->rc = rect;
240         } else {
241             TRACE("WHERE_SOURCE %s\n", wine_dbgstr_rect(&wma->source));
242             lpParms->rc = wma->source;
243         }
244     }
245     if (dwFlags & MCI_DGV_WHERE_VIDEO) {
246         if (dwFlags & MCI_DGV_WHERE_MAX)
247             FIXME("WHERE_VIDEO_MAX\n");
248         else
249             FIXME("WHERE_VIDEO\n");
250         LeaveCriticalSection(&wma->cs);
251         return MCIERR_UNRECOGNIZED_COMMAND;
252     }
253     if (dwFlags & MCI_DGV_WHERE_WINDOW) {
254         if (dwFlags & MCI_DGV_WHERE_MAX) {
255             GetWindowRect(GetDesktopWindow(), &lpParms->rc);
256             TRACE("WHERE_WINDOW_MAX %s\n", wine_dbgstr_rect(&lpParms->rc));
257         } else {
258             GetWindowRect(wma->hWndPaint, &lpParms->rc);
259             TRACE("WHERE_WINDOW %s\n", wine_dbgstr_rect(&lpParms->rc));
260         }
261     }
262     LeaveCriticalSection(&wma->cs);
263     return 0;
264 }
265
266 /***************************************************************************
267  *                              MCIAVI_mciWindow                        [internal]
268  */
269 DWORD   MCIAVI_mciWindow(UINT wDevID, DWORD dwFlags, LPMCI_DGV_WINDOW_PARMSW lpParms)
270 {
271     WINE_MCIAVI*        wma = MCIAVI_mciGetOpenDev(wDevID);
272
273     TRACE("(%04x, %08lX, %p)\n", wDevID, dwFlags, lpParms);
274
275     if (lpParms == NULL)        return MCIERR_NULL_PARAMETER_BLOCK;
276     if (wma == NULL)            return MCIERR_INVALID_DEVICE_ID;
277
278     EnterCriticalSection(&wma->cs);
279
280     if (dwFlags & MCI_DGV_WINDOW_HWND) {
281         if (IsWindow(lpParms->hWnd))
282         {
283             TRACE("Setting hWnd to %p\n", lpParms->hWnd);
284             if (wma->hWnd) ShowWindow(wma->hWnd, SW_HIDE);
285             wma->hWndPaint = (lpParms->hWnd == MCI_DGV_WINDOW_DEFAULT) ? wma->hWnd : lpParms->hWnd;
286         }
287     }
288     if (dwFlags & MCI_DGV_WINDOW_STATE) {
289         TRACE("Setting nCmdShow to %d\n", lpParms->nCmdShow);
290         ShowWindow(wma->hWndPaint, lpParms->nCmdShow);
291     }
292     if (dwFlags & MCI_DGV_WINDOW_TEXT) {
293         TRACE("Setting caption to %s\n", debugstr_w(lpParms->lpstrText));
294         SetWindowTextW(wma->hWndPaint, lpParms->lpstrText);
295     }
296
297     LeaveCriticalSection(&wma->cs);
298     return 0;
299 }