- Add a lot of traces to make debugging a bit easier.
[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     return 0;
89 }
90
91 BOOL MCIAVI_UnregisterClass(void)
92 {
93     return UnregisterClassW(mciaviW, MCIAVI_hInstance);
94 }
95
96 BOOL MCIAVI_RegisterClass(void)
97 {
98     WNDCLASSW wndClass;
99
100     ZeroMemory(&wndClass, sizeof(WNDCLASSW));
101     wndClass.style         = CS_DBLCLKS;
102     wndClass.lpfnWndProc   = MCIAVI_WindowProc;
103     wndClass.cbWndExtra    = sizeof(MCIDEVICEID);
104     wndClass.hInstance     = MCIAVI_hInstance;
105     wndClass.hCursor       = LoadCursorW(0, (LPCWSTR)IDC_ARROW);
106     wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
107     wndClass.lpszClassName = mciaviW;
108
109     if (RegisterClassW(&wndClass)) return TRUE;
110     if (GetLastError() == ERROR_CLASS_ALREADY_EXISTS) return TRUE;
111
112     return FALSE;
113 }
114
115 BOOL    MCIAVI_CreateWindow(WINE_MCIAVI* wma, DWORD dwFlags, LPMCI_DGV_OPEN_PARMSA lpOpenParms)
116 {
117     static const WCHAR captionW[] = {'W','i','n','e',' ','M','C','I','-','A','V','I',' ','p','l','a','y','e','r',0};
118     HWND        hParent = 0;
119     DWORD       dwStyle = WS_OVERLAPPEDWINDOW;
120     int         p = CW_USEDEFAULT;
121     RECT rc;
122
123     /* what should be done ? */
124     if (wma->hWnd) return TRUE;
125
126     if (dwFlags & MCI_DGV_OPEN_PARENT)  hParent = lpOpenParms->hWndParent;
127     if (dwFlags & MCI_DGV_OPEN_WS)      dwStyle = lpOpenParms->dwStyle;
128     if (dwStyle & WS_CHILD)             p = 0;
129
130     rc.left = p;
131     rc.top = p;
132     rc.right = (wma->hic ? wma->outbih : wma->inbih)->biWidth;
133     rc.bottom = (wma->hic ? wma->outbih : wma->inbih)->biHeight;
134     AdjustWindowRect(&rc, dwStyle, FALSE);
135
136     wma->hWnd = CreateWindowW(mciaviW, captionW,
137                              dwStyle, rc.left, rc.top,
138                              rc.right, rc.bottom,
139                              hParent, 0, MCIAVI_hInstance,
140                               (LPVOID)wma->wDevID);
141     wma->hWndPaint = wma->hWnd;
142     return (BOOL)wma->hWnd;
143 }
144
145 /***************************************************************************
146  *                              MCIAVI_mciPut                   [internal]
147  */
148 DWORD   MCIAVI_mciPut(UINT wDevID, DWORD dwFlags, LPMCI_DGV_PUT_PARMS lpParms)
149 {
150     WINE_MCIAVI*        wma = MCIAVI_mciGetOpenDev(wDevID);
151     RECT                rc;
152
153     TRACE("(%04x, %08lX, %p)\n", wDevID, dwFlags, lpParms);
154
155     if (lpParms == NULL)        return MCIERR_NULL_PARAMETER_BLOCK;
156     if (wma == NULL)            return MCIERR_INVALID_DEVICE_ID;
157
158     EnterCriticalSection(&wma->cs);
159
160     if (dwFlags & MCI_DGV_RECT) {
161         rc = lpParms->rc;
162     } else {
163         GetClientRect(wma->hWndPaint, &rc);
164     }
165
166     if (dwFlags & MCI_DGV_PUT_CLIENT) {
167         FIXME("PUT_CLIENT %s\n", wine_dbgstr_rect(&rc));
168         LeaveCriticalSection(&wma->cs);
169         return MCIERR_UNRECOGNIZED_COMMAND;
170     }
171     if (dwFlags & MCI_DGV_PUT_DESTINATION) {
172         TRACE("PUT_DESTINATION %s\n", wine_dbgstr_rect(&rc));
173         wma->dest = rc;
174     }
175     if (dwFlags & MCI_DGV_PUT_FRAME) {
176         FIXME("PUT_FRAME %s\n", wine_dbgstr_rect(&rc));
177         LeaveCriticalSection(&wma->cs);
178         return MCIERR_UNRECOGNIZED_COMMAND;
179     }
180     if (dwFlags & MCI_DGV_PUT_SOURCE) {
181         TRACE("PUT_SOURCE %s\n", wine_dbgstr_rect(&rc));
182         wma->source = rc;
183     }
184     if (dwFlags & MCI_DGV_PUT_VIDEO) {
185         FIXME("PUT_VIDEO %s\n", wine_dbgstr_rect(&rc));
186         LeaveCriticalSection(&wma->cs);
187         return MCIERR_UNRECOGNIZED_COMMAND;
188     }
189     if (dwFlags & MCI_DGV_PUT_WINDOW) {
190         FIXME("PUT_WINDOW %s\n", wine_dbgstr_rect(&rc));
191         LeaveCriticalSection(&wma->cs);
192         return MCIERR_UNRECOGNIZED_COMMAND;
193     }
194     LeaveCriticalSection(&wma->cs);
195     return 0;
196 }
197
198 /******************************************************************************
199  *                              MCIAVI_mciWhere                 [internal]
200  */
201 DWORD   MCIAVI_mciWhere(UINT wDevID, DWORD dwFlags, LPMCI_DGV_RECT_PARMS lpParms)
202 {
203     WINE_MCIAVI*        wma = MCIAVI_mciGetOpenDev(wDevID);
204
205     TRACE("(%04x, %08lx, %p)\n", wDevID, dwFlags, lpParms);
206
207     if (lpParms == NULL)        return MCIERR_NULL_PARAMETER_BLOCK;
208     if (wma == NULL)            return MCIERR_INVALID_DEVICE_ID;
209
210     if (dwFlags & MCI_DGV_WHERE_MAX)
211     {
212         FIXME("WHERE_MAX\n");
213         return MCIERR_UNRECOGNIZED_COMMAND;
214     }
215
216     EnterCriticalSection(&wma->cs);
217
218     if (dwFlags & MCI_DGV_WHERE_DESTINATION) {
219         TRACE("WHERE_DESTINATION %s\n", wine_dbgstr_rect(&wma->dest));
220         lpParms->rc = wma->dest;
221     }
222     if (dwFlags & MCI_DGV_WHERE_FRAME) {
223        FIXME("MCI_DGV_WHERE_FRAME\n");
224         LeaveCriticalSection(&wma->cs);
225         return MCIERR_UNRECOGNIZED_COMMAND;
226     }
227     if (dwFlags & MCI_DGV_WHERE_SOURCE) {
228         TRACE("WHERE_SOURCE %s\n", wine_dbgstr_rect(&wma->source));
229         lpParms->rc = wma->source;
230     }
231     if (dwFlags & MCI_DGV_WHERE_VIDEO) {
232        FIXME("WHERE_VIDEO\n");
233         LeaveCriticalSection(&wma->cs);
234         return MCIERR_UNRECOGNIZED_COMMAND;
235     }
236     if (dwFlags & MCI_DGV_WHERE_WINDOW) {
237         GetClientRect(wma->hWndPaint, &lpParms->rc);
238         TRACE("WHERE_WINDOW %s\n", wine_dbgstr_rect(&lpParms->rc));
239     }
240     LeaveCriticalSection(&wma->cs);
241     return 0;
242 }
243
244 /***************************************************************************
245  *                              MCIAVI_mciWindow                        [internal]
246  */
247 DWORD   MCIAVI_mciWindow(UINT wDevID, DWORD dwFlags, LPMCI_DGV_WINDOW_PARMSA lpParms)
248 {
249     WINE_MCIAVI*        wma = MCIAVI_mciGetOpenDev(wDevID);
250
251     TRACE("(%04x, %08lX, %p)\n", wDevID, dwFlags, lpParms);
252
253     if (lpParms == NULL)        return MCIERR_NULL_PARAMETER_BLOCK;
254     if (wma == NULL)            return MCIERR_INVALID_DEVICE_ID;
255
256     EnterCriticalSection(&wma->cs);
257
258     if (dwFlags & MCI_DGV_WINDOW_HWND) {
259         if (IsWindow(lpParms->hWnd))
260         {
261             TRACE("Setting hWnd to %p\n", lpParms->hWnd);
262             if (wma->hWnd) ShowWindow(wma->hWnd, SW_HIDE);
263             wma->hWndPaint = (lpParms->hWnd == MCI_DGV_WINDOW_DEFAULT) ? wma->hWnd : lpParms->hWnd;
264         }
265     }
266     if (dwFlags & MCI_DGV_WINDOW_STATE) {
267         TRACE("Setting nCmdShow to %d\n", lpParms->nCmdShow);
268         ShowWindow(wma->hWndPaint, lpParms->nCmdShow);
269     }
270     if (dwFlags & MCI_DGV_WINDOW_TEXT) {
271         TRACE("Setting caption to '%s'\n", lpParms->lpstrText);
272        SetWindowTextA(wma->hWndPaint, lpParms->lpstrText);
273     }
274
275     LeaveCriticalSection(&wma->cs);
276     return 0;
277 }