gdi32: Move remaining 16-bit metafile functions to metafile16.c
[wine] / dlls / gdi32 / gdi16.c
1 /*
2  * GDI 16-bit functions
3  *
4  * Copyright 2002 Alexandre Julliard
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 <stdarg.h>
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "wingdi.h"
26 #include "wownt32.h"
27 #include "wine/wingdi16.h"
28 #include "gdi_private.h"
29 #include "wine/debug.h"
30
31 WINE_DEFAULT_DEBUG_CHANNEL(gdi);
32
33 #define HGDIOBJ_32(handle16)    ((HGDIOBJ)(ULONG_PTR)(handle16))
34 #define HGDIOBJ_16(handle32)    ((HGDIOBJ16)(ULONG_PTR)(handle32))
35
36 struct callback16_info
37 {
38     FARPROC16 proc;
39     LPARAM    param;
40 };
41
42 /* callback for LineDDA16 */
43 static void CALLBACK linedda_callback( INT x, INT y, LPARAM param )
44 {
45     const struct callback16_info *info = (struct callback16_info *)param;
46     WORD args[4];
47
48     args[3] = x;
49     args[2] = y;
50     args[1] = HIWORD(info->param);
51     args[0] = LOWORD(info->param);
52     WOWCallback16Ex( (DWORD)info->proc, WCB16_PASCAL, sizeof(args), args, NULL );
53 }
54
55 /* callback for EnumObjects16 */
56 static INT CALLBACK enum_pens_callback( void *ptr, LPARAM param )
57 {
58     const struct callback16_info *info = (struct callback16_info *)param;
59     LOGPEN *pen = ptr;
60     LOGPEN16 pen16;
61     SEGPTR segptr;
62     DWORD ret;
63     WORD args[4];
64
65     pen16.lopnStyle   = pen->lopnStyle;
66     pen16.lopnWidth.x = pen->lopnWidth.x;
67     pen16.lopnWidth.y = pen->lopnWidth.y;
68     pen16.lopnColor   = pen->lopnColor;
69     segptr = MapLS( &pen16 );
70     args[3] = SELECTOROF(segptr);
71     args[2] = OFFSETOF(segptr);
72     args[1] = HIWORD(info->param);
73     args[0] = LOWORD(info->param);
74     WOWCallback16Ex( (DWORD)info->proc, WCB16_PASCAL, sizeof(args), args, &ret );
75     UnMapLS( segptr );
76     return LOWORD(ret);
77 }
78
79 /* callback for EnumObjects16 */
80 static INT CALLBACK enum_brushes_callback( void *ptr, LPARAM param )
81 {
82     const struct callback16_info *info = (struct callback16_info *)param;
83     LOGBRUSH *brush = ptr;
84     LOGBRUSH16 brush16;
85     SEGPTR segptr;
86     DWORD ret;
87     WORD args[4];
88
89     brush16.lbStyle = brush->lbStyle;
90     brush16.lbColor = brush->lbColor;
91     brush16.lbHatch = brush->lbHatch;
92     segptr = MapLS( &brush16 );
93     args[3] = SELECTOROF(segptr);
94     args[2] = OFFSETOF(segptr);
95     args[1] = HIWORD(info->param);
96     args[0] = LOWORD(info->param);
97     WOWCallback16Ex( (DWORD)info->proc, WCB16_PASCAL, sizeof(args), args, &ret );
98     UnMapLS( segptr );
99     return ret;
100 }
101
102 /* convert a LOGFONT16 to a LOGFONTW */
103 static void logfont_16_to_W( const LOGFONT16 *font16, LPLOGFONTW font32 )
104 {
105     font32->lfHeight = font16->lfHeight;
106     font32->lfWidth = font16->lfWidth;
107     font32->lfEscapement = font16->lfEscapement;
108     font32->lfOrientation = font16->lfOrientation;
109     font32->lfWeight = font16->lfWeight;
110     font32->lfItalic = font16->lfItalic;
111     font32->lfUnderline = font16->lfUnderline;
112     font32->lfStrikeOut = font16->lfStrikeOut;
113     font32->lfCharSet = font16->lfCharSet;
114     font32->lfOutPrecision = font16->lfOutPrecision;
115     font32->lfClipPrecision = font16->lfClipPrecision;
116     font32->lfQuality = font16->lfQuality;
117     font32->lfPitchAndFamily = font16->lfPitchAndFamily;
118     MultiByteToWideChar( CP_ACP, 0, font16->lfFaceName, -1, font32->lfFaceName, LF_FACESIZE );
119     font32->lfFaceName[LF_FACESIZE-1] = 0;
120 }
121
122 /* convert a LOGFONTW to a LOGFONT16 */
123 static void logfont_W_to_16( const LOGFONTW* font32, LPLOGFONT16 font16 )
124 {
125     font16->lfHeight = font32->lfHeight;
126     font16->lfWidth = font32->lfWidth;
127     font16->lfEscapement = font32->lfEscapement;
128     font16->lfOrientation = font32->lfOrientation;
129     font16->lfWeight = font32->lfWeight;
130     font16->lfItalic = font32->lfItalic;
131     font16->lfUnderline = font32->lfUnderline;
132     font16->lfStrikeOut = font32->lfStrikeOut;
133     font16->lfCharSet = font32->lfCharSet;
134     font16->lfOutPrecision = font32->lfOutPrecision;
135     font16->lfClipPrecision = font32->lfClipPrecision;
136     font16->lfQuality = font32->lfQuality;
137     font16->lfPitchAndFamily = font32->lfPitchAndFamily;
138     WideCharToMultiByte( CP_ACP, 0, font32->lfFaceName, -1, font16->lfFaceName, LF_FACESIZE, NULL, NULL );
139     font16->lfFaceName[LF_FACESIZE-1] = 0;
140 }
141
142 /* convert a ENUMLOGFONTEXW to a ENUMLOGFONTEX16 */
143 static void enumlogfontex_W_to_16( const ENUMLOGFONTEXW *fontW,
144                                    LPENUMLOGFONTEX16 font16 )
145 {
146     logfont_W_to_16( (const LOGFONTW *)fontW, (LPLOGFONT16)font16);
147
148     WideCharToMultiByte( CP_ACP, 0, fontW->elfFullName, -1,
149                          (LPSTR) font16->elfFullName, LF_FULLFACESIZE, NULL, NULL );
150     font16->elfFullName[LF_FULLFACESIZE-1] = '\0';
151     WideCharToMultiByte( CP_ACP, 0, fontW->elfStyle, -1,
152                          (LPSTR) font16->elfStyle, LF_FACESIZE, NULL, NULL );
153     font16->elfStyle[LF_FACESIZE-1] = '\0';
154     WideCharToMultiByte( CP_ACP, 0, fontW->elfScript, -1,
155                          (LPSTR) font16->elfScript, LF_FACESIZE, NULL, NULL );
156     font16->elfScript[LF_FACESIZE-1] = '\0';
157 }
158
159 /* convert a NEWTEXTMETRICEXW to a NEWTEXTMETRICEX16 */
160 static void newtextmetricex_W_to_16( const NEWTEXTMETRICEXW *ptmW,
161                                      LPNEWTEXTMETRICEX16 ptm16 )
162 {
163     ptm16->ntmTm.tmHeight = ptmW->ntmTm.tmHeight;
164     ptm16->ntmTm.tmAscent = ptmW->ntmTm.tmAscent;
165     ptm16->ntmTm.tmDescent = ptmW->ntmTm.tmDescent;
166     ptm16->ntmTm.tmInternalLeading = ptmW->ntmTm.tmInternalLeading;
167     ptm16->ntmTm.tmExternalLeading = ptmW->ntmTm.tmExternalLeading;
168     ptm16->ntmTm.tmAveCharWidth = ptmW->ntmTm.tmAveCharWidth;
169     ptm16->ntmTm.tmMaxCharWidth = ptmW->ntmTm.tmMaxCharWidth;
170     ptm16->ntmTm.tmWeight = ptmW->ntmTm.tmWeight;
171     ptm16->ntmTm.tmOverhang = ptmW->ntmTm.tmOverhang;
172     ptm16->ntmTm.tmDigitizedAspectX = ptmW->ntmTm.tmDigitizedAspectX;
173     ptm16->ntmTm.tmDigitizedAspectY = ptmW->ntmTm.tmDigitizedAspectY;
174     ptm16->ntmTm.tmFirstChar = ptmW->ntmTm.tmFirstChar > 255 ? 255 : ptmW->ntmTm.tmFirstChar;
175     ptm16->ntmTm.tmLastChar = ptmW->ntmTm.tmLastChar > 255 ? 255 : ptmW->ntmTm.tmLastChar;
176     ptm16->ntmTm.tmDefaultChar = ptmW->ntmTm.tmDefaultChar > 255 ? 255 : ptmW->ntmTm.tmDefaultChar;
177     ptm16->ntmTm.tmBreakChar = ptmW->ntmTm.tmBreakChar > 255 ? 255 : ptmW->ntmTm.tmBreakChar;
178     ptm16->ntmTm.tmItalic = ptmW->ntmTm.tmItalic;
179     ptm16->ntmTm.tmUnderlined = ptmW->ntmTm.tmUnderlined;
180     ptm16->ntmTm.tmStruckOut = ptmW->ntmTm.tmStruckOut;
181     ptm16->ntmTm.tmPitchAndFamily = ptmW->ntmTm.tmPitchAndFamily;
182     ptm16->ntmTm.tmCharSet = ptmW->ntmTm.tmCharSet;
183     ptm16->ntmTm.ntmFlags = ptmW->ntmTm.ntmFlags;
184     ptm16->ntmTm.ntmSizeEM = ptmW->ntmTm.ntmSizeEM;
185     ptm16->ntmTm.ntmCellHeight = ptmW->ntmTm.ntmCellHeight;
186     ptm16->ntmTm.ntmAvgWidth = ptmW->ntmTm.ntmAvgWidth;
187     ptm16->ntmFontSig = ptmW->ntmFontSig;
188 }
189
190 /*
191  * callback for EnumFontFamiliesEx16
192  * Note: plf is really an ENUMLOGFONTEXW, and ptm is a NEWTEXTMETRICEXW.
193  *       We have to use other types because of the FONTENUMPROCW definition.
194  */
195 static INT CALLBACK enum_font_callback( const LOGFONTW *plf,
196                                         const TEXTMETRICW *ptm, DWORD fType,
197                                         LPARAM param )
198 {
199     const struct callback16_info *info = (struct callback16_info *)param;
200     ENUMLOGFONTEX16 elfe16;
201     NEWTEXTMETRICEX16 ntm16;
202     SEGPTR segelfe16;
203     SEGPTR segntm16;
204     WORD args[7];
205     DWORD ret;
206
207     enumlogfontex_W_to_16((const ENUMLOGFONTEXW *)plf, &elfe16);
208     newtextmetricex_W_to_16((const NEWTEXTMETRICEXW *)ptm, &ntm16);
209     segelfe16 = MapLS( &elfe16 );
210     segntm16 = MapLS( &ntm16 );
211     args[6] = SELECTOROF(segelfe16);
212     args[5] = OFFSETOF(segelfe16);
213     args[4] = SELECTOROF(segntm16);
214     args[3] = OFFSETOF(segntm16);
215     args[2] = fType;
216     args[1] = HIWORD(info->param);
217     args[0] = LOWORD(info->param);
218
219     WOWCallback16Ex( (DWORD)info->proc, WCB16_PASCAL, sizeof(args), args, &ret );
220     UnMapLS( segelfe16 );
221     UnMapLS( segntm16 );
222     return LOWORD(ret);
223 }
224
225
226 /***********************************************************************
227  *           SetBkColor    (GDI.1)
228  */
229 COLORREF WINAPI SetBkColor16( HDC16 hdc, COLORREF color )
230 {
231     return SetBkColor( HDC_32(hdc), color );
232 }
233
234
235 /***********************************************************************
236  *              SetBkMode (GDI.2)
237  */
238 INT16 WINAPI SetBkMode16( HDC16 hdc, INT16 mode )
239 {
240     return SetBkMode( HDC_32(hdc), mode );
241 }
242
243
244 /***********************************************************************
245  *           SetMapMode    (GDI.3)
246  */
247 INT16 WINAPI SetMapMode16( HDC16 hdc, INT16 mode )
248 {
249     return SetMapMode( HDC_32(hdc), mode );
250 }
251
252
253 /***********************************************************************
254  *              SetROP2 (GDI.4)
255  */
256 INT16 WINAPI SetROP216( HDC16 hdc, INT16 mode )
257 {
258     return SetROP2( HDC_32(hdc), mode );
259 }
260
261
262 /***********************************************************************
263  *              SetRelAbs (GDI.5)
264  */
265 INT16 WINAPI SetRelAbs16( HDC16 hdc, INT16 mode )
266 {
267     return SetRelAbs( HDC_32(hdc), mode );
268 }
269
270
271 /***********************************************************************
272  *              SetPolyFillMode (GDI.6)
273  */
274 INT16 WINAPI SetPolyFillMode16( HDC16 hdc, INT16 mode )
275 {
276     return SetPolyFillMode( HDC_32(hdc), mode );
277 }
278
279
280 /***********************************************************************
281  *              SetStretchBltMode (GDI.7)
282  */
283 INT16 WINAPI SetStretchBltMode16( HDC16 hdc, INT16 mode )
284 {
285     return SetStretchBltMode( HDC_32(hdc), mode );
286 }
287
288
289 /***********************************************************************
290  *           SetTextCharacterExtra    (GDI.8)
291  */
292 INT16 WINAPI SetTextCharacterExtra16( HDC16 hdc, INT16 extra )
293 {
294     return SetTextCharacterExtra( HDC_32(hdc), extra );
295 }
296
297
298 /***********************************************************************
299  *           SetTextColor    (GDI.9)
300  */
301 COLORREF WINAPI SetTextColor16( HDC16 hdc, COLORREF color )
302 {
303     return SetTextColor( HDC_32(hdc), color );
304 }
305
306
307 /***********************************************************************
308  *           SetTextJustification    (GDI.10)
309  */
310 INT16 WINAPI SetTextJustification16( HDC16 hdc, INT16 extra, INT16 breaks )
311 {
312     return SetTextJustification( HDC_32(hdc), extra, breaks );
313 }
314
315
316 /***********************************************************************
317  *           SetWindowOrg    (GDI.11)
318  */
319 DWORD WINAPI SetWindowOrg16( HDC16 hdc, INT16 x, INT16 y )
320 {
321     POINT pt;
322     if (!SetWindowOrgEx( HDC_32(hdc), x, y, &pt )) return 0;
323     return MAKELONG( pt.x, pt.y );
324 }
325
326
327 /***********************************************************************
328  *           SetWindowExt    (GDI.12)
329  */
330 DWORD WINAPI SetWindowExt16( HDC16 hdc, INT16 x, INT16 y )
331 {
332     SIZE size;
333     if (!SetWindowExtEx( HDC_32(hdc), x, y, &size )) return 0;
334     return MAKELONG( size.cx, size.cy );
335 }
336
337
338 /***********************************************************************
339  *           SetViewportOrg    (GDI.13)
340  */
341 DWORD WINAPI SetViewportOrg16( HDC16 hdc, INT16 x, INT16 y )
342 {
343     POINT pt;
344     if (!SetViewportOrgEx( HDC_32(hdc), x, y, &pt )) return 0;
345     return MAKELONG( pt.x, pt.y );
346 }
347
348
349 /***********************************************************************
350  *           SetViewportExt    (GDI.14)
351  */
352 DWORD WINAPI SetViewportExt16( HDC16 hdc, INT16 x, INT16 y )
353 {
354     SIZE size;
355     if (!SetViewportExtEx( HDC_32(hdc), x, y, &size )) return 0;
356     return MAKELONG( size.cx, size.cy );
357 }
358
359
360 /***********************************************************************
361  *           OffsetWindowOrg    (GDI.15)
362  */
363 DWORD WINAPI OffsetWindowOrg16( HDC16 hdc, INT16 x, INT16 y )
364 {
365     POINT pt;
366     if (!OffsetWindowOrgEx( HDC_32(hdc), x, y, &pt )) return 0;
367     return MAKELONG( pt.x, pt.y );
368 }
369
370
371 /***********************************************************************
372  *           ScaleWindowExt    (GDI.16)
373  */
374 DWORD WINAPI ScaleWindowExt16( HDC16 hdc, INT16 xNum, INT16 xDenom,
375                              INT16 yNum, INT16 yDenom )
376 {
377     SIZE size;
378     if (!ScaleWindowExtEx( HDC_32(hdc), xNum, xDenom, yNum, yDenom, &size ))
379         return FALSE;
380     return MAKELONG( size.cx,  size.cy );
381 }
382
383
384 /***********************************************************************
385  *           OffsetViewportOrg    (GDI.17)
386  */
387 DWORD WINAPI OffsetViewportOrg16( HDC16 hdc, INT16 x, INT16 y )
388 {
389     POINT pt;
390     if (!OffsetViewportOrgEx( HDC_32(hdc), x, y, &pt )) return 0;
391     return MAKELONG( pt.x, pt.y );
392 }
393
394
395 /***********************************************************************
396  *           ScaleViewportExt    (GDI.18)
397  */
398 DWORD WINAPI ScaleViewportExt16( HDC16 hdc, INT16 xNum, INT16 xDenom,
399                                INT16 yNum, INT16 yDenom )
400 {
401     SIZE size;
402     if (!ScaleViewportExtEx( HDC_32(hdc), xNum, xDenom, yNum, yDenom, &size ))
403         return FALSE;
404     return MAKELONG( size.cx,  size.cy );
405 }
406
407
408 /***********************************************************************
409  *           LineTo    (GDI.19)
410  */
411 BOOL16 WINAPI LineTo16( HDC16 hdc, INT16 x, INT16 y )
412 {
413     return LineTo( HDC_32(hdc), x, y );
414 }
415
416
417 /***********************************************************************
418  *           MoveTo    (GDI.20)
419  */
420 DWORD WINAPI MoveTo16( HDC16 hdc, INT16 x, INT16 y )
421 {
422     POINT pt;
423
424     if (!MoveToEx( HDC_32(hdc), x, y, &pt )) return 0;
425     return MAKELONG(pt.x,pt.y);
426 }
427
428
429 /***********************************************************************
430  *           ExcludeClipRect    (GDI.21)
431  */
432 INT16 WINAPI ExcludeClipRect16( HDC16 hdc, INT16 left, INT16 top,
433                                 INT16 right, INT16 bottom )
434 {
435     return ExcludeClipRect( HDC_32(hdc), left, top, right, bottom );
436 }
437
438
439 /***********************************************************************
440  *           IntersectClipRect    (GDI.22)
441  */
442 INT16 WINAPI IntersectClipRect16( HDC16 hdc, INT16 left, INT16 top,
443                                   INT16 right, INT16 bottom )
444 {
445     return IntersectClipRect( HDC_32(hdc), left, top, right, bottom );
446 }
447
448
449 /***********************************************************************
450  *           Arc    (GDI.23)
451  */
452 BOOL16 WINAPI Arc16( HDC16 hdc, INT16 left, INT16 top, INT16 right,
453                      INT16 bottom, INT16 xstart, INT16 ystart,
454                      INT16 xend, INT16 yend )
455 {
456     return Arc( HDC_32(hdc), left, top, right, bottom, xstart, ystart, xend, yend );
457 }
458
459
460 /***********************************************************************
461  *           Ellipse    (GDI.24)
462  */
463 BOOL16 WINAPI Ellipse16( HDC16 hdc, INT16 left, INT16 top,
464                          INT16 right, INT16 bottom )
465 {
466     return Ellipse( HDC_32(hdc), left, top, right, bottom );
467 }
468
469
470 /**********************************************************************
471  *          FloodFill   (GDI.25)
472  */
473 BOOL16 WINAPI FloodFill16( HDC16 hdc, INT16 x, INT16 y, COLORREF color )
474 {
475     return ExtFloodFill( HDC_32(hdc), x, y, color, FLOODFILLBORDER );
476 }
477
478
479 /***********************************************************************
480  *           Pie    (GDI.26)
481  */
482 BOOL16 WINAPI Pie16( HDC16 hdc, INT16 left, INT16 top,
483                      INT16 right, INT16 bottom, INT16 xstart, INT16 ystart,
484                      INT16 xend, INT16 yend )
485 {
486     return Pie( HDC_32(hdc), left, top, right, bottom, xstart, ystart, xend, yend );
487 }
488
489
490 /***********************************************************************
491  *           Rectangle    (GDI.27)
492  */
493 BOOL16 WINAPI Rectangle16( HDC16 hdc, INT16 left, INT16 top,
494                            INT16 right, INT16 bottom )
495 {
496     return Rectangle( HDC_32(hdc), left, top, right, bottom );
497 }
498
499
500 /***********************************************************************
501  *           RoundRect    (GDI.28)
502  */
503 BOOL16 WINAPI RoundRect16( HDC16 hdc, INT16 left, INT16 top, INT16 right,
504                            INT16 bottom, INT16 ell_width, INT16 ell_height )
505 {
506     return RoundRect( HDC_32(hdc), left, top, right, bottom, ell_width, ell_height );
507 }
508
509
510 /***********************************************************************
511  *           PatBlt    (GDI.29)
512  */
513 BOOL16 WINAPI PatBlt16( HDC16 hdc, INT16 left, INT16 top,
514                         INT16 width, INT16 height, DWORD rop)
515 {
516     return PatBlt( HDC_32(hdc), left, top, width, height, rop );
517 }
518
519
520 /***********************************************************************
521  *           SaveDC    (GDI.30)
522  */
523 INT16 WINAPI SaveDC16( HDC16 hdc )
524 {
525     return SaveDC( HDC_32(hdc) );
526 }
527
528
529 /***********************************************************************
530  *           SetPixel    (GDI.31)
531  */
532 COLORREF WINAPI SetPixel16( HDC16 hdc, INT16 x, INT16 y, COLORREF color )
533 {
534     return SetPixel( HDC_32(hdc), x, y, color );
535 }
536
537
538 /***********************************************************************
539  *           OffsetClipRgn    (GDI.32)
540  */
541 INT16 WINAPI OffsetClipRgn16( HDC16 hdc, INT16 x, INT16 y )
542 {
543     return OffsetClipRgn( HDC_32(hdc), x, y );
544 }
545
546
547 /***********************************************************************
548  *           TextOut    (GDI.33)
549  */
550 BOOL16 WINAPI TextOut16( HDC16 hdc, INT16 x, INT16 y, LPCSTR str, INT16 count )
551 {
552     return TextOutA( HDC_32(hdc), x, y, str, count );
553 }
554
555
556 /***********************************************************************
557  *           BitBlt    (GDI.34)
558  */
559 BOOL16 WINAPI BitBlt16( HDC16 hdcDst, INT16 xDst, INT16 yDst, INT16 width,
560                         INT16 height, HDC16 hdcSrc, INT16 xSrc, INT16 ySrc,
561                         DWORD rop )
562 {
563     return BitBlt( HDC_32(hdcDst), xDst, yDst, width, height, HDC_32(hdcSrc), xSrc, ySrc, rop );
564 }
565
566
567 /***********************************************************************
568  *           StretchBlt    (GDI.35)
569  */
570 BOOL16 WINAPI StretchBlt16( HDC16 hdcDst, INT16 xDst, INT16 yDst,
571                             INT16 widthDst, INT16 heightDst,
572                             HDC16 hdcSrc, INT16 xSrc, INT16 ySrc,
573                             INT16 widthSrc, INT16 heightSrc, DWORD rop )
574 {
575     return StretchBlt( HDC_32(hdcDst), xDst, yDst, widthDst, heightDst,
576                        HDC_32(hdcSrc), xSrc, ySrc, widthSrc, heightSrc, rop );
577 }
578
579
580 /**********************************************************************
581  *          Polygon  (GDI.36)
582  */
583 BOOL16 WINAPI Polygon16( HDC16 hdc, const POINT16* pt, INT16 count )
584 {
585     register int i;
586     BOOL ret;
587     LPPOINT pt32 = HeapAlloc( GetProcessHeap(), 0, count*sizeof(POINT) );
588
589     if (!pt32) return FALSE;
590     for (i=count;i--;)
591     {
592         pt32[i].x = pt[i].x;
593         pt32[i].y = pt[i].y;
594     }
595     ret = Polygon(HDC_32(hdc),pt32,count);
596     HeapFree( GetProcessHeap(), 0, pt32 );
597     return ret;
598 }
599
600
601 /**********************************************************************
602  *          Polyline  (GDI.37)
603  */
604 BOOL16 WINAPI Polyline16( HDC16 hdc, const POINT16* pt, INT16 count )
605 {
606     register int i;
607     BOOL16 ret;
608     LPPOINT pt32 = HeapAlloc( GetProcessHeap(), 0, count*sizeof(POINT) );
609
610     if (!pt32) return FALSE;
611     for (i=count;i--;)
612     {
613         pt32[i].x = pt[i].x;
614         pt32[i].y = pt[i].y;
615     }
616     ret = Polyline(HDC_32(hdc),pt32,count);
617     HeapFree( GetProcessHeap(), 0, pt32 );
618     return ret;
619 }
620
621
622 /***********************************************************************
623  *            Escape   (GDI.38)
624  */
625 INT16 WINAPI Escape16( HDC16 hdc, INT16 escape, INT16 in_count, SEGPTR in_data, LPVOID out_data )
626 {
627     INT ret;
628
629     switch(escape)
630     {
631     /* Escape(hdc,CLIP_TO_PATH,LPINT16,NULL) */
632     /* Escape(hdc,DRAFTMODE,LPINT16,NULL) */
633     /* Escape(hdc,ENUMPAPERBINS,LPINT16,LPSTR); */
634     /* Escape(hdc,EPSPRINTING,LPINT16,NULL) */
635     /* Escape(hdc,EXT_DEVICE_CAPS,LPINT16,LPDWORD) */
636     /* Escape(hdc,GETCOLORTABLE,LPINT16,LPDWORD) */
637     /* Escape(hdc,MOUSETRAILS,LPINT16,NULL) */
638     /* Escape(hdc,POSTSCRIPT_IGNORE,LPINT16,NULL) */
639     /* Escape(hdc,QUERYESCSUPPORT,LPINT16,NULL) */
640     /* Escape(hdc,SET_ARC_DIRECTION,LPINT16,NULL) */
641     /* Escape(hdc,SET_POLY_MODE,LPINT16,NULL) */
642     /* Escape(hdc,SET_SCREEN_ANGLE,LPINT16,NULL) */
643     /* Escape(hdc,SET_SPREAD,LPINT16,NULL) */
644     case CLIP_TO_PATH:
645     case DRAFTMODE:
646     case ENUMPAPERBINS:
647     case EPSPRINTING:
648     case EXT_DEVICE_CAPS:
649     case GETCOLORTABLE:
650     case MOUSETRAILS:
651     case POSTSCRIPT_IGNORE:
652     case QUERYESCSUPPORT:
653     case SET_ARC_DIRECTION:
654     case SET_POLY_MODE:
655     case SET_SCREEN_ANGLE:
656     case SET_SPREAD:
657     {
658         INT16 *ptr = MapSL(in_data);
659         INT data = *ptr;
660         return Escape( HDC_32(hdc), escape, sizeof(data), (LPCSTR)&data, out_data );
661     }
662
663     /* Escape(hdc,ENABLEDUPLEX,LPUINT16,NULL) */
664     case ENABLEDUPLEX:
665     {
666         UINT16 *ptr = MapSL(in_data);
667         UINT data = *ptr;
668         return Escape( HDC_32(hdc), escape, sizeof(data), (LPCSTR)&data, NULL );
669     }
670
671     /* Escape(hdc,GETPHYSPAGESIZE,NULL,LPPOINT16) */
672     /* Escape(hdc,GETPRINTINGOFFSET,NULL,LPPOINT16) */
673     /* Escape(hdc,GETSCALINGFACTOR,NULL,LPPOINT16) */
674     case GETPHYSPAGESIZE:
675     case GETPRINTINGOFFSET:
676     case GETSCALINGFACTOR:
677     {
678         POINT16 *ptr = out_data;
679         POINT pt32;
680         ret = Escape( HDC_32(hdc), escape, 0, NULL, &pt32 );
681         ptr->x = pt32.x;
682         ptr->y = pt32.y;
683         return ret;
684     }
685
686     /* Escape(hdc,ENABLEPAIRKERNING,LPINT16,LPINT16); */
687     /* Escape(hdc,ENABLERELATIVEWIDTHS,LPINT16,LPINT16); */
688     /* Escape(hdc,SETCOPYCOUNT,LPINT16,LPINT16) */
689     /* Escape(hdc,SETKERNTRACK,LPINT16,LPINT16) */
690     /* Escape(hdc,SETLINECAP,LPINT16,LPINT16) */
691     /* Escape(hdc,SETLINEJOIN,LPINT16,LPINT16) */
692     /* Escape(hdc,SETMITERLIMIT,LPINT16,LPINT16) */
693     case ENABLEPAIRKERNING:
694     case ENABLERELATIVEWIDTHS:
695     case SETCOPYCOUNT:
696     case SETKERNTRACK:
697     case SETLINECAP:
698     case SETLINEJOIN:
699     case SETMITERLIMIT:
700     {
701         INT16 *new = MapSL(in_data);
702         INT16 *old = out_data;
703         INT out, in = *new;
704         ret = Escape( HDC_32(hdc), escape, sizeof(in), (LPCSTR)&in, &out );
705         *old = out;
706         return ret;
707     }
708
709     /* Escape(hdc,SETABORTPROC,ABORTPROC,NULL); */
710     case SETABORTPROC:
711         return SetAbortProc16( hdc, (ABORTPROC16)in_data );
712
713     /* Escape(hdc,STARTDOC,LPSTR,LPDOCINFO16);
714      * lpvOutData is actually a pointer to the DocInfo structure and used as
715      * a second input parameter */
716     case STARTDOC:
717         if (out_data)
718         {
719             ret = StartDoc16( hdc, out_data );
720             if (ret > 0) ret = StartPage( HDC_32(hdc) );
721             return ret;
722         }
723         return Escape( HDC_32(hdc), escape, in_count, MapSL(in_data), NULL );
724
725     /* Escape(hdc,SET_BOUNDS,LPRECT16,NULL); */
726     /* Escape(hdc,SET_CLIP_BOX,LPRECT16,NULL); */
727     case SET_BOUNDS:
728     case SET_CLIP_BOX:
729     {
730         RECT16 *rc16 = MapSL(in_data);
731         RECT rc;
732         rc.left   = rc16->left;
733         rc.top    = rc16->top;
734         rc.right  = rc16->right;
735         rc.bottom = rc16->bottom;
736         return Escape( HDC_32(hdc), escape, sizeof(rc), (LPCSTR)&rc, NULL );
737     }
738
739     /* Escape(hdc,NEXTBAND,NULL,LPRECT16); */
740     case NEXTBAND:
741     {
742         RECT rc;
743         RECT16 *rc16 = out_data;
744         ret = Escape( HDC_32(hdc), escape, 0, NULL, &rc );
745         rc16->left   = rc.left;
746         rc16->top    = rc.top;
747         rc16->right  = rc.right;
748         rc16->bottom = rc.bottom;
749         return ret;
750     }
751     /* Escape(hdc,DRAWPATTERNRECT,PRECT_STRUCT*,NULL); */
752     case DRAWPATTERNRECT:
753     {
754         DRAWPATRECT pr;
755         DRAWPATRECT16 *pr16 = MapSL(in_data);
756
757         pr.ptPosition.x = pr16->ptPosition.x;
758         pr.ptPosition.y = pr16->ptPosition.y;
759         pr.ptSize.x     = pr16->ptSize.x;
760         pr.ptSize.y     = pr16->ptSize.y;
761         pr.wStyle       = pr16->wStyle;
762         pr.wPattern     = pr16->wPattern;
763         return Escape( HDC_32(hdc), escape, sizeof(pr), (LPCSTR)&pr, NULL );
764     }
765
766     /* Escape(hdc,ABORTDOC,NULL,NULL); */
767     /* Escape(hdc,BANDINFO,BANDINFOSTRUCT*,BANDINFOSTRUCT*); */
768     /* Escape(hdc,BEGIN_PATH,NULL,NULL); */
769     /* Escape(hdc,ENDDOC,NULL,NULL); */
770     /* Escape(hdc,END_PATH,PATHINFO,NULL); */
771     /* Escape(hdc,EXTTEXTOUT,EXTTEXT_STRUCT*,NULL); */
772     /* Escape(hdc,FLUSHOUTPUT,NULL,NULL); */
773     /* Escape(hdc,GETFACENAME,NULL,LPSTR); */
774     /* Escape(hdc,GETPAIRKERNTABLE,NULL,KERNPAIR*); */
775     /* Escape(hdc,GETSETPAPERBINS,BinInfo*,BinInfo*); */
776     /* Escape(hdc,GETSETPRINTORIENT,ORIENT*,NULL); */
777     /* Escape(hdc,GETSETSCREENPARAMS,SCREENPARAMS*,SCREENPARAMS*); */
778     /* Escape(hdc,GETTECHNOLOGY,NULL,LPSTR); */
779     /* Escape(hdc,GETTRACKKERNTABLE,NULL,KERNTRACK*); */
780     /* Escape(hdc,MFCOMMENT,LPSTR,NULL); */
781     /* Escape(hdc,NEWFRAME,NULL,NULL); */
782     /* Escape(hdc,PASSTHROUGH,LPSTR,NULL); */
783     /* Escape(hdc,RESTORE_CTM,NULL,NULL); */
784     /* Escape(hdc,SAVE_CTM,NULL,NULL); */
785     /* Escape(hdc,SETALLJUSTVALUES,EXTTEXTDATA*,NULL); */
786     /* Escape(hdc,SETCOLORTABLE,COLORTABLE_STRUCT*,LPDWORD); */
787     /* Escape(hdc,SET_BACKGROUND_COLOR,LPDWORD,LPDWORD); */
788     /* Escape(hdc,TRANSFORM_CTM,LPSTR,NULL); */
789     case ABORTDOC:
790     case BANDINFO:
791     case BEGIN_PATH:
792     case ENDDOC:
793     case END_PATH:
794     case EXTTEXTOUT:
795     case FLUSHOUTPUT:
796     case GETFACENAME:
797     case GETPAIRKERNTABLE:
798     case GETSETPAPERBINS:
799     case GETSETPRINTORIENT:
800     case GETSETSCREENPARAMS:
801     case GETTECHNOLOGY:
802     case GETTRACKKERNTABLE:
803     case MFCOMMENT:
804     case NEWFRAME:
805     case PASSTHROUGH:
806     case RESTORE_CTM:
807     case SAVE_CTM:
808     case SETALLJUSTVALUES:
809     case SETCOLORTABLE:
810     case SET_BACKGROUND_COLOR:
811     case TRANSFORM_CTM:
812         /* pass it unmodified to the 32-bit function */
813         return Escape( HDC_32(hdc), escape, in_count, MapSL(in_data), out_data );
814
815     /* Escape(hdc,ENUMPAPERMETRICS,LPINT16,LPRECT16); */
816     /* Escape(hdc,GETEXTENDEDTEXTMETRICS,LPUINT16,EXTTEXTMETRIC*); */
817     /* Escape(hdc,GETEXTENTTABLE,LPSTR,LPINT16); */
818     /* Escape(hdc,GETSETPAPERMETRICS,LPRECT16,LPRECT16); */
819     /* Escape(hdc,GETVECTORBRUSHSIZE,LPLOGBRUSH16,LPPOINT16); */
820     /* Escape(hdc,GETVECTORPENSIZE,LPLOGPEN16,LPPOINT16); */
821     case ENUMPAPERMETRICS:
822     case GETEXTENDEDTEXTMETRICS:
823     case GETEXTENTTABLE:
824     case GETSETPAPERMETRICS:
825     case GETVECTORBRUSHSIZE:
826     case GETVECTORPENSIZE:
827     default:
828         FIXME("unknown/unsupported 16-bit escape %x (%d,%p,%p\n",
829               escape, in_count, MapSL(in_data), out_data );
830         return Escape( HDC_32(hdc), escape, in_count, MapSL(in_data), out_data );
831     }
832 }
833
834
835 /***********************************************************************
836  *           RestoreDC    (GDI.39)
837  */
838 BOOL16 WINAPI RestoreDC16( HDC16 hdc, INT16 level )
839 {
840     return RestoreDC( HDC_32(hdc), level );
841 }
842
843
844 /***********************************************************************
845  *           FillRgn    (GDI.40)
846  */
847 BOOL16 WINAPI FillRgn16( HDC16 hdc, HRGN16 hrgn, HBRUSH16 hbrush )
848 {
849     return FillRgn( HDC_32(hdc), HRGN_32(hrgn), HBRUSH_32(hbrush) );
850 }
851
852
853 /***********************************************************************
854  *           FrameRgn     (GDI.41)
855  */
856 BOOL16 WINAPI FrameRgn16( HDC16 hdc, HRGN16 hrgn, HBRUSH16 hbrush,
857                           INT16 nWidth, INT16 nHeight )
858 {
859     return FrameRgn( HDC_32(hdc), HRGN_32(hrgn), HBRUSH_32(hbrush), nWidth, nHeight );
860 }
861
862
863 /***********************************************************************
864  *           InvertRgn    (GDI.42)
865  */
866 BOOL16 WINAPI InvertRgn16( HDC16 hdc, HRGN16 hrgn )
867 {
868     return InvertRgn( HDC_32(hdc), HRGN_32(hrgn) );
869 }
870
871
872 /***********************************************************************
873  *           PaintRgn    (GDI.43)
874  */
875 BOOL16 WINAPI PaintRgn16( HDC16 hdc, HRGN16 hrgn )
876 {
877     return PaintRgn( HDC_32(hdc), HRGN_32(hrgn) );
878 }
879
880
881 /***********************************************************************
882  *           SelectClipRgn    (GDI.44)
883  */
884 INT16 WINAPI SelectClipRgn16( HDC16 hdc, HRGN16 hrgn )
885 {
886     return SelectClipRgn( HDC_32(hdc), HRGN_32(hrgn) );
887 }
888
889
890 /***********************************************************************
891  *           SelectObject    (GDI.45)
892  */
893 HGDIOBJ16 WINAPI SelectObject16( HDC16 hdc, HGDIOBJ16 handle )
894 {
895     return HGDIOBJ_16( SelectObject( HDC_32(hdc), HGDIOBJ_32(handle) ) );
896 }
897
898
899 /***********************************************************************
900  *           CombineRgn    (GDI.47)
901  */
902 INT16 WINAPI CombineRgn16(HRGN16 hDest, HRGN16 hSrc1, HRGN16 hSrc2, INT16 mode)
903 {
904     return CombineRgn( HRGN_32(hDest), HRGN_32(hSrc1), HRGN_32(hSrc2), mode );
905 }
906
907
908 /***********************************************************************
909  *           CreateBitmap    (GDI.48)
910  */
911 HBITMAP16 WINAPI CreateBitmap16( INT16 width, INT16 height, UINT16 planes,
912                                  UINT16 bpp, LPCVOID bits )
913 {
914     return HBITMAP_16( CreateBitmap( width, height, planes & 0xff, bpp & 0xff, bits ) );
915 }
916
917
918 /***********************************************************************
919  *           CreateBitmapIndirect    (GDI.49)
920  */
921 HBITMAP16 WINAPI CreateBitmapIndirect16( const BITMAP16 * bmp )
922 {
923     return CreateBitmap16( bmp->bmWidth, bmp->bmHeight, bmp->bmPlanes,
924                            bmp->bmBitsPixel, MapSL( bmp->bmBits ) );
925 }
926
927
928 /***********************************************************************
929  *           CreateBrushIndirect    (GDI.50)
930  */
931 HBRUSH16 WINAPI CreateBrushIndirect16( const LOGBRUSH16 * brush )
932 {
933     LOGBRUSH brush32;
934
935     if (brush->lbStyle == BS_DIBPATTERN || brush->lbStyle == BS_DIBPATTERN8X8)
936         return CreateDIBPatternBrush16( brush->lbHatch, brush->lbColor );
937
938     brush32.lbStyle = brush->lbStyle;
939     brush32.lbColor = brush->lbColor;
940     brush32.lbHatch = brush->lbHatch;
941     return HBRUSH_16( CreateBrushIndirect(&brush32) );
942 }
943
944
945 /***********************************************************************
946  *           CreateCompatibleBitmap    (GDI.51)
947  */
948 HBITMAP16 WINAPI CreateCompatibleBitmap16( HDC16 hdc, INT16 width, INT16 height )
949 {
950     return HBITMAP_16( CreateCompatibleBitmap( HDC_32(hdc), width, height ) );
951 }
952
953
954 /***********************************************************************
955  *           CreateCompatibleDC    (GDI.52)
956  */
957 HDC16 WINAPI CreateCompatibleDC16( HDC16 hdc )
958 {
959     return HDC_16( CreateCompatibleDC( HDC_32(hdc) ) );
960 }
961
962
963 /***********************************************************************
964  *           CreateDC    (GDI.53)
965  */
966 HDC16 WINAPI CreateDC16( LPCSTR driver, LPCSTR device, LPCSTR output,
967                          const DEVMODEA *initData )
968 {
969     return HDC_16( CreateDCA( driver, device, output, initData ) );
970 }
971
972
973 /***********************************************************************
974  *           CreateEllipticRgn    (GDI.54)
975  */
976 HRGN16 WINAPI CreateEllipticRgn16( INT16 left, INT16 top, INT16 right, INT16 bottom )
977 {
978     return HRGN_16( CreateEllipticRgn( left, top, right, bottom ) );
979 }
980
981
982 /***********************************************************************
983  *           CreateEllipticRgnIndirect    (GDI.55)
984  */
985 HRGN16 WINAPI CreateEllipticRgnIndirect16( const RECT16 *rect )
986 {
987     return HRGN_16( CreateEllipticRgn( rect->left, rect->top, rect->right, rect->bottom ) );
988 }
989
990
991 /***********************************************************************
992  *           CreateFont    (GDI.56)
993  */
994 HFONT16 WINAPI CreateFont16(INT16 height, INT16 width, INT16 esc, INT16 orient,
995                             INT16 weight, BYTE italic, BYTE underline,
996                             BYTE strikeout, BYTE charset, BYTE outpres,
997                             BYTE clippres, BYTE quality, BYTE pitch,
998                             LPCSTR name )
999 {
1000     return HFONT_16( CreateFontA( height, width, esc, orient, weight, italic, underline,
1001                                   strikeout, charset, outpres, clippres, quality, pitch, name ));
1002 }
1003
1004 /***********************************************************************
1005  *           CreateFontIndirect   (GDI.57)
1006  */
1007 HFONT16 WINAPI CreateFontIndirect16( const LOGFONT16 *plf16 )
1008 {
1009     HFONT ret;
1010
1011     if (plf16)
1012     {
1013         LOGFONTW lfW;
1014         logfont_16_to_W( plf16, &lfW );
1015         ret = CreateFontIndirectW( &lfW );
1016     }
1017     else ret = CreateFontIndirectW( NULL );
1018     return HFONT_16(ret);
1019 }
1020
1021
1022 /***********************************************************************
1023  *           CreateHatchBrush    (GDI.58)
1024  */
1025 HBRUSH16 WINAPI CreateHatchBrush16( INT16 style, COLORREF color )
1026 {
1027     return HBRUSH_16( CreateHatchBrush( style, color ) );
1028 }
1029
1030
1031 /***********************************************************************
1032  *           CreatePatternBrush    (GDI.60)
1033  */
1034 HBRUSH16 WINAPI CreatePatternBrush16( HBITMAP16 hbitmap )
1035 {
1036     return HBRUSH_16( CreatePatternBrush( HBITMAP_32(hbitmap) ));
1037 }
1038
1039
1040 /***********************************************************************
1041  *           CreatePen    (GDI.61)
1042  */
1043 HPEN16 WINAPI CreatePen16( INT16 style, INT16 width, COLORREF color )
1044 {
1045     LOGPEN logpen;
1046
1047     logpen.lopnStyle = style;
1048     logpen.lopnWidth.x = width;
1049     logpen.lopnWidth.y = 0;
1050     logpen.lopnColor = color;
1051     return HPEN_16( CreatePenIndirect( &logpen ) );
1052 }
1053
1054
1055 /***********************************************************************
1056  *           CreatePenIndirect    (GDI.62)
1057  */
1058 HPEN16 WINAPI CreatePenIndirect16( const LOGPEN16 * pen )
1059 {
1060     LOGPEN logpen;
1061
1062     if (pen->lopnStyle > PS_INSIDEFRAME) return 0;
1063     logpen.lopnStyle   = pen->lopnStyle;
1064     logpen.lopnWidth.x = pen->lopnWidth.x;
1065     logpen.lopnWidth.y = pen->lopnWidth.y;
1066     logpen.lopnColor   = pen->lopnColor;
1067     return HPEN_16( CreatePenIndirect( &logpen ) );
1068 }
1069
1070
1071 /***********************************************************************
1072  *           CreatePolygonRgn    (GDI.63)
1073  */
1074 HRGN16 WINAPI CreatePolygonRgn16( const POINT16 * points, INT16 count, INT16 mode )
1075 {
1076     return CreatePolyPolygonRgn16( points, &count, 1, mode );
1077 }
1078
1079
1080 /***********************************************************************
1081  *           CreateRectRgn    (GDI.64)
1082  *
1083  * NOTE: cf. SetRectRgn16
1084  */
1085 HRGN16 WINAPI CreateRectRgn16( INT16 left, INT16 top, INT16 right, INT16 bottom )
1086 {
1087     HRGN hrgn;
1088
1089     if (left < right) hrgn = CreateRectRgn( left, top, right, bottom );
1090     else hrgn = CreateRectRgn( 0, 0, 0, 0 );
1091     return HRGN_16(hrgn);
1092 }
1093
1094
1095 /***********************************************************************
1096  *           CreateRectRgnIndirect    (GDI.65)
1097  */
1098 HRGN16 WINAPI CreateRectRgnIndirect16( const RECT16* rect )
1099 {
1100     return CreateRectRgn16( rect->left, rect->top, rect->right, rect->bottom );
1101 }
1102
1103
1104 /***********************************************************************
1105  *           CreateSolidBrush    (GDI.66)
1106  */
1107 HBRUSH16 WINAPI CreateSolidBrush16( COLORREF color )
1108 {
1109     return HBRUSH_16( CreateSolidBrush( color ) );
1110 }
1111
1112
1113 /***********************************************************************
1114  *           DeleteDC    (GDI.68)
1115  */
1116 BOOL16 WINAPI DeleteDC16( HDC16 hdc )
1117 {
1118     return DeleteDC( HDC_32(hdc) );
1119 }
1120
1121
1122 /***********************************************************************
1123  *           DeleteObject    (GDI.69)
1124  *           SysDeleteObject (GDI.605)
1125  */
1126 BOOL16 WINAPI DeleteObject16( HGDIOBJ16 obj )
1127 {
1128     return DeleteObject( HGDIOBJ_32(obj) );
1129 }
1130
1131
1132 /***********************************************************************
1133  *           EnumFonts      (GDI.70)
1134  */
1135 INT16 WINAPI EnumFonts16( HDC16 hDC, LPCSTR lpName, FONTENUMPROC16 efproc,
1136                           LPARAM lpData )
1137 {
1138     return EnumFontFamilies16( hDC, lpName, efproc, lpData );
1139 }
1140
1141
1142 /***********************************************************************
1143  *           EnumObjects    (GDI.71)
1144  */
1145 INT16 WINAPI EnumObjects16( HDC16 hdc, INT16 obj, GOBJENUMPROC16 proc, LPARAM lParam )
1146 {
1147     struct callback16_info info;
1148
1149     info.proc  = (FARPROC16)proc;
1150     info.param = lParam;
1151     switch(obj)
1152     {
1153     case OBJ_PEN:
1154         return EnumObjects( HDC_32(hdc), OBJ_PEN, enum_pens_callback, (LPARAM)&info );
1155     case OBJ_BRUSH:
1156         return EnumObjects( HDC_32(hdc), OBJ_BRUSH, enum_brushes_callback, (LPARAM)&info );
1157     }
1158     return 0;
1159 }
1160
1161
1162 /***********************************************************************
1163  *           EqualRgn    (GDI.72)
1164  */
1165 BOOL16 WINAPI EqualRgn16( HRGN16 rgn1, HRGN16 rgn2 )
1166 {
1167     return EqualRgn( HRGN_32(rgn1), HRGN_32(rgn2) );
1168 }
1169
1170
1171 /***********************************************************************
1172  *           GetBitmapBits    (GDI.74)
1173  */
1174 LONG WINAPI GetBitmapBits16( HBITMAP16 hbitmap, LONG count, LPVOID buffer )
1175 {
1176     return GetBitmapBits( HBITMAP_32(hbitmap), count, buffer );
1177 }
1178
1179
1180 /***********************************************************************
1181  *              GetBkColor (GDI.75)
1182  */
1183 COLORREF WINAPI GetBkColor16( HDC16 hdc )
1184 {
1185     return GetBkColor( HDC_32(hdc) );
1186 }
1187
1188
1189 /***********************************************************************
1190  *              GetBkMode (GDI.76)
1191  */
1192 INT16 WINAPI GetBkMode16( HDC16 hdc )
1193 {
1194     return GetBkMode( HDC_32(hdc) );
1195 }
1196
1197
1198 /***********************************************************************
1199  *           GetClipBox    (GDI.77)
1200  */
1201 INT16 WINAPI GetClipBox16( HDC16 hdc, LPRECT16 rect )
1202 {
1203     RECT rect32;
1204     INT ret = GetClipBox( HDC_32(hdc), &rect32 );
1205
1206     if (ret != ERROR)
1207     {
1208         rect->left   = rect32.left;
1209         rect->top    = rect32.top;
1210         rect->right  = rect32.right;
1211         rect->bottom = rect32.bottom;
1212     }
1213     return ret;
1214 }
1215
1216
1217 /***********************************************************************
1218  *              GetCurrentPosition (GDI.78)
1219  */
1220 DWORD WINAPI GetCurrentPosition16( HDC16 hdc )
1221 {
1222     POINT pt32;
1223     if (!GetCurrentPositionEx( HDC_32(hdc), &pt32 )) return 0;
1224     return MAKELONG( pt32.x, pt32.y );
1225 }
1226
1227
1228 /***********************************************************************
1229  *           GetDCOrg    (GDI.79)
1230  */
1231 DWORD WINAPI GetDCOrg16( HDC16 hdc )
1232 {
1233     POINT pt;
1234     if (GetDCOrgEx( HDC_32(hdc), &pt )) return MAKELONG( pt.x, pt.y );
1235     return 0;
1236 }
1237
1238
1239 /***********************************************************************
1240  *           GetDeviceCaps    (GDI.80)
1241  */
1242 INT16 WINAPI GetDeviceCaps16( HDC16 hdc, INT16 cap )
1243 {
1244     INT16 ret = GetDeviceCaps( HDC_32(hdc), cap );
1245     /* some apps don't expect -1 and think it's a B&W screen */
1246     if ((cap == NUMCOLORS) && (ret == -1)) ret = 2048;
1247     return ret;
1248 }
1249
1250
1251 /***********************************************************************
1252  *              GetMapMode (GDI.81)
1253  */
1254 INT16 WINAPI GetMapMode16( HDC16 hdc )
1255 {
1256     return GetMapMode( HDC_32(hdc) );
1257 }
1258
1259
1260 /***********************************************************************
1261  *           GetObject    (GDI.82)
1262  */
1263 INT16 WINAPI GetObject16( HGDIOBJ16 handle16, INT16 count, LPVOID buffer )
1264 {
1265     HGDIOBJ handle = HGDIOBJ_32( handle16 );
1266     switch( GetObjectType( handle ))
1267     {
1268     case OBJ_PEN:
1269         if (buffer)
1270         {
1271             LOGPEN16 *pen16 = buffer;
1272             LOGPEN pen;
1273
1274             if (count < sizeof(LOGPEN16)) return 0;
1275             if (!GetObjectW( handle, sizeof(pen), &pen )) return 0;
1276
1277             pen16->lopnStyle   = pen.lopnStyle;
1278             pen16->lopnColor   = pen.lopnColor;
1279             pen16->lopnWidth.x = pen.lopnWidth.x;
1280             pen16->lopnWidth.y = pen.lopnWidth.y;
1281         }
1282         return sizeof(LOGPEN16);
1283
1284     case OBJ_BRUSH:
1285         if (buffer)
1286         {
1287             LOGBRUSH brush;
1288             LOGBRUSH16 brush16;
1289
1290             if (!GetObjectW( handle, sizeof(brush), &brush )) return 0;
1291             brush16.lbStyle = brush.lbStyle;
1292             brush16.lbColor = brush.lbColor;
1293             brush16.lbHatch = brush.lbHatch;
1294             if (count > sizeof(brush16)) count = sizeof(brush16);
1295             memcpy( buffer, &brush16, count );
1296             return count;
1297         }
1298         return sizeof(LOGBRUSH16);
1299
1300     case OBJ_PAL:
1301         return GetObjectW( handle, count, buffer );
1302
1303     case OBJ_FONT:
1304         if (buffer)
1305         {
1306             LOGFONTW font;
1307             LOGFONT16 font16;
1308
1309             if (!GetObjectW( handle, sizeof(font), &font )) return 0;
1310             logfont_W_to_16( &font, &font16 );
1311             if (count > sizeof(font16)) count = sizeof(font16);
1312             memcpy( buffer, &font16, count );
1313             return count;
1314         }
1315         return sizeof(LOGFONT16);
1316
1317     case OBJ_BITMAP:
1318         {
1319             DIBSECTION dib;
1320             INT size;
1321             BITMAP16 *bmp16 = buffer;
1322
1323             if (!(size = GetObjectW( handle, sizeof(dib), &dib ))) return 0;
1324             if (size == sizeof(DIBSECTION) && count > sizeof(BITMAP16))
1325             {
1326                 FIXME("not implemented for DIBs: count %d\n", count);
1327                 return 0;
1328             }
1329             else
1330             {
1331                 if (count < sizeof(BITMAP16)) return 0;
1332                 bmp16->bmType       = dib.dsBm.bmType;
1333                 bmp16->bmWidth      = dib.dsBm.bmWidth;
1334                 bmp16->bmHeight     = dib.dsBm.bmHeight;
1335                 bmp16->bmWidthBytes = dib.dsBm.bmWidthBytes;
1336                 bmp16->bmPlanes     = dib.dsBm.bmPlanes;
1337                 bmp16->bmBitsPixel  = dib.dsBm.bmBitsPixel;
1338                 bmp16->bmBits       = 0;
1339                 return sizeof(BITMAP16);
1340             }
1341         }
1342
1343     default:
1344         return 0;
1345     }
1346 }
1347
1348
1349 /***********************************************************************
1350  *           GetPixel    (GDI.83)
1351  */
1352 COLORREF WINAPI GetPixel16( HDC16 hdc, INT16 x, INT16 y )
1353 {
1354     return GetPixel( HDC_32(hdc), x, y );
1355 }
1356
1357
1358 /***********************************************************************
1359  *              GetPolyFillMode (GDI.84)
1360  */
1361 INT16 WINAPI GetPolyFillMode16( HDC16 hdc )
1362 {
1363     return GetPolyFillMode( HDC_32(hdc) );
1364 }
1365
1366
1367 /***********************************************************************
1368  *              GetROP2 (GDI.85)
1369  */
1370 INT16 WINAPI GetROP216( HDC16 hdc )
1371 {
1372     return GetROP2( HDC_32(hdc) );
1373 }
1374
1375
1376 /***********************************************************************
1377  *              GetRelAbs (GDI.86)
1378  */
1379 INT16 WINAPI GetRelAbs16( HDC16 hdc )
1380 {
1381     return GetRelAbs( HDC_32(hdc), 0 );
1382 }
1383
1384
1385 /***********************************************************************
1386  *           GetStockObject    (GDI.87)
1387  */
1388 HGDIOBJ16 WINAPI GetStockObject16( INT16 obj )
1389 {
1390     return HGDIOBJ_16( GetStockObject( obj ) );
1391 }
1392
1393
1394 /***********************************************************************
1395  *              GetStretchBltMode (GDI.88)
1396  */
1397 INT16 WINAPI GetStretchBltMode16( HDC16 hdc )
1398 {
1399     return GetStretchBltMode( HDC_32(hdc) );
1400 }
1401
1402
1403 /***********************************************************************
1404  *           GetTextCharacterExtra    (GDI.89)
1405  */
1406 INT16 WINAPI GetTextCharacterExtra16( HDC16 hdc )
1407 {
1408     return GetTextCharacterExtra( HDC_32(hdc) );
1409 }
1410
1411
1412 /***********************************************************************
1413  *              GetTextColor (GDI.90)
1414  */
1415 COLORREF WINAPI GetTextColor16( HDC16 hdc )
1416 {
1417     return GetTextColor( HDC_32(hdc) );
1418 }
1419
1420
1421 /***********************************************************************
1422  *           GetTextExtent    (GDI.91)
1423  */
1424 DWORD WINAPI GetTextExtent16( HDC16 hdc, LPCSTR str, INT16 count )
1425 {
1426     SIZE size;
1427     if (!GetTextExtentPoint32A( HDC_32(hdc), str, count, &size )) return 0;
1428     return MAKELONG( size.cx, size.cy );
1429 }
1430
1431
1432 /***********************************************************************
1433  *           GetTextFace    (GDI.92)
1434  */
1435 INT16 WINAPI GetTextFace16( HDC16 hdc, INT16 count, LPSTR name )
1436 {
1437     return GetTextFaceA( HDC_32(hdc), count, name );
1438 }
1439
1440
1441 /***********************************************************************
1442  *           GetTextMetrics    (GDI.93)
1443  */
1444 BOOL16 WINAPI GetTextMetrics16( HDC16 hdc, TEXTMETRIC16 *tm )
1445 {
1446     TEXTMETRICW tm32;
1447
1448     if (!GetTextMetricsW( HDC_32(hdc), &tm32 )) return FALSE;
1449
1450     tm->tmHeight           = tm32.tmHeight;
1451     tm->tmAscent           = tm32.tmAscent;
1452     tm->tmDescent          = tm32.tmDescent;
1453     tm->tmInternalLeading  = tm32.tmInternalLeading;
1454     tm->tmExternalLeading  = tm32.tmExternalLeading;
1455     tm->tmAveCharWidth     = tm32.tmAveCharWidth;
1456     tm->tmMaxCharWidth     = tm32.tmMaxCharWidth;
1457     tm->tmWeight           = tm32.tmWeight;
1458     tm->tmOverhang         = tm32.tmOverhang;
1459     tm->tmDigitizedAspectX = tm32.tmDigitizedAspectX;
1460     tm->tmDigitizedAspectY = tm32.tmDigitizedAspectY;
1461     tm->tmFirstChar        = tm32.tmFirstChar;
1462     tm->tmLastChar         = tm32.tmLastChar;
1463     tm->tmDefaultChar      = tm32.tmDefaultChar;
1464     tm->tmBreakChar        = tm32.tmBreakChar;
1465     tm->tmItalic           = tm32.tmItalic;
1466     tm->tmUnderlined       = tm32.tmUnderlined;
1467     tm->tmStruckOut        = tm32.tmStruckOut;
1468     tm->tmPitchAndFamily   = tm32.tmPitchAndFamily;
1469     tm->tmCharSet          = tm32.tmCharSet;
1470     return TRUE;
1471 }
1472
1473
1474 /***********************************************************************
1475  *              GetViewportExt (GDI.94)
1476  */
1477 DWORD WINAPI GetViewportExt16( HDC16 hdc )
1478 {
1479     SIZE size;
1480     if (!GetViewportExtEx( HDC_32(hdc), &size )) return 0;
1481     return MAKELONG( size.cx, size.cy );
1482 }
1483
1484
1485 /***********************************************************************
1486  *              GetViewportOrg (GDI.95)
1487  */
1488 DWORD WINAPI GetViewportOrg16( HDC16 hdc )
1489 {
1490     POINT pt;
1491     if (!GetViewportOrgEx( HDC_32(hdc), &pt )) return 0;
1492     return MAKELONG( pt.x, pt.y );
1493 }
1494
1495
1496 /***********************************************************************
1497  *              GetWindowExt (GDI.96)
1498  */
1499 DWORD WINAPI GetWindowExt16( HDC16 hdc )
1500 {
1501     SIZE size;
1502     if (!GetWindowExtEx( HDC_32(hdc), &size )) return 0;
1503     return MAKELONG( size.cx, size.cy );
1504 }
1505
1506
1507 /***********************************************************************
1508  *              GetWindowOrg (GDI.97)
1509  */
1510 DWORD WINAPI GetWindowOrg16( HDC16 hdc )
1511 {
1512     POINT pt;
1513     if (!GetWindowOrgEx( HDC_32(hdc), &pt )) return 0;
1514     return MAKELONG( pt.x, pt.y );
1515 }
1516
1517
1518
1519
1520 /**********************************************************************
1521  *           LineDDA   (GDI.100)
1522  */
1523 void WINAPI LineDDA16( INT16 nXStart, INT16 nYStart, INT16 nXEnd,
1524                        INT16 nYEnd, LINEDDAPROC16 proc, LPARAM lParam )
1525 {
1526     struct callback16_info info;
1527     info.proc  = (FARPROC16)proc;
1528     info.param = lParam;
1529     LineDDA( nXStart, nYStart, nXEnd, nYEnd, linedda_callback, (LPARAM)&info );
1530 }
1531
1532
1533 /***********************************************************************
1534  *           OffsetRgn    (GDI.101)
1535  */
1536 INT16 WINAPI OffsetRgn16( HRGN16 hrgn, INT16 x, INT16 y )
1537 {
1538     return OffsetRgn( HRGN_32(hrgn), x, y );
1539 }
1540
1541
1542 /***********************************************************************
1543  *           PtVisible    (GDI.103)
1544  */
1545 BOOL16 WINAPI PtVisible16( HDC16 hdc, INT16 x, INT16 y )
1546 {
1547     return PtVisible( HDC_32(hdc), x, y );
1548 }
1549
1550
1551 /***********************************************************************
1552  *           SelectVisRgn   (GDI.105)
1553  */
1554 INT16 WINAPI SelectVisRgn16( HDC16 hdc, HRGN16 hrgn )
1555 {
1556     return SelectVisRgn( HDC_32(hdc), HRGN_32(hrgn) );
1557 }
1558
1559
1560 /***********************************************************************
1561  *           SetBitmapBits    (GDI.106)
1562  */
1563 LONG WINAPI SetBitmapBits16( HBITMAP16 hbitmap, LONG count, LPCVOID buffer )
1564 {
1565     return SetBitmapBits( HBITMAP_32(hbitmap), count, buffer );
1566 }
1567
1568
1569 /***********************************************************************
1570  *           AddFontResource    (GDI.119)
1571  */
1572 INT16 WINAPI AddFontResource16( LPCSTR filename )
1573 {
1574     return AddFontResourceA( filename );
1575 }
1576
1577
1578 /***********************************************************************
1579  *           Death    (GDI.121)
1580  *
1581  * Disables GDI, switches back to text mode.
1582  * We don't have to do anything here,
1583  * just let console support handle everything
1584  */
1585 void WINAPI Death16(HDC16 hdc)
1586 {
1587     MESSAGE("Death(%04x) called. Application enters text mode...\n", hdc);
1588 }
1589
1590
1591 /***********************************************************************
1592  *           Resurrection    (GDI.122)
1593  *
1594  * Restores GDI functionality
1595  */
1596 void WINAPI Resurrection16(HDC16 hdc,
1597                            WORD w1, WORD w2, WORD w3, WORD w4, WORD w5, WORD w6)
1598 {
1599     MESSAGE("Resurrection(%04x, %04x, %04x, %04x, %04x, %04x, %04x) called. Application left text mode.\n",
1600             hdc, w1, w2, w3, w4, w5, w6);
1601 }
1602
1603
1604 /***********************************************************************
1605  *           MulDiv   (GDI.128)
1606  */
1607 INT16 WINAPI MulDiv16( INT16 nMultiplicand, INT16 nMultiplier, INT16 nDivisor)
1608 {
1609     INT ret;
1610     if (!nDivisor) return -32768;
1611     /* We want to deal with a positive divisor to simplify the logic. */
1612     if (nDivisor < 0)
1613     {
1614       nMultiplicand = - nMultiplicand;
1615       nDivisor = -nDivisor;
1616     }
1617     /* If the result is positive, we "add" to round. else,
1618      * we subtract to round. */
1619     if ( ( (nMultiplicand <  0) && (nMultiplier <  0) ) ||
1620          ( (nMultiplicand >= 0) && (nMultiplier >= 0) ) )
1621         ret = (((int)nMultiplicand * nMultiplier) + (nDivisor/2)) / nDivisor;
1622     else
1623         ret = (((int)nMultiplicand * nMultiplier) - (nDivisor/2)) / nDivisor;
1624     if ((ret > 32767) || (ret < -32767)) return -32768;
1625     return (INT16) ret;
1626 }
1627
1628
1629 /***********************************************************************
1630  *           GetRgnBox    (GDI.134)
1631  */
1632 INT16 WINAPI GetRgnBox16( HRGN16 hrgn, LPRECT16 rect )
1633 {
1634     RECT r;
1635     INT16 ret = GetRgnBox( HRGN_32(hrgn), &r );
1636     rect->left   = r.left;
1637     rect->top    = r.top;
1638     rect->right  = r.right;
1639     rect->bottom = r.bottom;
1640     return ret;
1641 }
1642
1643
1644 /***********************************************************************
1645  *           RemoveFontResource    (GDI.136)
1646  */
1647 BOOL16 WINAPI RemoveFontResource16( LPCSTR str )
1648 {
1649     return RemoveFontResourceA(str);
1650 }
1651
1652
1653 /***********************************************************************
1654  *           SetBrushOrg    (GDI.148)
1655  */
1656 DWORD WINAPI SetBrushOrg16( HDC16 hdc, INT16 x, INT16 y )
1657 {
1658     POINT pt;
1659
1660     if (!SetBrushOrgEx( HDC_32(hdc), x, y, &pt )) return 0;
1661     return MAKELONG( pt.x, pt.y );
1662 }
1663
1664
1665 /***********************************************************************
1666  *              GetBrushOrg (GDI.149)
1667  */
1668 DWORD WINAPI GetBrushOrg16( HDC16 hdc )
1669 {
1670     POINT pt;
1671     if (!GetBrushOrgEx( HDC_32(hdc), &pt )) return 0;
1672     return MAKELONG( pt.x, pt.y );
1673 }
1674
1675
1676 /***********************************************************************
1677  *           UnrealizeObject    (GDI.150)
1678  */
1679 BOOL16 WINAPI UnrealizeObject16( HGDIOBJ16 obj )
1680 {
1681     return UnrealizeObject( HGDIOBJ_32(obj) );
1682 }
1683
1684
1685 /***********************************************************************
1686  *           CreateIC    (GDI.153)
1687  */
1688 HDC16 WINAPI CreateIC16( LPCSTR driver, LPCSTR device, LPCSTR output,
1689                          const DEVMODEA* initData )
1690 {
1691     return HDC_16( CreateICA( driver, device, output, initData ) );
1692 }
1693
1694
1695 /***********************************************************************
1696  *           GetNearestColor   (GDI.154)
1697  */
1698 COLORREF WINAPI GetNearestColor16( HDC16 hdc, COLORREF color )
1699 {
1700     return GetNearestColor( HDC_32(hdc), color );
1701 }
1702
1703
1704 /***********************************************************************
1705  *           CreateDiscardableBitmap    (GDI.156)
1706  */
1707 HBITMAP16 WINAPI CreateDiscardableBitmap16( HDC16 hdc, INT16 width, INT16 height )
1708 {
1709     return HBITMAP_16( CreateDiscardableBitmap( HDC_32(hdc), width, height ) );
1710 }
1711
1712
1713 /***********************************************************************
1714  *           PtInRegion    (GDI.161)
1715  */
1716 BOOL16 WINAPI PtInRegion16( HRGN16 hrgn, INT16 x, INT16 y )
1717 {
1718     return PtInRegion( HRGN_32(hrgn), x, y );
1719 }
1720
1721
1722 /***********************************************************************
1723  *           GetBitmapDimension    (GDI.162)
1724  */
1725 DWORD WINAPI GetBitmapDimension16( HBITMAP16 hbitmap )
1726 {
1727     SIZE16 size;
1728     if (!GetBitmapDimensionEx16( hbitmap, &size )) return 0;
1729     return MAKELONG( size.cx, size.cy );
1730 }
1731
1732
1733 /***********************************************************************
1734  *           SetBitmapDimension    (GDI.163)
1735  */
1736 DWORD WINAPI SetBitmapDimension16( HBITMAP16 hbitmap, INT16 x, INT16 y )
1737 {
1738     SIZE16 size;
1739     if (!SetBitmapDimensionEx16( hbitmap, x, y, &size )) return 0;
1740     return MAKELONG( size.cx, size.cy );
1741 }
1742
1743
1744 /***********************************************************************
1745  *           SetRectRgn    (GDI.172)
1746  *
1747  * NOTE: Win 3.1 sets region to empty if left > right
1748  */
1749 void WINAPI SetRectRgn16( HRGN16 hrgn, INT16 left, INT16 top, INT16 right, INT16 bottom )
1750 {
1751     if (left < right) SetRectRgn( HRGN_32(hrgn), left, top, right, bottom );
1752     else SetRectRgn( HRGN_32(hrgn), 0, 0, 0, 0 );
1753 }
1754
1755
1756 /******************************************************************
1757  *             PlayMetaFileRecord   (GDI.176)
1758  */
1759 void WINAPI PlayMetaFileRecord16( HDC16 hdc, HANDLETABLE16 *ht, METARECORD *mr, UINT16 handles )
1760 {
1761     HANDLETABLE *ht32 = HeapAlloc( GetProcessHeap(), 0, handles * sizeof(*ht32) );
1762     unsigned int i;
1763
1764     for (i = 0; i < handles; i++) ht32->objectHandle[i] = HGDIOBJ_32(ht->objectHandle[i]);
1765     PlayMetaFileRecord( HDC_32(hdc), ht32, mr, handles );
1766     for (i = 0; i < handles; i++) ht->objectHandle[i] = HGDIOBJ_16(ht32->objectHandle[i]);
1767     HeapFree( GetProcessHeap(), 0, ht32 );
1768 }
1769
1770
1771 /***********************************************************************
1772  *           SetHookFlags   (GDI.192)
1773  */
1774 WORD WINAPI SetHookFlags16( HDC16 hdc, WORD flags )
1775 {
1776     return SetHookFlags( HDC_32(hdc), flags );
1777 }
1778
1779
1780 /***********************************************************************
1781  *           SetBoundsRect    (GDI.193)
1782  */
1783 UINT16 WINAPI SetBoundsRect16( HDC16 hdc, const RECT16* rect, UINT16 flags )
1784 {
1785     if (rect)
1786     {
1787         RECT rect32;
1788         rect32.left   = rect->left;
1789         rect32.top    = rect->top;
1790         rect32.right  = rect->right;
1791         rect32.bottom = rect->bottom;
1792         return SetBoundsRect( HDC_32( hdc ), &rect32, flags );
1793     }
1794     else return SetBoundsRect( HDC_32( hdc ), NULL, flags );
1795 }
1796
1797
1798 /***********************************************************************
1799  *           GetBoundsRect    (GDI.194)
1800  */
1801 UINT16 WINAPI GetBoundsRect16( HDC16 hdc, LPRECT16 rect, UINT16 flags)
1802 {
1803     RECT rect32;
1804     UINT ret = GetBoundsRect( HDC_32( hdc ), &rect32, flags );
1805     if (rect)
1806     {
1807         rect->left   = rect32.left;
1808         rect->top    = rect32.top;
1809         rect->right  = rect32.right;
1810         rect->bottom = rect32.bottom;
1811     }
1812     return ret;
1813 }
1814
1815
1816 /***********************************************************************
1817  *              EngineEnumerateFont (GDI.300)
1818  */
1819 WORD WINAPI EngineEnumerateFont16(LPSTR fontname, FARPROC16 proc, DWORD data )
1820 {
1821     FIXME("(%s,%p,%x),stub\n",fontname,proc,data);
1822     return 0;
1823 }
1824
1825
1826 /***********************************************************************
1827  *              EngineDeleteFont (GDI.301)
1828  */
1829 WORD WINAPI EngineDeleteFont16(LPFONTINFO16 lpFontInfo)
1830 {
1831     WORD handle;
1832
1833     /*  untested, don't know if it works.
1834         We seem to access some structure that is located after the
1835         FONTINFO. The FONTINFO documentation says that there may
1836         follow some char-width table or font bitmap or vector info.
1837         I think it is some kind of font bitmap that begins at offset 0x52,
1838         as FONTINFO goes up to 0x51.
1839         If this is correct, everything should be implemented correctly.
1840     */
1841     if ( ((lpFontInfo->dfType & (RASTER_FONTTYPE|DEVICE_FONTTYPE)) == (RASTER_FONTTYPE|DEVICE_FONTTYPE))
1842          && (LOWORD(lpFontInfo->dfFace) == LOWORD(lpFontInfo)+0x6e)
1843          && (handle = *(WORD *)(lpFontInfo+0x54)) )
1844     {
1845         *(WORD *)(lpFontInfo+0x54) = 0;
1846         GlobalFree16(handle);
1847     }
1848     return 1;
1849 }
1850
1851
1852 /***********************************************************************
1853  *              EngineRealizeFont (GDI.302)
1854  */
1855 WORD WINAPI EngineRealizeFont16(LPLOGFONT16 lplogFont, LPTEXTXFORM16 lptextxform, LPFONTINFO16 lpfontInfo)
1856 {
1857     FIXME("(%p,%p,%p),stub\n",lplogFont,lptextxform,lpfontInfo);
1858
1859     return 0;
1860 }
1861
1862
1863 /***********************************************************************
1864  *              EngineRealizeFontExt (GDI.315)
1865  */
1866 WORD WINAPI EngineRealizeFontExt16(LONG l1, LONG l2, LONG l3, LONG l4)
1867 {
1868     FIXME("(%08x,%08x,%08x,%08x),stub\n",l1,l2,l3,l4);
1869
1870     return 0;
1871 }
1872
1873
1874 /***********************************************************************
1875  *              EngineGetCharWidth (GDI.303)
1876  */
1877 WORD WINAPI EngineGetCharWidth16(LPFONTINFO16 lpFontInfo, BYTE firstChar, BYTE lastChar, LPINT16 buffer)
1878 {
1879     int i;
1880
1881     for (i = firstChar; i <= lastChar; i++)
1882        FIXME(" returns font's average width for range %d to %d\n", firstChar, lastChar);
1883     *buffer++ = lpFontInfo->dfAvgWidth; /* insert some charwidth functionality here; use average width for now */
1884     return 1;
1885 }
1886
1887
1888 /***********************************************************************
1889  *              EngineSetFontContext (GDI.304)
1890  */
1891 WORD WINAPI EngineSetFontContext16(LPFONTINFO16 lpFontInfo, WORD data)
1892 {
1893    FIXME("stub?\n");
1894    return 0;
1895 }
1896
1897 /***********************************************************************
1898  *              EngineGetGlyphBMP (GDI.305)
1899  */
1900 WORD WINAPI EngineGetGlyphBMP16(WORD word, LPFONTINFO16 lpFontInfo, WORD w1, WORD w2,
1901                               LPSTR string, DWORD dword, /*LPBITMAPMETRICS16*/ LPVOID metrics)
1902 {
1903     FIXME("stub?\n");
1904     return 0;
1905 }
1906
1907
1908 /***********************************************************************
1909  *              EngineMakeFontDir (GDI.306)
1910  */
1911 DWORD WINAPI EngineMakeFontDir16(HDC16 hdc, LPFONTDIR16 fontdir, LPCSTR string)
1912 {
1913     FIXME(" stub! (always fails)\n");
1914     return ~0UL; /* error */
1915 }
1916
1917
1918 /***********************************************************************
1919  *           GetCharABCWidths   (GDI.307)
1920  */
1921 BOOL16 WINAPI GetCharABCWidths16( HDC16 hdc, UINT16 firstChar, UINT16 lastChar, LPABC16 abc )
1922 {
1923     BOOL ret;
1924     UINT i;
1925     LPABC abc32 = HeapAlloc( GetProcessHeap(), 0, sizeof(ABC) * (lastChar - firstChar + 1) );
1926
1927     if ((ret = GetCharABCWidthsA( HDC_32(hdc), firstChar, lastChar, abc32 )))
1928     {
1929         for (i = firstChar; i <= lastChar; i++)
1930         {
1931             abc[i-firstChar].abcA = abc32[i-firstChar].abcA;
1932             abc[i-firstChar].abcB = abc32[i-firstChar].abcB;
1933             abc[i-firstChar].abcC = abc32[i-firstChar].abcC;
1934         }
1935     }
1936     HeapFree( GetProcessHeap(), 0, abc32 );
1937     return ret;
1938 }
1939
1940
1941 /***********************************************************************
1942  *           GetOutlineTextMetrics (GDI.308)
1943  *
1944  * Gets metrics for TrueType fonts.
1945  *
1946  * PARAMS
1947  *    hdc    [In]  Handle of device context
1948  *    cbData [In]  Size of metric data array
1949  *    lpOTM  [Out] Address of metric data array
1950  *
1951  * RETURNS
1952  *    Success: Non-zero or size of required buffer
1953  *    Failure: 0
1954  *
1955  * NOTES
1956  *    lpOTM should be LPOUTLINETEXTMETRIC
1957  */
1958 UINT16 WINAPI GetOutlineTextMetrics16( HDC16 hdc, UINT16 cbData,
1959                                        LPOUTLINETEXTMETRIC16 lpOTM )
1960 {
1961     FIXME("(%04x,%04x,%p): stub\n", hdc,cbData,lpOTM);
1962     return 0;
1963 }
1964
1965
1966 /***********************************************************************
1967  *           GetGlyphOutline    (GDI.309)
1968  */
1969 DWORD WINAPI GetGlyphOutline16( HDC16 hdc, UINT16 uChar, UINT16 fuFormat,
1970                                 LPGLYPHMETRICS16 lpgm, DWORD cbBuffer,
1971                                 LPVOID lpBuffer, const MAT2 *lpmat2 )
1972 {
1973     DWORD ret;
1974     GLYPHMETRICS gm32;
1975
1976     ret = GetGlyphOutlineA( HDC_32(hdc), uChar, fuFormat, &gm32, cbBuffer, lpBuffer, lpmat2);
1977     if (ret && ret != GDI_ERROR)
1978     {
1979         lpgm->gmBlackBoxX = gm32.gmBlackBoxX;
1980         lpgm->gmBlackBoxY = gm32.gmBlackBoxY;
1981         lpgm->gmptGlyphOrigin.x = gm32.gmptGlyphOrigin.x;
1982         lpgm->gmptGlyphOrigin.y = gm32.gmptGlyphOrigin.y;
1983         lpgm->gmCellIncX = gm32.gmCellIncX;
1984         lpgm->gmCellIncY = gm32.gmCellIncY;
1985     }
1986     return ret;
1987 }
1988
1989
1990 /***********************************************************************
1991  *           CreateScalableFontResource   (GDI.310)
1992  */
1993 BOOL16 WINAPI CreateScalableFontResource16( UINT16 fHidden, LPCSTR lpszResourceFile,
1994                                             LPCSTR fontFile, LPCSTR path )
1995 {
1996     return CreateScalableFontResourceA( fHidden, lpszResourceFile, fontFile, path );
1997 }
1998
1999
2000 /*************************************************************************
2001  *             GetFontData    (GDI.311)
2002  *
2003  */
2004 DWORD WINAPI GetFontData16( HDC16 hdc, DWORD table, DWORD offset, LPVOID buffer, DWORD count )
2005 {
2006     return GetFontData( HDC_32(hdc), table, offset, buffer, count );
2007 }
2008
2009
2010 /*************************************************************************
2011  *             GetRasterizerCaps   (GDI.313)
2012  */
2013 BOOL16 WINAPI GetRasterizerCaps16( LPRASTERIZER_STATUS lprs, UINT16 cbNumBytes )
2014 {
2015     return GetRasterizerCaps( lprs, cbNumBytes );
2016 }
2017
2018
2019 /***********************************************************************
2020  *             EnumFontFamilies    (GDI.330)
2021  */
2022 INT16 WINAPI EnumFontFamilies16( HDC16 hDC, LPCSTR lpFamily,
2023                                  FONTENUMPROC16 efproc, LPARAM lpData )
2024 {
2025     LOGFONT16 lf, *plf;
2026
2027     if (lpFamily)
2028     {
2029         if (!*lpFamily) return 1;
2030         lstrcpynA( lf.lfFaceName, lpFamily, LF_FACESIZE );
2031         lf.lfCharSet = DEFAULT_CHARSET;
2032         lf.lfPitchAndFamily = 0;
2033         plf = &lf;
2034     }
2035     else plf = NULL;
2036
2037     return EnumFontFamiliesEx16( hDC, plf, efproc, lpData, 0 );
2038 }
2039
2040
2041 /*************************************************************************
2042  *             GetKerningPairs   (GDI.332)
2043  *
2044  */
2045 INT16 WINAPI GetKerningPairs16( HDC16 hdc, INT16 count, LPKERNINGPAIR16 pairs )
2046 {
2047     KERNINGPAIR *pairs32;
2048     INT i, ret;
2049
2050     if (!count) return 0;
2051
2052     if (!(pairs32 = HeapAlloc( GetProcessHeap(), 0, count * sizeof(*pairs32) ))) return 0;
2053     if ((ret = GetKerningPairsA( HDC_32(hdc), count, pairs32 )))
2054     {
2055         for (i = 0; i < ret; i++)
2056         {
2057             pairs->wFirst      = pairs32->wFirst;
2058             pairs->wSecond     = pairs32->wSecond;
2059             pairs->iKernAmount = pairs32->iKernAmount;
2060         }
2061     }
2062     HeapFree( GetProcessHeap(), 0, pairs32 );
2063     return ret;
2064 }
2065
2066
2067
2068 /***********************************************************************
2069  *              GetTextAlign (GDI.345)
2070  */
2071 UINT16 WINAPI GetTextAlign16( HDC16 hdc )
2072 {
2073     return GetTextAlign( HDC_32(hdc) );
2074 }
2075
2076
2077 /***********************************************************************
2078  *           SetTextAlign    (GDI.346)
2079  */
2080 UINT16 WINAPI SetTextAlign16( HDC16 hdc, UINT16 align )
2081 {
2082     return SetTextAlign( HDC_32(hdc), align );
2083 }
2084
2085
2086 /***********************************************************************
2087  *           Chord    (GDI.348)
2088  */
2089 BOOL16 WINAPI Chord16( HDC16 hdc, INT16 left, INT16 top,
2090                        INT16 right, INT16 bottom, INT16 xstart, INT16 ystart,
2091                        INT16 xend, INT16 yend )
2092 {
2093     return Chord( HDC_32(hdc), left, top, right, bottom, xstart, ystart, xend, yend );
2094 }
2095
2096
2097 /***********************************************************************
2098  *           SetMapperFlags    (GDI.349)
2099  */
2100 DWORD WINAPI SetMapperFlags16( HDC16 hdc, DWORD flags )
2101 {
2102     return SetMapperFlags( HDC_32(hdc), flags );
2103 }
2104
2105
2106 /***********************************************************************
2107  *           GetCharWidth    (GDI.350)
2108  */
2109 BOOL16 WINAPI GetCharWidth16( HDC16 hdc, UINT16 firstChar, UINT16 lastChar, LPINT16 buffer )
2110 {
2111     BOOL retVal = FALSE;
2112
2113     if( firstChar != lastChar )
2114     {
2115         LPINT buf32 = HeapAlloc(GetProcessHeap(), 0, sizeof(INT)*(1 + (lastChar - firstChar)));
2116         if( buf32 )
2117         {
2118             LPINT obuf32 = buf32;
2119             int i;
2120
2121             retVal = GetCharWidth32A( HDC_32(hdc), firstChar, lastChar, buf32);
2122             if (retVal)
2123             {
2124                 for (i = firstChar; i <= lastChar; i++) *buffer++ = *buf32++;
2125             }
2126             HeapFree(GetProcessHeap(), 0, obuf32);
2127         }
2128     }
2129     else /* happens quite often to warrant a special treatment */
2130     {
2131         INT chWidth;
2132         retVal = GetCharWidth32A( HDC_32(hdc), firstChar, lastChar, &chWidth );
2133         *buffer = chWidth;
2134     }
2135     return retVal;
2136 }
2137
2138
2139 /***********************************************************************
2140  *           ExtTextOut   (GDI.351)
2141  */
2142 BOOL16 WINAPI ExtTextOut16( HDC16 hdc, INT16 x, INT16 y, UINT16 flags,
2143                             const RECT16 *lprect, LPCSTR str, UINT16 count,
2144                             const INT16 *lpDx )
2145 {
2146     BOOL        ret;
2147     int         i;
2148     RECT        rect32;
2149     LPINT       lpdx32 = NULL;
2150
2151     if (lpDx) {
2152         lpdx32 = HeapAlloc( GetProcessHeap(),0, sizeof(INT)*count );
2153         if(lpdx32 == NULL) return FALSE;
2154         for (i=count;i--;) lpdx32[i]=lpDx[i];
2155     }
2156     if (lprect)
2157     {
2158         rect32.left   = lprect->left;
2159         rect32.top    = lprect->top;
2160         rect32.right  = lprect->right;
2161         rect32.bottom = lprect->bottom;
2162     }
2163     ret = ExtTextOutA(HDC_32(hdc),x,y,flags,lprect?&rect32:NULL,str,count,lpdx32);
2164     HeapFree( GetProcessHeap(), 0, lpdx32 );
2165     return ret;
2166 }
2167
2168
2169 /***********************************************************************
2170  *           CreatePalette    (GDI.360)
2171  */
2172 HPALETTE16 WINAPI CreatePalette16( const LOGPALETTE* palette )
2173 {
2174     return HPALETTE_16( CreatePalette( palette ) );
2175 }
2176
2177
2178 /***********************************************************************
2179  *           GDISelectPalette   (GDI.361)
2180  */
2181 HPALETTE16 WINAPI GDISelectPalette16( HDC16 hdc, HPALETTE16 hpalette, WORD wBkg )
2182 {
2183     return HPALETTE_16( GDISelectPalette( HDC_32(hdc), HPALETTE_32(hpalette), wBkg ));
2184 }
2185
2186
2187 /***********************************************************************
2188  *           GDIRealizePalette   (GDI.362)
2189  */
2190 UINT16 WINAPI GDIRealizePalette16( HDC16 hdc )
2191 {
2192     return GDIRealizePalette( HDC_32(hdc) );
2193 }
2194
2195
2196 /***********************************************************************
2197  *           GetPaletteEntries    (GDI.363)
2198  */
2199 UINT16 WINAPI GetPaletteEntries16( HPALETTE16 hpalette, UINT16 start,
2200                                    UINT16 count, LPPALETTEENTRY entries )
2201 {
2202     return GetPaletteEntries( HPALETTE_32(hpalette), start, count, entries );
2203 }
2204
2205
2206 /***********************************************************************
2207  *           SetPaletteEntries    (GDI.364)
2208  */
2209 UINT16 WINAPI SetPaletteEntries16( HPALETTE16 hpalette, UINT16 start,
2210                                    UINT16 count, const PALETTEENTRY *entries )
2211 {
2212     return SetPaletteEntries( HPALETTE_32(hpalette), start, count, entries );
2213 }
2214
2215
2216 /**********************************************************************
2217  *            UpdateColors   (GDI.366)
2218  */
2219 INT16 WINAPI UpdateColors16( HDC16 hdc )
2220 {
2221     UpdateColors( HDC_32(hdc) );
2222     return TRUE;
2223 }
2224
2225
2226 /***********************************************************************
2227  *           AnimatePalette   (GDI.367)
2228  */
2229 void WINAPI AnimatePalette16( HPALETTE16 hpalette, UINT16 StartIndex,
2230                               UINT16 NumEntries, const PALETTEENTRY* PaletteColors)
2231 {
2232     AnimatePalette( HPALETTE_32(hpalette), StartIndex, NumEntries, PaletteColors );
2233 }
2234
2235
2236 /***********************************************************************
2237  *           ResizePalette   (GDI.368)
2238  */
2239 BOOL16 WINAPI ResizePalette16( HPALETTE16 hpalette, UINT16 cEntries )
2240 {
2241     return ResizePalette( HPALETTE_32(hpalette), cEntries );
2242 }
2243
2244
2245 /***********************************************************************
2246  *           GetNearestPaletteIndex   (GDI.370)
2247  */
2248 UINT16 WINAPI GetNearestPaletteIndex16( HPALETTE16 hpalette, COLORREF color )
2249 {
2250     return GetNearestPaletteIndex( HPALETTE_32(hpalette), color );
2251 }
2252
2253
2254 /**********************************************************************
2255  *          ExtFloodFill   (GDI.372)
2256  */
2257 BOOL16 WINAPI ExtFloodFill16( HDC16 hdc, INT16 x, INT16 y, COLORREF color,
2258                               UINT16 fillType )
2259 {
2260     return ExtFloodFill( HDC_32(hdc), x, y, color, fillType );
2261 }
2262
2263
2264 /***********************************************************************
2265  *           SetSystemPaletteUse   (GDI.373)
2266  */
2267 UINT16 WINAPI SetSystemPaletteUse16( HDC16 hdc, UINT16 use )
2268 {
2269     return SetSystemPaletteUse( HDC_32(hdc), use );
2270 }
2271
2272
2273 /***********************************************************************
2274  *           GetSystemPaletteUse   (GDI.374)
2275  */
2276 UINT16 WINAPI GetSystemPaletteUse16( HDC16 hdc )
2277 {
2278     return GetSystemPaletteUse( HDC_32(hdc) );
2279 }
2280
2281
2282 /***********************************************************************
2283  *           GetSystemPaletteEntries   (GDI.375)
2284  */
2285 UINT16 WINAPI GetSystemPaletteEntries16( HDC16 hdc, UINT16 start, UINT16 count,
2286                                          LPPALETTEENTRY entries )
2287 {
2288     return GetSystemPaletteEntries( HDC_32(hdc), start, count, entries );
2289 }
2290
2291
2292 /***********************************************************************
2293  *           ResetDC    (GDI.376)
2294  */
2295 HDC16 WINAPI ResetDC16( HDC16 hdc, const DEVMODEA *devmode )
2296 {
2297     return HDC_16( ResetDCA(HDC_32(hdc), devmode) );
2298 }
2299
2300
2301 /******************************************************************
2302  *           StartDoc   (GDI.377)
2303  */
2304 INT16 WINAPI StartDoc16( HDC16 hdc, const DOCINFO16 *lpdoc )
2305 {
2306     DOCINFOA docA;
2307
2308     docA.cbSize = lpdoc->cbSize;
2309     docA.lpszDocName = MapSL(lpdoc->lpszDocName);
2310     docA.lpszOutput = MapSL(lpdoc->lpszOutput);
2311     if(lpdoc->cbSize > offsetof(DOCINFO16,lpszDatatype))
2312         docA.lpszDatatype = MapSL(lpdoc->lpszDatatype);
2313     else
2314         docA.lpszDatatype = NULL;
2315     if(lpdoc->cbSize > offsetof(DOCINFO16,fwType))
2316         docA.fwType = lpdoc->fwType;
2317     else
2318         docA.fwType = 0;
2319     return StartDocA( HDC_32(hdc), &docA );
2320 }
2321
2322
2323 /******************************************************************
2324  *           EndDoc   (GDI.378)
2325  */
2326 INT16 WINAPI EndDoc16( HDC16 hdc )
2327 {
2328     return EndDoc( HDC_32(hdc) );
2329 }
2330
2331
2332 /******************************************************************
2333  *           StartPage   (GDI.379)
2334  */
2335 INT16 WINAPI StartPage16( HDC16 hdc )
2336 {
2337     return StartPage( HDC_32(hdc) );
2338 }
2339
2340
2341 /******************************************************************
2342  *           EndPage   (GDI.380)
2343  */
2344 INT16 WINAPI EndPage16( HDC16 hdc )
2345 {
2346     return EndPage( HDC_32(hdc) );
2347 }
2348
2349
2350 /******************************************************************************
2351  *           AbortDoc   (GDI.382)
2352  */
2353 INT16 WINAPI AbortDoc16( HDC16 hdc )
2354 {
2355     return AbortDoc( HDC_32(hdc) );
2356 }
2357
2358
2359 /***********************************************************************
2360  *           FastWindowFrame    (GDI.400)
2361  */
2362 BOOL16 WINAPI FastWindowFrame16( HDC16 hdc, const RECT16 *rect,
2363                                INT16 width, INT16 height, DWORD rop )
2364 {
2365     HDC hdc32 = HDC_32(hdc);
2366     HBRUSH hbrush = SelectObject( hdc32, GetStockObject( GRAY_BRUSH ) );
2367     PatBlt( hdc32, rect->left, rect->top,
2368             rect->right - rect->left - width, height, rop );
2369     PatBlt( hdc32, rect->left, rect->top + height, width,
2370             rect->bottom - rect->top - height, rop );
2371     PatBlt( hdc32, rect->left + width, rect->bottom - 1,
2372             rect->right - rect->left - width, -height, rop );
2373     PatBlt( hdc32, rect->right - 1, rect->top, -width,
2374             rect->bottom - rect->top - height, rop );
2375     SelectObject( hdc32, hbrush );
2376     return TRUE;
2377 }
2378
2379
2380 /***********************************************************************
2381  *           GdiInit2     (GDI.403)
2382  *
2383  * See "Undocumented Windows"
2384  *
2385  * PARAMS
2386  *   h1 [I] GDI object
2387  *   h2 [I] global data
2388  */
2389 HANDLE16 WINAPI GdiInit216( HANDLE16 h1, HANDLE16 h2 )
2390 {
2391     FIXME("(%04x, %04x), stub.\n", h1, h2);
2392     if (h2 == 0xffff) return 0xffff; /* undefined return value */
2393     return h1; /* FIXME: should be the memory handle of h1 */
2394 }
2395
2396
2397 /***********************************************************************
2398  *           FinalGdiInit     (GDI.405)
2399  */
2400 void WINAPI FinalGdiInit16( HBRUSH16 hPattern /* [in] fill pattern of desktop */ )
2401 {
2402 }
2403
2404
2405 /***********************************************************************
2406  *           CreateUserBitmap    (GDI.407)
2407  */
2408 HBITMAP16 WINAPI CreateUserBitmap16( INT16 width, INT16 height, UINT16 planes,
2409                                      UINT16 bpp, LPCVOID bits )
2410 {
2411     return CreateBitmap16( width, height, planes, bpp, bits );
2412 }
2413
2414
2415 /***********************************************************************
2416  *           CreateUserDiscardableBitmap    (GDI.409)
2417  */
2418 HBITMAP16 WINAPI CreateUserDiscardableBitmap16( WORD dummy, INT16 width, INT16 height )
2419 {
2420     HDC hdc = CreateDCA( "DISPLAY", NULL, NULL, NULL );
2421     HBITMAP ret = CreateCompatibleBitmap( hdc, width, height );
2422     DeleteDC( hdc );
2423     return HBITMAP_16(ret);
2424 }
2425
2426
2427 /***********************************************************************
2428  *              GetCurLogFont (GDI.411)
2429  */
2430 HFONT16 WINAPI GetCurLogFont16( HDC16 hdc )
2431 {
2432     return HFONT_16( GetCurrentObject( HDC_32(hdc), OBJ_FONT ) );
2433 }
2434
2435
2436 /***********************************************************************
2437  *           StretchDIBits   (GDI.439)
2438  */
2439 INT16 WINAPI StretchDIBits16( HDC16 hdc, INT16 xDst, INT16 yDst, INT16 widthDst,
2440                               INT16 heightDst, INT16 xSrc, INT16 ySrc, INT16 widthSrc,
2441                               INT16 heightSrc, const VOID *bits,
2442                               const BITMAPINFO *info, UINT16 wUsage, DWORD dwRop )
2443 {
2444     return StretchDIBits( HDC_32(hdc), xDst, yDst, widthDst, heightDst,
2445                           xSrc, ySrc, widthSrc, heightSrc, bits,
2446                           info, wUsage, dwRop );
2447 }
2448
2449
2450 /***********************************************************************
2451  *           SetDIBits    (GDI.440)
2452  */
2453 INT16 WINAPI SetDIBits16( HDC16 hdc, HBITMAP16 hbitmap, UINT16 startscan,
2454                           UINT16 lines, LPCVOID bits, const BITMAPINFO *info,
2455                           UINT16 coloruse )
2456 {
2457     return SetDIBits( HDC_32(hdc), HBITMAP_32(hbitmap), startscan, lines, bits, info, coloruse );
2458 }
2459
2460
2461 /***********************************************************************
2462  *           GetDIBits    (GDI.441)
2463  */
2464 INT16 WINAPI GetDIBits16( HDC16 hdc, HBITMAP16 hbitmap, UINT16 startscan,
2465                           UINT16 lines, LPVOID bits, BITMAPINFO * info,
2466                           UINT16 coloruse )
2467 {
2468     return GetDIBits( HDC_32(hdc), HBITMAP_32(hbitmap), startscan, lines, bits, info, coloruse );
2469 }
2470
2471
2472 /***********************************************************************
2473  *           CreateDIBitmap    (GDI.442)
2474  */
2475 HBITMAP16 WINAPI CreateDIBitmap16( HDC16 hdc, const BITMAPINFOHEADER * header,
2476                                    DWORD init, LPCVOID bits, const BITMAPINFO * data,
2477                                    UINT16 coloruse )
2478 {
2479     return HBITMAP_16( CreateDIBitmap( HDC_32(hdc), header, init, bits, data, coloruse ) );
2480 }
2481
2482
2483 /***********************************************************************
2484  *           SetDIBitsToDevice    (GDI.443)
2485  */
2486 INT16 WINAPI SetDIBitsToDevice16( HDC16 hdc, INT16 xDest, INT16 yDest, INT16 cx,
2487                                   INT16 cy, INT16 xSrc, INT16 ySrc, UINT16 startscan,
2488                                   UINT16 lines, LPCVOID bits, const BITMAPINFO *info,
2489                                   UINT16 coloruse )
2490 {
2491     return SetDIBitsToDevice( HDC_32(hdc), xDest, yDest, cx, cy, xSrc, ySrc,
2492                               startscan, lines, bits, info, coloruse );
2493 }
2494
2495
2496 /***********************************************************************
2497  *           CreateRoundRectRgn    (GDI.444)
2498  *
2499  * If either ellipse dimension is zero we call CreateRectRgn16 for its
2500  * `special' behaviour. -ve ellipse dimensions can result in GPFs under win3.1
2501  * we just let CreateRoundRectRgn convert them to +ve values.
2502  */
2503
2504 HRGN16 WINAPI CreateRoundRectRgn16( INT16 left, INT16 top, INT16 right, INT16 bottom,
2505                                     INT16 ellipse_width, INT16 ellipse_height )
2506 {
2507     if( ellipse_width == 0 || ellipse_height == 0 )
2508         return CreateRectRgn16( left, top, right, bottom );
2509     else
2510         return HRGN_16( CreateRoundRectRgn( left, top, right, bottom,
2511                                             ellipse_width, ellipse_height ));
2512 }
2513
2514
2515 /***********************************************************************
2516  *           CreateDIBPatternBrush    (GDI.445)
2517  */
2518 HBRUSH16 WINAPI CreateDIBPatternBrush16( HGLOBAL16 hbitmap, UINT16 coloruse )
2519 {
2520     BITMAPINFO *bmi;
2521     HBRUSH16 ret;
2522
2523     if (!(bmi = GlobalLock16( hbitmap ))) return 0;
2524     ret = HBRUSH_16( CreateDIBPatternBrushPt( bmi, coloruse ));
2525     GlobalUnlock16( hbitmap );
2526     return ret;
2527 }
2528
2529
2530 /**********************************************************************
2531  *          PolyPolygon (GDI.450)
2532  */
2533 BOOL16 WINAPI PolyPolygon16( HDC16 hdc, const POINT16* pt, const INT16* counts,
2534                              UINT16 polygons )
2535 {
2536     int         i,nrpts;
2537     LPPOINT     pt32;
2538     LPINT       counts32;
2539     BOOL16      ret;
2540
2541     nrpts=0;
2542     for (i=polygons;i--;)
2543         nrpts+=counts[i];
2544     pt32 = HeapAlloc( GetProcessHeap(), 0, sizeof(POINT)*nrpts);
2545     if(pt32 == NULL) return FALSE;
2546     for (i=nrpts;i--;)
2547     {
2548         pt32[i].x = pt[i].x;
2549         pt32[i].y = pt[i].y;
2550     }
2551     counts32 = HeapAlloc( GetProcessHeap(), 0, polygons*sizeof(INT) );
2552     if(counts32 == NULL) {
2553         HeapFree( GetProcessHeap(), 0, pt32 );
2554         return FALSE;
2555     }
2556     for (i=polygons;i--;) counts32[i]=counts[i];
2557
2558     ret = PolyPolygon(HDC_32(hdc),pt32,counts32,polygons);
2559     HeapFree( GetProcessHeap(), 0, counts32 );
2560     HeapFree( GetProcessHeap(), 0, pt32 );
2561     return ret;
2562 }
2563
2564
2565 /***********************************************************************
2566  *           CreatePolyPolygonRgn    (GDI.451)
2567  */
2568 HRGN16 WINAPI CreatePolyPolygonRgn16( const POINT16 *points,
2569                                       const INT16 *count, INT16 nbpolygons, INT16 mode )
2570 {
2571     HRGN hrgn;
2572     int i, npts = 0;
2573     INT *count32;
2574     POINT *points32;
2575
2576     for (i = 0; i < nbpolygons; i++) npts += count[i];
2577     points32 = HeapAlloc( GetProcessHeap(), 0, npts * sizeof(POINT) );
2578     for (i = 0; i < npts; i++)
2579     {
2580         points32[i].x = points[i].x;
2581         points32[i].y = points[i].y;
2582     }
2583
2584     count32 = HeapAlloc( GetProcessHeap(), 0, nbpolygons * sizeof(INT) );
2585     for (i = 0; i < nbpolygons; i++) count32[i] = count[i];
2586     hrgn = CreatePolyPolygonRgn( points32, count32, nbpolygons, mode );
2587     HeapFree( GetProcessHeap(), 0, count32 );
2588     HeapFree( GetProcessHeap(), 0, points32 );
2589     return HRGN_16(hrgn);
2590 }
2591
2592
2593 /***********************************************************************
2594  *           GdiSeeGdiDo   (GDI.452)
2595  */
2596 DWORD WINAPI GdiSeeGdiDo16( WORD wReqType, WORD wParam1, WORD wParam2,
2597                           WORD wParam3 )
2598 {
2599     DWORD ret = ~0U;
2600
2601     switch (wReqType)
2602     {
2603     case 0x0001:  /* LocalAlloc */
2604         WARN("LocalAlloc16(%x, %x): ignoring\n", wParam1, wParam3);
2605         ret = 0;
2606         break;
2607     case 0x0002:  /* LocalFree */
2608         WARN("LocalFree16(%x): ignoring\n", wParam1);
2609         ret = 0;
2610         break;
2611     case 0x0003:  /* LocalCompact */
2612         WARN("LocalCompact16(%x): ignoring\n", wParam3);
2613         ret = 65000; /* lie about the amount of free space */
2614         break;
2615     case 0x0103:  /* LocalHeap */
2616         WARN("LocalHeap16(): ignoring\n");
2617         break;
2618     default:
2619         WARN("(wReqType=%04x): Unknown\n", wReqType);
2620         break;
2621     }
2622     return ret;
2623 }
2624
2625
2626 /***********************************************************************
2627  *           SetObjectOwner    (GDI.461)
2628  */
2629 void WINAPI SetObjectOwner16( HGDIOBJ16 handle, HANDLE16 owner )
2630 {
2631     /* Nothing to do */
2632 }
2633
2634
2635 /***********************************************************************
2636  *           IsGDIObject    (GDI.462)
2637  *
2638  * returns type of object if valid (W95 system programming secrets p. 264-5)
2639  */
2640 BOOL16 WINAPI IsGDIObject16( HGDIOBJ16 handle16 )
2641 {
2642     static const BYTE type_map[] =
2643     {
2644         0,  /* bad */
2645         1,  /* OBJ_PEN */
2646         2,  /* OBJ_BRUSH */
2647         7,  /* OBJ_DC */
2648         9,  /* OBJ_METADC */
2649         4,  /* OBJ_PAL */
2650         3,  /* OBJ_FONT */
2651         5,  /* OBJ_BITMAP */
2652         6,  /* OBJ_REGION */
2653         10, /* OBJ_METAFILE */
2654         7,  /* OBJ_MEMDC */
2655         0,  /* OBJ_EXTPEN */
2656         9,  /* OBJ_ENHMETADC */
2657         12, /* OBJ_ENHMETAFILE */
2658         0   /* OBJ_COLORSPACE */
2659     };
2660
2661     UINT type = GetObjectType( HGDIOBJ_32( handle16 ));
2662
2663     if (type >= sizeof(type_map)/sizeof(type_map[0])) return 0;
2664     return type_map[type];
2665 }
2666
2667
2668 /***********************************************************************
2669  *           RectVisible    (GDI.465)
2670  *           RectVisibleOld (GDI.104)
2671  */
2672 BOOL16 WINAPI RectVisible16( HDC16 hdc, const RECT16* rect16 )
2673 {
2674     RECT rect;
2675
2676     rect.left   = rect16->left;
2677     rect.top    = rect16->top;
2678     rect.right  = rect16->right;
2679     rect.bottom = rect16->bottom;
2680     return RectVisible( HDC_32(hdc), &rect );
2681 }
2682
2683
2684 /***********************************************************************
2685  *           RectInRegion    (GDI.466)
2686  *           RectInRegionOld (GDI.181)
2687  */
2688 BOOL16 WINAPI RectInRegion16( HRGN16 hrgn, const RECT16 *rect )
2689 {
2690     RECT r32;
2691
2692     r32.left   = rect->left;
2693     r32.top    = rect->top;
2694     r32.right  = rect->right;
2695     r32.bottom = rect->bottom;
2696     return RectInRegion( HRGN_32(hrgn), &r32 );
2697 }
2698
2699
2700 /***********************************************************************
2701  *           GetBitmapDimensionEx    (GDI.468)
2702  */
2703 BOOL16 WINAPI GetBitmapDimensionEx16( HBITMAP16 hbitmap, LPSIZE16 size )
2704 {
2705     SIZE size32;
2706     BOOL ret = GetBitmapDimensionEx( HBITMAP_32(hbitmap), &size32 );
2707
2708     if (ret)
2709     {
2710         size->cx = size32.cx;
2711         size->cy = size32.cy;
2712     }
2713     return ret;
2714 }
2715
2716
2717 /***********************************************************************
2718  *              GetBrushOrgEx (GDI.469)
2719  */
2720 BOOL16 WINAPI GetBrushOrgEx16( HDC16 hdc, LPPOINT16 pt )
2721 {
2722     POINT pt32;
2723     if (!GetBrushOrgEx( HDC_32(hdc), &pt32 )) return FALSE;
2724     pt->x = pt32.x;
2725     pt->y = pt32.y;
2726     return TRUE;
2727 }
2728
2729
2730 /***********************************************************************
2731  *              GetCurrentPositionEx (GDI.470)
2732  */
2733 BOOL16 WINAPI GetCurrentPositionEx16( HDC16 hdc, LPPOINT16 pt )
2734 {
2735     POINT pt32;
2736     if (!GetCurrentPositionEx( HDC_32(hdc), &pt32 )) return FALSE;
2737     pt->x = pt32.x;
2738     pt->y = pt32.y;
2739     return TRUE;
2740 }
2741
2742
2743 /***********************************************************************
2744  *           GetTextExtentPoint    (GDI.471)
2745  *
2746  * FIXME: Should this have a bug for compatibility?
2747  * Original Windows versions of GetTextExtentPoint{A,W} have documented
2748  * bugs (-> MSDN KB q147647.txt).
2749  */
2750 BOOL16 WINAPI GetTextExtentPoint16( HDC16 hdc, LPCSTR str, INT16 count, LPSIZE16 size )
2751 {
2752     SIZE size32;
2753     BOOL ret = GetTextExtentPoint32A( HDC_32(hdc), str, count, &size32 );
2754
2755     if (ret)
2756     {
2757         size->cx = size32.cx;
2758         size->cy = size32.cy;
2759     }
2760     return ret;
2761 }
2762
2763
2764 /***********************************************************************
2765  *              GetViewportExtEx (GDI.472)
2766  */
2767 BOOL16 WINAPI GetViewportExtEx16( HDC16 hdc, LPSIZE16 size )
2768 {
2769     SIZE size32;
2770     if (!GetViewportExtEx( HDC_32(hdc), &size32 )) return FALSE;
2771     size->cx = size32.cx;
2772     size->cy = size32.cy;
2773     return TRUE;
2774 }
2775
2776
2777 /***********************************************************************
2778  *              GetViewportOrgEx (GDI.473)
2779  */
2780 BOOL16 WINAPI GetViewportOrgEx16( HDC16 hdc, LPPOINT16 pt )
2781 {
2782     POINT pt32;
2783     if (!GetViewportOrgEx( HDC_32(hdc), &pt32 )) return FALSE;
2784     pt->x = pt32.x;
2785     pt->y = pt32.y;
2786     return TRUE;
2787 }
2788
2789
2790 /***********************************************************************
2791  *              GetWindowExtEx (GDI.474)
2792  */
2793 BOOL16 WINAPI GetWindowExtEx16( HDC16 hdc, LPSIZE16 size )
2794 {
2795     SIZE size32;
2796     if (!GetWindowExtEx( HDC_32(hdc), &size32 )) return FALSE;
2797     size->cx = size32.cx;
2798     size->cy = size32.cy;
2799     return TRUE;
2800 }
2801
2802
2803 /***********************************************************************
2804  *              GetWindowOrgEx (GDI.475)
2805  */
2806 BOOL16 WINAPI GetWindowOrgEx16( HDC16 hdc, LPPOINT16 pt )
2807 {
2808     POINT pt32;
2809     if (!GetWindowOrgEx( HDC_32(hdc), &pt32 )) return FALSE;
2810     pt->x = pt32.x;
2811     pt->y = pt32.y;
2812     return TRUE;
2813 }
2814
2815
2816 /***********************************************************************
2817  *           OffsetViewportOrgEx    (GDI.476)
2818  */
2819 BOOL16 WINAPI OffsetViewportOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt)
2820 {
2821     POINT pt32;
2822     BOOL16 ret = OffsetViewportOrgEx( HDC_32(hdc), x, y, &pt32 );
2823     if (pt)
2824     {
2825         pt->x = pt32.x;
2826         pt->y = pt32.y;
2827     }
2828     return ret;
2829 }
2830
2831
2832 /***********************************************************************
2833  *           OffsetWindowOrgEx    (GDI.477)
2834  */
2835 BOOL16 WINAPI OffsetWindowOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt )
2836 {
2837     POINT pt32;
2838     BOOL16 ret = OffsetWindowOrgEx( HDC_32(hdc), x, y, &pt32 );
2839     if (pt)
2840     {
2841         pt->x = pt32.x;
2842         pt->y = pt32.y;
2843     }
2844     return ret;
2845 }
2846
2847
2848 /***********************************************************************
2849  *           SetBitmapDimensionEx    (GDI.478)
2850  */
2851 BOOL16 WINAPI SetBitmapDimensionEx16( HBITMAP16 hbitmap, INT16 x, INT16 y, LPSIZE16 prevSize )
2852 {
2853     SIZE size32;
2854     BOOL ret = SetBitmapDimensionEx( HBITMAP_32(hbitmap), x, y, &size32 );
2855
2856     if (ret && prevSize)
2857     {
2858         prevSize->cx = size32.cx;
2859         prevSize->cy = size32.cy;
2860     }
2861     return ret;
2862 }
2863
2864
2865 /***********************************************************************
2866  *           SetViewportExtEx    (GDI.479)
2867  */
2868 BOOL16 WINAPI SetViewportExtEx16( HDC16 hdc, INT16 x, INT16 y, LPSIZE16 size )
2869 {
2870     SIZE size32;
2871     BOOL16 ret = SetViewportExtEx( HDC_32(hdc), x, y, &size32 );
2872     if (size) { size->cx = size32.cx; size->cy = size32.cy; }
2873     return ret;
2874 }
2875
2876
2877 /***********************************************************************
2878  *           SetViewportOrgEx    (GDI.480)
2879  */
2880 BOOL16 WINAPI SetViewportOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt )
2881 {
2882     POINT pt32;
2883     BOOL16 ret = SetViewportOrgEx( HDC_32(hdc), x, y, &pt32 );
2884     if (pt)
2885     {
2886         pt->x = pt32.x;
2887         pt->y = pt32.y;
2888     }
2889     return ret;
2890 }
2891
2892
2893 /***********************************************************************
2894  *           SetWindowExtEx    (GDI.481)
2895  */
2896 BOOL16 WINAPI SetWindowExtEx16( HDC16 hdc, INT16 x, INT16 y, LPSIZE16 size )
2897 {
2898     SIZE size32;
2899     BOOL16 ret = SetWindowExtEx( HDC_32(hdc), x, y, &size32 );
2900     if (size) { size->cx = size32.cx; size->cy = size32.cy; }
2901     return ret;
2902 }
2903
2904
2905 /***********************************************************************
2906  *           SetWindowOrgEx    (GDI.482)
2907  */
2908 BOOL16 WINAPI SetWindowOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt )
2909 {
2910     POINT pt32;
2911     BOOL16 ret = SetWindowOrgEx( HDC_32(hdc), x, y, &pt32 );
2912     if (pt)
2913     {
2914         pt->x = pt32.x;
2915         pt->y = pt32.y;
2916     }
2917     return ret;
2918 }
2919
2920
2921 /***********************************************************************
2922  *           MoveToEx    (GDI.483)
2923  */
2924 BOOL16 WINAPI MoveToEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt )
2925 {
2926     POINT pt32;
2927
2928     if (!MoveToEx( HDC_32(hdc), x, y, &pt32 )) return FALSE;
2929     if (pt)
2930     {
2931         pt->x = pt32.x;
2932         pt->y = pt32.y;
2933     }
2934     return TRUE;
2935 }
2936
2937
2938 /***********************************************************************
2939  *           ScaleViewportExtEx    (GDI.484)
2940  */
2941 BOOL16 WINAPI ScaleViewportExtEx16( HDC16 hdc, INT16 xNum, INT16 xDenom,
2942                                     INT16 yNum, INT16 yDenom, LPSIZE16 size )
2943 {
2944     SIZE size32;
2945     BOOL16 ret = ScaleViewportExtEx( HDC_32(hdc), xNum, xDenom, yNum, yDenom,
2946                                        &size32 );
2947     if (size) { size->cx = size32.cx; size->cy = size32.cy; }
2948     return ret;
2949 }
2950
2951
2952 /***********************************************************************
2953  *           ScaleWindowExtEx    (GDI.485)
2954  */
2955 BOOL16 WINAPI ScaleWindowExtEx16( HDC16 hdc, INT16 xNum, INT16 xDenom,
2956                                   INT16 yNum, INT16 yDenom, LPSIZE16 size )
2957 {
2958     SIZE size32;
2959     BOOL16 ret = ScaleWindowExtEx( HDC_32(hdc), xNum, xDenom, yNum, yDenom,
2960                                      &size32 );
2961     if (size) { size->cx = size32.cx; size->cy = size32.cy; }
2962     return ret;
2963 }
2964
2965
2966 /***********************************************************************
2967  *           GetAspectRatioFilterEx  (GDI.486)
2968  */
2969 BOOL16 WINAPI GetAspectRatioFilterEx16( HDC16 hdc, LPSIZE16 pAspectRatio )
2970 {
2971     FIXME("(%04x, %p): -- Empty Stub !\n", hdc, pAspectRatio);
2972     return FALSE;
2973 }
2974
2975
2976 /******************************************************************************
2977  *           PolyBezier  (GDI.502)
2978  */
2979 BOOL16 WINAPI PolyBezier16( HDC16 hdc, const POINT16* lppt, INT16 cPoints )
2980 {
2981     int i;
2982     BOOL16 ret;
2983     LPPOINT pt32 = HeapAlloc( GetProcessHeap(), 0, cPoints*sizeof(POINT) );
2984     if(!pt32) return FALSE;
2985     for (i=cPoints;i--;)
2986     {
2987         pt32[i].x = lppt[i].x;
2988         pt32[i].y = lppt[i].y;
2989     }
2990     ret= PolyBezier(HDC_32(hdc), pt32, cPoints);
2991     HeapFree( GetProcessHeap(), 0, pt32 );
2992     return ret;
2993 }
2994
2995
2996 /******************************************************************************
2997  *           PolyBezierTo  (GDI.503)
2998  */
2999 BOOL16 WINAPI PolyBezierTo16( HDC16 hdc, const POINT16* lppt, INT16 cPoints )
3000 {
3001     int i;
3002     BOOL16 ret;
3003     LPPOINT pt32 = HeapAlloc( GetProcessHeap(), 0,
3004                                            cPoints*sizeof(POINT) );
3005     if(!pt32) return FALSE;
3006     for (i=cPoints;i--;)
3007     {
3008         pt32[i].x = lppt[i].x;
3009         pt32[i].y = lppt[i].y;
3010     }
3011     ret= PolyBezierTo(HDC_32(hdc), pt32, cPoints);
3012     HeapFree( GetProcessHeap(), 0, pt32 );
3013     return ret;
3014 }
3015
3016
3017 /******************************************************************************
3018  *           ExtSelectClipRgn   (GDI.508)
3019  */
3020 INT16 WINAPI ExtSelectClipRgn16( HDC16 hdc, HRGN16 hrgn, INT16 fnMode )
3021 {
3022   return ExtSelectClipRgn( HDC_32(hdc), HRGN_32(hrgn), fnMode);
3023 }
3024
3025
3026 /***********************************************************************
3027  *           AbortPath    (GDI.511)
3028  */
3029 BOOL16 WINAPI AbortPath16(HDC16 hdc)
3030 {
3031     return AbortPath( HDC_32(hdc) );
3032 }
3033
3034
3035 /***********************************************************************
3036  *           BeginPath    (GDI.512)
3037  */
3038 BOOL16 WINAPI BeginPath16(HDC16 hdc)
3039 {
3040     return BeginPath( HDC_32(hdc) );
3041 }
3042
3043
3044 /***********************************************************************
3045  *           CloseFigure    (GDI.513)
3046  */
3047 BOOL16 WINAPI CloseFigure16(HDC16 hdc)
3048 {
3049     return CloseFigure( HDC_32(hdc) );
3050 }
3051
3052
3053 /***********************************************************************
3054  *           EndPath    (GDI.514)
3055  */
3056 BOOL16 WINAPI EndPath16(HDC16 hdc)
3057 {
3058     return EndPath( HDC_32(hdc) );
3059 }
3060
3061
3062 /***********************************************************************
3063  *           FillPath    (GDI.515)
3064  */
3065 BOOL16 WINAPI FillPath16(HDC16 hdc)
3066 {
3067     return FillPath( HDC_32(hdc) );
3068 }
3069
3070
3071 /*******************************************************************
3072  *           FlattenPath    (GDI.516)
3073  */
3074 BOOL16 WINAPI FlattenPath16(HDC16 hdc)
3075 {
3076     return FlattenPath( HDC_32(hdc) );
3077 }
3078
3079
3080 /***********************************************************************
3081  *           GetPath    (GDI.517)
3082  */
3083 INT16 WINAPI GetPath16(HDC16 hdc, LPPOINT16 pPoints, LPBYTE pTypes, INT16 nSize)
3084 {
3085     FIXME("(%d,%p,%p): stub\n",hdc,pPoints,pTypes);
3086     return 0;
3087 }
3088
3089
3090 /***********************************************************************
3091  *           PathToRegion    (GDI.518)
3092  */
3093 HRGN16 WINAPI PathToRegion16(HDC16 hdc)
3094 {
3095     return HRGN_16( PathToRegion( HDC_32(hdc) ));
3096 }
3097
3098
3099 /***********************************************************************
3100  *           SelectClipPath    (GDI.519)
3101  */
3102 BOOL16 WINAPI SelectClipPath16(HDC16 hdc, INT16 iMode)
3103 {
3104     return SelectClipPath( HDC_32(hdc), iMode );
3105 }
3106
3107
3108 /*******************************************************************
3109  *           StrokeAndFillPath    (GDI.520)
3110  */
3111 BOOL16 WINAPI StrokeAndFillPath16(HDC16 hdc)
3112 {
3113     return StrokeAndFillPath( HDC_32(hdc) );
3114 }
3115
3116
3117 /*******************************************************************
3118  *           StrokePath    (GDI.521)
3119  */
3120 BOOL16 WINAPI StrokePath16(HDC16 hdc)
3121 {
3122     return StrokePath( HDC_32(hdc) );
3123 }
3124
3125
3126 /*******************************************************************
3127  *           WidenPath    (GDI.522)
3128  */
3129 BOOL16 WINAPI WidenPath16(HDC16 hdc)
3130 {
3131     return WidenPath( HDC_32(hdc) );
3132 }
3133
3134
3135 /***********************************************************************
3136  *              GetArcDirection (GDI.524)
3137  */
3138 INT16 WINAPI GetArcDirection16( HDC16 hdc )
3139 {
3140     return GetArcDirection( HDC_32(hdc) );
3141 }
3142
3143
3144 /***********************************************************************
3145  *           SetArcDirection    (GDI.525)
3146  */
3147 INT16 WINAPI SetArcDirection16( HDC16 hdc, INT16 nDirection )
3148 {
3149     return SetArcDirection( HDC_32(hdc), (INT)nDirection );
3150 }
3151
3152
3153 /***********************************************************************
3154  *           CreateHalftonePalette (GDI.529)
3155  */
3156 HPALETTE16 WINAPI CreateHalftonePalette16( HDC16 hdc )
3157 {
3158     return HPALETTE_16( CreateHalftonePalette( HDC_32(hdc) ));
3159 }
3160
3161
3162 /***********************************************************************
3163  *           SetDIBColorTable    (GDI.602)
3164  */
3165 UINT16 WINAPI SetDIBColorTable16( HDC16 hdc, UINT16 startpos, UINT16 entries, RGBQUAD *colors )
3166 {
3167     return SetDIBColorTable( HDC_32(hdc), startpos, entries, colors );
3168 }
3169
3170
3171 /***********************************************************************
3172  *           GetDIBColorTable    (GDI.603)
3173  */
3174 UINT16 WINAPI GetDIBColorTable16( HDC16 hdc, UINT16 startpos, UINT16 entries, RGBQUAD *colors )
3175 {
3176     return GetDIBColorTable( HDC_32(hdc), startpos, entries, colors );
3177 }
3178
3179
3180 /***********************************************************************
3181  *           GetRegionData   (GDI.607)
3182  *
3183  * FIXME: is LPRGNDATA the same in Win16 and Win32 ?
3184  */
3185 DWORD WINAPI GetRegionData16( HRGN16 hrgn, DWORD count, LPRGNDATA rgndata )
3186 {
3187     return GetRegionData( HRGN_32(hrgn), count, rgndata );
3188 }
3189
3190
3191 /***********************************************************************
3192  *           GdiFreeResources   (GDI.609)
3193  */
3194 WORD WINAPI GdiFreeResources16( DWORD reserve )
3195 {
3196     return 90; /* lie about it, it shouldn't matter */
3197 }
3198
3199
3200 /***********************************************************************
3201  *           GdiSignalProc32     (GDI.610)
3202  */
3203 WORD WINAPI GdiSignalProc( UINT uCode, DWORD dwThreadOrProcessID,
3204                            DWORD dwFlags, HMODULE16 hModule )
3205 {
3206     return 0;
3207 }
3208
3209
3210 /***********************************************************************
3211  *           GetTextCharset   (GDI.612)
3212  */
3213 UINT16 WINAPI GetTextCharset16( HDC16 hdc )
3214 {
3215     return GetTextCharset( HDC_32(hdc) );
3216 }
3217
3218
3219 /***********************************************************************
3220  *           EnumFontFamiliesEx (GDI.613)
3221  */
3222 INT16 WINAPI EnumFontFamiliesEx16( HDC16 hdc, LPLOGFONT16 plf,
3223                                    FONTENUMPROC16 proc, LPARAM lParam,
3224                                    DWORD dwFlags)
3225 {
3226     struct callback16_info info;
3227     LOGFONTW lfW, *plfW;
3228
3229     info.proc  = (FARPROC16)proc;
3230     info.param = lParam;
3231
3232     if (plf)
3233     {
3234         logfont_16_to_W(plf, &lfW);
3235         plfW = &lfW;
3236     }
3237     else plfW = NULL;
3238
3239     return EnumFontFamiliesExW( HDC_32(hdc), plfW, enum_font_callback,
3240                                 (LPARAM)&info, dwFlags );
3241 }
3242
3243
3244 /*************************************************************************
3245  *             GetFontLanguageInfo   (GDI.616)
3246  */
3247 DWORD WINAPI GetFontLanguageInfo16( HDC16 hdc )
3248 {
3249     return GetFontLanguageInfo( HDC_32(hdc) );
3250 }
3251
3252
3253 /***********************************************************************
3254  *           SetLayout   (GDI.1000)
3255  *
3256  * Sets left->right or right->left text layout flags of a dc.
3257  */
3258 BOOL16 WINAPI SetLayout16( HDC16 hdc, DWORD layout )
3259 {
3260     return SetLayout( HDC_32(hdc), layout );
3261 }
3262
3263
3264 /***********************************************************************
3265  *           SetSolidBrush   (GDI.604)
3266  *
3267  * Change the color of a solid brush.
3268  *
3269  * PARAMS
3270  *  hBrush   [I] Brush to change the color of
3271  *  newColor [I] New color for hBrush
3272  *
3273  * RETURNS
3274  *  Success: TRUE. The color of hBrush is set to newColor.
3275  *  Failure: FALSE.
3276  *
3277  * FIXME
3278  *  This function is undocumented and untested. The implementation may
3279  *  not be correct.
3280  */
3281 BOOL16 WINAPI SetSolidBrush16(HBRUSH16 hBrush, COLORREF newColor )
3282 {
3283     TRACE("(hBrush %04x, newColor %08x)\n", hBrush, newColor);
3284
3285     return BRUSH_SetSolid( HBRUSH_32(hBrush), newColor );
3286 }
3287
3288
3289 /***********************************************************************
3290  *           Copy   (GDI.250)
3291  */
3292 void WINAPI Copy16( LPVOID src, LPVOID dst, WORD size )
3293 {
3294     memcpy( dst, src, size );
3295 }
3296
3297 /***********************************************************************
3298  *           RealizeDefaultPalette    (GDI.365)
3299  */
3300 UINT16 WINAPI RealizeDefaultPalette16( HDC16 hdc )
3301 {
3302     UINT16 ret = 0;
3303     DC          *dc;
3304
3305     TRACE("%04x\n", hdc );
3306
3307     if (!(dc = get_dc_ptr( HDC_32(hdc) ))) return 0;
3308
3309     if (dc->funcs->pRealizeDefaultPalette) ret = dc->funcs->pRealizeDefaultPalette( dc->physDev );
3310     release_dc_ptr( dc );
3311     return ret;
3312 }
3313
3314 /***********************************************************************
3315  *           IsDCCurrentPalette   (GDI.412)
3316  */
3317 BOOL16 WINAPI IsDCCurrentPalette16(HDC16 hDC)
3318 {
3319     DC *dc = get_dc_ptr( HDC_32(hDC) );
3320     if (dc)
3321     {
3322       BOOL bRet = dc->hPalette == hPrimaryPalette;
3323       release_dc_ptr( dc );
3324       return bRet;
3325     }
3326     return FALSE;
3327 }
3328
3329 /*********************************************************************
3330  *           SetMagicColors   (GDI.606)
3331  */
3332 VOID WINAPI SetMagicColors16(HDC16 hDC, COLORREF color, UINT16 index)
3333 {
3334     FIXME("(hDC %04x, color %04x, index %04x): stub\n", hDC, (int)color, index);
3335
3336 }
3337
3338
3339 /***********************************************************************
3340  *           DPtoLP    (GDI.67)
3341  */
3342 BOOL16 WINAPI DPtoLP16( HDC16 hdc, LPPOINT16 points, INT16 count )
3343 {
3344     DC * dc = get_dc_ptr( HDC_32(hdc) );
3345     if (!dc) return FALSE;
3346
3347     while (count--)
3348     {
3349         points->x = MulDiv( points->x - dc->vportOrgX, dc->wndExtX, dc->vportExtX ) + dc->wndOrgX;
3350         points->y = MulDiv( points->y - dc->vportOrgY, dc->wndExtY, dc->vportExtY ) + dc->wndOrgY;
3351         points++;
3352     }
3353     release_dc_ptr( dc );
3354     return TRUE;
3355 }
3356
3357
3358 /***********************************************************************
3359  *           LPtoDP    (GDI.99)
3360  */
3361 BOOL16 WINAPI LPtoDP16( HDC16 hdc, LPPOINT16 points, INT16 count )
3362 {
3363     DC * dc = get_dc_ptr( HDC_32(hdc) );
3364     if (!dc) return FALSE;
3365
3366     while (count--)
3367     {
3368         points->x = MulDiv( points->x - dc->wndOrgX, dc->vportExtX, dc->wndExtX ) + dc->vportOrgX;
3369         points->y = MulDiv( points->y - dc->wndOrgY, dc->vportExtY, dc->wndExtY ) + dc->vportOrgY;
3370         points++;
3371     }
3372     release_dc_ptr( dc );
3373     return TRUE;
3374 }
3375
3376
3377 /***********************************************************************
3378  *           GetDCState   (GDI.179)
3379  */
3380 HDC16 WINAPI GetDCState16( HDC16 hdc )
3381 {
3382     ERR( "no longer supported\n" );
3383     return 0;
3384 }
3385
3386
3387 /***********************************************************************
3388  *           SetDCState   (GDI.180)
3389  */
3390 void WINAPI SetDCState16( HDC16 hdc, HDC16 hdcs )
3391 {
3392     ERR( "no longer supported\n" );
3393 }
3394
3395 /***********************************************************************
3396  *           SetDCOrg   (GDI.117)
3397  */
3398 DWORD WINAPI SetDCOrg16( HDC16 hdc16, INT16 x, INT16 y )
3399 {
3400     DWORD prevOrg = 0;
3401     HDC hdc = HDC_32( hdc16 );
3402     DC *dc = get_dc_ptr( hdc );
3403     if (!dc) return 0;
3404     if (dc->funcs->pSetDCOrg) prevOrg = dc->funcs->pSetDCOrg( dc->physDev, x, y );
3405     release_dc_ptr( dc );
3406     return prevOrg;
3407 }
3408
3409
3410 /***********************************************************************
3411  *              InquireVisRgn   (GDI.131)
3412  */
3413 HRGN16 WINAPI InquireVisRgn16( HDC16 hdc )
3414 {
3415     HRGN16 ret = 0;
3416     DC * dc = get_dc_ptr( HDC_32(hdc) );
3417     if (dc)
3418     {
3419         ret = HRGN_16(dc->hVisRgn);
3420         release_dc_ptr( dc );
3421     }
3422     return ret;
3423 }
3424
3425
3426 /***********************************************************************
3427  *           OffsetVisRgn    (GDI.102)
3428  */
3429 INT16 WINAPI OffsetVisRgn16( HDC16 hdc16, INT16 x, INT16 y )
3430 {
3431     INT16 retval;
3432     HDC hdc = HDC_32( hdc16 );
3433     DC * dc = get_dc_ptr( hdc );
3434
3435     if (!dc) return ERROR;
3436     TRACE("%p %d,%d\n", hdc, x, y );
3437     update_dc( dc );
3438     retval = OffsetRgn( dc->hVisRgn, x, y );
3439     CLIPPING_UpdateGCRegion( dc );
3440     release_dc_ptr( dc );
3441     return retval;
3442 }
3443
3444
3445 /***********************************************************************
3446  *           ExcludeVisRect   (GDI.73)
3447  */
3448 INT16 WINAPI ExcludeVisRect16( HDC16 hdc16, INT16 left, INT16 top, INT16 right, INT16 bottom )
3449 {
3450     HRGN tempRgn;
3451     INT16 ret;
3452     POINT pt[2];
3453     HDC hdc = HDC_32( hdc16 );
3454     DC * dc = get_dc_ptr( hdc );
3455     if (!dc) return ERROR;
3456
3457     pt[0].x = left;
3458     pt[0].y = top;
3459     pt[1].x = right;
3460     pt[1].y = bottom;
3461
3462     LPtoDP( hdc, pt, 2 );
3463
3464     TRACE("%p %d,%d - %d,%d\n", hdc, pt[0].x, pt[0].y, pt[1].x, pt[1].y);
3465
3466     if (!(tempRgn = CreateRectRgn( pt[0].x, pt[0].y, pt[1].x, pt[1].y ))) ret = ERROR;
3467     else
3468     {
3469         update_dc( dc );
3470         ret = CombineRgn( dc->hVisRgn, dc->hVisRgn, tempRgn, RGN_DIFF );
3471         DeleteObject( tempRgn );
3472     }
3473     if (ret != ERROR) CLIPPING_UpdateGCRegion( dc );
3474     release_dc_ptr( dc );
3475     return ret;
3476 }
3477
3478
3479 /***********************************************************************
3480  *           IntersectVisRect   (GDI.98)
3481  */
3482 INT16 WINAPI IntersectVisRect16( HDC16 hdc16, INT16 left, INT16 top, INT16 right, INT16 bottom )
3483 {
3484     HRGN tempRgn;
3485     INT16 ret;
3486     POINT pt[2];
3487     HDC hdc = HDC_32( hdc16 );
3488     DC * dc = get_dc_ptr( hdc );
3489     if (!dc) return ERROR;
3490
3491     pt[0].x = left;
3492     pt[0].y = top;
3493     pt[1].x = right;
3494     pt[1].y = bottom;
3495
3496     LPtoDP( hdc, pt, 2 );
3497
3498     TRACE("%p %d,%d - %d,%d\n", hdc, pt[0].x, pt[0].y, pt[1].x, pt[1].y);
3499
3500     if (!(tempRgn = CreateRectRgn( pt[0].x, pt[0].y, pt[1].x, pt[1].y ))) ret = ERROR;
3501     else
3502     {
3503         update_dc( dc );
3504         ret = CombineRgn( dc->hVisRgn, dc->hVisRgn, tempRgn, RGN_AND );
3505         DeleteObject( tempRgn );
3506     }
3507     if (ret != ERROR) CLIPPING_UpdateGCRegion( dc );
3508     release_dc_ptr( dc );
3509     return ret;
3510 }
3511
3512
3513 /***********************************************************************
3514  *           SaveVisRgn   (GDI.129)
3515  */
3516 HRGN16 WINAPI SaveVisRgn16( HDC16 hdc16 )
3517 {
3518     struct saved_visrgn *saved;
3519     HDC hdc = HDC_32( hdc16 );
3520     DC *dc = get_dc_ptr( hdc );
3521
3522     if (!dc) return 0;
3523     TRACE("%p\n", hdc );
3524
3525     update_dc( dc );
3526     if (!(saved = HeapAlloc( GetProcessHeap(), 0, sizeof(*saved) ))) goto error;
3527     if (!(saved->hrgn = CreateRectRgn( 0, 0, 0, 0 ))) goto error;
3528     CombineRgn( saved->hrgn, dc->hVisRgn, 0, RGN_COPY );
3529     saved->next = dc->saved_visrgn;
3530     dc->saved_visrgn = saved;
3531     release_dc_ptr( dc );
3532     return HRGN_16(saved->hrgn);
3533
3534 error:
3535     release_dc_ptr( dc );
3536     HeapFree( GetProcessHeap(), 0, saved );
3537     return 0;
3538 }
3539
3540
3541 /***********************************************************************
3542  *           RestoreVisRgn   (GDI.130)
3543  */
3544 INT16 WINAPI RestoreVisRgn16( HDC16 hdc16 )
3545 {
3546     struct saved_visrgn *saved;
3547     HDC hdc = HDC_32( hdc16 );
3548     DC *dc = get_dc_ptr( hdc );
3549     INT16 ret = ERROR;
3550
3551     if (!dc) return ERROR;
3552
3553     TRACE("%p\n", hdc );
3554
3555     if (!(saved = dc->saved_visrgn)) goto done;
3556
3557     ret = CombineRgn( dc->hVisRgn, saved->hrgn, 0, RGN_COPY );
3558     dc->saved_visrgn = saved->next;
3559     DeleteObject( saved->hrgn );
3560     HeapFree( GetProcessHeap(), 0, saved );
3561     CLIPPING_UpdateGCRegion( dc );
3562  done:
3563     release_dc_ptr( dc );
3564     return ret;
3565 }
3566
3567
3568 /***********************************************************************
3569  *              GetClipRgn (GDI.173)
3570  */
3571 HRGN16 WINAPI GetClipRgn16( HDC16 hdc )
3572 {
3573     HRGN16 ret = 0;
3574     DC * dc = get_dc_ptr( HDC_32(hdc) );
3575     if (dc)
3576     {
3577         ret = HRGN_16(dc->hClipRgn);
3578         release_dc_ptr( dc );
3579     }
3580     return ret;
3581 }
3582
3583
3584 /***********************************************************************
3585  *           MakeObjectPrivate    (GDI.463)
3586  *
3587  * What does that mean ?
3588  * Some little docu can be found in "Undocumented Windows",
3589  * but this is basically useless.
3590  */
3591 void WINAPI MakeObjectPrivate16( HGDIOBJ16 handle16, BOOL16 private )
3592 {
3593     FIXME( "stub: %x %u\n", handle16, private );
3594 }
3595
3596 /***********************************************************************
3597  *           CreateDIBSection    (GDI.489)
3598  */
3599 HBITMAP16 WINAPI CreateDIBSection16 (HDC16 hdc, const BITMAPINFO *bmi, UINT16 usage,
3600                                      SEGPTR *bits16, HANDLE section, DWORD offset)
3601 {
3602     LPVOID bits32;
3603     HBITMAP hbitmap;
3604
3605     hbitmap = CreateDIBSection( HDC_32(hdc), bmi, usage, &bits32, section, offset );
3606     if (hbitmap)
3607     {
3608         BITMAPOBJ *bmp = GDI_GetObjPtr(hbitmap, OBJ_BITMAP);
3609         if (bmp && bmp->dib && bits32)
3610         {
3611             const BITMAPINFOHEADER *bi = &bmi->bmiHeader;
3612             LONG width, height;
3613             WORD planes, bpp;
3614             DWORD compr, size;
3615             INT width_bytes;
3616             WORD count, sel;
3617             int i;
3618
3619             DIB_GetBitmapInfo(bi, &width, &height, &planes, &bpp, &compr, &size);
3620
3621             height = height >= 0 ? height : -height;
3622             width_bytes = DIB_GetDIBWidthBytes(width, bpp);
3623
3624             if (!size || (compr != BI_RLE4 && compr != BI_RLE8)) size = width_bytes * height;
3625
3626             /* calculate number of sel's needed for size with 64K steps */
3627             count = (size + 0xffff) / 0x10000;
3628             sel = AllocSelectorArray16(count);
3629
3630             for (i = 0; i < count; i++)
3631             {
3632                 SetSelectorBase(sel + (i << __AHSHIFT), (DWORD)bits32 + i * 0x10000);
3633                 SetSelectorLimit16(sel + (i << __AHSHIFT), size - 1); /* yep, limit is correct */
3634                 size -= 0x10000;
3635             }
3636             bmp->segptr_bits = MAKESEGPTR( sel, 0 );
3637             if (bits16) *bits16 = bmp->segptr_bits;
3638         }
3639         if (bmp) GDI_ReleaseObj( hbitmap );
3640     }
3641     return HBITMAP_16(hbitmap);
3642 }