mshtml: Don't crash creating a URI if we have no document.
[wine.git] / dlls / mciavi32 / wnd.c
blob66c7565e31dc61fa823247ec4b90e49fa29d558a
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 const WCHAR mciaviW[] = {'M','C','I','A','V','I',0};
30 static LRESULT WINAPI MCIAVI_WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
32 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n", hWnd, uMsg, wParam, lParam);
34 switch (uMsg) {
35 case WM_CREATE:
36 SetWindowLongW(hWnd, 0, (LPARAM)((CREATESTRUCTW *)lParam)->lpCreateParams);
37 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
39 case WM_DESTROY:
40 MCIAVI_mciClose(GetWindowLongW(hWnd, 0), MCI_WAIT, NULL);
41 SetWindowLongW(hWnd, 0, 0);
42 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
44 case WM_ERASEBKGND:
46 RECT rect;
47 GetClientRect(hWnd, &rect);
48 FillRect((HDC)wParam, &rect, GetStockObject(BLACK_BRUSH));
50 return 1;
52 case WM_PAINT:
54 WINE_MCIAVI *wma = (WINE_MCIAVI *)mciGetDriverData(GetWindowLongW(hWnd, 0));
56 if (!wma)
57 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
59 EnterCriticalSection(&wma->cs);
61 /* the animation isn't playing, don't paint */
62 if (wma->dwStatus == MCI_MODE_NOT_READY)
64 LeaveCriticalSection(&wma->cs);
65 /* default paint handling */
66 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
69 if (wParam)
70 MCIAVI_PaintFrame(wma, (HDC)wParam);
71 else
73 PAINTSTRUCT ps;
74 BeginPaint(hWnd, &ps);
75 MCIAVI_PaintFrame(wma, ps.hdc);
76 EndPaint(hWnd, &ps);
79 LeaveCriticalSection(&wma->cs);
81 return 1;
83 default:
84 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
88 BOOL MCIAVI_UnregisterClass(void)
90 return UnregisterClassW(mciaviW, MCIAVI_hInstance);
93 BOOL MCIAVI_RegisterClass(void)
95 WNDCLASSW wndClass;
97 ZeroMemory(&wndClass, sizeof(WNDCLASSW));
98 wndClass.style = CS_DBLCLKS;
99 wndClass.lpfnWndProc = MCIAVI_WindowProc;
100 wndClass.cbWndExtra = sizeof(MCIDEVICEID);
101 wndClass.hInstance = MCIAVI_hInstance;
102 wndClass.hCursor = LoadCursorW(0, (LPCWSTR)IDC_ARROW);
103 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
104 wndClass.lpszClassName = mciaviW;
106 if (RegisterClassW(&wndClass)) return TRUE;
107 if (GetLastError() == ERROR_CLASS_ALREADY_EXISTS) return TRUE;
109 return FALSE;
112 BOOL MCIAVI_CreateWindow(WINE_MCIAVI* wma, DWORD dwFlags, LPMCI_DGV_OPEN_PARMSW lpOpenParms)
114 static const WCHAR captionW[] = {'W','i','n','e',' ','M','C','I','-','A','V','I',' ','p','l','a','y','e','r',0};
115 HWND hParent = 0;
116 DWORD dwStyle = WS_OVERLAPPEDWINDOW;
117 RECT rc;
119 /* what should be done ? */
120 if (wma->hWnd) return TRUE;
122 if (dwFlags & MCI_DGV_OPEN_PARENT) hParent = lpOpenParms->hWndParent;
123 if (dwFlags & MCI_DGV_OPEN_WS) dwStyle = lpOpenParms->dwStyle;
125 if (wma->hic)
126 SetRect(&rc, 0, 0, wma->outbih->biWidth, wma->outbih->biHeight);
127 else
128 SetRect(&rc, 0, 0, wma->inbih->biWidth, wma->inbih->biHeight);
130 AdjustWindowRect(&rc, dwStyle, FALSE);
131 if (!(dwStyle & (WS_CHILD|WS_POPUP))) /* overlapped window ? */
133 rc.right -= rc.left;
134 rc.bottom -= rc.top;
135 rc.left = rc.top = CW_USEDEFAULT;
138 wma->hWnd = CreateWindowW(mciaviW, captionW,
139 dwStyle, rc.left, rc.top,
140 rc.right, rc.bottom,
141 hParent, 0, MCIAVI_hInstance,
142 ULongToPtr(wma->wDevID));
143 wma->hWndPaint = wma->hWnd;
144 return wma->hWnd != 0;
147 /***************************************************************************
148 * MCIAVI_mciPut [internal]
150 DWORD MCIAVI_mciPut(UINT wDevID, DWORD dwFlags, LPMCI_DGV_PUT_PARMS lpParms)
152 WINE_MCIAVI* wma = MCIAVI_mciGetOpenDev(wDevID);
153 RECT rc;
155 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
157 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
158 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
159 if (dwFlags & MCI_TEST) return 0;
161 EnterCriticalSection(&wma->cs);
163 if (dwFlags & MCI_DGV_RECT) {
164 /* In MCI, RECT structure is used differently: rc.right = width & rc.bottom = height
165 * So convert input MCI RECT into a normal RECT */
166 SetRect(&rc, lpParms->rc.left, lpParms->rc.top, lpParms->rc.left + lpParms->rc.right,
167 lpParms->rc.top + lpParms->rc.bottom);
168 } else {
169 GetClientRect(wma->hWndPaint, &rc);
172 if (dwFlags & MCI_DGV_PUT_CLIENT) {
173 FIXME("PUT_CLIENT %s\n", wine_dbgstr_rect(&rc));
174 LeaveCriticalSection(&wma->cs);
175 return MCIERR_UNRECOGNIZED_COMMAND;
177 if (dwFlags & MCI_DGV_PUT_DESTINATION) {
178 TRACE("PUT_DESTINATION %s\n", wine_dbgstr_rect(&rc));
179 wma->dest = rc;
181 if (dwFlags & MCI_DGV_PUT_FRAME) {
182 FIXME("PUT_FRAME %s\n", wine_dbgstr_rect(&rc));
183 LeaveCriticalSection(&wma->cs);
184 return MCIERR_UNRECOGNIZED_COMMAND;
186 if (dwFlags & MCI_DGV_PUT_SOURCE) {
187 TRACE("PUT_SOURCE %s\n", wine_dbgstr_rect(&rc));
188 wma->source = rc;
190 if (dwFlags & MCI_DGV_PUT_VIDEO) {
191 FIXME("PUT_VIDEO %s\n", wine_dbgstr_rect(&rc));
192 LeaveCriticalSection(&wma->cs);
193 return MCIERR_UNRECOGNIZED_COMMAND;
195 if (dwFlags & MCI_DGV_PUT_WINDOW) {
196 TRACE("PUT_WINDOW %s\n", wine_dbgstr_rect(&rc));
197 SetWindowPos(wma->hWndPaint, NULL, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_NOZORDER);
199 LeaveCriticalSection(&wma->cs);
200 return 0;
203 /******************************************************************************
204 * MCIAVI_mciWhere [internal]
206 DWORD MCIAVI_mciWhere(UINT wDevID, DWORD dwFlags, LPMCI_DGV_RECT_PARMS lpParms)
208 WINE_MCIAVI* wma = MCIAVI_mciGetOpenDev(wDevID);
209 RECT rc;
211 TRACE("(%04x, %08x, %p)\n", wDevID, dwFlags, lpParms);
213 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
214 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
215 /* Ignore MCI_TEST flag. */
217 EnterCriticalSection(&wma->cs);
219 if (dwFlags & MCI_DGV_WHERE_DESTINATION) {
220 if (dwFlags & MCI_DGV_WHERE_MAX) {
221 GetClientRect(wma->hWndPaint, &rc);
222 TRACE("WHERE_DESTINATION_MAX %s\n", wine_dbgstr_rect(&rc));
223 } else {
224 TRACE("WHERE_DESTINATION %s\n", wine_dbgstr_rect(&wma->dest));
225 rc = wma->dest;
228 if (dwFlags & MCI_DGV_WHERE_FRAME) {
229 if (dwFlags & MCI_DGV_WHERE_MAX)
230 FIXME("MCI_DGV_WHERE_FRAME_MAX\n");
231 else
232 FIXME("MCI_DGV_WHERE_FRAME\n");
233 LeaveCriticalSection(&wma->cs);
234 return MCIERR_UNRECOGNIZED_COMMAND;
236 if (dwFlags & MCI_DGV_WHERE_SOURCE) {
237 if (dwFlags & MCI_DGV_WHERE_MAX) {
238 SetRect(&rc, 0, 0, wma->inbih->biWidth, wma->inbih->biHeight);
239 TRACE("WHERE_SOURCE_MAX %s\n", wine_dbgstr_rect(&rc));
240 } else {
241 TRACE("WHERE_SOURCE %s\n", wine_dbgstr_rect(&wma->source));
242 rc = wma->source;
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;
253 if (dwFlags & MCI_DGV_WHERE_WINDOW) {
254 if (dwFlags & MCI_DGV_WHERE_MAX) {
255 GetWindowRect(GetDesktopWindow(), &rc);
256 TRACE("WHERE_WINDOW_MAX %s\n", wine_dbgstr_rect(&rc));
257 } else {
258 GetWindowRect(wma->hWndPaint, &rc);
259 TRACE("WHERE_WINDOW %s\n", wine_dbgstr_rect(&rc));
263 /* In MCI, RECT structure is used differently: rc.right = width & rc.bottom = height
264 * So convert the normal RECT into a MCI RECT before returning */
265 SetRect(&lpParms->rc, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top);
267 LeaveCriticalSection(&wma->cs);
268 return 0;
271 /***************************************************************************
272 * MCIAVI_mciWindow [internal]
274 DWORD MCIAVI_mciWindow(UINT wDevID, DWORD dwFlags, LPMCI_DGV_WINDOW_PARMSW lpParms)
276 WINE_MCIAVI* wma = MCIAVI_mciGetOpenDev(wDevID);
278 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
280 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
281 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
282 if (dwFlags & MCI_TEST) return 0;
284 EnterCriticalSection(&wma->cs);
286 if (dwFlags & MCI_DGV_WINDOW_HWND) {
287 if (IsWindow(lpParms->hWnd))
289 TRACE("Setting hWnd to %p\n", lpParms->hWnd);
290 if (wma->hWnd) ShowWindow(wma->hWnd, SW_HIDE);
291 wma->hWndPaint = (lpParms->hWnd == MCI_DGV_WINDOW_DEFAULT) ? wma->hWnd : lpParms->hWnd;
294 if (dwFlags & MCI_DGV_WINDOW_STATE) {
295 TRACE("Setting nCmdShow to %d\n", lpParms->nCmdShow);
296 ShowWindow(wma->hWndPaint, lpParms->nCmdShow);
298 if (dwFlags & MCI_DGV_WINDOW_TEXT) {
299 TRACE("Setting caption to %s\n", debugstr_w(lpParms->lpstrText));
300 SetWindowTextW(wma->hWndPaint, lpParms->lpstrText);
303 LeaveCriticalSection(&wma->cs);
304 return 0;