fixed modifier bug in textfield again
[wmaker-crm.git] / WINGs / wpixmap.c
blobbe8f80834575c4c6957165dd1d563d5717295838
2 #include "WINGsP.h"
4 #include <wraster.h>
7 WMPixmap*
8 WMRetainPixmap(WMPixmap *pixmap)
10 if (pixmap)
11 pixmap->refCount++;
13 return pixmap;
17 void
18 WMReleasePixmap(WMPixmap *pixmap)
20 wassertr(pixmap!=NULL);
22 pixmap->refCount--;
24 if (pixmap->refCount<1) {
25 if (pixmap->pixmap)
26 XFreePixmap(pixmap->screen->display, pixmap->pixmap);
27 if (pixmap->mask)
28 XFreePixmap(pixmap->screen->display, pixmap->mask);
29 wfree(pixmap);
34 WMPixmap*
35 WMCreatePixmap(WMScreen *scrPtr, int width, int height, int depth, Bool masked)
37 WMPixmap *pixPtr;
39 pixPtr = malloc(sizeof(WMPixmap));
40 if (!pixPtr) {
41 return NULL;
43 pixPtr->screen = scrPtr;
44 pixPtr->width = width;
45 pixPtr->height = height;
46 pixPtr->depth = depth;
47 pixPtr->refCount = 1;
49 pixPtr->pixmap = XCreatePixmap(scrPtr->display, W_DRAWABLE(scrPtr),
50 width, height, depth);
51 if (masked) {
52 pixPtr->mask = XCreatePixmap(scrPtr->display, W_DRAWABLE(scrPtr),
53 width, height, 1);
54 } else {
55 pixPtr->mask = None;
58 return pixPtr;
62 WMPixmap*
63 WMCreatePixmapFromXPixmaps(WMScreen *scrPtr, Pixmap pixmap, Pixmap mask,
64 int width, int height, int depth)
66 WMPixmap *pixPtr;
68 pixPtr = malloc(sizeof(WMPixmap));
69 if (!pixPtr) {
70 return NULL;
72 pixPtr->screen = scrPtr;
73 pixPtr->pixmap = pixmap;
74 pixPtr->mask = mask;
75 pixPtr->width = width;
76 pixPtr->height = height;
77 pixPtr->depth = depth;
78 pixPtr->refCount = 1;
80 return pixPtr;
86 WMPixmap*
87 WMCreatePixmapFromFile(WMScreen *scrPtr, char *fileName)
89 WMPixmap *pixPtr;
90 RImage *image;
92 image = RLoadImage(scrPtr->rcontext, fileName, 0);
93 if (!image)
94 return NULL;
96 pixPtr = WMCreatePixmapFromRImage(scrPtr, image, 127);
98 RDestroyImage(image);
100 return pixPtr;
104 WMPixmap*
105 WMCreatePixmapFromRImage(WMScreen *scrPtr, RImage *image, int threshold)
107 WMPixmap *pixPtr;
108 Pixmap pixmap, mask;
110 if (!RConvertImageMask(scrPtr->rcontext, image, &pixmap, &mask,
111 threshold)) {
112 return NULL;
115 pixPtr = malloc(sizeof(WMPixmap));
116 if (!pixPtr) {
117 return NULL;
119 pixPtr->screen = scrPtr;
120 pixPtr->pixmap = pixmap;
121 pixPtr->mask = mask;
122 pixPtr->width = image->width;
123 pixPtr->height = image->height;
124 pixPtr->depth = scrPtr->depth;
125 pixPtr->refCount = 1;
127 return pixPtr;
131 WMPixmap*
132 WMCreateBlendedPixmapFromFile(WMScreen *scrPtr, char *fileName, RColor *color)
134 WMPixmap *pixPtr;
135 RImage *image;
138 image = RLoadImage(scrPtr->rcontext, fileName, 0);
139 if (!image)
140 return NULL;
142 RCombineImageWithColor(image, color);
144 pixPtr = WMCreatePixmapFromRImage(scrPtr, image, 0);
146 RDestroyImage(image);
148 return pixPtr;
152 WMPixmap*
153 WMCreatePixmapFromXPMData(WMScreen *scrPtr, char **data)
155 WMPixmap *pixPtr;
156 RImage *image;
158 image = RGetImageFromXPMData(scrPtr->rcontext, data);
159 if (!image)
160 return NULL;
162 pixPtr = WMCreatePixmapFromRImage(scrPtr, image, 127);
164 RDestroyImage(image);
166 return pixPtr;
170 Pixmap
171 WMGetPixmapXID(WMPixmap *pixmap)
173 wassertrv(pixmap != NULL, None);
175 return pixmap->pixmap;
179 Pixmap
180 WMGetPixmapMaskXID(WMPixmap *pixmap)
182 wassertrv(pixmap != NULL, None);
184 return pixmap->mask;
188 WMSize
189 WMGetPixmapSize(WMPixmap *pixmap)
191 WMSize size = {0,0};
193 wassertrv(pixmap != NULL, size);
195 size.width = pixmap->width;
196 size.height = pixmap->height;
198 return size;
202 WMPixmap*
203 WMGetSystemPixmap(WMScreen *scr, int image)
205 switch (image) {
206 case WSIReturnArrow:
207 return WMRetainPixmap(scr->buttonArrow);
209 case WSIHighlightedReturnArrow:
210 return WMRetainPixmap(scr->pushedButtonArrow);
212 case WSIScrollerDimple:
213 return WMRetainPixmap(scr->scrollerDimple);
215 case WSIArrowLeft:
216 return WMRetainPixmap(scr->leftArrow);
218 case WSIHighlightedArrowLeft:
219 return WMRetainPixmap(scr->hiLeftArrow);
221 case WSIArrowRight:
222 return WMRetainPixmap(scr->rightArrow);
224 case WSIHighlightedArrowRight:
225 return WMRetainPixmap(scr->hiRightArrow);
227 case WSIArrowUp:
228 return WMRetainPixmap(scr->upArrow);
230 case WSIHighlightedArrowUp:
231 return WMRetainPixmap(scr->hiUpArrow);
233 case WSIArrowDown:
234 return WMRetainPixmap(scr->downArrow);
236 case WSIHighlightedArrowDown:
237 return WMRetainPixmap(scr->hiDownArrow);
239 case WSICheckMark:
240 return WMRetainPixmap(scr->checkMark);
242 default:
243 return NULL;
249 void
250 WMDrawPixmap(WMPixmap *pixmap, Drawable d, int x, int y)
252 WMScreen *scr = pixmap->screen;
254 XSetClipMask(scr->display, scr->clipGC, pixmap->mask);
255 XSetClipOrigin(scr->display, scr->clipGC, x, y);
257 XCopyArea(scr->display, pixmap->pixmap, d, scr->clipGC, 0, 0,
258 pixmap->width, pixmap->height, x, y);