Restructure how we look for Read files slightly.
[fvwm.git] / modules / FvwmScript / Widgets / Tools.c
blob02221dff8321957c5b492319d7030727eaabb01f
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 "Tools.h"
21 /* helper functions */
22 /* get byte offset corresponding to character offset, including
23 bounds check to represent end of text */
24 int getByteOffsetBoundsCheck(FlocaleFont *flf, char *str, int offset)
26 if(offset < FlocaleStringCharLength(flf,str))
27 return FlocaleStringCharToByteOffset(flf, str, offset);
28 else
29 return strlen(str);
32 /* opposite of the above, return character offset */
33 int getCharOffsetBoundsCheck(FlocaleFont *flf, char *str, int offset)
35 if(offset < strlen(str))
36 return FlocaleStringByteToCharOffset(flf, str, offset);
37 else
38 return FlocaleStringCharLength(flf, str);
42 * Fonction d'ecriture en relief
44 void MyDrawString(
45 Display *dpy, struct XObj *xobj, Window win, int x, int y,
46 char *str, unsigned long ForeC,unsigned long HiC,
47 unsigned long BackC, int WithRelief, XRectangle *clip, XEvent *evp)
49 Region region = None;
50 XRectangle inter;
51 Bool do_draw = True;
53 if (evp && clip)
55 if (!frect_get_intersection(
56 clip->x, clip->y, clip->width, clip->height,
57 evp->xexpose.x, evp->xexpose.y,
58 evp->xexpose.width, evp->xexpose.height,
59 &inter))
61 do_draw = False;
64 else if (clip)
66 inter.x = clip->x;
67 inter.y = clip->y;
68 inter.width = clip->width;
69 inter.height = clip->height;
71 else if (evp)
73 inter.x = evp->xexpose.x;
74 inter.y = evp->xexpose.y;
75 inter.width = evp->xexpose.width;
76 inter.height = evp->xexpose.height;
78 if (!do_draw)
80 return;
82 if (clip || evp)
84 region = XCreateRegion();
85 XUnionRectWithRegion (&inter, region, region);
86 XSetClipRectangles(dpy, xobj->gc, 0, 0, &inter, 1, Unsorted);
87 FwinString->flags.has_clip_region = True;
88 FwinString->clip_region = region;
90 else
92 FwinString->flags.has_clip_region = False;
95 FwinString->win = win;
96 FwinString->str = str;
97 FwinString->gc = xobj->gc;
98 FwinString->flags.has_colorset = False;
99 if (xobj->colorset >= 0)
101 FwinString->colorset = &Colorset[xobj->colorset];
102 FwinString->flags.has_colorset = True;
104 if (WithRelief && xobj->Ffont->shadow_size == 0)
106 XSetBackground(dpy, xobj->gc, xobj->TabColor[BackC]);
107 XSetForeground(dpy, xobj->gc, xobj->TabColor[HiC]);
108 FwinString->x = x+1;
109 FwinString->y = y+1;
110 FlocaleDrawString(dpy, xobj->Ffont, FwinString, 0);
111 XSetForeground(dpy, xobj->gc, xobj->TabColor[ForeC]);
112 FwinString->x = x;
113 FwinString->y = y;
114 FlocaleDrawString(dpy, xobj->Ffont, FwinString, 0);
116 else
118 XSetBackground(dpy, xobj->gc, xobj->TabColor[BackC]);
119 XSetForeground(dpy, xobj->gc, xobj->TabColor[ForeC]);
120 FwinString->x = x;
121 FwinString->y = y+1;
122 FlocaleDrawString(dpy, xobj->Ffont, FwinString, 0);
124 if (region)
126 XDestroyRegion(region);
127 XSetClipMask(dpy, xobj->gc, None);
129 FwinString->flags.has_clip_region = False;
133 * Return the x text position of the widget
135 int GetXTextPosition(struct XObj *xobj, int obj_width, int str_len,
136 int left_offset, int center_offset, int right_offset)
138 int position;
139 int x;
141 if (!IS_TEXT_POS_DEFAULT(xobj))
143 position = GET_TEXT_POS(xobj);
145 else
147 switch (xobj->TypeWidget)
149 case ItemDraw:
150 case PushButton:
151 position = TEXT_POS_CENTER;
152 break;
153 default:
154 position = TEXT_POS_LEFT;
155 break;
159 if (position == TEXT_POS_CENTER)
161 x = (obj_width - str_len)/2 + center_offset;
163 else if (position == TEXT_POS_LEFT)
165 x = left_offset;
167 else /* position == TEXT_POS_RIGHT */
169 x = (obj_width - str_len) - right_offset;
171 return x;
175 * Retourne le titre de l'option id du menu
177 char* GetMenuTitle(char *str, int id)
179 int i=1;
180 int w=0;
181 int w2=0;
182 char* TempStr;
184 while ((str[w+w2] != '\0') && (str[w+w2] != '|'))
185 w2++;
187 while ((i < id) && (str[w] != '\0'))
189 i++;
190 if (str[w+w2] == '|')
191 w2++;
192 w = w+w2;
193 w2 = 0;
194 while ((str[w+w2] != '\0') && (str[w+w2] != '|'))
195 w2++;
197 TempStr = (char*)calloc(sizeof(char),w2+1);
198 TempStr = strncpy(TempStr,&str[w],w2);
199 return TempStr;
203 * Dessine le contenu de la fenetre du popup-menu
205 void DrawPMenu(struct XObj *xobj, Window WinPop, int h, int StrtOpt)
207 XSegment segm[2];
208 unsigned int i;
209 int x,y;
210 unsigned int width,height;
211 Window Root;
213 if (!XGetGeometry(dpy, WinPop, &Root, &x, &y, &width, &height, &i, &i))
214 return;
215 for (i=0; i<2; i++)
217 segm[0].x1 = i;
218 segm[0].y1 = i;
219 segm[0].x2 = width-i-1;
220 segm[0].y2 = i;
222 segm[1].x1 = i;
223 segm[1].y1 = i;
224 segm[1].x2 = i;
225 segm[1].y2 = height-i-1;
226 XSetForeground(dpy, xobj->gc, xobj->TabColor[hili]);
227 XDrawSegments(dpy, WinPop, xobj->gc, segm, 2);
229 segm[0].x1 = 1+i;
230 segm[0].y1 = height-i-1;
231 segm[0].x2 = width-i-1;
232 segm[0].y2 = height-i-1;
234 segm[1].x1 = width-i-1;
235 segm[1].y1 = i;
236 segm[1].x2 = width-i-1;
237 segm[1].y2 = height-i-1;
238 XSetForeground(dpy, xobj->gc, xobj->TabColor[shad]);
239 XDrawSegments(dpy, WinPop, xobj->gc, segm, 2);
241 /* Ecriture des options */
242 for (i=StrtOpt; i <= xobj->value3; i++)
243 UnselectMenu(
244 xobj, WinPop, h, i, width, xobj->Ffont->ascent, StrtOpt);
247 void UnselectMenu(struct XObj *xobj, Window WinPop, int hOpt, int value,
248 unsigned int width, int asc, int start)
250 int y,x,len;
251 char *str;
253 y = hOpt * (value - 1);
254 XClearArea(dpy, WinPop, 2, y + 2, width - 4, hOpt - 4, False);
255 str = (char*)GetMenuTitle(xobj->title, value + start);
256 y += asc + 4;
257 len = strlen(str);
258 x = GetXTextPosition(xobj, width, FlocaleTextWidth(xobj->Ffont,str,len),
259 8, 0, 8);
260 MyDrawString(dpy, xobj, WinPop, x, y, str, fore, hili, back,
261 !xobj->flags[1], NULL, NULL);
262 free(str);
266 * Dessine l'option active d'un menu
268 void SelectMenu(struct XObj *xobj, Window WinPop, int hOpt, int value)
270 XSegment segm[2];
271 unsigned int i;
272 int x,y;
273 unsigned int width,height;
274 Window Root;
276 if (!XGetGeometry(dpy, WinPop, &Root, &x, &y, &width, &height, &i, &i))
277 return;
278 y = hOpt*(value-1);
279 for (i=0; i<2; i++)
281 segm[0].x1 = i+2;
282 segm[0].y1 = i+y+2;
283 segm[0].x2 = width-i-3;
284 segm[0].y2 = i+y+2;
286 segm[1].x1 = i+2;
287 segm[1].y1 = i+y+2;
288 segm[1].x2 = i+2;
289 segm[1].y2 = y+hOpt-4-i;
290 XSetForeground(dpy, xobj->gc, xobj->TabColor[hili]);
291 XDrawSegments(dpy, WinPop, xobj->gc, segm, 2);
293 segm[0].x1 = i+3;
294 segm[0].y1 = y-i-3+hOpt;
295 segm[0].x2 = width-i-3;
296 segm[0].y2 = y-i-3+hOpt;
298 segm[1].x1 = width-i-3;
299 segm[1].y1 = i+y+2;
300 segm[1].x2 = width-i-3;
301 segm[1].y2 = i+y-4+hOpt;
302 XSetForeground(dpy, xobj->gc, xobj->TabColor[shad]);
303 XDrawSegments(dpy, WinPop, xobj->gc, segm, 2);
308 * Compte le nombre d'option contenu dans un menu
310 int CountOption(char *str)
312 int i=1;
313 int w=0;
315 while (str[w] != '\0')
317 if (str[w] == '|') i++;
318 w++;
321 return i;
326 * Dessine l'icone et le titre du widget
328 void DrawIconStr(
329 int offset, struct XObj *xobj, int DoRedraw,
330 int l_offset, int c_offset, int r_offset,
331 XRectangle *str_clip, XRectangle *icon_clip, XEvent *evp)
333 int i,j;
334 char *str;
335 int len = 0;
336 XRectangle clear_r, inter;
337 Bool do_clear = True;
339 inter.x = clear_r.x = 4;
340 inter.y = clear_r.y = 4;
341 inter.width = clear_r.width = xobj->width-8;
342 inter.height = clear_r.height = xobj->height-8;
344 if (evp)
346 if (!frect_get_intersection(
347 clear_r.x, clear_r.y, clear_r.width,
348 clear_r.height, evp->xexpose.x, evp->xexpose.y,
349 evp->xexpose.width, evp->xexpose.height,
350 &inter))
352 do_clear = False;
355 #if 0
356 else if (clip)
358 inter.x = clip->x;
359 inter.y = clip->y;
360 inter.width = clip->width;
361 inter.height = clip->height;
363 else if (evp)
365 inter.x = evp->xexpose.x;
366 inter.y = evp->xexpose.y;
367 inter.width = evp->xexpose.width;
368 inter.height = evp->xexpose.height;
370 #endif
371 if (DoRedraw && do_clear)
373 XClearArea(
374 dpy, xobj->win,
375 inter.x, inter.y, inter.width, inter.height, False);
378 str = GetMenuTitle(xobj->title,1);
379 len = strlen(str);
380 i = GetXTextPosition(
381 xobj, xobj->width, FlocaleTextWidth(xobj->Ffont,str,len),
382 l_offset, c_offset, r_offset);
384 if (len > 0 && xobj->iconPixmap==None)
386 /* Si l'icone n'existe pas */
387 j = xobj->height/2 - (xobj->Ffont->height)/2 +
388 xobj->Ffont->ascent + offset;
389 MyDrawString(
390 dpy,xobj,xobj->win,i,j,str,fore,hili,back,
391 !xobj->flags[1], str_clip, evp);
393 else
395 /* Si l'icone existe */
396 FvwmRenderAttributes fra;
397 Bool do_draw_icon = True;
398 XRectangle ir;
399 int iy = (xobj->height - xobj->icon_h)/2+offset;
400 int ix = (xobj->width - xobj->icon_w)/2+offset;
402 if (evp && icon_clip)
404 if (!frect_get_intersection(
405 icon_clip->x, icon_clip->y,
406 icon_clip->width, icon_clip->height,
407 evp->xexpose.x, evp->xexpose.y,
408 evp->xexpose.width, evp->xexpose.height,
409 &inter))
411 do_draw_icon = False;
413 else if (!frect_get_intersection(
414 inter.x, inter.y,
415 inter.width, inter.height,
416 ix, iy, xobj->icon_w, xobj->icon_h,
417 &ir))
419 do_draw_icon = False;
422 else if (icon_clip)
424 if (!frect_get_intersection(
425 icon_clip->x, icon_clip->y,
426 icon_clip->width, icon_clip->height,
427 ix, iy, xobj->icon_w, xobj->icon_h,
428 &ir))
430 do_draw_icon = False;
433 else if (evp)
435 if (!frect_get_intersection(
436 evp->xexpose.x, evp->xexpose.y,
437 evp->xexpose.width, evp->xexpose.height,
438 ix, iy, xobj->icon_w, xobj->icon_h,
439 &ir))
441 do_draw_icon = False;
444 else
446 ir.x = ix;
447 ir.y = iy;
448 ir.width = xobj->icon_w;
449 ir.height = xobj->icon_h;
452 if (len > 0)
454 j = ((xobj->height - xobj->icon_h)/4)*3 +
455 xobj->icon_h + offset + xobj->Ffont->ascent;
456 MyDrawString(
457 dpy,xobj,xobj->win,i,j,str,fore,hili,
458 back,!xobj->flags[1], str_clip, evp);
460 /* Dessin de l'icone */
461 fra.mask = FRAM_DEST_IS_A_WINDOW;
462 if (xobj->colorset >= 0)
464 fra.mask |= FRAM_HAVE_ICON_CSET;
465 fra.colorset = &Colorset[xobj->colorset];
467 if (do_draw_icon)
469 PGraphicsRenderPixmaps(
470 dpy, xobj->win, xobj->iconPixmap,
471 xobj->icon_maskPixmap, xobj->icon_alphaPixmap,
472 Pdepth, &fra, xobj->win, xobj->gc, None, None,
473 ir.x - ix, ir.y - iy, ir.width, ir.height,
474 ir.x, ir.y, ir.width, ir.height, False);
477 free(str);
481 * Fonction de dessin d'un rectangle en relief
483 void DrawReliefRect(int x, int y, int width, int height, struct XObj *xobj,
484 unsigned int LiC, unsigned int ShadC)
486 XSegment segm[2];
487 int i;
488 int j;
490 width--;
491 height--;
493 for (i=0; i<2; i++)
495 j = -1-i;
496 segm[0].x1 = i+x;
497 segm[0].y1 = i+y;
498 segm[0].x2 = i+x;
499 segm[0].y2 = height+j+y+1;
500 segm[1].x1 = i+x;
501 segm[1].y1 = i+y;
502 segm[1].x2 = width+j+x+1;
503 segm[1].y2 = i+y;
504 XSetForeground(dpy, xobj->gc, xobj->TabColor[LiC]);
505 XDrawSegments(dpy, xobj->win, xobj->gc, segm, 2);
507 segm[0].x1 = width+j+x+1;
508 segm[0].y1 = i+1+y;
509 segm[0].x2 = width+j+x+1;
510 segm[0].y2 = height+j+y+1;
511 segm[1].x1 = i+1+x;
512 segm[1].y1 = height+j+y+1;
513 segm[1].x2 = width+j+x+1;
514 segm[1].y2 = height+j+y+1;
515 XSetForeground(dpy, xobj->gc, xobj->TabColor[ShadC]);
516 XDrawSegments(dpy, xobj->win, xobj->gc, segm, 2);
518 XSetForeground(dpy, xobj->gc, xobj->TabColor[fore]);
522 * Insertion d'un str dans le titre d'un objet
524 int InsertText(struct XObj *xobj, char *str, int SizeStr)
526 int Size;
527 int NewPos;
528 int i;
530 /* Insertion du caractere dans le titre */
531 NewPos = getByteOffsetBoundsCheck(xobj->Ffont, xobj->title,
532 xobj->value);
533 Size = strlen(xobj->title);
534 xobj->title = (char*)realloc(
535 xobj->title, (1+SizeStr+Size)*sizeof(char));
536 memmove(&xobj->title[NewPos+SizeStr], &xobj->title[NewPos],
537 Size-NewPos+1);
538 for (i=NewPos; i < NewPos+SizeStr; i++)
539 xobj->title[i] = str[i-NewPos];
540 NewPos = NewPos+SizeStr;
541 return getCharOffsetBoundsCheck(xobj->Ffont, xobj->title, NewPos);
545 * Lecture d'un morceau de texte de xobj->value à End
547 char *GetText(struct XObj *xobj, int End)
549 char *str;
550 int a,b;
552 if (End > xobj->value)
554 a = getByteOffsetBoundsCheck(xobj->Ffont, xobj->title,
555 xobj->value);
556 b = getByteOffsetBoundsCheck(xobj->Ffont, xobj->title,
557 End);
559 else
561 b = getByteOffsetBoundsCheck(xobj->Ffont, xobj->title,
562 xobj->value);
563 a = getByteOffsetBoundsCheck(xobj->Ffont, xobj->title,
564 End);
566 str = (char*)calloc(b-a+2,1);
567 memcpy(str, &xobj->title[a], b-a);
568 str[b-a+1] = '\0';
569 return str;
572 void UnselectAllTextField(struct XObj **txobj)
574 int i;
576 for (i=0; i<nbobj; i++)
578 if (txobj[i]->TypeWidget == TextField)
580 if (txobj[i]->value2 != txobj[i]->value)
582 txobj[i]->value2 = txobj[i]->value;
583 txobj[i]->DrawObj(txobj[i],NULL);
584 return;
590 void SelectOneTextField(struct XObj *xobj)
592 int i;
594 for (i=0; i<nbobj; i++)
596 if ((tabxobj[i]->TypeWidget == TextField) &&
597 (xobj != tabxobj[i]))
599 if (tabxobj[i]->value2 != tabxobj[i]->value)
601 tabxobj[i]->value2 = tabxobj[i]->value;
602 tabxobj[i]->DrawObj(tabxobj[i],NULL);
603 return;
610 * Dessine une fleche direction nord
612 void DrawArrowN(struct XObj *xobj, int x, int y, int Press)
614 XSegment segm[4];
616 segm[0].x1 = 5+x;
617 segm[0].y1 = 1+y;
618 segm[0].x2 = 0+x;
619 segm[0].y2 = 12+y;
620 segm[1].x1 = 5+x;
621 segm[1].y1 = 3+y;
622 segm[1].x2 = 1+x;
623 segm[1].y2 = 12+y;
624 if (Press == 1)
625 XSetForeground(dpy, xobj->gc, xobj->TabColor[shad]);
626 else
627 XSetForeground(dpy, xobj->gc, xobj->TabColor[hili]);
628 XDrawSegments(dpy, xobj->win, xobj->gc, segm, 2);
630 segm[0].x1 = 2+x;
631 segm[0].y1 = 11+y;
632 segm[0].x2 = 11+x;
633 segm[0].y2 = 11+y;
634 segm[1].x1 = 1+x;
635 segm[1].y1 = 12+y;
636 segm[1].x2 = 12+x;
637 segm[1].y2 = 12+y;
639 segm[2].x1 = 6+x;
640 segm[2].y1 = 0+y;
641 segm[2].x2 = 12+x;
642 segm[2].y2 = 12+y;
643 segm[3].x1 = 6+x;
644 segm[3].y1 = 2+y;
645 segm[3].x2 = 10+x;
646 segm[3].y2 = 11+y;
647 if (Press == 1)
648 XSetForeground(dpy, xobj->gc, xobj->TabColor[hili]);
649 else
650 XSetForeground(dpy, xobj->gc, xobj->TabColor[shad]);
651 XDrawSegments(dpy, xobj->win, xobj->gc, segm, 4);
655 * Dessine une fleche direction sud
657 void DrawArrowS(struct XObj *xobj, int x, int y, int Press)
659 XSegment segm[4];
661 segm[0].x1 = 0+x;
662 segm[0].y1 = 0+y;
663 segm[0].x2 = 12+x;
664 segm[0].y2 = 0+y;
665 segm[1].x1 = 1+x;
666 segm[1].y1 = 1+y;
667 segm[1].x2 = 11+x;
668 segm[1].y2 = 1+y;
670 segm[2].x1 = 1+x;
671 segm[2].y1 = 1+y;
672 segm[2].x2 = 5+x;
673 segm[2].y2 = 10+y;
674 segm[3].x1 = 2+x;
675 segm[3].y1 = 1+y;
676 segm[3].x2 = 5+x;
677 segm[3].y2 = 8+y;
678 if (Press == 1)
679 XSetForeground(dpy, xobj->gc, xobj->TabColor[shad]);
680 else
681 XSetForeground(dpy, xobj->gc, xobj->TabColor[hili]);
682 XDrawSegments(dpy, xobj->win, xobj->gc, segm, 4);
684 segm[0].x1 = 6+x;
685 segm[0].y1 = 11+y;
686 segm[0].x2 = 12+x;
687 segm[0].y2 = 1+y;
688 segm[1].x1 = 6+x;
689 segm[1].y1 = 10+y;
690 segm[1].x2 = 10+x;
691 segm[1].y2 = 2+y;
692 if (Press == 1)
693 XSetForeground(dpy, xobj->gc, xobj->TabColor[hili]);
694 else
695 XSetForeground(dpy, xobj->gc, xobj->TabColor[shad]);
696 XDrawSegments(dpy, xobj->win, xobj->gc, segm, 2);
699 void DrawArrowE(struct XObj *xobj, int x, int y, int Press)
701 XSegment segm[4];
703 segm[0].x1 = 12+x;
704 segm[0].y1 = 6+y;
705 segm[0].x2 = 1+x;
706 segm[0].y2 = 12+y;
707 segm[1].x1 = 10+x;
708 segm[1].y1 = 6+y;
709 segm[1].x2 = 2+x;
710 segm[1].y2 = 10+y;
711 if (Press == 1)
712 XSetForeground(dpy, xobj->gc, xobj->TabColor[hili]);
713 else
714 XSetForeground(dpy, xobj->gc, xobj->TabColor[shad]);
715 XDrawSegments(dpy, xobj->win, xobj->gc, segm, 2);
717 segm[0].x1 = 0+x;
718 segm[0].y1 = 0+y;
719 segm[0].x2 = 0+x;
720 segm[0].y2 = 12+y;
721 segm[1].x1 = 1+x;
722 segm[1].y1 = 0+y;
723 segm[1].x2 = 1+x;
724 segm[1].y2 = 11+y;
726 segm[2].x1 = 0+x;
727 segm[2].y1 = 0+y;
728 segm[2].x2 = 11+x;
729 segm[2].y2 = 5+y;
730 segm[3].x1 = 0+x;
731 segm[3].y1 = 1+y;
732 segm[3].x2 = 9+x;
733 segm[3].y2 = 5+y;
734 if (Press == 1)
735 XSetForeground(dpy, xobj->gc, xobj->TabColor[shad]);
736 else
737 XSetForeground(dpy, xobj->gc, xobj->TabColor[hili]);
738 XDrawSegments(dpy, xobj->win, xobj->gc, segm, 4);
741 void DrawArrowW(struct XObj *xobj, int x, int y, int Press)
743 XSegment segm[4];
745 segm[0].x1 = 2+x;
746 segm[0].y1 = 5+y;
747 segm[0].x2 = 12+x;
748 segm[0].y2 = 0+y;
749 segm[1].x1 = 4+x;
750 segm[1].y1 = 5+y;
751 segm[1].x2 = 10+x;
752 segm[1].y2 = 2+y;
753 if (Press == 1)
754 XSetForeground(dpy, xobj->gc, xobj->TabColor[shad]);
755 else
756 XSetForeground(dpy, xobj->gc, xobj->TabColor[hili]);
757 XDrawSegments(dpy, xobj->win, xobj->gc, segm, 2);
759 segm[0].x1 = 0+x;
760 segm[0].y1 = 6+y;
761 segm[0].x2 = 12+x;
762 segm[0].y2 = 12+y;
763 segm[1].x1 = 2+x;
764 segm[1].y1 = 6+y;
765 segm[1].x2 = 11+x;
766 segm[1].y2 = 10+y;
768 segm[2].x1 = 12+x;
769 segm[2].y1 = 1+y;
770 segm[2].x2 = 12+x;
771 segm[2].y2 = 12+y;
772 segm[3].x1 = 11+x;
773 segm[3].y1 = 2+y;
774 segm[3].x2 = 11+x;
775 segm[3].y2 = 11+y;
776 if (Press == 1)
777 XSetForeground(dpy, xobj->gc, xobj->TabColor[hili]);
778 else
779 XSetForeground(dpy, xobj->gc, xobj->TabColor[shad]);
780 XDrawSegments(dpy, xobj->win, xobj->gc, segm, 4);
783 int PtInRect(XPoint pt, XRectangle rect)
785 return ((pt.x >= rect.x) && (pt.y >= rect.y) &&
786 (pt.x <= rect.x+rect.width) && (pt.y <= rect.y+rect.height));
789 /* Arret pendant t*1/60 de secondes */
790 void Wait(int t)
792 struct timeval *tv;
793 long tus,ts;
795 tv = (struct timeval*)calloc(1,sizeof(struct timeval));
796 gettimeofday(tv,NULL);
797 tus = tv->tv_usec;
798 ts = tv->tv_sec;
799 while (((tv->tv_usec-tus)+(tv->tv_sec-ts)*1000000) < 16667*t)
800 gettimeofday(tv,NULL);
801 free(tv);
804 int IsItDoubleClic(struct XObj *xobj)
806 XEvent Event;
807 XFlush(dpy);
808 Wait(12);
809 return (FCheckTypedEvent(dpy, ButtonPress, &Event));