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 CheckBox / functions for CheckBox
27 void InitCheckBox(struct XObj
*xobj
)
30 XSetWindowAttributes Attr
;
32 /* Enregistrement des couleurs et de la police / fonts and colors */
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
.background_pixel
= xobj
->TabColor
[back
];
48 Attr
.cursor
= XCreateFontCursor(dpy
,XC_hand2
);
49 mask
|= CWCursor
; /* Curseur pour la fenetre / Cursor for the window */
51 xobj
->win
= XCreateWindow(dpy
, *xobj
->ParentWin
,
52 xobj
->x
, xobj
->y
, xobj
->width
, xobj
->height
,0,
53 CopyFromParent
, InputOutput
, CopyFromParent
,
55 xobj
->gc
= fvwmlib_XCreateGC(dpy
,xobj
->win
,0,NULL
);
56 XSetForeground(dpy
, xobj
->gc
, xobj
->TabColor
[fore
]);
58 if ((xobj
->Ffont
= FlocaleLoadFont(dpy
, xobj
->font
, ScriptName
)) == NULL
)
60 fprintf(stderr
, "%s: Couldn't load font. Exiting!\n", ScriptName
);
63 if (xobj
->Ffont
->font
!= NULL
)
64 XSetFont(dpy
, xobj
->gc
, xobj
->Ffont
->font
->fid
);
66 XSetLineAttributes(dpy
, xobj
->gc
, 1, LineSolid
, CapRound
, JoinMiter
);
68 /* Redimensionnement du widget / resize the widget */
69 xobj
->height
= xobj
->Ffont
->height
+ 5;
71 FlocaleTextWidth(xobj
->Ffont
, xobj
->title
, strlen(xobj
->title
)) + 30;
72 XResizeWindow(dpy
, xobj
->win
, xobj
->width
, xobj
->height
);
73 if (xobj
->colorset
>= 0)
74 SetWindowBackground(dpy
, xobj
->win
, xobj
->width
, xobj
->height
,
75 &Colorset
[xobj
->colorset
], Pdepth
,
77 XSelectInput(dpy
, xobj
->win
, ExposureMask
);
80 void DestroyCheckBox(struct XObj
*xobj
)
82 FlocaleUnloadFont(dpy
, xobj
->Ffont
);
83 XFreeGC(dpy
,xobj
->gc
);
84 XDestroyWindow(dpy
,xobj
->win
);
87 void DrawCheckBox(struct XObj
*xobj
, XEvent
*evp
)
91 /* Dessin du rectangle arrondi / drawing of the round rectangle */
92 DrawReliefRect(0, xobj
->Ffont
->ascent
- 11, xobj
->height
, xobj
->height
,
95 /* Calcul de la position de la chaine de charactere */
96 /* Compute the position of string */
97 MyDrawString(dpy
, xobj
, xobj
->win
, 23, xobj
->Ffont
->ascent
, xobj
->title
,
98 fore
, hili
, back
, !xobj
->flags
[1], NULL
, evp
);
99 /* Dessin de la croix / draw the cross */
102 XSetLineAttributes(dpy
, xobj
->gc
, 2, LineSolid
, CapProjecting
, JoinMiter
);
105 segm
[0].x2
= xobj
->height
- 6;
106 segm
[0].y2
= xobj
->height
- 6;
108 segm
[1].y1
= xobj
->height
- 6;
109 segm
[1].x2
= xobj
->height
- 6;
111 XSetForeground(dpy
, xobj
->gc
, xobj
->TabColor
[fore
]);
112 XDrawSegments(dpy
, xobj
->win
, xobj
->gc
, segm
, 2);
113 XSetLineAttributes(dpy
, xobj
->gc
, 1, LineSolid
, CapRound
, JoinMiter
);
117 void EvtMouseCheckBox(struct XObj
*xobj
, XButtonEvent
*EvtButton
)
130 FNextEvent(dpy
, &event
);
134 FQueryPointer(dpy
, *xobj
->ParentWin
,
135 &Win1
, &Win2
, &x1
, &y1
, &x2
, &y2
, &modif
);
139 /* Mouse on button */
140 DrawReliefRect(0, xobj
->Ffont
->ascent
- 11, xobj
->height
,
141 xobj
->height
, xobj
, shad
, hili
);
148 /* Mouse on button */
149 DrawReliefRect(0, xobj
->Ffont
->ascent
- 11, xobj
->height
, xobj
->height
,
156 /* Mouse not on button */
157 DrawReliefRect(0, xobj
->Ffont
->ascent
- 11, xobj
->height
, xobj
->height
,
163 FQueryPointer(dpy
, *xobj
->ParentWin
,
164 &Win1
, &Win2
, &x1
, &y1
, &x2
, &y2
, &modif
);
168 /* Mouse on button */
169 DrawReliefRect(0, xobj
->Ffont
->ascent
- 11, xobj
->height
, xobj
->height
,
174 /* Mouse not on button */
175 DrawReliefRect(0, xobj
->Ffont
->ascent
- 11, xobj
->height
, xobj
->height
,
182 /* Mouse not on button */
185 /* Envoie d'un message vide de type SingleClic pour un clique souris */
186 xobj
->value
= !xobj
->value
;
187 DrawReliefRect(0, xobj
->Ffont
->ascent
-11, xobj
->height
, xobj
->height
,
189 SendMsg(xobj
,SingleClic
);
193 XSetLineAttributes(dpy
, xobj
->gc
, 2,
194 LineSolid
, CapProjecting
, JoinMiter
);
197 segm
[0].x2
= xobj
->height
- 6;
198 segm
[0].y2
= xobj
->height
- 6;
200 segm
[1].y1
= xobj
->height
- 6;
201 segm
[1].x2
= xobj
->height
- 6;
203 XSetForeground(dpy
, xobj
->gc
, xobj
->TabColor
[fore
]);
204 XDrawSegments(dpy
, xobj
->win
, xobj
->gc
, segm
, 2);
205 XSetLineAttributes(dpy
, xobj
->gc
, 1, LineSolid
, CapRound
, JoinMiter
);
209 XClearArea(dpy
, xobj
->win
, 4, 4, xobj
->height
-8, xobj
->height
-8, False
);
216 void EvtKeyCheckBox(struct XObj
*xobj
, XKeyEvent
*EvtKey
)
219 unsigned char buf
[10];
222 XLookupString(EvtKey
, (char *)buf
, sizeof(buf
), &ks
, NULL
);
223 if (ks
== XK_Return
) {
224 xobj
->value
= !xobj
->value
;
225 DrawReliefRect(0, xobj
->Ffont
->ascent
- 11, xobj
->height
,
226 xobj
->height
, xobj
, hili
, shad
);
227 SendMsg(xobj
,SingleClic
);
230 XSetLineAttributes(dpy
, xobj
->gc
, 2,
231 LineSolid
, CapProjecting
, JoinMiter
);
234 segm
[0].x2
= xobj
->height
- 6;
235 segm
[0].y2
= xobj
->height
- 6;
237 segm
[1].y1
= xobj
->height
- 6;
238 segm
[1].x2
= xobj
->height
- 6;
240 XSetForeground(dpy
, xobj
->gc
, xobj
->TabColor
[fore
]);
241 XDrawSegments(dpy
, xobj
->win
, xobj
->gc
, segm
, 2);
242 XSetLineAttributes(dpy
, xobj
->gc
, 1, LineSolid
, CapRound
, JoinMiter
);
246 XClearArea(dpy
, xobj
->win
, 4, 4, xobj
->height
-8, xobj
->height
-8, False
);
252 void ProcessMsgCheckBox(struct XObj
*xobj
, unsigned long type
, unsigned long *body
)