b9592e09fc2658bc4bd2876c5cc269310f847563
[reactos.git] / reactos / subsystems / win32 / win32k / objects / print.c
1 /*
2 * ReactOS W32 Subsystem
3 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 /* $Id$ */
20
21 #include <win32k.h>
22
23 #define NDEBUG
24 #include <debug.h>
25
26 INT
27 APIENTRY
28 NtGdiAbortDoc(HDC hDC)
29 {
30 UNIMPLEMENTED;
31 return 0;
32 }
33
34 INT
35 APIENTRY
36 NtGdiEndDoc(HDC hDC)
37 {
38 UNIMPLEMENTED;
39 return 0;
40 }
41
42 INT
43 APIENTRY
44 NtGdiEndPage(HDC hDC)
45 {
46 UNIMPLEMENTED;
47 return 0;
48 }
49
50 INT
51 FASTCALL
52 IntGdiEscape(PDC dc,
53 INT Escape,
54 INT InSize,
55 LPCSTR InData,
56 LPVOID OutData)
57 {
58 if (Escape == QUERYESCSUPPORT)
59 return FALSE;
60
61 UNIMPLEMENTED;
62 return SP_ERROR;
63 }
64
65 INT
66 APIENTRY
67 NtGdiEscape(HDC hDC,
68 INT Escape,
69 INT InSize,
70 LPCSTR InData,
71 LPVOID OutData)
72 {
73 PDC dc;
74 INT ret;
75
76 dc = DC_LockDc(hDC);
77 if (dc == NULL)
78 {
79 EngSetLastError(ERROR_INVALID_HANDLE);
80 return SP_ERROR;
81 }
82
83 /* TODO FIXME - don't pass umode buffer to an Int function */
84 ret = IntGdiEscape(dc, Escape, InSize, InData, OutData);
85
86 DC_UnlockDc( dc );
87 return ret;
88 }
89
90 INT
91 APIENTRY
92 IntGdiExtEscape(
93 PDC dc,
94 INT Escape,
95 INT InSize,
96 LPCSTR InData,
97 INT OutSize,
98 LPSTR OutData)
99 {
100 SURFACE *psurf = dc->dclevel.pSurface;
101 INT Result;
102
103 if (!dc->ppdev->DriverFunctions.Escape)
104 {
105 Result = 0;
106 }
107 else
108 {
109 Result = dc->ppdev->DriverFunctions.Escape(
110 psurf ? &psurf->SurfObj : NULL,
111 Escape,
112 InSize,
113 (PVOID)InData,
114 OutSize,
115 (PVOID)OutData );
116 }
117
118 return Result;
119 }
120
121 INT
122 APIENTRY
123 NtGdiExtEscape(
124 HDC hDC,
125 IN OPTIONAL PWCHAR pDriver,
126 IN INT nDriver,
127 INT Escape,
128 INT InSize,
129 OPTIONAL LPSTR UnsafeInData,
130 INT OutSize,
131 OPTIONAL LPSTR UnsafeOutData)
132 {
133 PDC pDC;
134 LPVOID SafeInData = NULL;
135 LPVOID SafeOutData = NULL;
136 NTSTATUS Status = STATUS_SUCCESS;
137 INT Result;
138
139 if (hDC == 0)
140 {
141 hDC = UserGetWindowDC(NULL);
142 }
143
144 pDC = DC_LockDc(hDC);
145 if ( pDC == NULL )
146 {
147 EngSetLastError(ERROR_INVALID_HANDLE);
148 return -1;
149 }
150 if ( pDC->dctype == DC_TYPE_INFO)
151 {
152 DC_UnlockDc(pDC);
153 return 0;
154 }
155
156 if ( InSize && UnsafeInData )
157 {
158 _SEH2_TRY
159 {
160 ProbeForRead(UnsafeInData,
161 InSize,
162 1);
163 }
164 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
165 {
166 Status = _SEH2_GetExceptionCode();
167 }
168 _SEH2_END;
169
170 if (!NT_SUCCESS(Status))
171 {
172 DC_UnlockDc(pDC);
173 SetLastNtError(Status);
174 return -1;
175 }
176
177 SafeInData = ExAllocatePoolWithTag ( PagedPool, InSize, TAG_PRINT );
178 if ( !SafeInData )
179 {
180 DC_UnlockDc(pDC);
181 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY);
182 return -1;
183 }
184
185 _SEH2_TRY
186 {
187 /* pointers were already probed! */
188 RtlCopyMemory(SafeInData,
189 UnsafeInData,
190 InSize);
191 }
192 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
193 {
194 Status = _SEH2_GetExceptionCode();
195 }
196 _SEH2_END;
197
198 if ( !NT_SUCCESS(Status) )
199 {
200 ExFreePoolWithTag ( SafeInData, TAG_PRINT );
201 DC_UnlockDc(pDC);
202 SetLastNtError(Status);
203 return -1;
204 }
205 }
206
207 if ( OutSize && UnsafeOutData )
208 {
209 _SEH2_TRY
210 {
211 ProbeForWrite(UnsafeOutData,
212 OutSize,
213 1);
214 }
215 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
216 {
217 Status = _SEH2_GetExceptionCode();
218 }
219 _SEH2_END;
220
221 if (!NT_SUCCESS(Status))
222 {
223 SetLastNtError(Status);
224 goto freeout;
225 }
226
227 SafeOutData = ExAllocatePoolWithTag ( PagedPool, OutSize, TAG_PRINT );
228 if ( !SafeOutData )
229 {
230 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY);
231 freeout:
232 if ( SafeInData )
233 ExFreePoolWithTag ( SafeInData, TAG_PRINT );
234 DC_UnlockDc(pDC);
235 return -1;
236 }
237 }
238
239 Result = IntGdiExtEscape ( pDC, Escape, InSize, SafeInData, OutSize, SafeOutData );
240
241 DC_UnlockDc(pDC);
242
243 if ( SafeInData )
244 ExFreePoolWithTag ( SafeInData ,TAG_PRINT );
245
246 if ( SafeOutData )
247 {
248 _SEH2_TRY
249 {
250 /* pointers were already probed! */
251 RtlCopyMemory(UnsafeOutData,
252 SafeOutData,
253 OutSize);
254 }
255 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
256 {
257 Status = _SEH2_GetExceptionCode();
258 }
259 _SEH2_END;
260
261 ExFreePoolWithTag ( SafeOutData, TAG_PRINT );
262 if ( !NT_SUCCESS(Status) )
263 {
264 SetLastNtError(Status);
265 return -1;
266 }
267 }
268
269 return Result;
270 }
271
272 INT
273 APIENTRY
274 NtGdiStartDoc(
275 IN HDC hdc,
276 IN DOCINFOW *pdi,
277 OUT BOOL *pbBanding,
278 IN INT iJob)
279 {
280 UNIMPLEMENTED;
281 return 0;
282 }
283
284 INT
285 APIENTRY
286 NtGdiStartPage(HDC hDC)
287 {
288 UNIMPLEMENTED;
289 return 0;
290 }
291 /* EOF */