/*********************************************************************** * SelectBrush (X11DRV.@) */ HBRUSH X11DRV_SelectBrush( PHYSDEV dev, HBRUSH hbrush ) { X11DRV_PDEVICE *physDev = get_x11drv_dev( dev ); LOGBRUSH logbrush; if (!GetObjectA( hbrush, sizeof(logbrush), &logbrush )) return 0; TRACE("hdc=%p hbrush=%p\n", dev->hdc, hbrush); if (physDev->brush.pixmap) { wine_tsx11_lock(); XFreePixmap( gdi_display, physDev->brush.pixmap ); wine_tsx11_unlock(); physDev->brush.pixmap = 0; } physDev->brush.style = logbrush.lbStyle; if (hbrush == GetStockObject( DC_BRUSH )) logbrush.lbColor = GetDCBrushColor( dev->hdc ); switch(logbrush.lbStyle) { case BS_NULL: TRACE("BS_NULL\n" ); break; case BS_SOLID: TRACE("BS_SOLID\n" ); BRUSH_SelectSolidBrush( physDev, logbrush.lbColor ); break; case BS_HATCHED: TRACE("BS_HATCHED\n" ); physDev->brush.pixel = X11DRV_PALETTE_ToPhysical( physDev, logbrush.lbColor ); wine_tsx11_lock(); physDev->brush.pixmap = XCreateBitmapFromData( gdi_display, root_window, HatchBrushes[logbrush.lbHatch], 8, 8 ); wine_tsx11_unlock(); physDev->brush.fillStyle = FillStippled; break; case BS_PATTERN: TRACE("BS_PATTERN\n"); if (!BRUSH_SelectPatternBrush( physDev, (HBITMAP)logbrush.lbHatch )) return 0; break; case BS_DIBPATTERN: TRACE("BS_DIBPATTERN\n"); if (!BRUSH_SelectDIBPatternBrush( physDev, (HGLOBAL)logbrush.lbHatch )) return 0; break; } return hbrush; }
/*********************************************************************** * BRUSH_SelectDIBPatternBrush */ static BOOL BRUSH_SelectDIBPatternBrush( X11DRV_PDEVICE *physDev, HGLOBAL mem ) { BOOL ret; HDC memdc; BITMAPINFO *info = GlobalLock( mem ); HBITMAP bitmap = CreateDIBitmap( physDev->dev.hdc, &info->bmiHeader, CBM_INIT, (LPBYTE)info + bitmap_info_size( info, DIB_RGB_COLORS ), info, DIB_RGB_COLORS ); /* make sure it's owned by x11drv */ memdc = CreateCompatibleDC( physDev->dev.hdc ); SelectObject( memdc, bitmap ); DeleteDC( memdc ); if ((ret = BRUSH_SelectPatternBrush( physDev, bitmap ))) { X_PHYSBITMAP *physBitmap = X11DRV_get_phys_bitmap( bitmap ); physBitmap->pixmap = 0; /* so it doesn't get freed */ } DeleteObject( bitmap ); GlobalUnlock( mem ); return ret; }
/*********************************************************************** * SelectBrush (X11DRV.@) */ HBRUSH X11DRV_SelectBrush( PHYSDEV dev, HBRUSH hbrush, const struct brush_pattern *pattern ) { X11DRV_PDEVICE *physDev = get_x11drv_dev( dev ); LOGBRUSH logbrush; if (pattern) /* pattern brush */ { X_PHYSBITMAP *physbitmap; HBITMAP bitmap = pattern->bitmap; BOOL delete_bitmap = FALSE; if (!bitmap || !(physbitmap = X11DRV_get_phys_bitmap( bitmap ))) { if (!(bitmap = create_brush_bitmap( physDev, pattern ))) return 0; physbitmap = X11DRV_get_phys_bitmap( bitmap ); delete_bitmap = TRUE; } BRUSH_SelectPatternBrush( physDev, bitmap, physbitmap ); TRACE("BS_PATTERN\n"); physDev->brush.style = BS_PATTERN; if (delete_bitmap) DeleteObject( bitmap ); return hbrush; } if (!GetObjectA( hbrush, sizeof(logbrush), &logbrush )) return 0; TRACE("hdc=%p hbrush=%p\n", dev->hdc, hbrush); if (physDev->brush.pixmap) { wine_tsx11_lock(); XFreePixmap( gdi_display, physDev->brush.pixmap ); wine_tsx11_unlock(); physDev->brush.pixmap = 0; } physDev->brush.style = logbrush.lbStyle; if (hbrush == GetStockObject( DC_BRUSH )) logbrush.lbColor = GetDCBrushColor( dev->hdc ); switch(logbrush.lbStyle) { case BS_NULL: TRACE("BS_NULL\n" ); break; case BS_SOLID: TRACE("BS_SOLID\n" ); BRUSH_SelectSolidBrush( physDev, logbrush.lbColor ); break; case BS_HATCHED: TRACE("BS_HATCHED\n" ); physDev->brush.pixel = X11DRV_PALETTE_ToPhysical( physDev, logbrush.lbColor ); wine_tsx11_lock(); physDev->brush.pixmap = XCreateBitmapFromData( gdi_display, root_window, HatchBrushes[logbrush.lbHatch], 8, 8 ); wine_tsx11_unlock(); physDev->brush.fillStyle = FillStippled; break; } return hbrush; }
/*********************************************************************** * SelectBrush (X11DRV.@) */ HBRUSH CDECL X11DRV_SelectBrush( X11DRV_PDEVICE *physDev, HBRUSH hbrush ) { LOGBRUSH logbrush; HBITMAP hBitmap; BITMAPINFO * bmpInfo; if (!GetObjectA( hbrush, sizeof(logbrush), &logbrush )) return 0; TRACE("hdc=%p hbrush=%p\n", physDev->hdc,hbrush); if (physDev->brush.pixmap) { wine_tsx11_lock(); XFreePixmap( gdi_display, physDev->brush.pixmap ); wine_tsx11_unlock(); physDev->brush.pixmap = 0; } physDev->brush.style = logbrush.lbStyle; if (hbrush == GetStockObject( DC_BRUSH )) logbrush.lbColor = GetDCBrushColor( physDev->hdc ); switch(logbrush.lbStyle) { case BS_NULL: TRACE("BS_NULL\n" ); break; case BS_SOLID: TRACE("BS_SOLID\n" ); BRUSH_SelectSolidBrush( physDev, logbrush.lbColor ); break; case BS_HATCHED: TRACE("BS_HATCHED\n" ); physDev->brush.pixel = X11DRV_PALETTE_ToPhysical( physDev, logbrush.lbColor ); wine_tsx11_lock(); physDev->brush.pixmap = XCreateBitmapFromData( gdi_display, root_window, HatchBrushes[logbrush.lbHatch], 8, 8 ); wine_tsx11_unlock(); physDev->brush.fillStyle = FillStippled; break; case BS_PATTERN: TRACE("BS_PATTERN\n"); if (!BRUSH_SelectPatternBrush( physDev, (HBITMAP)logbrush.lbHatch )) return 0; break; case BS_DIBPATTERN: TRACE("BS_DIBPATTERN\n"); if ((bmpInfo = GlobalLock( (HGLOBAL)logbrush.lbHatch ))) { int size = bitmap_info_size( bmpInfo, logbrush.lbColor ); hBitmap = CreateDIBitmap( physDev->hdc, &bmpInfo->bmiHeader, CBM_INIT, ((char *)bmpInfo) + size, bmpInfo, (WORD)logbrush.lbColor ); BRUSH_SelectPatternBrush( physDev, hBitmap ); DeleteObject( hBitmap ); GlobalUnlock( (HGLOBAL)logbrush.lbHatch ); } break; } return hbrush; }