update for HEAD-2003091401
[reactos.git] / subsys / 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 #undef WIN32_LEAN_AND_MEAN
22 #include <windows.h>
23 #include <ddk/ntddk.h>
24 #include <win32k/dc.h>
25 #include <win32k/region.h>
26 #include <win32k/cliprgn.h>
27 #include <win32k/coord.h>
28 #include <include/error.h>
29 #include "../eng/clip.h"
30
31 #define NDEBUG
32 #include <win32k/debug1.h>
33
34 VOID FASTCALL
35 CLIPPING_UpdateGCRegion(DC* Dc)
36 {
37   HRGN Combined;
38   PROSRGNDATA CombinedRegion;
39
40 #ifndef TODO
41   if (Dc->w.hGCClipRgn == NULL)
42     {
43       Dc->w.hGCClipRgn = NtGdiCreateRectRgn(0, 0, 0, 0);
44     }
45
46   if (Dc->w.hGCClipRgn == NULL)
47     return;
48
49   if (Dc->w.hClipRgn == NULL)
50     {
51       NtGdiCombineRgn(Dc->w.hGCClipRgn, Dc->w.hVisRgn, 0, RGN_COPY);
52     }
53   else
54     {
55       NtGdiCombineRgn(Dc->w.hGCClipRgn, Dc->w.hClipRgn, Dc->w.hVisRgn,
56                      RGN_AND);
57     }
58 #endif
59
60   Combined = NtGdiCreateRectRgn(0, 0, 0, 0);
61   ASSERT(NULL != Combined);
62
63   if (Dc->w.hClipRgn == NULL)
64     {
65       NtGdiCombineRgn(Combined, Dc->w.hVisRgn, 0, RGN_COPY);
66     }
67   else
68     {
69       NtGdiCombineRgn(Combined, Dc->w.hClipRgn, Dc->w.hVisRgn,
70                      RGN_AND);
71     }
72   NtGdiOffsetRgn(Combined, Dc->w.DCOrgX, Dc->w.DCOrgY);
73
74   CombinedRegion = RGNDATA_LockRgn(Combined);
75   ASSERT(NULL != CombinedRegion);
76
77   if (NULL != Dc->CombinedClip)
78     {
79       IntEngDeleteClipRegion(Dc->CombinedClip);
80     }
81
82   Dc->CombinedClip = IntEngCreateClipRegion(CombinedRegion->rdh.nCount,
83                                             (PRECTL)CombinedRegion->Buffer,
84                                             CombinedRegion->rdh.rcBound);
85   ASSERT(NULL != Dc->CombinedClip);
86
87   RGNDATA_UnlockRgn(Combined);
88   NtGdiDeleteObject(Combined);
89 }
90
91 HRGN WINAPI SaveVisRgn(HDC hdc)
92 {
93   HRGN copy;
94   PROSRGNDATA obj, copyObj;
95   PDC dc = DC_LockDc(hdc);
96
97   if (!dc) return 0;
98
99   obj = RGNDATA_LockRgn(dc->w.hVisRgn);
100
101   if(!(copy = NtGdiCreateRectRgn(0, 0, 0, 0)))
102   {
103     RGNDATA_UnlockRgn(dc->w.hVisRgn);
104     DC_UnlockDc(hdc);
105     return 0;
106   }
107   NtGdiCombineRgn(copy, dc->w.hVisRgn, 0, RGN_COPY);
108   copyObj = RGNDATA_LockRgn(copy);
109 /*  copyObj->header.hNext = obj->header.hNext;
110   header.hNext = copy; */
111
112   return copy;
113 }
114
115 INT STDCALL
116 NtGdiSelectVisRgn(HDC hdc, HRGN hrgn)
117 {
118   int retval;
119   DC *dc;
120
121   if (!hrgn)
122         return ERROR;
123   if (!(dc = DC_LockDc(hdc)))
124         return ERROR;
125
126   dc->w.flags &= ~DC_DIRTY;
127
128   if (dc->w.hVisRgn == NULL)
129     {
130       dc->w.hVisRgn = NtGdiCreateRectRgn(0, 0, 0, 0);
131     }
132
133   retval = NtGdiCombineRgn(dc->w.hVisRgn, hrgn, 0, RGN_COPY);
134   CLIPPING_UpdateGCRegion(dc);
135   DC_UnlockDc( hdc );
136
137   return retval;
138 }
139
140 int STDCALL NtGdiExcludeClipRect(HDC  hDC,
141                          int  LeftRect,
142                          int  TopRect,
143                          int  RightRect,
144                          int  BottomRect)
145 {
146   UNIMPLEMENTED;
147 }
148
149 int STDCALL NtGdiExtSelectClipRgn(HDC  hDC,
150                           HRGN  hrgn,
151                           int  fnMode)
152 {
153   UNIMPLEMENTED;
154 }
155
156 int STDCALL NtGdiGetClipBox(HDC  hDC,
157                            LPRECT  rc)
158 {
159   int retval;
160   DC *dc;
161
162   if (!(dc = DC_LockDc(hDC)))
163         return ERROR;
164   retval = UnsafeIntGetRgnBox(dc->w.hGCClipRgn, rc);
165
166   DC_UnlockDc( hDC );
167   NtGdiDPtoLP(hDC, (LPPOINT)rc, 2);
168   return(retval);
169 }
170
171 int STDCALL NtGdiGetMetaRgn(HDC  hDC,
172                     HRGN  hrgn)
173 {
174   UNIMPLEMENTED;
175 }
176
177 int STDCALL NtGdiIntersectClipRect(HDC  hDC,
178                            int  LeftRect,
179                            int  TopRect,
180                            int  RightRect,
181                            int  BottomRect)
182 {
183   UNIMPLEMENTED;
184 }
185
186 int STDCALL NtGdiOffsetClipRgn(HDC  hDC,
187                        int  XOffset,
188                        int  YOffset)
189 {
190   UNIMPLEMENTED;
191 }
192
193 BOOL STDCALL NtGdiPtVisible(HDC  hDC,
194                     int  X,
195                     int  Y)
196 {
197   UNIMPLEMENTED;
198 }
199
200 BOOL STDCALL NtGdiRectVisible(HDC  hDC,
201                       CONST PRECT  rc)
202 {
203   UNIMPLEMENTED;
204 }
205
206 BOOL STDCALL NtGdiSelectClipPath(HDC  hDC,
207                          int  Mode)
208 {
209   UNIMPLEMENTED;
210 }
211
212 int STDCALL NtGdiSelectClipRgn(HDC  hDC,
213                               HRGN hRgn)
214 {
215   int Type;
216   PDC dc;
217   HRGN Copy;
218
219   dc = DC_LockDc(hDC);
220   if (NULL == dc)
221     {
222     SetLastWin32Error(ERROR_INVALID_HANDLE);
223     return ERROR;
224     }
225
226   if (NULL != hRgn)
227     {
228       Copy = NtGdiCreateRectRgn(0, 0, 0, 0);
229       if (NULL == Copy)
230         {
231           DC_UnlockDc(hDC);
232           return ERROR;
233         }
234       Type = NtGdiCombineRgn(Copy, hRgn, 0, RGN_COPY);
235       if (ERROR == Type)
236         {
237           NtGdiDeleteObject(Copy);
238           DC_UnlockDc(hDC);
239           return ERROR;
240         }
241     }
242   else
243     {
244       Copy = NULL;
245     }
246
247   if (NULL != dc->w.hClipRgn)
248     {
249       NtGdiDeleteObject(dc->w.hClipRgn);
250     }
251   dc->w.hClipRgn = Copy;
252   CLIPPING_UpdateGCRegion(dc);
253   DC_UnlockDc(hDC);
254
255   return ERROR;
256 }
257
258 int STDCALL NtGdiSetMetaRgn(HDC  hDC)
259 {
260   UNIMPLEMENTED;
261 }
262
263
264 /* EOF */