Convert lpnFit back to multibyte in GetTextExtentExPointA.
[wine] / graphics / escape.c
1 /*
2  * Escape() function.
3  *
4  * Copyright 1994  Bob Amstadt
5  * Copyright 2001  Alexandre Julliard
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include <stdarg.h>
23 #include <string.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wingdi.h"
27 #include "gdi.h"
28 #include "wine/debug.h"
29
30 WINE_DEFAULT_DEBUG_CHANNEL(driver);
31
32
33 /************************************************************************
34  *             Escape  [GDI32.@]
35  */
36 INT WINAPI Escape( HDC hdc, INT escape, INT in_count, LPCSTR in_data, LPVOID out_data )
37 {
38     INT ret;
39     POINT *pt;
40
41     switch (escape)
42     {
43     case ABORTDOC:
44         return AbortDoc( hdc );
45
46     case ENDDOC:
47         return EndDoc( hdc );
48
49     case GETPHYSPAGESIZE:
50         pt = out_data;
51         pt->x = GetDeviceCaps( hdc, PHYSICALWIDTH );
52         pt->y = GetDeviceCaps( hdc, PHYSICALHEIGHT );
53         return 1;
54
55     case GETPRINTINGOFFSET:
56         pt = out_data;
57         pt->x = GetDeviceCaps( hdc, PHYSICALOFFSETX );
58         pt->y = GetDeviceCaps( hdc, PHYSICALOFFSETY );
59         return 1;
60
61     case GETSCALINGFACTOR:
62         pt = out_data;
63         pt->x = GetDeviceCaps( hdc, SCALINGFACTORX );
64         pt->y = GetDeviceCaps( hdc, SCALINGFACTORY );
65         return 1;
66
67     case NEWFRAME:
68         return EndPage( hdc );
69
70     case SETABORTPROC:
71         return SetAbortProc( hdc, (ABORTPROC)in_data );
72
73     case STARTDOC:
74         {
75             DOCINFOA doc;
76             char *name = NULL;
77
78             /* in_data may not be 0 terminated so we must copy it */
79             if (in_data)
80             {
81                 name = HeapAlloc( GetProcessHeap(), 0, in_count+1 );
82                 memcpy( name, in_data, in_count );
83                 name[in_count] = 0;
84             }
85             /* out_data is actually a pointer to the DocInfo structure and used as
86              * a second input parameter */
87             if (out_data) doc = *(DOCINFOA *)out_data;
88             else
89             {
90                 doc.cbSize = sizeof(doc);
91                 doc.lpszOutput = NULL;
92                 doc.lpszDatatype = NULL;
93                 doc.fwType = 0;
94             }
95             doc.lpszDocName = name;
96             ret = StartDocA( hdc, &doc );
97             if (name) HeapFree( GetProcessHeap(), 0, name );
98             if (ret > 0) ret = StartPage( hdc );
99             return ret;
100         }
101
102     case QUERYESCSUPPORT:
103         {
104             INT *ptr = (INT *)in_data;
105             if (in_count < sizeof(INT)) return 0;
106             switch(*ptr)
107             {
108             case ABORTDOC:
109             case ENDDOC:
110             case GETPHYSPAGESIZE:
111             case GETPRINTINGOFFSET:
112             case GETSCALINGFACTOR:
113             case NEWFRAME:
114             case QUERYESCSUPPORT:
115             case SETABORTPROC:
116             case STARTDOC:
117                 return TRUE;
118             }
119             break;
120         }
121     }
122
123     /* if not handled internally, pass it to the driver */
124     return ExtEscape( hdc, escape, in_count, in_data, 0, out_data );
125 }
126
127
128 /******************************************************************************
129  *              ExtEscape       [GDI32.@]
130  *
131  * PARAMS
132  *    hdc         [I] Handle to device context
133  *    nEscape     [I] Escape function
134  *    cbInput     [I] Number of bytes in input structure
135  *    lpszInData  [I] Pointer to input structure
136  *    cbOutput    [I] Number of bytes in output structure
137  *    lpszOutData [O] Pointer to output structure
138  *
139  * RETURNS
140  *    Success: >0
141  *    Not implemented: 0
142  *    Failure: <0
143  */
144 INT WINAPI ExtEscape( HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData,
145                       INT cbOutput, LPSTR lpszOutData )
146 {
147     INT ret = 0;
148     DC * dc = DC_GetDCPtr( hdc );
149     if (dc)
150     {
151         if (dc->funcs->pExtEscape)
152             ret = dc->funcs->pExtEscape( dc->physDev, nEscape, cbInput, lpszInData, cbOutput, lpszOutData );
153         GDI_ReleaseObj( hdc );
154     }
155     return ret;
156 }
157
158
159 /*******************************************************************
160  *      DrawEscape [GDI32.@]
161  *
162  *
163  */
164 INT WINAPI DrawEscape(HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData)
165 {
166     FIXME("DrawEscape, stub\n");
167     return 0;
168 }