Change RECT to use LONG to match win32 standard headers and fix format
[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  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 #include <string.h>
24 #include "private_mciavi.h"
25 #include "wine/debug.h"
26
27 WINE_DEFAULT_DEBUG_CHANNEL(mciavi);
28
29 static LRESULT WINAPI MCIAVI_WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
30 {
31     TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n", hWnd, uMsg, wParam, lParam);
32
33     if (!(WINE_MCIAVI*)GetWindowLongA(hWnd, 0) && uMsg != WM_CREATE)
34         return DefWindowProcA(hWnd, uMsg, wParam, lParam);
35
36     switch (uMsg) {
37     case WM_CREATE:
38         SetWindowLongA(hWnd, 0, (LPARAM)((CREATESTRUCTA*)lParam)->lpCreateParams);
39         return DefWindowProcA(hWnd, uMsg, wParam, lParam);
40
41     case WM_DESTROY:
42         SetWindowLongA(hWnd, 0, 0);
43         return DefWindowProcA(hWnd, uMsg, wParam, lParam);
44
45     case WM_ERASEBKGND:
46         {
47             RECT        rect;
48             GetClientRect(hWnd, &rect);
49             FillRect((HDC)wParam, &rect, GetStockObject(BLACK_BRUSH));
50         }
51         break;
52     case WM_PAINT:
53         {
54             WINE_MCIAVI* wma = (WINE_MCIAVI*)GetWindowLongA(hWnd, 0);
55
56             /* the animation isn't playing, don't paint */
57             if (wma->dwStatus == MCI_MODE_NOT_READY)
58                 /* default paint handling */
59                 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
60
61             if (wParam) {
62                 EnterCriticalSection(&wma->cs);
63                 MCIAVI_PaintFrame(wma, (HDC)wParam);
64                 LeaveCriticalSection(&wma->cs);
65             } else {
66                 PAINTSTRUCT ps;
67                 HDC hDC = BeginPaint(hWnd, &ps);
68
69                 EnterCriticalSection(&wma->cs);
70                 MCIAVI_PaintFrame(wma, hDC);
71                 LeaveCriticalSection(&wma->cs);
72
73                 EndPaint(hWnd, &ps);
74             }
75         }
76         break;
77
78     default:
79         return DefWindowProcA(hWnd, uMsg, wParam, lParam);
80     }
81     return 0;
82 }
83
84 BOOL    MCIAVI_CreateWindow(WINE_MCIAVI* wma, DWORD dwFlags, LPMCI_DGV_OPEN_PARMSA lpOpenParms)
85 {
86     WNDCLASSA   wndClass;
87     HWND        hParent = 0;
88     DWORD       dwStyle = WS_OVERLAPPEDWINDOW;
89     int         p = CW_USEDEFAULT;
90
91     /* what should be done ? */
92     if (wma->hWnd) return TRUE;
93
94     ZeroMemory(&wndClass, sizeof(WNDCLASSA));
95     wndClass.style         = CS_GLOBALCLASS | CS_DBLCLKS;
96     wndClass.lpfnWndProc   = (WNDPROC)MCIAVI_WindowProc;
97     wndClass.cbClsExtra    = 0;
98     wndClass.cbWndExtra    = sizeof(WINE_MCIAVI*);
99     wndClass.hCursor       = LoadCursorA(0, IDC_ARROWA);
100     wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
101     wndClass.lpszClassName = "MCIAVI";
102
103     RegisterClassA(&wndClass);
104
105     if (dwFlags & MCI_DGV_OPEN_PARENT)  hParent = lpOpenParms->hWndParent;
106     if (dwFlags & MCI_DGV_OPEN_WS)      dwStyle = lpOpenParms->dwStyle;
107     if (dwStyle & WS_CHILD)             p = 0;
108
109     wma->hWnd = CreateWindowA("MCIAVI", "Wine MCI-AVI player",
110                               dwStyle, p, p,
111                               (wma->hic ? wma->outbih : wma->inbih)->biWidth,
112                               (wma->hic ? wma->outbih : wma->inbih)->biHeight,
113                               hParent, 0, MCIAVI_hInstance, wma);
114     return (BOOL)wma->hWnd;
115 }
116
117 /***************************************************************************
118  *                              MCIAVI_mciPut                   [internal]
119  */
120 DWORD   MCIAVI_mciPut(UINT wDevID, DWORD dwFlags, LPMCI_DGV_PUT_PARMS lpParms)
121 {
122     WINE_MCIAVI*        wma = MCIAVI_mciGetOpenDev(wDevID);
123     RECT                rc;
124     char                buffer[256];
125
126     FIXME("(%04x, %08lX, %p) : stub\n", wDevID, dwFlags, lpParms);
127
128     if (lpParms == NULL)        return MCIERR_NULL_PARAMETER_BLOCK;
129     if (wma == NULL)            return MCIERR_INVALID_DEVICE_ID;
130
131     if (dwFlags & MCI_DGV_RECT) {
132         rc = lpParms->rc;
133     } else {
134         SetRectEmpty(&rc);
135     }
136
137     *buffer = 0;
138     if (dwFlags & MCI_DGV_PUT_CLIENT) {
139         strncat(buffer, "PUT_CLIENT", sizeof(buffer));
140     }
141     if (dwFlags & MCI_DGV_PUT_DESTINATION) {
142         strncat(buffer, "PUT_DESTINATION", sizeof(buffer));
143     }
144     if (dwFlags & MCI_DGV_PUT_FRAME) {
145         strncat(buffer, "PUT_FRAME", sizeof(buffer));
146     }
147     if (dwFlags & MCI_DGV_PUT_SOURCE) {
148         strncat(buffer, "PUT_SOURCE", sizeof(buffer));
149     }
150     if (dwFlags & MCI_DGV_PUT_VIDEO) {
151         strncat(buffer, "PUT_VIDEO", sizeof(buffer));
152     }
153     if (dwFlags & MCI_DGV_PUT_WINDOW) {
154         strncat(buffer, "PUT_WINDOW", sizeof(buffer));
155     }
156     TRACE("%s (%ld,%ld,%ld,%ld)\n", buffer, rc.left, rc.top, rc.right, rc.bottom);
157
158     return 0;
159 }
160
161 /******************************************************************************
162  *                              MCIAVI_mciWhere                 [internal]
163  */
164 DWORD   MCIAVI_mciWhere(UINT wDevID, DWORD dwFlags, LPMCI_DGV_RECT_PARMS lpParms)
165 {
166     WINE_MCIAVI*        wma = MCIAVI_mciGetOpenDev(wDevID);
167     LPSTR               x = "";
168
169     TRACE("(%04x, %08lx, %p)\n", wDevID, dwFlags, lpParms);
170
171     if (lpParms == NULL)        return MCIERR_NULL_PARAMETER_BLOCK;
172     if (wma == NULL)            return MCIERR_INVALID_DEVICE_ID;
173
174     if (dwFlags & MCI_DGV_WHERE_MAX) FIXME("Max NIY\n");
175
176     if (dwFlags & MCI_DGV_WHERE_DESTINATION) {
177         x = "Dest";
178         GetClientRect(wma->hWnd, &lpParms->rc);
179     }
180     if (dwFlags & MCI_DGV_WHERE_FRAME) {
181         FIXME(x = "Frame\n");
182         return MCIERR_UNRECOGNIZED_COMMAND;
183     }
184     if (dwFlags & MCI_DGV_WHERE_SOURCE) {
185         x = "Source";
186         lpParms->rc.left = lpParms->rc.top = 0;
187         lpParms->rc.right = wma->mah.dwWidth;
188         lpParms->rc.bottom = wma->mah.dwHeight;
189     }
190     if (dwFlags & MCI_DGV_WHERE_VIDEO) {
191         FIXME(x = "Video\n");
192         return MCIERR_UNRECOGNIZED_COMMAND;
193     }
194     if (dwFlags & MCI_DGV_WHERE_WINDOW) {
195         x = "Window";
196         GetClientRect(wma->hWnd, &lpParms->rc);
197     }
198     TRACE("%s -> (%ld,%ld,%ld,%ld)\n",
199           x, lpParms->rc.left, lpParms->rc.top, lpParms->rc.right, lpParms->rc.bottom);
200
201     return 0;
202 }
203
204 /***************************************************************************
205  *                              MCIAVI_mciWindow                        [internal]
206  */
207 DWORD   MCIAVI_mciWindow(UINT wDevID, DWORD dwFlags, LPMCI_DGV_WINDOW_PARMSA lpParms)
208 {
209     WINE_MCIAVI*        wma = MCIAVI_mciGetOpenDev(wDevID);
210
211     TRACE("(%04x, %08lX, %p)\n", wDevID, dwFlags, lpParms);
212
213     if (lpParms == NULL)        return MCIERR_NULL_PARAMETER_BLOCK;
214     if (wma == NULL)            return MCIERR_INVALID_DEVICE_ID;
215
216     if (dwFlags & MCI_DGV_WINDOW_HWND) {
217         FIXME("Setting hWnd to %08lx\n", (DWORD)lpParms->hWnd);
218 #if 0
219         if (wma->hWnd) DestroyWindow(wma->hWnd);
220         /* is the window to be subclassed ? */
221         wma->hWnd = lpParms->hWnd;
222 #endif
223     }
224     if (dwFlags & MCI_DGV_WINDOW_STATE) {
225         TRACE("Setting nCmdShow to %d\n", lpParms->nCmdShow);
226         ShowWindow(wma->hWnd, lpParms->nCmdShow);
227     }
228     if (dwFlags & MCI_DGV_WINDOW_TEXT) {
229         TRACE("Setting caption to '%s'\n", lpParms->lpstrText);
230         SetWindowTextA(wma->hWnd, lpParms->lpstrText);
231     }
232
233     return 0;
234 }
235