remove useless NtGdiOffsetRgn
[reactos.git] / reactos / subsystems / win32 / win32k / objects / cliprgn.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 FASTCALL
27 CLIPPING_UpdateGCRegion(DC* Dc)
28 {
29 PROSRGNDATA CombinedRegion;
30
31 if (Dc->w.hGCClipRgn == NULL)
32 Dc->w.hGCClipRgn = NtGdiCreateRectRgn(0, 0, 0, 0);
33
34 if (Dc->w.hClipRgn == NULL)
35 NtGdiCombineRgn(Dc->w.hGCClipRgn, Dc->w.hVisRgn, 0, RGN_COPY);
36 else
37 NtGdiCombineRgn(Dc->w.hGCClipRgn, Dc->w.hClipRgn, Dc->w.hVisRgn, RGN_AND);
38 NtGdiOffsetRgn(Dc->w.hGCClipRgn, Dc->w.DCOrgX, Dc->w.DCOrgY);
39
40 if((CombinedRegion = RGNDATA_LockRgn(Dc->w.hGCClipRgn)))
41 {
42 if (Dc->CombinedClip != NULL)
43 IntEngDeleteClipRegion(Dc->CombinedClip);
44
45 Dc->CombinedClip = IntEngCreateClipRegion(
46 CombinedRegion->rdh.nCount,
47 (PRECTL)CombinedRegion->Buffer,
48 (PRECTL)&CombinedRegion->rdh.rcBound);
49
50 RGNDATA_UnlockRgn(CombinedRegion);
51 }
52
53 if ( NULL == Dc->CombinedClip )
54 {
55 DPRINT1("IntEngCreateClipRegion() failed\n");
56 return ERROR;
57 }
58
59 return NtGdiOffsetRgn(Dc->w.hGCClipRgn, -Dc->w.DCOrgX, -Dc->w.DCOrgY);
60 }
61
62 INT STDCALL
63 NtGdiSelectVisRgn(HDC hdc, HRGN hrgn)
64 {
65 int retval;
66 DC *dc;
67
68 if (!hrgn)
69 {
70 SetLastWin32Error(ERROR_INVALID_PARAMETER);
71 return ERROR;
72 }
73 if (!(dc = DC_LockDc(hdc)))
74 {
75 SetLastWin32Error(ERROR_INVALID_HANDLE);
76 return ERROR;
77 }
78
79 dc->w.flags &= ~DC_DIRTY;
80
81 if (dc->w.hVisRgn == NULL)
82 {
83 dc->w.hVisRgn = NtGdiCreateRectRgn(0, 0, 0, 0);
84 GDIOBJ_CopyOwnership(GdiHandleTable, hdc, dc->w.hVisRgn);
85 }
86
87 retval = NtGdiCombineRgn(dc->w.hVisRgn, hrgn, 0, RGN_COPY);
88 if ( retval != ERROR )
89 {
90 NtGdiOffsetRgn(dc->w.hVisRgn, -dc->w.DCOrgX, -dc->w.DCOrgY);
91 CLIPPING_UpdateGCRegion(dc);
92 }
93 DC_UnlockDc(dc);
94
95 return retval;
96 }
97
98
99 int STDCALL IntGdiExtSelectClipRgn(PDC dc,
100 HRGN hrgn,
101 int fnMode)
102 {
103 int retval;
104 // dc->w.flags &= ~DC_DIRTY;
105
106 if (!hrgn)
107 {
108 if (fnMode == RGN_COPY)
109 {
110 if (dc->w.hClipRgn != NULL)
111 {
112 NtGdiDeleteObject(dc->w.hClipRgn);
113 dc->w.hClipRgn = NULL;
114 retval = NULLREGION;
115 }
116 }
117 else
118 {
119 SetLastWin32Error(ERROR_INVALID_PARAMETER);
120 return ERROR;
121 }
122 }
123 else
124 {
125 if (!dc->w.hClipRgn)
126 {
127 PROSRGNDATA Rgn;
128 RECT rect;
129 if((Rgn = RGNDATA_LockRgn(dc->w.hVisRgn)))
130 {
131 UnsafeIntGetRgnBox(Rgn, &rect);
132 RGNDATA_UnlockRgn(Rgn);
133 dc->w.hClipRgn = UnsafeIntCreateRectRgnIndirect(&rect);
134 }
135 else
136 {
137 dc->w.hClipRgn = NtGdiCreateRectRgn(0, 0, 0, 0);
138 }
139 }
140 if(fnMode == RGN_COPY)
141 {
142 NtGdiCombineRgn(dc->w.hClipRgn, hrgn, 0, fnMode);
143 }
144 else
145 NtGdiCombineRgn(dc->w.hClipRgn, dc->w.hClipRgn, hrgn, fnMode);
146 }
147
148 retval = CLIPPING_UpdateGCRegion(dc);
149 return retval;
150 }
151
152
153 int STDCALL NtGdiExtSelectClipRgn(HDC hDC,
154 HRGN hrgn,
155 int fnMode)
156 {
157 int retval;
158 DC *dc;
159
160 if (!(dc = DC_LockDc(hDC)))
161 {
162 SetLastWin32Error(ERROR_INVALID_HANDLE);
163 return ERROR;
164 }
165
166 retval = IntGdiExtSelectClipRgn ( dc, hrgn, fnMode );
167
168 DC_UnlockDc(dc);
169 return retval;
170 }
171
172 INT FASTCALL
173 IntGdiGetClipBox(HDC hDC, LPRECT rc)
174 {
175 PROSRGNDATA Rgn;
176 INT retval;
177 PDC dc;
178
179 if (!(dc = DC_LockDc(hDC)))
180 {
181 SetLastWin32Error(ERROR_INVALID_HANDLE);
182 return ERROR;
183 }
184
185 if (!(Rgn = RGNDATA_LockRgn(dc->w.hGCClipRgn)))
186 {
187 DC_UnlockDc(dc);
188 SetLastWin32Error(ERROR_INVALID_HANDLE);
189 return ERROR;
190 }
191 retval = UnsafeIntGetRgnBox(Rgn, rc);
192 RGNDATA_UnlockRgn(Rgn);
193 IntDPtoLP(dc, (LPPOINT)rc, 2);
194 DC_UnlockDc(dc);
195
196 return retval;
197 }
198
199 int STDCALL NtGdiGetClipBox(HDC hDC,
200 LPRECT rc)
201 {
202 int Ret;
203 NTSTATUS Status = STATUS_SUCCESS;
204 RECT Saferect;
205
206 Ret = IntGdiGetClipBox(hDC, &Saferect);
207
208 _SEH_TRY
209 {
210 ProbeForWrite(rc,
211 sizeof(RECT),
212 1);
213 *rc = Saferect;
214 }
215 _SEH_HANDLE
216 {
217 Status = _SEH_GetExceptionCode();
218 }
219 _SEH_END;
220
221 if(!NT_SUCCESS(Status))
222 {
223
224 SetLastNtError(Status);
225 return ERROR;
226 }
227
228 return Ret;
229 }
230
231 int STDCALL NtGdiGetMetaRgn(HDC hDC,
232 HRGN hrgn)
233 {
234 UNIMPLEMENTED;
235 return 0;
236 }
237
238 int STDCALL NtGdiExcludeClipRect(HDC hDC,
239 int LeftRect,
240 int TopRect,
241 int RightRect,
242 int BottomRect)
243 {
244 INT Result;
245 RECT Rect;
246 HRGN NewRgn;
247 PDC dc = DC_LockDc(hDC);
248
249 if (!dc)
250 {
251 SetLastWin32Error(ERROR_INVALID_HANDLE);
252 return ERROR;
253 }
254
255 Rect.left = LeftRect;
256 Rect.top = TopRect;
257 Rect.right = RightRect;
258 Rect.bottom = BottomRect;
259
260 IntLPtoDP(dc, (LPPOINT)&Rect, 2);
261
262 NewRgn = UnsafeIntCreateRectRgnIndirect(&Rect);
263 if (!NewRgn)
264 {
265 Result = ERROR;
266 }
267 else
268 {
269 if (!dc->w.hClipRgn)
270 {
271 dc->w.hClipRgn = NtGdiCreateRectRgn(0, 0, 0, 0);
272 NtGdiCombineRgn(dc->w.hClipRgn, dc->w.hVisRgn, NewRgn, RGN_DIFF);
273 Result = SIMPLEREGION;
274 }
275 else
276 {
277 Result = NtGdiCombineRgn(dc->w.hClipRgn, dc->w.hClipRgn, NewRgn, RGN_DIFF);
278 }
279 NtGdiDeleteObject(NewRgn);
280 }
281 if (Result != ERROR)
282 CLIPPING_UpdateGCRegion(dc);
283
284 DC_UnlockDc(dc);
285
286 return Result;
287 }
288
289 int STDCALL NtGdiIntersectClipRect(HDC hDC,
290 int LeftRect,
291 int TopRect,
292 int RightRect,
293 int BottomRect)
294 {
295 INT Result;
296 RECT Rect;
297 HRGN NewRgn;
298 PDC dc = DC_LockDc(hDC);
299
300 DPRINT("NtGdiIntersectClipRect(%x, %d,%d-%d,%d)\n",
301 hDC, LeftRect, TopRect, RightRect, BottomRect);
302
303 if (!dc)
304 {
305 SetLastWin32Error(ERROR_INVALID_HANDLE);
306 return ERROR;
307 }
308
309 Rect.left = LeftRect;
310 Rect.top = TopRect;
311 Rect.right = RightRect;
312 Rect.bottom = BottomRect;
313
314 IntLPtoDP(dc, (LPPOINT)&Rect, 2);
315
316 NewRgn = UnsafeIntCreateRectRgnIndirect(&Rect);
317 if (!NewRgn)
318 {
319 Result = ERROR;
320 }
321 else if (!dc->w.hClipRgn)
322 {
323 dc->w.hClipRgn = NewRgn;
324 Result = SIMPLEREGION;
325 }
326 else
327 {
328 Result = NtGdiCombineRgn(dc->w.hClipRgn, dc->w.hClipRgn, NewRgn, RGN_AND);
329 NtGdiDeleteObject(NewRgn);
330 }
331 if (Result != ERROR)
332 CLIPPING_UpdateGCRegion(dc);
333
334 DC_UnlockDc(dc);
335
336 return Result;
337 }
338
339 int STDCALL NtGdiOffsetClipRgn(HDC hDC,
340 int XOffset,
341 int YOffset)
342 {
343 INT Result;
344 DC *dc;
345
346 if(!(dc = DC_LockDc(hDC)))
347 {
348 SetLastWin32Error(ERROR_INVALID_HANDLE);
349 return ERROR;
350 }
351
352 if(dc->w.hClipRgn != NULL)
353 {
354 Result = NtGdiOffsetRgn(dc->w.hClipRgn,
355 XOffset,
356 YOffset);
357 CLIPPING_UpdateGCRegion(dc);
358 }
359 else
360 {
361 Result = NULLREGION;
362 }
363
364 DC_UnlockDc(dc);
365 return Result;
366 }
367
368 BOOL STDCALL NtGdiPtVisible(HDC hDC,
369 int X,
370 int Y)
371 {
372 HRGN rgn;
373 DC *dc;
374
375 if(!(dc = DC_LockDc(hDC)))
376 {
377 SetLastWin32Error(ERROR_INVALID_HANDLE);
378 return FALSE;
379 }
380
381 rgn = dc->w.hGCClipRgn;
382 DC_UnlockDc(dc);
383
384 return (rgn ? NtGdiPtInRegion(rgn, X, Y) : FALSE);
385 }
386
387 BOOL STDCALL NtGdiRectVisible(HDC hDC,
388 CONST PRECT UnsafeRect)
389 {
390 NTSTATUS Status = STATUS_SUCCESS;
391 PROSRGNDATA Rgn;
392 PDC dc = DC_LockDc(hDC);
393 BOOL Result = FALSE;
394 RECT Rect;
395
396 if (!dc)
397 {
398 SetLastWin32Error(ERROR_INVALID_HANDLE);
399 return FALSE;
400 }
401
402 _SEH_TRY
403 {
404 ProbeForRead(UnsafeRect,
405 sizeof(RECT),
406 1);
407 Rect = *UnsafeRect;
408 }
409 _SEH_HANDLE
410 {
411 Status = _SEH_GetExceptionCode();
412 }
413 _SEH_END;
414
415 if(!NT_SUCCESS(Status))
416 {
417 DC_UnlockDc(dc);
418 SetLastNtError(Status);
419 return FALSE;
420 }
421
422 if (dc->w.hGCClipRgn)
423 {
424 if((Rgn = (PROSRGNDATA)RGNDATA_LockRgn(dc->w.hGCClipRgn)))
425 {
426 IntLPtoDP(dc, (LPPOINT)&Rect, 2);
427 Result = UnsafeIntRectInRegion(Rgn, &Rect);
428 RGNDATA_UnlockRgn(Rgn);
429 }
430 }
431 DC_UnlockDc(dc);
432
433 return Result;
434 }
435
436 INT STDCALL
437 NtGdiSelectClipRgn(HDC hDC, HRGN hRgn)
438 {
439 return NtGdiExtSelectClipRgn(hDC, hRgn, RGN_COPY);
440 }
441
442 int STDCALL NtGdiSetMetaRgn(HDC hDC)
443 {
444 UNIMPLEMENTED;
445 return 0;
446 }
447
448 /* EOF */