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 EvtMousePushButton(struct XObj *xobj, XButtonEvent *EvtButton) { static XEvent event; int End = 1; unsigned int modif; int x1,x2,y1,y2,i; Window Win1,Win2,WinPop; Window WinBut = 0; int In = 0; char *str; int x,y,hOpt,yMenu,hMenu,wMenu; int oldvalue = 0,newvalue; unsigned long mask; XSetWindowAttributes Attr; if (EvtButton->button == Button1) { i = (xobj->width - FlocaleTextWidth( xobj->Ffont, xobj->title, strlen(xobj->title)))/2; while (End) { FNextEvent(dpy, &event); switch (event.type) { case EnterNotify: FQueryPointer( dpy, *xobj->ParentWin, &Win1, &Win2, &x1, &y1, &x2, &y2, &modif); if (WinBut == 0) { WinBut = Win2; DrawReliefRect( 0, 0, xobj->width, xobj->height, xobj, shad, hili); DrawIconStr( 0,xobj, True, PUSH_BUTTON_LCR_OFFSETS, NULL, NULL, NULL); In = 1; } else { if (Win2 == WinBut) { DrawReliefRect( 0, 0, xobj->width, xobj->height, xobj, shad, hili); DrawIconStr( 1, xobj, True, PUSH_BUTTON_LCR_OFFSETS, NULL, NULL, NULL); In = 1; } else if (In) { In = 0; DrawReliefRect( 0, 0, xobj->width, xobj->height, xobj, hili, shad); DrawIconStr( 0, xobj, True, PUSH_BUTTON_LCR_OFFSETS, NULL, NULL, NULL); } } break; case LeaveNotify: FQueryPointer( dpy, *xobj->ParentWin, &Win1, &Win2, &x1, &y1, &x2, &y2, &modif); if (Win2 == WinBut) { In = 1; DrawReliefRect( 0, 0, xobj->width, xobj->height, xobj, shad, hili); DrawIconStr( 1, xobj, True, PUSH_BUTTON_LCR_OFFSETS, NULL, NULL, NULL); } else if (In) { DrawReliefRect( 0, 0, xobj->width, xobj->height, xobj, hili, shad); DrawIconStr( 0, xobj, True, PUSH_BUTTON_LCR_OFFSETS, NULL, NULL, NULL); In = 0; } break; case ButtonRelease: End = 0; DrawReliefRect( 0, 0, xobj->width, xobj->height, xobj, hili, shad); DrawIconStr( 0, xobj, True, PUSH_BUTTON_LCR_OFFSETS, NULL, NULL, NULL); if (In) { /* Envoie d'un message vide de type * SingleClic pour un clique souris */ xobj->value = 1; SendMsg(xobj, SingleClic); xobj->value = 0; } break; } } } /* affichage du popup menu / Drawing the popup menu */ else if (EvtButton->button == Button3) { if (xobj->value3 > 1) { hOpt = xobj->Ffont->height + 10; /* Hauteur totale du menu / Total height of the menu */ hMenu = (xobj->value3 - 1) * hOpt; yMenu = xobj->y + xobj->height; wMenu = 0; for (i = 2 ; i <= xobj->value3; i++) { str = (char*)GetMenuTitle(xobj->title, i); if (wMenu < FlocaleTextWidth( xobj->Ffont, str, strlen(str))+34) wMenu = FlocaleTextWidth( xobj->Ffont, str, strlen(str))+34; free(str); } /* Creation de la fenetre menu / create the menu * window */ XTranslateCoordinates(dpy, *xobj->ParentWin, Root, xobj->x, yMenu, &x, &y, &Win1); if (x<0) x = 0; if (y<0) y = 0; if (x + wMenu > XDisplayWidth(dpy, screen)) { x = XDisplayWidth(dpy, screen) - wMenu; } if (y + hMenu > XDisplayHeight(dpy, screen)) { y = y-hMenu-xobj->height; } 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 */ Attr.override_redirect = True; mask |= CWOverrideRedirect; WinPop = XCreateWindow( dpy, Root, x, y, wMenu-5, hMenu, 0, Pdepth, InputOutput, Pvisual, mask, &Attr); if (xobj->colorset >= 0) SetWindowBackground( dpy, WinPop, wMenu - 5, hMenu, &Colorset[xobj->colorset], Pdepth, xobj->gc, True); XMapRaised(dpy, WinPop); /* Dessin du menu */ DrawPMenu(xobj, WinPop, hOpt, 1); do { FQueryPointer( dpy, Root, &Win1, &Win2, &x1, &y1, &x2, &y2, &modif); /* Determiner l'option courante / Current * option */ y2 = y2 - y; x2 = x2 - x; { /* calcule de xobj->value / Compute * xobj->value */ if ((x2 > 0) && (x2 < wMenu) && (y2 > 0) && (y2 < hMenu)) newvalue = y2 / hOpt+1; else newvalue = 0; if (newvalue!=oldvalue) { UnselectMenu( xobj, WinPop, hOpt, oldvalue, wMenu-5, xobj->Ffont->ascent, 1); SelectMenu( xobj, WinPop, hOpt, newvalue); oldvalue = newvalue; } } } while (!FCheckTypedEvent(dpy, ButtonRelease, &event)); XDestroyWindow(dpy, WinPop); if (newvalue != 0) { xobj->value = newvalue; SendMsg(xobj, SingleClic); xobj->value = 0; } xobj->DrawObj(xobj, NULL); } /* xobj->value3 > 1 */ } /* EvtButton->button == Button3 */ }