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
);
82 /***********************************************************************
83 * CreateBrushIndirect (GDI32.@)
86 * As for Windows 95 and Windows 98:
87 * Creating brushes from bitmaps or DIBs larger than 8x8 pixels
88 * is not supported. If a larger bitmap is given, only a portion
89 * of the bitmap is used.
91 HBRUSH WINAPI
CreateBrushIndirect( const LOGBRUSH
* brush
)
96 if (!(ptr
= GDI_AllocObject( sizeof(BRUSHOBJ
), BRUSH_MAGIC
, &hbrush
, &brush_funcs
))) return 0;
97 ptr
->logbrush
.lbStyle
= brush
->lbStyle
;
98 ptr
->logbrush
.lbColor
= brush
->lbColor
;
99 ptr
->logbrush
.lbHatch
= brush
->lbHatch
;
101 switch (ptr
->logbrush
.lbStyle
)
104 ptr
->logbrush
.lbStyle
= BS_PATTERN
;
107 ptr
->logbrush
.lbHatch
= (LONG
)BITMAP_CopyBitmap( (HBITMAP
) ptr
->logbrush
.lbHatch
);
108 if (!ptr
->logbrush
.lbHatch
) goto error
;
111 case BS_DIBPATTERNPT
:
112 ptr
->logbrush
.lbStyle
= BS_DIBPATTERN
;
113 ptr
->logbrush
.lbHatch
= (LONG
)dib_copy( (BITMAPINFO
*) ptr
->logbrush
.lbHatch
,
114 ptr
->logbrush
.lbColor
);
115 if (!ptr
->logbrush
.lbHatch
) goto error
;
118 case BS_DIBPATTERN8X8
:
122 HGLOBAL h
= (HGLOBAL
)ptr
->logbrush
.lbHatch
;
124 ptr
->logbrush
.lbStyle
= BS_DIBPATTERN
;
125 if (!(bmi
= (BITMAPINFO
*)GlobalLock( h
))) goto error
;
126 ptr
->logbrush
.lbHatch
= dib_copy( bmi
, ptr
->logbrush
.lbColor
);
128 if (!ptr
->logbrush
.lbHatch
) goto error
;
133 if(ptr
->logbrush
.lbStyle
> BS_MONOPATTERN
) goto error
;
137 GDI_ReleaseObj( hbrush
);
138 TRACE("%08x\n", hbrush
);
142 GDI_FreeObject( hbrush
, ptr
);
147 /***********************************************************************
148 * CreateHatchBrush (GDI32.@)
150 HBRUSH WINAPI
CreateHatchBrush( INT style
, COLORREF color
)
154 TRACE("%d %06lx\n", style
, color
);
156 logbrush
.lbStyle
= BS_HATCHED
;
157 logbrush
.lbColor
= color
;
158 logbrush
.lbHatch
= style
;
160 return CreateBrushIndirect( &logbrush
);
164 /***********************************************************************
165 * CreatePatternBrush (GDI32.@)
167 HBRUSH WINAPI
CreatePatternBrush( HBITMAP hbitmap
)
169 LOGBRUSH logbrush
= { BS_PATTERN
, 0, 0 };
170 TRACE("%04x\n", hbitmap
);
172 logbrush
.lbHatch
= (ULONG_PTR
)hbitmap
;
173 return CreateBrushIndirect( &logbrush
);
177 /***********************************************************************
178 * CreateDIBPatternBrush (GDI32.@)
180 * Create a logical brush which has the pattern specified by the DIB
182 * Function call is for compatibility only. CreateDIBPatternBrushPt should be used.
186 * Handle to a logical brush on success, NULL on failure.
191 HBRUSH WINAPI
CreateDIBPatternBrush(
192 HGLOBAL hbitmap
, /* [in] Global object containg BITMAPINFO structure */
193 UINT coloruse
/* [in] Specifies color format, if provided */
198 TRACE("%04x\n", hbitmap
);
200 logbrush
.lbStyle
= BS_DIBPATTERN
;
201 logbrush
.lbColor
= coloruse
;
203 logbrush
.lbHatch
= (LONG
)hbitmap
;
205 return CreateBrushIndirect( &logbrush
);
209 /***********************************************************************
210 * CreateDIBPatternBrushPt (GDI32.@)
212 * Create a logical brush which has the pattern specified by the DIB
216 * Handle to a logical brush on success, NULL on failure.
221 HBRUSH WINAPI
CreateDIBPatternBrushPt(
222 const void* data
, /* [in] Pointer to a BITMAPINFO structure followed by more data */
223 UINT coloruse
/* [in] Specifies color format, if provided */
226 BITMAPINFO
*info
=(BITMAPINFO
*)data
;
229 TRACE("%p %ldx%ld %dbpp\n", info
, info
->bmiHeader
.biWidth
,
230 info
->bmiHeader
.biHeight
, info
->bmiHeader
.biBitCount
);
232 logbrush
.lbStyle
= BS_DIBPATTERNPT
;
233 logbrush
.lbColor
= coloruse
;
234 logbrush
.lbHatch
= (LONG
) data
;
236 return CreateBrushIndirect( &logbrush
);
240 /***********************************************************************
241 * CreateSolidBrush (GDI32.@)
243 HBRUSH WINAPI
CreateSolidBrush( COLORREF color
)
247 TRACE("%06lx\n", color
);
249 logbrush
.lbStyle
= BS_SOLID
;
250 logbrush
.lbColor
= color
;
251 logbrush
.lbHatch
= 0;
253 return CreateBrushIndirect( &logbrush
);
257 /***********************************************************************
258 * SetBrushOrgEx (GDI32.@)
260 BOOL WINAPI
SetBrushOrgEx( HDC hdc
, INT x
, INT y
, LPPOINT oldorg
)
262 DC
*dc
= DC_GetDCPtr( hdc
);
264 if (!dc
) return FALSE
;
267 oldorg
->x
= dc
->brushOrgX
;
268 oldorg
->y
= dc
->brushOrgY
;
272 GDI_ReleaseObj( hdc
);
276 /***********************************************************************
277 * FixBrushOrgEx (GDI32.@)
278 * SDK says discontinued, but in Win95 GDI32 this is the same as SetBrushOrgEx
280 BOOL WINAPI
FixBrushOrgEx( HDC hdc
, INT x
, INT y
, LPPOINT oldorg
)
282 return SetBrushOrgEx(hdc
,x
,y
,oldorg
);
286 /***********************************************************************
289 static HGDIOBJ
BRUSH_SelectObject( HGDIOBJ handle
, void *obj
, HDC hdc
)
291 BRUSHOBJ
*brush
= obj
;
293 DC
*dc
= DC_GetDCPtr( hdc
);
297 if (brush
->logbrush
.lbStyle
== BS_PATTERN
)
298 BITMAP_SetOwnerDC( (HBITMAP
)brush
->logbrush
.lbHatch
, dc
);
301 if (dc
->funcs
->pSelectBrush
) handle
= dc
->funcs
->pSelectBrush( dc
->physDev
, handle
);
302 if (handle
) dc
->hBrush
= handle
;
304 GDI_ReleaseObj( hdc
);
309 /***********************************************************************
312 static BOOL
BRUSH_DeleteObject( HGDIOBJ handle
, void *obj
)
314 BRUSHOBJ
*brush
= obj
;
316 switch(brush
->logbrush
.lbStyle
)
319 DeleteObject( (HGDIOBJ
)brush
->logbrush
.lbHatch
);
322 GlobalFree16( (HGLOBAL16
)brush
->logbrush
.lbHatch
);
325 return GDI_FreeObject( handle
, obj
);
329 /***********************************************************************
332 static INT
BRUSH_GetObject16( HGDIOBJ handle
, void *obj
, INT count
, LPVOID buffer
)
334 BRUSHOBJ
*brush
= obj
;
337 logbrush
.lbStyle
= brush
->logbrush
.lbStyle
;
338 logbrush
.lbColor
= brush
->logbrush
.lbColor
;
339 logbrush
.lbHatch
= brush
->logbrush
.lbHatch
;
340 if (count
> sizeof(logbrush
)) count
= sizeof(logbrush
);
341 memcpy( buffer
, &logbrush
, count
);
346 /***********************************************************************
349 static INT
BRUSH_GetObject( HGDIOBJ handle
, void *obj
, INT count
, LPVOID buffer
)
351 BRUSHOBJ
*brush
= obj
;
353 if (count
> sizeof(brush
->logbrush
)) count
= sizeof(brush
->logbrush
);
354 memcpy( buffer
, &brush
->logbrush
, count
);
359 /***********************************************************************
360 * SetSolidBrush (GDI.604)
362 * If hBrush is a solid brush, change its color to newColor.
365 * TRUE on success, FALSE on failure.
367 * FIXME: untested, not sure if correct.
369 BOOL16 WINAPI
SetSolidBrush16(HBRUSH16 hBrush
, COLORREF newColor
)
374 TRACE("(hBrush %04x, newColor %08lx)\n", hBrush
, (DWORD
)newColor
);
375 if (!(brushPtr
= (BRUSHOBJ
*) GDI_GetObjPtr( hBrush
, BRUSH_MAGIC
)))
378 if (brushPtr
->logbrush
.lbStyle
== BS_SOLID
)
380 brushPtr
->logbrush
.lbColor
= newColor
;
384 GDI_ReleaseObj( hBrush
);