4 * Copyright 1993 Alexandre Julliard
6 static char Copyright[] = "Copyright Alexandre Julliard, 1993";
16 #define NB_HATCH_STYLES 6
18 static char HatchBrushes
[NB_HATCH_STYLES
][8] =
20 { 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00 }, /* HS_HORIZONTAL */
21 { 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08 }, /* HS_VERTICAL */
22 { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 }, /* HS_FDIAGONAL */
23 { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }, /* HS_BDIAGONAL */
24 { 0x08, 0x08, 0x08, 0xff, 0x08, 0x08, 0x08, 0x08 }, /* HS_CROSS */
25 { 0x81, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x81 } /* HS_DIAGCROSS */
29 /***********************************************************************
30 * CreateBrushIndirect (GDI.50)
32 HBRUSH
CreateBrushIndirect( LOGBRUSH
* brush
)
35 HBRUSH hbrush
= GDI_AllocObject( sizeof(BRUSHOBJ
), BRUSH_MAGIC
);
36 if (!hbrush
) return 0;
37 brushPtr
= (BRUSHOBJ
*) GDI_HEAP_ADDR( hbrush
);
38 memcpy( &brushPtr
->logbrush
, brush
, sizeof(LOGBRUSH
) );
43 /***********************************************************************
44 * CreateHatchBrush (GDI.58)
46 HBRUSH
CreateHatchBrush( short style
, COLORREF color
)
48 LOGBRUSH logbrush
= { BS_HATCHED
, color
, style
};
49 dprintf_gdi(stddeb
, "CreateHatchBrush: %d %06lx\n", style
, color
);
50 if ((style
< 0) || (style
>= NB_HATCH_STYLES
)) return 0;
51 return CreateBrushIndirect( &logbrush
);
55 /***********************************************************************
56 * CreatePatternBrush (GDI.60)
58 HBRUSH
CreatePatternBrush( HBITMAP hbitmap
)
60 LOGBRUSH logbrush
= { BS_PATTERN
, 0, 0 };
61 BITMAPOBJ
*bmp
, *newbmp
;
63 dprintf_gdi(stddeb
, "CreatePatternBrush: %d\n", hbitmap
);
65 /* Make a copy of the bitmap */
67 if (!(bmp
= (BITMAPOBJ
*) GDI_GetObjPtr( hbitmap
, BITMAP_MAGIC
)))
69 logbrush
.lbHatch
= CreateBitmapIndirect( &bmp
->bitmap
);
70 newbmp
= (BITMAPOBJ
*) GDI_GetObjPtr( logbrush
.lbHatch
, BITMAP_MAGIC
);
71 if (!newbmp
) return 0;
72 XCopyArea( display
, bmp
->pixmap
, newbmp
->pixmap
, BITMAP_GC(bmp
),
73 0, 0, bmp
->bitmap
.bmWidth
, bmp
->bitmap
.bmHeight
, 0, 0 );
74 return CreateBrushIndirect( &logbrush
);
78 /***********************************************************************
79 * CreateDIBPatternBrush (GDI.445)
81 HBRUSH
CreateDIBPatternBrush( HANDLE hbitmap
, WORD coloruse
)
83 LOGBRUSH logbrush
= { BS_DIBPATTERN
, coloruse
, 0 };
84 BITMAPINFO
*info
, *newInfo
;
87 dprintf_gdi(stddeb
, "CreateDIBPatternBrush: %d\n", hbitmap
);
89 /* Make a copy of the bitmap */
91 if (!(info
= (BITMAPINFO
*) GlobalLock( hbitmap
))) return 0;
93 size
= info
->bmiHeader
.biSizeImage
;
95 size
= (info
->bmiHeader
.biWidth
* info
->bmiHeader
.biBitCount
+ 31) / 32
96 * 8 * info
->bmiHeader
.biHeight
;
97 size
+= DIB_BitmapInfoSize( info
, coloruse
);
99 if (!(logbrush
.lbHatch
= GlobalAlloc( GMEM_MOVEABLE
, size
)))
101 GlobalUnlock( hbitmap
);
104 newInfo
= (BITMAPINFO
*) GlobalLock( logbrush
.lbHatch
);
105 memcpy( newInfo
, info
, size
);
106 GlobalUnlock( logbrush
.lbHatch
);
107 GlobalUnlock( hbitmap
);
108 return CreateBrushIndirect( &logbrush
);
112 /***********************************************************************
113 * CreateSolidBrush (GDI.66)
115 HBRUSH
CreateSolidBrush( COLORREF color
)
117 LOGBRUSH logbrush
= { BS_SOLID
, color
, 0 };
118 dprintf_gdi(stddeb
, "CreateSolidBrush: %06lx\n", color
);
119 return CreateBrushIndirect( &logbrush
);
123 /***********************************************************************
124 * SetBrushOrg (GDI.148)
126 DWORD
SetBrushOrg( HDC hdc
, short x
, short y
)
129 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
130 if (!dc
) return FALSE
;
131 retval
= dc
->w
.brushOrgX
| (dc
->w
.brushOrgY
<< 16);
137 /***********************************************************************
138 * GetSysColorBrush (USER.281)
140 WORD
GetSysColorBrush(WORD x
)
142 return GetStockObject(GRAY_BRUSH
);
145 /***********************************************************************
148 BOOL
BRUSH_DeleteObject( HBRUSH hbrush
, BRUSHOBJ
* brush
)
150 switch(brush
->logbrush
.lbStyle
)
153 DeleteObject( brush
->logbrush
.lbHatch
);
156 GlobalFree( brush
->logbrush
.lbHatch
);
159 return GDI_FreeObject( hbrush
);
163 /***********************************************************************
166 int BRUSH_GetObject( BRUSHOBJ
* brush
, int count
, LPSTR buffer
)
168 if (count
> sizeof(LOGBRUSH
)) count
= sizeof(LOGBRUSH
);
169 memcpy( buffer
, &brush
->logbrush
, count
);
174 /***********************************************************************
175 * BRUSH_MakeSolidBrush
177 static void BRUSH_SelectSolidBrush( DC
*dc
, COLORREF color
)
179 if ((dc
->w
.bitsPerPixel
> 1) && (screenDepth
<= 8) && !COLOR_IsSolid( color
))
182 dc
->u
.x
.brush
.pixmap
= DITHER_DitherColor( dc
, color
);
183 dc
->u
.x
.brush
.fillStyle
= FillTiled
;
184 dc
->u
.x
.brush
.pixel
= 0;
189 dc
->u
.x
.brush
.pixel
= COLOR_ToPhysical( dc
, color
);
190 dc
->u
.x
.brush
.fillStyle
= FillSolid
;
195 /***********************************************************************
196 * BRUSH_SelectPatternBrush
198 static BOOL
BRUSH_SelectPatternBrush( DC
* dc
, HBITMAP hbitmap
)
200 BITMAPOBJ
* bmp
= (BITMAPOBJ
*) GDI_GetObjPtr( hbitmap
, BITMAP_MAGIC
);
201 if (!bmp
) return FALSE
;
202 dc
->u
.x
.brush
.pixmap
= XCreatePixmap( display
, rootWindow
,
203 8, 8, bmp
->bitmap
.bmBitsPixel
);
204 XCopyArea( display
, bmp
->pixmap
, dc
->u
.x
.brush
.pixmap
,
205 BITMAP_GC(bmp
), 0, 0, 8, 8, 0, 0 );
207 if (bmp
->bitmap
.bmBitsPixel
> 1)
209 dc
->u
.x
.brush
.fillStyle
= FillTiled
;
210 dc
->u
.x
.brush
.pixel
= 0; /* Ignored */
214 dc
->u
.x
.brush
.fillStyle
= FillOpaqueStippled
;
215 dc
->u
.x
.brush
.pixel
= -1; /* Special case (see DC_SetupGCForBrush) */
222 /***********************************************************************
225 HBRUSH
BRUSH_SelectObject( HDC hdc
, DC
* dc
, HBRUSH hbrush
, BRUSHOBJ
* brush
)
228 BITMAPINFO
* bmpInfo
;
229 HBRUSH prevHandle
= dc
->w
.hBrush
;
231 dprintf_gdi(stddeb
, "Brush_SelectObject hdc=%04x hbrush=%04x\n",
233 if (dc
->header
.wMagic
== METAFILE_DC_MAGIC
)
235 switch (brush
->logbrush
.lbStyle
)
240 if (!MF_CreateBrushIndirect(dc
, hbrush
, &(brush
->logbrush
)))
246 if (!MF_CreatePatternBrush(dc
, hbrush
, &(brush
->logbrush
)))
253 dc
->w
.hBrush
= hbrush
;
255 if (dc
->u
.x
.brush
.pixmap
)
257 XFreePixmap( display
, dc
->u
.x
.brush
.pixmap
);
258 dc
->u
.x
.brush
.pixmap
= 0;
260 dc
->u
.x
.brush
.style
= brush
->logbrush
.lbStyle
;
262 switch(brush
->logbrush
.lbStyle
)
265 dprintf_gdi( stddeb
,"BS_NULL\n" );
269 dprintf_gdi( stddeb
,"BS_SOLID\n" );
270 BRUSH_SelectSolidBrush( dc
, brush
->logbrush
.lbColor
);
274 dprintf_gdi( stddeb
, "BS_HATCHED\n" );
275 dc
->u
.x
.brush
.pixel
= COLOR_ToPhysical( dc
, brush
->logbrush
.lbColor
);
276 dc
->u
.x
.brush
.pixmap
= XCreateBitmapFromData( display
, rootWindow
,
277 HatchBrushes
[brush
->logbrush
.lbHatch
], 8, 8 );
278 dc
->u
.x
.brush
.fillStyle
= FillStippled
;
282 dprintf_gdi( stddeb
, "BS_PATTERN\n");
283 BRUSH_SelectPatternBrush( dc
, brush
->logbrush
.lbHatch
);
287 dprintf_gdi( stddeb
, "BS_DIBPATTERN\n");
288 if ((bmpInfo
= (BITMAPINFO
*) GlobalLock( brush
->logbrush
.lbHatch
)))
290 int size
= DIB_BitmapInfoSize( bmpInfo
, brush
->logbrush
.lbColor
);
291 hBitmap
= CreateDIBitmap( hdc
, &bmpInfo
->bmiHeader
, CBM_INIT
,
292 ((char *)bmpInfo
) + size
, bmpInfo
,
293 (WORD
) brush
->logbrush
.lbColor
);
294 BRUSH_SelectPatternBrush( dc
, hBitmap
);
295 DeleteObject( hBitmap
);
296 GlobalUnlock( brush
->logbrush
.lbHatch
);