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 HScrollBar
27 void DrawThumbH(struct XObj
*xobj
, XEvent
*evp
)
34 (xobj
->width
- 36)*(xobj
->value
- xobj
->value2
) /
35 (xobj
->value3
- xobj
->value2
);
36 y
= xobj
->height
/2 - 11;
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
+ 15 - (FlocaleTextWidth(xobj
->Ffont
, str
, strlen(str
)) / 2);
56 y
= y
- xobj
->Ffont
->descent
- 4;
57 MyDrawString(dpy
, xobj
, xobj
->win
, x
, y
, str
, fore
, hili
, back
,
58 !xobj
->flags
[1], NULL
, evp
);
61 void HideThumbH(struct XObj
*xobj
)
66 (xobj
->width
- 36) * (xobj
->value
- xobj
->value2
) /
67 (xobj
->value3
-xobj
->value2
);
68 y
= xobj
->height
/2 - 11;
69 XClearArea(dpy
, xobj
->win
, x
, y
, 32, 22, False
);
71 XClearArea(dpy
, xobj
->win
, 0, 0, xobj
->width
, xobj
->height
/2-15, False
);
74 void InitHScrollBar(struct XObj
*xobj
)
77 XSetWindowAttributes Attr
;
81 /* Enregistrement des couleurs et de la police */
82 if (xobj
->colorset
>= 0) {
83 xobj
->TabColor
[fore
] = Colorset
[xobj
->colorset
].fg
;
84 xobj
->TabColor
[back
] = Colorset
[xobj
->colorset
].bg
;
85 xobj
->TabColor
[hili
] = Colorset
[xobj
->colorset
].hilite
;
86 xobj
->TabColor
[shad
] = Colorset
[xobj
->colorset
].shadow
;
88 xobj
->TabColor
[fore
] = GetColor(xobj
->forecolor
);
89 xobj
->TabColor
[back
] = GetColor(xobj
->backcolor
);
90 xobj
->TabColor
[hili
] = GetColor(xobj
->hilicolor
);
91 xobj
->TabColor
[shad
] = GetColor(xobj
->shadcolor
);
95 Attr
.background_pixel
= xobj
->TabColor
[back
];
97 Attr
.cursor
= XCreateFontCursor(dpy
,XC_hand2
);
98 mask
|= CWCursor
; /* Curseur pour la fenetre */
100 xobj
->win
= XCreateWindow(dpy
, *xobj
->ParentWin
,
101 xobj
->x
, xobj
->y
, xobj
->width
, xobj
->height
, 0,
102 CopyFromParent
, InputOutput
, CopyFromParent
,
104 xobj
->gc
= fvwmlib_XCreateGC(dpy
, xobj
->win
, 0, NULL
);
105 XSetForeground(dpy
, xobj
->gc
, xobj
->TabColor
[fore
]);
106 XSetBackground(dpy
, xobj
->gc
, xobj
->TabColor
[back
]);
108 if ((xobj
->Ffont
= FlocaleLoadFont(dpy
, xobj
->font
, ScriptName
)) == NULL
)
110 fprintf(stderr
, "%s: Couldn't load font. Exiting!\n", ScriptName
);
113 if (xobj
->Ffont
->font
!= NULL
)
114 XSetFont(dpy
, xobj
->gc
, xobj
->Ffont
->font
->fid
);
116 XSetLineAttributes(dpy
, xobj
->gc
, 1, LineSolid
, CapRound
, JoinMiter
);
118 if ((xobj
->value3
- xobj
->value2
) <= 0)
119 xobj
->value3
= xobj
->value2
+ 10;
120 if (!((xobj
->value
>= xobj
->value2
) && (xobj
->value
<= xobj
->value3
)))
121 xobj
->value
= xobj
->value2
;
122 xobj
->height
= xobj
->Ffont
->height
* 2 + 30;
123 sprintf(str
, "%d", xobj
->value2
);
124 i
= FlocaleTextWidth(xobj
->Ffont
, str
, strlen(str
));
125 sprintf(str
, "%d", xobj
->value3
);
126 i
= FlocaleTextWidth(xobj
->Ffont
, str
, strlen(str
)) + i
+ 20;
129 XResizeWindow(dpy
, xobj
->win
, xobj
->width
, xobj
->height
);
130 if (xobj
->colorset
>= 0)
131 SetWindowBackground(dpy
, xobj
->win
, xobj
->width
, xobj
->height
,
132 &Colorset
[xobj
->colorset
], Pdepth
,
134 XSelectInput(dpy
, xobj
->win
, ExposureMask
);
137 void DestroyHScrollBar(struct XObj
*xobj
)
139 FlocaleUnloadFont(dpy
,xobj
->Ffont
);
140 XFreeGC(dpy
,xobj
->gc
);
141 XDestroyWindow(dpy
,xobj
->win
);
144 void DrawHScrollBar(struct XObj
*xobj
, XEvent
*evp
)
149 /* Calcul de la taille de l'ascenseur */
151 y
= xobj
->height
/2-13;
154 DrawThumbH(xobj
, evp
);
155 DrawReliefRect(x
, y
, w
, h
, xobj
, shad
, hili
);
156 /* Ecriture des valeurs */
157 sprintf(str
, "%d", xobj
->value2
);
159 y
= y
+ xobj
->Ffont
->ascent
+ h
;
160 MyDrawString(dpy
, xobj
, xobj
->win
, x
, y
, str
, fore
, hili
, back
,
161 !xobj
->flags
[1], NULL
, evp
);
162 sprintf(str
, "%d", xobj
->value3
);
163 x
= w
- FlocaleTextWidth(xobj
->Ffont
, str
, strlen(str
)) - 4;
164 MyDrawString(dpy
, xobj
, xobj
->win
, x
, y
, str
, fore
, hili
, back
,
165 !xobj
->flags
[1], NULL
, evp
);
168 void EvtMouseHScrollBar(struct XObj
*xobj
, XButtonEvent
*EvtButton
)
180 x
= 2 + ((xobj
->width
- 36) * xobj
->value
) / (xobj
->value3
- xobj
->value2
);
181 y
= xobj
->height
/2 - 11;
187 /* On suit les mouvements de la souris */
188 FQueryPointer(dpy
, *xobj
->ParentWin
, &Win1
, &Win2
, &x1
, &y1
, &x2
, &y2
, &modif
);
192 if (x2
> xobj
->width
-21)
193 x2
= xobj
->width
- 21;
197 /* calcule de xobj->value */
198 newvalue
= (x2
-15)*xobj
->width
/ (xobj
->width
- 36) *
199 (xobj
->value3
- xobj
->value2
) / (xobj
->width
) + xobj
->value2
;
200 if (newvalue
!=oldvalue
)
203 xobj
->value
= newvalue
;
204 DrawThumbH(xobj
, NULL
);
206 SendMsg(xobj
,SingleClic
);
212 FD_SET(x_fd
, &in_fdset
);
213 select(32, SELECT_FD_SET_CAST
&in_fdset
, NULL
, NULL
, NULL
);
215 while (!FCheckTypedEvent(dpy
, ButtonRelease
, &event
) && EvtButton
!= NULL
);
218 void EvtKeyHScrollBar(struct XObj
*xobj
, XKeyEvent
*EvtKey
)
221 unsigned char buf
[10];
223 XLookupString(EvtKey
, (char *)buf
, sizeof(buf
), &ks
, NULL
);
224 if (ks
== XK_Left
&& xobj
->value
> 0) {
227 DrawThumbH(xobj
, NULL
);
228 SendMsg(xobj
,SingleClic
);
230 else if (ks
== XK_Right
&&
232 xobj
->width
*(xobj
->value3
-xobj
->value2
)/(xobj
->width
) + xobj
->value2
) {
235 DrawThumbH(xobj
, NULL
);
236 SendMsg(xobj
,SingleClic
);
238 else if (ks
== XK_Return
) {
239 EvtMouseHScrollBar(xobj
, NULL
);
243 void ProcessMsgHScrollBar(struct XObj
*xobj
,unsigned long type
,unsigned long *body
)