Correct return value in a couple of error cases.
[wine] / dlls / gdi / 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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.h"
29 #include "gdi_private.h"
30 #include "wine/debug.h"
31
32 WINE_DEFAULT_DEBUG_CHANNEL(gdi);
33
34 #define HGDIOBJ_32(handle16)    ((HGDIOBJ)(ULONG_PTR)(handle16))
35 #define HGDIOBJ_16(handle32)    ((HGDIOBJ16)(ULONG_PTR)(handle32))
36
37 struct callback16_info
38 {
39     FARPROC16 proc;
40     LPARAM    param;
41 };
42
43 /* callback for LineDDA16 */
44 static void CALLBACK linedda_callback( INT x, INT y, LPARAM param )
45 {
46     const struct callback16_info *info = (struct callback16_info *)param;
47     WORD args[4];
48
49     args[3] = x;
50     args[2] = y;
51     args[1] = HIWORD(info->param);
52     args[0] = LOWORD(info->param);
53     WOWCallback16Ex( (DWORD)info->proc, WCB16_PASCAL, sizeof(args), args, NULL );
54 }
55
56 /* callback for EnumObjects16 */
57 static INT CALLBACK enum_pens_callback( void *ptr, LPARAM param )
58 {
59     const struct callback16_info *info = (struct callback16_info *)param;
60     LOGPEN *pen = ptr;
61     LOGPEN16 pen16;
62     SEGPTR segptr;
63     DWORD ret;
64     WORD args[4];
65
66     pen16.lopnStyle   = pen->lopnStyle;
67     pen16.lopnWidth.x = pen->lopnWidth.x;
68     pen16.lopnWidth.y = pen->lopnWidth.y;
69     pen16.lopnColor   = pen->lopnColor;
70     segptr = MapLS( &pen16 );
71     args[3] = SELECTOROF(segptr);
72     args[2] = OFFSETOF(segptr);
73     args[1] = HIWORD(info->param);
74     args[0] = LOWORD(info->param);
75     WOWCallback16Ex( (DWORD)info->proc, WCB16_PASCAL, sizeof(args), args, &ret );
76     UnMapLS( segptr );
77     return LOWORD(ret);
78 }
79
80 /* callback for EnumObjects16 */
81 static INT CALLBACK enum_brushes_callback( void *ptr, LPARAM param )
82 {
83     const struct callback16_info *info = (struct callback16_info *)param;
84     LOGBRUSH *brush = ptr;
85     LOGBRUSH16 brush16;
86     SEGPTR segptr;
87     DWORD ret;
88     WORD args[4];
89
90     brush16.lbStyle = brush->lbStyle;
91     brush16.lbColor = brush->lbColor;
92     brush16.lbHatch = brush->lbHatch;
93     segptr = MapLS( &brush16 );
94     args[3] = SELECTOROF(segptr);
95     args[2] = OFFSETOF(segptr);
96     args[1] = HIWORD(info->param);
97     args[0] = LOWORD(info->param);
98     WOWCallback16Ex( (DWORD)info->proc, WCB16_PASCAL, sizeof(args), args, &ret );
99     UnMapLS( segptr );
100     return ret;
101 }
102
103 /* convert a LOGFONT16 to a LOGFONTW */
104 static void logfont_16_to_W( const LOGFONT16 *font16, LPLOGFONTW font32 )
105 {
106     font32->lfHeight = font16->lfHeight;
107     font32->lfWidth = font16->lfWidth;
108     font32->lfEscapement = font16->lfEscapement;
109     font32->lfOrientation = font16->lfOrientation;
110     font32->lfWeight = font16->lfWeight;
111     font32->lfItalic = font16->lfItalic;
112     font32->lfUnderline = font16->lfUnderline;
113     font32->lfStrikeOut = font16->lfStrikeOut;
114     font32->lfCharSet = font16->lfCharSet;
115     font32->lfOutPrecision = font16->lfOutPrecision;
116     font32->lfClipPrecision = font16->lfClipPrecision;
117     font32->lfQuality = font16->lfQuality;
118     font32->lfPitchAndFamily = font16->lfPitchAndFamily;
119     MultiByteToWideChar( CP_ACP, 0, font16->lfFaceName, -1, font32->lfFaceName, LF_FACESIZE );
120     font32->lfFaceName[LF_FACESIZE-1] = 0;
121 }
122
123
124 /***********************************************************************
125  *           SetBkColor    (GDI.1)
126  */
127 COLORREF WINAPI SetBkColor16( HDC16 hdc, COLORREF color )
128 {
129     return SetBkColor( HDC_32(hdc), color );
130 }
131
132
133 /***********************************************************************
134  *              SetBkMode (GDI.2)
135  */
136 INT16 WINAPI SetBkMode16( HDC16 hdc, INT16 mode )
137 {
138     return SetBkMode( HDC_32(hdc), mode );
139 }
140
141
142 /***********************************************************************
143  *           SetMapMode    (GDI.3)
144  */
145 INT16 WINAPI SetMapMode16( HDC16 hdc, INT16 mode )
146 {
147     return SetMapMode( HDC_32(hdc), mode );
148 }
149
150
151 /***********************************************************************
152  *              SetROP2 (GDI.4)
153  */
154 INT16 WINAPI SetROP216( HDC16 hdc, INT16 mode )
155 {
156     return SetROP2( HDC_32(hdc), mode );
157 }
158
159
160 /***********************************************************************
161  *              SetRelAbs (GDI.5)
162  */
163 INT16 WINAPI SetRelAbs16( HDC16 hdc, INT16 mode )
164 {
165     return SetRelAbs( HDC_32(hdc), mode );
166 }
167
168
169 /***********************************************************************
170  *              SetPolyFillMode (GDI.6)
171  */
172 INT16 WINAPI SetPolyFillMode16( HDC16 hdc, INT16 mode )
173 {
174     return SetPolyFillMode( HDC_32(hdc), mode );
175 }
176
177
178 /***********************************************************************
179  *              SetStretchBltMode (GDI.7)
180  */
181 INT16 WINAPI SetStretchBltMode16( HDC16 hdc, INT16 mode )
182 {
183     return SetStretchBltMode( HDC_32(hdc), mode );
184 }
185
186
187 /***********************************************************************
188  *           SetTextCharacterExtra    (GDI.8)
189  */
190 INT16 WINAPI SetTextCharacterExtra16( HDC16 hdc, INT16 extra )
191 {
192     return SetTextCharacterExtra( HDC_32(hdc), extra );
193 }
194
195
196 /***********************************************************************
197  *           SetTextColor    (GDI.9)
198  */
199 COLORREF WINAPI SetTextColor16( HDC16 hdc, COLORREF color )
200 {
201     return SetTextColor( HDC_32(hdc), color );
202 }
203
204
205 /***********************************************************************
206  *           SetTextJustification    (GDI.10)
207  */
208 INT16 WINAPI SetTextJustification16( HDC16 hdc, INT16 extra, INT16 breaks )
209 {
210     return SetTextJustification( HDC_32(hdc), extra, breaks );
211 }
212
213
214 /***********************************************************************
215  *           SetWindowOrg    (GDI.11)
216  */
217 DWORD WINAPI SetWindowOrg16( HDC16 hdc, INT16 x, INT16 y )
218 {
219     POINT pt;
220     if (!SetWindowOrgEx( HDC_32(hdc), x, y, &pt )) return 0;
221     return MAKELONG( pt.x, pt.y );
222 }
223
224
225 /***********************************************************************
226  *           SetWindowExt    (GDI.12)
227  */
228 DWORD WINAPI SetWindowExt16( HDC16 hdc, INT16 x, INT16 y )
229 {
230     SIZE size;
231     if (!SetWindowExtEx( HDC_32(hdc), x, y, &size )) return 0;
232     return MAKELONG( size.cx, size.cy );
233 }
234
235
236 /***********************************************************************
237  *           SetViewportOrg    (GDI.13)
238  */
239 DWORD WINAPI SetViewportOrg16( HDC16 hdc, INT16 x, INT16 y )
240 {
241     POINT pt;
242     if (!SetViewportOrgEx( HDC_32(hdc), x, y, &pt )) return 0;
243     return MAKELONG( pt.x, pt.y );
244 }
245
246
247 /***********************************************************************
248  *           SetViewportExt    (GDI.14)
249  */
250 DWORD WINAPI SetViewportExt16( HDC16 hdc, INT16 x, INT16 y )
251 {
252     SIZE size;
253     if (!SetViewportExtEx( HDC_32(hdc), x, y, &size )) return 0;
254     return MAKELONG( size.cx, size.cy );
255 }
256
257
258 /***********************************************************************
259  *           OffsetWindowOrg    (GDI.15)
260  */
261 DWORD WINAPI OffsetWindowOrg16( HDC16 hdc, INT16 x, INT16 y )
262 {
263     POINT pt;
264     if (!OffsetWindowOrgEx( HDC_32(hdc), x, y, &pt )) return 0;
265     return MAKELONG( pt.x, pt.y );
266 }
267
268
269 /***********************************************************************
270  *           ScaleWindowExt    (GDI.16)
271  */
272 DWORD WINAPI ScaleWindowExt16( HDC16 hdc, INT16 xNum, INT16 xDenom,
273                              INT16 yNum, INT16 yDenom )
274 {
275     SIZE size;
276     if (!ScaleWindowExtEx( HDC_32(hdc), xNum, xDenom, yNum, yDenom, &size ))
277         return FALSE;
278     return MAKELONG( size.cx,  size.cy );
279 }
280
281
282 /***********************************************************************
283  *           OffsetViewportOrg    (GDI.17)
284  */
285 DWORD WINAPI OffsetViewportOrg16( HDC16 hdc, INT16 x, INT16 y )
286 {
287     POINT pt;
288     if (!OffsetViewportOrgEx( HDC_32(hdc), x, y, &pt )) return 0;
289     return MAKELONG( pt.x, pt.y );
290 }
291
292
293 /***********************************************************************
294  *           ScaleViewportExt    (GDI.18)
295  */
296 DWORD WINAPI ScaleViewportExt16( HDC16 hdc, INT16 xNum, INT16 xDenom,
297                                INT16 yNum, INT16 yDenom )
298 {
299     SIZE size;
300     if (!ScaleViewportExtEx( HDC_32(hdc), xNum, xDenom, yNum, yDenom, &size ))
301         return FALSE;
302     return MAKELONG( size.cx,  size.cy );
303 }
304
305
306 /***********************************************************************
307  *           LineTo    (GDI.19)
308  */
309 BOOL16 WINAPI LineTo16( HDC16 hdc, INT16 x, INT16 y )
310 {
311     return LineTo( HDC_32(hdc), x, y );
312 }
313
314
315 /***********************************************************************
316  *           MoveTo    (GDI.20)
317  */
318 DWORD WINAPI MoveTo16( HDC16 hdc, INT16 x, INT16 y )
319 {
320     POINT pt;
321
322     if (!MoveToEx( HDC_32(hdc), x, y, &pt )) return 0;
323     return MAKELONG(pt.x,pt.y);
324 }
325
326
327 /***********************************************************************
328  *           ExcludeClipRect    (GDI.21)
329  */
330 INT16 WINAPI ExcludeClipRect16( HDC16 hdc, INT16 left, INT16 top,
331                                 INT16 right, INT16 bottom )
332 {
333     return ExcludeClipRect( HDC_32(hdc), left, top, right, bottom );
334 }
335
336
337 /***********************************************************************
338  *           IntersectClipRect    (GDI.22)
339  */
340 INT16 WINAPI IntersectClipRect16( HDC16 hdc, INT16 left, INT16 top,
341                                   INT16 right, INT16 bottom )
342 {
343     return IntersectClipRect( HDC_32(hdc), left, top, right, bottom );
344 }
345
346
347 /***********************************************************************
348  *           Arc    (GDI.23)
349  */
350 BOOL16 WINAPI Arc16( HDC16 hdc, INT16 left, INT16 top, INT16 right,
351                      INT16 bottom, INT16 xstart, INT16 ystart,
352                      INT16 xend, INT16 yend )
353 {
354     return Arc( HDC_32(hdc), left, top, right, bottom, xstart, ystart, xend, yend );
355 }
356
357
358 /***********************************************************************
359  *           Ellipse    (GDI.24)
360  */
361 BOOL16 WINAPI Ellipse16( HDC16 hdc, INT16 left, INT16 top,
362                          INT16 right, INT16 bottom )
363 {
364     return Ellipse( HDC_32(hdc), left, top, right, bottom );
365 }
366
367
368 /**********************************************************************
369  *          FloodFill   (GDI.25)
370  */
371 BOOL16 WINAPI FloodFill16( HDC16 hdc, INT16 x, INT16 y, COLORREF color )
372 {
373     return ExtFloodFill( HDC_32(hdc), x, y, color, FLOODFILLBORDER );
374 }
375
376
377 /***********************************************************************
378  *           Pie    (GDI.26)
379  */
380 BOOL16 WINAPI Pie16( HDC16 hdc, INT16 left, INT16 top,
381                      INT16 right, INT16 bottom, INT16 xstart, INT16 ystart,
382                      INT16 xend, INT16 yend )
383 {
384     return Pie( HDC_32(hdc), left, top, right, bottom, xstart, ystart, xend, yend );
385 }
386
387
388 /***********************************************************************
389  *           Rectangle    (GDI.27)
390  */
391 BOOL16 WINAPI Rectangle16( HDC16 hdc, INT16 left, INT16 top,
392                            INT16 right, INT16 bottom )
393 {
394     return Rectangle( HDC_32(hdc), left, top, right, bottom );
395 }
396
397
398 /***********************************************************************
399  *           RoundRect    (GDI.28)
400  */
401 BOOL16 WINAPI RoundRect16( HDC16 hdc, INT16 left, INT16 top, INT16 right,
402                            INT16 bottom, INT16 ell_width, INT16 ell_height )
403 {
404     return RoundRect( HDC_32(hdc), left, top, right, bottom, ell_width, ell_height );
405 }
406
407
408 /***********************************************************************
409  *           PatBlt    (GDI.29)
410  */
411 BOOL16 WINAPI PatBlt16( HDC16 hdc, INT16 left, INT16 top,
412                         INT16 width, INT16 height, DWORD rop)
413 {
414     return PatBlt( HDC_32(hdc), left, top, width, height, rop );
415 }
416
417
418 /***********************************************************************
419  *           SaveDC    (GDI.30)
420  */
421 INT16 WINAPI SaveDC16( HDC16 hdc )
422 {
423     return SaveDC( HDC_32(hdc) );
424 }
425
426
427 /***********************************************************************
428  *           SetPixel    (GDI.31)
429  */
430 COLORREF WINAPI SetPixel16( HDC16 hdc, INT16 x, INT16 y, COLORREF color )
431 {
432     return SetPixel( HDC_32(hdc), x, y, color );
433 }
434
435
436 /***********************************************************************
437  *           OffsetClipRgn    (GDI.32)
438  */
439 INT16 WINAPI OffsetClipRgn16( HDC16 hdc, INT16 x, INT16 y )
440 {
441     return OffsetClipRgn( HDC_32(hdc), x, y );
442 }
443
444
445 /***********************************************************************
446  *           TextOut    (GDI.33)
447  */
448 BOOL16 WINAPI TextOut16( HDC16 hdc, INT16 x, INT16 y, LPCSTR str, INT16 count )
449 {
450     return TextOutA( HDC_32(hdc), x, y, str, count );
451 }
452
453
454 /***********************************************************************
455  *           BitBlt    (GDI.34)
456  */
457 BOOL16 WINAPI BitBlt16( HDC16 hdcDst, INT16 xDst, INT16 yDst, INT16 width,
458                         INT16 height, HDC16 hdcSrc, INT16 xSrc, INT16 ySrc,
459                         DWORD rop )
460 {
461     return BitBlt( HDC_32(hdcDst), xDst, yDst, width, height, HDC_32(hdcSrc), xSrc, ySrc, rop );
462 }
463
464
465 /***********************************************************************
466  *           StretchBlt    (GDI.35)
467  */
468 BOOL16 WINAPI StretchBlt16( HDC16 hdcDst, INT16 xDst, INT16 yDst,
469                             INT16 widthDst, INT16 heightDst,
470                             HDC16 hdcSrc, INT16 xSrc, INT16 ySrc,
471                             INT16 widthSrc, INT16 heightSrc, DWORD rop )
472 {
473     return StretchBlt( HDC_32(hdcDst), xDst, yDst, widthDst, heightDst,
474                        HDC_32(hdcSrc), xSrc, ySrc, widthSrc, heightSrc, rop );
475 }
476
477
478 /**********************************************************************
479  *          Polygon  (GDI.36)
480  */
481 BOOL16 WINAPI Polygon16( HDC16 hdc, const POINT16* pt, INT16 count )
482 {
483     register int i;
484     BOOL ret;
485     LPPOINT pt32 = (LPPOINT)HeapAlloc( GetProcessHeap(), 0,
486                                            count*sizeof(POINT) );
487
488     if (!pt32) return FALSE;
489     for (i=count;i--;) CONV_POINT16TO32(&(pt[i]),&(pt32[i]));
490     ret = Polygon(HDC_32(hdc),pt32,count);
491     HeapFree( GetProcessHeap(), 0, pt32 );
492     return ret;
493 }
494
495
496 /**********************************************************************
497  *          Polyline  (GDI.37)
498  */
499 BOOL16 WINAPI Polyline16( HDC16 hdc, const POINT16* pt, INT16 count )
500 {
501     register int i;
502     BOOL16 ret;
503     LPPOINT pt32 = (LPPOINT)HeapAlloc( GetProcessHeap(), 0,
504                                            count*sizeof(POINT) );
505
506     if (!pt32) return FALSE;
507     for (i=count;i--;) CONV_POINT16TO32(&(pt[i]),&(pt32[i]));
508     ret = Polyline(HDC_32(hdc),pt32,count);
509     HeapFree( GetProcessHeap(), 0, pt32 );
510     return ret;
511 }
512
513
514 /***********************************************************************
515  *            Escape   (GDI.38)
516  */
517 INT16 WINAPI Escape16( HDC16 hdc, INT16 escape, INT16 in_count, SEGPTR in_data, LPVOID out_data )
518 {
519     INT ret;
520
521     switch(escape)
522     {
523     /* Escape(hdc,CLIP_TO_PATH,LPINT16,NULL) */
524     /* Escape(hdc,DRAFTMODE,LPINT16,NULL) */
525     /* Escape(hdc,ENUMPAPERBINS,LPINT16,LPSTR); */
526     /* Escape(hdc,EPSPRINTING,LPINT16,NULL) */
527     /* Escape(hdc,EXT_DEVICE_CAPS,LPINT16,LPDWORD) */
528     /* Escape(hdc,GETCOLORTABLE,LPINT16,LPDWORD) */
529     /* Escape(hdc,MOUSETRAILS,LPINT16,NULL) */
530     /* Escape(hdc,POSTSCRIPT_IGNORE,LPINT16,NULL) */
531     /* Escape(hdc,QUERYESCSUPPORT,LPINT16,NULL) */
532     /* Escape(hdc,SET_ARC_DIRECTION,LPINT16,NULL) */
533     /* Escape(hdc,SET_POLY_MODE,LPINT16,NULL) */
534     /* Escape(hdc,SET_SCREEN_ANGLE,LPINT16,NULL) */
535     /* Escape(hdc,SET_SPREAD,LPINT16,NULL) */
536     case CLIP_TO_PATH:
537     case DRAFTMODE:
538     case ENUMPAPERBINS:
539     case EPSPRINTING:
540     case EXT_DEVICE_CAPS:
541     case GETCOLORTABLE:
542     case MOUSETRAILS:
543     case POSTSCRIPT_IGNORE:
544     case QUERYESCSUPPORT:
545     case SET_ARC_DIRECTION:
546     case SET_POLY_MODE:
547     case SET_SCREEN_ANGLE:
548     case SET_SPREAD:
549     {
550         INT16 *ptr = MapSL(in_data);
551         INT data = *ptr;
552         return Escape( HDC_32(hdc), escape, sizeof(data), (LPCSTR)&data, out_data );
553     }
554
555     /* Escape(hdc,ENABLEDUPLEX,LPUINT16,NULL) */
556     case ENABLEDUPLEX:
557     {
558         UINT16 *ptr = MapSL(in_data);
559         UINT data = *ptr;
560         return Escape( HDC_32(hdc), escape, sizeof(data), (LPCSTR)&data, NULL );
561     }
562
563     /* Escape(hdc,GETPHYSPAGESIZE,NULL,LPPOINT16) */
564     /* Escape(hdc,GETPRINTINGOFFSET,NULL,LPPOINT16) */
565     /* Escape(hdc,GETSCALINGFACTOR,NULL,LPPOINT16) */
566     case GETPHYSPAGESIZE:
567     case GETPRINTINGOFFSET:
568     case GETSCALINGFACTOR:
569     {
570         POINT16 *ptr = out_data;
571         POINT pt32;
572         ret = Escape( HDC_32(hdc), escape, 0, NULL, &pt32 );
573         ptr->x = pt32.x;
574         ptr->y = pt32.y;
575         return ret;
576     }
577
578     /* Escape(hdc,ENABLEPAIRKERNING,LPINT16,LPINT16); */
579     /* Escape(hdc,ENABLERELATIVEWIDTHS,LPINT16,LPINT16); */
580     /* Escape(hdc,SETCOPYCOUNT,LPINT16,LPINT16) */
581     /* Escape(hdc,SETKERNTRACK,LPINT16,LPINT16) */
582     /* Escape(hdc,SETLINECAP,LPINT16,LPINT16) */
583     /* Escape(hdc,SETLINEJOIN,LPINT16,LPINT16) */
584     /* Escape(hdc,SETMITERLIMIT,LPINT16,LPINT16) */
585     case ENABLEPAIRKERNING:
586     case ENABLERELATIVEWIDTHS:
587     case SETCOPYCOUNT:
588     case SETKERNTRACK:
589     case SETLINECAP:
590     case SETLINEJOIN:
591     case SETMITERLIMIT:
592     {
593         INT16 *new = MapSL(in_data);
594         INT16 *old = out_data;
595         INT out, in = *new;
596         ret = Escape( HDC_32(hdc), escape, sizeof(in), (LPCSTR)&in, &out );
597         *old = out;
598         return ret;
599     }
600
601     /* Escape(hdc,SETABORTPROC,ABORTPROC,NULL); */
602     case SETABORTPROC:
603         return SetAbortProc16( hdc, (ABORTPROC16)in_data );
604
605     /* Escape(hdc,STARTDOC,LPSTR,LPDOCINFO16);
606      * lpvOutData is actually a pointer to the DocInfo structure and used as
607      * a second input parameter */
608     case STARTDOC:
609         if (out_data)
610         {
611             ret = StartDoc16( hdc, out_data );
612             if (ret > 0) ret = StartPage( HDC_32(hdc) );
613             return ret;
614         }
615         return Escape( HDC_32(hdc), escape, in_count, MapSL(in_data), NULL );
616
617     /* Escape(hdc,SET_BOUNDS,LPRECT16,NULL); */
618     /* Escape(hdc,SET_CLIP_BOX,LPRECT16,NULL); */
619     case SET_BOUNDS:
620     case SET_CLIP_BOX:
621     {
622         RECT16 *rc16 = MapSL(in_data);
623         RECT rc;
624         rc.left   = rc16->left;
625         rc.top    = rc16->top;
626         rc.right  = rc16->right;
627         rc.bottom = rc16->bottom;
628         return Escape( HDC_32(hdc), escape, sizeof(rc), (LPCSTR)&rc, NULL );
629     }
630
631     /* Escape(hdc,NEXTBAND,NULL,LPRECT16); */
632     case NEXTBAND:
633     {
634         RECT rc;
635         RECT16 *rc16 = out_data;
636         ret = Escape( HDC_32(hdc), escape, 0, NULL, &rc );
637         rc16->left   = rc.left;
638         rc16->top    = rc.top;
639         rc16->right  = rc.right;
640         rc16->bottom = rc.bottom;
641         return ret;
642     }
643
644     /* Escape(hdc,ABORTDOC,NULL,NULL); */
645     /* Escape(hdc,BANDINFO,BANDINFOSTRUCT*,BANDINFOSTRUCT*); */
646     /* Escape(hdc,BEGIN_PATH,NULL,NULL); */
647     /* Escape(hdc,DRAWPATTERNRECT,PRECT_STRUCT*,NULL); */
648     /* Escape(hdc,ENDDOC,NULL,NULL); */
649     /* Escape(hdc,END_PATH,PATHINFO,NULL); */
650     /* Escape(hdc,EXTTEXTOUT,EXTTEXT_STRUCT*,NULL); */
651     /* Escape(hdc,FLUSHOUTPUT,NULL,NULL); */
652     /* Escape(hdc,GETFACENAME,NULL,LPSTR); */
653     /* Escape(hdc,GETPAIRKERNTABLE,NULL,KERNPAIR*); */
654     /* Escape(hdc,GETSETPAPERBINS,BinInfo*,BinInfo*); */
655     /* Escape(hdc,GETSETPRINTORIENT,ORIENT*,NULL); */
656     /* Escape(hdc,GETSETSCREENPARAMS,SCREENPARAMS*,SCREENPARAMS*); */
657     /* Escape(hdc,GETTECHNOLOGY,NULL,LPSTR); */
658     /* Escape(hdc,GETTRACKKERNTABLE,NULL,KERNTRACK*); */
659     /* Escape(hdc,MFCOMMENT,LPSTR,NULL); */
660     /* Escape(hdc,NEWFRAME,NULL,NULL); */
661     /* Escape(hdc,PASSTHROUGH,LPSTR,NULL); */
662     /* Escape(hdc,RESTORE_CTM,NULL,NULL); */
663     /* Escape(hdc,SAVE_CTM,NULL,NULL); */
664     /* Escape(hdc,SETALLJUSTVALUES,EXTTEXTDATA*,NULL); */
665     /* Escape(hdc,SETCOLORTABLE,COLORTABLE_STRUCT*,LPDWORD); */
666     /* Escape(hdc,SET_BACKGROUND_COLOR,LPDWORD,LPDWORD); */
667     /* Escape(hdc,TRANSFORM_CTM,LPSTR,NULL); */
668     case ABORTDOC:
669     case BANDINFO:
670     case BEGIN_PATH:
671     case DRAWPATTERNRECT:
672     case ENDDOC:
673     case END_PATH:
674     case EXTTEXTOUT:
675     case FLUSHOUTPUT:
676     case GETFACENAME:
677     case GETPAIRKERNTABLE:
678     case GETSETPAPERBINS:
679     case GETSETPRINTORIENT:
680     case GETSETSCREENPARAMS:
681     case GETTECHNOLOGY:
682     case GETTRACKKERNTABLE:
683     case MFCOMMENT:
684     case NEWFRAME:
685     case PASSTHROUGH:
686     case RESTORE_CTM:
687     case SAVE_CTM:
688     case SETALLJUSTVALUES:
689     case SETCOLORTABLE:
690     case SET_BACKGROUND_COLOR:
691     case TRANSFORM_CTM:
692         /* pass it unmodified to the 32-bit function */
693         return Escape( HDC_32(hdc), escape, in_count, MapSL(in_data), out_data );
694
695     /* Escape(hdc,ENUMPAPERMETRICS,LPINT16,LPRECT16); */
696     /* Escape(hdc,GETEXTENDEDTEXTMETRICS,LPUINT16,EXTTEXTMETRIC*); */
697     /* Escape(hdc,GETEXTENTTABLE,LPSTR,LPINT16); */
698     /* Escape(hdc,GETSETPAPERMETRICS,LPRECT16,LPRECT16); */
699     /* Escape(hdc,GETVECTORBRUSHSIZE,LPLOGBRUSH16,LPPOINT16); */
700     /* Escape(hdc,GETVECTORPENSIZE,LPLOGPEN16,LPPOINT16); */
701     case ENUMPAPERMETRICS:
702     case GETEXTENDEDTEXTMETRICS:
703     case GETEXTENTTABLE:
704     case GETSETPAPERMETRICS:
705     case GETVECTORBRUSHSIZE:
706     case GETVECTORPENSIZE:
707     default:
708         FIXME("unknown/unsupported 16-bit escape %x (%d,%p,%p\n",
709               escape, in_count, MapSL(in_data), out_data );
710         return Escape( HDC_32(hdc), escape, in_count, MapSL(in_data), out_data );
711     }
712 }
713
714
715 /***********************************************************************
716  *           RestoreDC    (GDI.39)
717  */
718 BOOL16 WINAPI RestoreDC16( HDC16 hdc, INT16 level )
719 {
720     return RestoreDC( HDC_32(hdc), level );
721 }
722
723
724 /***********************************************************************
725  *           FillRgn    (GDI.40)
726  */
727 BOOL16 WINAPI FillRgn16( HDC16 hdc, HRGN16 hrgn, HBRUSH16 hbrush )
728 {
729     return FillRgn( HDC_32(hdc), HRGN_32(hrgn), HBRUSH_32(hbrush) );
730 }
731
732
733 /***********************************************************************
734  *           FrameRgn     (GDI.41)
735  */
736 BOOL16 WINAPI FrameRgn16( HDC16 hdc, HRGN16 hrgn, HBRUSH16 hbrush,
737                           INT16 nWidth, INT16 nHeight )
738 {
739     return FrameRgn( HDC_32(hdc), HRGN_32(hrgn), HBRUSH_32(hbrush), nWidth, nHeight );
740 }
741
742
743 /***********************************************************************
744  *           InvertRgn    (GDI.42)
745  */
746 BOOL16 WINAPI InvertRgn16( HDC16 hdc, HRGN16 hrgn )
747 {
748     return InvertRgn( HDC_32(hdc), HRGN_32(hrgn) );
749 }
750
751
752 /***********************************************************************
753  *           PaintRgn    (GDI.43)
754  */
755 BOOL16 WINAPI PaintRgn16( HDC16 hdc, HRGN16 hrgn )
756 {
757     return PaintRgn( HDC_32(hdc), HRGN_32(hrgn) );
758 }
759
760
761 /***********************************************************************
762  *           SelectClipRgn    (GDI.44)
763  */
764 INT16 WINAPI SelectClipRgn16( HDC16 hdc, HRGN16 hrgn )
765 {
766     return SelectClipRgn( HDC_32(hdc), HRGN_32(hrgn) );
767 }
768
769
770 /***********************************************************************
771  *           SelectObject    (GDI.45)
772  */
773 HGDIOBJ16 WINAPI SelectObject16( HDC16 hdc, HGDIOBJ16 handle )
774 {
775     return HGDIOBJ_16( SelectObject( HDC_32(hdc), HGDIOBJ_32(handle) ) );
776 }
777
778
779 /***********************************************************************
780  *           CombineRgn    (GDI.47)
781  */
782 INT16 WINAPI CombineRgn16(HRGN16 hDest, HRGN16 hSrc1, HRGN16 hSrc2, INT16 mode)
783 {
784     return CombineRgn( HRGN_32(hDest), HRGN_32(hSrc1), HRGN_32(hSrc2), mode );
785 }
786
787
788 /***********************************************************************
789  *           CreateBitmap    (GDI.48)
790  */
791 HBITMAP16 WINAPI CreateBitmap16( INT16 width, INT16 height, UINT16 planes,
792                                  UINT16 bpp, LPCVOID bits )
793 {
794     return HBITMAP_16( CreateBitmap( width, height, planes, bpp, bits ) );
795 }
796
797
798 /***********************************************************************
799  *           CreateBitmapIndirect    (GDI.49)
800  */
801 HBITMAP16 WINAPI CreateBitmapIndirect16( const BITMAP16 * bmp )
802 {
803     return CreateBitmap16( bmp->bmWidth, bmp->bmHeight, bmp->bmPlanes,
804                            bmp->bmBitsPixel, MapSL( bmp->bmBits ) );
805 }
806
807
808 /***********************************************************************
809  *           CreateBrushIndirect    (GDI.50)
810  */
811 HBRUSH16 WINAPI CreateBrushIndirect16( const LOGBRUSH16 * brush )
812 {
813     LOGBRUSH brush32;
814
815     if (brush->lbStyle == BS_DIBPATTERN || brush->lbStyle == BS_DIBPATTERN8X8)
816         return CreateDIBPatternBrush16( brush->lbHatch, brush->lbColor );
817
818     brush32.lbStyle = brush->lbStyle;
819     brush32.lbColor = brush->lbColor;
820     brush32.lbHatch = brush->lbHatch;
821     return HBRUSH_16( CreateBrushIndirect(&brush32) );
822 }
823
824
825 /***********************************************************************
826  *           CreateCompatibleBitmap    (GDI.51)
827  */
828 HBITMAP16 WINAPI CreateCompatibleBitmap16( HDC16 hdc, INT16 width, INT16 height )
829 {
830     return HBITMAP_16( CreateCompatibleBitmap( HDC_32(hdc), width, height ) );
831 }
832
833
834 /***********************************************************************
835  *           CreateCompatibleDC    (GDI.52)
836  */
837 HDC16 WINAPI CreateCompatibleDC16( HDC16 hdc )
838 {
839     return HDC_16( CreateCompatibleDC( HDC_32(hdc) ) );
840 }
841
842
843 /***********************************************************************
844  *           CreateDC    (GDI.53)
845  */
846 HDC16 WINAPI CreateDC16( LPCSTR driver, LPCSTR device, LPCSTR output,
847                          const DEVMODEA *initData )
848 {
849     return HDC_16( CreateDCA( driver, device, output, initData ) );
850 }
851
852
853 /***********************************************************************
854  *           CreateEllipticRgn    (GDI.54)
855  */
856 HRGN16 WINAPI CreateEllipticRgn16( INT16 left, INT16 top, INT16 right, INT16 bottom )
857 {
858     return HRGN_16( CreateEllipticRgn( left, top, right, bottom ) );
859 }
860
861
862 /***********************************************************************
863  *           CreateEllipticRgnIndirect    (GDI.55)
864  */
865 HRGN16 WINAPI CreateEllipticRgnIndirect16( const RECT16 *rect )
866 {
867     return HRGN_16( CreateEllipticRgn( rect->left, rect->top, rect->right, rect->bottom ) );
868 }
869
870
871 /***********************************************************************
872  *           CreateFont    (GDI.56)
873  */
874 HFONT16 WINAPI CreateFont16(INT16 height, INT16 width, INT16 esc, INT16 orient,
875                             INT16 weight, BYTE italic, BYTE underline,
876                             BYTE strikeout, BYTE charset, BYTE outpres,
877                             BYTE clippres, BYTE quality, BYTE pitch,
878                             LPCSTR name )
879 {
880     return HFONT_16( CreateFontA( height, width, esc, orient, weight, italic, underline,
881                                   strikeout, charset, outpres, clippres, quality, pitch, name ));
882 }
883
884 /***********************************************************************
885  *           CreateFontIndirect   (GDI.57)
886  */
887 HFONT16 WINAPI CreateFontIndirect16( const LOGFONT16 *plf16 )
888 {
889     HFONT ret;
890
891     if (plf16)
892     {
893         LOGFONTW lfW;
894         logfont_16_to_W( plf16, &lfW );
895         ret = CreateFontIndirectW( &lfW );
896     }
897     else ret = CreateFontIndirectW( NULL );
898     return HFONT_16(ret);
899 }
900
901
902 /***********************************************************************
903  *           CreateHatchBrush    (GDI.58)
904  */
905 HBRUSH16 WINAPI CreateHatchBrush16( INT16 style, COLORREF color )
906 {
907     return HBRUSH_16( CreateHatchBrush( style, color ) );
908 }
909
910
911 /***********************************************************************
912  *           CreatePatternBrush    (GDI.60)
913  */
914 HBRUSH16 WINAPI CreatePatternBrush16( HBITMAP16 hbitmap )
915 {
916     return HBRUSH_16( CreatePatternBrush( HBITMAP_32(hbitmap) ));
917 }
918
919
920 /***********************************************************************
921  *           CreatePen    (GDI.61)
922  */
923 HPEN16 WINAPI CreatePen16( INT16 style, INT16 width, COLORREF color )
924 {
925     LOGPEN logpen;
926
927     logpen.lopnStyle = style;
928     logpen.lopnWidth.x = width;
929     logpen.lopnWidth.y = 0;
930     logpen.lopnColor = color;
931     return HPEN_16( CreatePenIndirect( &logpen ) );
932 }
933
934
935 /***********************************************************************
936  *           CreatePenIndirect    (GDI.62)
937  */
938 HPEN16 WINAPI CreatePenIndirect16( const LOGPEN16 * pen )
939 {
940     LOGPEN logpen;
941
942     if (pen->lopnStyle > PS_INSIDEFRAME) return 0;
943     logpen.lopnStyle   = pen->lopnStyle;
944     logpen.lopnWidth.x = pen->lopnWidth.x;
945     logpen.lopnWidth.y = pen->lopnWidth.y;
946     logpen.lopnColor   = pen->lopnColor;
947     return HPEN_16( CreatePenIndirect( &logpen ) );
948 }
949
950
951 /***********************************************************************
952  *           CreatePolygonRgn    (GDI.63)
953  */
954 HRGN16 WINAPI CreatePolygonRgn16( const POINT16 * points, INT16 count, INT16 mode )
955 {
956     return CreatePolyPolygonRgn16( points, &count, 1, mode );
957 }
958
959
960 /***********************************************************************
961  *           CreateRectRgn    (GDI.64)
962  *
963  * NOTE: cf. SetRectRgn16
964  */
965 HRGN16 WINAPI CreateRectRgn16( INT16 left, INT16 top, INT16 right, INT16 bottom )
966 {
967     HRGN hrgn;
968
969     if (left < right) hrgn = CreateRectRgn( left, top, right, bottom );
970     else hrgn = CreateRectRgn( 0, 0, 0, 0 );
971     return HRGN_16(hrgn);
972 }
973
974
975 /***********************************************************************
976  *           CreateRectRgnIndirect    (GDI.65)
977  */
978 HRGN16 WINAPI CreateRectRgnIndirect16( const RECT16* rect )
979 {
980     return CreateRectRgn16( rect->left, rect->top, rect->right, rect->bottom );
981 }
982
983
984 /***********************************************************************
985  *           CreateSolidBrush    (GDI.66)
986  */
987 HBRUSH16 WINAPI CreateSolidBrush16( COLORREF color )
988 {
989     return HBRUSH_16( CreateSolidBrush( color ) );
990 }
991
992
993 /***********************************************************************
994  *           DeleteDC    (GDI.68)
995  */
996 BOOL16 WINAPI DeleteDC16( HDC16 hdc )
997 {
998     return DeleteDC( HDC_32(hdc) );
999 }
1000
1001
1002 /***********************************************************************
1003  *           DeleteObject    (GDI.69)
1004  *           SysDeleteObject (GDI.605)
1005  */
1006 BOOL16 WINAPI DeleteObject16( HGDIOBJ16 obj )
1007 {
1008     return DeleteObject( HGDIOBJ_32(obj) );
1009 }
1010
1011
1012 /***********************************************************************
1013  *           EnumObjects    (GDI.71)
1014  */
1015 INT16 WINAPI EnumObjects16( HDC16 hdc, INT16 obj, GOBJENUMPROC16 proc, LPARAM lParam )
1016 {
1017     struct callback16_info info;
1018
1019     info.proc  = (FARPROC16)proc;
1020     info.param = lParam;
1021     switch(obj)
1022     {
1023     case OBJ_PEN:
1024         return EnumObjects( HDC_32(hdc), OBJ_PEN, enum_pens_callback, (LPARAM)&info );
1025     case OBJ_BRUSH:
1026         return EnumObjects( HDC_32(hdc), OBJ_BRUSH, enum_brushes_callback, (LPARAM)&info );
1027     }
1028     return 0;
1029 }
1030
1031
1032 /***********************************************************************
1033  *           EqualRgn    (GDI.72)
1034  */
1035 BOOL16 WINAPI EqualRgn16( HRGN16 rgn1, HRGN16 rgn2 )
1036 {
1037     return EqualRgn( HRGN_32(rgn1), HRGN_32(rgn2) );
1038 }
1039
1040
1041 /***********************************************************************
1042  *           GetBitmapBits    (GDI.74)
1043  */
1044 LONG WINAPI GetBitmapBits16( HBITMAP16 hbitmap, LONG count, LPVOID buffer )
1045 {
1046     return GetBitmapBits( HBITMAP_32(hbitmap), count, buffer );
1047 }
1048
1049
1050 /***********************************************************************
1051  *              GetBkColor (GDI.75)
1052  */
1053 COLORREF WINAPI GetBkColor16( HDC16 hdc )
1054 {
1055     return GetBkColor( HDC_32(hdc) );
1056 }
1057
1058
1059 /***********************************************************************
1060  *              GetBkMode (GDI.76)
1061  */
1062 INT16 WINAPI GetBkMode16( HDC16 hdc )
1063 {
1064     return GetBkMode( HDC_32(hdc) );
1065 }
1066
1067
1068 /***********************************************************************
1069  *           GetClipBox    (GDI.77)
1070  */
1071 INT16 WINAPI GetClipBox16( HDC16 hdc, LPRECT16 rect )
1072 {
1073     RECT rect32;
1074     INT ret = GetClipBox( HDC_32(hdc), &rect32 );
1075
1076     if (ret != ERROR)
1077     {
1078         rect->left   = rect32.left;
1079         rect->top    = rect32.top;
1080         rect->right  = rect32.right;
1081         rect->bottom = rect32.bottom;
1082     }
1083     return ret;
1084 }
1085
1086
1087 /***********************************************************************
1088  *              GetCurrentPosition (GDI.78)
1089  */
1090 DWORD WINAPI GetCurrentPosition16( HDC16 hdc )
1091 {
1092     POINT pt32;
1093     if (!GetCurrentPositionEx( HDC_32(hdc), &pt32 )) return 0;
1094     return MAKELONG( pt32.x, pt32.y );
1095 }
1096
1097
1098 /***********************************************************************
1099  *           GetDCOrg    (GDI.79)
1100  */
1101 DWORD WINAPI GetDCOrg16( HDC16 hdc )
1102 {
1103     POINT pt;
1104     if (GetDCOrgEx( HDC_32(hdc), &pt )) return MAKELONG( pt.x, pt.y );
1105     return 0;
1106 }
1107
1108
1109 /***********************************************************************
1110  *           GetDeviceCaps    (GDI.80)
1111  */
1112 INT16 WINAPI GetDeviceCaps16( HDC16 hdc, INT16 cap )
1113 {
1114     INT16 ret = GetDeviceCaps( HDC_32(hdc), cap );
1115     /* some apps don't expect -1 and think it's a B&W screen */
1116     if ((cap == NUMCOLORS) && (ret == -1)) ret = 2048;
1117     return ret;
1118 }
1119
1120
1121 /***********************************************************************
1122  *              GetMapMode (GDI.81)
1123  */
1124 INT16 WINAPI GetMapMode16( HDC16 hdc )
1125 {
1126     return GetMapMode( HDC_32(hdc) );
1127 }
1128
1129
1130 /***********************************************************************
1131  *           GetPixel    (GDI.83)
1132  */
1133 COLORREF WINAPI GetPixel16( HDC16 hdc, INT16 x, INT16 y )
1134 {
1135     return GetPixel( HDC_32(hdc), x, y );
1136 }
1137
1138
1139 /***********************************************************************
1140  *              GetPolyFillMode (GDI.84)
1141  */
1142 INT16 WINAPI GetPolyFillMode16( HDC16 hdc )
1143 {
1144     return GetPolyFillMode( HDC_32(hdc) );
1145 }
1146
1147
1148 /***********************************************************************
1149  *              GetROP2 (GDI.85)
1150  */
1151 INT16 WINAPI GetROP216( HDC16 hdc )
1152 {
1153     return GetROP2( HDC_32(hdc) );
1154 }
1155
1156
1157 /***********************************************************************
1158  *              GetRelAbs (GDI.86)
1159  */
1160 INT16 WINAPI GetRelAbs16( HDC16 hdc )
1161 {
1162     return GetRelAbs( HDC_32(hdc), 0 );
1163 }
1164
1165
1166 /***********************************************************************
1167  *           GetStockObject    (GDI.87)
1168  */
1169 HGDIOBJ16 WINAPI GetStockObject16( INT16 obj )
1170 {
1171     return HGDIOBJ_16( GetStockObject( obj ) );
1172 }
1173
1174
1175 /***********************************************************************
1176  *              GetStretchBltMode (GDI.88)
1177  */
1178 INT16 WINAPI GetStretchBltMode16( HDC16 hdc )
1179 {
1180     return GetStretchBltMode( HDC_32(hdc) );
1181 }
1182
1183
1184 /***********************************************************************
1185  *           GetTextCharacterExtra    (GDI.89)
1186  */
1187 INT16 WINAPI GetTextCharacterExtra16( HDC16 hdc )
1188 {
1189     return GetTextCharacterExtra( HDC_32(hdc) );
1190 }
1191
1192
1193 /***********************************************************************
1194  *              GetTextColor (GDI.90)
1195  */
1196 COLORREF WINAPI GetTextColor16( HDC16 hdc )
1197 {
1198     return GetTextColor( HDC_32(hdc) );
1199 }
1200
1201
1202 /***********************************************************************
1203  *           GetTextExtent    (GDI.91)
1204  */
1205 DWORD WINAPI GetTextExtent16( HDC16 hdc, LPCSTR str, INT16 count )
1206 {
1207     SIZE size;
1208     if (!GetTextExtentPoint32A( HDC_32(hdc), str, count, &size )) return 0;
1209     return MAKELONG( size.cx, size.cy );
1210 }
1211
1212
1213 /***********************************************************************
1214  *           GetTextFace    (GDI.92)
1215  */
1216 INT16 WINAPI GetTextFace16( HDC16 hdc, INT16 count, LPSTR name )
1217 {
1218     return GetTextFaceA( HDC_32(hdc), count, name );
1219 }
1220
1221
1222 /***********************************************************************
1223  *           GetTextMetrics    (GDI.93)
1224  */
1225 BOOL16 WINAPI GetTextMetrics16( HDC16 hdc, TEXTMETRIC16 *tm )
1226 {
1227     TEXTMETRICW tm32;
1228
1229     if (!GetTextMetricsW( HDC_32(hdc), &tm32 )) return FALSE;
1230
1231     tm->tmHeight           = tm32.tmHeight;
1232     tm->tmAscent           = tm32.tmAscent;
1233     tm->tmDescent          = tm32.tmDescent;
1234     tm->tmInternalLeading  = tm32.tmInternalLeading;
1235     tm->tmExternalLeading  = tm32.tmExternalLeading;
1236     tm->tmAveCharWidth     = tm32.tmAveCharWidth;
1237     tm->tmMaxCharWidth     = tm32.tmMaxCharWidth;
1238     tm->tmWeight           = tm32.tmWeight;
1239     tm->tmOverhang         = tm32.tmOverhang;
1240     tm->tmDigitizedAspectX = tm32.tmDigitizedAspectX;
1241     tm->tmDigitizedAspectY = tm32.tmDigitizedAspectY;
1242     tm->tmFirstChar        = tm32.tmFirstChar;
1243     tm->tmLastChar         = tm32.tmLastChar;
1244     tm->tmDefaultChar      = tm32.tmDefaultChar;
1245     tm->tmBreakChar        = tm32.tmBreakChar;
1246     tm->tmItalic           = tm32.tmItalic;
1247     tm->tmUnderlined       = tm32.tmUnderlined;
1248     tm->tmStruckOut        = tm32.tmStruckOut;
1249     tm->tmPitchAndFamily   = tm32.tmPitchAndFamily;
1250     tm->tmCharSet          = tm32.tmCharSet;
1251     return TRUE;
1252 }
1253
1254
1255 /***********************************************************************
1256  *              GetViewportExt (GDI.94)
1257  */
1258 DWORD WINAPI GetViewportExt16( HDC16 hdc )
1259 {
1260     SIZE size;
1261     if (!GetViewportExtEx( HDC_32(hdc), &size )) return 0;
1262     return MAKELONG( size.cx, size.cy );
1263 }
1264
1265
1266 /***********************************************************************
1267  *              GetViewportOrg (GDI.95)
1268  */
1269 DWORD WINAPI GetViewportOrg16( HDC16 hdc )
1270 {
1271     POINT pt;
1272     if (!GetViewportOrgEx( HDC_32(hdc), &pt )) return 0;
1273     return MAKELONG( pt.x, pt.y );
1274 }
1275
1276
1277 /***********************************************************************
1278  *              GetWindowExt (GDI.96)
1279  */
1280 DWORD WINAPI GetWindowExt16( HDC16 hdc )
1281 {
1282     SIZE size;
1283     if (!GetWindowExtEx( HDC_32(hdc), &size )) return 0;
1284     return MAKELONG( size.cx, size.cy );
1285 }
1286
1287
1288 /***********************************************************************
1289  *              GetWindowOrg (GDI.97)
1290  */
1291 DWORD WINAPI GetWindowOrg16( HDC16 hdc )
1292 {
1293     POINT pt;
1294     if (!GetWindowOrgEx( HDC_32(hdc), &pt )) return 0;
1295     return MAKELONG( pt.x, pt.y );
1296 }
1297
1298
1299
1300
1301 /**********************************************************************
1302  *           LineDDA   (GDI.100)
1303  */
1304 void WINAPI LineDDA16( INT16 nXStart, INT16 nYStart, INT16 nXEnd,
1305                        INT16 nYEnd, LINEDDAPROC16 proc, LPARAM lParam )
1306 {
1307     struct callback16_info info;
1308     info.proc  = (FARPROC16)proc;
1309     info.param = lParam;
1310     LineDDA( nXStart, nYStart, nXEnd, nYEnd, linedda_callback, (LPARAM)&info );
1311 }
1312
1313
1314 /***********************************************************************
1315  *           OffsetRgn    (GDI.101)
1316  */
1317 INT16 WINAPI OffsetRgn16( HRGN16 hrgn, INT16 x, INT16 y )
1318 {
1319     return OffsetRgn( HRGN_32(hrgn), x, y );
1320 }
1321
1322
1323 /***********************************************************************
1324  *           PtVisible    (GDI.103)
1325  */
1326 BOOL16 WINAPI PtVisible16( HDC16 hdc, INT16 x, INT16 y )
1327 {
1328     return PtVisible( HDC_32(hdc), x, y );
1329 }
1330
1331
1332 /***********************************************************************
1333  *           SetBitmapBits    (GDI.106)
1334  */
1335 LONG WINAPI SetBitmapBits16( HBITMAP16 hbitmap, LONG count, LPCVOID buffer )
1336 {
1337     return SetBitmapBits( HBITMAP_32(hbitmap), count, buffer );
1338 }
1339
1340
1341 /***********************************************************************
1342  *           AddFontResource    (GDI.119)
1343  */
1344 INT16 WINAPI AddFontResource16( LPCSTR filename )
1345 {
1346     return AddFontResourceA( filename );
1347 }
1348
1349
1350 /***********************************************************************
1351  *           Death    (GDI.121)
1352  *
1353  * Disables GDI, switches back to text mode.
1354  * We don't have to do anything here,
1355  * just let console support handle everything
1356  */
1357 void WINAPI Death16(HDC16 hdc)
1358 {
1359     MESSAGE("Death(%04x) called. Application enters text mode...\n", hdc);
1360 }
1361
1362
1363 /***********************************************************************
1364  *           Resurrection    (GDI.122)
1365  *
1366  * Restores GDI functionality
1367  */
1368 void WINAPI Resurrection16(HDC16 hdc,
1369                            WORD w1, WORD w2, WORD w3, WORD w4, WORD w5, WORD w6)
1370 {
1371     MESSAGE("Resurrection(%04x, %04x, %04x, %04x, %04x, %04x, %04x) called. Application left text mode.\n",
1372             hdc, w1, w2, w3, w4, w5, w6);
1373 }
1374
1375
1376 /**********************************************************************
1377  *           CreateMetaFile     (GDI.125)
1378  */
1379 HDC16 WINAPI CreateMetaFile16( LPCSTR filename )
1380 {
1381     return HDC_16( CreateMetaFileA( filename ) );
1382 }
1383
1384
1385 /***********************************************************************
1386  *           MulDiv   (GDI.128)
1387  */
1388 INT16 WINAPI MulDiv16( INT16 nMultiplicand, INT16 nMultiplier, INT16 nDivisor)
1389 {
1390     INT ret;
1391     if (!nDivisor) return -32768;
1392     /* We want to deal with a positive divisor to simplify the logic. */
1393     if (nDivisor < 0)
1394     {
1395       nMultiplicand = - nMultiplicand;
1396       nDivisor = -nDivisor;
1397     }
1398     /* If the result is positive, we "add" to round. else,
1399      * we subtract to round. */
1400     if ( ( (nMultiplicand <  0) && (nMultiplier <  0) ) ||
1401          ( (nMultiplicand >= 0) && (nMultiplier >= 0) ) )
1402         ret = (((int)nMultiplicand * nMultiplier) + (nDivisor/2)) / nDivisor;
1403     else
1404         ret = (((int)nMultiplicand * nMultiplier) - (nDivisor/2)) / nDivisor;
1405     if ((ret > 32767) || (ret < -32767)) return -32768;
1406     return (INT16) ret;
1407 }
1408
1409
1410 /***********************************************************************
1411  *           GetRgnBox    (GDI.134)
1412  */
1413 INT16 WINAPI GetRgnBox16( HRGN16 hrgn, LPRECT16 rect )
1414 {
1415     RECT r;
1416     INT16 ret = GetRgnBox( HRGN_32(hrgn), &r );
1417     CONV_RECT32TO16( &r, rect );
1418     return ret;
1419 }
1420
1421
1422 /***********************************************************************
1423  *           RemoveFontResource    (GDI.136)
1424  */
1425 BOOL16 WINAPI RemoveFontResource16( LPCSTR str )
1426 {
1427     return RemoveFontResourceA(str);
1428 }
1429
1430
1431 /***********************************************************************
1432  *           SetBrushOrg    (GDI.148)
1433  */
1434 DWORD WINAPI SetBrushOrg16( HDC16 hdc, INT16 x, INT16 y )
1435 {
1436     POINT pt;
1437
1438     if (!SetBrushOrgEx( HDC_32(hdc), x, y, &pt )) return 0;
1439     return MAKELONG( pt.x, pt.y );
1440 }
1441
1442
1443 /***********************************************************************
1444  *              GetBrushOrg (GDI.149)
1445  */
1446 DWORD WINAPI GetBrushOrg16( HDC16 hdc )
1447 {
1448     POINT pt;
1449     if (!GetBrushOrgEx( HDC_32(hdc), &pt )) return 0;
1450     return MAKELONG( pt.x, pt.y );
1451 }
1452
1453
1454 /***********************************************************************
1455  *           UnrealizeObject    (GDI.150)
1456  */
1457 BOOL16 WINAPI UnrealizeObject16( HGDIOBJ16 obj )
1458 {
1459     return UnrealizeObject( HGDIOBJ_32(obj) );
1460 }
1461
1462
1463 /***********************************************************************
1464  *           CreateIC    (GDI.153)
1465  */
1466 HDC16 WINAPI CreateIC16( LPCSTR driver, LPCSTR device, LPCSTR output,
1467                          const DEVMODEA* initData )
1468 {
1469     return HDC_16( CreateICA( driver, device, output, initData ) );
1470 }
1471
1472
1473 /***********************************************************************
1474  *           GetNearestColor   (GDI.154)
1475  */
1476 COLORREF WINAPI GetNearestColor16( HDC16 hdc, COLORREF color )
1477 {
1478     return GetNearestColor( HDC_32(hdc), color );
1479 }
1480
1481
1482 /***********************************************************************
1483  *           CreateDiscardableBitmap    (GDI.156)
1484  */
1485 HBITMAP16 WINAPI CreateDiscardableBitmap16( HDC16 hdc, INT16 width, INT16 height )
1486 {
1487     return HBITMAP_16( CreateDiscardableBitmap( HDC_32(hdc), width, height ) );
1488 }
1489
1490
1491 /***********************************************************************
1492  *           PtInRegion    (GDI.161)
1493  */
1494 BOOL16 WINAPI PtInRegion16( HRGN16 hrgn, INT16 x, INT16 y )
1495 {
1496     return PtInRegion( HRGN_32(hrgn), x, y );
1497 }
1498
1499
1500 /***********************************************************************
1501  *           GetBitmapDimension    (GDI.162)
1502  */
1503 DWORD WINAPI GetBitmapDimension16( HBITMAP16 hbitmap )
1504 {
1505     SIZE16 size;
1506     if (!GetBitmapDimensionEx16( hbitmap, &size )) return 0;
1507     return MAKELONG( size.cx, size.cy );
1508 }
1509
1510
1511 /***********************************************************************
1512  *           SetBitmapDimension    (GDI.163)
1513  */
1514 DWORD WINAPI SetBitmapDimension16( HBITMAP16 hbitmap, INT16 x, INT16 y )
1515 {
1516     SIZE16 size;
1517     if (!SetBitmapDimensionEx16( hbitmap, x, y, &size )) return 0;
1518     return MAKELONG( size.cx, size.cy );
1519 }
1520
1521
1522 /***********************************************************************
1523  *           SetRectRgn    (GDI.172)
1524  *
1525  * NOTE: Win 3.1 sets region to empty if left > right
1526  */
1527 void WINAPI SetRectRgn16( HRGN16 hrgn, INT16 left, INT16 top, INT16 right, INT16 bottom )
1528 {
1529     if (left < right) SetRectRgn( HRGN_32(hrgn), left, top, right, bottom );
1530     else SetRectRgn( HRGN_32(hrgn), 0, 0, 0, 0 );
1531 }
1532
1533
1534 /******************************************************************
1535  *             PlayMetaFileRecord   (GDI.176)
1536  */
1537 void WINAPI PlayMetaFileRecord16( HDC16 hdc, HANDLETABLE16 *ht, METARECORD *mr, UINT16 handles )
1538 {
1539     HANDLETABLE *ht32 = HeapAlloc( GetProcessHeap(), 0, handles * sizeof(*ht32) );
1540     unsigned int i;
1541
1542     for (i = 0; i < handles; i++) ht32->objectHandle[i] = (HGDIOBJ)(ULONG_PTR)ht->objectHandle[i];
1543     PlayMetaFileRecord( HDC_32(hdc), ht32, mr, handles );
1544     for (i = 0; i < handles; i++) ht->objectHandle[i] = LOWORD(ht32->objectHandle[i]);
1545     HeapFree( GetProcessHeap(), 0, ht32 );
1546 }
1547
1548
1549 /***********************************************************************
1550  *           SetBoundsRect    (GDI.193)
1551  */
1552 UINT16 WINAPI SetBoundsRect16( HDC16 hdc, const RECT16* rect, UINT16 flags )
1553 {
1554     if (rect)
1555     {
1556         RECT rect32;
1557         CONV_RECT16TO32( rect, &rect32 );
1558         return SetBoundsRect( HDC_32( hdc ), &rect32, flags );
1559     }
1560     else return SetBoundsRect( HDC_32( hdc ), NULL, flags );
1561 }
1562
1563
1564 /***********************************************************************
1565  *           GetBoundsRect    (GDI.194)
1566  */
1567 UINT16 WINAPI GetBoundsRect16( HDC16 hdc, LPRECT16 rect, UINT16 flags)
1568 {
1569     RECT rect32;
1570     UINT ret = GetBoundsRect( HDC_32( hdc ), &rect32, flags );
1571     if (rect) CONV_RECT32TO16( &rect32, rect );
1572     return ret;
1573 }
1574
1575
1576 /***********************************************************************
1577  *              EngineEnumerateFont (GDI.300)
1578  */
1579 WORD WINAPI EngineEnumerateFont16(LPSTR fontname, FARPROC16 proc, DWORD data )
1580 {
1581     FIXME("(%s,%p,%lx),stub\n",fontname,proc,data);
1582     return 0;
1583 }
1584
1585
1586 /***********************************************************************
1587  *              EngineDeleteFont (GDI.301)
1588  */
1589 WORD WINAPI EngineDeleteFont16(LPFONTINFO16 lpFontInfo)
1590 {
1591     WORD handle;
1592
1593     /*  untested, don't know if it works.
1594         We seem to access some structure that is located after the
1595         FONTINFO. The FONTINFO documentation says that there may
1596         follow some char-width table or font bitmap or vector info.
1597         I think it is some kind of font bitmap that begins at offset 0x52,
1598         as FONTINFO goes up to 0x51.
1599         If this is correct, everything should be implemented correctly.
1600     */
1601     if ( ((lpFontInfo->dfType & (RASTER_FONTTYPE|DEVICE_FONTTYPE)) == (RASTER_FONTTYPE|DEVICE_FONTTYPE))
1602          && (LOWORD(lpFontInfo->dfFace) == LOWORD(lpFontInfo)+0x6e)
1603          && (handle = *(WORD *)(lpFontInfo+0x54)) )
1604     {
1605         *(WORD *)(lpFontInfo+0x54) = 0;
1606         GlobalFree16(handle);
1607     }
1608     return 1;
1609 }
1610
1611
1612 /***********************************************************************
1613  *              EngineRealizeFont (GDI.302)
1614  */
1615 WORD WINAPI EngineRealizeFont16(LPLOGFONT16 lplogFont, LPTEXTXFORM16 lptextxform, LPFONTINFO16 lpfontInfo)
1616 {
1617     FIXME("(%p,%p,%p),stub\n",lplogFont,lptextxform,lpfontInfo);
1618
1619     return 0;
1620 }
1621
1622
1623 /***********************************************************************
1624  *              EngineRealizeFontExt (GDI.315)
1625  */
1626 WORD WINAPI EngineRealizeFontExt16(LONG l1, LONG l2, LONG l3, LONG l4)
1627 {
1628     FIXME("(%08lx,%08lx,%08lx,%08lx),stub\n",l1,l2,l3,l4);
1629
1630     return 0;
1631 }
1632
1633
1634 /***********************************************************************
1635  *              EngineGetCharWidth (GDI.303)
1636  */
1637 WORD WINAPI EngineGetCharWidth16(LPFONTINFO16 lpFontInfo, BYTE firstChar, BYTE lastChar, LPINT16 buffer)
1638 {
1639     int i;
1640
1641     for (i = firstChar; i <= lastChar; i++)
1642        FIXME(" returns font's average width for range %d to %d\n", firstChar, lastChar);
1643     *buffer++ = lpFontInfo->dfAvgWidth; /* insert some charwidth functionality here; use average width for now */
1644     return 1;
1645 }
1646
1647
1648 /***********************************************************************
1649  *              EngineSetFontContext (GDI.304)
1650  */
1651 WORD WINAPI EngineSetFontContext(LPFONTINFO16 lpFontInfo, WORD data)
1652 {
1653    FIXME("stub?\n");
1654    return 0;
1655 }
1656
1657 /***********************************************************************
1658  *              EngineGetGlyphBMP (GDI.305)
1659  */
1660 WORD WINAPI EngineGetGlyphBMP(WORD word, LPFONTINFO16 lpFontInfo, WORD w1, WORD w2,
1661                               LPSTR string, DWORD dword, /*LPBITMAPMETRICS16*/ LPVOID metrics)
1662 {
1663     FIXME("stub?\n");
1664     return 0;
1665 }
1666
1667
1668 /***********************************************************************
1669  *              EngineMakeFontDir (GDI.306)
1670  */
1671 DWORD WINAPI EngineMakeFontDir(HDC16 hdc, LPFONTDIR16 fontdir, LPCSTR string)
1672 {
1673     FIXME(" stub! (always fails)\n");
1674     return ~0UL; /* error */
1675 }
1676
1677
1678 /***********************************************************************
1679  *           GetCharABCWidths   (GDI.307)
1680  */
1681 BOOL16 WINAPI GetCharABCWidths16( HDC16 hdc, UINT16 firstChar, UINT16 lastChar, LPABC16 abc )
1682 {
1683     BOOL ret;
1684     UINT i;
1685     LPABC abc32 = HeapAlloc( GetProcessHeap(), 0, sizeof(ABC) * (lastChar - firstChar + 1) );
1686
1687     if ((ret = GetCharABCWidthsA( HDC_32(hdc), firstChar, lastChar, abc32 )))
1688     {
1689         for (i = firstChar; i <= lastChar; i++)
1690         {
1691             abc[i-firstChar].abcA = abc32[i-firstChar].abcA;
1692             abc[i-firstChar].abcB = abc32[i-firstChar].abcB;
1693             abc[i-firstChar].abcC = abc32[i-firstChar].abcC;
1694         }
1695     }
1696     HeapFree( GetProcessHeap(), 0, abc32 );
1697     return ret;
1698 }
1699
1700
1701 /***********************************************************************
1702  *           CreateScalableFontResource   (GDI.310)
1703  */
1704 BOOL16 WINAPI CreateScalableFontResource16( UINT16 fHidden, LPCSTR lpszResourceFile,
1705                                             LPCSTR fontFile, LPCSTR path )
1706 {
1707     return CreateScalableFontResourceA( fHidden, lpszResourceFile, fontFile, path );
1708 }
1709
1710
1711 /*************************************************************************
1712  *             GetFontData    (GDI.311)
1713  *
1714  */
1715 DWORD WINAPI GetFontData16( HDC16 hdc, DWORD table, DWORD offset, LPVOID buffer, DWORD count )
1716 {
1717     return GetFontData( HDC_32(hdc), table, offset, buffer, count );
1718 }
1719
1720
1721 /*************************************************************************
1722  *             GetRasterizerCaps   (GDI.313)
1723  */
1724 BOOL16 WINAPI GetRasterizerCaps16( LPRASTERIZER_STATUS lprs, UINT16 cbNumBytes )
1725 {
1726     return GetRasterizerCaps( lprs, cbNumBytes );
1727 }
1728
1729
1730 /*************************************************************************
1731  *             GetKerningPairs   (GDI.332)
1732  *
1733  */
1734 INT16 WINAPI GetKerningPairs16( HDC16 hdc, INT16 count, LPKERNINGPAIR16 pairs )
1735 {
1736     KERNINGPAIR *pairs32;
1737     INT i, ret;
1738
1739     if (!count) return 0;
1740
1741     if (!(pairs32 = HeapAlloc( GetProcessHeap(), 0, count * sizeof(*pairs32) ))) return 0;
1742     if ((ret = GetKerningPairsA( HDC_32(hdc), count, pairs32 )))
1743     {
1744         for (i = 0; i < ret; i++)
1745         {
1746             pairs->wFirst      = pairs32->wFirst;
1747             pairs->wSecond     = pairs32->wSecond;
1748             pairs->iKernAmount = pairs32->iKernAmount;
1749         }
1750     }
1751     HeapFree( GetProcessHeap(), 0, pairs32 );
1752     return ret;
1753 }
1754
1755
1756
1757 /***********************************************************************
1758  *              GetTextAlign (GDI.345)
1759  */
1760 UINT16 WINAPI GetTextAlign16( HDC16 hdc )
1761 {
1762     return GetTextAlign( HDC_32(hdc) );
1763 }
1764
1765
1766 /***********************************************************************
1767  *           SetTextAlign    (GDI.346)
1768  */
1769 UINT16 WINAPI SetTextAlign16( HDC16 hdc, UINT16 align )
1770 {
1771     return SetTextAlign( HDC_32(hdc), align );
1772 }
1773
1774
1775 /***********************************************************************
1776  *           Chord    (GDI.348)
1777  */
1778 BOOL16 WINAPI Chord16( HDC16 hdc, INT16 left, INT16 top,
1779                        INT16 right, INT16 bottom, INT16 xstart, INT16 ystart,
1780                        INT16 xend, INT16 yend )
1781 {
1782     return Chord( HDC_32(hdc), left, top, right, bottom, xstart, ystart, xend, yend );
1783 }
1784
1785
1786 /***********************************************************************
1787  *           SetMapperFlags    (GDI.349)
1788  */
1789 DWORD WINAPI SetMapperFlags16( HDC16 hdc, DWORD flags )
1790 {
1791     return SetMapperFlags( HDC_32(hdc), flags );
1792 }
1793
1794
1795 /***********************************************************************
1796  *           GetCharWidth    (GDI.350)
1797  */
1798 BOOL16 WINAPI GetCharWidth16( HDC16 hdc, UINT16 firstChar, UINT16 lastChar, LPINT16 buffer )
1799 {
1800     BOOL retVal = FALSE;
1801
1802     if( firstChar != lastChar )
1803     {
1804         LPINT buf32 = HeapAlloc(GetProcessHeap(), 0, sizeof(INT)*(1 + (lastChar - firstChar)));
1805         if( buf32 )
1806         {
1807             LPINT obuf32 = buf32;
1808             int i;
1809
1810             retVal = GetCharWidth32A( HDC_32(hdc), firstChar, lastChar, buf32);
1811             if (retVal)
1812             {
1813                 for (i = firstChar; i <= lastChar; i++) *buffer++ = *buf32++;
1814             }
1815             HeapFree(GetProcessHeap(), 0, obuf32);
1816         }
1817     }
1818     else /* happens quite often to warrant a special treatment */
1819     {
1820         INT chWidth;
1821         retVal = GetCharWidth32A( HDC_32(hdc), firstChar, lastChar, &chWidth );
1822         *buffer = chWidth;
1823     }
1824     return retVal;
1825 }
1826
1827
1828 /***********************************************************************
1829  *           ExtTextOut   (GDI.351)
1830  */
1831 BOOL16 WINAPI ExtTextOut16( HDC16 hdc, INT16 x, INT16 y, UINT16 flags,
1832                             const RECT16 *lprect, LPCSTR str, UINT16 count,
1833                             const INT16 *lpDx )
1834 {
1835     BOOL        ret;
1836     int         i;
1837     RECT        rect32;
1838     LPINT       lpdx32 = NULL;
1839
1840     if (lpDx) {
1841         lpdx32 = (LPINT)HeapAlloc( GetProcessHeap(),0, sizeof(INT)*count );
1842         if(lpdx32 == NULL) return FALSE;
1843         for (i=count;i--;) lpdx32[i]=lpDx[i];
1844     }
1845     if (lprect) CONV_RECT16TO32(lprect,&rect32);
1846     ret = ExtTextOutA(HDC_32(hdc),x,y,flags,lprect?&rect32:NULL,str,count,lpdx32);
1847     if (lpdx32) HeapFree( GetProcessHeap(), 0, lpdx32 );
1848     return ret;
1849 }
1850
1851
1852 /***********************************************************************
1853  *           CreatePalette    (GDI.360)
1854  */
1855 HPALETTE16 WINAPI CreatePalette16( const LOGPALETTE* palette )
1856 {
1857     return HPALETTE_16( CreatePalette( palette ) );
1858 }
1859
1860
1861 /***********************************************************************
1862  *           GDISelectPalette   (GDI.361)
1863  */
1864 HPALETTE16 WINAPI GDISelectPalette16( HDC16 hdc, HPALETTE16 hpalette, WORD wBkg )
1865 {
1866     return HPALETTE_16( GDISelectPalette( HDC_32(hdc), HPALETTE_32(hpalette), wBkg ));
1867 }
1868
1869
1870 /***********************************************************************
1871  *           GDIRealizePalette   (GDI.362)
1872  */
1873 UINT16 WINAPI GDIRealizePalette16( HDC16 hdc )
1874 {
1875     return GDIRealizePalette( HDC_32(hdc) );
1876 }
1877
1878
1879 /***********************************************************************
1880  *           GetPaletteEntries    (GDI.363)
1881  */
1882 UINT16 WINAPI GetPaletteEntries16( HPALETTE16 hpalette, UINT16 start,
1883                                    UINT16 count, LPPALETTEENTRY entries )
1884 {
1885     return GetPaletteEntries( HPALETTE_32(hpalette), start, count, entries );
1886 }
1887
1888
1889 /***********************************************************************
1890  *           SetPaletteEntries    (GDI.364)
1891  */
1892 UINT16 WINAPI SetPaletteEntries16( HPALETTE16 hpalette, UINT16 start,
1893                                    UINT16 count, const PALETTEENTRY *entries )
1894 {
1895     return SetPaletteEntries( HPALETTE_32(hpalette), start, count, entries );
1896 }
1897
1898
1899 /**********************************************************************
1900  *            UpdateColors   (GDI.366)
1901  */
1902 INT16 WINAPI UpdateColors16( HDC16 hdc )
1903 {
1904     UpdateColors( HDC_32(hdc) );
1905     return TRUE;
1906 }
1907
1908
1909 /***********************************************************************
1910  *           AnimatePalette   (GDI.367)
1911  */
1912 void WINAPI AnimatePalette16( HPALETTE16 hpalette, UINT16 StartIndex,
1913                               UINT16 NumEntries, const PALETTEENTRY* PaletteColors)
1914 {
1915     AnimatePalette( HPALETTE_32(hpalette), StartIndex, NumEntries, PaletteColors );
1916 }
1917
1918
1919 /***********************************************************************
1920  *           ResizePalette   (GDI.368)
1921  */
1922 BOOL16 WINAPI ResizePalette16( HPALETTE16 hpalette, UINT16 cEntries )
1923 {
1924     return ResizePalette( HPALETTE_32(hpalette), cEntries );
1925 }
1926
1927
1928 /***********************************************************************
1929  *           GetNearestPaletteIndex   (GDI.370)
1930  */
1931 UINT16 WINAPI GetNearestPaletteIndex16( HPALETTE16 hpalette, COLORREF color )
1932 {
1933     return GetNearestPaletteIndex( HPALETTE_32(hpalette), color );
1934 }
1935
1936
1937 /**********************************************************************
1938  *          ExtFloodFill   (GDI.372)
1939  */
1940 BOOL16 WINAPI ExtFloodFill16( HDC16 hdc, INT16 x, INT16 y, COLORREF color,
1941                               UINT16 fillType )
1942 {
1943     return ExtFloodFill( HDC_32(hdc), x, y, color, fillType );
1944 }
1945
1946
1947 /***********************************************************************
1948  *           SetSystemPaletteUse   (GDI.373)
1949  */
1950 UINT16 WINAPI SetSystemPaletteUse16( HDC16 hdc, UINT16 use )
1951 {
1952     return SetSystemPaletteUse( HDC_32(hdc), use );
1953 }
1954
1955
1956 /***********************************************************************
1957  *           GetSystemPaletteUse   (GDI.374)
1958  */
1959 UINT16 WINAPI GetSystemPaletteUse16( HDC16 hdc )
1960 {
1961     return GetSystemPaletteUse( HDC_32(hdc) );
1962 }
1963
1964
1965 /***********************************************************************
1966  *           GetSystemPaletteEntries   (GDI.375)
1967  */
1968 UINT16 WINAPI GetSystemPaletteEntries16( HDC16 hdc, UINT16 start, UINT16 count,
1969                                          LPPALETTEENTRY entries )
1970 {
1971     return GetSystemPaletteEntries( HDC_32(hdc), start, count, entries );
1972 }
1973
1974
1975 /***********************************************************************
1976  *           ResetDC    (GDI.376)
1977  */
1978 HDC16 WINAPI ResetDC16( HDC16 hdc, const DEVMODEA *devmode )
1979 {
1980     return HDC_16( ResetDCA(HDC_32(hdc), devmode) );
1981 }
1982
1983
1984 /******************************************************************
1985  *           StartDoc   (GDI.377)
1986  */
1987 INT16 WINAPI StartDoc16( HDC16 hdc, const DOCINFO16 *lpdoc )
1988 {
1989     DOCINFOA docA;
1990
1991     docA.cbSize = lpdoc->cbSize;
1992     docA.lpszDocName = MapSL(lpdoc->lpszDocName);
1993     docA.lpszOutput = MapSL(lpdoc->lpszOutput);
1994     if(lpdoc->cbSize > offsetof(DOCINFO16,lpszDatatype))
1995         docA.lpszDatatype = MapSL(lpdoc->lpszDatatype);
1996     else
1997         docA.lpszDatatype = NULL;
1998     if(lpdoc->cbSize > offsetof(DOCINFO16,fwType))
1999         docA.fwType = lpdoc->fwType;
2000     else
2001         docA.fwType = 0;
2002     return StartDocA( HDC_32(hdc), &docA );
2003 }
2004
2005
2006 /******************************************************************
2007  *           EndDoc   (GDI.378)
2008  */
2009 INT16 WINAPI EndDoc16( HDC16 hdc )
2010 {
2011     return EndDoc( HDC_32(hdc) );
2012 }
2013
2014
2015 /******************************************************************
2016  *           StartPage   (GDI.379)
2017  */
2018 INT16 WINAPI StartPage16( HDC16 hdc )
2019 {
2020     return StartPage( HDC_32(hdc) );
2021 }
2022
2023
2024 /******************************************************************
2025  *           EndPage   (GDI.380)
2026  */
2027 INT16 WINAPI EndPage16( HDC16 hdc )
2028 {
2029     return EndPage( HDC_32(hdc) );
2030 }
2031
2032
2033 /******************************************************************************
2034  *           AbortDoc   (GDI.382)
2035  */
2036 INT16 WINAPI AbortDoc16( HDC16 hdc )
2037 {
2038     return AbortDoc( HDC_32(hdc) );
2039 }
2040
2041
2042 /***********************************************************************
2043  *           FastWindowFrame    (GDI.400)
2044  */
2045 BOOL16 WINAPI FastWindowFrame16( HDC16 hdc, const RECT16 *rect,
2046                                INT16 width, INT16 height, DWORD rop )
2047 {
2048     HDC hdc32 = HDC_32(hdc);
2049     HBRUSH hbrush = SelectObject( hdc32, GetStockObject( GRAY_BRUSH ) );
2050     PatBlt( hdc32, rect->left, rect->top,
2051             rect->right - rect->left - width, height, rop );
2052     PatBlt( hdc32, rect->left, rect->top + height, width,
2053             rect->bottom - rect->top - height, rop );
2054     PatBlt( hdc32, rect->left + width, rect->bottom - 1,
2055             rect->right - rect->left - width, -height, rop );
2056     PatBlt( hdc32, rect->right - 1, rect->top, -width,
2057             rect->bottom - rect->top - height, rop );
2058     SelectObject( hdc32, hbrush );
2059     return TRUE;
2060 }
2061
2062
2063 /***********************************************************************
2064  *           CreateUserBitmap    (GDI.407)
2065  */
2066 HBITMAP16 WINAPI CreateUserBitmap16( INT16 width, INT16 height, UINT16 planes,
2067                                      UINT16 bpp, LPCVOID bits )
2068 {
2069     return CreateBitmap16( width, height, planes, bpp, bits );
2070 }
2071
2072
2073 /***********************************************************************
2074  *           CreateUserDiscardableBitmap    (GDI.409)
2075  */
2076 HBITMAP16 WINAPI CreateUserDiscardableBitmap16( WORD dummy, INT16 width, INT16 height )
2077 {
2078     HDC hdc = CreateDCA( "DISPLAY", NULL, NULL, NULL );
2079     HBITMAP ret = CreateCompatibleBitmap( hdc, width, height );
2080     DeleteDC( hdc );
2081     return HBITMAP_16(ret);
2082 }
2083
2084
2085 /***********************************************************************
2086  *              GetCurLogFont (GDI.411)
2087  */
2088 HFONT16 WINAPI GetCurLogFont16( HDC16 hdc )
2089 {
2090     return HFONT_16( GetCurrentObject( HDC_32(hdc), OBJ_FONT ) );
2091 }
2092
2093
2094 /***********************************************************************
2095  *           StretchDIBits   (GDI.439)
2096  */
2097 INT16 WINAPI StretchDIBits16( HDC16 hdc, INT16 xDst, INT16 yDst, INT16 widthDst,
2098                               INT16 heightDst, INT16 xSrc, INT16 ySrc, INT16 widthSrc,
2099                               INT16 heightSrc, const VOID *bits,
2100                               const BITMAPINFO *info, UINT16 wUsage, DWORD dwRop )
2101 {
2102     return StretchDIBits( HDC_32(hdc), xDst, yDst, widthDst, heightDst,
2103                           xSrc, ySrc, widthSrc, heightSrc, bits,
2104                           info, wUsage, dwRop );
2105 }
2106
2107
2108 /***********************************************************************
2109  *           SetDIBits    (GDI.440)
2110  */
2111 INT16 WINAPI SetDIBits16( HDC16 hdc, HBITMAP16 hbitmap, UINT16 startscan,
2112                           UINT16 lines, LPCVOID bits, const BITMAPINFO *info,
2113                           UINT16 coloruse )
2114 {
2115     return SetDIBits( HDC_32(hdc), HBITMAP_32(hbitmap), startscan, lines, bits, info, coloruse );
2116 }
2117
2118
2119 /***********************************************************************
2120  *           GetDIBits    (GDI.441)
2121  */
2122 INT16 WINAPI GetDIBits16( HDC16 hdc, HBITMAP16 hbitmap, UINT16 startscan,
2123                           UINT16 lines, LPVOID bits, BITMAPINFO * info,
2124                           UINT16 coloruse )
2125 {
2126     return GetDIBits( HDC_32(hdc), HBITMAP_32(hbitmap), startscan, lines, bits, info, coloruse );
2127 }
2128
2129
2130 /***********************************************************************
2131  *           CreateDIBitmap    (GDI.442)
2132  */
2133 HBITMAP16 WINAPI CreateDIBitmap16( HDC16 hdc, const BITMAPINFOHEADER * header,
2134                                    DWORD init, LPCVOID bits, const BITMAPINFO * data,
2135                                    UINT16 coloruse )
2136 {
2137     return HBITMAP_16( CreateDIBitmap( HDC_32(hdc), header, init, bits, data, coloruse ) );
2138 }
2139
2140
2141 /***********************************************************************
2142  *           SetDIBitsToDevice    (GDI.443)
2143  */
2144 INT16 WINAPI SetDIBitsToDevice16( HDC16 hdc, INT16 xDest, INT16 yDest, INT16 cx,
2145                                   INT16 cy, INT16 xSrc, INT16 ySrc, UINT16 startscan,
2146                                   UINT16 lines, LPCVOID bits, const BITMAPINFO *info,
2147                                   UINT16 coloruse )
2148 {
2149     return SetDIBitsToDevice( HDC_32(hdc), xDest, yDest, cx, cy, xSrc, ySrc,
2150                               startscan, lines, bits, info, coloruse );
2151 }
2152
2153
2154 /***********************************************************************
2155  *           CreateRoundRectRgn    (GDI.444)
2156  *
2157  * If either ellipse dimension is zero we call CreateRectRgn16 for its
2158  * `special' behaviour. -ve ellipse dimensions can result in GPFs under win3.1
2159  * we just let CreateRoundRectRgn convert them to +ve values.
2160  */
2161
2162 HRGN16 WINAPI CreateRoundRectRgn16( INT16 left, INT16 top, INT16 right, INT16 bottom,
2163                                     INT16 ellipse_width, INT16 ellipse_height )
2164 {
2165     if( ellipse_width == 0 || ellipse_height == 0 )
2166         return CreateRectRgn16( left, top, right, bottom );
2167     else
2168         return HRGN_16( CreateRoundRectRgn( left, top, right, bottom,
2169                                             ellipse_width, ellipse_height ));
2170 }
2171
2172
2173 /***********************************************************************
2174  *           CreateDIBPatternBrush    (GDI.445)
2175  */
2176 HBRUSH16 WINAPI CreateDIBPatternBrush16( HGLOBAL16 hbitmap, UINT16 coloruse )
2177 {
2178     BITMAPINFO *bmi;
2179     HBRUSH16 ret;
2180
2181     if (!(bmi = GlobalLock16( hbitmap ))) return 0;
2182     ret = HBRUSH_16( CreateDIBPatternBrushPt( bmi, coloruse ));
2183     GlobalUnlock16( hbitmap );
2184     return ret;
2185 }
2186
2187
2188 /**********************************************************************
2189  *          PolyPolygon (GDI.450)
2190  */
2191 BOOL16 WINAPI PolyPolygon16( HDC16 hdc, const POINT16* pt, const INT16* counts,
2192                              UINT16 polygons )
2193 {
2194     int         i,nrpts;
2195     LPPOINT     pt32;
2196     LPINT       counts32;
2197     BOOL16      ret;
2198
2199     nrpts=0;
2200     for (i=polygons;i--;)
2201         nrpts+=counts[i];
2202     pt32 = (LPPOINT)HeapAlloc( GetProcessHeap(), 0, sizeof(POINT)*nrpts);
2203     if(pt32 == NULL) return FALSE;
2204     for (i=nrpts;i--;)
2205         CONV_POINT16TO32(&(pt[i]),&(pt32[i]));
2206     counts32 = (LPINT)HeapAlloc( GetProcessHeap(), 0, polygons*sizeof(INT) );
2207     if(counts32 == NULL) {
2208         HeapFree( GetProcessHeap(), 0, pt32 );
2209         return FALSE;
2210     }
2211     for (i=polygons;i--;) counts32[i]=counts[i];
2212
2213     ret = PolyPolygon(HDC_32(hdc),pt32,counts32,polygons);
2214     HeapFree( GetProcessHeap(), 0, counts32 );
2215     HeapFree( GetProcessHeap(), 0, pt32 );
2216     return ret;
2217 }
2218
2219
2220 /***********************************************************************
2221  *           CreatePolyPolygonRgn    (GDI.451)
2222  */
2223 HRGN16 WINAPI CreatePolyPolygonRgn16( const POINT16 *points,
2224                                       const INT16 *count, INT16 nbpolygons, INT16 mode )
2225 {
2226     HRGN hrgn;
2227     int i, npts = 0;
2228     INT *count32;
2229     POINT *points32;
2230
2231     for (i = 0; i < nbpolygons; i++) npts += count[i];
2232     points32 = HeapAlloc( GetProcessHeap(), 0, npts * sizeof(POINT) );
2233     for (i = 0; i < npts; i++) CONV_POINT16TO32( &(points[i]), &(points32[i]) );
2234
2235     count32 = HeapAlloc( GetProcessHeap(), 0, nbpolygons * sizeof(INT) );
2236     for (i = 0; i < nbpolygons; i++) count32[i] = count[i];
2237     hrgn = CreatePolyPolygonRgn( points32, count32, nbpolygons, mode );
2238     HeapFree( GetProcessHeap(), 0, count32 );
2239     HeapFree( GetProcessHeap(), 0, points32 );
2240     return HRGN_16(hrgn);
2241 }
2242
2243
2244 /***********************************************************************
2245  *           SetObjectOwner    (GDI.461)
2246  */
2247 void WINAPI SetObjectOwner16( HGDIOBJ16 handle, HANDLE16 owner )
2248 {
2249     /* Nothing to do */
2250 }
2251
2252
2253 /***********************************************************************
2254  *           RectVisible    (GDI.465)
2255  *           RectVisibleOld (GDI.104)
2256  */
2257 BOOL16 WINAPI RectVisible16( HDC16 hdc, const RECT16* rect16 )
2258 {
2259     RECT rect;
2260     CONV_RECT16TO32( rect16, &rect );
2261     return RectVisible( HDC_32(hdc), &rect );
2262 }
2263
2264
2265 /***********************************************************************
2266  *           RectInRegion    (GDI.466)
2267  *           RectInRegionOld (GDI.181)
2268  */
2269 BOOL16 WINAPI RectInRegion16( HRGN16 hrgn, const RECT16 *rect )
2270 {
2271     RECT r32;
2272
2273     CONV_RECT16TO32(rect, &r32);
2274     return RectInRegion( HRGN_32(hrgn), &r32 );
2275 }
2276
2277
2278 /***********************************************************************
2279  *           GetBitmapDimensionEx    (GDI.468)
2280  */
2281 BOOL16 WINAPI GetBitmapDimensionEx16( HBITMAP16 hbitmap, LPSIZE16 size )
2282 {
2283     SIZE size32;
2284     BOOL ret = GetBitmapDimensionEx( HBITMAP_32(hbitmap), &size32 );
2285
2286     if (ret)
2287     {
2288         size->cx = size32.cx;
2289         size->cy = size32.cy;
2290     }
2291     return ret;
2292 }
2293
2294
2295 /***********************************************************************
2296  *              GetBrushOrgEx (GDI.469)
2297  */
2298 BOOL16 WINAPI GetBrushOrgEx16( HDC16 hdc, LPPOINT16 pt )
2299 {
2300     POINT pt32;
2301     if (!GetBrushOrgEx( HDC_32(hdc), &pt32 )) return FALSE;
2302     pt->x = pt32.x;
2303     pt->y = pt32.y;
2304     return TRUE;
2305 }
2306
2307
2308 /***********************************************************************
2309  *              GetCurrentPositionEx (GDI.470)
2310  */
2311 BOOL16 WINAPI GetCurrentPositionEx16( HDC16 hdc, LPPOINT16 pt )
2312 {
2313     POINT pt32;
2314     if (!GetCurrentPositionEx( HDC_32(hdc), &pt32 )) return FALSE;
2315     pt->x = pt32.x;
2316     pt->y = pt32.y;
2317     return TRUE;
2318 }
2319
2320
2321 /***********************************************************************
2322  *           GetTextExtentPoint    (GDI.471)
2323  *
2324  * FIXME: Should this have a bug for compatibility?
2325  * Original Windows versions of GetTextExtentPoint{A,W} have documented
2326  * bugs (-> MSDN KB q147647.txt).
2327  */
2328 BOOL16 WINAPI GetTextExtentPoint16( HDC16 hdc, LPCSTR str, INT16 count, LPSIZE16 size )
2329 {
2330     SIZE size32;
2331     BOOL ret = GetTextExtentPoint32A( HDC_32(hdc), str, count, &size32 );
2332
2333     if (ret)
2334     {
2335         size->cx = size32.cx;
2336         size->cy = size32.cy;
2337     }
2338     return ret;
2339 }
2340
2341
2342 /***********************************************************************
2343  *              GetViewportExtEx (GDI.472)
2344  */
2345 BOOL16 WINAPI GetViewportExtEx16( HDC16 hdc, LPSIZE16 size )
2346 {
2347     SIZE size32;
2348     if (!GetViewportExtEx( HDC_32(hdc), &size32 )) return FALSE;
2349     size->cx = size32.cx;
2350     size->cy = size32.cy;
2351     return TRUE;
2352 }
2353
2354
2355 /***********************************************************************
2356  *              GetViewportOrgEx (GDI.473)
2357  */
2358 BOOL16 WINAPI GetViewportOrgEx16( HDC16 hdc, LPPOINT16 pt )
2359 {
2360     POINT pt32;
2361     if (!GetViewportOrgEx( HDC_32(hdc), &pt32 )) return FALSE;
2362     pt->x = pt32.x;
2363     pt->y = pt32.y;
2364     return TRUE;
2365 }
2366
2367
2368 /***********************************************************************
2369  *              GetWindowExtEx (GDI.474)
2370  */
2371 BOOL16 WINAPI GetWindowExtEx16( HDC16 hdc, LPSIZE16 size )
2372 {
2373     SIZE size32;
2374     if (!GetWindowExtEx( HDC_32(hdc), &size32 )) return FALSE;
2375     size->cx = size32.cx;
2376     size->cy = size32.cy;
2377     return TRUE;
2378 }
2379
2380
2381 /***********************************************************************
2382  *              GetWindowOrgEx (GDI.475)
2383  */
2384 BOOL16 WINAPI GetWindowOrgEx16( HDC16 hdc, LPPOINT16 pt )
2385 {
2386     POINT pt32;
2387     if (!GetWindowOrgEx( HDC_32(hdc), &pt32 )) return FALSE;
2388     pt->x = pt32.x;
2389     pt->y = pt32.y;
2390     return TRUE;
2391 }
2392
2393
2394 /***********************************************************************
2395  *           OffsetViewportOrgEx    (GDI.476)
2396  */
2397 BOOL16 WINAPI OffsetViewportOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt)
2398 {
2399     POINT pt32;
2400     BOOL16 ret = OffsetViewportOrgEx( HDC_32(hdc), x, y, &pt32 );
2401     if (pt) CONV_POINT32TO16( &pt32, pt );
2402     return ret;
2403 }
2404
2405
2406 /***********************************************************************
2407  *           OffsetWindowOrgEx    (GDI.477)
2408  */
2409 BOOL16 WINAPI OffsetWindowOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt )
2410 {
2411     POINT pt32;
2412     BOOL16 ret = OffsetWindowOrgEx( HDC_32(hdc), x, y, &pt32 );
2413     if (pt) CONV_POINT32TO16( &pt32, pt );
2414     return ret;
2415 }
2416
2417
2418 /***********************************************************************
2419  *           SetBitmapDimensionEx    (GDI.478)
2420  */
2421 BOOL16 WINAPI SetBitmapDimensionEx16( HBITMAP16 hbitmap, INT16 x, INT16 y, LPSIZE16 prevSize )
2422 {
2423     SIZE size32;
2424     BOOL ret = SetBitmapDimensionEx( HBITMAP_32(hbitmap), x, y, &size32 );
2425
2426     if (ret && prevSize)
2427     {
2428         prevSize->cx = size32.cx;
2429         prevSize->cy = size32.cy;
2430     }
2431     return ret;
2432 }
2433
2434
2435 /***********************************************************************
2436  *           SetViewportExtEx    (GDI.479)
2437  */
2438 BOOL16 WINAPI SetViewportExtEx16( HDC16 hdc, INT16 x, INT16 y, LPSIZE16 size )
2439 {
2440     SIZE size32;
2441     BOOL16 ret = SetViewportExtEx( HDC_32(hdc), x, y, &size32 );
2442     if (size) { size->cx = size32.cx; size->cy = size32.cy; }
2443     return ret;
2444 }
2445
2446
2447 /***********************************************************************
2448  *           SetViewportOrgEx    (GDI.480)
2449  */
2450 BOOL16 WINAPI SetViewportOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt )
2451 {
2452     POINT pt32;
2453     BOOL16 ret = SetViewportOrgEx( HDC_32(hdc), x, y, &pt32 );
2454     if (pt) CONV_POINT32TO16( &pt32, pt );
2455     return ret;
2456 }
2457
2458
2459 /***********************************************************************
2460  *           SetWindowExtEx    (GDI.481)
2461  */
2462 BOOL16 WINAPI SetWindowExtEx16( HDC16 hdc, INT16 x, INT16 y, LPSIZE16 size )
2463 {
2464     SIZE size32;
2465     BOOL16 ret = SetWindowExtEx( HDC_32(hdc), x, y, &size32 );
2466     if (size) { size->cx = size32.cx; size->cy = size32.cy; }
2467     return ret;
2468 }
2469
2470
2471 /***********************************************************************
2472  *           SetWindowOrgEx    (GDI.482)
2473  */
2474 BOOL16 WINAPI SetWindowOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt )
2475 {
2476     POINT pt32;
2477     BOOL16 ret = SetWindowOrgEx( HDC_32(hdc), x, y, &pt32 );
2478     if (pt) CONV_POINT32TO16( &pt32, pt );
2479     return ret;
2480 }
2481
2482
2483 /***********************************************************************
2484  *           MoveToEx    (GDI.483)
2485  */
2486 BOOL16 WINAPI MoveToEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt )
2487 {
2488     POINT pt32;
2489
2490     if (!MoveToEx( HDC_32(hdc), x, y, &pt32 )) return FALSE;
2491     if (pt) CONV_POINT32TO16( &pt32, pt );
2492     return TRUE;
2493 }
2494
2495
2496 /***********************************************************************
2497  *           ScaleViewportExtEx    (GDI.484)
2498  */
2499 BOOL16 WINAPI ScaleViewportExtEx16( HDC16 hdc, INT16 xNum, INT16 xDenom,
2500                                     INT16 yNum, INT16 yDenom, LPSIZE16 size )
2501 {
2502     SIZE size32;
2503     BOOL16 ret = ScaleViewportExtEx( HDC_32(hdc), xNum, xDenom, yNum, yDenom,
2504                                        &size32 );
2505     if (size) { size->cx = size32.cx; size->cy = size32.cy; }
2506     return ret;
2507 }
2508
2509
2510 /***********************************************************************
2511  *           ScaleWindowExtEx    (GDI.485)
2512  */
2513 BOOL16 WINAPI ScaleWindowExtEx16( HDC16 hdc, INT16 xNum, INT16 xDenom,
2514                                   INT16 yNum, INT16 yDenom, LPSIZE16 size )
2515 {
2516     SIZE size32;
2517     BOOL16 ret = ScaleWindowExtEx( HDC_32(hdc), xNum, xDenom, yNum, yDenom,
2518                                      &size32 );
2519     if (size) { size->cx = size32.cx; size->cy = size32.cy; }
2520     return ret;
2521 }
2522
2523
2524 /******************************************************************************
2525  *           PolyBezier  (GDI.502)
2526  */
2527 BOOL16 WINAPI PolyBezier16( HDC16 hdc, const POINT16* lppt, INT16 cPoints )
2528 {
2529     int i;
2530     BOOL16 ret;
2531     LPPOINT pt32 = (LPPOINT)HeapAlloc( GetProcessHeap(), 0,
2532                                            cPoints*sizeof(POINT) );
2533     if(!pt32) return FALSE;
2534     for (i=cPoints;i--;) CONV_POINT16TO32(&(lppt[i]),&(pt32[i]));
2535     ret= PolyBezier(HDC_32(hdc), pt32, cPoints);
2536     HeapFree( GetProcessHeap(), 0, pt32 );
2537     return ret;
2538 }
2539
2540
2541 /******************************************************************************
2542  *           PolyBezierTo  (GDI.503)
2543  */
2544 BOOL16 WINAPI PolyBezierTo16( HDC16 hdc, const POINT16* lppt, INT16 cPoints )
2545 {
2546     int i;
2547     BOOL16 ret;
2548     LPPOINT pt32 = (LPPOINT)HeapAlloc( GetProcessHeap(), 0,
2549                                            cPoints*sizeof(POINT) );
2550     if(!pt32) return FALSE;
2551     for (i=cPoints;i--;) CONV_POINT16TO32(&(lppt[i]),&(pt32[i]));
2552     ret= PolyBezierTo(HDC_32(hdc), pt32, cPoints);
2553     HeapFree( GetProcessHeap(), 0, pt32 );
2554     return ret;
2555 }
2556
2557
2558 /******************************************************************************
2559  *           ExtSelectClipRgn   (GDI.508)
2560  */
2561 INT16 WINAPI ExtSelectClipRgn16( HDC16 hdc, HRGN16 hrgn, INT16 fnMode )
2562 {
2563   return ExtSelectClipRgn( HDC_32(hdc), HRGN_32(hrgn), fnMode);
2564 }
2565
2566
2567 /***********************************************************************
2568  *           AbortPath    (GDI.511)
2569  */
2570 BOOL16 WINAPI AbortPath16(HDC16 hdc)
2571 {
2572     return AbortPath( HDC_32(hdc) );
2573 }
2574
2575
2576 /***********************************************************************
2577  *           BeginPath    (GDI.512)
2578  */
2579 BOOL16 WINAPI BeginPath16(HDC16 hdc)
2580 {
2581     return BeginPath( HDC_32(hdc) );
2582 }
2583
2584
2585 /***********************************************************************
2586  *           CloseFigure    (GDI.513)
2587  */
2588 BOOL16 WINAPI CloseFigure16(HDC16 hdc)
2589 {
2590     return CloseFigure( HDC_32(hdc) );
2591 }
2592
2593
2594 /***********************************************************************
2595  *           EndPath    (GDI.514)
2596  */
2597 BOOL16 WINAPI EndPath16(HDC16 hdc)
2598 {
2599     return EndPath( HDC_32(hdc) );
2600 }
2601
2602
2603 /***********************************************************************
2604  *           FillPath    (GDI.515)
2605  */
2606 BOOL16 WINAPI FillPath16(HDC16 hdc)
2607 {
2608     return FillPath( HDC_32(hdc) );
2609 }
2610
2611
2612 /*******************************************************************
2613  *           FlattenPath    (GDI.516)
2614  */
2615 BOOL16 WINAPI FlattenPath16(HDC16 hdc)
2616 {
2617     return FlattenPath( HDC_32(hdc) );
2618 }
2619
2620
2621 /***********************************************************************
2622  *           GetPath    (GDI.517)
2623  */
2624 INT16 WINAPI GetPath16(HDC16 hdc, LPPOINT16 pPoints, LPBYTE pTypes, INT16 nSize)
2625 {
2626     FIXME("(%d,%p,%p): stub\n",hdc,pPoints,pTypes);
2627     return 0;
2628 }
2629
2630
2631 /***********************************************************************
2632  *           PathToRegion    (GDI.518)
2633  */
2634 HRGN16 WINAPI PathToRegion16(HDC16 hdc)
2635 {
2636     return HRGN_16( PathToRegion( HDC_32(hdc) ));
2637 }
2638
2639
2640 /***********************************************************************
2641  *           SelectClipPath    (GDI.519)
2642  */
2643 BOOL16 WINAPI SelectClipPath16(HDC16 hdc, INT16 iMode)
2644 {
2645     return SelectClipPath( HDC_32(hdc), iMode );
2646 }
2647
2648
2649 /*******************************************************************
2650  *           StrokeAndFillPath    (GDI.520)
2651  */
2652 BOOL16 WINAPI StrokeAndFillPath16(HDC16 hdc)
2653 {
2654     return StrokeAndFillPath( HDC_32(hdc) );
2655 }
2656
2657
2658 /*******************************************************************
2659  *           StrokePath    (GDI.521)
2660  */
2661 BOOL16 WINAPI StrokePath16(HDC16 hdc)
2662 {
2663     return StrokePath( HDC_32(hdc) );
2664 }
2665
2666
2667 /*******************************************************************
2668  *           WidenPath    (GDI.522)
2669  */
2670 BOOL16 WINAPI WidenPath16(HDC16 hdc)
2671 {
2672     return WidenPath( HDC_32(hdc) );
2673 }
2674
2675
2676 /***********************************************************************
2677  *              GetArcDirection (GDI.524)
2678  */
2679 INT16 WINAPI GetArcDirection16( HDC16 hdc )
2680 {
2681     return GetArcDirection( HDC_32(hdc) );
2682 }
2683
2684
2685 /***********************************************************************
2686  *           SetArcDirection    (GDI.525)
2687  */
2688 INT16 WINAPI SetArcDirection16( HDC16 hdc, INT16 nDirection )
2689 {
2690     return SetArcDirection( HDC_32(hdc), (INT)nDirection );
2691 }
2692
2693
2694 /***********************************************************************
2695  *           CreateHalftonePalette (GDI.529)
2696  */
2697 HPALETTE16 WINAPI CreateHalftonePalette16( HDC16 hdc )
2698 {
2699     return HPALETTE_16( CreateHalftonePalette( HDC_32(hdc) ));
2700 }
2701
2702
2703 /***********************************************************************
2704  *           SetDIBColorTable    (GDI.602)
2705  */
2706 UINT16 WINAPI SetDIBColorTable16( HDC16 hdc, UINT16 startpos, UINT16 entries, RGBQUAD *colors )
2707 {
2708     return SetDIBColorTable( HDC_32(hdc), startpos, entries, colors );
2709 }
2710
2711
2712 /***********************************************************************
2713  *           GetDIBColorTable    (GDI.603)
2714  */
2715 UINT16 WINAPI GetDIBColorTable16( HDC16 hdc, UINT16 startpos, UINT16 entries, RGBQUAD *colors )
2716 {
2717     return GetDIBColorTable( HDC_32(hdc), startpos, entries, colors );
2718 }
2719
2720
2721 /***********************************************************************
2722  *           GetRegionData   (GDI.607)
2723  *
2724  * FIXME: is LPRGNDATA the same in Win16 and Win32 ?
2725  */
2726 DWORD WINAPI GetRegionData16( HRGN16 hrgn, DWORD count, LPRGNDATA rgndata )
2727 {
2728     return GetRegionData( HRGN_32(hrgn), count, rgndata );
2729 }
2730
2731
2732 /***********************************************************************
2733  *           GetTextCharset   (GDI.612)
2734  */
2735 UINT16 WINAPI GetTextCharset16( HDC16 hdc )
2736 {
2737     return GetTextCharset( HDC_32(hdc) );
2738 }
2739
2740
2741 /*************************************************************************
2742  *             GetFontLanguageInfo   (GDI.616)
2743  */
2744 DWORD WINAPI GetFontLanguageInfo16( HDC16 hdc )
2745 {
2746     return GetFontLanguageInfo( HDC_32(hdc) );
2747 }
2748
2749
2750 /***********************************************************************
2751  *           SetLayout   (GDI.1000)
2752  *
2753  * Sets left->right or right->left text layout flags of a dc.
2754  */
2755 BOOL16 WINAPI SetLayout16( HDC16 hdc, DWORD layout )
2756 {
2757     return SetLayout( HDC_32(hdc), layout );
2758 }