mf/session: Forward more events to the application.
[wine/zf.git] / dlls / mciavi32 / wnd.c
blobd48dbb1357a722003e0b58fbd0a8d5265109aef9
1 /*
2 * Digital video MCI Wine Driver
4 * Copyright 1999, 2000 Eric POUECH
5 * Copyright 2003 Dmitry Timoshkov
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <string.h>
23 #include "private_mciavi.h"
24 #include "wine/debug.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(mciavi);
28 static LRESULT WINAPI MCIAVI_WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
30 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n", hWnd, uMsg, wParam, lParam);
32 switch (uMsg) {
33 case WM_CREATE:
34 SetWindowLongW(hWnd, 0, (LPARAM)((CREATESTRUCTW *)lParam)->lpCreateParams);
35 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
37 case WM_DESTROY:
38 MCIAVI_mciClose(GetWindowLongW(hWnd, 0), MCI_WAIT, NULL);
39 SetWindowLongW(hWnd, 0, 0);
40 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
42 case WM_ERASEBKGND:
44 RECT rect;
45 GetClientRect(hWnd, &rect);
46 FillRect((HDC)wParam, &rect, GetStockObject(BLACK_BRUSH));
48 return 1;
50 case WM_PAINT:
52 WINE_MCIAVI *wma = (WINE_MCIAVI *)mciGetDriverData(GetWindowLongW(hWnd, 0));
54 if (!wma)
55 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
57 EnterCriticalSection(&wma->cs);
59 /* the animation isn't playing, don't paint */
60 if (wma->dwStatus == MCI_MODE_NOT_READY)
62 LeaveCriticalSection(&wma->cs);
63 /* default paint handling */
64 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
67 if (wParam)
68 MCIAVI_PaintFrame(wma, (HDC)wParam);
69 else
71 PAINTSTRUCT ps;
72 BeginPaint(hWnd, &ps);
73 MCIAVI_PaintFrame(wma, ps.hdc);
74 EndPaint(hWnd, &ps);
77 LeaveCriticalSection(&wma->cs);
79 return 1;
81 default:
82 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
86 BOOL MCIAVI_UnregisterClass(void)
88 return UnregisterClassW(L"MCIAVI", MCIAVI_hInstance);
91 BOOL MCIAVI_RegisterClass(void)
93 WNDCLASSW wndClass;
95 ZeroMemory(&wndClass, sizeof(WNDCLASSW));
96 wndClass.style = CS_DBLCLKS;
97 wndClass.lpfnWndProc = MCIAVI_WindowProc;
98 wndClass.cbWndExtra = sizeof(MCIDEVICEID);
99 wndClass.hInstance = MCIAVI_hInstance;
100 wndClass.hCursor = LoadCursorW(0, (LPCWSTR)IDC_ARROW);
101 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
102 wndClass.lpszClassName = L"MCIAVI";
104 if (RegisterClassW(&wndClass)) return TRUE;
105 if (GetLastError() == ERROR_CLASS_ALREADY_EXISTS) return TRUE;
107 return FALSE;
110 BOOL MCIAVI_CreateWindow(WINE_MCIAVI* wma, DWORD dwFlags, LPMCI_DGV_OPEN_PARMSW lpParms)
112 HWND hParent = 0;
113 DWORD dwStyle = WS_OVERLAPPEDWINDOW;
114 RECT rc;
116 /* what should be done ? */
117 if (wma->hWnd) return TRUE;
119 if (dwFlags & MCI_DGV_OPEN_PARENT) hParent = lpParms->hWndParent;
120 if (dwFlags & MCI_DGV_OPEN_WS) dwStyle = lpParms->dwStyle;
122 if (wma->hic)
123 SetRect(&rc, 0, 0, wma->outbih->biWidth, wma->outbih->biHeight);
124 else
125 SetRect(&rc, 0, 0, wma->inbih->biWidth, wma->inbih->biHeight);
127 AdjustWindowRect(&rc, dwStyle, FALSE);
128 if (!(dwStyle & (WS_CHILD|WS_POPUP))) /* overlapped window ? */
130 rc.right -= rc.left;
131 rc.bottom -= rc.top;
132 rc.left = rc.top = CW_USEDEFAULT;
135 wma->hWnd = CreateWindowW(L"MCIAVI", L"Wine MCI-AVI player", dwStyle, rc.left, rc.top,
136 rc.right, rc.bottom, hParent, 0, MCIAVI_hInstance,
137 ULongToPtr(wma->wDevID));
138 wma->hWndPaint = wma->hWnd;
140 TRACE("(%04x, %08X, %p, style %x, parent %p, dimensions %dx%d, hwnd %p)\n", wma->wDevID,
141 dwFlags, lpParms, dwStyle, hParent, rc.right - rc.left, rc.bottom - rc.top, wma->hWnd);
142 return wma->hWnd != 0;
145 /***************************************************************************
146 * MCIAVI_mciPut [internal]
148 DWORD MCIAVI_mciPut(UINT wDevID, DWORD dwFlags, LPMCI_DGV_PUT_PARMS lpParms)
150 WINE_MCIAVI* wma = MCIAVI_mciGetOpenDev(wDevID);
151 RECT rc;
153 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
155 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
156 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
157 if (dwFlags & MCI_TEST) return 0;
159 EnterCriticalSection(&wma->cs);
161 if (dwFlags & MCI_DGV_RECT) {
162 /* In MCI, RECT structure is used differently: rc.right = width & rc.bottom = height
163 * So convert input MCI RECT into a normal RECT */
164 SetRect(&rc, lpParms->rc.left, lpParms->rc.top, lpParms->rc.left + lpParms->rc.right,
165 lpParms->rc.top + lpParms->rc.bottom);
166 } else {
167 GetClientRect(wma->hWndPaint, &rc);
170 if (dwFlags & MCI_DGV_PUT_CLIENT) {
171 FIXME("PUT_CLIENT %s\n", wine_dbgstr_rect(&rc));
172 LeaveCriticalSection(&wma->cs);
173 return MCIERR_UNRECOGNIZED_COMMAND;
175 if (dwFlags & MCI_DGV_PUT_DESTINATION) {
176 TRACE("PUT_DESTINATION %s\n", wine_dbgstr_rect(&rc));
177 wma->dest = rc;
179 if (dwFlags & MCI_DGV_PUT_FRAME) {
180 FIXME("PUT_FRAME %s\n", wine_dbgstr_rect(&rc));
181 LeaveCriticalSection(&wma->cs);
182 return MCIERR_UNRECOGNIZED_COMMAND;
184 if (dwFlags & MCI_DGV_PUT_SOURCE) {
185 TRACE("PUT_SOURCE %s\n", wine_dbgstr_rect(&rc));
186 wma->source = rc;
188 if (dwFlags & MCI_DGV_PUT_VIDEO) {
189 FIXME("PUT_VIDEO %s\n", wine_dbgstr_rect(&rc));
190 LeaveCriticalSection(&wma->cs);
191 return MCIERR_UNRECOGNIZED_COMMAND;
193 if (dwFlags & MCI_DGV_PUT_WINDOW) {
194 TRACE("PUT_WINDOW %s\n", wine_dbgstr_rect(&rc));
195 SetWindowPos(wma->hWndPaint, NULL, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_NOZORDER);
197 LeaveCriticalSection(&wma->cs);
198 return 0;
201 /******************************************************************************
202 * MCIAVI_mciWhere [internal]
204 DWORD MCIAVI_mciWhere(UINT wDevID, DWORD dwFlags, LPMCI_DGV_RECT_PARMS lpParms)
206 WINE_MCIAVI* wma = MCIAVI_mciGetOpenDev(wDevID);
207 RECT rc;
209 TRACE("(%04x, %08x, %p)\n", wDevID, dwFlags, lpParms);
211 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
212 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
213 /* Ignore MCI_TEST flag. */
215 EnterCriticalSection(&wma->cs);
217 if (dwFlags & MCI_DGV_WHERE_DESTINATION) {
218 if (dwFlags & MCI_DGV_WHERE_MAX) {
219 GetClientRect(wma->hWndPaint, &rc);
220 TRACE("WHERE_DESTINATION_MAX %s\n", wine_dbgstr_rect(&rc));
221 } else {
222 TRACE("WHERE_DESTINATION %s\n", wine_dbgstr_rect(&wma->dest));
223 rc = wma->dest;
226 if (dwFlags & MCI_DGV_WHERE_FRAME) {
227 if (dwFlags & MCI_DGV_WHERE_MAX)
228 FIXME("MCI_DGV_WHERE_FRAME_MAX\n");
229 else
230 FIXME("MCI_DGV_WHERE_FRAME\n");
231 LeaveCriticalSection(&wma->cs);
232 return MCIERR_UNRECOGNIZED_COMMAND;
234 if (dwFlags & MCI_DGV_WHERE_SOURCE) {
235 if (dwFlags & MCI_DGV_WHERE_MAX) {
236 SetRect(&rc, 0, 0, wma->inbih->biWidth, wma->inbih->biHeight);
237 TRACE("WHERE_SOURCE_MAX %s\n", wine_dbgstr_rect(&rc));
238 } else {
239 TRACE("WHERE_SOURCE %s\n", wine_dbgstr_rect(&wma->source));
240 rc = wma->source;
243 if (dwFlags & MCI_DGV_WHERE_VIDEO) {
244 if (dwFlags & MCI_DGV_WHERE_MAX)
245 FIXME("WHERE_VIDEO_MAX\n");
246 else
247 FIXME("WHERE_VIDEO\n");
248 LeaveCriticalSection(&wma->cs);
249 return MCIERR_UNRECOGNIZED_COMMAND;
251 if (dwFlags & MCI_DGV_WHERE_WINDOW) {
252 if (dwFlags & MCI_DGV_WHERE_MAX) {
253 GetWindowRect(GetDesktopWindow(), &rc);
254 TRACE("WHERE_WINDOW_MAX %s\n", wine_dbgstr_rect(&rc));
255 } else {
256 GetWindowRect(wma->hWndPaint, &rc);
257 TRACE("WHERE_WINDOW %s\n", wine_dbgstr_rect(&rc));
261 /* In MCI, RECT structure is used differently: rc.right = width & rc.bottom = height
262 * So convert the normal RECT into a MCI RECT before returning */
263 SetRect(&lpParms->rc, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top);
265 LeaveCriticalSection(&wma->cs);
266 return 0;
269 /***************************************************************************
270 * MCIAVI_mciWindow [internal]
272 DWORD MCIAVI_mciWindow(UINT wDevID, DWORD dwFlags, LPMCI_DGV_WINDOW_PARMSW lpParms)
274 WINE_MCIAVI* wma = MCIAVI_mciGetOpenDev(wDevID);
276 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
278 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
279 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
280 if (dwFlags & MCI_TEST) return 0;
282 EnterCriticalSection(&wma->cs);
284 if (dwFlags & MCI_DGV_WINDOW_HWND) {
285 if (IsWindow(lpParms->hWnd))
287 TRACE("Setting hWnd to %p\n", lpParms->hWnd);
288 if (wma->hWnd) ShowWindow(wma->hWnd, SW_HIDE);
289 wma->hWndPaint = (lpParms->hWnd == MCI_DGV_WINDOW_DEFAULT) ? wma->hWnd : lpParms->hWnd;
292 if (dwFlags & MCI_DGV_WINDOW_STATE) {
293 TRACE("Setting nCmdShow to %d\n", lpParms->nCmdShow);
294 ShowWindow(wma->hWndPaint, lpParms->nCmdShow);
296 if (dwFlags & MCI_DGV_WINDOW_TEXT) {
297 TRACE("Setting caption to %s\n", debugstr_w(lpParms->lpstrText));
298 SetWindowTextW(wma->hWndPaint, lpParms->lpstrText);
301 LeaveCriticalSection(&wma->cs);
302 return 0;