Implement PrivilegeCheck.
[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     int         p = CW_USEDEFAULT;
120     RECT        rc;
121
122     /* what should be done ? */
123     if (wma->hWnd) return TRUE;
124
125     if (dwFlags & MCI_DGV_OPEN_PARENT)  hParent = lpOpenParms->hWndParent;
126     if (dwFlags & MCI_DGV_OPEN_WS)      dwStyle = lpOpenParms->dwStyle;
127     if (dwStyle & WS_CHILD)             p = 0;
128
129     rc.left = p;
130     rc.top = p;
131     rc.right = (wma->hic ? wma->outbih : wma->inbih)->biWidth;
132     rc.bottom = (wma->hic ? wma->outbih : wma->inbih)->biHeight;
133     AdjustWindowRect(&rc, dwStyle, FALSE);
134
135     wma->hWnd = CreateWindowW(mciaviW, captionW,
136                               dwStyle, rc.left, rc.top,
137                               rc.right, rc.bottom,
138                               hParent, 0, MCIAVI_hInstance,
139                               (LPVOID)wma->wDevID);
140     wma->hWndPaint = wma->hWnd;
141     return (BOOL)wma->hWnd;
142 }
143
144 /***************************************************************************
145  *                              MCIAVI_mciPut                   [internal]
146  */
147 DWORD   MCIAVI_mciPut(UINT wDevID, DWORD dwFlags, LPMCI_DGV_PUT_PARMS lpParms)
148 {
149     WINE_MCIAVI*        wma = MCIAVI_mciGetOpenDev(wDevID);
150     RECT                rc;
151
152     TRACE("(%04x, %08lX, %p)\n", wDevID, dwFlags, lpParms);
153
154     if (lpParms == NULL)        return MCIERR_NULL_PARAMETER_BLOCK;
155     if (wma == NULL)            return MCIERR_INVALID_DEVICE_ID;
156
157     EnterCriticalSection(&wma->cs);
158
159     if (dwFlags & MCI_DGV_RECT) {
160         rc = lpParms->rc;
161     } else {
162         GetClientRect(wma->hWndPaint, &rc);
163     }
164
165     if (dwFlags & MCI_DGV_PUT_CLIENT) {
166         FIXME("PUT_CLIENT %s\n", wine_dbgstr_rect(&rc));
167         LeaveCriticalSection(&wma->cs);
168         return MCIERR_UNRECOGNIZED_COMMAND;
169     }
170     if (dwFlags & MCI_DGV_PUT_DESTINATION) {
171         TRACE("PUT_DESTINATION %s\n", wine_dbgstr_rect(&rc));
172         wma->dest = rc;
173     }
174     if (dwFlags & MCI_DGV_PUT_FRAME) {
175         FIXME("PUT_FRAME %s\n", wine_dbgstr_rect(&rc));
176         LeaveCriticalSection(&wma->cs);
177         return MCIERR_UNRECOGNIZED_COMMAND;
178     }
179     if (dwFlags & MCI_DGV_PUT_SOURCE) {
180         TRACE("PUT_SOURCE %s\n", wine_dbgstr_rect(&rc));
181         wma->source = rc;
182     }
183     if (dwFlags & MCI_DGV_PUT_VIDEO) {
184         FIXME("PUT_VIDEO %s\n", wine_dbgstr_rect(&rc));
185         LeaveCriticalSection(&wma->cs);
186         return MCIERR_UNRECOGNIZED_COMMAND;
187     }
188     if (dwFlags & MCI_DGV_PUT_WINDOW) {
189         FIXME("PUT_WINDOW %s\n", wine_dbgstr_rect(&rc));
190         LeaveCriticalSection(&wma->cs);
191         return MCIERR_UNRECOGNIZED_COMMAND;
192     }
193     LeaveCriticalSection(&wma->cs);
194     return 0;
195 }
196
197 /******************************************************************************
198  *                              MCIAVI_mciWhere                 [internal]
199  */
200 DWORD   MCIAVI_mciWhere(UINT wDevID, DWORD dwFlags, LPMCI_DGV_RECT_PARMS lpParms)
201 {
202     WINE_MCIAVI*        wma = MCIAVI_mciGetOpenDev(wDevID);
203
204     TRACE("(%04x, %08lx, %p)\n", wDevID, dwFlags, lpParms);
205
206     if (lpParms == NULL)        return MCIERR_NULL_PARAMETER_BLOCK;
207     if (wma == NULL)            return MCIERR_INVALID_DEVICE_ID;
208
209     EnterCriticalSection(&wma->cs);
210
211     if (dwFlags & MCI_DGV_WHERE_DESTINATION) {
212         if (dwFlags & MCI_DGV_WHERE_MAX) {
213             GetClientRect(wma->hWndPaint, &lpParms->rc);
214             TRACE("WHERE_DESTINATION_MAX %s\n", wine_dbgstr_rect(&lpParms->rc));
215         } else {
216             TRACE("WHERE_DESTINATION %s\n", wine_dbgstr_rect(&wma->dest));
217             lpParms->rc = wma->dest;
218         }
219     }
220     if (dwFlags & MCI_DGV_WHERE_FRAME) {
221         if (dwFlags & MCI_DGV_WHERE_MAX)
222             FIXME("MCI_DGV_WHERE_FRAME_MAX\n");
223         else
224             FIXME("MCI_DGV_WHERE_FRAME\n");
225         LeaveCriticalSection(&wma->cs);
226         return MCIERR_UNRECOGNIZED_COMMAND;
227     }
228     if (dwFlags & MCI_DGV_WHERE_SOURCE) {
229         if (dwFlags & MCI_DGV_WHERE_MAX) {
230             RECT rect;
231             rect.left = 0;
232             rect.top = 0;
233             rect.right = wma->inbih->biWidth; 
234             rect.bottom = wma->inbih->biHeight; 
235             TRACE("WHERE_SOURCE_MAX %s\n", wine_dbgstr_rect(&rect));
236             lpParms->rc = rect;
237         } else {
238             TRACE("WHERE_SOURCE %s\n", wine_dbgstr_rect(&wma->source));
239             lpParms->rc = wma->source;
240         }
241     }
242     if (dwFlags & MCI_DGV_WHERE_VIDEO) {
243         if (dwFlags & MCI_DGV_WHERE_MAX)
244             FIXME("WHERE_VIDEO_MAX\n");
245         else
246             FIXME("WHERE_VIDEO\n");
247         LeaveCriticalSection(&wma->cs);
248         return MCIERR_UNRECOGNIZED_COMMAND;
249     }
250     if (dwFlags & MCI_DGV_WHERE_WINDOW) {
251         if (dwFlags & MCI_DGV_WHERE_MAX) {
252             GetWindowRect(GetDesktopWindow(), &lpParms->rc);
253             TRACE("WHERE_WINDOW_MAX %s\n", wine_dbgstr_rect(&lpParms->rc));
254         } else {
255             GetWindowRect(wma->hWndPaint, &lpParms->rc);
256             TRACE("WHERE_WINDOW %s\n", wine_dbgstr_rect(&lpParms->rc));
257         }
258     }
259     LeaveCriticalSection(&wma->cs);
260     return 0;
261 }
262
263 /***************************************************************************
264  *                              MCIAVI_mciWindow                        [internal]
265  */
266 DWORD   MCIAVI_mciWindow(UINT wDevID, DWORD dwFlags, LPMCI_DGV_WINDOW_PARMSW lpParms)
267 {
268     WINE_MCIAVI*        wma = MCIAVI_mciGetOpenDev(wDevID);
269
270     TRACE("(%04x, %08lX, %p)\n", wDevID, dwFlags, lpParms);
271
272     if (lpParms == NULL)        return MCIERR_NULL_PARAMETER_BLOCK;
273     if (wma == NULL)            return MCIERR_INVALID_DEVICE_ID;
274
275     EnterCriticalSection(&wma->cs);
276
277     if (dwFlags & MCI_DGV_WINDOW_HWND) {
278         if (IsWindow(lpParms->hWnd))
279         {
280             TRACE("Setting hWnd to %p\n", lpParms->hWnd);
281             if (wma->hWnd) ShowWindow(wma->hWnd, SW_HIDE);
282             wma->hWndPaint = (lpParms->hWnd == MCI_DGV_WINDOW_DEFAULT) ? wma->hWnd : lpParms->hWnd;
283         }
284     }
285     if (dwFlags & MCI_DGV_WINDOW_STATE) {
286         TRACE("Setting nCmdShow to %d\n", lpParms->nCmdShow);
287         ShowWindow(wma->hWndPaint, lpParms->nCmdShow);
288     }
289     if (dwFlags & MCI_DGV_WINDOW_TEXT) {
290         TRACE("Setting caption to %s\n", debugstr_w(lpParms->lpstrText));
291         SetWindowTextW(wma->hWndPaint, lpParms->lpstrText);
292     }
293
294     LeaveCriticalSection(&wma->cs);
295     return 0;
296 }