Update Serbian translation from master branch
[wmaker-crm.git] / src / pixmap.c
blob9bb06228dcfdbcf6914d4805d5d41a0d820fe1af
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));
57 RConvertImageMask(scr->rcontext, image, &pix->image, &pix->mask, 128);
59 pix->width = image->width;
60 pix->height = image->height;
61 pix->depth = scr->w_depth;
63 RReleaseImage(image);
65 return pix;
69 *----------------------------------------------------------------------
70 * wPixmapCreateFromXBMData--
71 * Creates a WPixmap structure and initializes it with the supplied
72 * XBM structure data, size and mask.
74 * Returns:
75 * A WPixmap structure or NULL on failure.
77 *----------------------------------------------------------------------
79 WPixmap *wPixmapCreateFromXBMData(WScreen * scr, char *data, char *mask,
80 int width, int height, unsigned long fg, unsigned long bg)
82 WPixmap *pix;
84 pix = wmalloc(sizeof(WPixmap));
85 pix->image = XCreatePixmapFromBitmapData(dpy, scr->w_win, data, width, height, fg, bg, scr->w_depth);
86 if (pix->image == None) {
87 wfree(pix);
88 return NULL;
90 if (mask) {
91 pix->mask = XCreateBitmapFromData(dpy, scr->w_win, mask, width, height);
92 } else {
93 pix->mask = None;
95 pix->width = width;
96 pix->height = height;
97 pix->depth = scr->w_depth;
98 return pix;
101 WPixmap *wPixmapCreate(Pixmap image, Pixmap mask)
103 WPixmap *pix;
104 Window foo;
105 int bar;
106 unsigned int width, height, depth, baz;
108 pix = wmalloc(sizeof(WPixmap));
109 pix->image = image;
110 pix->mask = mask;
111 if (!XGetGeometry(dpy, image, &foo, &bar, &bar, &width, &height, &baz, &depth)) {
112 wwarning("XGetGeometry() failed during wPixmapCreate()");
113 wfree(pix);
114 return NULL;
116 pix->width = width;
117 pix->height = height;
118 pix->depth = depth;
119 return pix;
123 *----------------------------------------------------------------------
124 * wPixmapDestroy--
125 * Destroys a WPixmap structure and the pixmap/mask it holds.
127 * Returns:
128 * None
129 *----------------------------------------------------------------------
131 void wPixmapDestroy(WPixmap * pix)
133 if (!pix->shared) {
134 if (pix->mask && !pix->client_owned_mask) {
135 XFreePixmap(dpy, pix->mask);
138 if (pix->image && !pix->client_owned) {
139 XFreePixmap(dpy, pix->image);
142 wfree(pix);