wnd.c 9.79 KB
Newer Older
1 2 3 4
/*
 * Digital video MCI Wine Driver
 *
 * Copyright 1999, 2000 Eric POUECH
5
 * Copyright 2003 Dmitry Timoshkov
6 7 8 9 10 11 12 13 14 15 16 17 18
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * 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 23
 */

#include <string.h>
#include "private_mciavi.h"
24
#include "wine/debug.h"
25

26
WINE_DEFAULT_DEBUG_CHANNEL(mciavi);
27

28 29
static const WCHAR mciaviW[] = {'M','C','I','A','V','I',0};

30 31
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);
33

34 35
    switch (uMsg) {
    case WM_CREATE:
36 37
        SetWindowLongW(hWnd, 0, (LPARAM)((CREATESTRUCTW *)lParam)->lpCreateParams);
        return DefWindowProcW(hWnd, uMsg, wParam, lParam);
38

39
    case WM_DESTROY:
40 41 42
        MCIAVI_mciClose(GetWindowLongW(hWnd, 0), MCI_WAIT, NULL);
        SetWindowLongW(hWnd, 0, 0);
        return DefWindowProcW(hWnd, uMsg, wParam, lParam);
43

44 45 46 47 48 49
    case WM_ERASEBKGND:
	{
	    RECT	rect;
	    GetClientRect(hWnd, &rect);
	    FillRect((HDC)wParam, &rect, GetStockObject(BLACK_BRUSH));
	}
50 51
       return 1;

52 53
    case WM_PAINT:
        {
54
            WINE_MCIAVI *wma = (WINE_MCIAVI *)mciGetDriverData(GetWindowLongW(hWnd, 0));
55 56

            if (!wma)
57
                return DefWindowProcW(hWnd, uMsg, wParam, lParam);
58 59
            
            EnterCriticalSection(&wma->cs);
60

61 62
            /* the animation isn't playing, don't paint */
	    if (wma->dwStatus == MCI_MODE_NOT_READY)
63 64
            {
                LeaveCriticalSection(&wma->cs);
65
		/* default paint handling */
66
                return DefWindowProcW(hWnd, uMsg, wParam, lParam);
67
            }
68

69
            if (wParam)
70
                MCIAVI_PaintFrame(wma, (HDC)wParam);
71 72
            else
            {
73
	        PAINTSTRUCT ps;
74 75
                BeginPaint(hWnd, &ps);
                MCIAVI_PaintFrame(wma, ps.hdc);
76 77
	        EndPaint(hWnd, &ps);
	    }
78 79

            LeaveCriticalSection(&wma->cs);
80
        }
81
       return 1;
82

83
    default:
84
        return DefWindowProcW(hWnd, uMsg, wParam, lParam);
85 86 87
    }
}

88
BOOL MCIAVI_UnregisterClass(void)
89
{
90
    return UnregisterClassW(mciaviW, MCIAVI_hInstance);
91
}
92

93 94
BOOL MCIAVI_RegisterClass(void)
{
95
    WNDCLASSW wndClass;
96

97
    ZeroMemory(&wndClass, sizeof(WNDCLASSW));
98
    wndClass.style         = CS_DBLCLKS;
99
    wndClass.lpfnWndProc   = MCIAVI_WindowProc;
100 101
    wndClass.cbWndExtra    = sizeof(MCIDEVICEID);
    wndClass.hInstance     = MCIAVI_hInstance;
102 103 104 105 106 107
    wndClass.hCursor       = LoadCursorW(0, (LPCWSTR)IDC_ARROW);
    wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
    wndClass.lpszClassName = mciaviW;

    if (RegisterClassW(&wndClass)) return TRUE;
    if (GetLastError() == ERROR_CLASS_ALREADY_EXISTS) return TRUE;
108

109
    return FALSE;
110 111
}

112
BOOL    MCIAVI_CreateWindow(WINE_MCIAVI* wma, DWORD dwFlags, LPMCI_DGV_OPEN_PARMSW lpOpenParms)
113
{
114
    static const WCHAR captionW[] = {'W','i','n','e',' ','M','C','I','-','A','V','I',' ','p','l','a','y','e','r',0};
115 116
    HWND	hParent = 0;
    DWORD	dwStyle = WS_OVERLAPPEDWINDOW;
117
    RECT        rc;
118 119 120

    /* what should be done ? */
    if (wma->hWnd) return TRUE;
121 122 123 124

    if (dwFlags & MCI_DGV_OPEN_PARENT)	hParent = lpOpenParms->hWndParent;
    if (dwFlags & MCI_DGV_OPEN_WS)	dwStyle = lpOpenParms->dwStyle;

125
    rc.left = rc.top = 0;
126 127 128
    rc.right = (wma->hic ? wma->outbih : wma->inbih)->biWidth;
    rc.bottom = (wma->hic ? wma->outbih : wma->inbih)->biHeight;
    AdjustWindowRect(&rc, dwStyle, FALSE);
129 130 131 132 133 134
    if (!(dwStyle & (WS_CHILD|WS_POPUP))) /* overlapped window ? */
    {
        rc.right -= rc.left;
        rc.bottom -= rc.top;
        rc.left = rc.top = CW_USEDEFAULT;
    }
135

136
    wma->hWnd = CreateWindowW(mciaviW, captionW,
137 138 139
                              dwStyle, rc.left, rc.top,
                              rc.right, rc.bottom,
                              hParent, 0, MCIAVI_hInstance,
140
                              ULongToPtr(wma->wDevID));
141
    wma->hWndPaint = wma->hWnd;
142
    return wma->hWnd != 0;
143 144 145 146 147 148 149 150 151
}

/***************************************************************************
 * 				MCIAVI_mciPut			[internal]
 */
DWORD	MCIAVI_mciPut(UINT wDevID, DWORD dwFlags, LPMCI_DGV_PUT_PARMS lpParms)
{
    WINE_MCIAVI*	wma = MCIAVI_mciGetOpenDev(wDevID);
    RECT		rc;
152

153
    TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
154

155 156
    if (lpParms == NULL)	return MCIERR_NULL_PARAMETER_BLOCK;
    if (wma == NULL)		return MCIERR_INVALID_DEVICE_ID;
157

158 159
    EnterCriticalSection(&wma->cs);

160
    if (dwFlags & MCI_DGV_RECT) {
161 162 163 164 165 166
        /* In MCI, RECT structure is used differently: rc.right = width & rc.bottom = height
         * So convert input MCI RECT into a normal RECT */
        rc.left = lpParms->rc.left;
        rc.top = lpParms->rc.top;
        rc.right = lpParms->rc.left + lpParms->rc.right;
        rc.bottom = lpParms->rc.top + lpParms->rc.bottom;
167
    } else {
168
        GetClientRect(wma->hWndPaint, &rc);
169
    }
170

171
    if (dwFlags & MCI_DGV_PUT_CLIENT) {
172 173 174
        FIXME("PUT_CLIENT %s\n", wine_dbgstr_rect(&rc));
        LeaveCriticalSection(&wma->cs);
        return MCIERR_UNRECOGNIZED_COMMAND;
175 176
    }
    if (dwFlags & MCI_DGV_PUT_DESTINATION) {
177 178
        TRACE("PUT_DESTINATION %s\n", wine_dbgstr_rect(&rc));
        wma->dest = rc;
179 180
    }
    if (dwFlags & MCI_DGV_PUT_FRAME) {
181 182 183
        FIXME("PUT_FRAME %s\n", wine_dbgstr_rect(&rc));
        LeaveCriticalSection(&wma->cs);
        return MCIERR_UNRECOGNIZED_COMMAND;
184 185
    }
    if (dwFlags & MCI_DGV_PUT_SOURCE) {
186 187
        TRACE("PUT_SOURCE %s\n", wine_dbgstr_rect(&rc));
        wma->source = rc;
188 189
    }
    if (dwFlags & MCI_DGV_PUT_VIDEO) {
190 191 192
        FIXME("PUT_VIDEO %s\n", wine_dbgstr_rect(&rc));
        LeaveCriticalSection(&wma->cs);
        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 200 201 202 203 204 205 206 207
    return 0;
}

/******************************************************************************
 * 				MCIAVI_mciWhere			[internal]
 */
DWORD	MCIAVI_mciWhere(UINT wDevID, DWORD dwFlags, LPMCI_DGV_RECT_PARMS lpParms)
{
    WINE_MCIAVI*	wma = MCIAVI_mciGetOpenDev(wDevID);
208
    RECT		rc;
209

210
    TRACE("(%04x, %08x, %p)\n", wDevID, dwFlags, lpParms);
211

212 213
    if (lpParms == NULL)	return MCIERR_NULL_PARAMETER_BLOCK;
    if (wma == NULL)		return MCIERR_INVALID_DEVICE_ID;
214

215
    EnterCriticalSection(&wma->cs);
216 217

    if (dwFlags & MCI_DGV_WHERE_DESTINATION) {
218
	if (dwFlags & MCI_DGV_WHERE_MAX) {
219 220
	    GetClientRect(wma->hWndPaint, &rc);
	    TRACE("WHERE_DESTINATION_MAX %s\n", wine_dbgstr_rect(&rc));
221 222
	} else {
	    TRACE("WHERE_DESTINATION %s\n", wine_dbgstr_rect(&wma->dest));
223
	    rc = wma->dest;
224
	}
225 226
    }
    if (dwFlags & MCI_DGV_WHERE_FRAME) {
227 228 229 230 231
	if (dwFlags & MCI_DGV_WHERE_MAX)
	    FIXME("MCI_DGV_WHERE_FRAME_MAX\n");
	else
	    FIXME("MCI_DGV_WHERE_FRAME\n");
	LeaveCriticalSection(&wma->cs);
232 233 234
	return MCIERR_UNRECOGNIZED_COMMAND;
    }
    if (dwFlags & MCI_DGV_WHERE_SOURCE) {
235
	if (dwFlags & MCI_DGV_WHERE_MAX) {
236 237 238 239 240
	    rc.left = 0;
	    rc.top = 0;
	    rc.right = wma->inbih->biWidth;
	    rc.bottom = wma->inbih->biHeight;
	    TRACE("WHERE_SOURCE_MAX %s\n", wine_dbgstr_rect(&rc));
241 242
 	} else {
	    TRACE("WHERE_SOURCE %s\n", wine_dbgstr_rect(&wma->source));
243
	    rc = wma->source;
244
	}
245 246
    }
    if (dwFlags & MCI_DGV_WHERE_VIDEO) {
247 248 249 250 251
	if (dwFlags & MCI_DGV_WHERE_MAX)
	    FIXME("WHERE_VIDEO_MAX\n");
	else
	    FIXME("WHERE_VIDEO\n");
	LeaveCriticalSection(&wma->cs);
252 253 254
	return MCIERR_UNRECOGNIZED_COMMAND;
    }
    if (dwFlags & MCI_DGV_WHERE_WINDOW) {
255
	if (dwFlags & MCI_DGV_WHERE_MAX) {
256 257
	    GetWindowRect(GetDesktopWindow(), &rc);
	    TRACE("WHERE_WINDOW_MAX %s\n", wine_dbgstr_rect(&rc));
258
	} else {
259 260
	    GetWindowRect(wma->hWndPaint, &rc);
	    TRACE("WHERE_WINDOW %s\n", wine_dbgstr_rect(&rc));
261
	}
262
    }
263 264 265 266 267 268 269 270

    /* In MCI, RECT structure is used differently: rc.right = width & rc.bottom = height
     * So convert the normal RECT into a MCI RECT before returning */
    lpParms->rc.left = rc.left;
    lpParms->rc.top = rc.top;
    lpParms->rc.right = rc.right - rc.left;
    lpParms->rc.bottom = rc.bottom - rc.top;

271
    LeaveCriticalSection(&wma->cs);
272 273 274 275 276 277
    return 0;
}

/***************************************************************************
 * 				MCIAVI_mciWindow			[internal]
 */
278
DWORD	MCIAVI_mciWindow(UINT wDevID, DWORD dwFlags, LPMCI_DGV_WINDOW_PARMSW lpParms)
279 280
{
    WINE_MCIAVI*	wma = MCIAVI_mciGetOpenDev(wDevID);
281

282
    TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms);
283

284 285
    if (lpParms == NULL)	return MCIERR_NULL_PARAMETER_BLOCK;
    if (wma == NULL)		return MCIERR_INVALID_DEVICE_ID;
286

287 288
    EnterCriticalSection(&wma->cs);

289
    if (dwFlags & MCI_DGV_WINDOW_HWND) {
290 291 292 293 294 295
        if (IsWindow(lpParms->hWnd))
        {
            TRACE("Setting hWnd to %p\n", lpParms->hWnd);
            if (wma->hWnd) ShowWindow(wma->hWnd, SW_HIDE);
            wma->hWndPaint = (lpParms->hWnd == MCI_DGV_WINDOW_DEFAULT) ? wma->hWnd : lpParms->hWnd;
        }
296 297 298
    }
    if (dwFlags & MCI_DGV_WINDOW_STATE) {
	TRACE("Setting nCmdShow to %d\n", lpParms->nCmdShow);
299
        ShowWindow(wma->hWndPaint, lpParms->nCmdShow);
300 301
    }
    if (dwFlags & MCI_DGV_WINDOW_TEXT) {
302 303
	TRACE("Setting caption to %s\n", debugstr_w(lpParms->lpstrText));
        SetWindowTextW(wma->hWndPaint, lpParms->lpstrText);
304
    }
305

306
    LeaveCriticalSection(&wma->cs);
307 308
    return 0;
}