示例#1
0
/* Traverse over an internal menu */
Boolean
dmenuOpen(DMenu *menu, int *choice, int *scroll, int *curr, int *max, Boolean buttons)
{
    int n, rval = 0;
    dialogMenuItem *items;

    items = menu->items;
    if (buttons)
	items += 2;
    /* Count up all the items */
    for (n = 0; items[n].title; n++);

    while (1) {
	char buf[FILENAME_MAX];
	WINDOW *w = savescr();

	/* Any helpful hints, put 'em up! */
	use_helpline(menu->helpline);
	use_helpfile(systemHelpFile(menu->helpfile, buf));
	dialog_clear_norefresh();
	/* Pop up that dialog! */
	if (menu->type & DMENU_NORMAL_TYPE)
	    rval = dialog_menu((u_char *)menu->title, (u_char *)menu->prompt,
		-1, -1, menu_height(menu, n), -n, items,
		(char *)(uintptr_t)buttons, choice, scroll);

	else if (menu->type & DMENU_RADIO_TYPE)
	    rval = dialog_radiolist((u_char *)menu->title,
		(u_char *)menu->prompt, -1, -1, menu_height(menu, n), -n,
		items, (char *)(uintptr_t)buttons);

	else if (menu->type & DMENU_CHECKLIST_TYPE)
	    rval = dialog_checklist((u_char *)menu->title,
		(u_char *)menu->prompt, -1, -1, menu_height(menu, n), -n,
		items, (char *)(uintptr_t)buttons);
	else
	    msgFatal("Menu: `%s' is of an unknown type\n", menu->title);
	if (exited) {
	    exited = FALSE;
	    restorescr(w);
	    return TRUE;
	}
	else if (rval) {
	    restorescr(w);
	    return FALSE;
	}
	else if (menu->type & DMENU_SELECTION_RETURNS) {
	    restorescr(w);
	    return TRUE;
	}
    }
}
示例#2
0
int pd_height(t_pulldown *pd)
{
    int i, h;

    h = 0;
    for (i = 0; (i < pd->nmenu); i++)
    {
        h = std::max(h, menu_height(pd->m[i]));
    }

    return h;
}
示例#3
0
文件: menu.c 项目: Cougar/pwm
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);
	}
}
示例#4
0
/* Set the default item for a menu by index and scroll to it. */
void
dmenuSetDefaultIndex(DMenu *menu, int *choice, int *scroll, int *curr, int *max)
{
    int nitem;
    int height;

    *curr = *max = 0;

    for (nitem = 0; menu->items[nitem].prompt; ++nitem);

    height = menu_height(menu, nitem);
    if (*choice > height)
    {
	*scroll = MIN(nitem - height, *choice);
	*choice = *choice - *scroll;
    }
    else
	*scroll = 0;
}
示例#5
0
文件: menu.c 项目: Cougar/pwm
/* 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;
}