int pd_width(t_pulldown *pd) { int i, w; w = 0; for (i = 0; (i < pd->nmenu); i++) { w = std::max(w, menu_width(pd->m[i])); } w = std::max(w, pd->xpos[pd->nmenu]); return w; }
static void update_menu(WMenu *menu) { int w, h; w=menu_width(menu->data, menu->flags); h=menu_height(menu->data); h+=menu->title_height; if(menu->w!=w || menu->h!=h){ menu->w=w; menu->h=h; XResizeWindow(wglobal.dpy, menu->menu_win, w, h); }else{ draw_menu(menu, TRUE); } }
static bool PDCallBack(t_x11 *x11, XEvent *event, Window w, void *data) { t_pulldown *pd; int i, x, x1, y, nsel; pd = (t_pulldown *)data; y = pd->wd.height; switch (event->type) { case Expose: XSetForeground(x11->disp, x11->gc, x11->fg); XDrawLine(x11->disp, w, x11->gc, 0, y-1, pd->wd.width, y-1); for (i = 0; (i < pd->nmenu); i++) { XDrawString(x11->disp, pd->wd.self, x11->gc, pd->xpos[i], x11->font->ascent, pd->title[i], std::strlen(pd->title[i])); } break; case ButtonPress: if (pd->nsel == -1) { x = event->xbutton.x; for (nsel = 0; (pd->xpos[nsel+1] < x) && (nsel < pd->nmenu-1); nsel++) { ; } pd->nsel = nsel; x1 = std::max(0, std::min(pd_width(pd)-menu_width(pd->m[nsel]), pd->xpos[nsel])); show_menu(x11, pd->m[nsel], x1, y+1, false); } break; case ButtonRelease: hide_pd(x11, pd); break; default: break; } return false; }
/* Create a menu window */ static WMenu* create_menu(WMenuData *mdata, WThing *context, int x, int y, WMenu *parent) { int w, h, th, eh; int flags=0; Window win; WMenu *menu; if(mdata->init_func!=NULL && mdata->nref==0) mdata->init_func(mdata, context); if(mdata->flags&WMENUDATA_CONTEXTUAL){ if(context==NULL || WTHING_IS(context, WTHING_SCREEN) || WTHING_IS(context, WTHING_MENU)) return NULL; flags|=(WMENU_NOTITLE|WMENU_CONTEXTUAL); }else{ context=NULL; } if(mdata->nref!=0) flags|=(WMENU_NOTITLE|WMENU_CONTEXTUAL); if(mdata->title==NULL) flags|=(WMENU_NOTITLE|WMENU_CONTEXTUAL); if(parent!=NULL) flags|=parent->flags&(WMENU_NOTITLE|WMENU_CONTEXTUAL); /* */ w=menu_width(mdata, flags); h=menu_height(mdata); /* Don't display empty menus */ if(w==0 || h==0) return NULL; /* */ menu=ALLOC(WMenu); if(menu==NULL){ warn_err(); return NULL; } WTHING_INIT(menu, WTHING_MENU); th=FONT_HEIGHT(GRDATA->font)+2*CF_MENUTITLE_V_SPACE; eh=FONT_HEIGHT(GRDATA->menu_font)+2*CF_MENUENT_V_SPACE; if(parent==NULL){ x-=w/2; y+=th/(flags&WMENU_NOTITLE ? 2 : -2 ); }else if(!(flags&WMENU_NOTITLE)){ y-=th; } if(flags&WMENU_NOTITLE) th=0; h+=th; win=create_simple_window(x, y, w, h, GRDATA->base_colors.pixels[WCG_PIX_BG]); menu->menu_win=win; menu->x=x; menu->y=y; menu->w=w; menu->h=h; menu->title_height=th; menu->entry_height=eh; menu->flags=flags; menu->selected=NO_ENTRY; menu->data=mdata; menu->context=context; if(mdata->nref++==0) mdata->inst1=menu; XSelectInput(wglobal.dpy, win, MENU_MASK); XSaveContext(wglobal.dpy, win, wglobal.win_context, (XPointer)menu); if(parent==NULL) add_winobj((WWinObj*)menu, WORKSPACE_STICKY, LVL_MENU); else add_winobj_above((WWinObj*)menu, (WWinObj*)parent); map_winobj((WWinObj*)menu); return menu; }