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"
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(gdi
);
33 /* GDI logical brush object */
40 #define NB_HATCH_STYLES 6
42 static HGDIOBJ
BRUSH_SelectObject( HGDIOBJ handle
, void *obj
, HDC hdc
);
43 static INT
BRUSH_GetObject16( HGDIOBJ handle
, void *obj
, INT count
, LPVOID buffer
);
44 static INT
BRUSH_GetObject( HGDIOBJ handle
, void *obj
, INT count
, LPVOID buffer
);
45 static BOOL
BRUSH_DeleteObject( HGDIOBJ handle
, void *obj
);
47 static const struct gdi_obj_funcs brush_funcs
=
49 BRUSH_SelectObject
, /* pSelectObject */
50 BRUSH_GetObject16
, /* pGetObject16 */
51 BRUSH_GetObject
, /* pGetObjectA */
52 BRUSH_GetObject
, /* pGetObjectW */
53 NULL
, /* pUnrealizeObject */
54 BRUSH_DeleteObject
/* pDeleteObject */
57 static HGLOBAL16
dib_copy(BITMAPINFO
*info
, UINT coloruse
)
63 if (info
->bmiHeader
.biCompression
)
64 size
= info
->bmiHeader
.biSizeImage
;
66 size
= DIB_GetDIBImageBytes(info
->bmiHeader
.biWidth
,
67 info
->bmiHeader
.biHeight
,
68 info
->bmiHeader
.biBitCount
);
69 size
+= DIB_BitmapInfoSize( info
, coloruse
);
71 if (!(hmem
= GlobalAlloc16( GMEM_MOVEABLE
, size
)))
75 newInfo
= (BITMAPINFO
*) GlobalLock16( hmem
);
76 memcpy( newInfo
, info
, size
);
77 GlobalUnlock16( hmem
);
83 static BOOL
create_brush_indirect(BRUSHOBJ
*brushPtr
, BOOL v16
)
85 LOGBRUSH
*brush
= &brushPtr
->logbrush
;
87 switch (brush
->lbStyle
)
90 brush
->lbStyle
= BS_PATTERN
;
92 brush
->lbHatch
= (LONG
)BITMAP_CopyBitmap( (HBITMAP
) brush
->lbHatch
);
98 brush
->lbStyle
= BS_DIBPATTERN
;
99 brush
->lbHatch
= (LONG
)dib_copy( (BITMAPINFO
*) brush
->lbHatch
,
101 if (! brush
->lbHatch
)
105 case BS_DIBPATTERN8X8
:
109 HGLOBAL h
= brush
->lbHatch
;
111 brush
->lbStyle
= BS_DIBPATTERN
;
114 if (!(bmi
= (BITMAPINFO
*)GlobalLock16( h
)))
119 if (!(bmi
= (BITMAPINFO
*)GlobalLock( h
)))
123 brush
->lbHatch
= dib_copy( bmi
, brush
->lbColor
);
125 if (v16
) GlobalUnlock16( h
);
126 else GlobalUnlock( h
);
135 if( brush
->lbStyle
<= BS_MONOPATTERN
)
143 /***********************************************************************
144 * CreateBrushIndirect (GDI.50)
146 HBRUSH16 WINAPI
CreateBrushIndirect16( const LOGBRUSH16
* brush
)
152 if (!(brushPtr
= GDI_AllocObject( sizeof(BRUSHOBJ
), BRUSH_MAGIC
, &hbrush
, &brush_funcs
)))
154 brushPtr
->logbrush
.lbStyle
= brush
->lbStyle
;
155 brushPtr
->logbrush
.lbColor
= brush
->lbColor
;
156 brushPtr
->logbrush
.lbHatch
= brush
->lbHatch
;
157 success
= create_brush_indirect(brushPtr
, TRUE
);
160 GDI_FreeObject( hbrush
, brushPtr
);
163 else GDI_ReleaseObj( hbrush
);
164 TRACE("%04x\n", hbrush
);
169 /***********************************************************************
170 * CreateBrushIndirect (GDI32.@)
173 * As for Windows 95 and Windows 98:
174 * Creating brushes from bitmaps or DIBs larger than 8x8 pixels
175 * is not supported. If a larger bitmap is given, only a portion
176 * of the bitmap is used.
178 HBRUSH WINAPI
CreateBrushIndirect( const LOGBRUSH
* brush
)
183 if (!(brushPtr
= GDI_AllocObject( sizeof(BRUSHOBJ
), BRUSH_MAGIC
, &hbrush
, &brush_funcs
)))
185 brushPtr
->logbrush
.lbStyle
= brush
->lbStyle
;
186 brushPtr
->logbrush
.lbColor
= brush
->lbColor
;
187 brushPtr
->logbrush
.lbHatch
= brush
->lbHatch
;
188 success
= create_brush_indirect(brushPtr
, FALSE
);
191 GDI_FreeObject( hbrush
, brushPtr
);
194 else GDI_ReleaseObj( hbrush
);
195 TRACE("%08x\n", hbrush
);
200 /***********************************************************************
201 * CreateHatchBrush (GDI32.@)
203 HBRUSH WINAPI
CreateHatchBrush( INT style
, COLORREF color
)
207 TRACE("%d %06lx\n", style
, color
);
209 logbrush
.lbStyle
= BS_HATCHED
;
210 logbrush
.lbColor
= color
;
211 logbrush
.lbHatch
= style
;
213 return CreateBrushIndirect( &logbrush
);
217 /***********************************************************************
218 * CreatePatternBrush (GDI32.@)
220 HBRUSH WINAPI
CreatePatternBrush( HBITMAP hbitmap
)
222 LOGBRUSH logbrush
= { BS_PATTERN
, 0, 0 };
223 TRACE("%04x\n", hbitmap
);
225 logbrush
.lbHatch
= hbitmap
;
226 return CreateBrushIndirect( &logbrush
);
230 /***********************************************************************
231 * CreateDIBPatternBrush (GDI.445)
233 HBRUSH16 WINAPI
CreateDIBPatternBrush16( HGLOBAL16 hbitmap
, UINT16 coloruse
)
237 TRACE("%04x\n", hbitmap
);
239 logbrush
.lbStyle
= BS_DIBPATTERN
;
240 logbrush
.lbColor
= coloruse
;
241 logbrush
.lbHatch
= hbitmap
;
243 return CreateBrushIndirect16( &logbrush
);
247 /***********************************************************************
248 * CreateDIBPatternBrush (GDI32.@)
250 * Create a logical brush which has the pattern specified by the DIB
252 * Function call is for compatibility only. CreateDIBPatternBrushPt should be used.
256 * Handle to a logical brush on success, NULL on failure.
261 HBRUSH WINAPI
CreateDIBPatternBrush(
262 HGLOBAL hbitmap
, /* [in] Global object containg BITMAPINFO structure */
263 UINT coloruse
/* [in] Specifies color format, if provided */
268 TRACE("%04x\n", hbitmap
);
270 logbrush
.lbStyle
= BS_DIBPATTERN
;
271 logbrush
.lbColor
= coloruse
;
273 logbrush
.lbHatch
= (LONG
)hbitmap
;
275 return CreateBrushIndirect( &logbrush
);
279 /***********************************************************************
280 * CreateDIBPatternBrushPt (GDI32.@)
282 * Create a logical brush which has the pattern specified by the DIB
286 * Handle to a logical brush on success, NULL on failure.
291 HBRUSH WINAPI
CreateDIBPatternBrushPt(
292 const void* data
, /* [in] Pointer to a BITMAPINFO structure followed by more data */
293 UINT coloruse
/* [in] Specifies color format, if provided */
296 BITMAPINFO
*info
=(BITMAPINFO
*)data
;
299 TRACE("%p %ldx%ld %dbpp\n", info
, info
->bmiHeader
.biWidth
,
300 info
->bmiHeader
.biHeight
, info
->bmiHeader
.biBitCount
);
302 logbrush
.lbStyle
= BS_DIBPATTERNPT
;
303 logbrush
.lbColor
= coloruse
;
304 logbrush
.lbHatch
= (LONG
) data
;
306 return CreateBrushIndirect( &logbrush
);
310 /***********************************************************************
311 * CreateSolidBrush (GDI32.@)
313 HBRUSH WINAPI
CreateSolidBrush( COLORREF color
)
317 TRACE("%06lx\n", color
);
319 logbrush
.lbStyle
= BS_SOLID
;
320 logbrush
.lbColor
= color
;
321 logbrush
.lbHatch
= 0;
323 return CreateBrushIndirect( &logbrush
);
327 /***********************************************************************
328 * SetBrushOrgEx (GDI32.@)
330 BOOL WINAPI
SetBrushOrgEx( HDC hdc
, INT x
, INT y
, LPPOINT oldorg
)
332 DC
*dc
= DC_GetDCPtr( hdc
);
334 if (!dc
) return FALSE
;
337 oldorg
->x
= dc
->brushOrgX
;
338 oldorg
->y
= dc
->brushOrgY
;
342 GDI_ReleaseObj( hdc
);
346 /***********************************************************************
347 * FixBrushOrgEx (GDI32.@)
348 * SDK says discontinued, but in Win95 GDI32 this is the same as SetBrushOrgEx
350 BOOL WINAPI
FixBrushOrgEx( HDC hdc
, INT x
, INT y
, LPPOINT oldorg
)
352 return SetBrushOrgEx(hdc
,x
,y
,oldorg
);
356 /***********************************************************************
359 static HGDIOBJ
BRUSH_SelectObject( HGDIOBJ handle
, void *obj
, HDC hdc
)
361 BRUSHOBJ
*brush
= obj
;
363 DC
*dc
= DC_GetDCPtr( hdc
);
367 if (brush
->logbrush
.lbStyle
== BS_PATTERN
)
368 BITMAP_SetOwnerDC( (HBITMAP
)brush
->logbrush
.lbHatch
, dc
);
371 if (dc
->funcs
->pSelectBrush
) handle
= dc
->funcs
->pSelectBrush( dc
->physDev
, handle
);
372 if (handle
) dc
->hBrush
= handle
;
374 GDI_ReleaseObj( hdc
);
379 /***********************************************************************
382 static BOOL
BRUSH_DeleteObject( HGDIOBJ handle
, void *obj
)
384 BRUSHOBJ
*brush
= obj
;
386 switch(brush
->logbrush
.lbStyle
)
389 DeleteObject( (HGDIOBJ
)brush
->logbrush
.lbHatch
);
392 GlobalFree16( (HGLOBAL16
)brush
->logbrush
.lbHatch
);
395 return GDI_FreeObject( handle
, obj
);
399 /***********************************************************************
402 static INT
BRUSH_GetObject16( HGDIOBJ handle
, void *obj
, INT count
, LPVOID buffer
)
404 BRUSHOBJ
*brush
= obj
;
407 logbrush
.lbStyle
= brush
->logbrush
.lbStyle
;
408 logbrush
.lbColor
= brush
->logbrush
.lbColor
;
409 logbrush
.lbHatch
= brush
->logbrush
.lbHatch
;
410 if (count
> sizeof(logbrush
)) count
= sizeof(logbrush
);
411 memcpy( buffer
, &logbrush
, count
);
416 /***********************************************************************
419 static INT
BRUSH_GetObject( HGDIOBJ handle
, void *obj
, INT count
, LPVOID buffer
)
421 BRUSHOBJ
*brush
= obj
;
423 if (count
> sizeof(brush
->logbrush
)) count
= sizeof(brush
->logbrush
);
424 memcpy( buffer
, &brush
->logbrush
, count
);
429 /***********************************************************************
430 * SetSolidBrush (GDI.604)
432 * If hBrush is a solid brush, change its color to newColor.
435 * TRUE on success, FALSE on failure.
437 * FIXME: untested, not sure if correct.
439 BOOL16 WINAPI
SetSolidBrush16(HBRUSH16 hBrush
, COLORREF newColor
)
444 TRACE("(hBrush %04x, newColor %08lx)\n", hBrush
, (DWORD
)newColor
);
445 if (!(brushPtr
= (BRUSHOBJ
*) GDI_GetObjPtr( hBrush
, BRUSH_MAGIC
)))
448 if (brushPtr
->logbrush
.lbStyle
== BS_SOLID
)
450 brushPtr
->logbrush
.lbColor
= newColor
;
454 GDI_ReleaseObj( hBrush
);