~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/dlls/gdi32/brush.c

Version: ~ [ wine-1.5.30 ] ~ [ wine-1.5.29 ] ~ [ wine-1.5.28 ] ~ [ wine-1.5.27 ] ~ [ wine-1.5.26 ] ~ [ wine-1.5.25 ] ~ [ wine-1.5.24 ] ~ [ wine-1.5.23 ] ~ [ wine-1.5.22 ] ~ [ wine-1.5.21 ] ~ [ wine-1.5.20 ] ~ [ wine-1.5.19 ] ~ [ wine-1.5.18 ] ~ [ wine-1.5.17 ] ~ [ wine-1.5.16 ] ~ [ wine-1.5.15 ] ~ [ wine-1.5.14 ] ~ [ wine-1.5.13 ] ~ [ wine-1.5.12 ] ~ [ wine-1.5.11 ] ~ [ wine-1.5.10 ] ~ [ wine-1.5.9 ] ~ [ wine-1.5.8 ] ~ [ wine-1.5.7 ] ~ [ wine-1.4.1 ] ~ [ wine-1.5.6 ] ~ [ wine-1.5.5 ] ~ [ wine-1.5.4 ] ~ [ wine-1.5.3 ] ~ [ wine-1.5.2 ] ~ [ wine-1.5.1 ] ~ [ wine-1.5.0 ] ~ [ wine-1.4 ] ~ [ wine-1.4-rc6 ] ~ [ wine-1.4-rc5 ] ~ [ wine-1.4-rc4 ] ~ [ wine-1.4-rc3 ] ~ [ wine-1.4-rc2 ] ~ [ wine-1.4-rc1 ] ~ [ wine-1.3.37 ] ~ [ wine-1.3.36 ] ~ [ wine-1.3.35 ] ~ [ wine-1.3.34 ] ~ [ wine-1.3.33 ] ~ [ wine-1.3.32 ] ~ [ wine-1.3.31 ] ~ [ wine-1.3.30 ] ~ [ wine-1.3.29 ] ~ [ wine-1.3.28 ] ~ [ wine-1.3.27 ] ~ [ wine-1.3.26 ] ~ [ wine-1.3.25 ] ~ [ wine-1.3.24 ] ~ [ wine-1.3.23 ] ~ [ wine-1.3.22 ] ~ [ wine-1.3.21 ] ~ [ wine-1.3.20 ] ~ [ wine-1.3.19 ] ~ [ wine-1.3.18 ] ~ [ wine-1.2.3 ] ~ [ wine-1.3.17 ] ~ [ wine-1.3.16 ] ~ [ wine-1.3.15 ] ~ [ wine-1.3.14 ] ~ [ wine-1.3.13 ] ~ [ wine-1.3.12 ] ~ [ wine-1.3.11 ] ~ [ wine-1.3.10 ] ~ [ wine-1.3.9 ] ~ [ wine-1.2.2 ] ~ [ wine-1.3.8 ] ~ [ wine-1.3.7 ] ~ [ wine-1.3.6 ] ~ [ wine-1.3.5 ] ~ [ wine-1.2.1 ] ~ [ wine-1.3.4 ] ~ [ wine-1.3.3 ] ~ [ wine-1.3.2 ] ~ [ wine-1.3.1 ] ~ [ wine-1.3.0 ] ~ [ wine-1.2 ] ~ [ wine-1.2-rc7 ] ~ [ wine-1.2-rc6 ] ~ [ wine-1.2-rc5 ] ~ [ wine-1.2-rc4 ] ~ [ wine-1.2-rc3 ] ~ [ wine-1.2-rc2 ] ~ [ wine-1.2-rc1 ] ~ [ wine-1.1.44 ] ~ [ wine-1.1.43 ] ~ [ wine-1.1.42 ] ~ [ wine-1.1.41 ] ~ [ wine-1.1.40 ] ~ [ wine-1.1.39 ] ~ [ wine-1.1.38 ] ~ [ wine-1.1.37 ] ~ [ wine-1.1.36 ] ~ [ wine-1.1.35 ] ~ [ wine-1.1.34 ] ~ [ wine-1.1.33 ] ~ [ wine-1.1.32 ] ~ [ wine-1.1.31 ] ~ [ wine-1.1.30 ] ~ [ wine-1.1.29 ] ~ [ wine-1.1.28 ] ~ [ wine-1.1.27 ] ~ [ wine-1.1.26 ] ~ [ wine-1.1.25 ] ~ [ wine-1.1.24 ] ~ [ wine-1.1.23 ] ~ [ wine-1.1.22 ] ~ [ wine-1.1.21 ] ~ [ wine-1.1.20 ] ~ [ wine-1.1.19 ] ~ [ wine-1.1.18 ] ~ [ wine-1.1.17 ] ~ [ wine-1.1.16 ] ~ [ wine-1.1.15 ] ~ [ wine-1.1.14 ] ~ [ wine-1.1.13 ] ~ [ wine-1.1.12 ] ~ [ wine-1.1.11 ] ~ [ wine-1.1.10 ] ~ [ wine-1.1.9 ] ~ [ wine-1.1.8 ] ~ [ wine-1.1.7 ] ~ [ wine-1.0.1 ] ~ [ wine-1.1.6 ] ~ [ wine-1.1.5 ] ~ [ wine-1.1.4 ] ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~

  1 /*
  2  * GDI brush objects
  3  *
  4  * Copyright 1993, 1994  Alexandre Julliard
  5  *
  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.
 10  *
 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.
 15  *
 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
 19  */
 20 
 21 #include "config.h"
 22 
 23 #include <stdarg.h>
 24 #include <string.h>
 25 
 26 #include "windef.h"
 27 #include "winbase.h"
 28 #include "wingdi.h"
 29 #include "wine/wingdi16.h"
 30 #include "wownt32.h"
 31 #include "gdi_private.h"
 32 #include "wine/debug.h"
 33 
 34 WINE_DEFAULT_DEBUG_CHANNEL(gdi);
 35 
 36 /* GDI logical brush object */
 37 typedef struct
 38 {
 39     GDIOBJHDR header;
 40     LOGBRUSH  logbrush;
 41 } BRUSHOBJ;
 42 
 43 #define NB_HATCH_STYLES  6
 44 
 45 static HGDIOBJ BRUSH_SelectObject( HGDIOBJ handle, HDC hdc );
 46 static INT BRUSH_GetObject( HGDIOBJ handle, void *obj, INT count, LPVOID buffer );
 47 static BOOL BRUSH_DeleteObject( HGDIOBJ handle, void *obj );
 48 
 49 static const struct gdi_obj_funcs brush_funcs =
 50 {
 51     BRUSH_SelectObject,  /* pSelectObject */
 52     BRUSH_GetObject,     /* pGetObjectA */
 53     BRUSH_GetObject,     /* pGetObjectW */
 54     NULL,                /* pUnrealizeObject */
 55     BRUSH_DeleteObject   /* pDeleteObject */
 56 };
 57 
 58 static HGLOBAL16 dib_copy(const BITMAPINFO *info, UINT coloruse)
 59 {
 60     BITMAPINFO  *newInfo;
 61     HGLOBAL16   hmem;
 62     INT         size;
 63 
 64     if (info->bmiHeader.biCompression != BI_RGB && info->bmiHeader.biCompression != BI_BITFIELDS)
 65         size = info->bmiHeader.biSizeImage;
 66     else
 67         size = DIB_GetDIBImageBytes(info->bmiHeader.biWidth,
 68                                     info->bmiHeader.biHeight,
 69                                     info->bmiHeader.biBitCount);
 70     size += bitmap_info_size( info, coloruse );
 71 
 72     if (!(hmem = GlobalAlloc16( GMEM_MOVEABLE, size )))
 73     {
 74         return 0;
 75     }
 76     newInfo = GlobalLock16( hmem );
 77     memcpy( newInfo, info, size );
 78     GlobalUnlock16( hmem );
 79     return hmem;
 80 }
 81 
 82 
 83 /***********************************************************************
 84  *           CreateBrushIndirect    (GDI32.@)
 85  *
 86  * Create a logical brush with a given style, color or pattern.
 87  *
 88  * PARAMS
 89  *  brush [I] Pointer to a LOGBRUSH structure describing the desired brush.
 90  *
 91  * RETURNS
 92  *  A handle to the created brush, or a NULL handle if the brush cannot be 
 93  *  created.
 94  *
 95  * NOTES
 96  * - The brush returned should be freed by the caller using DeleteObject()
 97  *   when it is no longer required.
 98  * - Windows 95 and earlier cannot create brushes from bitmaps or DIBs larger
 99  *   than 8x8 pixels. If a larger bitmap is given, only a portion of the bitmap
100  *   is used.
101  */
102 HBRUSH WINAPI CreateBrushIndirect( const LOGBRUSH * brush )
103 {
104     BRUSHOBJ * ptr;
105     HBRUSH hbrush;
106 
107     if (!(ptr = GDI_AllocObject( sizeof(BRUSHOBJ), BRUSH_MAGIC,
108                                 (HGDIOBJ *)&hbrush, &brush_funcs ))) return 0;
109     ptr->logbrush.lbStyle = brush->lbStyle;
110     ptr->logbrush.lbColor = brush->lbColor;
111     ptr->logbrush.lbHatch = brush->lbHatch;
112 
113     switch (ptr->logbrush.lbStyle)
114     {
115     case BS_PATTERN8X8:
116         ptr->logbrush.lbStyle = BS_PATTERN;
117         /* fall through */
118     case BS_PATTERN:
119         ptr->logbrush.lbHatch = (ULONG_PTR)BITMAP_CopyBitmap( (HBITMAP) ptr->logbrush.lbHatch );
120         if (!ptr->logbrush.lbHatch) goto error;
121         break;
122 
123     case BS_DIBPATTERNPT:
124         ptr->logbrush.lbStyle = BS_DIBPATTERN;
125         ptr->logbrush.lbHatch = (ULONG_PTR)dib_copy( (BITMAPINFO *) ptr->logbrush.lbHatch,
126                                                      ptr->logbrush.lbColor);
127         if (!ptr->logbrush.lbHatch) goto error;
128         break;
129 
130     case BS_DIBPATTERN8X8:
131     case BS_DIBPATTERN:
132        {
133             BITMAPINFO* bmi;
134             HGLOBAL h = (HGLOBAL)ptr->logbrush.lbHatch;
135 
136             ptr->logbrush.lbStyle = BS_DIBPATTERN;
137             if (!(bmi = GlobalLock( h ))) goto error;
138             ptr->logbrush.lbHatch = dib_copy( bmi, ptr->logbrush.lbColor);
139             GlobalUnlock( h );
140             if (!ptr->logbrush.lbHatch) goto error;
141             break;
142        }
143 
144     default:
145         if(ptr->logbrush.lbStyle > BS_MONOPATTERN) goto error;
146         break;
147     }
148 
149     GDI_ReleaseObj( hbrush );
150     TRACE("%p\n", hbrush);
151     return hbrush;
152 
153  error:
154     GDI_FreeObject( hbrush, ptr );
155     return 0;
156 }
157 
158 
159 /***********************************************************************
160  *           CreateHatchBrush    (GDI32.@)
161  *
162  * Create a logical brush with a hatched pattern.
163  *
164  * PARAMS
165  *  style [I] Direction of lines for the hatch pattern (HS_* values from "wingdi.h")
166  *  color [I] Colour of the hatched pattern
167  *
168  * RETURNS
169  *  A handle to the created brush, or a NULL handle if the brush cannot
170  *  be created.
171  *
172  * NOTES
173  * - This function uses CreateBrushIndirect() to create the brush.
174  * - The brush returned should be freed by the caller using DeleteObject()
175  *   when it is no longer required.
176  */
177 HBRUSH WINAPI CreateHatchBrush( INT style, COLORREF color )
178 {
179     LOGBRUSH logbrush;
180 
181     TRACE("%d %06x\n", style, color );
182 
183     logbrush.lbStyle = BS_HATCHED;
184     logbrush.lbColor = color;
185     logbrush.lbHatch = style;
186 
187     return CreateBrushIndirect( &logbrush );
188 }
189 
190 
191 /***********************************************************************
192  *           CreatePatternBrush    (GDI32.@)
193  *
194  * Create a logical brush with a pattern from a bitmap.
195  *
196  * PARAMS
197  *  hbitmap  [I] Bitmap containing pattern for the brush
198  *
199  * RETURNS
200  *  A handle to the created brush, or a NULL handle if the brush cannot 
201  *  be created.
202  *
203  * NOTES
204  * - This function uses CreateBrushIndirect() to create the brush.
205  * - The brush returned should be freed by the caller using DeleteObject()
206  *   when it is no longer required.
207  */
208 HBRUSH WINAPI CreatePatternBrush( HBITMAP hbitmap )
209 {
210     LOGBRUSH logbrush = { BS_PATTERN, 0, 0 };
211     TRACE("%p\n", hbitmap );
212 
213     logbrush.lbHatch = (ULONG_PTR)hbitmap;
214     return CreateBrushIndirect( &logbrush );
215 }
216 
217 
218 /***********************************************************************
219  *           CreateDIBPatternBrush    (GDI32.@)
220  *
221  * Create a logical brush with a pattern from a DIB.
222  *
223  * PARAMS
224  *  hbitmap  [I] Global object containing BITMAPINFO structure for the pattern
225  *  coloruse [I] Specifies color format, if provided
226  *
227  * RETURNS
228  *  A handle to the created brush, or a NULL handle if the brush cannot 
229  *  be created.
230  *
231  * NOTES
232  * - This function uses CreateBrushIndirect() to create the brush.
233  * - The brush returned should be freed by the caller using DeleteObject()
234  *   when it is no longer required.
235  * - This function is for compatibility only. CreateDIBPatternBrushPt() should 
236  *   be used instead.
237  */
238 HBRUSH WINAPI CreateDIBPatternBrush( HGLOBAL hbitmap, UINT coloruse )
239 {
240     LOGBRUSH logbrush;
241 
242     TRACE("%p\n", hbitmap );
243 
244     logbrush.lbStyle = BS_DIBPATTERN;
245     logbrush.lbColor = coloruse;
246 
247     logbrush.lbHatch = (ULONG_PTR)hbitmap;
248 
249     return CreateBrushIndirect( &logbrush );
250 }
251 
252 
253 /***********************************************************************
254  *           CreateDIBPatternBrushPt    (GDI32.@)
255  *
256  * Create a logical brush with a pattern from a DIB.
257  *
258  * PARAMS
259  *  data     [I] Pointer to a BITMAPINFO structure and image data  for the pattern
260  *  coloruse [I] Specifies color format, if provided
261  *
262  * RETURNS
263  *  A handle to the created brush, or a NULL handle if the brush cannot
264  *  be created.
265  *
266  * NOTES
267  * - This function uses CreateBrushIndirect() to create the brush.
268  * - The brush returned should be freed by the caller using DeleteObject()
269  *   when it is no longer required.
270  */
271 HBRUSH WINAPI CreateDIBPatternBrushPt( const void* data, UINT coloruse )
272 {
273     const BITMAPINFO *info=(const BITMAPINFO*)data;
274     LOGBRUSH logbrush;
275 
276     if (!data)
277         return NULL;
278 
279     TRACE("%p %dx%d %dbpp\n", info, info->bmiHeader.biWidth,
280           info->bmiHeader.biHeight,  info->bmiHeader.biBitCount);
281 
282     logbrush.lbStyle = BS_DIBPATTERNPT;
283     logbrush.lbColor = coloruse;
284     logbrush.lbHatch = (ULONG_PTR)data;
285 
286     return CreateBrushIndirect( &logbrush );
287 }
288 
289 
290 /***********************************************************************
291  *           CreateSolidBrush    (GDI32.@)
292  *
293  * Create a logical brush consisting of a single colour.
294  *
295  * PARAMS
296  *  color [I] Colour to make the solid brush
297  *
298  * RETURNS
299  *  A handle to the newly created brush, or a NULL handle if the brush cannot
300  *  be created.
301  *
302  * NOTES
303  * - This function uses CreateBrushIndirect() to create the brush.
304  * - The brush returned should be freed by the caller using DeleteObject()
305  *   when it is no longer required.
306  */
307 HBRUSH WINAPI CreateSolidBrush( COLORREF color )
308 {
309     LOGBRUSH logbrush;
310 
311     TRACE("%06x\n", color );
312 
313     logbrush.lbStyle = BS_SOLID;
314     logbrush.lbColor = color;
315     logbrush.lbHatch = 0;
316 
317     return CreateBrushIndirect( &logbrush );
318 }
319 
320 
321 /***********************************************************************
322  *           SetBrushOrgEx    (GDI32.@)
323  *
324  * Set the brush origin for a device context.
325  *
326  * PARAMS
327  *  hdc    [I] Device context to set the brush origin for 
328  *  x      [I] New x origin
329  *  y      [I] Ney y origin
330  *  oldorg [O] If non NULL, destination for previously set brush origin.
331  *
332  * RETURNS
333  *  Success: TRUE. The origin is set to (x,y), and oldorg is updated if given.
334  */
335 BOOL WINAPI SetBrushOrgEx( HDC hdc, INT x, INT y, LPPOINT oldorg )
336 {
337     DC *dc = get_dc_ptr( hdc );
338 
339     if (!dc) return FALSE;
340     if (oldorg)
341     {
342         oldorg->x = dc->brushOrgX;
343         oldorg->y = dc->brushOrgY;
344     }
345     dc->brushOrgX = x;
346     dc->brushOrgY = y;
347     release_dc_ptr( dc );
348     return TRUE;
349 }
350 
351 /***********************************************************************
352  *           FixBrushOrgEx    (GDI32.@)
353  *
354  * See SetBrushOrgEx.
355  *
356  * NOTES
357  *  This function is no longer documented by MSDN, but in Win95 GDI32 it
358  *  is the same as SetBrushOrgEx().
359  */
360 BOOL WINAPI FixBrushOrgEx( HDC hdc, INT x, INT y, LPPOINT oldorg )
361 {
362     return SetBrushOrgEx(hdc,x,y,oldorg);
363 }
364 
365 
366 /***********************************************************************
367  *           BRUSH_SelectObject
368  */
369 static HGDIOBJ BRUSH_SelectObject( HGDIOBJ handle, HDC hdc )
370 {
371     BRUSHOBJ *brush;
372     HGDIOBJ ret = 0;
373     DC *dc = get_dc_ptr( hdc );
374 
375     if (!dc)
376     {
377         SetLastError( ERROR_INVALID_HANDLE );
378         return 0;
379     }
380 
381     if ((brush = GDI_GetObjPtr( handle, BRUSH_MAGIC )))
382     {
383         if (brush->logbrush.lbStyle == BS_PATTERN)
384             BITMAP_SetOwnerDC( (HBITMAP)brush->logbrush.lbHatch, dc );
385 
386         GDI_inc_ref_count( handle );
387         GDI_ReleaseObj( handle );
388 
389         if (dc->funcs->pSelectBrush && !dc->funcs->pSelectBrush( dc->physDev, handle ))
390         {
391             GDI_dec_ref_count( handle );
392         }
393         else
394         {
395             ret = dc->hBrush;
396             dc->hBrush = handle;
397             GDI_dec_ref_count( ret );
398         }
399     }
400     release_dc_ptr( dc );
401     return ret;
402 }
403 
404 
405 /***********************************************************************
406  *           BRUSH_DeleteObject
407  */
408 static BOOL BRUSH_DeleteObject( HGDIOBJ handle, void *obj )
409 {
410     BRUSHOBJ *brush = obj;
411 
412     switch(brush->logbrush.lbStyle)
413     {
414       case BS_PATTERN:
415           DeleteObject( (HGDIOBJ)brush->logbrush.lbHatch );
416           break;
417       case BS_DIBPATTERN:
418           GlobalFree16( (HGLOBAL16)brush->logbrush.lbHatch );
419           break;
420     }
421     return GDI_FreeObject( handle, obj );
422 }
423 
424 
425 /***********************************************************************
426  *           BRUSH_GetObject
427  */
428 static INT BRUSH_GetObject( HGDIOBJ handle, void *obj, INT count, LPVOID buffer )
429 {
430     BRUSHOBJ *brush = obj;
431 
432     if( !buffer )
433         return sizeof(brush->logbrush);
434 
435     if (count > sizeof(brush->logbrush)) count = sizeof(brush->logbrush);
436     memcpy( buffer, &brush->logbrush, count );
437     return count;
438 }
439 
440 
441 /***********************************************************************
442  *           SetSolidBrush   (GDI.604)
443  *
444  * Change the color of a solid brush.
445  *
446  * PARAMS
447  *  hBrush   [I] Brush to change the color of
448  *  newColor [I] New color for hBrush
449  *
450  * RETURNS
451  *  Success: TRUE. The color of hBrush is set to newColor.
452  *  Failure: FALSE.
453  *
454  * FIXME
455  *  This function is undocumented and untested. The implementation may
456  *  not be correct.
457  */
458 BOOL16 WINAPI SetSolidBrush16(HBRUSH16 hBrush, COLORREF newColor )
459 {
460     BRUSHOBJ * brushPtr;
461     BOOL16 res = FALSE;
462 
463     TRACE("(hBrush %04x, newColor %08x)\n", hBrush, newColor);
464     if (!(brushPtr = GDI_GetObjPtr( HBRUSH_32(hBrush), BRUSH_MAGIC )))
465         return FALSE;
466 
467     if (brushPtr->logbrush.lbStyle == BS_SOLID)
468     {
469         brushPtr->logbrush.lbColor = newColor;
470         res = TRUE;
471     }
472 
473      GDI_ReleaseObj( HBRUSH_32(hBrush) );
474      return res;
475 }
476 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.