update for HEAD-2003091401
[reactos.git] / subsys / win32k / objects / brush.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
22
23 #undef WIN32_LEAN_AND_MEAN
24 #include <windows.h>
25 #include <ddk/ntddk.h>
26 #include <win32k/bitmaps.h>
27 #include <win32k/brush.h>
28 //#include <win32k/debug.h>
29 #include <include/object.h>
30 #include <include/inteng.h>
31 #include <include/error.h>
32
33 #define NDEBUG
34 #include <win32k/debug1.h>
35
36 HBRUSH STDCALL NtGdiCreateBrushIndirect(CONST LOGBRUSH  *lb)
37 {
38   PBRUSHOBJ  brushPtr;
39   HBRUSH  hBrush;
40
41   hBrush = BRUSHOBJ_AllocBrush();
42   if (hBrush == NULL)
43   {
44     return 0;
45   }
46
47   brushPtr = BRUSHOBJ_LockBrush (hBrush);
48 /* FIXME: Occurs! FiN */
49 /*  ASSERT( brushPtr ); *///I want to know if this ever occurs
50
51   if( brushPtr ){
52         brushPtr->iSolidColor = lb->lbColor;
53         brushPtr->logbrush.lbStyle = lb->lbStyle;
54         brushPtr->logbrush.lbColor = lb->lbColor;
55         brushPtr->logbrush.lbHatch = lb->lbHatch;
56
57         BRUSHOBJ_UnlockBrush( hBrush );
58         return  hBrush;
59   }
60   return NULL;
61 }
62
63 HBRUSH STDCALL NtGdiCreateDIBPatternBrush(HGLOBAL  hDIBPacked,
64                                   UINT  ColorSpec)
65 {
66   UNIMPLEMENTED;
67 #if 0
68   LOGBRUSH  logbrush;
69   PBITMAPINFO  info, newInfo;
70   INT  size;
71
72   DPRINT("%04x\n", hbitmap );
73
74   logbrush.lbStyle = BS_DIBPATTERN;
75   logbrush.lbColor = coloruse;
76   logbrush.lbHatch = 0;
77
78   /* Make a copy of the bitmap */
79   if (!(info = (BITMAPINFO *)GlobalLock( hbitmap )))
80   {
81     return 0;
82   }
83
84
85   if (info->bmiHeader.biCompression) size = info->bmiHeader.biSizeImage;
86   else
87     size = DIB_GetDIBImageBytes(info->bmiHeader.biWidth, info->bmiHeader.biHeight, info->bmiHeader.biBitCount);
88   size += DIB_BitmapInfoSize(info, coloruse);
89
90   if (!(logbrush.lbHatch = (INT)GlobalAlloc16( GMEM_MOVEABLE, size )))
91   {
92     GlobalUnlock16( hbitmap );
93     return 0;
94   }
95   newInfo = (BITMAPINFO *) GlobalLock16((HGLOBAL16)logbrush.lbHatch);
96   memcpy(newInfo, info, size);
97   GlobalUnlock16((HGLOBAL16)logbrush.lbHatch);
98   GlobalUnlock(hbitmap);
99   return NtGdiCreateBrushIndirect(&logbrush);
100 #endif
101 }
102
103 HBRUSH STDCALL NtGdiCreateDIBPatternBrushPt(CONST VOID  *PackedDIB,
104                                     UINT  Usage)
105 {
106   INT  size;
107   LOGBRUSH  logbrush;
108   PBITMAPINFO  info;
109   PBITMAPINFO  newInfo;
110
111   info = (BITMAPINFO *) PackedDIB;
112   if (info == NULL)
113   {
114     return 0;
115   }
116   DPRINT ("%p %ldx%ld %dbpp\n",
117           info,
118           info->bmiHeader.biWidth,
119           info->bmiHeader.biHeight,
120           info->bmiHeader.biBitCount);
121
122   logbrush.lbStyle = BS_DIBPATTERN;
123   logbrush.lbColor = Usage;
124   logbrush.lbHatch = 0;
125
126   /* Make a copy of the bitmap */
127
128   if (info->bmiHeader.biCompression)
129   {
130     size = info->bmiHeader.biSizeImage;
131   }
132   else
133     {
134     size = DIB_GetDIBImageBytes (info->bmiHeader.biWidth, info->bmiHeader.biHeight, info->bmiHeader.biBitCount);
135   }
136   size += DIB_BitmapInfoSize (info, Usage);
137
138   logbrush.lbHatch = (LONG) GDIOBJ_AllocObj(size, GDI_OBJECT_TYPE_DONTCARE, NULL);
139   if (logbrush.lbHatch == 0)
140   {
141     return 0;
142   }
143   newInfo = (PBITMAPINFO) GDIOBJ_LockObj ((HGDIOBJ) logbrush.lbHatch, GDI_OBJECT_TYPE_DONTCARE);
144   ASSERT(newInfo);
145   memcpy(newInfo, info, size);
146   GDIOBJ_UnlockObj((HGDIOBJ) logbrush.lbHatch, GDI_OBJECT_TYPE_DONTCARE);
147
148   return  NtGdiCreateBrushIndirect (&logbrush);
149 }
150
151 HBRUSH STDCALL NtGdiCreateHatchBrush(INT  Style,
152                              COLORREF  Color)
153 {
154   LOGBRUSH  logbrush;
155
156   DPRINT("%d %06lx\n", Style, Color);
157
158   if (Style < 0 || Style >= NB_HATCH_STYLES)
159   {
160     return 0;
161   }
162   logbrush.lbStyle = BS_HATCHED;
163   logbrush.lbColor = Color;
164   logbrush.lbHatch = Style;
165
166   return  NtGdiCreateBrushIndirect (&logbrush);
167 }
168
169 HBRUSH STDCALL NtGdiCreatePatternBrush(HBITMAP  hBitmap)
170 {
171   LOGBRUSH  logbrush = { BS_PATTERN, 0, 0 };
172
173   DPRINT ("%04x\n", hBitmap);
174   logbrush.lbHatch = (INT) BITMAPOBJ_CopyBitmap (hBitmap);
175   if(!logbrush.lbHatch)
176   {
177     return 0;
178   }
179   else
180   {
181     return NtGdiCreateBrushIndirect( &logbrush );
182   }
183 }
184
185 HBRUSH STDCALL NtGdiCreateSolidBrush(COLORREF  Color)
186 {
187   LOGBRUSH logbrush;
188
189   logbrush.lbStyle = BS_SOLID;
190   logbrush.lbColor = Color;
191   logbrush.lbHatch = 0;
192
193   return NtGdiCreateBrushIndirect(&logbrush);
194 }
195
196 BOOL STDCALL NtGdiFixBrushOrgEx(VOID)
197 {
198   return FALSE;
199 }
200
201 BOOL STDCALL IntPatBlt(DC *dc,
202                         INT  XLeft,
203                         INT  YLeft,
204                         INT  Width,
205                         INT  Height,
206                         DWORD  ROP,
207                         PBRUSHOBJ BrushObj)
208 {
209   RECT DestRect;
210   PSURFOBJ SurfObj;
211   BOOL ret;
212
213   SurfObj = (SURFOBJ*)AccessUserObject((ULONG)dc->Surface);
214
215   assert(BrushObj);
216   if (BrushObj->logbrush.lbStyle != BS_NULL)
217     {
218       if (Width > 0)
219         {
220           DestRect.left = XLeft + dc->w.DCOrgX;
221           DestRect.right = XLeft + Width + dc->w.DCOrgX;
222         }
223       else
224         {
225           DestRect.left = XLeft + Width + 1 + dc->w.DCOrgX;
226           DestRect.right = XLeft + dc->w.DCOrgX + 1;
227         }
228       if (Height > 0)
229         {
230           DestRect.top = YLeft + dc->w.DCOrgY;
231           DestRect.bottom = YLeft + Height + dc->w.DCOrgY;
232         }
233       else
234         {
235           DestRect.top = YLeft + Height + dc->w.DCOrgY + 1;
236           DestRect.bottom = YLeft + dc->w.DCOrgY + 1;
237         }
238       ret = IntEngBitBlt(SurfObj,
239                          NULL,
240                          NULL,
241                          dc->CombinedClip,
242                          NULL,
243                          &DestRect,
244                          NULL,
245                          NULL,
246                          BrushObj,
247                          NULL,
248                          ROP);
249     }
250   return(ret);
251 }
252
253 BOOL STDCALL NtGdiPolyPatBlt(HDC hDC,
254                         DWORD dwRop,
255                         PPATRECT pRects,
256                         int cRects,
257                         ULONG Reserved)
258 {
259         int i;
260         PATRECT r;
261         PBRUSHOBJ BrushObj;
262         DC *dc = DC_LockDc(hDC);
263         if (dc == NULL)
264         {
265                 SetLastWin32Error(ERROR_INVALID_HANDLE);
266                 return(FALSE);
267         }
268         for (i = 0;i<cRects;i++)
269         {
270                 r = *pRects;
271                 BrushObj = BRUSHOBJ_LockBrush(r.hBrush);
272                 IntPatBlt(dc,r.r.left,r.r.top,r.r.right,r.r.bottom,dwRop,BrushObj);
273                 BRUSHOBJ_UnlockBrush(r.hBrush);
274                 pRects++;
275         }
276         DC_UnlockDc( hDC );
277         return TRUE;
278 }
279
280 BOOL STDCALL NtGdiPatBlt(HDC  hDC,
281                         INT  XLeft,
282                         INT  YLeft,
283                         INT  Width,
284                         INT  Height,
285                         DWORD  ROP)
286 {
287   PBRUSHOBJ BrushObj;
288   DC *dc = DC_LockDc(hDC);
289   BOOL ret;
290
291   if (dc == NULL)
292     {
293       SetLastWin32Error(ERROR_INVALID_HANDLE);
294       return(FALSE);
295     }
296
297   BrushObj = BRUSHOBJ_LockBrush(dc->w.hBrush);
298   ret = IntPatBlt(dc,XLeft,YLeft,Width,Height,ROP,BrushObj);
299
300   BRUSHOBJ_UnlockBrush(dc->w.hBrush);
301   DC_UnlockDc( hDC );
302   return(ret);
303 }
304
305 BOOL STDCALL NtGdiSetBrushOrgEx(HDC  hDC,
306                         INT  XOrg,
307                         INT  YOrg,
308                         LPPOINT  Point)
309 {
310   UNIMPLEMENTED;
311 }
312 /* EOF */