Started moving some X11 window management code to windows/x11drv.
[wine.git] / objects / brush.c
blob2bed5915cf373133473b136eebe3b86b0b33a8d3
1 /*
2 * GDI brush objects
4 * Copyright 1993, 1994 Alexandre Julliard
5 */
7 #include <stdlib.h>
8 #include "brush.h"
9 #include "bitmap.h"
10 #include "metafile.h"
11 #include "color.h"
12 #include "debug.h"
15 /***********************************************************************
16 * CreateBrushIndirect16 (GDI.50)
18 HBRUSH16 WINAPI CreateBrushIndirect16( const LOGBRUSH16 * brush )
20 BRUSHOBJ * brushPtr;
21 HBRUSH16 hbrush = GDI_AllocObject( sizeof(BRUSHOBJ), BRUSH_MAGIC );
22 if (!hbrush) return 0;
23 brushPtr = (BRUSHOBJ *) GDI_HEAP_LOCK( hbrush );
24 brushPtr->logbrush.lbStyle = brush->lbStyle;
25 brushPtr->logbrush.lbColor = brush->lbColor;
26 brushPtr->logbrush.lbHatch = brush->lbHatch;
27 GDI_HEAP_UNLOCK( hbrush );
28 return hbrush;
32 /***********************************************************************
33 * CreateBrushIndirect32 (GDI32.27)
35 HBRUSH32 WINAPI CreateBrushIndirect32( const LOGBRUSH32 * brush )
37 BRUSHOBJ * brushPtr;
38 HBRUSH32 hbrush = GDI_AllocObject( sizeof(BRUSHOBJ), BRUSH_MAGIC );
39 if (!hbrush) return 0;
40 brushPtr = (BRUSHOBJ *) GDI_HEAP_LOCK( hbrush );
41 brushPtr->logbrush.lbStyle = brush->lbStyle;
42 brushPtr->logbrush.lbColor = brush->lbColor;
43 brushPtr->logbrush.lbHatch = brush->lbHatch;
44 GDI_HEAP_UNLOCK( hbrush );
45 return hbrush;
49 /***********************************************************************
50 * CreateHatchBrush16 (GDI.58)
52 HBRUSH16 WINAPI CreateHatchBrush16( INT16 style, COLORREF color )
54 LOGBRUSH32 logbrush = { BS_HATCHED, color, style };
55 TRACE(gdi, "%d %06lx\n", style, color );
56 if ((style < 0) || (style >= NB_HATCH_STYLES)) return 0;
57 return CreateBrushIndirect32( &logbrush );
61 /***********************************************************************
62 * CreateHatchBrush32 (GDI32.48)
64 HBRUSH32 WINAPI CreateHatchBrush32( INT32 style, COLORREF color )
66 LOGBRUSH32 logbrush = { BS_HATCHED, color, style };
67 TRACE(gdi, "%d %06lx\n", style, color );
68 if ((style < 0) || (style >= NB_HATCH_STYLES)) return 0;
69 return CreateBrushIndirect32( &logbrush );
73 /***********************************************************************
74 * CreatePatternBrush16 (GDI.60)
76 HBRUSH16 WINAPI CreatePatternBrush16( HBITMAP16 hbitmap )
78 return (HBRUSH16)CreatePatternBrush32( hbitmap );
82 /***********************************************************************
83 * CreatePatternBrush32 (GDI32.54)
85 HBRUSH32 WINAPI CreatePatternBrush32( HBITMAP32 hbitmap )
87 LOGBRUSH32 logbrush = { BS_PATTERN, 0, 0 };
88 TRACE(gdi, "%04x\n", hbitmap );
90 logbrush.lbHatch = (INT32)BITMAP_CopyBitmap( hbitmap );
91 if(!logbrush.lbHatch)
92 return 0;
93 else
94 return CreateBrushIndirect32( &logbrush );
98 /***********************************************************************
99 * CreateDIBPatternBrush16 (GDI.445)
101 HBRUSH16 WINAPI CreateDIBPatternBrush16( HGLOBAL16 hbitmap, UINT16 coloruse )
103 LOGBRUSH32 logbrush = { BS_DIBPATTERN, coloruse, 0 };
104 BITMAPINFO *info, *newInfo;
105 INT32 size;
107 TRACE(gdi, "%04x\n", hbitmap );
109 /* Make a copy of the bitmap */
111 if (!(info = (BITMAPINFO *)GlobalLock16( hbitmap ))) return 0;
113 if (info->bmiHeader.biCompression)
114 size = info->bmiHeader.biSizeImage;
115 else
116 size = (info->bmiHeader.biWidth * info->bmiHeader.biBitCount + 31) / 32
117 * 8 * info->bmiHeader.biHeight;
118 size += DIB_BitmapInfoSize( info, coloruse );
120 if (!(logbrush.lbHatch = (INT16)GlobalAlloc16( GMEM_MOVEABLE, size )))
122 GlobalUnlock16( hbitmap );
123 return 0;
125 newInfo = (BITMAPINFO *) GlobalLock16( (HGLOBAL16)logbrush.lbHatch );
126 memcpy( newInfo, info, size );
127 GlobalUnlock16( (HGLOBAL16)logbrush.lbHatch );
128 GlobalUnlock16( hbitmap );
129 return CreateBrushIndirect32( &logbrush );
133 /***********************************************************************
134 * CreateDIBPatternBrush32 (GDI32.34)
136 HBRUSH32 WINAPI CreateDIBPatternBrush32( HGLOBAL32 hbitmap, UINT32 coloruse )
138 LOGBRUSH32 logbrush = { BS_DIBPATTERN, coloruse, 0 };
139 BITMAPINFO *info, *newInfo;
140 INT32 size;
142 TRACE(gdi, "%04x\n", hbitmap );
144 /* Make a copy of the bitmap */
146 if (!(info = (BITMAPINFO *)GlobalLock32( hbitmap ))) return 0;
148 if (info->bmiHeader.biCompression)
149 size = info->bmiHeader.biSizeImage;
150 else
151 size = (info->bmiHeader.biWidth * info->bmiHeader.biBitCount + 31) / 32
152 * 8 * info->bmiHeader.biHeight;
153 size += DIB_BitmapInfoSize( info, coloruse );
155 if (!(logbrush.lbHatch = (INT32)GlobalAlloc16( GMEM_MOVEABLE, size )))
157 GlobalUnlock16( hbitmap );
158 return 0;
160 newInfo = (BITMAPINFO *) GlobalLock16( (HGLOBAL16)logbrush.lbHatch );
161 memcpy( newInfo, info, size );
162 GlobalUnlock16( (HGLOBAL16)logbrush.lbHatch );
163 GlobalUnlock16( hbitmap );
164 return CreateBrushIndirect32( &logbrush );
168 /***********************************************************************
169 * CreateSolidBrush (GDI.66)
171 HBRUSH16 WINAPI CreateSolidBrush16( COLORREF color )
173 LOGBRUSH32 logbrush = { BS_SOLID, color, 0 };
174 TRACE(gdi, "%06lx\n", color );
175 return CreateBrushIndirect32( &logbrush );
179 /***********************************************************************
180 * CreateSolidBrush32 (GDI32.64)
182 HBRUSH32 WINAPI CreateSolidBrush32( COLORREF color )
184 LOGBRUSH32 logbrush = { BS_SOLID, color, 0 };
185 TRACE(gdi, "%06lx\n", color );
186 return CreateBrushIndirect32( &logbrush );
190 /***********************************************************************
191 * SetBrushOrg (GDI.148)
193 DWORD WINAPI SetBrushOrg( HDC16 hdc, INT16 x, INT16 y )
195 DWORD retval;
196 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
197 if (!dc) return FALSE;
198 retval = dc->w.brushOrgX | (dc->w.brushOrgY << 16);
199 dc->w.brushOrgX = x;
200 dc->w.brushOrgY = y;
201 return retval;
205 /***********************************************************************
206 * SetBrushOrgEx (GDI32.308)
208 BOOL32 WINAPI SetBrushOrgEx( HDC32 hdc, INT32 x, INT32 y, LPPOINT32 oldorg )
210 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
212 if (!dc) return FALSE;
213 if (oldorg)
215 oldorg->x = dc->w.brushOrgX;
216 oldorg->y = dc->w.brushOrgY;
218 dc->w.brushOrgX = x;
219 dc->w.brushOrgY = y;
220 return TRUE;
223 /***********************************************************************
224 * FixBrushOrgEx (GDI32.102)
225 * SDK says discontinued, but in Win95 GDI32 this is the same as SetBrushOrgEx
227 BOOL32 WINAPI FixBrushOrgEx( HDC32 hdc, INT32 x, INT32 y, LPPOINT32 oldorg )
229 return SetBrushOrgEx(hdc,x,y,oldorg);
233 /***********************************************************************
234 * BRUSH_DeleteObject
236 BOOL32 BRUSH_DeleteObject( HBRUSH16 hbrush, BRUSHOBJ * brush )
238 switch(brush->logbrush.lbStyle)
240 case BS_PATTERN:
241 DeleteObject32( (HGDIOBJ32)brush->logbrush.lbHatch );
242 break;
243 case BS_DIBPATTERN:
244 GlobalFree16( (HGLOBAL16)brush->logbrush.lbHatch );
245 break;
247 return GDI_FreeObject( hbrush );
251 /***********************************************************************
252 * BRUSH_GetObject16
254 INT16 BRUSH_GetObject16( BRUSHOBJ * brush, INT16 count, LPSTR buffer )
256 LOGBRUSH16 logbrush;
258 logbrush.lbStyle = brush->logbrush.lbStyle;
259 logbrush.lbColor = brush->logbrush.lbColor;
260 logbrush.lbHatch = brush->logbrush.lbHatch;
261 if (count > sizeof(logbrush)) count = sizeof(logbrush);
262 memcpy( buffer, &logbrush, count );
263 return count;
267 /***********************************************************************
268 * BRUSH_GetObject32
270 INT32 BRUSH_GetObject32( BRUSHOBJ * brush, INT32 count, LPSTR buffer )
272 if (count > sizeof(brush->logbrush)) count = sizeof(brush->logbrush);
273 memcpy( buffer, &brush->logbrush, count );
274 return count;