4 * Copyright 1993 Alexandre Julliard
7 static char Copyright
[] = "Copyright Alexandre Julliard, 1993";
11 #include <X11/Xutil.h>
15 /* Include OEM bitmaps */
16 #include "bitmaps/check_boxes"
17 #include "bitmaps/check_mark"
18 #include "bitmaps/menu_arrow"
20 /* Handle of the bitmap selected by default in a memory DC */
21 HBITMAP BITMAP_hbitmapMemDC
= 0;
23 /* GCs used for B&W and color bitmap operations */
24 GC BITMAP_monoGC
= 0, BITMAP_colorGC
= 0;
27 /***********************************************************************
34 /* Create the necessary GCs */
36 if ((tmpPixmap
= XCreatePixmap( display
, rootWindow
, 1, 1, 1 )))
38 BITMAP_monoGC
= XCreateGC( display
, tmpPixmap
, 0, NULL
);
39 XSetGraphicsExposures( display
, BITMAP_monoGC
, False
);
40 XFreePixmap( display
, tmpPixmap
);
45 if ((tmpPixmap
= XCreatePixmap(display
, rootWindow
, 1,1,screenDepth
)))
47 BITMAP_colorGC
= XCreateGC( display
, tmpPixmap
, 0, NULL
);
48 XSetGraphicsExposures( display
, BITMAP_colorGC
, False
);
49 XFreePixmap( display
, tmpPixmap
);
53 BITMAP_hbitmapMemDC
= CreateBitmap( 1, 1, 1, 1, NULL
);
54 return (BITMAP_hbitmapMemDC
!= 0);
58 /***********************************************************************
61 * Create an XImage pointing to the bitmap data.
63 static XImage
*BITMAP_BmpToImage( BITMAP
* bmp
, void * bmpData
)
65 extern void _XInitImageFuncPtrs( XImage
* );
68 image
= XCreateImage( display
, DefaultVisualOfScreen(screen
),
69 bmp
->bmBitsPixel
, ZPixmap
, 0, bmpData
,
70 bmp
->bmWidth
, bmp
->bmHeight
, 16, bmp
->bmWidthBytes
);
72 image
->byte_order
= MSBFirst
;
73 image
->bitmap_bit_order
= MSBFirst
;
74 image
->bitmap_unit
= 16;
75 _XInitImageFuncPtrs(image
);
80 /***********************************************************************
81 * BITMAP_LoadOEMBitmap
83 HBITMAP
BITMAP_LoadOEMBitmap( WORD id
)
85 BITMAPOBJ
* bmpObjPtr
;
93 width
= menu_arrow_width
;
94 height
= menu_arrow_height
;
95 data
= menu_arrow_bits
;
99 width
= check_boxes_width
;
100 height
= check_boxes_height
;
101 data
= check_boxes_bits
;
105 width
= check_mark_width
;
106 height
= check_mark_height
;
107 data
= check_mark_bits
;
114 /* Create the BITMAPOBJ */
115 if (!(hbitmap
= GDI_AllocObject( sizeof(BITMAPOBJ
), BITMAP_MAGIC
)))
117 bmpObjPtr
= (BITMAPOBJ
*) GDI_HEAP_ADDR( hbitmap
);
118 bmpObjPtr
->size
.cx
= 0;
119 bmpObjPtr
->size
.cy
= 0;
120 bmpObjPtr
->bitmap
.bmType
= 0;
121 bmpObjPtr
->bitmap
.bmWidth
= width
;
122 bmpObjPtr
->bitmap
.bmHeight
= height
;
123 bmpObjPtr
->bitmap
.bmWidthBytes
= (width
+ 15) / 16 * 2;
124 bmpObjPtr
->bitmap
.bmPlanes
= 1;
125 bmpObjPtr
->bitmap
.bmBitsPixel
= 1;
126 bmpObjPtr
->bitmap
.bmBits
= NULL
;
128 /* Create the pixmap */
129 if (!(bmpObjPtr
->pixmap
= XCreateBitmapFromData( display
, rootWindow
,
130 data
, width
, height
)))
132 GDI_HEAP_FREE( hbitmap
);
139 /***********************************************************************
140 * CreateBitmap (GDI.48)
142 HBITMAP
CreateBitmap( short width
, short height
,
143 BYTE planes
, BYTE bpp
, LPSTR bits
)
145 BITMAP bitmap
= { 0, width
, height
, 0, planes
, bpp
, bits
};
147 printf( "CreateBitmap: %dx%d, %d colors\n",
148 width
, height
, 1 << (planes
*bpp
) );
150 return CreateBitmapIndirect( &bitmap
);
154 /***********************************************************************
155 * CreateCompatibleBitmap (GDI.51)
157 HBITMAP
CreateCompatibleBitmap( HDC hdc
, short width
, short height
)
161 printf( "CreateCompatibleBitmap: %d %dx%d\n", hdc
, width
, height
);
163 if (!(dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
))) return 0;
164 return CreateBitmap( width
, height
, 1, dc
->w
.bitsPerPixel
, NULL
);
168 /***********************************************************************
169 * CreateBitmapIndirect (GDI.49)
171 HBITMAP
CreateBitmapIndirect( BITMAP
* bmp
)
173 BITMAPOBJ
* bmpObjPtr
;
176 /* Check parameters */
177 if (!bmp
->bmHeight
|| !bmp
->bmWidth
) return 0;
178 if (bmp
->bmPlanes
!= 1) return 0;
179 if ((bmp
->bmBitsPixel
!= 1) && (bmp
->bmBitsPixel
!= screenDepth
)) return 0;
181 if (bmp
->bmHeight
< 0)
182 bmp
->bmHeight
= -bmp
->bmHeight
;
184 if (bmp
->bmWidth
< 0)
185 bmp
->bmWidth
= -bmp
->bmWidth
;
188 /* Create the BITMAPOBJ */
189 hbitmap
= GDI_AllocObject( sizeof(BITMAPOBJ
), BITMAP_MAGIC
);
190 if (!hbitmap
) return 0;
191 bmpObjPtr
= (BITMAPOBJ
*) GDI_HEAP_ADDR( hbitmap
);
193 bmpObjPtr
->size
.cx
= 0;
194 bmpObjPtr
->size
.cy
= 0;
195 bmpObjPtr
->bitmap
= *bmp
;
196 bmpObjPtr
->bitmap
.bmBits
= NULL
;
197 bmpObjPtr
->bitmap
.bmWidthBytes
= (bmp
->bmWidth
*bmp
->bmBitsPixel
+15)/16 * 2;
199 /* Create the pixmap */
200 bmpObjPtr
->pixmap
= XCreatePixmap( display
, rootWindow
, bmp
->bmWidth
,
201 bmp
->bmHeight
, bmp
->bmBitsPixel
);
202 if (!bmpObjPtr
->pixmap
)
204 GDI_HEAP_FREE( hbitmap
);
207 else if (bmp
->bmBits
) /* Set bitmap bits */
208 SetBitmapBits( hbitmap
, bmp
->bmHeight
*bmp
->bmWidthBytes
, bmp
->bmBits
);
213 /***********************************************************************
214 * GetBitmapBits (GDI.74)
216 LONG
GetBitmapBits( HBITMAP hbitmap
, LONG count
, LPSTR buffer
)
222 bmp
= (BITMAPOBJ
*) GDI_GetObjPtr( hbitmap
, BITMAP_MAGIC
);
226 printf( "GetBitmapBits: %dx%d %d colors %p\n",
227 bmp
->bitmap
.bmWidth
, bmp
->bitmap
.bmHeight
,
228 1 << bmp
->bitmap
.bmBitsPixel
, buffer
);
230 /* Only get entire lines */
231 height
= count
/ bmp
->bitmap
.bmWidthBytes
;
232 if (height
> bmp
->bitmap
.bmHeight
) height
= bmp
->bitmap
.bmHeight
;
233 if (!height
) return 0;
235 if (!(image
= BITMAP_BmpToImage( &bmp
->bitmap
, buffer
))) return 0;
236 XGetSubImage( display
, bmp
->pixmap
, 0, 0, bmp
->bitmap
.bmWidth
, height
,
237 AllPlanes
, ZPixmap
, image
, 0, 0 );
239 XDestroyImage( image
);
240 return height
* bmp
->bitmap
.bmWidthBytes
;
244 /***********************************************************************
245 * SetBitmapBits (GDI.106)
247 LONG
SetBitmapBits( HBITMAP hbitmap
, LONG count
, LPSTR buffer
)
253 bmp
= (BITMAPOBJ
*) GDI_GetObjPtr( hbitmap
, BITMAP_MAGIC
);
257 printf( "SetBitmapBits: %dx%d %d colors %p\n",
258 bmp
->bitmap
.bmWidth
, bmp
->bitmap
.bmHeight
,
259 1 << bmp
->bitmap
.bmBitsPixel
, buffer
);
261 /* Only set entire lines */
262 height
= count
/ bmp
->bitmap
.bmWidthBytes
;
263 if (height
> bmp
->bitmap
.bmHeight
) height
= bmp
->bitmap
.bmHeight
;
264 if (!height
) return 0;
266 if (!(image
= BITMAP_BmpToImage( &bmp
->bitmap
, buffer
))) return 0;
267 XPutImage( display
, bmp
->pixmap
, BITMAP_GC(bmp
), image
, 0, 0,
268 0, 0, bmp
->bitmap
.bmWidth
, height
);
270 XDestroyImage( image
);
271 return height
* bmp
->bitmap
.bmWidthBytes
;
275 /***********************************************************************
278 BOOL
BMP_DeleteObject( HBITMAP hbitmap
, BITMAPOBJ
* bitmap
)
280 XFreePixmap( display
, bitmap
->pixmap
);
281 return GDI_FreeObject( hbitmap
);
285 /***********************************************************************
288 int BMP_GetObject( BITMAPOBJ
* bmp
, int count
, LPSTR buffer
)
290 if (count
> sizeof(BITMAP
)) count
= sizeof(BITMAP
);
291 memcpy( buffer
, &bmp
->bitmap
, count
);
296 /***********************************************************************
297 * BITMAP_SelectObject
299 HBITMAP
BITMAP_SelectObject( HDC hdc
, DC
* dc
, HBITMAP hbitmap
,
302 HBITMAP prevHandle
= dc
->w
.hBitmap
;
304 if (!(dc
->w
.flags
& DC_MEMORY
)) return 0;
305 dc
->u
.x
.drawable
= bmp
->pixmap
;
306 dc
->w
.DCSizeX
= bmp
->bitmap
.bmWidth
;
307 dc
->w
.DCSizeY
= bmp
->bitmap
.bmHeight
;
308 dc
->w
.hBitmap
= hbitmap
;
310 /* Change GC depth if needed */
312 if (dc
->w
.bitsPerPixel
!= bmp
->bitmap
.bmBitsPixel
)
314 XFreeGC( display
, dc
->u
.x
.gc
);
315 dc
->u
.x
.gc
= XCreateGC( display
, dc
->u
.x
.drawable
, 0, NULL
);
316 dc
->w
.bitsPerPixel
= bmp
->bitmap
.bmBitsPixel
;
317 /* Re-select objects with changed depth */
318 SelectObject( hdc
, dc
->w
.hPen
);
319 SelectObject( hdc
, dc
->w
.hBrush
);
324 /***********************************************************************
325 * CreateDiscardableBitmap (GDI.156)
327 HBITMAP
CreateDiscardableBitmap(HDC hdc
, short width
, short height
)
329 printf("CreateDiscardableBitmap(%04X, %d, %d); "
330 "// call CreateCompatibleBitmap() for now!\n",
332 return CreateCompatibleBitmap(hdc
, width
, height
);
335 /***********************************************************************
336 * GetBitmapDimensionEx (GDI.468)
338 BOOL
GetBitmapDimensionEx( HBITMAP hbitmap
, LPSIZE size
)
340 BITMAPOBJ
* bmp
= (BITMAPOBJ
*) GDI_GetObjPtr( hbitmap
, BITMAP_MAGIC
);
341 if (!bmp
) return FALSE
;
347 /***********************************************************************
348 * GetBitmapDimension (GDI.162)
350 DWORD
GetBitmapDimension( HBITMAP hbitmap
)
353 if (!GetBitmapDimensionEx( hbitmap
, &size
)) return 0;
354 return size
.cx
| (size
.cy
<< 16);
357 /***********************************************************************
358 * SetBitmapDimensionEx (GDI.478)
360 BOOL
SetBitmapDimensionEx( HBITMAP hbitmap
, short x
, short y
, LPSIZE prevSize
)
362 BITMAPOBJ
* bmp
= (BITMAPOBJ
*) GDI_GetObjPtr( hbitmap
, BITMAP_MAGIC
);
363 if (!bmp
) return FALSE
;
364 if (prevSize
) *prevSize
= bmp
->size
;
371 /***********************************************************************
372 * SetBitmapDimension (GDI.163)
374 DWORD
SetBitmapDimension( HBITMAP hbitmap
, short x
, short y
)
377 if (!SetBitmapDimensionEx( hbitmap
, x
, y
, &size
)) return 0;
378 return size
.cx
| (size
.cy
<< 16);