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 VScrollBar
27 void DrawThumbV(struct XObj
*xobj
, XEvent
*evp
)
33 x
= xobj
->width
/2 - 10;
35 (xobj
->height
- 36)*(xobj
->value
- xobj
->value3
) /
36 (xobj
->value2
- xobj
->value3
);
39 DrawReliefRect(x
, y
, w
, h
, xobj
, hili
, shad
);
44 XSetForeground(dpy
, xobj
->gc
, xobj
->TabColor
[shad
]);
45 XDrawSegments(dpy
, xobj
->win
, xobj
->gc
, &segm
, 1);
50 XSetForeground(dpy
, xobj
->gc
, xobj
->TabColor
[hili
]);
51 XDrawSegments(dpy
, xobj
->win
, xobj
->gc
, &segm
, 1);
52 XSetForeground(dpy
, xobj
->gc
, xobj
->TabColor
[fore
]);
54 sprintf(str
, "%d", xobj
->value
);
55 x
= x
-FlocaleTextWidth(xobj
->Ffont
, str
, strlen(str
))-6;
56 y
= y
+ 13 + xobj
->Ffont
->ascent
/2;
57 MyDrawString(dpy
, xobj
, xobj
->win
, x
, y
, str
, fore
, hili
, back
,
58 !xobj
->flags
[1], NULL
, evp
);
61 void HideThumbV(struct XObj
*xobj
)
66 x
= xobj
->width
/2 - 10;
68 (xobj
->height
- 36) * (xobj
->value
- xobj
->value3
) /
69 (xobj
->value2
- xobj
->value3
);
70 XClearArea(dpy
, xobj
->win
, x
, y
, 20, 32, False
);
71 sprintf(str
, "%d", xobj
->value
);
73 dpy
, xobj
->win
, 0, 0,xobj
->width
/2 - 14,xobj
->height
, False
);
76 void InitVScrollBar(struct XObj
*xobj
)
79 XSetWindowAttributes Attr
;
83 /* Enregistrement des couleurs et de la police */
84 if (xobj
->colorset
>= 0) {
85 xobj
->TabColor
[fore
] = Colorset
[xobj
->colorset
].fg
;
86 xobj
->TabColor
[back
] = Colorset
[xobj
->colorset
].bg
;
87 xobj
->TabColor
[hili
] = Colorset
[xobj
->colorset
].hilite
;
88 xobj
->TabColor
[shad
] = Colorset
[xobj
->colorset
].shadow
;
90 xobj
->TabColor
[fore
] = GetColor(xobj
->forecolor
);
91 xobj
->TabColor
[back
] = GetColor(xobj
->backcolor
);
92 xobj
->TabColor
[hili
] = GetColor(xobj
->hilicolor
);
93 xobj
->TabColor
[shad
] = GetColor(xobj
->shadcolor
);
97 Attr
.background_pixel
= xobj
->TabColor
[back
];
99 Attr
.cursor
= XCreateFontCursor(dpy
,XC_hand2
);
100 mask
|= CWCursor
; /* Curseur pour la fenetre */
102 xobj
->win
= XCreateWindow(
103 dpy
, *xobj
->ParentWin
, xobj
->x
, xobj
->y
, xobj
->width
,
104 xobj
->height
, 0, CopyFromParent
, InputOutput
, CopyFromParent
,
106 xobj
->gc
= fvwmlib_XCreateGC(dpy
, xobj
->win
, 0, NULL
);
107 XSetForeground(dpy
, xobj
->gc
, xobj
->TabColor
[fore
]);
110 if ((xobj
->Ffont
= FlocaleLoadFont(dpy
, xobj
->font
, ScriptName
)) ==
114 stderr
, "%s: Couldn't load font. Exiting!\n",
118 if (xobj
->Ffont
->font
!= NULL
)
119 XSetFont(dpy
, xobj
->gc
, xobj
->Ffont
->font
->fid
);
121 XSetLineAttributes(dpy
, xobj
->gc
, 1, LineSolid
, CapRound
, JoinMiter
);
123 if ((xobj
->value3
- xobj
->value2
) <= 0)
124 xobj
->value3
= xobj
->value2
+ 10;
125 if (!((xobj
->value
>= xobj
->value2
) && (xobj
->value
<= xobj
->value3
)))
126 xobj
->value
= xobj
->value2
;
128 i
= (xobj
->Ffont
->height
)*2+30;
129 if (xobj
->height
< i
)
131 sprintf(str
, "%d", xobj
->value2
);
132 i
= FlocaleTextWidth(xobj
->Ffont
, str
, strlen(str
));
133 sprintf(str
, "%d", xobj
->value3
);
134 j
= FlocaleTextWidth(xobj
->Ffont
, str
, strlen(str
));
140 XResizeWindow(dpy
, xobj
->win
, xobj
->width
, xobj
->height
);
141 if (xobj
->colorset
>= 0)
142 SetWindowBackground(dpy
, xobj
->win
, xobj
->width
, xobj
->height
,
143 &Colorset
[xobj
->colorset
], Pdepth
,
145 XSelectInput(dpy
, xobj
->win
, ExposureMask
);
148 void DestroyVScrollBar(struct XObj
*xobj
)
150 FlocaleUnloadFont(dpy
,xobj
->Ffont
);
151 XFreeGC(dpy
,xobj
->gc
);
152 XDestroyWindow(dpy
,xobj
->win
);
155 void DrawVScrollBar(struct XObj
*xobj
, XEvent
*evp
)
160 /* Calcul de la taille de l'ascenseur */
161 x
= xobj
->width
/2 - 12;
165 DrawThumbV(xobj
, evp
);
166 DrawReliefRect(x
, y
, w
, h
, xobj
, shad
, hili
);
167 /* Ecriture des valeurs */
169 y
= xobj
->Ffont
->ascent
+ 2;
170 sprintf(str
, "%d", xobj
->value3
);
171 MyDrawString(dpy
, xobj
, xobj
->win
, x
, y
, str
, fore
, hili
, back
,
172 !xobj
->flags
[1], NULL
, evp
);
173 sprintf(str
, "%d", xobj
->value2
);
174 y
= h
- xobj
->Ffont
->descent
- 2;
175 MyDrawString(dpy
, xobj
, xobj
->win
, x
, y
, str
, fore
, hili
, back
,
176 !xobj
->flags
[1], NULL
, evp
);
179 void EvtMouseVScrollBar(struct XObj
*xobj
, XButtonEvent
*EvtButton
)
192 /* On suit les mouvements de la souris */
193 FQueryPointer(dpy
, *xobj
->ParentWin
, &Win1
, &Win2
,
194 &x1
, &y1
, &x2
, &y2
, &modif
);
198 if (y2
> xobj
->height
- 21)
199 y2
= xobj
->height
- 21;
203 /* calcule de xobj->value */
204 newvalue
= (y2
-15)*xobj
->height
/(xobj
->height
- 36) *
205 (xobj
->value2
- xobj
->value3
) /
206 (xobj
->height
) + xobj
->value3
;
207 if (newvalue
!=oldvalue
)
210 xobj
->value
= newvalue
;
211 DrawThumbV(xobj
, NULL
);
213 SendMsg(xobj
,SingleClic
);
219 FD_SET(x_fd
, &in_fdset
);
220 select(32, SELECT_FD_SET_CAST
&in_fdset
, NULL
, NULL
, NULL
);
222 while (!FCheckTypedEvent(dpy
, ButtonRelease
, &event
) &&
226 void EvtKeyVScrollBar(struct XObj
*xobj
, XKeyEvent
*EvtKey
)
229 unsigned char buf
[10];
231 XLookupString(EvtKey
, (char *)buf
, sizeof(buf
), &ks
, NULL
);
232 if (ks
== XK_Down
&& xobj
->value
> 0) {
235 DrawThumbV(xobj
, NULL
);
236 SendMsg(xobj
,SingleClic
);
238 else if (ks
== XK_Up
&&
240 xobj
->width
*(xobj
->value3
-xobj
->value2
) /
241 (xobj
->width
)+xobj
->value2
) {
244 DrawThumbV(xobj
, NULL
);
245 SendMsg(xobj
,SingleClic
);
247 else if (ks
== XK_Return
) {
248 EvtMouseVScrollBar(xobj
, NULL
);
252 void ProcessMsgVScrollBar(
253 struct XObj
*xobj
,unsigned long type
,unsigned long *body
)