update for HEAD-2003021201
[reactos.git] / subsys / win32k / objects / brush.c
1 /* $Id$
2  */
3
4
5 #undef WIN32_LEAN_AND_MEAN
6 #include <windows.h>
7 #include <ddk/ntddk.h>
8 #include <win32k/bitmaps.h>
9 #include <win32k/brush.h>
10 //#include <win32k/debug.h>
11 #include <include/object.h>
12
13 #define NDEBUG
14 #include <win32k/debug1.h>
15
16 HBRUSH STDCALL W32kCreateBrushIndirect(CONST LOGBRUSH  *lb)
17 {
18   PBRUSHOBJ  brushPtr;
19   HBRUSH  hBrush;
20
21   hBrush = BRUSHOBJ_AllocBrush();
22   if (hBrush == NULL)
23   {
24     return 0;
25   }
26
27   brushPtr = BRUSHOBJ_LockBrush (hBrush);
28   ASSERT( brushPtr ); //I want to know if this ever occurs
29
30   if( brushPtr ){
31         brushPtr->iSolidColor = lb->lbColor;
32         brushPtr->logbrush.lbStyle = lb->lbStyle;
33         brushPtr->logbrush.lbColor = lb->lbColor;
34         brushPtr->logbrush.lbHatch = lb->lbHatch;
35
36         BRUSHOBJ_UnlockBrush( hBrush );
37         return  hBrush;
38   }
39   return NULL;
40 }
41
42 HBRUSH STDCALL W32kCreateDIBPatternBrush(HGLOBAL  hDIBPacked,
43                                   UINT  ColorSpec)
44 {
45   UNIMPLEMENTED;
46 #if 0
47   LOGBRUSH  logbrush;
48   PBITMAPINFO  info, newInfo;
49   INT  size;
50
51   DPRINT("%04x\n", hbitmap );
52
53   logbrush.lbStyle = BS_DIBPATTERN;
54   logbrush.lbColor = coloruse;
55   logbrush.lbHatch = 0;
56
57   /* Make a copy of the bitmap */
58   if (!(info = (BITMAPINFO *)GlobalLock( hbitmap )))
59   {
60     return 0;
61   }
62
63
64   if (info->bmiHeader.biCompression) size = info->bmiHeader.biSizeImage;
65   else
66     size = DIB_GetDIBImageBytes(info->bmiHeader.biWidth, info->bmiHeader.biHeight, info->bmiHeader.biBitCount);
67   size += DIB_BitmapInfoSize(info, coloruse);
68
69   if (!(logbrush.lbHatch = (INT)GlobalAlloc16( GMEM_MOVEABLE, size )))
70   {
71     GlobalUnlock16( hbitmap );
72     return 0;
73   }
74   newInfo = (BITMAPINFO *) GlobalLock16((HGLOBAL16)logbrush.lbHatch);
75   memcpy(newInfo, info, size);
76   GlobalUnlock16((HGLOBAL16)logbrush.lbHatch);
77   GlobalUnlock(hbitmap);
78   return W32kCreateBrushIndirect(&logbrush);
79 #endif
80 }
81
82 HBRUSH STDCALL W32kCreateDIBPatternBrushPt(CONST VOID  *PackedDIB,
83                                     UINT  Usage)
84 {
85   INT  size;
86   LOGBRUSH  logbrush;
87   PBITMAPINFO  info;
88   PBITMAPINFO  newInfo;
89
90   info = (BITMAPINFO *) PackedDIB;
91   if (info == NULL)
92   {
93     return 0;
94   }
95   DPRINT ("%p %ldx%ld %dbpp\n",
96           info,
97           info->bmiHeader.biWidth,
98           info->bmiHeader.biHeight,
99           info->bmiHeader.biBitCount);
100
101   logbrush.lbStyle = BS_DIBPATTERN;
102   logbrush.lbColor = Usage;
103   logbrush.lbHatch = 0;
104
105   /* Make a copy of the bitmap */
106
107   if (info->bmiHeader.biCompression)
108   {
109     size = info->bmiHeader.biSizeImage;
110   }
111   else
112     {
113     size = DIB_GetDIBImageBytes (info->bmiHeader.biWidth, info->bmiHeader.biHeight, info->bmiHeader.biBitCount);
114   }
115   size += DIB_BitmapInfoSize (info, Usage);
116
117   logbrush.lbHatch = (LONG) GDIOBJ_AllocObj(size, GO_MAGIC_DONTCARE);
118   if (logbrush.lbHatch == 0)
119   {
120     return 0;
121   }
122   newInfo = (PBITMAPINFO) GDIOBJ_LockObj ((HGDIOBJ) logbrush.lbHatch, GO_MAGIC_DONTCARE);
123   ASSERT(newInfo);
124   memcpy(newInfo, info, size);
125   GDIOBJ_UnlockObj( (HGDIOBJ) logbrush.lbHatch, GO_MAGIC_DONTCARE );
126
127   return  W32kCreateBrushIndirect (&logbrush);
128 }
129
130 HBRUSH STDCALL W32kCreateHatchBrush(INT  Style,
131                              COLORREF  Color)
132 {
133   LOGBRUSH  logbrush;
134
135   DPRINT("%d %06lx\n", Style, Color);
136
137   if (Style < 0 || Style >= NB_HATCH_STYLES)
138   {
139     return 0;
140   }
141   logbrush.lbStyle = BS_HATCHED;
142   logbrush.lbColor = Color;
143   logbrush.lbHatch = Style;
144
145   return  W32kCreateBrushIndirect (&logbrush);
146 }
147
148 HBRUSH STDCALL W32kCreatePatternBrush(HBITMAP  hBitmap)
149 {
150   LOGBRUSH  logbrush = { BS_PATTERN, 0, 0 };
151
152   DPRINT ("%04x\n", hBitmap);
153   logbrush.lbHatch = (INT) BITMAPOBJ_CopyBitmap (hBitmap);
154   if(!logbrush.lbHatch)
155   {
156     return 0;
157   }
158   else
159   {
160     return W32kCreateBrushIndirect( &logbrush );
161   }
162 }
163
164 HBRUSH STDCALL W32kCreateSolidBrush(COLORREF  Color)
165 {
166   LOGBRUSH logbrush;
167
168   logbrush.lbStyle = BS_SOLID;
169   logbrush.lbColor = Color;
170   logbrush.lbHatch = 0;
171
172   return W32kCreateBrushIndirect(&logbrush);
173 }
174
175 BOOL STDCALL W32kFixBrushOrgEx(VOID)
176 {
177   return FALSE;
178 }
179
180 BOOL STDCALL W32kPatBlt(HDC  hDC,
181                         INT  XLeft,
182                         INT  YLeft,
183                         INT  Width,
184                         INT  Height,
185                         DWORD  ROP)
186 {
187   RECT DestRect;
188   PBRUSHOBJ BrushObj;
189   PSURFOBJ SurfObj;
190   DC *dc = DC_HandleToPtr(hDC);
191   BOOL ret;
192
193   if (dc == NULL)
194     {
195       return(FALSE);
196     }
197
198   SurfObj = (SURFOBJ*)AccessUserObject((ULONG)dc->Surface);
199
200   BrushObj = (BRUSHOBJ*) GDIOBJ_LockObj(dc->w.hBrush, GO_BRUSH_MAGIC);
201   assert(BrushObj);
202   if (BrushObj->logbrush.lbStyle != BS_NULL)
203     {
204       if (Width > 0)
205         {
206           DestRect.left = XLeft + dc->w.DCOrgX;
207           DestRect.right = XLeft + Width + dc->w.DCOrgX;
208         }
209       else
210         {
211           DestRect.left = XLeft + Width + dc->w.DCOrgX;
212           DestRect.right = XLeft + dc->w.DCOrgX;
213         }
214       if (Height > 0)
215         {
216           DestRect.top = YLeft + dc->w.DCOrgY;
217           DestRect.bottom = YLeft + Height + dc->w.DCOrgY;
218         }
219       else
220         {
221           DestRect.top = YLeft + Height + dc->w.DCOrgY;
222           DestRect.bottom = YLeft + dc->w.DCOrgY;
223         }
224       ret = EngBitBlt(SurfObj,
225                       NULL,
226                       NULL,
227                       NULL,
228                       NULL,
229                       &DestRect,
230                       NULL,
231                       NULL,
232                       BrushObj,
233                       NULL,
234                       PATCOPY);
235     }
236   GDIOBJ_UnlockObj( dc->w.hBrush, GO_BRUSH_MAGIC );
237   DC_ReleasePtr( hDC );
238   return(ret);
239 }
240
241 BOOL STDCALL W32kSetBrushOrgEx(HDC  hDC,
242                         INT  XOrg,
243                         INT  YOrg,
244                         LPPOINT  Point)
245 {
246   UNIMPLEMENTED;
247 }