MENUPAN* menu_pan_create(MENU *menu, int y, int x, int id) { MENUPAN *menupan; assert(menu); menupan=(MENUPAN *)malloc(sizeof(MENUPAN)); if(!menupan) { set_error(ERR_NOMEM); lpr_error("menu_pan_create"); } menupan->id=id; menupan->menu=menu; menupan->win=new_panel(newwin(item_count(menu)+2, MSIZE, y, x)); menupan->sub=new_panel(derwin(menupan->win->win, item_count(menu), MSIZE-2, 1, 1)); wcolor_set(menupan->win->win, 1, NULL); set_menu_fore(menu, COLOR_PAIR(1) | A_REVERSE); set_menu_back(menu, COLOR_PAIR(1)); set_menu_grey(menu, COLOR_PAIR(1)); set_menu_win(menu, menupan->win->win); set_menu_sub(menu, menupan->sub->win); box(menupan->win->win, 0, 0); menupan_hide(menupan); return menupan; }
void NCPanelContainer::setActive(const NCPanel * panel) { for (int i = 0; i < mPanels.size(); i++) if ( mPanels[i] == panel ) { mPanels[i]->setActive(true); MENU * menu = mPanels[i]->getWidget()->getMenu(); set_menu_grey(menu, COLOR_PAIR(3)); set_menu_fore(menu, COLOR_PAIR(4)); set_menu_back(menu, COLOR_PAIR(1)); current = i; break; } }
void NCRowMenu::setup() { wbkgd(getWindow(),COLOR_PAIR(2)); ITEM **my_items; MENU *my_menu; WINDOW *my_menu_win; int i; my_items = (ITEM **) calloc(choices.size()+2, sizeof(ITEM *)); for(i = 0; i < choices.size(); ++i) my_items[i] = new_item(choices[i].c_str(), "NULL"); my_menu = new_menu((ITEM **) my_items); set_menu_grey(my_menu, COLOR_PAIR(2)); set_menu_fore(my_menu, COLOR_PAIR(2)); set_menu_back(my_menu, COLOR_PAIR(2)); menu_opts_off(my_menu, O_SHOWDESC); my_menu_win = getWindow(); keypad(my_menu_win, FALSE); /* Set main window and sub window */ set_menu_win(my_menu, my_menu_win); //set_menu_sub(my_menu, derwin(my_menu_win, 10, 150, 3, 1)); set_menu_format(my_menu, 1, 10); set_menu_mark(my_menu, " "); //box(my_menu_win, 0, 0); //wbkgdset(getWindow(), COLOR_PAIR(2)); //wrefresh(getWindow()); wrefresh(stdscr); refresh(); /* Post the menu */ post_menu(my_menu); wrefresh(my_menu_win); //setBorder(0, 0); }
void NCPanelContainer::changePanels() { int curr = 0; for (curr = 0; curr < mPanels.size(); curr++) { MENU * menu = mPanels[curr]->getWidget()->getMenu(); set_menu_grey(menu, COLOR_PAIR(5)); set_menu_fore(menu, COLOR_PAIR(5)); set_menu_back(menu, COLOR_PAIR(5)); if ( mPanels[curr]->isActive() ) { mPanels[curr]->setActive(false); break; } } curr = (curr+1) % mPanels.size(); setActive( mPanels[curr] ); }
/* * create the internal menu for the files */ static void wdg_file_menu_create(struct wdg_object *wo) { WDG_WO_EXT(struct wdg_file_handle, ww); int mrows, mcols; int i; size_t c = wdg_get_ncols(wo); size_t x = wdg_get_begin_x(wo); size_t y = wdg_get_begin_y(wo); struct stat buf; /* the menu is already posted */ if (ww->nitems) return; WDG_DEBUG_MSG("wdg_file_menu_create"); /* get the working directory */ getcwd(ww->curpath, PATH_MAX); /* scan the directory */ ww->nlist = scandir(".", &ww->namelist, 0, alphasort); /* on error display the message in the box */ if (ww->nlist <= 0) { ww->nitems = 2; WDG_SAFE_REALLOC(ww->items, ww->nitems * sizeof(ITEM *)); ww->items[ww->nitems - 2] = new_item("/", "root"); ww->items[ww->nitems - 1] = new_item("Cannot open the directory", ""); item_opts_off(ww->items[ww->nitems - 1], O_SELECTABLE); } else { /* for each directory in the directory */ for (i = 0; i < ww->nlist; i++) { /* * transform the current dir into the root. * useful to exit from a path whose parent is not readable */ if (!strcmp(ww->namelist[i]->d_name, ".")) { strncpy(ww->namelist[i]->d_name, "/", 1); ww->nitems++; WDG_SAFE_REALLOC(ww->items, ww->nitems * sizeof(ITEM *)); ww->items[ww->nitems - 1] = new_item(ww->namelist[i]->d_name, "root"); continue; } /* get the file properties */ stat(ww->namelist[i]->d_name, &buf); if (S_ISDIR(buf.st_mode)) { ww->nitems++; WDG_SAFE_REALLOC(ww->items, ww->nitems * sizeof(ITEM *)); ww->items[ww->nitems - 1] = new_item(ww->namelist[i]->d_name, "[...]"); } // if not readable //item_opts_off(ww->items[ww->nitems - 1], O_SELECTABLE); } /* and now add the files */ for (i = 0; i < ww->nlist; i++) { /* get the file properties */ stat(ww->namelist[i]->d_name, &buf); if (!S_ISDIR(buf.st_mode)) { ww->nitems++; WDG_SAFE_REALLOC(ww->items, ww->nitems * sizeof(ITEM *)); ww->items[ww->nitems - 1] = new_item(ww->namelist[i]->d_name, ""); } } } /* null terminate the array */ WDG_SAFE_REALLOC(ww->items, (ww->nitems + 1) * sizeof(ITEM *)); ww->items[ww->nitems] = NULL; /* create the menu */ ww->m = new_menu(ww->items); /* set the dimensions */ set_menu_format(ww->m, ww->y - 2, 1); set_menu_spacing(ww->m, 2, 0, 0); /* get the geometry to make a window */ scale_menu(ww->m, &mrows, &mcols); /* * if the menu is larger than the main window * adapt to the new dimensions */ if (mcols > (int)c - 4) { ww->x = mcols + 4; wdg_file_redraw(wo); return; } /* create the window for the menu */ ww->mwin = newwin(mrows, MAX(mcols, (int)c - 4), y + 1, x + 2); /* set the color */ wbkgd(ww->mwin, COLOR_PAIR(wo->window_color)); keypad(ww->mwin, TRUE); /* associate with the menu */ set_menu_win(ww->m, ww->mwin); /* the subwin for the menu */ set_menu_sub(ww->m, derwin(ww->mwin, mrows + 1, mcols, 1, 1)); /* menu attributes */ set_menu_mark(ww->m, ""); set_menu_grey(ww->m, COLOR_PAIR(wo->window_color)); set_menu_back(ww->m, COLOR_PAIR(wo->window_color)); set_menu_fore(ww->m, COLOR_PAIR(wo->window_color) | A_REVERSE | A_BOLD); /* display the menu */ post_menu(ww->m); wnoutrefresh(ww->mwin); }
static VALUE rbncurs_c_set_menu_grey(VALUE rb_menu, VALUE attr) { MENU *menu = get_menu(rb_menu); return INT2NUM(set_menu_grey(menu, NUM2ULONG(attr))); }
int main() { ITEM **my_items; int c; MENU *my_menu; int n_choices, i; ITEM *cur_item; /* Initialize curses */ initscr(); start_color(); cbreak(); noecho(); keypad(stdscr, TRUE); init_pair(1, COLOR_RED, COLOR_BLACK); init_pair(2, COLOR_GREEN, COLOR_BLACK); init_pair(3, COLOR_MAGENTA, COLOR_BLACK); /* Initialize items */ n_choices = ARRAY_SIZE(choices); my_items = (ITEM **)calloc(n_choices + 1, sizeof(ITEM *)); for(i = 0; i < n_choices; ++i) my_items[i] = new_item(choices[i], choices[i]); my_items[n_choices] = (ITEM *)NULL; item_opts_off(my_items[3], O_SELECTABLE); item_opts_off(my_items[6], O_SELECTABLE); /* Create menu */ my_menu = new_menu((ITEM **)my_items); /* Set fore ground and back ground of the menu */ set_menu_fore(my_menu, COLOR_PAIR(1) | A_REVERSE); set_menu_back(my_menu, COLOR_PAIR(2)); set_menu_grey(my_menu, COLOR_PAIR(3)); /* Post the menu */ mvprintw(LINES - 3, 0, "Press <ENTER> to see the option selected"); mvprintw(LINES - 2, 0, "Up and Down arrow keys to naviage (F1 to Exit)"); post_menu(my_menu); refresh(); while((c = getch()) != KEY_F(1)) { switch(c) { case KEY_DOWN: menu_driver(my_menu, REQ_DOWN_ITEM); break; case KEY_UP: menu_driver(my_menu, REQ_UP_ITEM); break; case 10: /* Enter */ move(20, 0); clrtoeol(); mvprintw(20, 0, "Item selected is : %s", item_name(current_item(my_menu))); pos_menu_cursor(my_menu); break; } } unpost_menu(my_menu); for(i = 0; i < n_choices; ++i) free_item(my_items[i]); free_menu(my_menu); endwin(); }
/* * Return codes: * 0 - action performed * -1 - quit was pressed (only for main menu) * +1 - backspace or escape was pressed, back to previous menu */ static int do_menu(struct menuoption *runmenu, int num, int upper, const char *title, ...) { int ch, i, y, x; // char buf[BUFSIZ]; char *buf; struct menuoption *curmenu; ITEM **mitems, *mitem; MENU *mmenu; WINDOW *msubwin; va_list ap; /* Clear screen and print title */ if (upper) show_mainwin(0); else show_mainwin(1); va_start(ap, title); head_mainwin(title, ap); va_end(ap); x = 0; y = 0; if (upper) msubwin = create_uppersubwin(); else msubwin = create_lowersubwin(&y, &x); mitems = (ITEM **)calloc(num + 1, sizeof(ITEM*)); for (curmenu = runmenu, i = 0; i < num; i++) { ch = sizeof buf > x ? x - 1 : sizeof buf - 1; // if (snprintf(buf, ch, "%s", curmenu->m_name) <= 0) { if (asprintf(&buf, "%s", curmenu->m_name) <= 0) { ask_ok("Error creating the menu."); for (i--; i >= 0; i--) free(mitems[i]); return 0; } mitems[i] = new_item(buf, NULL); set_item_userptr(mitems[i], (void *)curmenu); // warnx("%ld %s", (long)curmenu, curmenu->m_name); curmenu++; } mitems[num] = NULL; mmenu = new_menu(mitems); set_menu_win(mmenu, mainwin); set_menu_sub(mmenu, msubwin); set_menu_format(mmenu, upper ? 1 : y, 1); if (colouring) { set_menu_fore(mmenu, COLOR_PAIR(1)); set_menu_back(mmenu, COLOR_PAIR(1)); set_menu_grey(mmenu, COLOR_PAIR(1)); } set_menu_mark(mmenu, ">"); if (post_menu(mmenu)) { ask_ok("Error posting the menu."); return 1; } show_mainwin(0); show_lowersubwin(0, msubwin); while ((ch = getch()) != '\n' && ch != '\b') { switch (ch) { case KEY_DOWN: menu_driver(mmenu, REQ_NEXT_ITEM); break; case KEY_UP: menu_driver(mmenu, REQ_PREV_ITEM); break; case KEY_NPAGE: menu_driver(mmenu, REQ_SCR_DPAGE); break; case KEY_PPAGE: menu_driver(mmenu, REQ_SCR_UPAGE); break; case KEY_END: menu_driver(mmenu, REQ_LAST_ITEM); break; case KEY_HOME: menu_driver(mmenu, REQ_FIRST_ITEM); break; } show_mainwin(0); show_lowersubwin(0, msubwin); } mitem = current_item(mmenu); curmenu = (struct menuoption *)item_userptr(mitem); unpost_menu(mmenu); delwin(msubwin); free_menu(mmenu); for (i = 0; i < num; i++) free_item(mitems[i]); free(mitems); if (ch != '\b' && curmenu->m_action != NULL) { curmenu->m_action(curmenu->m_argv); return 0; } else { return 1; } }