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