Revert, thx Thomas, wasnt sure.
[reactos.git] / reactos / subsys / 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
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 /* $Id$ */
20
21 #include <w32k.h>
22
23 #define NDEBUG
24 #include <debug.h>
25
26 INT
27 STDCALL
28 NtGdiAbortDoc(HDC hDC)
29 {
30 UNIMPLEMENTED;
31 return 0;
32 }
33
34 INT
35 STDCALL
36 NtGdiEndDoc(HDC hDC)
37 {
38 UNIMPLEMENTED;
39 return 0;
40 }
41
42 INT
43 STDCALL
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 STDCALL
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 SetLastWin32Error(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 STDCALL
92 IntEngExtEscape(
93 SURFOBJ *Surface,
94 INT Escape,
95 INT InSize,
96 LPVOID InData,
97 INT OutSize,
98 LPVOID OutData)
99 {
100 if (Escape == QUERYESCSUPPORT)
101 return FALSE;
102
103 DPRINT1("IntEngExtEscape is unimplemented. - Keep going and have a nice day\n");
104 return -1;
105 }
106
107 INT
108 STDCALL
109 IntGdiExtEscape(
110 PDC dc,
111 INT Escape,
112 INT InSize,
113 LPCSTR InData,
114 INT OutSize,
115 LPSTR OutData)
116 {
117 BITMAPOBJ *BitmapObj = BITMAPOBJ_LockBitmap(dc->w.hBitmap);
118 INT Result;
119
120 /* FIXME - Handle BitmapObj == NULL !!!!!! */
121
122 if ( NULL == dc->DriverFunctions.Escape )
123 {
124 Result = IntEngExtEscape(
125 &BitmapObj->SurfObj,
126 Escape,
127 InSize,
128 (PVOID)InData,
129 OutSize,
130 (PVOID)OutData);
131 }
132 else
133 {
134 Result = dc->DriverFunctions.Escape(
135 &BitmapObj->SurfObj,
136 Escape,
137 InSize,
138 (PVOID)InData,
139 OutSize,
140 (PVOID)OutData );
141 }
142 BITMAPOBJ_UnlockBitmap(BitmapObj);
143
144 return Result;
145 }
146
147 INT
148 STDCALL
149 NtGdiExtEscape(
150 HDC hDC,
151 IN OPTIONAL PWCHAR pDriver,
152 IN INT nDriver,
153 INT Escape,
154 INT InSize,
155 OPTIONAL LPSTR UnsafeInData,
156 INT OutSize,
157 OPTIONAL LPSTR UnsafeOutData)
158 {
159 PDC pDC = DC_LockDc(hDC);
160 LPVOID SafeInData = NULL;
161 LPVOID SafeOutData = NULL;
162 NTSTATUS Status = STATUS_SUCCESS;
163 INT Result;
164
165 if ( pDC == NULL )
166 {
167 SetLastWin32Error(ERROR_INVALID_HANDLE);
168 return -1;
169 }
170 if ( pDC->IsIC )
171 {
172 DC_UnlockDc(pDC);
173 return 0;
174 }
175
176 if ( InSize && UnsafeInData )
177 {
178 _SEH_TRY
179 {
180 ProbeForRead(UnsafeInData,
181 InSize,
182 1);
183 }
184 _SEH_HANDLE
185 {
186 Status = _SEH_GetExceptionCode();
187 }
188 _SEH_END;
189
190 if (!NT_SUCCESS(Status))
191 {
192 DC_UnlockDc(pDC);
193 SetLastNtError(Status);
194 return -1;
195 }
196
197 SafeInData = ExAllocatePoolWithTag ( PagedPool, InSize, TAG_PRINT );
198 if ( !SafeInData )
199 {
200 DC_UnlockDc(pDC);
201 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY);
202 return -1;
203 }
204
205 _SEH_TRY
206 {
207 /* pointers were already probed! */
208 RtlCopyMemory(SafeInData,
209 UnsafeInData,
210 InSize);
211 }
212 _SEH_HANDLE
213 {
214 Status = _SEH_GetExceptionCode();
215 }
216 _SEH_END;
217
218 if ( !NT_SUCCESS(Status) )
219 {
220 ExFreePool ( SafeInData );
221 DC_UnlockDc(pDC);
222 SetLastNtError(Status);
223 return -1;
224 }
225 }
226
227 if ( OutSize && UnsafeOutData )
228 {
229 _SEH_TRY
230 {
231 ProbeForWrite(UnsafeOutData,
232 OutSize,
233 1);
234 }
235 _SEH_HANDLE
236 {
237 Status = _SEH_GetExceptionCode();
238 }
239 _SEH_END;
240
241 if (!NT_SUCCESS(Status))
242 {
243 SetLastNtError(Status);
244 goto freeout;
245 }
246
247 SafeOutData = ExAllocatePoolWithTag ( PagedPool, OutSize, TAG_PRINT );
248 if ( !SafeOutData )
249 {
250 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY);
251 freeout:
252 if ( SafeInData )
253 ExFreePool ( SafeInData );
254 DC_UnlockDc(pDC);
255 return -1;
256 }
257 }
258
259 Result = IntGdiExtEscape ( pDC, Escape, InSize, SafeInData, OutSize, SafeOutData );
260
261 DC_UnlockDc(pDC);
262
263 if ( SafeInData )
264 ExFreePool ( SafeInData );
265
266 if ( SafeOutData )
267 {
268 _SEH_TRY
269 {
270 /* pointers were already probed! */
271 RtlCopyMemory(UnsafeOutData,
272 SafeOutData,
273 OutSize);
274 }
275 _SEH_HANDLE
276 {
277 Status = _SEH_GetExceptionCode();
278 }
279 _SEH_END;
280
281 ExFreePool ( SafeOutData );
282 if ( !NT_SUCCESS(Status) )
283 {
284 SetLastNtError(Status);
285 return -1;
286 }
287 }
288
289 return Result;
290 }
291
292 INT
293 STDCALL
294 NtGdiSetAbortProc(HDC hDC,
295 ABORTPROC AbortProc)
296 {
297 UNIMPLEMENTED;
298 return 0;
299 }
300
301 INT
302 APIENTRY
303 NtGdiStartDoc(
304 IN HDC hdc,
305 IN DOCINFOW *pdi,
306 OUT BOOL *pbBanding,
307 IN INT iJob)
308 {
309 UNIMPLEMENTED;
310 return 0;
311 }
312
313 INT
314 STDCALL
315 NtGdiStartPage(HDC hDC)
316 {
317 UNIMPLEMENTED;
318 return 0;
319 }
320 /* EOF */