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