cvsimport
[fvwm.git] / modules / FvwmButtons / icons.c
blob4d23881e10bc26c416cf017d69c96c651995adab
1 /* -*-c-*- */
2 /*
3 * Fvwmbuttons, copyright 1996, Jarl Totland
5 * This module, and the entire GoodStuff program, and the concept for
6 * interfacing this module to the Window Manager, are all original work
7 * by Robert Nation
9 * Copyright 1993, Robert Nation. No guarantees or warantees or anything
10 * are provided or implied in any way whatsoever. Use this program at your
11 * own risk. Permission to use this program for any purpose is given,
12 * 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"
39 #include <stdio.h>
40 #include <unistd.h>
41 #include <signal.h>
43 #include <X11/Xlib.h>
44 #include <X11/Xutil.h>
45 #include <X11/Xproto.h>
46 #include <X11/Xatom.h>
47 #include <X11/Intrinsic.h>
49 #ifdef HAVE_FCNTL_H
50 #include <fcntl.h>
51 #endif
53 #include "libs/fvwmlib.h"
54 #include "libs/FShape.h"
55 #include "FvwmButtons.h"
56 #include "libs/PictureGraphics.h"
57 #include "libs/Colorset.h"
58 #include "libs/Rectangles.h"
63 * Combines icon shape masks after a resize
66 Bool GetIconPosition(button_info *b,
67 FvwmPicture *pic, int *r_x, int *r_y, int *r_w, int *r_h)
69 #ifdef NO_ICONS
70 return False;
71 #else
72 int x, y, width, height;
73 int xoff, yoff;
74 int framew, xpad, ypad;
75 FlocaleFont *Ffont;
76 int BW,BH;
77 Bool has_title = (buttonTitle(b) != NULL ? True : False);
79 buttonInfo(b, &x, &y, &xpad, &ypad, &framew);
80 framew = abs(framew);
81 Ffont = buttonFont(b);
83 width = pic->width;
84 height = pic->height;
85 BW = buttonWidth(b);
86 BH = buttonHeight(b);
88 width = min(width, BW - 2 * (xpad + framew));
90 if (has_title == True && Ffont && !(buttonJustify(b) & b_Horizontal))
92 height = min(height, BH - 2 * (ypad + framew)
93 - Ffont->ascent - Ffont->descent);
95 else
97 height = min(height,BH-2*(ypad+framew));
100 if (b->flags.b_Right)
102 xoff = BW-framew - xpad-width;
104 else if (b->flags.b_Left)
106 xoff = framew + xpad;
108 else
110 if (buttonJustify(b) & b_Horizontal)
112 xoff = 0;
114 else
116 xoff = (BW - width) >> 1;
118 if (xoff < framew + xpad)
120 xoff = framew + xpad;
124 if (has_title == True && Ffont && !(buttonJustify(b) & b_Horizontal))
126 yoff = (BH - (height + Ffont->height)) >> 1;
128 else
130 yoff = (BH - height) >> 1;
133 if (yoff < framew + ypad)
135 yoff = framew + ypad;
138 x += xoff;
139 y += yoff;
141 *r_x = x;
142 *r_y = y;
143 *r_w = width;
144 *r_h = height;
146 return True;
147 #endif
150 void DrawForegroundIcon(button_info *b, XEvent *pev)
152 #ifndef NO_ICONS
153 int x, y, w, h;
154 int cset;
155 XRectangle clip;
156 FvwmRenderAttributes fra;
157 FvwmPicture *pic = buttonIcon(b);
159 if (!GetIconPosition(b, pic, &x, &y, &w, &h))
161 return;
164 if (w < 1 || h < 1)
166 return; /* No need drawing to this */
169 clip.x = x;
170 clip.y = y;
171 clip.width = w;
172 clip.height = h;
174 if (pev)
176 if (!frect_get_intersection(
177 x, y, w, h,
178 pev->xexpose.x, pev->xexpose.y,
179 pev->xexpose.width, pev->xexpose.height,
180 &clip))
182 return;
186 if (0 && !pev)
188 XClearArea(
189 Dpy, MyWindow, clip.x, clip.y, clip.width, clip.height,
190 False);
193 cset = buttonColorset(b);
194 fra.mask = FRAM_DEST_IS_A_WINDOW;
195 if (cset >= 0)
197 fra.mask |= FRAM_HAVE_ICON_CSET;
198 fra.colorset = &Colorset[cset];
201 PGraphicsRenderPicture(
202 Dpy, MyWindow, pic, &fra, MyWindow,
203 NormalGC, None, None,
204 clip.x - x, clip.y - y, clip.width, clip.height,
205 clip.x, clip.y, clip.width, clip.height, False);
206 #endif