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
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
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"
49 #include <X11/Xutil.h>
50 #include <X11/Xproto.h>
51 #include <X11/Xatom.h>
52 #include <X11/Intrinsic.h>
64 * Loads an icon file into a pixmap
67 Bool
LoadIconFile(int button
, int ico
)
71 FvwmPictureAttributes fpa
;
73 fpa
.mask
= FPAM_NO_ALLOC_PIXELS
;
74 path
= PictureFindImageFile(Buttons
[button
].icons
[ico
].file
, imagePath
,
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
,
89 fprintf(stderr
, "[FvwmWharf] cannot load pixmap from "
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;
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)) {
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
);
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
;
134 * Creates an Icon Window
137 void CreateIconWindow(int button
, Window
*win
)
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))
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
);
163 * Combines icon shape masks after a resize
166 void ConfigureIconWindow(int button
, int row
, int column
, int colorset
)
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)
184 if(Buttons
[button
].swallow
!= 0)
188 x
= column
*BUTTONWIDTH
;
189 y
= row
*BUTTONHEIGHT
;
191 XMoveResizeWindow(dpy
, Buttons
[button
].IconWin
, x
,y
,BUTTONWIDTH
,
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);
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
;
213 xoff
= (BUTTONWIDTH
- w
)/2;
214 yoff
= (BUTTONHEIGHT
- h
)/2;
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
,
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
);
236 * Make a gradient pixmap
240 int GetXPMGradient(int button
, int from
[3], int to
[3], int maxcols
,
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
) {
252 Buttons
[button
].icons
[0].depth
= Pdepth
;
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
);
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
);
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
);
280 DrawOutline(Buttons
[button
].icons
[0].icon
,64,64);
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
) {
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);
318 * Make a solid color pixmap
322 int GetSolidXPM(int button
, Pixel pixel
)
327 gcv
.foreground
=pixel
;
328 gc
=fvwmlib_XCreateGC(dpy
,main_win
,GCForeground
, &gcv
);
329 if (button
==BACK_BUTTON
) {
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
;
341 DrawOutline(Buttons
[button
].icons
[0].icon
,64,64);