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
19 #include "libs/fvwmlib.h"
20 #include "libs/ColorUtils.h"
21 #include "libs/Graphics.h"
25 * Fonction pour RadioButton / Function for RadioButton
27 void InitRadioButton(struct XObj
*xobj
)
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
;
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
);
46 Attr
.cursor
=XCreateFontCursor(dpy
,XC_hand2
);
47 mask
|=CWCursor
; /* Curseur pour la fenetre */
48 Attr
.background_pixel
=xobj
->TabColor
[back
];
51 xobj
->win
=XCreateWindow(dpy
,*xobj
->ParentWin
,
52 xobj
->x
,xobj
->y
,xobj
->width
,xobj
->height
,0,
53 CopyFromParent
,InputOutput
,CopyFromParent
,
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
)
63 stderr
, "%s: Couldn't load font. Exiting!\n",
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)
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
)
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
]);
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
)
125 i
=(xobj
->width
-FlocaleTextWidth(
126 xobj
->Ffont
,xobj
->title
,strlen(xobj
->title
)))/2;
130 FNextEvent(dpy
, &event
);
134 FQueryPointer(dpy
,*xobj
->ParentWin
,
135 &Win1
,&Win2
,&x1
,&y1
,&x2
,&y2
,&modif
);
139 /* Mouse on button */
141 dpy
,xobj
->gc
,xobj
->TabColor
[back
]);
143 dpy
,xobj
->win
,xobj
->gc
,2,j
-10,9,9,
151 /* Mouse on button */
154 xobj
->TabColor
[back
]);
156 dpy
,xobj
->win
,xobj
->gc
,2,j
-10,
163 /* Mouse not on button */
166 xobj
->TabColor
[fore
]);
168 dpy
,xobj
->win
,xobj
->gc
,2,j
-10,
174 FQueryPointer(dpy
,*xobj
->ParentWin
,
175 &Win1
,&Win2
,&x1
,&y1
,&x2
,&y2
,&modif
);
179 /* Mouse on button */
181 dpy
,xobj
->gc
,xobj
->TabColor
[back
]);
183 dpy
,xobj
->win
,xobj
->gc
,2,j
-10,8,8,
188 /* Mouse not on button */
190 dpy
,xobj
->gc
,xobj
->TabColor
[back
]);
192 dpy
,xobj
->win
,xobj
->gc
,2,j
-10,8,8,
199 /* Mouse not on button */
202 /* Envoie d'un message vide de type SingleClic
203 * pour un clique souris */
206 dpy
,xobj
->gc
,xobj
->TabColor
[fore
]);
208 dpy
,xobj
->win
,xobj
->gc
,2,j
-10,8,8,
210 SendMsg(xobj
,SingleClic
);
212 else if (xobj
->value
)
215 dpy
,xobj
->gc
,xobj
->TabColor
[fore
]);
217 dpy
,xobj
->win
,xobj
->gc
,2,j
-10,8,8,
223 dpy
,xobj
->gc
,xobj
->TabColor
[back
]);
225 dpy
,xobj
->win
,xobj
->gc
,2,j
-10,8,8,
233 void EvtKeyRadioButton(struct XObj
*xobj
,XKeyEvent
*EvtKey
)
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
) {
242 XSetForeground(dpy
,xobj
->gc
,xobj
->TabColor
[fore
]);
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
)