winex11: Add support for receiving mouse events on non-toplevel windows.
[wine/multimedia.git] / dlls / wing.dll16 / wing.c
blobfb4aa56daeb2fab3e5c7af8e2e172b4ca76a7e31
1 /*
2 * WinG support
4 * Copyright (C) Robert Pouliot <krynos@clic.net>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
23 #include <stdarg.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "wingdi.h"
28 #include "wownt32.h"
29 #include "wine/wingdi16.h"
30 #include "wine/list.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(wing);
35 struct dib_segptr_bits
37 struct list entry;
38 HBITMAP bmp;
39 WORD sel;
40 WORD count;
43 static struct list dib_segptr_list = LIST_INIT( dib_segptr_list );
45 /* remove saved bits for bitmaps that no longer exist */
46 static void cleanup_segptr_bits(void)
48 unsigned int i;
49 struct dib_segptr_bits *bits, *next;
51 LIST_FOR_EACH_ENTRY_SAFE( bits, next, &dib_segptr_list, struct dib_segptr_bits, entry )
53 if (GetObjectType( bits->bmp ) == OBJ_BITMAP) continue;
54 for (i = 0; i < bits->count; i++) FreeSelector16( bits->sel + (i << __AHSHIFT) );
55 list_remove( &bits->entry );
56 HeapFree( GetProcessHeap(), 0, bits );
60 static SEGPTR alloc_segptr_bits( HBITMAP bmp, void *bits32 )
62 DIBSECTION dib;
63 unsigned int i, size;
64 struct dib_segptr_bits *bits;
66 cleanup_segptr_bits();
68 if (!(bits = HeapAlloc( GetProcessHeap(), 0, sizeof(*bits) ))) return 0;
70 GetObjectW( bmp, sizeof(dib), &dib );
71 size = dib.dsBm.bmHeight * dib.dsBm.bmWidthBytes;
73 /* calculate number of sel's needed for size with 64K steps */
74 bits->bmp = bmp;
75 bits->count = (size + 0xffff) / 0x10000;
76 bits->sel = AllocSelectorArray16( bits->count );
78 for (i = 0; i < bits->count; i++)
80 SetSelectorBase(bits->sel + (i << __AHSHIFT), (DWORD)bits32 + i * 0x10000);
81 SetSelectorLimit16(bits->sel + (i << __AHSHIFT), size - 1); /* yep, limit is correct */
82 size -= 0x10000;
84 list_add_head( &dib_segptr_list, &bits->entry );
85 return MAKESEGPTR( bits->sel, 0 );
88 /*************************************************************************
89 * WING {WING}
91 * The Windows Game dll provides a number of functions designed to allow
92 * programmers to bypass Gdi and write directly to video memory. The intention
93 * was to bolster the use of Windows as a gaming platform and remove the
94 * need for Dos based games using 32 bit Dos extenders.
96 * This initial approach could not compete with the performance of Dos games
97 * (such as Doom and Warcraft) at the time, and so this dll was eventually
98 * superseded by DirectX. It should not be used by new applications, and is
99 * provided only for compatibility with older Windows programs.
102 typedef enum WING_DITHER_TYPE
104 WING_DISPERSED_4x4, WING_DISPERSED_8x8, WING_CLUSTERED_4x4
105 } WING_DITHER_TYPE;
107 /***********************************************************************
108 * WinGCreateDC (WING.1001)
110 * Create a new WinG device context.
112 * PARAMS
113 * None.
115 * RETURNS
116 * Success: A handle to the created device context.
117 * Failure: A NULL handle.
119 HDC16 WINAPI WinGCreateDC16(void)
121 TRACE("(void)\n");
122 return HDC_16( CreateCompatibleDC( 0 ));
125 /***********************************************************************
126 * WinGRecommendDIBFormat (WING.1002)
128 * Get the recommended format of bitmaps for the current display.
130 * PARAMS
131 * bmpi [O] Destination for format information
133 * RETURNS
134 * Success: TRUE. bmpi is filled with the best (fastest) bitmap format
135 * Failure: FALSE, if bmpi is NULL.
137 BOOL16 WINAPI WinGRecommendDIBFormat16(BITMAPINFO *bmpi)
139 TRACE("(%p)\n", bmpi);
141 if (!bmpi)
142 return FALSE;
144 bmpi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
145 bmpi->bmiHeader.biWidth = 320;
146 bmpi->bmiHeader.biHeight = -1;
147 bmpi->bmiHeader.biPlanes = 1;
148 bmpi->bmiHeader.biBitCount = 8;
149 bmpi->bmiHeader.biCompression = BI_RGB;
150 bmpi->bmiHeader.biSizeImage = 0;
151 bmpi->bmiHeader.biXPelsPerMeter = 0;
152 bmpi->bmiHeader.biYPelsPerMeter = 0;
153 bmpi->bmiHeader.biClrUsed = 0;
154 bmpi->bmiHeader.biClrImportant = 0;
156 return TRUE;
159 /***********************************************************************
160 * WinGCreateBitmap (WING.1003)
162 * Create a new WinG bitmap.
164 * PARAMS
165 * hdc [I] WinG device context
166 * bmpi [I] Information about the bitmap
167 * bits [I] Location of the bitmap image data
169 * RETURNS
170 * Success: A handle to the created bitmap.
171 * Failure: A NULL handle.
173 HBITMAP16 WINAPI WinGCreateBitmap16(HDC16 hdc, BITMAPINFO *bmpi, SEGPTR *bits)
175 LPVOID bits32;
176 HBITMAP hbitmap;
178 TRACE("(%d,%p,%p): create %dx%dx%d bitmap\n", hdc, bmpi, bits,
179 bmpi->bmiHeader.biWidth, bmpi->bmiHeader.biHeight, bmpi->bmiHeader.biPlanes);
181 hbitmap = CreateDIBSection( HDC_32(hdc), bmpi, BI_RGB, &bits32, 0, 0 );
182 if (hbitmap)
184 SEGPTR segptr = alloc_segptr_bits( hbitmap, bits32 );
185 if (bits) *bits = segptr;
187 return HBITMAP_16(hbitmap);
190 /***********************************************************************
191 * WinGGetDIBPointer (WING.1004)
193 SEGPTR WINAPI WinGGetDIBPointer16(HBITMAP16 hWinGBitmap, BITMAPINFO* bmpi)
195 struct dib_segptr_bits *bits;
197 if (bmpi) FIXME( "%04x %p: setting BITMAPINFO not supported\n", hWinGBitmap, bmpi );
199 LIST_FOR_EACH_ENTRY( bits, &dib_segptr_list, struct dib_segptr_bits, entry )
200 if (HBITMAP_16(bits->bmp) == hWinGBitmap) return MAKESEGPTR( bits->sel, 0 );
202 return 0;
205 /***********************************************************************
206 * WinGSetDIBColorTable (WING.1006)
208 * Set all or part of the color table for a WinG device context.
210 * PARAMS
211 * hdc [I] WinG device context
212 * start [I] Start color
213 * num [I] Number of entries to set
214 * colors [I] Array of color data
216 * RETURNS
217 * The number of entries set.
219 UINT16 WINAPI WinGSetDIBColorTable16(HDC16 hdc, UINT16 start, UINT16 num, RGBQUAD *colors)
221 TRACE("(%d,%d,%d,%p)\n", hdc, start, num, colors);
222 return SetDIBColorTable( HDC_32(hdc), start, num, colors );
225 /***********************************************************************
226 * WinGGetDIBColorTable (WING.1005)
228 * Get all or part of the color table for a WinG device context.
230 * PARAMS
231 * hdc [I] WinG device context
232 * start [I] Start color
233 * num [I] Number of entries to set
234 * colors [O] Destination for the array of color data
236 * RETURNS
237 * The number of entries retrieved.
239 UINT16 WINAPI WinGGetDIBColorTable16(HDC16 hdc, UINT16 start, UINT16 num, RGBQUAD *colors)
241 TRACE("(%d,%d,%d,%p)\n", hdc, start, num, colors);
242 return GetDIBColorTable( HDC_32(hdc), start, num, colors );
245 /***********************************************************************
246 * WinGCreateHalfTonePalette (WING.1007)
248 * Create a half tone palette.
250 * PARAMS
251 * None.
253 * RETURNS
254 * Success: A handle to the created palette.
255 * Failure: A NULL handle.
257 HPALETTE16 WINAPI WinGCreateHalfTonePalette16(void)
259 HDC hdc = CreateCompatibleDC(0);
260 HPALETTE16 ret = HPALETTE_16( CreateHalftonePalette( hdc ));
261 TRACE("(void)\n");
262 DeleteDC( hdc );
263 return ret;
266 /***********************************************************************
267 * WinGCreateHalfToneBrush (WING.1008)
269 * Create a half tone brush for a WinG device context.
271 * PARAMS
272 * winDC [I] WinG device context
273 * col [I] Color
274 * type [I] Desired dithering type.
276 * RETURNS
277 * Success: A handle to the created brush.
278 * Failure: A NULL handle.
280 HBRUSH16 WINAPI WinGCreateHalfToneBrush16(HDC16 winDC, COLORREF col,
281 WING_DITHER_TYPE type)
283 TRACE("(%d,%d,%d)\n", winDC, col, type);
284 return HBRUSH_16( CreateSolidBrush( col ));
287 /***********************************************************************
288 * WinGStretchBlt (WING.1009)
290 * See StretchBlt16.
292 BOOL16 WINAPI WinGStretchBlt16(HDC16 destDC, INT16 xDest, INT16 yDest,
293 INT16 widDest, INT16 heiDest,
294 HDC16 srcDC, INT16 xSrc, INT16 ySrc,
295 INT16 widSrc, INT16 heiSrc)
297 BOOL retval;
298 TRACE("(%d,%d,...)\n", destDC, srcDC);
299 SetStretchBltMode( HDC_32(destDC), COLORONCOLOR );
300 retval = StretchBlt( HDC_32(destDC), xDest, yDest, widDest, heiDest,
301 HDC_32(srcDC), xSrc, ySrc, widSrc, heiSrc, SRCCOPY );
302 SetStretchBltMode( HDC_32(destDC), BLACKONWHITE );
303 return retval;
306 /***********************************************************************
307 * WinGBitBlt (WING.1010)
309 * See BitBlt16.
311 BOOL16 WINAPI WinGBitBlt16(HDC16 destDC, INT16 xDest, INT16 yDest,
312 INT16 widDest, INT16 heiDest, HDC16 srcDC,
313 INT16 xSrc, INT16 ySrc)
315 TRACE("(%d,%d,...)\n", destDC, srcDC);
316 return BitBlt( HDC_32(destDC), xDest, yDest, widDest, heiDest, HDC_32(srcDC), xSrc, ySrc, SRCCOPY );