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