Update local copy of GPLv2 and FSF address in copyrights
[wmaker-crm.git] / src / pixmap.c
blob62c4cebc52b3820931817b9edd2758a5a36ca436
1 /*
2 * Window Maker window manager
4 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program 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
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "wconfig.h"
23 #include <X11/Xlib.h>
24 #include <X11/Xutil.h>
26 #include <wraster.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include "WindowMaker.h"
31 #include "pixmap.h"
34 *----------------------------------------------------------------------
35 * wPixmapCreateFromXPMData--
36 * Creates a WPixmap structure and initializes it with the supplied
37 * XPM structure data.
39 * Returns:
40 * A WPixmap structure or NULL on failure.
42 * Notes:
43 * DEF_XPM_CLOSENESS specifies the XpmCloseness
44 *----------------------------------------------------------------------
46 WPixmap *wPixmapCreateFromXPMData(WScreen * scr, char **data)
48 RImage *image;
49 WPixmap *pix;
51 image = RGetImageFromXPMData(scr->rcontext, data);
52 if (!image)
53 return NULL;
55 pix = wmalloc(sizeof(WPixmap));
56 memset(pix, 0, sizeof(WPixmap));
58 RConvertImageMask(scr->rcontext, image, &pix->image, &pix->mask, 128);
60 pix->width = image->width;
61 pix->height = image->height;
62 pix->depth = scr->w_depth;
64 RReleaseImage(image);
66 return pix;
70 *----------------------------------------------------------------------
71 * wPixmapCreateFromXBMData--
72 * Creates a WPixmap structure and initializes it with the supplied
73 * XBM structure data, size and mask.
75 * Returns:
76 * A WPixmap structure or NULL on failure.
78 *----------------------------------------------------------------------
80 WPixmap *wPixmapCreateFromXBMData(WScreen * scr, char *data, char *mask,
81 int width, int height, unsigned long fg, unsigned long bg)
83 WPixmap *pix;
85 pix = wmalloc(sizeof(WPixmap));
86 memset(pix, 0, sizeof(WPixmap));
87 pix->image = XCreatePixmapFromBitmapData(dpy, scr->w_win, data, width, height, fg, bg, scr->w_depth);
88 if (pix->image == None) {
89 wfree(pix);
90 return NULL;
92 if (mask) {
93 pix->mask = XCreateBitmapFromData(dpy, scr->w_win, mask, width, height);
94 } else {
95 pix->mask = None;
97 pix->width = width;
98 pix->height = height;
99 pix->depth = scr->w_depth;
100 return pix;
103 WPixmap *wPixmapCreate(WScreen * scr, Pixmap image, Pixmap mask)
105 WPixmap *pix;
106 Window foo;
107 int bar;
108 unsigned int width, height, depth, baz;
110 pix = wmalloc(sizeof(WPixmap));
111 memset(pix, 0, sizeof(WPixmap));
112 pix->image = image;
113 pix->mask = mask;
114 if (!XGetGeometry(dpy, image, &foo, &bar, &bar, &width, &height, &baz, &depth)) {
115 wwarning("XGetGeometry() failed during wPixmapCreate()");
116 wfree(pix);
117 return NULL;
119 pix->width = width;
120 pix->height = height;
121 pix->depth = depth;
122 return pix;
126 *----------------------------------------------------------------------
127 * wPixmapDestroy--
128 * Destroys a WPixmap structure and the pixmap/mask it holds.
130 * Returns:
131 * None
132 *----------------------------------------------------------------------
134 void wPixmapDestroy(WPixmap * pix)
136 if (!pix->shared) {
137 if (pix->mask && !pix->client_owned_mask) {
138 XFreePixmap(dpy, pix->mask);
141 if (pix->image && !pix->client_owned) {
142 XFreePixmap(dpy, pix->image);
145 wfree(pix);