void DrawList(struct XObj *xobj) { int asc,desc,dir,HeightCell; XCharStruct struc; int NbVisCell,NbCell; XRectangle r; /* Dessin du contour */ DrawReliefRect(0,0,xobj->width,xobj->height,xobj, xobj->TabColor[li].pixel,xobj->TabColor[shad].pixel,xobj->TabColor[fore].pixel,-1); /* Dessin du contour de la liste */ r.x=2+BdWidth; r.y=r.x; r.width=xobj->width-r.x-4-2*BdWidth-SbWidth; r.height=xobj->height-r.y-2*BdWidth; DrawReliefRect(r.x,r.y,r.width,r.height,xobj,xobj->TabColor[shad].pixel, xobj->TabColor[li].pixel,xobj->TabColor[fore].pixel,-1); /* Calcul du nombre de cellules visibles */ XTextExtents(xobj->xfont,"lp",strlen("lp"),&dir,&asc,&desc,&struc); HeightCell=asc+desc+3; NbVisCell=r.height/HeightCell; NbCell=CountOption(xobj->title); if (NbCell>NbVisCell) { if (xobj->value2>(NbCell-NbVisCell+1)) xobj->value2=NbCell-NbVisCell+1; if ((xobj->value2<1)||(xobj->value2<0)) xobj->value2=1; } else xobj->value2=1; /* Dessin des cellules */ DrawCellule(xobj,NbCell,NbVisCell,HeightCell,asc); /* Dessin de l'ascenseur vertical */ DrawVSbList(xobj,NbCell,NbVisCell,0); }
void InitPopupMenu(struct XObj *xobj) { unsigned long mask; XSetWindowAttributes Attr; int i; char *str; /* Enregistrement des couleurs et de la police / set the colors and the font */ if (xobj->colorset >= 0) { xobj->TabColor[fore] = Colorset[xobj->colorset].fg; xobj->TabColor[back] = Colorset[xobj->colorset].bg; xobj->TabColor[hili] = Colorset[xobj->colorset].hilite; xobj->TabColor[shad] = Colorset[xobj->colorset].shadow; } else { xobj->TabColor[fore] = GetColor(xobj->forecolor); xobj->TabColor[back] = GetColor(xobj->backcolor); xobj->TabColor[hili] = GetColor(xobj->hilicolor); xobj->TabColor[shad] = GetColor(xobj->shadcolor); } mask = 0; Attr.background_pixel = xobj->TabColor[back]; mask |= CWBackPixel; Attr.cursor = XCreateFontCursor(dpy, XC_hand2); mask |= CWCursor; /* Curseur pour la fenetre / window cursor */ xobj->win = XCreateWindow(dpy, *xobj->ParentWin, xobj->x, xobj->y, xobj->width, xobj->height, 0, CopyFromParent, InputOutput, CopyFromParent, mask, &Attr); xobj->gc = fvwmlib_XCreateGC(dpy, xobj->win, 0, NULL); XSetForeground(dpy, xobj->gc, xobj->TabColor[fore]); if ((xobj->Ffont = FlocaleLoadFont(dpy, xobj->font, ScriptName)) == NULL) { fprintf(stderr, "%s: Couldn't load font. Exiting!\n", ScriptName); exit(1); } if (xobj->Ffont->font != NULL) XSetFont(dpy, xobj->gc, xobj->Ffont->font->fid); XSetLineAttributes(dpy, xobj->gc, 1, LineSolid, CapRound, JoinMiter); xobj->value3 = CountOption(xobj->title); if (xobj->value > xobj->value3) xobj->value = xobj->value3; if (xobj->value < 1) xobj->value = 1; /* Redimensionnement du widget / Widget resizing */ xobj->height = xobj->Ffont->height +12; xobj->width = 30; for (i = 1; i <= xobj->value3; i++) { str = (char*)GetMenuTitle(xobj->title, i); if (xobj->width < FlocaleTextWidth(xobj->Ffont, str, strlen(str))+34) xobj->width = FlocaleTextWidth(xobj->Ffont, str, strlen(str))+34; free(str); } XResizeWindow(dpy, xobj->win, xobj->width, xobj->height); if (xobj->colorset >= 0) SetWindowBackground(dpy, xobj->win, xobj->width, xobj->height, &Colorset[xobj->colorset], Pdepth, xobj->gc, True); XSelectInput(dpy, xobj->win, ExposureMask); }
void EvtMousePopupMenu(struct XObj *xobj, XButtonEvent *EvtButton) { static XEvent event; int x,y,hOpt,yMenu,hMenu; int x1,y1,x2,y2,oldy; int oldvalue = 0; int newvalue = 0; Window Win1,Win2,WinPop; unsigned int modif; unsigned long mask; unsigned long while_mask; XSetWindowAttributes Attr; Time start_time = 0; KeySym ks; unsigned char buf[10]; Bool End = 1; int asc = xobj->Ffont->ascent; hOpt = xobj->Ffont->height + 10; xobj->value3 = CountOption(xobj->title); yMenu = xobj->y - ((xobj->value-1) * hOpt); hMenu = xobj->value3 * hOpt; /* Creation de la fenetre menu */ XTranslateCoordinates(dpy, *xobj->ParentWin, Root, xobj->x, yMenu, &x, &y, &Win1); if (x < 0) x = 0; if (y < 0) y = 0; if (x+xobj->width > XDisplayWidth(dpy, screen)) x = XDisplayWidth(dpy, screen) - xobj->width; if (y+hMenu > XDisplayHeight(dpy, screen)) y = XDisplayHeight(dpy, screen) - hMenu; mask = 0; Attr.background_pixel = xobj->TabColor[back]; mask |= CWBackPixel; Attr.border_pixel = 0; mask |= CWBorderPixel; Attr.colormap = Pcmap; mask |= CWColormap; Attr.cursor = XCreateFontCursor(dpy, XC_hand2); mask |= CWCursor; /* Curseur pour la fenetre / Window cursor */ Attr.override_redirect = True; mask |= CWOverrideRedirect; WinPop = XCreateWindow(dpy, Root, x, y, xobj->width, hMenu, 0, Pdepth, InputOutput, Pvisual, mask, &Attr); if (xobj->colorset >= 0) SetWindowBackground(dpy, WinPop, xobj->width, hMenu, &Colorset[xobj->colorset], Pdepth, xobj->gc, True); XMapRaised(dpy, WinPop); /* Dessin du menu / Drawing the menu */ DrawPMenu(xobj, WinPop, hOpt, 0); XGrabPointer(dpy, WinPop, True, GRAB_EVMASK, GrabModeAsync, GrabModeAsync, None, None, CurrentTime); if (EvtButton == NULL) { while_mask = ButtonPress; } else { start_time = EvtButton->time; while_mask = ButtonRelease; } while (End) { FQueryPointer(dpy, Root, &Win1, &Win2, &x1, &y1, &x2, &y2, &modif); /* Determiner l'option courante / Current option */ y2 = y2 - y; x2 = x2 - x; oldy = y2; /* calcule de xobj->value / compute xobj->value */ if ((x2 > 0) && (x2 < xobj->width) && (y2 > 0) && (y2 < hMenu)) newvalue = y2 / hOpt+1; else newvalue = 0; if (newvalue != oldvalue) { UnselectMenu(xobj, WinPop, hOpt, oldvalue, xobj->width, asc, 0); SelectMenu(xobj, WinPop, hOpt, newvalue); oldvalue = newvalue; } FNextEvent(dpy, &event); switch (event.type) { case KeyPress: XLookupString(&event.xkey, (char *)buf, sizeof(buf), &ks, NULL); if (ks == XK_Escape) { newvalue = 0; End = 0; } else if (ks == XK_Return) { End = 0; } else if (ks == XK_Up && y2 >= hOpt) { FWarpPointer(dpy, None, None, 0, 0, 0, 0, 0, -hOpt); } else if (ks == XK_Down && y2 + hOpt <= hMenu) { FWarpPointer(dpy, None, None, 0, 0, 0, 0, 0, hOpt); } break; case ButtonPress: if (while_mask == ButtonPress) End = 0; break; case ButtonRelease: if (start_time != 0 && event.xbutton.time - start_time < MENU_DRAG_TIME) { while_mask = ButtonPress; start_time = 0; } if (while_mask == ButtonRelease) End = 0; break; } } #if 0 do { FQueryPointer(dpy, Root, &Win1, &Win2, &x1, &y1, &x2, &y2, &modif); /* Determiner l'option courante / Current option */ y2 = y2 - y; x2 = x2 - x; { oldy = y2; /* calcule de xobj->value / compute xobj->value */ if ((x2 > 0) && (x2 < xobj->width) && (y2 > 0) && (y2 < hMenu)) newvalue = y2 / hOpt+1; else newvalue = 0; if (newvalue != oldvalue) { UnselectMenu(xobj, WinPop, hOpt, oldvalue, xobj->width, asc, 0); SelectMenu(xobj, WinPop, hOpt, newvalue); oldvalue = newvalue; } } FD_ZERO(&in_fdset); FD_SET(x_fd, &in_fdset); select(32, SELECT_FD_SET_CAST &in_fdset, NULL, NULL, NULL); } while (!FCheckTypedEvent(dpy, while_mask, &event)); #endif XUngrabPointer(dpy, CurrentTime); XSync(dpy,0); XDestroyWindow(dpy, WinPop); if (newvalue != 0) { xobj->value = newvalue; SendMsg(xobj, SingleClic); } }
void InitList(struct XObj *xobj) { unsigned long mask; XSetWindowAttributes Attr; int asc,desc,dir; XCharStruct struc; int minw,minh,resize=0; int NbVisCell,NbCell; /* Enregistrement des couleurs et de la police */ MyAllocNamedColor(xobj->display,*xobj->colormap,xobj->forecolor,&xobj->TabColor[fore]); MyAllocNamedColor(xobj->display,*xobj->colormap,xobj->backcolor,&xobj->TabColor[back]); MyAllocNamedColor(xobj->display,*xobj->colormap,xobj->licolor,&xobj->TabColor[li]); MyAllocNamedColor(xobj->display,*xobj->colormap,xobj->shadcolor,&xobj->TabColor[shad]); MyAllocNamedColor(xobj->display,*xobj->colormap,"#000000",&xobj->TabColor[black]); MyAllocNamedColor(xobj->display,*xobj->colormap,"#FFFFFF",&xobj->TabColor[white]); mask=0; Attr.background_pixel=xobj->TabColor[back].pixel; mask|=CWBackPixel; Attr.cursor=XCreateFontCursor(xobj->display,XC_hand2); mask|=CWCursor; /* Curseur pour la fenetre */ xobj->win=XCreateWindow(xobj->display,*xobj->ParentWin, xobj->x,xobj->y,xobj->width,xobj->height,0, CopyFromParent,InputOutput,CopyFromParent, mask,&Attr); xobj->gc=XCreateGC(xobj->display,xobj->win,0,NULL); XSetForeground(xobj->display,xobj->gc,xobj->TabColor[fore].pixel); XSetBackground(xobj->display,xobj->gc,xobj->TabColor[back].pixel); XSetLineAttributes(xobj->display,xobj->gc,1,LineSolid,CapRound,JoinMiter); if ((xobj->xfont=XLoadQueryFont(xobj->display,xobj->font))==NULL) fprintf(stderr,"Can't load font %s\n",xobj->font); else XSetFont(xobj->display,xobj->gc,xobj->xfont->fid); /* Calcul de la taille du widget */ /* Taille minimum: une ligne ou ascenseur visible */ XTextExtents(xobj->xfont,"lp",strlen("lp"),&dir,&asc,&desc,&struc); minh=8+3*BdWidth+3*(asc+desc+3); if (xobj->height<minh) { xobj->height=minh; resize=1; } minw=12+3*BdWidth+SbWidth+75; if (xobj->width<minw) { xobj->width=minw; resize=1; } if (resize) XResizeWindow(xobj->display,xobj->win,xobj->width,xobj->height); /* Calcul de la premiere cellule visible */ NbVisCell=(xobj->height-2-3*BdWidth)/(asc+desc+3); NbCell=CountOption(xobj->title); if (NbCell>NbVisCell) { if (xobj->value2>(NbCell-NbVisCell+1)) xobj->value2=NbCell-NbVisCell+1; if ((xobj->value2<1)||(xobj->value2<0)) xobj->value2=1; } else xobj->value2=1; }
void EvtMouseList(struct XObj *xobj,XButtonEvent *EvtButton) { XRectangle rect,rectT; XPoint pt; XCharStruct struc; int x1,y1,x2,y2; Window Win1,Win2; unsigned int modif; int In=1; static XEvent event; int asc,desc,dir; int NbVisCell,NbCell,HeightCell,NPosCell,PosMouse; fd_set in_fdset; pt.x=EvtButton->x-xobj->x; pt.y=EvtButton->y-xobj->y; /* Clic dans une cellule */ rect.x=4+BdWidth; rect.y=rect.x; rect.width=xobj->width-rect.x-10-2*BdWidth-SbWidth; rect.height=xobj->height-rect.y-4-2*BdWidth; if(PtInRect(pt,rect)) { /* Determination de la cellule */ pt.y=pt.y-rect.y; XTextExtents(xobj->xfont,"lp",strlen("lp"),&dir,&asc,&desc,&struc); NPosCell=xobj->value2+(pt.y/(asc+desc+3)); if (NPosCell>CountOption(xobj->title)) NPosCell=0; if (NPosCell!=xobj->value) { xobj->value=NPosCell; DrawList(xobj); } /* if (IsItDoubleClic(xobj)) SendMsg(xobj,DoubleClic); else*/ SendMsg(xobj,SingleClic); return ; } XTextExtents(xobj->xfont,"lp",strlen("lp"),&dir,&asc,&desc,&struc); HeightCell=asc+desc+3; NbVisCell=(xobj->height-6-BdWidth)/HeightCell; NbCell=CountOption(xobj->title); /* Clic fleche haute asc vertical */ rect.y=5+BdWidth; rect.x=xobj->width-(6+BdWidth)-SbWidth+3; rect.height=12; rect.width=12; if(PtInRect(pt,rect)) { DrawVSbList(xobj,NbCell,NbVisCell,1); do { XQueryPointer(xobj->display,*xobj->ParentWin,&Win1,&Win2,&x1,&y1,&x2,&y2,&modif); pt.y=y2-xobj->y; pt.x=x2-xobj->x; if (PtInRect(pt,rect)) { if (In) { Wait(8); xobj->value2--; if (xobj->value2<1) xobj->value2=1; else { DrawCellule(xobj,NbCell,NbVisCell,HeightCell,asc); DrawVSbList(xobj,NbCell,NbVisCell,1); } } else { In=1; DrawVSbList(xobj,NbCell,NbVisCell,1); xobj->value2--; if (xobj->value2<1) xobj->value2=1; else DrawCellule(xobj,NbCell,NbVisCell,HeightCell,asc); } } else { if (In) { In=0; DrawVSbList(xobj,NbCell,NbVisCell,0); } } FD_ZERO(&in_fdset); FD_SET(x_fd,&in_fdset); select(32, &in_fdset, NULL, NULL, NULL); } while (!XCheckTypedEvent(xobj->display,ButtonRelease,&event)); DrawVSbList(xobj,NbCell,NbVisCell,0); return; } /* Clic flache basse asc vertical */ rect.y=xobj->height-2*BdWidth-16; if(PtInRect(pt,rect)) { DrawVSbList(xobj,NbCell,NbVisCell,2); do { XQueryPointer(xobj->display,*xobj->ParentWin,&Win1,&Win2,&x1,&y1,&x2,&y2,&modif); pt.y=y2-xobj->y; pt.x=x2-xobj->x; if (PtInRect(pt,rect)) { if (In) { Wait(8); if (xobj->value2<=NbCell-NbVisCell) { xobj->value2++; DrawCellule(xobj,NbCell,NbVisCell,HeightCell,asc); DrawVSbList(xobj,NbCell,NbVisCell,2); } } else { In=1; DrawVSbList(xobj,NbCell,NbVisCell,2); if (xobj->value2<=NbCell-NbVisCell) { xobj->value2++; DrawCellule(xobj,NbCell,NbVisCell,HeightCell,asc); } } } else { if (In) { In=0; DrawVSbList(xobj,NbCell,NbVisCell,0); } } FD_ZERO(&in_fdset); FD_SET(x_fd,&in_fdset); select(32, &in_fdset, NULL, NULL, NULL); } while (!XCheckTypedEvent(xobj->display,ButtonRelease,&event)); DrawVSbList(xobj,NbCell,NbVisCell,0); return; } /* clic sur la zone pouce de l'ascenseur de l'ascenseur */ rect.y=17+BdWidth; rect.x=xobj->width-(6+BdWidth)-SbWidth+2; rect.height=xobj->height-rect.y-19-2*BdWidth; rect.width=SbWidth; if(PtInRect(pt,rect)) { /* Clic dans le pouce */ rectT.x=rect.x; rectT.y=rect.y+(xobj->value2-1)*(rect.height-8)/NbCell; if (NbVisCell<NbCell) rectT.height=NbVisCell*(rect.height-8)/NbCell+8; rectT.width=rect.width; if(PtInRect(pt,rectT)) { PosMouse=pt.y-rectT.y-HeightCell/2+2; do { XQueryPointer(xobj->display,*xobj->ParentWin,&Win1,&Win2,&x1,&y1,&x2,&y2,&modif); /* Calcul de l'id de la premiere cellule */ pt.y=y2-xobj->y-PosMouse; NPosCell=(pt.y-rect.y)*NbCell/(rect.height); if (NPosCell<1) NPosCell=1; if (NbCell>NbVisCell) { if (NPosCell>(NbCell-NbVisCell+1)) NPosCell=NbCell-NbVisCell+1; } else NPosCell=1; if (xobj->value2!=NPosCell) { xobj->value2=NPosCell; DrawCellule(xobj,NbCell,NbVisCell,HeightCell,asc); DrawVSbList(xobj,NbCell,NbVisCell,0); } FD_ZERO(&in_fdset); FD_SET(x_fd,&in_fdset); select(32, &in_fdset, NULL, NULL, NULL); } while (!XCheckTypedEvent(xobj->display,ButtonRelease,&event)); } else if (pt.y<rectT.y) { NPosCell=xobj->value2-NbVisCell; if (NPosCell<1) NPosCell=1; if (xobj->value2!=NPosCell) { xobj->value2=NPosCell; DrawCellule(xobj,NbCell,NbVisCell,HeightCell,asc); DrawVSbList(xobj,NbCell,NbVisCell,0); } } else if (pt.y>rectT.y+rectT.height) { NPosCell=xobj->value2+NbVisCell; if (NbCell>NbVisCell) { if (NPosCell>(NbCell-NbVisCell+1)) NPosCell=NbCell-NbVisCell+1; } else NPosCell=1; if (xobj->value2!=NPosCell) { xobj->value2=NPosCell; DrawCellule(xobj,NbCell,NbVisCell,HeightCell,asc); DrawVSbList(xobj,NbCell,NbVisCell,0); } } } }
/* * Fonction pour PushButton */ void InitPushButton(struct XObj *xobj) { unsigned long mask; XSetWindowAttributes Attr; int i; char *str; /* Enregistrement des couleurs et de la police */ if (xobj->colorset >= 0) { xobj->TabColor[fore] = Colorset[xobj->colorset].fg; xobj->TabColor[back] = Colorset[xobj->colorset].bg; xobj->TabColor[hili] = Colorset[xobj->colorset].hilite; xobj->TabColor[shad] = Colorset[xobj->colorset].shadow; } else { xobj->TabColor[fore] = GetColor(xobj->forecolor); xobj->TabColor[back] = GetColor(xobj->backcolor); xobj->TabColor[hili] = GetColor(xobj->hilicolor); xobj->TabColor[shad] = GetColor(xobj->shadcolor); } mask = 0; Attr.cursor = XCreateFontCursor(dpy, XC_hand2); mask |= CWCursor; Attr.background_pixel = xobj->TabColor[back]; mask |= CWBackPixel; /* Epaisseur de la fenetre = 0 */ xobj->win = XCreateWindow( dpy, *xobj->ParentWin, xobj->x, xobj->y, xobj->width, xobj->height, 0, CopyFromParent, InputOutput, CopyFromParent, mask, &Attr); xobj->gc = fvwmlib_XCreateGC(dpy, xobj->win, 0, NULL); XSetForeground(dpy, xobj->gc, xobj->TabColor[fore]); if ((xobj->Ffont = FlocaleLoadFont( dpy, xobj->font, ScriptName)) == NULL) { fprintf( stderr, "%s: Couldn't load font. Exiting!\n", ScriptName); exit(1); } if (xobj->Ffont->font != NULL) XSetFont(dpy, xobj->gc, xobj->Ffont->font->fid); XSetLineAttributes(dpy, xobj->gc, 1, LineSolid, CapRound, JoinMiter); /* Redimensionnement du widget */ str = (char*)GetMenuTitle(xobj->title, 1); if (xobj->icon == NULL) { i = xobj->Ffont->height + 12; if (xobj->height < i) xobj->height = i; i = FlocaleTextWidth(xobj->Ffont, str, strlen(str)) + 16; if (xobj->width < i) xobj->width = i; } else if (strlen(str) == 0) { if (xobj->height < xobj->icon_h + 10) xobj->height = xobj->icon_h + 10; if (xobj->width < xobj->icon_w + 10) xobj->width = xobj->icon_w + 10; } else { if (xobj->icon_w + 10 > FlocaleTextWidth( xobj->Ffont, str, strlen(str)) + 16) i = xobj->icon_w + 10; else i = FlocaleTextWidth( xobj->Ffont, str, strlen(str)) + 16; if (xobj->width < i) xobj->width = i; i = xobj->icon_h+ 2 * (xobj->Ffont->height + 10); if (xobj->height < i) xobj->height = i; } XResizeWindow(dpy, xobj->win, xobj->width, xobj->height); if (xobj->colorset >= 0) SetWindowBackground(dpy, xobj->win, xobj->width, xobj->height, &Colorset[xobj->colorset], Pdepth, xobj->gc, True); xobj->value3 = CountOption(xobj->title); XSelectInput(dpy, xobj->win, ExposureMask); }