Copy purify.fvwm2rc to /tmp - add instructions in README.
[fvwm.git] / modules / FvwmWharf / icons.c
blob9788cdf92fdd1dad17e123c78fb9416eb07c8070
1 /* -*-c-*- */
2 /* icons.c. by Bo Yang.
3 * Modifications: Copyright 1995 by Bo Yang.
5 * based on icons.c by Robert Nation
6 * The icons module, and the entire GoodStuff program, and the concept for
7 * interfacing this module to the Window Manager, are all original work
8 * by Robert Nation
10 * Copyright 1993, Robert Nation.
11 * No guarantees or warantees or anything
12 * are provided or implied in any way whatsoever. Use this program at your
13 * own risk. Permission to use this program for any purpose is given,
14 * as long as the copyright is kept intact. */
16 /* This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 * Derived from fvwm icon code
37 #include "config.h"
38 #include "libs/fvwmlib.h"
39 #include "libs/Picture.h"
40 #include "libs/Colorset.h"
41 #include "libs/PictureGraphics.h"
42 #include "libs/Graphics.h"
44 #include <stdio.h>
45 #include <unistd.h>
46 #include <signal.h>
48 #include <X11/Xlib.h>
49 #include <X11/Xutil.h>
50 #include <X11/Xproto.h>
51 #include <X11/Xatom.h>
52 #include <X11/Intrinsic.h>
54 #ifdef HAVE_FCNTL_H
55 #include <fcntl.h>
56 #endif
58 #include "Wharf.h"
59 #include "stepgfx.h"
64 * Loads an icon file into a pixmap
67 Bool LoadIconFile(int button, int ico)
69 #ifndef NO_ICONS
70 char *path = NULL;
71 FvwmPictureAttributes fpa;
73 fpa.mask = FPAM_NO_ALLOC_PIXELS;
74 path = PictureFindImageFile(Buttons[button].icons[ico].file, imagePath,
75 R_OK);
76 if (path == NULL)
78 return False;
80 if (!PImageLoadPixmapFromFile(
81 dpy, main_win, path, &Buttons[button].icons[ico].icon,
82 &Buttons[button].icons[ico].mask,
83 &Buttons[button].icons[ico].alpha,
84 &Buttons[button].icons[ico].w,
85 &Buttons[button].icons[ico].h,
86 &Buttons[button].icons[ico].depth,
87 0, NULL, 0, fpa))
89 fprintf(stderr, "[FvwmWharf] cannot load pixmap from "
90 "file '%s'\n",path);
91 free(path);
92 Buttons[button].icons[ico].w = 0;
93 Buttons[button].icons[ico].h = 0;
94 Buttons[button].icons[ico].icon = None;
95 Buttons[button].icons[ico].depth = 0;
96 return False;
98 free(path);
99 if (Buttons[button].icons[ico].depth == Pdepth && button==BACK_BUTTON)
101 BUTTONWIDTH = Buttons[button].icons[ico].w;
102 BUTTONHEIGHT = Buttons[button].icons[ico].h;
103 if (ForceSize && (BUTTONWIDTH > 64 || BUTTONHEIGHT > 64)) {
104 Pixmap resized;
106 BUTTONWIDTH = 64;
107 BUTTONHEIGHT = 64;
108 resized = XCreatePixmap(dpy, main_win, 64, 64, Pdepth);
109 XCopyArea(dpy, Buttons[button].icons[ico].icon,
110 resized, NormalGC, 0, 0, 64, 64, 0, 0);
111 XFreePixmap(dpy, Buttons[button].icons[ico].icon);
112 Buttons[button].icons[ico].icon = resized;
114 DrawOutline(Buttons[button].icons[ico].icon,
115 BUTTONWIDTH,BUTTONHEIGHT);
116 return True;
118 else if (button == BACK_BUTTON)
120 Buttons[button].icons[ico].w = 0;
121 Buttons[button].icons[ico].h = 0;
122 Buttons[button].icons[ico].depth = 0;
123 XFreePixmap(dpy, Buttons[button].icons[ico].icon);
124 Buttons[button].icons[ico].icon = None;
126 return False;
127 #else
128 return False;
129 #endif
134 * Creates an Icon Window
137 void CreateIconWindow(int button, Window *win)
139 #ifndef NO_ICONS
140 unsigned long valuemask; /* mask for create windows */
141 XSetWindowAttributes attributes; /* attributes for create windows */
143 /* This used to make buttons without icons explode when pushed
144 if((Buttons[button].icon_w == 0)&&(Buttons[button].icon_h == 0))
145 return;
147 attributes.background_pixel = back_pix;
148 attributes.border_pixel = 0;
149 attributes.colormap = Pcmap;
150 attributes.event_mask = ExposureMask;
151 valuemask = CWEventMask | CWBackPixel | CWBorderPixel | CWColormap;
153 Buttons[button].IconWin =
154 XCreateWindow(dpy, *win, 0, 0, BUTTONWIDTH, BUTTONHEIGHT, 0, Pdepth,
155 InputOutput, Pvisual, valuemask, &attributes);
157 return;
158 #endif
163 * Combines icon shape masks after a resize
166 void ConfigureIconWindow(int button, int row, int column, int colorset)
168 #ifndef NO_ICONS
169 int x,y, w, h;
170 int xoff,yoff;
171 int i;
172 FvwmRenderAttributes fra;
174 if (Buttons[button].completeIcon != None)
176 XFreePixmap(dpy, Buttons[button].completeIcon);
177 Buttons[button].completeIcon = None;
180 if(Buttons[button].iconno == 0)
182 return;
184 if(Buttons[button].swallow != 0)
186 return;
188 x = column*BUTTONWIDTH;
189 y = row*BUTTONHEIGHT;
191 XMoveResizeWindow(dpy, Buttons[button].IconWin, x,y,BUTTONWIDTH,
192 BUTTONHEIGHT);
193 Buttons[button].completeIcon =
194 XCreatePixmap(dpy,main_win, BUTTONWIDTH,BUTTONHEIGHT,Pdepth);
195 XCopyArea(dpy, Buttons[BACK_BUTTON].icons[0].icon,
196 Buttons[button].completeIcon, NormalGC, 0,0,
197 BUTTONWIDTH,BUTTONHEIGHT, 0,0);
199 fra.mask = 0;
200 if (colorset >= 0)
202 fra.mask |= FRAM_HAVE_ICON_CSET;
203 fra.colorset = &Colorset[colorset];
205 for(i=0;i<Buttons[button].iconno;i++) {
206 w = Buttons[button].icons[i].w;
207 h = Buttons[button].icons[i].h;
208 if (w<1 || h<1) continue;
209 if (w > BUTTONWIDTH) w = BUTTONWIDTH;
210 if (h > BUTTONHEIGHT) h = BUTTONHEIGHT;
211 if (w < 1) w = 1;
212 if (h < 1) h = 1;
213 xoff = (BUTTONWIDTH - w)/2;
214 yoff = (BUTTONHEIGHT - h)/2;
215 if (xoff<0) xoff=0;
216 if (yoff<0) yoff=0;
217 PGraphicsRenderPixmaps(
218 dpy, Buttons[button].IconWin,
219 Buttons[button].icons[i].icon,
220 Buttons[button].icons[i].mask,
221 Buttons[button].icons[i].alpha,
222 Buttons[button].icons[i].depth,
223 &fra,
224 Buttons[button].completeIcon,
225 NormalGC, None, None,
226 0, 0, w, h, xoff, yoff, 0, 0, False);
228 XSetWindowBackgroundPixmap(dpy, Buttons[button].IconWin,
229 Buttons[button].completeIcon);
230 XClearWindow(dpy,Buttons[button].IconWin);
231 #endif
236 * Make a gradient pixmap
240 int GetXPMGradient(int button, int from[3], int to[3], int maxcols,
241 int type)
243 Buttons[button].icons[0].icon=XCreatePixmap(dpy,main_win,64,64, Pdepth);
244 Buttons[button].icons[0].mask=None;
245 Buttons[button].icons[0].alpha=None;
246 Buttons[button].icons[0].w = 64;
247 Buttons[button].icons[0].h = 64;
248 if (button==BACK_BUTTON) {
249 BUTTONWIDTH = 64;
250 BUTTONHEIGHT = 64;
252 Buttons[button].icons[0].depth = Pdepth;
253 switch (type) {
254 case TEXTURE_GRADIENT:
255 if (!DrawDegradeRelief(dpy, Buttons[button].icons[0].icon, 0,0,64,64,
256 from, to, 0, maxcols)) {
257 XFreePixmap(dpy, Buttons[button].icons[0].icon);
258 return 0;
260 break;
261 case TEXTURE_HGRADIENT:
262 case TEXTURE_HCGRADIENT:
263 if (!DrawHGradient(dpy, Buttons[button].icons[0].icon, 0, 0, 64,64,
264 from, to, 0, maxcols, type-TEXTURE_HGRADIENT)) {
265 XFreePixmap(dpy, Buttons[button].icons[0].icon);
266 return 0;
268 break;
269 case TEXTURE_VGRADIENT:
270 case TEXTURE_VCGRADIENT:
271 if (!DrawVGradient(dpy, Buttons[button].icons[0].icon, 0, 0, 64,64,
272 from, to, 0, maxcols, type-TEXTURE_VGRADIENT)) {
273 XFreePixmap(dpy, Buttons[button].icons[0].icon);
274 return 0;
276 break;
277 default:
278 return 0;
280 DrawOutline(Buttons[button].icons[0].icon,64,64);
282 return 1;
287 * Make a colorset pixmap
291 void GetXPMColorset(int button, int colorset)
293 if (Buttons[button].icons[0].icon == None)
295 Buttons[button].icons[0].icon=XCreatePixmap(dpy,main_win,64,64, Pdepth);
296 Buttons[button].icons[0].mask=None;
297 Buttons[button].icons[0].alpha=None;
298 Buttons[button].icons[0].w = 64;
299 Buttons[button].icons[0].h = 64;
300 if (button==BACK_BUTTON) {
301 BUTTONWIDTH = 64;
302 BUTTONHEIGHT = 64;
304 Buttons[button].icons[0].depth = Pdepth;
307 SetRectangleBackground(
308 dpy, Buttons[button].icons[0].icon, 0, 0, 64, 64,
309 &(Colorset[colorset]), Pdepth, NormalGC);
311 DrawOutline(Buttons[button].icons[0].icon,64,64);
313 return;
318 * Make a solid color pixmap
322 int GetSolidXPM(int button, Pixel pixel)
324 GC gc;
325 XGCValues gcv;
327 gcv.foreground=pixel;
328 gc=fvwmlib_XCreateGC(dpy,main_win,GCForeground, &gcv);
329 if (button==BACK_BUTTON) {
330 BUTTONWIDTH = 64;
331 BUTTONHEIGHT = 64;
333 Buttons[button].icons[0].icon=XCreatePixmap(dpy,main_win,64,64, Pdepth);
334 Buttons[button].icons[0].mask=None;
335 Buttons[button].icons[0].alpha=None;
336 XFillRectangle(dpy,Buttons[button].icons[0].icon,gc,0,0,64,64);
337 Buttons[button].icons[0].w = 64;
338 Buttons[button].icons[0].h = 64;
339 Buttons[button].icons[0].depth = Pdepth;
340 XFreeGC(dpy,gc);
341 DrawOutline(Buttons[button].icons[0].icon,64,64);
343 return 1;