Order of send message processing was not respected and the message
[wine.git] / objects / brush.c
blobcb2fa909855e324ca91f1cac2c2950996c395753
1 /*
2 * GDI brush objects
4 * Copyright 1993, 1994 Alexandre Julliard
5 */
7 #include <stdlib.h>
8 #include "winbase.h"
9 #include "brush.h"
10 #include "bitmap.h"
11 #include "debug.h"
14 /***********************************************************************
15 * CreateBrushIndirect16 (GDI.50)
17 HBRUSH16 WINAPI CreateBrushIndirect16( const LOGBRUSH16 * brush )
19 BRUSHOBJ * brushPtr;
20 HBRUSH16 hbrush = GDI_AllocObject( sizeof(BRUSHOBJ), BRUSH_MAGIC );
21 if (!hbrush) return 0;
22 brushPtr = (BRUSHOBJ *) GDI_HEAP_LOCK( hbrush );
23 brushPtr->logbrush.lbStyle = brush->lbStyle;
24 brushPtr->logbrush.lbColor = brush->lbColor;
25 brushPtr->logbrush.lbHatch = brush->lbHatch;
26 GDI_HEAP_UNLOCK( hbrush );
27 TRACE(gdi, "%04x\n", hbrush);
28 return hbrush;
32 /***********************************************************************
33 * CreateBrushIndirect32 (GDI32.27)
35 HBRUSH WINAPI CreateBrushIndirect( const LOGBRUSH * brush )
37 BRUSHOBJ * brushPtr;
38 HBRUSH 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 TRACE(gdi, "%08x\n", hbrush);
46 return hbrush;
50 /***********************************************************************
51 * CreateHatchBrush16 (GDI.58)
53 HBRUSH16 WINAPI CreateHatchBrush16( INT16 style, COLORREF color )
55 LOGBRUSH logbrush = { BS_HATCHED, color, style };
56 TRACE(gdi, "%d %06lx\n", style, color );
57 if ((style < 0) || (style >= NB_HATCH_STYLES)) return 0;
58 return CreateBrushIndirect( &logbrush );
62 /***********************************************************************
63 * CreateHatchBrush32 (GDI32.48)
65 HBRUSH WINAPI CreateHatchBrush( INT style, COLORREF color )
67 LOGBRUSH logbrush = { BS_HATCHED, color, style };
68 TRACE(gdi, "%d %06lx\n", style, color );
69 if ((style < 0) || (style >= NB_HATCH_STYLES)) return 0;
70 return CreateBrushIndirect( &logbrush );
74 /***********************************************************************
75 * CreatePatternBrush16 (GDI.60)
77 HBRUSH16 WINAPI CreatePatternBrush16( HBITMAP16 hbitmap )
79 return (HBRUSH16)CreatePatternBrush( hbitmap );
83 /***********************************************************************
84 * CreatePatternBrush32 (GDI32.54)
86 HBRUSH WINAPI CreatePatternBrush( HBITMAP hbitmap )
88 LOGBRUSH logbrush = { BS_PATTERN, 0, 0 };
89 TRACE(gdi, "%04x\n", hbitmap );
91 logbrush.lbHatch = (INT)BITMAP_CopyBitmap( hbitmap );
92 if(!logbrush.lbHatch)
93 return 0;
94 else
95 return CreateBrushIndirect( &logbrush );
99 /***********************************************************************
100 * CreateDIBPatternBrush16 (GDI.445)
102 HBRUSH16 WINAPI CreateDIBPatternBrush16( HGLOBAL16 hbitmap, UINT16 coloruse )
104 LOGBRUSH logbrush = { BS_DIBPATTERN, coloruse, 0 };
105 BITMAPINFO *info, *newInfo;
106 INT size;
108 TRACE(gdi, "%04x\n", hbitmap );
110 /* Make a copy of the bitmap */
112 if (!(info = (BITMAPINFO *)GlobalLock16( hbitmap ))) return 0;
114 if (info->bmiHeader.biCompression)
115 size = info->bmiHeader.biSizeImage;
116 else
117 size = DIB_GetDIBWidthBytes(info->bmiHeader.biWidth,
118 info->bmiHeader.biBitCount) *
119 info->bmiHeader.biHeight;
120 size += DIB_BitmapInfoSize( info, coloruse );
122 if (!(logbrush.lbHatch = (INT16)GlobalAlloc16( GMEM_MOVEABLE, size )))
124 GlobalUnlock16( hbitmap );
125 return 0;
127 newInfo = (BITMAPINFO *) GlobalLock16( (HGLOBAL16)logbrush.lbHatch );
128 memcpy( newInfo, info, size );
129 GlobalUnlock16( (HGLOBAL16)logbrush.lbHatch );
130 GlobalUnlock16( hbitmap );
131 return CreateBrushIndirect( &logbrush );
135 /***********************************************************************
136 * CreateDIBPatternBrush32 (GDI32.34)
138 * Create a logical brush which has the pattern specified by the DIB
140 * Function call is for compatability only. CreateDIBPatternBrushPt should be used.
142 * RETURNS
144 * Handle to a logical brush on success, NULL on failure.
146 * BUGS
149 HBRUSH WINAPI CreateDIBPatternBrush(
150 HGLOBAL hbitmap, /* Global object containg BITMAPINFO structure */
151 UINT coloruse /* Specifies color format, if provided */
154 LOGBRUSH logbrush = { BS_DIBPATTERN, coloruse, 0 };
155 BITMAPINFO *info, *newInfo;
156 INT size;
158 TRACE(gdi, "%04x\n", hbitmap );
160 /* Make a copy of the bitmap */
162 if (!(info = (BITMAPINFO *)GlobalLock( hbitmap ))) return 0;
164 if (info->bmiHeader.biCompression)
165 size = info->bmiHeader.biSizeImage;
166 else
167 size = DIB_GetDIBWidthBytes(info->bmiHeader.biWidth,
168 info->bmiHeader.biBitCount) *
169 info->bmiHeader.biHeight;
170 size += DIB_BitmapInfoSize( info, coloruse );
172 if (!(logbrush.lbHatch = (INT)GlobalAlloc16( GMEM_MOVEABLE, size )))
174 GlobalUnlock16( hbitmap );
175 return 0;
177 newInfo = (BITMAPINFO *) GlobalLock16( (HGLOBAL16)logbrush.lbHatch );
178 memcpy( newInfo, info, size );
179 GlobalUnlock16( (HGLOBAL16)logbrush.lbHatch );
180 GlobalUnlock( hbitmap );
181 return CreateBrushIndirect( &logbrush );
185 /***********************************************************************
186 * CreateDIBPatternBrushPt (GDI32.35)
188 * Create a logical brush which has the pattern specified by the DIB
190 * RETURNS
192 * Handle to a logical brush on success, NULL on failure.
194 * BUGS
197 HBRUSH WINAPI CreateDIBPatternBrushPt(
198 const void* data, /* Pointer to a BITMAPINFO structure followed by more data */
199 UINT coloruse /* Specifies color format, if provided */
202 BITMAPINFO *info=(BITMAPINFO*)data;
203 LOGBRUSH logbrush = { BS_DIBPATTERN, coloruse, 0 };
204 BITMAPINFO *newInfo;
205 INT size;
207 TRACE(gdi, "%p\n", info );
209 /* Make a copy of the bitmap */
212 if (info->bmiHeader.biCompression)
213 size = info->bmiHeader.biSizeImage;
214 else
215 size = DIB_GetDIBWidthBytes(info->bmiHeader.biWidth,
216 info->bmiHeader.biBitCount) *
217 info->bmiHeader.biHeight;
218 size += DIB_BitmapInfoSize( info, coloruse );
220 if (!(logbrush.lbHatch = (INT)GlobalAlloc16( GMEM_MOVEABLE, size )))
222 return 0;
224 newInfo = (BITMAPINFO *) GlobalLock16( (HGLOBAL16)logbrush.lbHatch );
225 memcpy( newInfo, info, size );
226 GlobalUnlock16( (HGLOBAL16)logbrush.lbHatch );
227 return CreateBrushIndirect( &logbrush );
231 /***********************************************************************
232 * CreateSolidBrush (GDI.66)
234 HBRUSH16 WINAPI CreateSolidBrush16( COLORREF color )
236 LOGBRUSH logbrush = { BS_SOLID, color, 0 };
237 TRACE(gdi, "%06lx\n", color );
238 return CreateBrushIndirect( &logbrush );
242 /***********************************************************************
243 * CreateSolidBrush32 (GDI32.64)
245 HBRUSH WINAPI CreateSolidBrush( COLORREF color )
247 LOGBRUSH logbrush = { BS_SOLID, color, 0 };
248 TRACE(gdi, "%06lx\n", color );
249 return CreateBrushIndirect( &logbrush );
253 /***********************************************************************
254 * SetBrushOrg (GDI.148)
256 DWORD WINAPI SetBrushOrg16( HDC16 hdc, INT16 x, INT16 y )
258 DWORD retval;
259 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
260 if (!dc) return FALSE;
261 retval = dc->w.brushOrgX | (dc->w.brushOrgY << 16);
262 dc->w.brushOrgX = x;
263 dc->w.brushOrgY = y;
264 return retval;
268 /***********************************************************************
269 * SetBrushOrgEx (GDI32.308)
271 BOOL WINAPI SetBrushOrgEx( HDC hdc, INT x, INT y, LPPOINT oldorg )
273 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
275 if (!dc) return FALSE;
276 if (oldorg)
278 oldorg->x = dc->w.brushOrgX;
279 oldorg->y = dc->w.brushOrgY;
281 dc->w.brushOrgX = x;
282 dc->w.brushOrgY = y;
283 return TRUE;
286 /***********************************************************************
287 * FixBrushOrgEx (GDI32.102)
288 * SDK says discontinued, but in Win95 GDI32 this is the same as SetBrushOrgEx
290 BOOL WINAPI FixBrushOrgEx( HDC hdc, INT x, INT y, LPPOINT oldorg )
292 return SetBrushOrgEx(hdc,x,y,oldorg);
296 /***********************************************************************
297 * BRUSH_DeleteObject
299 BOOL BRUSH_DeleteObject( HBRUSH16 hbrush, BRUSHOBJ * brush )
301 switch(brush->logbrush.lbStyle)
303 case BS_PATTERN:
304 DeleteObject( (HGDIOBJ)brush->logbrush.lbHatch );
305 break;
306 case BS_DIBPATTERN:
307 GlobalFree16( (HGLOBAL16)brush->logbrush.lbHatch );
308 break;
310 return GDI_FreeObject( hbrush );
314 /***********************************************************************
315 * BRUSH_GetObject16
317 INT16 BRUSH_GetObject16( BRUSHOBJ * brush, INT16 count, LPSTR buffer )
319 LOGBRUSH16 logbrush;
321 logbrush.lbStyle = brush->logbrush.lbStyle;
322 logbrush.lbColor = brush->logbrush.lbColor;
323 logbrush.lbHatch = brush->logbrush.lbHatch;
324 if (count > sizeof(logbrush)) count = sizeof(logbrush);
325 memcpy( buffer, &logbrush, count );
326 return count;
330 /***********************************************************************
331 * BRUSH_GetObject32
333 INT BRUSH_GetObject( BRUSHOBJ * brush, INT count, LPSTR buffer )
335 if (count > sizeof(brush->logbrush)) count = sizeof(brush->logbrush);
336 memcpy( buffer, &brush->logbrush, count );
337 return count;
341 /***********************************************************************
342 * SetSolidBrush16 (GDI.604)
344 * If hBrush is a solid brush, change it's color to newColor.
346 * RETURNS
347 * TRUE on success, FALSE on failure.
348 * FIXME: not yet implemented!
350 BOOL16 WINAPI SetSolidBrush16(HBRUSH16 hBrush, COLORREF newColor )
352 FIXME(gdi, "(hBrush %04x, newColor %04x): stub!\n", hBrush, (int)newColor);
354 return(FALSE);