4 * Copyright 1993, 1994 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "wine/wingdi16.h"
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(gdi);
34 /* GDI logical brush object */
41 #define NB_HATCH_STYLES 6
43 static HGDIOBJ BRUSH_SelectObject( HGDIOBJ handle, void *obj, HDC hdc );
44 static INT BRUSH_GetObject16( HGDIOBJ handle, void *obj, INT count, LPVOID buffer );
45 static INT BRUSH_GetObject( HGDIOBJ handle, void *obj, INT count, LPVOID buffer );
46 static BOOL BRUSH_DeleteObject( HGDIOBJ handle, void *obj );
48 static const struct gdi_obj_funcs brush_funcs =
50 BRUSH_SelectObject, /* pSelectObject */
51 BRUSH_GetObject16, /* pGetObject16 */
52 BRUSH_GetObject, /* pGetObjectA */
53 BRUSH_GetObject, /* pGetObjectW */
54 NULL, /* pUnrealizeObject */
55 BRUSH_DeleteObject /* pDeleteObject */
58 static HGLOBAL16 dib_copy(BITMAPINFO *info, UINT coloruse)
64 if (info->bmiHeader.biCompression)
65 size = info->bmiHeader.biSizeImage;
67 size = DIB_GetDIBImageBytes(info->bmiHeader.biWidth,
68 info->bmiHeader.biHeight,
69 info->bmiHeader.biBitCount);
70 size += DIB_BitmapInfoSize( info, coloruse );
72 if (!(hmem = GlobalAlloc16( GMEM_MOVEABLE, size )))
76 newInfo = (BITMAPINFO *) GlobalLock16( hmem );
77 memcpy( newInfo, info, size );
78 GlobalUnlock16( hmem );
83 /***********************************************************************
84 * CreateBrushIndirect (GDI32.@)
87 * As for Windows 95 and Windows 98:
88 * Creating brushes from bitmaps or DIBs larger than 8x8 pixels
89 * is not supported. If a larger bitmap is given, only a portion
90 * of the bitmap is used.
92 HBRUSH WINAPI CreateBrushIndirect( const LOGBRUSH * brush )
97 if (!(ptr = GDI_AllocObject( sizeof(BRUSHOBJ), BRUSH_MAGIC,
98 (HGDIOBJ *)&hbrush, &brush_funcs ))) return 0;
99 ptr->logbrush.lbStyle = brush->lbStyle;
100 ptr->logbrush.lbColor = brush->lbColor;
101 ptr->logbrush.lbHatch = brush->lbHatch;
103 switch (ptr->logbrush.lbStyle)
106 ptr->logbrush.lbStyle = BS_PATTERN;
109 ptr->logbrush.lbHatch = (LONG)BITMAP_CopyBitmap( (HBITMAP) ptr->logbrush.lbHatch );
110 if (!ptr->logbrush.lbHatch) goto error;
113 case BS_DIBPATTERNPT:
114 ptr->logbrush.lbStyle = BS_DIBPATTERN;
115 ptr->logbrush.lbHatch = (LONG)dib_copy( (BITMAPINFO *) ptr->logbrush.lbHatch,
116 ptr->logbrush.lbColor);
117 if (!ptr->logbrush.lbHatch) goto error;
120 case BS_DIBPATTERN8X8:
124 HGLOBAL h = (HGLOBAL)ptr->logbrush.lbHatch;
126 ptr->logbrush.lbStyle = BS_DIBPATTERN;
127 if (!(bmi = (BITMAPINFO *)GlobalLock( h ))) goto error;
128 ptr->logbrush.lbHatch = dib_copy( bmi, ptr->logbrush.lbColor);
130 if (!ptr->logbrush.lbHatch) goto error;
135 if(ptr->logbrush.lbStyle > BS_MONOPATTERN) goto error;
139 GDI_ReleaseObj( hbrush );
140 TRACE("%p\n", hbrush);
144 GDI_FreeObject( hbrush, ptr );
149 /***********************************************************************
150 * CreateHatchBrush (GDI32.@)
152 HBRUSH WINAPI CreateHatchBrush( INT style, COLORREF color )
156 TRACE("%d %06lx\n", style, color );
158 logbrush.lbStyle = BS_HATCHED;
159 logbrush.lbColor = color;
160 logbrush.lbHatch = style;
162 return CreateBrushIndirect( &logbrush );
166 /***********************************************************************
167 * CreatePatternBrush (GDI32.@)
169 HBRUSH WINAPI CreatePatternBrush( HBITMAP hbitmap )
171 LOGBRUSH logbrush = { BS_PATTERN, 0, 0 };
172 TRACE("%p\n", hbitmap );
174 logbrush.lbHatch = (ULONG_PTR)hbitmap;
175 return CreateBrushIndirect( &logbrush );
179 /***********************************************************************
180 * CreateDIBPatternBrush (GDI32.@)
182 * Create a logical brush which has the pattern specified by the DIB
184 * Function call is for compatibility only. CreateDIBPatternBrushPt should be used.
188 * Handle to a logical brush on success, NULL on failure.
193 HBRUSH WINAPI CreateDIBPatternBrush(
194 HGLOBAL hbitmap, /* [in] Global object containg BITMAPINFO structure */
195 UINT coloruse /* [in] Specifies color format, if provided */
200 TRACE("%p\n", hbitmap );
202 logbrush.lbStyle = BS_DIBPATTERN;
203 logbrush.lbColor = coloruse;
205 logbrush.lbHatch = (LONG)hbitmap;
207 return CreateBrushIndirect( &logbrush );
211 /***********************************************************************
212 * CreateDIBPatternBrushPt (GDI32.@)
214 * Create a logical brush which has the pattern specified by the DIB
218 * Handle to a logical brush on success, NULL on failure.
223 HBRUSH WINAPI CreateDIBPatternBrushPt(
224 const void* data, /* [in] Pointer to a BITMAPINFO structure followed by more data */
225 UINT coloruse /* [in] Specifies color format, if provided */
228 BITMAPINFO *info=(BITMAPINFO*)data;
231 TRACE("%p %ldx%ld %dbpp\n", info, info->bmiHeader.biWidth,
232 info->bmiHeader.biHeight, info->bmiHeader.biBitCount);
234 logbrush.lbStyle = BS_DIBPATTERNPT;
235 logbrush.lbColor = coloruse;
236 logbrush.lbHatch = (LONG) data;
238 return CreateBrushIndirect( &logbrush );
242 /***********************************************************************
243 * CreateSolidBrush (GDI32.@)
245 HBRUSH WINAPI CreateSolidBrush( COLORREF color )
249 TRACE("%06lx\n", color );
251 logbrush.lbStyle = BS_SOLID;
252 logbrush.lbColor = color;
253 logbrush.lbHatch = 0;
255 return CreateBrushIndirect( &logbrush );
259 /***********************************************************************
260 * SetBrushOrgEx (GDI32.@)
262 BOOL WINAPI SetBrushOrgEx( HDC hdc, INT x, INT y, LPPOINT oldorg )
264 DC *dc = DC_GetDCPtr( hdc );
266 if (!dc) return FALSE;
269 oldorg->x = dc->brushOrgX;
270 oldorg->y = dc->brushOrgY;
274 GDI_ReleaseObj( hdc );
278 /***********************************************************************
279 * FixBrushOrgEx (GDI32.@)
280 * SDK says discontinued, but in Win95 GDI32 this is the same as SetBrushOrgEx
282 BOOL WINAPI FixBrushOrgEx( HDC hdc, INT x, INT y, LPPOINT oldorg )
284 return SetBrushOrgEx(hdc,x,y,oldorg);
288 /***********************************************************************
291 static HGDIOBJ BRUSH_SelectObject( HGDIOBJ handle, void *obj, HDC hdc )
293 BRUSHOBJ *brush = obj;
295 DC *dc = DC_GetDCPtr( hdc );
299 if (brush->logbrush.lbStyle == BS_PATTERN)
300 BITMAP_SetOwnerDC( (HBITMAP)brush->logbrush.lbHatch, dc );
303 if (dc->funcs->pSelectBrush) handle = dc->funcs->pSelectBrush( dc->physDev, handle );
304 if (handle) dc->hBrush = handle;
306 GDI_ReleaseObj( hdc );
311 /***********************************************************************
314 static BOOL BRUSH_DeleteObject( HGDIOBJ handle, void *obj )
316 BRUSHOBJ *brush = obj;
318 switch(brush->logbrush.lbStyle)
321 DeleteObject( (HGDIOBJ)brush->logbrush.lbHatch );
324 GlobalFree16( (HGLOBAL16)brush->logbrush.lbHatch );
327 return GDI_FreeObject( handle, obj );
331 /***********************************************************************
334 static INT BRUSH_GetObject16( HGDIOBJ handle, void *obj, INT count, LPVOID buffer )
336 BRUSHOBJ *brush = obj;
339 logbrush.lbStyle = brush->logbrush.lbStyle;
340 logbrush.lbColor = brush->logbrush.lbColor;
341 logbrush.lbHatch = brush->logbrush.lbHatch;
342 if (count > sizeof(logbrush)) count = sizeof(logbrush);
343 memcpy( buffer, &logbrush, count );
348 /***********************************************************************
351 static INT BRUSH_GetObject( HGDIOBJ handle, void *obj, INT count, LPVOID buffer )
353 BRUSHOBJ *brush = obj;
355 if (count > sizeof(brush->logbrush)) count = sizeof(brush->logbrush);
356 memcpy( buffer, &brush->logbrush, count );
361 /***********************************************************************
362 * SetSolidBrush (GDI.604)
364 * If hBrush is a solid brush, change its color to newColor.
367 * TRUE on success, FALSE on failure.
369 * FIXME: untested, not sure if correct.
371 BOOL16 WINAPI SetSolidBrush16(HBRUSH16 hBrush, COLORREF newColor )
376 TRACE("(hBrush %04x, newColor %08lx)\n", hBrush, (DWORD)newColor);
377 if (!(brushPtr = (BRUSHOBJ *) GDI_GetObjPtr( HBRUSH_32(hBrush), BRUSH_MAGIC )))
380 if (brushPtr->logbrush.lbStyle == BS_SOLID)
382 brushPtr->logbrush.lbColor = newColor;
386 GDI_ReleaseObj( HBRUSH_32(hBrush) );