cvsimport
[fvwm.git] / modules / FvwmScript / Widgets / RadioButton.c
blobb68bc0d3e91a19ad4bc2f0fc34f5639e58f42283
1 /* -*-c-*- */
2 /* This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 #include "config.h"
19 #include "libs/fvwmlib.h"
20 #include "libs/ColorUtils.h"
21 #include "libs/Graphics.h"
22 #include "Tools.h"
25 * Fonction pour RadioButton / Function for RadioButton
27 void InitRadioButton(struct XObj *xobj)
29 unsigned long mask;
30 XSetWindowAttributes Attr;
32 /* Enregistrement des couleurs et de la police */
33 if (xobj->colorset >= 0) {
34 xobj->TabColor[fore] = Colorset[xobj->colorset].fg;
35 xobj->TabColor[back] = Colorset[xobj->colorset].bg;
36 xobj->TabColor[hili] = Colorset[xobj->colorset].hilite;
37 xobj->TabColor[shad] = Colorset[xobj->colorset].shadow;
38 } else {
39 xobj->TabColor[fore] = GetColor(xobj->forecolor);
40 xobj->TabColor[back] = GetColor(xobj->backcolor);
41 xobj->TabColor[hili] = GetColor(xobj->hilicolor);
42 xobj->TabColor[shad] = GetColor(xobj->shadcolor);
45 mask=0;
46 Attr.cursor=XCreateFontCursor(dpy,XC_hand2);
47 mask|=CWCursor; /* Curseur pour la fenetre */
48 Attr.background_pixel=xobj->TabColor[back];
49 mask|=CWBackPixel;
51 xobj->win=XCreateWindow(dpy,*xobj->ParentWin,
52 xobj->x,xobj->y,xobj->width,xobj->height,0,
53 CopyFromParent,InputOutput,CopyFromParent,
54 mask,&Attr);
56 xobj->gc=fvwmlib_XCreateGC(dpy,xobj->win,0,NULL);
57 XSetForeground(dpy,xobj->gc,xobj->TabColor[fore]);
59 if ((xobj->Ffont = FlocaleLoadFont(
60 dpy, xobj->font, ScriptName)) == NULL)
62 fprintf(
63 stderr, "%s: Couldn't load font. Exiting!\n",
64 ScriptName);
65 exit(1);
67 if (xobj->Ffont->font != NULL)
68 XSetFont(dpy, xobj->gc, xobj->Ffont->font->fid);
70 XSetLineAttributes(dpy,xobj->gc,1,LineSolid,CapRound,JoinMiter);
72 /* Redimensionnement du widget */
73 xobj->height= xobj->Ffont->height +5;
74 xobj->width=FlocaleTextWidth(
75 xobj->Ffont,xobj->title,strlen(xobj->title))+20;
76 XResizeWindow(dpy,xobj->win,xobj->width,xobj->height);
77 if (xobj->colorset >= 0)
78 SetWindowBackground(
79 dpy, xobj->win, xobj->width, xobj->height,
80 &Colorset[xobj->colorset], Pdepth, xobj->gc, True);
82 XSelectInput(dpy, xobj->win, ExposureMask);
85 void DestroyRadioButton(struct XObj *xobj)
87 FlocaleUnloadFont(dpy,xobj->Ffont);
88 XFreeGC(dpy,xobj->gc);
89 XDestroyWindow(dpy,xobj->win);
92 void DrawRadioButton(struct XObj *xobj, XEvent *evp)
94 int i,j;
96 j=xobj->height/2+3;
97 i=16;
98 /* Dessin du cercle arrondi */
99 XSetForeground(dpy,xobj->gc,xobj->TabColor[shad]);
100 XDrawArc(dpy,xobj->win,xobj->gc,1,j-11,11,11,45*64,180*64);
101 XSetForeground(dpy,xobj->gc,xobj->TabColor[hili]);
102 XDrawArc(dpy,xobj->win,xobj->gc,1,j-11,11,11,225*64,180*64);
103 XSetForeground(dpy,xobj->gc,xobj->TabColor[shad]);
104 XDrawArc(dpy,xobj->win,xobj->gc,2,j-10,9,9,0*64,360*64);
105 XSetForeground(dpy,xobj->gc,xobj->TabColor[fore]);
106 if (xobj->value)
107 XFillArc(dpy,xobj->win,xobj->gc,2,j-10,9,9,0*64,360*64);
109 /* Calcul de la position de la chaine de charactere */
110 MyDrawString(dpy,xobj,xobj->win,i,j,xobj->title,fore,hili,
111 back,!xobj->flags[1], NULL, evp);
114 void EvtMouseRadioButton(struct XObj *xobj,XButtonEvent *EvtButton)
116 static XEvent event;
117 int End=1;
118 unsigned int modif;
119 int x1,x2,y1,y2,i,j;
120 Window Win1,Win2;
121 Window WinBut=0;
122 int In = 0;
124 j=xobj->height/2+3;
125 i=(xobj->width-FlocaleTextWidth(
126 xobj->Ffont,xobj->title,strlen(xobj->title)))/2;
128 while (End)
130 FNextEvent(dpy, &event);
131 switch (event.type)
133 case EnterNotify:
134 FQueryPointer(dpy,*xobj->ParentWin,
135 &Win1,&Win2,&x1,&y1,&x2,&y2,&modif);
136 if (WinBut==0)
138 WinBut=Win2;
139 /* Mouse on button */
140 XSetForeground(
141 dpy,xobj->gc,xobj->TabColor[back]);
142 XFillArc(
143 dpy,xobj->win,xobj->gc,2,j-10,9,9,
144 0*64,360*64);
145 In=1;
147 else
149 if (Win2==WinBut)
151 /* Mouse on button */
152 XSetForeground(
153 dpy,xobj->gc,
154 xobj->TabColor[back]);
155 XFillArc(
156 dpy,xobj->win,xobj->gc,2,j-10,
157 9,9,0*64,360*64);
158 In=1;
160 else if (In)
162 In=0;
163 /* Mouse not on button */
164 XSetForeground(
165 dpy,xobj->gc,
166 xobj->TabColor[fore]);
167 XFillArc(
168 dpy,xobj->win,xobj->gc,2,j-10,
169 9,9,0*64,360*64);
172 break;
173 case LeaveNotify:
174 FQueryPointer(dpy,*xobj->ParentWin,
175 &Win1,&Win2,&x1,&y1,&x2,&y2,&modif);
176 if (Win2==WinBut)
178 In=1;
179 /* Mouse on button */
180 XSetForeground(
181 dpy,xobj->gc,xobj->TabColor[back]);
182 XFillArc(
183 dpy,xobj->win,xobj->gc,2,j-10,8,8,
184 0*64,360*64);
186 else if (In)
188 /* Mouse not on button */
189 XSetForeground(
190 dpy,xobj->gc,xobj->TabColor[back]);
191 XFillArc(
192 dpy,xobj->win,xobj->gc,2,j-10,8,8,
193 0*64,360*64);
194 In=0;
196 break;
197 case ButtonRelease:
198 End=0;
199 /* Mouse not on button */
200 if (In)
202 /* Envoie d'un message vide de type SingleClic
203 * pour un clique souris */
204 xobj->value=1;
205 XSetForeground(
206 dpy,xobj->gc,xobj->TabColor[fore]);
207 XFillArc(
208 dpy,xobj->win,xobj->gc,2,j-10,8,8,
209 0*64,360*64);
210 SendMsg(xobj,SingleClic);
212 else if (xobj->value)
214 XSetForeground(
215 dpy,xobj->gc,xobj->TabColor[fore]);
216 XFillArc(
217 dpy,xobj->win,xobj->gc,2,j-10,8,8,
218 0*64,360*64);
220 else
222 XSetForeground(
223 dpy,xobj->gc,xobj->TabColor[back]);
224 XFillArc(
225 dpy,xobj->win,xobj->gc,2,j-10,8,8,
226 0*64,360*64);
228 break;
233 void EvtKeyRadioButton(struct XObj *xobj,XKeyEvent *EvtKey)
235 KeySym ks;
236 unsigned char buf[10];
237 int j=xobj->height/2+3;
239 XLookupString(EvtKey, (char *)buf, sizeof(buf), &ks, NULL);
240 if (ks == XK_Return) {
241 xobj->value=1;
242 XSetForeground(dpy,xobj->gc,xobj->TabColor[fore]);
243 XFillArc(
244 dpy, xobj->win, xobj->gc, 2, j-10, 8, 8, 0*64, 360*64);
245 SendMsg(xobj,SingleClic);
249 void ProcessMsgRadioButton(
250 struct XObj *xobj,unsigned long type,unsigned long *body)