jscript: Added SetProperty(SCRIPTPROP_INVOKEVERSIONING) implementation.
[wine] / dlls / wing.dll16 / wing.c
1 /*
2  * WinG support
3  *
4  * Copyright (C) Robert Pouliot <krynos@clic.net>
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "config.h"
22
23 #include <stdarg.h>
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "wingdi.h"
28 #include "wownt32.h"
29 #include "wine/wingdi16.h"
30 #include "wine/debug.h"
31
32 WINE_DEFAULT_DEBUG_CHANNEL(wing);
33
34 /*************************************************************************
35  * WING {WING}
36  *
37  * The Windows Game dll provides a number of functions designed to allow
38  * programmers to bypass Gdi and write directly to video memory. The intention
39  * was to bolster the use of Windows as a gaming platform and remove the
40  * need for Dos based games using 32 bit Dos extenders.
41  *
42  * This initial approach could not compete with the performance of Dos games
43  * (such as Doom and Warcraft) at the time, and so this dll was eventually
44  * superseded by DirectX. It should not be used by new applications, and is
45  * provided only for compatibility with older Windows programs.
46  */
47
48 typedef enum WING_DITHER_TYPE
49 {
50   WING_DISPERSED_4x4, WING_DISPERSED_8x8, WING_CLUSTERED_4x4
51 } WING_DITHER_TYPE;
52
53 /***********************************************************************
54  *          WinGCreateDC        (WING.1001)
55  *
56  * Create a new WinG device context.
57  *
58  * PARAMS
59  *  None.
60  *
61  * RETURNS
62  *  Success: A handle to the created device context.
63  *  Failure: A NULL handle.
64  */
65 HDC16 WINAPI WinGCreateDC16(void)
66 {
67     TRACE("(void)\n");
68     return HDC_16( CreateCompatibleDC( 0 ));
69 }
70
71 /***********************************************************************
72  *  WinGRecommendDIBFormat    (WING.1002)
73  *
74  * Get the recommended format of bitmaps for the current display.
75  *
76  * PARAMS
77  *  bmpi [O] Destination for format information
78  *
79  * RETURNS
80  *  Success: TRUE. bmpi is filled with the best (fastest) bitmap format
81  *  Failure: FALSE, if bmpi is NULL.
82  */
83 BOOL16 WINAPI WinGRecommendDIBFormat16(BITMAPINFO *bmpi)
84 {
85     TRACE("(%p)\n", bmpi);
86
87     if (!bmpi)
88         return FALSE;
89
90     bmpi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
91     bmpi->bmiHeader.biWidth = 320;
92     bmpi->bmiHeader.biHeight = -1;
93     bmpi->bmiHeader.biPlanes = 1;
94     bmpi->bmiHeader.biBitCount = 8;
95     bmpi->bmiHeader.biCompression = BI_RGB;
96     bmpi->bmiHeader.biSizeImage = 0;
97     bmpi->bmiHeader.biXPelsPerMeter = 0;
98     bmpi->bmiHeader.biYPelsPerMeter = 0;
99     bmpi->bmiHeader.biClrUsed = 0;
100     bmpi->bmiHeader.biClrImportant = 0;
101
102     return TRUE;
103 }
104
105 /***********************************************************************
106  *        WinGCreateBitmap    (WING.1003)
107  *
108  * Create a new WinG bitmap.
109  *
110  * PARAMS
111  *  hdc  [I] WinG device context
112  *  bmpi [I] Information about the bitmap
113  *  bits [I] Location of the bitmap image data
114  *
115  * RETURNS
116  *  Success: A handle to the created bitmap.
117  *  Failure: A NULL handle.
118  */
119 HBITMAP16 WINAPI WinGCreateBitmap16(HDC16 hdc, BITMAPINFO *bmpi, SEGPTR *bits)
120 {
121     LPVOID bits32;
122     HBITMAP hbitmap;
123
124     TRACE("(%d,%p,%p): create %dx%dx%d bitmap\n", hdc, bmpi, bits,
125           bmpi->bmiHeader.biWidth, bmpi->bmiHeader.biHeight, bmpi->bmiHeader.biPlanes);
126
127     hbitmap = CreateDIBSection( HDC_32(hdc), bmpi, BI_RGB, &bits32, 0, 0 );
128     if (hbitmap)
129     {
130         DIBSECTION dib;
131         DWORD size;
132         WORD count, sel;
133         int i;
134
135         GetObjectW( hbitmap, sizeof(dib), &dib );
136         size = dib.dsBm.bmHeight * dib.dsBm.bmWidthBytes;
137
138         /* calculate number of sel's needed for size with 64K steps */
139         count = (size + 0xffff) / 0x10000;
140         sel = AllocSelectorArray16(count);
141
142         for (i = 0; i < count; i++)
143         {
144             SetSelectorBase(sel + (i << __AHSHIFT), (DWORD)bits32 + i * 0x10000);
145             SetSelectorLimit16(sel + (i << __AHSHIFT), size - 1); /* yep, limit is correct */
146             size -= 0x10000;
147         }
148         if (bits) *bits = MAKESEGPTR( sel, 0 );
149     }
150     return HBITMAP_16(hbitmap);
151 }
152
153 /***********************************************************************
154  *  WinGGetDIBPointer   (WING.1004)
155  */
156 SEGPTR WINAPI WinGGetDIBPointer16(HBITMAP16 hWinGBitmap, BITMAPINFO* bmpi)
157 {
158     FIXME("%x, %p: not supported\n", hWinGBitmap, bmpi );
159     return 0;
160 }
161
162 /***********************************************************************
163  *  WinGSetDIBColorTable   (WING.1006)
164  *
165  * Set all or part of the color table for a WinG device context.
166  *
167  * PARAMS
168  *  hdc    [I] WinG device context
169  *  start  [I] Start color
170  *  num    [I] Number of entries to set
171  *  colors [I] Array of color data
172  *
173  * RETURNS
174  *  The number of entries set.
175  */
176 UINT16 WINAPI WinGSetDIBColorTable16(HDC16 hdc, UINT16 start, UINT16 num, RGBQUAD *colors)
177 {
178     TRACE("(%d,%d,%d,%p)\n", hdc, start, num, colors);
179     return SetDIBColorTable( HDC_32(hdc), start, num, colors );
180 }
181
182 /***********************************************************************
183  *  WinGGetDIBColorTable   (WING.1005)
184  *
185  * Get all or part of the color table for a WinG device context.
186  *
187  * PARAMS
188  *  hdc    [I] WinG device context
189  *  start  [I] Start color
190  *  num    [I] Number of entries to set
191  *  colors [O] Destination for the array of color data
192  *
193  * RETURNS
194  *  The number of entries retrieved.
195  */
196 UINT16 WINAPI WinGGetDIBColorTable16(HDC16 hdc, UINT16 start, UINT16 num, RGBQUAD *colors)
197 {
198     TRACE("(%d,%d,%d,%p)\n", hdc, start, num, colors);
199     return GetDIBColorTable( HDC_32(hdc), start, num, colors );
200 }
201
202 /***********************************************************************
203  *  WinGCreateHalfTonePalette   (WING.1007)
204  *
205  * Create a half tone palette.
206  *
207  * PARAMS
208  *  None.
209  *
210  * RETURNS
211  *  Success: A handle to the created palette.
212  *  Failure: A NULL handle.
213  */
214 HPALETTE16 WINAPI WinGCreateHalfTonePalette16(void)
215 {
216     HDC hdc = CreateCompatibleDC(0);
217     HPALETTE16 ret = HPALETTE_16( CreateHalftonePalette( hdc ));
218     TRACE("(void)\n");
219     DeleteDC( hdc );
220     return ret;
221 }
222
223 /***********************************************************************
224  *  WinGCreateHalfToneBrush   (WING.1008)
225  *
226  * Create a half tone brush for a WinG device context.
227  *
228  * PARAMS
229  *  winDC [I] WinG device context
230  *  col   [I] Color
231  *  type  [I] Desired dithering type.
232  *
233  * RETURNS
234  *  Success: A handle to the created brush.
235  *  Failure: A NULL handle.
236  */
237 HBRUSH16 WINAPI WinGCreateHalfToneBrush16(HDC16 winDC, COLORREF col,
238                                             WING_DITHER_TYPE type)
239 {
240     TRACE("(%d,%d,%d)\n", winDC, col, type);
241     return HBRUSH_16( CreateSolidBrush( col ));
242 }
243
244 /***********************************************************************
245  *  WinGStretchBlt   (WING.1009)
246  *
247  * See StretchBlt16.
248  */
249 BOOL16 WINAPI WinGStretchBlt16(HDC16 destDC, INT16 xDest, INT16 yDest,
250                                INT16 widDest, INT16 heiDest,
251                                HDC16 srcDC, INT16 xSrc, INT16 ySrc,
252                                INT16 widSrc, INT16 heiSrc)
253 {
254     BOOL retval;
255     TRACE("(%d,%d,...)\n", destDC, srcDC);
256     SetStretchBltMode( HDC_32(destDC), COLORONCOLOR );
257     retval = StretchBlt( HDC_32(destDC), xDest, yDest, widDest, heiDest,
258                          HDC_32(srcDC), xSrc, ySrc, widSrc, heiSrc, SRCCOPY );
259     SetStretchBltMode( HDC_32(destDC), BLACKONWHITE );
260     return retval;
261 }
262
263 /***********************************************************************
264  *  WinGBitBlt   (WING.1010)
265  *
266  * See BitBlt16.
267  */
268 BOOL16 WINAPI WinGBitBlt16(HDC16 destDC, INT16 xDest, INT16 yDest,
269                            INT16 widDest, INT16 heiDest, HDC16 srcDC,
270                            INT16 xSrc, INT16 ySrc)
271 {
272     TRACE("(%d,%d,...)\n", destDC, srcDC);
273     return BitBlt( HDC_32(destDC), xDest, yDest, widDest, heiDest, HDC_32(srcDC), xSrc, ySrc, SRCCOPY );
274 }