/** *** select_button() *** Given (x,y) and uberbutton, returns pointer to referred button, or NULL **/ button_info *select_button(button_info *ub,int x,int y) { int i; int row; int column; button_info *b; if (!(ub->flags&b_Container)) return ub; x -= buttonXPad(ub) + buttonFrame(ub); y -= buttonYPad(ub) + buttonFrame(ub); if(x >= ub->c->width || x < 0 || y >= ub->c->height || y < 0) return ub; column = x * ub->c->num_columns / ub->c->width; row = y * ub->c->num_rows / ub->c->height; i = button_belongs_to(ub, column + row * ub->c->num_columns); if (i == -1) return ub; b = ub->c->buttons[i]; return select_button( b, x + ub->c->xpos - buttonXPos(b, i), y + ub->c->ypos - buttonYPos(b, i)); }
/** *** RedrawButton() *** Writes out title, if any, and displays the bevel right, by calling *** RelieveWindow. If clean is nonzero, also clears background. **/ void RedrawButton(button_info *b,int clean) { int i,j,k,BH,BW; int f,x,y,px,py; int ix,iy,iw,ih; XFontStruct *font=buttonFont(b); XGCValues gcv; unsigned long gcm=0; int rev=0; int justify=buttonJustify(b); BW = buttonWidth(b); BH = buttonHeight(b); buttonInfo(b,&x,&y,&px,&py,&f); GetInternalSize(b,&ix,&iy,&iw,&ih); /* This probably isn't the place for this, but it seems to work here and not elsewhere, so... */ if((buttonSwallowCount(b)==3) && b->IconWin!=None) XSetWindowBorderWidth(Dpy,b->IconWin,0); /* ----------------------------------------------------------------------- */ if(b->flags&b_Hangon || b==CurrentButton) /* Hanging or held down by user */ rev=1; if(b->flags&b_Action) /* If this is a Desk button that takes you to here.. */ { int n=0; while(n<4 && (!b->action[n] || strncasecmp(b->action[n],"Desk",4))) n++; if(n<4) { k=sscanf(&b->action[n][4],"%d%d",&i,&j); if(k==2 && i==0 && j==new_desk) rev=1; } } RelieveWindow(MyWindow,f,x,y,BW,BH,buttonHilite(b),buttonShadow(b),rev); /* ----------------------------------------------------------------------- */ f=abs(f); if(clean && BW>2*f && BH>2*f) { gcm = GCForeground; gcv.foreground=buttonBack(b); XChangeGC(Dpy,NormalGC,gcm,&gcv); if(b->flags&b_Container) { int x1=x+f,y1=y+f; int w1=px,h1=py,w2=w1,h2=h1; int w=BW-2*f,h=BH-2*f; w2+=iw - b->c->num_columns*b->c->ButtonWidth; h2+=ih - b->c->num_rows*b->c->ButtonHeight; if(w1)XFillRectangle(Dpy,MyWindow,NormalGC,x1,y1,w1,h); if(w2)XFillRectangle(Dpy,MyWindow,NormalGC,x1+w-w2,y1,w2,h); if(h1)XFillRectangle(Dpy,MyWindow,NormalGC,x1,y1,w,h1); if(h2)XFillRectangle(Dpy,MyWindow,NormalGC,x1,y1+h-h2,w,h2); } else XFillRectangle(Dpy,MyWindow,NormalGC,x+f,y+f,BW-2*f,BH-2*f); } /* ----------------------------------------------------------------------- */ /* If a title is to be shown, truncate it until it fits */ if(b->flags&b_Title && font) { int l,i,xpos; char *s; int just=justify&b_TitleHoriz; /* Left, center, right */ gcm = GCForeground | GCFont; gcv.foreground=buttonFore(b); gcv.font = font->fid; XChangeGC(Dpy,NormalGC,gcm,&gcv); if(justify&b_Horizontal) { if(b->flags&b_Icon) { ix+=b->icon->width+buttonXPad(b); iw-=b->icon->width+buttonXPad(b); } else if (buttonSwallowCount(b)==3) { ix+=b->icon_w+buttonXPad(b); iw-=b->icon_w+buttonXPad(b); } } s=b->title; l=strlen(s); i=XTextWidth(font,s,l); if(i>iw) { if(just==2) { while(i>iw && *s) i=XTextWidth(font,++s,--l); } else /* Left or center - cut off its tail */ { while(i>iw && l>0) i=XTextWidth(font,s,--l); } } if(just==0) /* Left */ xpos=ix; else if(just==2) /* Right */ xpos=max(ix,ix+iw-i); else /* Centered, I guess */ xpos=ix+(iw-i)/2; if(*s && l>0 && BH>=font->descent+font->ascent) /* Clip it somehow? */ { /* If there is more than the title, put it at the bottom */ /* Unless stack flag is set, put it to the right of icon */ if((b->flags&b_Icon || (buttonSwallowCount(b)==3)) && !(justify&b_Horizontal)) { XDrawString(Dpy,MyWindow,NormalGC,xpos, iy+ih-font->descent,s,l); /* Shrink the space available for icon/window */ ih-=font->descent+font->ascent; } /* Or else center vertically */ else { XDrawString(Dpy,MyWindow,NormalGC,xpos, iy+(ih+font->ascent-font->descent)/2,s,l); } } } }