[MAPI32] Sync with Wine Staging 3.3. CORE-14434
[reactos.git] / dll / win32 / mciavi32 / wnd.c
1 /*
2 * Digital video MCI Wine Driver
3 *
4 * Copyright 1999, 2000 Eric POUECH
5 * Copyright 2003 Dmitry Timoshkov
6 *
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.
11 *
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.
16 *
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
20 */
21
22 #include "private_mciavi.h"
23
24 static const WCHAR mciaviW[] = {'M','C','I','A','V','I',0};
25
26 static LRESULT WINAPI MCIAVI_WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
27 {
28 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n", hWnd, uMsg, wParam, lParam);
29
30 switch (uMsg) {
31 case WM_CREATE:
32 SetWindowLongW(hWnd, 0, (LPARAM)((CREATESTRUCTW *)lParam)->lpCreateParams);
33 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
34
35 case WM_DESTROY:
36 MCIAVI_mciClose(GetWindowLongW(hWnd, 0), MCI_WAIT, NULL);
37 SetWindowLongW(hWnd, 0, 0);
38 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
39
40 case WM_ERASEBKGND:
41 {
42 RECT rect;
43 GetClientRect(hWnd, &rect);
44 FillRect((HDC)wParam, &rect, GetStockObject(BLACK_BRUSH));
45 }
46 return 1;
47
48 case WM_PAINT:
49 {
50 WINE_MCIAVI *wma = (WINE_MCIAVI *)mciGetDriverData(GetWindowLongW(hWnd, 0));
51
52 if (!wma)
53 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
54
55 EnterCriticalSection(&wma->cs);
56
57 /* the animation isn't playing, don't paint */
58 if (wma->dwStatus == MCI_MODE_NOT_READY)
59 {
60 LeaveCriticalSection(&wma->cs);
61 /* default paint handling */
62 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
63 }
64
65 if (wParam)
66 MCIAVI_PaintFrame(wma, (HDC)wParam);
67 else
68 {
69 PAINTSTRUCT ps;
70 BeginPaint(hWnd, &ps);
71 MCIAVI_PaintFrame(wma, ps.hdc);
72 EndPaint(hWnd, &ps);
73 }
74
75 LeaveCriticalSection(&wma->cs);
76 }
77 return 1;
78
79 default:
80 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
81 }
82 }
83
84 BOOL MCIAVI_UnregisterClass(void)
85 {
86 return UnregisterClassW(mciaviW, MCIAVI_hInstance);
87 }
88
89 BOOL MCIAVI_RegisterClass(void)
90 {
91 WNDCLASSW wndClass;
92
93 ZeroMemory(&wndClass, sizeof(WNDCLASSW));
94 wndClass.style = CS_DBLCLKS;
95 wndClass.lpfnWndProc = MCIAVI_WindowProc;
96 wndClass.cbWndExtra = sizeof(MCIDEVICEID);
97 wndClass.hInstance = MCIAVI_hInstance;
98 wndClass.hCursor = LoadCursorW(0, (LPCWSTR)IDC_ARROW);
99 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
100 wndClass.lpszClassName = mciaviW;
101
102 if (RegisterClassW(&wndClass)) return TRUE;
103 if (GetLastError() == ERROR_CLASS_ALREADY_EXISTS) return TRUE;
104
105 return FALSE;
106 }
107
108 BOOL MCIAVI_CreateWindow(WINE_MCIAVI* wma, DWORD dwFlags, LPMCI_DGV_OPEN_PARMSW lpParms)
109 {
110 static const WCHAR captionW[] = {'W','i','n','e',' ','M','C','I','-','A','V','I',' ','p','l','a','y','e','r',0};
111 HWND hParent = 0;
112 DWORD dwStyle = WS_OVERLAPPEDWINDOW;
113 RECT rc;
114
115 /* what should be done ? */
116 if (wma->hWnd) return TRUE;
117
118 if (dwFlags & MCI_DGV_OPEN_PARENT) hParent = lpParms->hWndParent;
119 if (dwFlags & MCI_DGV_OPEN_WS) dwStyle = lpParms->dwStyle;
120
121 if (wma->hic)
122 SetRect(&rc, 0, 0, wma->outbih->biWidth, wma->outbih->biHeight);
123 else
124 SetRect(&rc, 0, 0, wma->inbih->biWidth, wma->inbih->biHeight);
125
126 AdjustWindowRect(&rc, dwStyle, FALSE);
127 if (!(dwStyle & (WS_CHILD|WS_POPUP))) /* overlapped window ? */
128 {
129 rc.right -= rc.left;
130 rc.bottom -= rc.top;
131 rc.left = rc.top = CW_USEDEFAULT;
132 }
133
134 wma->hWnd = CreateWindowW(mciaviW, captionW,
135 dwStyle, rc.left, rc.top,
136 rc.right, rc.bottom,
137 hParent, 0, MCIAVI_hInstance,
138 ULongToPtr(wma->wDevID));
139 wma->hWndPaint = wma->hWnd;
140
141 TRACE("(%04x, %08X, %p, style %x, parent %p, dimensions %dx%d, hwnd %p)\n", wma->wDevID,
142 dwFlags, lpParms, dwStyle, hParent, rc.right - rc.left, rc.bottom - rc.top, wma->hWnd);
143 return wma->hWnd != 0;
144 }
145
146 /***************************************************************************
147 * MCIAVI_mciPut [internal]
148 */
149 DWORD MCIAVI_mciPut(UINT wDevID, DWORD dwFlags, LPMCI_DGV_PUT_PARMS lpParms)
150 {
151 WINE_MCIAVI* wma = MCIAVI_mciGetOpenDev(wDevID);
152 RECT rc;
153
154 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
155
156 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
157 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
158 if (dwFlags & MCI_TEST) return 0;
159
160 EnterCriticalSection(&wma->cs);
161
162 if (dwFlags & MCI_DGV_RECT) {
163 /* In MCI, RECT structure is used differently: rc.right = width & rc.bottom = height
164 * So convert input MCI RECT into a normal RECT */
165 SetRect(&rc, lpParms->rc.left, lpParms->rc.top, lpParms->rc.left + lpParms->rc.right,
166 lpParms->rc.top + lpParms->rc.bottom);
167 } else {
168 GetClientRect(wma->hWndPaint, &rc);
169 }
170
171 if (dwFlags & MCI_DGV_PUT_CLIENT) {
172 FIXME("PUT_CLIENT %s\n", wine_dbgstr_rect(&rc));
173 LeaveCriticalSection(&wma->cs);
174 return MCIERR_UNRECOGNIZED_COMMAND;
175 }
176 if (dwFlags & MCI_DGV_PUT_DESTINATION) {
177 TRACE("PUT_DESTINATION %s\n", wine_dbgstr_rect(&rc));
178 wma->dest = rc;
179 }
180 if (dwFlags & MCI_DGV_PUT_FRAME) {
181 FIXME("PUT_FRAME %s\n", wine_dbgstr_rect(&rc));
182 LeaveCriticalSection(&wma->cs);
183 return MCIERR_UNRECOGNIZED_COMMAND;
184 }
185 if (dwFlags & MCI_DGV_PUT_SOURCE) {
186 TRACE("PUT_SOURCE %s\n", wine_dbgstr_rect(&rc));
187 wma->source = rc;
188 }
189 if (dwFlags & MCI_DGV_PUT_VIDEO) {
190 FIXME("PUT_VIDEO %s\n", wine_dbgstr_rect(&rc));
191 LeaveCriticalSection(&wma->cs);
192 return MCIERR_UNRECOGNIZED_COMMAND;
193 }
194 if (dwFlags & MCI_DGV_PUT_WINDOW) {
195 TRACE("PUT_WINDOW %s\n", wine_dbgstr_rect(&rc));
196 SetWindowPos(wma->hWndPaint, NULL, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_NOZORDER);
197 }
198 LeaveCriticalSection(&wma->cs);
199 return 0;
200 }
201
202 /******************************************************************************
203 * MCIAVI_mciWhere [internal]
204 */
205 DWORD MCIAVI_mciWhere(UINT wDevID, DWORD dwFlags, LPMCI_DGV_RECT_PARMS lpParms)
206 {
207 WINE_MCIAVI* wma = MCIAVI_mciGetOpenDev(wDevID);
208 RECT rc;
209
210 TRACE("(%04x, %08x, %p)\n", wDevID, dwFlags, lpParms);
211
212 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
213 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
214 /* Ignore MCI_TEST flag. */
215
216 EnterCriticalSection(&wma->cs);
217
218 if (dwFlags & MCI_DGV_WHERE_DESTINATION) {
219 if (dwFlags & MCI_DGV_WHERE_MAX) {
220 GetClientRect(wma->hWndPaint, &rc);
221 TRACE("WHERE_DESTINATION_MAX %s\n", wine_dbgstr_rect(&rc));
222 } else {
223 TRACE("WHERE_DESTINATION %s\n", wine_dbgstr_rect(&wma->dest));
224 rc = wma->dest;
225 }
226 }
227 if (dwFlags & MCI_DGV_WHERE_FRAME) {
228 if (dwFlags & MCI_DGV_WHERE_MAX)
229 FIXME("MCI_DGV_WHERE_FRAME_MAX\n");
230 else
231 FIXME("MCI_DGV_WHERE_FRAME\n");
232 LeaveCriticalSection(&wma->cs);
233 return MCIERR_UNRECOGNIZED_COMMAND;
234 }
235 if (dwFlags & MCI_DGV_WHERE_SOURCE) {
236 if (dwFlags & MCI_DGV_WHERE_MAX) {
237 SetRect(&rc, 0, 0, wma->inbih->biWidth, wma->inbih->biHeight);
238 TRACE("WHERE_SOURCE_MAX %s\n", wine_dbgstr_rect(&rc));
239 } else {
240 TRACE("WHERE_SOURCE %s\n", wine_dbgstr_rect(&wma->source));
241 rc = wma->source;
242 }
243 }
244 if (dwFlags & MCI_DGV_WHERE_VIDEO) {
245 if (dwFlags & MCI_DGV_WHERE_MAX)
246 FIXME("WHERE_VIDEO_MAX\n");
247 else
248 FIXME("WHERE_VIDEO\n");
249 LeaveCriticalSection(&wma->cs);
250 return MCIERR_UNRECOGNIZED_COMMAND;
251 }
252 if (dwFlags & MCI_DGV_WHERE_WINDOW) {
253 if (dwFlags & MCI_DGV_WHERE_MAX) {
254 GetWindowRect(GetDesktopWindow(), &rc);
255 TRACE("WHERE_WINDOW_MAX %s\n", wine_dbgstr_rect(&rc));
256 } else {
257 GetWindowRect(wma->hWndPaint, &rc);
258 TRACE("WHERE_WINDOW %s\n", wine_dbgstr_rect(&rc));
259 }
260 }
261
262 /* In MCI, RECT structure is used differently: rc.right = width & rc.bottom = height
263 * So convert the normal RECT into a MCI RECT before returning */
264 SetRect(&lpParms->rc, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top);
265
266 LeaveCriticalSection(&wma->cs);
267 return 0;
268 }
269
270 /***************************************************************************
271 * MCIAVI_mciWindow [internal]
272 */
273 DWORD MCIAVI_mciWindow(UINT wDevID, DWORD dwFlags, LPMCI_DGV_WINDOW_PARMSW lpParms)
274 {
275 WINE_MCIAVI* wma = MCIAVI_mciGetOpenDev(wDevID);
276
277 TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
278
279 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
280 if (wma == NULL) return MCIERR_INVALID_DEVICE_ID;
281 if (dwFlags & MCI_TEST) return 0;
282
283 EnterCriticalSection(&wma->cs);
284
285 if (dwFlags & MCI_DGV_WINDOW_HWND) {
286 if (IsWindow(lpParms->hWnd))
287 {
288 TRACE("Setting hWnd to %p\n", lpParms->hWnd);
289 if (wma->hWnd) ShowWindow(wma->hWnd, SW_HIDE);
290 wma->hWndPaint = (lpParms->hWnd == MCI_DGV_WINDOW_DEFAULT) ? wma->hWnd : lpParms->hWnd;
291 }
292 }
293 if (dwFlags & MCI_DGV_WINDOW_STATE) {
294 TRACE("Setting nCmdShow to %d\n", lpParms->nCmdShow);
295 ShowWindow(wma->hWndPaint, lpParms->nCmdShow);
296 }
297 if (dwFlags & MCI_DGV_WINDOW_TEXT) {
298 TRACE("Setting caption to %s\n", debugstr_w(lpParms->lpstrText));
299 SetWindowTextW(wma->hWndPaint, lpParms->lpstrText);
300 }
301
302 LeaveCriticalSection(&wma->cs);
303 return 0;
304 }