/* display current menu */ void display_menu() { int rows, cols, begin_y, begin_x; /* setup menu options */ menu_opts_off(menu_ptr, O_ROWMAJOR); set_menu_fore(menu_ptr, COLOR_PAIR(MENU_PAIR) | A_STANDOUT); set_menu_back(menu_ptr, COLOR_PAIR(MENU_PAIR) | A_DIM | A_NORMAL); /* setup appropriate windows */ set_menu_win(menu_ptr, stdscr); scale_menu(menu_ptr, &rows, &cols); /* locate menu in the center */ getmaxyx(stdscr,LINES,COLS); begin_y = (LINES-rows) / 2; begin_x = (COLS-cols) / 2; /* create main menu window */ sub_window = subwin(stdscr, rows, cols, begin_y, begin_x); set_menu_sub(menu_ptr, sub_window); /* display the menu */ post_menu(menu_ptr); refresh(); }
int main() { initscr(); start_color(); ITEM *menuitems[6]; MENU *menubar; WINDOW *win,*sub_win; int i,rows,cols; //initcolor(); menuitems[0]=new_item("File",""); menuitems[1]=new_item("Edit",""); menuitems[2]=new_item("Options",""); menuitems[3]=new_item("Window",""); menuitems[4]=new_item("Help",""); menuitems[5]=NULL; //menu_opts_off(menubar,O_ROWMAJOR); menubar=new_menu(menuitems); scale_menu(menubar,&rows,&cols); win=newwin(rows+2,cols+2,2,5); box(win,179,196); sub_win=derwin(win,rows,cols,1,1); set_menu_win(menubar,win); set_menu_sub(menubar,sub_win); post_menu(menubar); wrefresh(win); wgetch(sub_win); unpost_menu(menubar); free_menu(menubar); for(i=0;i<6;i++) free_item(menuitems[i]); endwin(); }
WINDOW* vwm_fmod_wndlist(gpointer anything) { const char *title=" Window List "; WINDOW *window; int width = 0,height = 0; MENU *menu; ITEM **item_list; gchar **titles; guint item_count; if(viper_window_find_by_class((gpointer)vwm_fmod_wndlist) != NULL) return NULL; viper_thread_enter(); titles = viper_deck_get_wndlist(); item_count = g_strv_length(titles); if(item_count == 0) { viper_thread_leave(); return NULL; } menu = viper_menu_create(titles); item_list = (ITEM**)g_malloc0(sizeof(ITEM*)*(item_count+1)); // override the default of 1 column X 16 entries per row set_menu_format(menu,20,1); // hide character mark on left hand side set_menu_mark(menu," "); scale_menu(menu,&height,&width); width++; if((strlen(title) + 10) > width) width = (strlen(title) + 10); window = viper_window_create((gchar*)title,0.95,2,width,height,TRUE); viper_menu_bind(menu,window,0,0,width,height); // set_menu_sub(menu,window); set_menu_fore(menu, VIPER_COLORS(COLOR_MAGENTA,COLOR_WHITE) | A_REVERSE | A_BOLD); set_menu_back(menu,VIPER_COLORS(COLOR_BLACK,COLOR_WHITE)); // post_menu(menu); /* viper_event_set(window,"window-activate",vwm_fmod_wndlist_ON_ACTIVATE,NULL); */ viper_event_set(window,"window-destroy",vwm_fmod_wndlist_ON_DESTROY, (gpointer)menu); viper_window_set_key_func(window,vwm_fmod_wndlist_ON_KEYSTROKE); viper_window_set_userptr(window,(gpointer)menu); viper_window_set_state(window,STATE_EMINENT); viper_thread_leave(); g_strfreev(titles); return window; }
/* glue items to menu and post menu */ static void display_menu(smsgloader *_this) { int rows,cols; VERBOSE_DEBUGPR("displaying scom menu requested\n"); if(_this->loadmenu) { DEBUGPR("Error!!!!! loadmenu already dsiplayed??\n"); return; } _this->loadmenu=new_menu(_this->loaditems); scale_menu(_this->loadmenu,&rows,&cols); wresize(_this->msgloaderwin,rows+5,cols+5); box(_this->msgloaderwin,0,0); wprintw(_this->msgloaderwin,"(%s)",SCOMMENU_TOGGLE_STR); set_menu_win(_this->loadmenu,_this->msgloaderwin); _this->derwin=derwin(_this->msgloaderwin,rows,cols,2,2); set_menu_sub(_this->loadmenu,_this->derwin); set_menu_mark(_this->loadmenu," * "); post_menu(_this->loadmenu); }
static VALUE rbncurs_c_scale_menu(VALUE rb_menu, VALUE rows, VALUE columns) { MENU *menu = get_menu(rb_menu); if (rb_obj_is_instance_of(rows, rb_cArray) != Qtrue || rb_obj_is_instance_of(columns, rb_cArray) != Qtrue) { rb_raise(rb_eArgError, "rows and columns arguments must be empty Arrays"); return Qnil; } else { int vals[2] = {0,0}; int result = scale_menu(menu, &vals[0],&vals[1]); rb_ary_push(rows, INT2NUM(vals[0])); rb_ary_push(columns, INT2NUM(vals[1])); return INT2NUM(result); } }
/* * 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); }
char* seleccionar_menu( Partida* par, int linea, int col ){ ITEM ** items; MENU* menu; WINDOW* menuwin; int cant = qg_partida_movidas_count( par ); int i; char* ret; int srow, scol; items = malloc( sizeof( ITEM ) * ( cant + 1 ) ); for( i = 0; i < cant; i ++ ){ Movdata movd; assert( qg_partida_movidas_data( par, i, &movd ) ); items[i] = new_item( strdup( movd.notacion ), NULL ); } items[i] = NULL; menu = new_menu( items ); set_menu_format( menu, 13, 3 ); scale_menu( menu, &srow, &scol ); menuwin = newwin( srow + 2, scol + 2, linea, col ); set_menu_win( menu, menuwin ); set_menu_sub( menu, derwin( menuwin, srow, scol, 1, 1 ) ); menu_opts_off( menu, O_SHOWDESC ); box( menuwin, 0, 0 ); keypad(menuwin, TRUE); post_menu( menu ); ITEM* selected = NULL; while(!selected){ wrefresh( menuwin ); switch( getch() ){ case 27: selected = (ITEM*)-1; break; case KEY_DOWN: menu_driver(menu, REQ_DOWN_ITEM); break; case KEY_UP: menu_driver(menu, REQ_UP_ITEM); break; case KEY_LEFT: menu_driver(menu, REQ_LEFT_ITEM); break; case KEY_RIGHT: menu_driver(menu, REQ_RIGHT_ITEM); break; case KEY_NPAGE: menu_driver(menu, REQ_SCR_DPAGE); break; case KEY_PPAGE: menu_driver(menu, REQ_SCR_UPAGE); break; case 10: selected = current_item(menu); break; } } if( selected != (ITEM*)-1 ){ ret = strdup( item_name(selected ) ); } else { ret = NULL; } for( i = 0; i < cant; i ++ ){ free( (void*)item_name(items[i]) ); free( items[i] ); } unpost_menu( menu ); free_menu( menu ); borrar_win( menuwin ); return ret; }
WINDOW* vwm_main_menu(void) { extern WINDOW *SCREEN_WINDOW; MENU *menu=NULL; WINDOW *window; gint width=0,height=0; gint screen_height; VWM_MODULE *vwm_module; GSList *category_list=NULL; GSList *module_list=NULL; GSList *node1; GSList *node2; gchar **item_list; gint idx=0; /* allocate storage for 128 menu items */ item_list=(gchar**)g_malloc0(sizeof(gchar*)*(MAX_MENU_ITEMS+1)); item_list[idx]=g_strdup_printf(" "); idx++; category_list=vwm_modules_list_categories(); node1=category_list; while(node1!=NULL && idx<MAX_MENU_ITEMS) { /* skip screensavers */ if(strcmp((gchar*)node1->data,VWM_SCREENSAVER)==0) { node1=node1->next; continue; } /* add the category */ item_list[idx]=g_strdup_printf("%s",(gchar*)node1->data); idx++; if(idx==MAX_MENU_ITEMS) break; module_list=vwm_modules_list((gchar*)node1->data); node2=module_list; while(node2!=NULL) { if(idx==MAX_MENU_ITEMS) break; vwm_module=(VWM_MODULE*)node2->data; item_list[idx]=g_strdup_printf("..%s",vwm_module->title); idx++; node2=node2->next; } /* add a space before the next menu category */ if(idx<MAX_MENU_ITEMS) { item_list[idx]=g_strdup_printf(" "); idx++; } if(module_list!=NULL) g_slist_free(module_list); node1=node1->next; } if(category_list!=NULL) g_slist_free(category_list); menu=viper_menu_create(item_list); while(idx!=-1) { g_free(item_list[idx]); idx--; } g_free(item_list); /* hide character mark on left hand side */ set_menu_mark(menu," "); window_get_size_scaled(SCREEN_WINDOW,NULL,&screen_height,0,0.80); scale_menu(menu,&height,&width); width++; if(width<16) width=16; /* override the default of 1 column X 16 entries per row */ if(height>(screen_height-4)) height=screen_height-4; set_menu_format(menu,height,1); viper_thread_enter(); window=viper_window_create(" Menu ",1,2,width,height,TRUE); /* todo: it would be nice if the user could resize the window (especially in the horizonal direction) and add more columns to the display. right now, it's not a priority (but it would be easy to implement). just need a few lines of code for the event window-resized. for now, just don't allow it */ set_menu_win(menu,window); set_menu_fore(menu,VIPER_COLORS(COLOR_WHITE,COLOR_BLUE) | A_BOLD); set_menu_back(menu,VIPER_COLORS(COLOR_BLACK,COLOR_WHITE)); menu_opts_off(menu,O_NONCYCLIC); post_menu(menu); vwm_menu_marshall(menu,REQ_DOWN_ITEM); /* viper_event_set(window,"window-activate",vwm_main_menu_ON_ACTIVATE,NULL); */ viper_event_set(window,"window-close",vwm_main_menu_ON_CLOSE, (gpointer)menu); viper_window_set_key_func(window,vwm_main_menu_ON_KEYSTROKE); viper_window_set_userptr(window,(gpointer)menu); viper_thread_leave(); return window; }
struct result selection_show(struct selection *selection, WINDOW *parent) { if (!selection) return result_set_system_error(EINVAL); selection->menu = new_menu(selection->items); if (!selection->menu) return result_ncurses_errno(); int menu_height; int menu_width; int code = scale_menu(selection->menu, &menu_height, &menu_width); if (E_OK != code) return result_ncurses_error(code); int title_width = (int)strlen(selection->title) + 1; if (title_width > menu_width) menu_width = title_width; int main_window_height; int main_window_width; getmaxyx(parent, main_window_height, main_window_width); int menu_window_height = menu_height + 4; int menu_window_width = menu_width + 5; int menu_window_y = (main_window_height - menu_window_height) / 2; int menu_window_x = (main_window_width - menu_window_width) / 2; selection->window = newwin(menu_window_height, menu_window_width, menu_window_y, menu_window_x); if (!selection->window) return result_ncurses_err(); code = keypad(selection->window, TRUE); if (ERR == code) return result_ncurses_err(); struct result result = draw_window(selection); if (!result_is_success(result)) return result; code = set_menu_win(selection->menu, selection->window); if (E_OK != code) return result_ncurses_error(code); int menu_sub_height = menu_height; int menu_sub_width = menu_width; int menu_sub_y = 2; int menu_sub_x = 2; selection->sub_window = derwin(selection->window, menu_sub_height, menu_sub_width, menu_sub_y, menu_sub_x); if (!selection->sub_window) return result_ncurses_err(); code = set_menu_sub(selection->menu, selection->sub_window); if (E_OK != code) return result_ncurses_error(code); selection->index = 0; code = post_menu(selection->menu); if (E_OK != code) return result_ncurses_error(code); code = wrefresh(selection->window); if (ERR == code) return result_ncurses_err(); result = get_selection(selection); if (!result_is_success(result)) return result; ITEM *selected_item = current_item(selection->menu); if (selected_item) selection->index = item_index(selected_item); code = unpost_menu(selection->menu); if (E_OK != code) return result_ncurses_error(code); code = wclear(selection->window); if (ERR == code) return result_ncurses_err(); code = wrefresh(selection->window); if (ERR == code) return result_ncurses_err(); code = free_menu(selection->menu); if (E_OK != code) return result_ncurses_error(code); selection->menu = NULL; code = delwin(selection->sub_window); if (E_OK != code) return result_ncurses_error(code); selection->sub_window = NULL; code = delwin(selection->window); if (E_OK != code) return result_ncurses_error(code); selection->window = NULL; return result_success(); }
WINDOW* vwm_main_menu(void) { extern WINDOW *SCREEN_WINDOW; MENU *menu = NULL; WINDOW *window; int width = 0,height = 0; int screen_height; vwm_module_t *vwm_module; char buf[NAME_MAX]; gchar **item_list; int idx = 0; int i; // allocate storage for a total of MAX_MENU_ITEMS item_list = (gchar**)g_malloc0(sizeof(gchar*) * (MAX_MENU_ITEMS + 1)); item_list[idx] = g_strdup_printf(" "); idx++; // iterate through the categories defined in modules.def for(i = 0;i < VWM_MOD_TYPE_MAX;i++) { // skip screensaver type modules. they are a special class. if(i == VWM_MOD_TYPE_SCREENSAVER) continue; // print the menu category (type) to the window item_list[idx] = g_strdup_printf("%s",modtype_desc[i]); idx++; vwm_module = NULL; do { if(idx == MAX_MENU_ITEMS) break; vwm_module = vwm_module_find_by_type(vwm_module,i); if(vwm_module == NULL) break; vwm_module_get_title(vwm_module,buf,sizeof(buf) - 1); item_list[idx] = g_strdup_printf("..%s",buf); idx++; } while(vwm_module != NULL); // add a space before the next menu category if(idx < MAX_MENU_ITEMS) { item_list[idx] = g_strdup_printf(" "); idx++; } } menu = viper_menu_create(item_list); while(idx != -1) { g_free(item_list[idx]); idx--; } g_free(item_list); // hide character mark on left hand side set_menu_mark(menu," "); window_get_size_scaled(SCREEN_WINDOW,NULL,&screen_height,0,0.80); scale_menu(menu,&height,&width); width++; if(width < 16) width = 16; // override the default of 1 column X 16 entries per row if(height>(screen_height-4)) height=screen_height-4; set_menu_format(menu,height,1); viper_thread_enter(); window = viper_window_create(" Menu ",1,2,width,height,TRUE); /* todo: it would be nice if the user could resize the menu (especially in the horizonal direction) and add more columns to the display. right now, it's not a priority (but it would be easy to implement). just need a few lines of code for the event window-resized. for now, just don't allow it */ set_menu_win(menu,window); set_menu_fore(menu,VIPER_COLORS(COLOR_WHITE,COLOR_BLUE) | A_BOLD); set_menu_back(menu,VIPER_COLORS(COLOR_BLACK,COLOR_WHITE)); menu_opts_off(menu,O_NONCYCLIC); post_menu(menu); vwm_menu_marshall(menu,REQ_DOWN_ITEM); /* viper_event_set(window,"window-activate",vwm_main_menu_ON_ACTIVATE,NULL); */ viper_event_set(window,"window-close",vwm_main_menu_ON_CLOSE, (gpointer)menu); viper_window_set_key_func(window,vwm_main_menu_ON_KEYSTROKE); viper_window_set_userptr(window,(gpointer)menu); viper_thread_leave(); return window; }