comctl32: Fix disabled thumb painting, for TBS_BOTH use edged rectangle.
[wine/multimedia.git] / dlls / wineps.drv / brush.c
blob73e67919d4e858ff4b324d7b8aae76a89182ae6a
1 /*
2 * PostScript brush handling
4 * Copyright 1998 Huw D M Davies
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "psdrv.h"
22 #include "wine/debug.h"
23 #include "winbase.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
27 /***********************************************************************
28 * SelectBrush (WINEPS.@)
30 HBRUSH PSDRV_SelectBrush( PHYSDEV dev, HBRUSH hbrush, const struct brush_pattern *pattern )
32 PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
33 LOGBRUSH logbrush;
35 if (!GetObjectA( hbrush, sizeof(logbrush), &logbrush )) return 0;
37 TRACE("hbrush = %p\n", hbrush);
39 if (hbrush == GetStockObject( DC_BRUSH ))
40 logbrush.lbColor = GetDCBrushColor( dev->hdc );
42 switch(logbrush.lbStyle) {
44 case BS_SOLID:
45 PSDRV_CreateColor(dev, &physDev->brush.color, logbrush.lbColor);
46 break;
48 case BS_NULL:
49 break;
51 case BS_HATCHED:
52 PSDRV_CreateColor(dev, &physDev->brush.color, logbrush.lbColor);
53 break;
55 case BS_PATTERN:
56 case BS_DIBPATTERN:
57 physDev->brush.pattern = *pattern;
58 break;
60 default:
61 FIXME("Unrecognized brush style %d\n", logbrush.lbStyle);
62 break;
65 physDev->brush.set = FALSE;
66 return hbrush;
70 /***********************************************************************
71 * SetDCBrushColor (WINEPS.@)
73 COLORREF PSDRV_SetDCBrushColor( PHYSDEV dev, COLORREF color )
75 PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
77 if (GetCurrentObject( dev->hdc, OBJ_BRUSH ) == GetStockObject( DC_BRUSH ))
79 PSDRV_CreateColor( dev, &physDev->brush.color, color );
80 physDev->brush.set = FALSE;
82 return color;
86 /**********************************************************************
88 * PSDRV_SetBrush
91 static BOOL PSDRV_SetBrush( PHYSDEV dev )
93 PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
94 LOGBRUSH logbrush;
95 BOOL ret = TRUE;
97 if (!GetObjectA( GetCurrentObject(dev->hdc,OBJ_BRUSH), sizeof(logbrush), &logbrush ))
99 ERR("Can't get BRUSHOBJ\n");
100 return FALSE;
103 switch (logbrush.lbStyle) {
104 case BS_SOLID:
105 case BS_HATCHED:
106 PSDRV_WriteSetColor(dev, &physDev->brush.color);
107 break;
109 case BS_NULL:
110 break;
112 default:
113 ret = FALSE;
114 break;
117 physDev->brush.set = TRUE;
118 return ret;
122 /**********************************************************************
124 * PSDRV_Fill
127 static BOOL PSDRV_Fill(PHYSDEV dev, BOOL EO)
129 if(!EO)
130 return PSDRV_WriteFill(dev);
131 else
132 return PSDRV_WriteEOFill(dev);
136 /**********************************************************************
138 * PSDRV_Clip
141 static BOOL PSDRV_Clip(PHYSDEV dev, BOOL EO)
143 if(!EO)
144 return PSDRV_WriteClip(dev);
145 else
146 return PSDRV_WriteEOClip(dev);
149 /**********************************************************************
151 * PSDRV_Brush
154 BOOL PSDRV_Brush(PHYSDEV dev, BOOL EO)
156 PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
157 LOGBRUSH logbrush;
158 BOOL ret = TRUE;
160 if(physDev->pathdepth)
161 return FALSE;
163 if (!GetObjectA( GetCurrentObject(dev->hdc,OBJ_BRUSH), sizeof(logbrush), &logbrush ))
165 ERR("Can't get BRUSHOBJ\n");
166 return FALSE;
169 switch (logbrush.lbStyle) {
170 case BS_SOLID:
171 PSDRV_WriteGSave(dev);
172 PSDRV_SetBrush(dev);
173 PSDRV_Fill(dev, EO);
174 PSDRV_WriteGRestore(dev);
175 break;
177 case BS_HATCHED:
178 PSDRV_WriteGSave(dev);
179 PSDRV_SetBrush(dev);
181 switch(logbrush.lbHatch) {
182 case HS_VERTICAL:
183 case HS_CROSS:
184 PSDRV_WriteGSave(dev);
185 PSDRV_Clip(dev, EO);
186 PSDRV_WriteHatch(dev);
187 PSDRV_WriteStroke(dev);
188 PSDRV_WriteGRestore(dev);
189 if(logbrush.lbHatch == HS_VERTICAL)
190 break;
191 /* else fallthrough for HS_CROSS */
193 case HS_HORIZONTAL:
194 PSDRV_WriteGSave(dev);
195 PSDRV_Clip(dev, EO);
196 PSDRV_WriteRotate(dev, 90.0);
197 PSDRV_WriteHatch(dev);
198 PSDRV_WriteStroke(dev);
199 PSDRV_WriteGRestore(dev);
200 break;
202 case HS_FDIAGONAL:
203 case HS_DIAGCROSS:
204 PSDRV_WriteGSave(dev);
205 PSDRV_Clip(dev, EO);
206 PSDRV_WriteRotate(dev, -45.0);
207 PSDRV_WriteHatch(dev);
208 PSDRV_WriteStroke(dev);
209 PSDRV_WriteGRestore(dev);
210 if(logbrush.lbHatch == HS_FDIAGONAL)
211 break;
212 /* else fallthrough for HS_DIAGCROSS */
214 case HS_BDIAGONAL:
215 PSDRV_WriteGSave(dev);
216 PSDRV_Clip(dev, EO);
217 PSDRV_WriteRotate(dev, 45.0);
218 PSDRV_WriteHatch(dev);
219 PSDRV_WriteStroke(dev);
220 PSDRV_WriteGRestore(dev);
221 break;
223 default:
224 ERR("Unknown hatch style\n");
225 ret = FALSE;
226 break;
228 PSDRV_WriteGRestore(dev);
229 break;
231 case BS_NULL:
232 break;
234 case BS_PATTERN:
235 case BS_DIBPATTERN:
236 if(physDev->pi->ppd->LanguageLevel > 1) {
237 PSDRV_WriteGSave(dev);
238 ret = PSDRV_WriteDIBPatternDict(dev, physDev->brush.pattern.info,
239 physDev->brush.pattern.bits.ptr, physDev->brush.pattern.usage );
240 PSDRV_Fill(dev, EO);
241 PSDRV_WriteGRestore(dev);
242 } else {
243 FIXME("Trying to set a pattern brush on a level 1 printer\n");
244 ret = FALSE;
246 break;
248 default:
249 ret = FALSE;
250 break;
252 return ret;