Release 980601
[wine] / graphics / x11drv / bitmap.c
1 /*
2  * GDI bitmap objects
3  *
4  * Copyright 1993 Alexandre Julliard
5  */
6
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include "ts_xlib.h"
10 #include "ts_xutil.h"
11 #include "gdi.h"
12 #include "callback.h"
13 #include "dc.h"
14 #include "bitmap.h"
15 #include "heap.h"
16 #include "debug.h"
17
18 /***********************************************************************
19  *           X11DRV_BITMAP_Init
20  */
21 BOOL32 X11DRV_BITMAP_Init(void)
22 {
23     Pixmap tmpPixmap;
24     
25       /* Create the necessary GCs */
26     
27     if ((tmpPixmap = TSXCreatePixmap( display, rootWindow, 1, 1, 1 )))
28     {
29         BITMAP_monoGC = TSXCreateGC( display, tmpPixmap, 0, NULL );
30         TSXSetGraphicsExposures( display, BITMAP_monoGC, False );
31         TSXFreePixmap( display, tmpPixmap );
32     }
33
34     if (screenDepth != 1)
35     {
36         if ((tmpPixmap = TSXCreatePixmap(display, rootWindow, 1,1,screenDepth)))
37         {
38             BITMAP_colorGC = TSXCreateGC( display, tmpPixmap, 0, NULL );
39             TSXSetGraphicsExposures( display, BITMAP_colorGC, False );
40             TSXFreePixmap( display, tmpPixmap );
41         }
42     }
43     return TRUE;
44 }
45
46 /***********************************************************************
47  *           X11DRV_BITMAP_SelectObject
48  */
49 HBITMAP32 X11DRV_BITMAP_SelectObject( DC * dc, HBITMAP32 hbitmap,
50                                       BITMAPOBJ * bmp )
51 {
52     HRGN32 hrgn;
53     HBITMAP32 prevHandle = dc->w.hBitmap;
54     
55     if (!(dc->w.flags & DC_MEMORY)) return 0;
56
57     if (dc->w.hVisRgn)
58        SetRectRgn32( dc->w.hVisRgn, 0, 0,
59                      bmp->bitmap.bmWidth, bmp->bitmap.bmHeight );
60     else
61     { 
62        hrgn = CreateRectRgn32(0, 0, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight);
63        if (!hrgn) return 0;
64        dc->w.hVisRgn    = hrgn;
65     }
66
67     dc->u.x.drawable = bmp->pixmap;
68     dc->w.hBitmap    = hbitmap;
69
70       /* Change GC depth if needed */
71
72     if (dc->w.bitsPerPixel != bmp->bitmap.bmBitsPixel)
73     {
74         TSXFreeGC( display, dc->u.x.gc );
75         dc->u.x.gc = TSXCreateGC( display, dc->u.x.drawable, 0, NULL );
76         dc->w.bitsPerPixel = bmp->bitmap.bmBitsPixel;
77         DC_InitDC( dc );
78     }
79     else CLIPPING_UpdateGCRegion( dc );  /* Just update GC clip region */
80     return prevHandle;
81 }