MENU* workspace_create(void) { MENU *menu; const char *choices[] = { "Lpr ", "Edita ", "Visualizza ", "Cerca ", "Help " , }; const char *desc[] = { NULL, NULL, NULL, NULL, NULL, }; menu=menu_create(choices, desc, A_SIZE(choices)); set_menu_format(menu, 1, A_SIZE(choices)); set_menu_fore(menu, COLOR_PAIR(1) | A_REVERSE); set_menu_back(menu, COLOR_PAIR(1)); post_menu(menu); return menu; }
void printMenus() { int i; MENU *fileMenu, *dirMenu; // Create items fileItems = malloc(numFiles * sizeof(ITEM *)); for (i = 0; i < numFiles; i++) { fileItems[i] = new_item(fileEntries[i]->d_name, NULL); if (fileItems[i] == NULL) break; } fileItems[numFiles] = NULL; dirItems = malloc(numDirs * sizeof(ITEM *)); for (i = 0; i < numDirs; i++) { dirItems[i] = new_item(dirEntries[i]->d_name, NULL); if (dirItems[i] == NULL) break; } dirItems[numDirs] = NULL; // Create menus fileMenu = new_menu(fileItems); dirMenu = new_menu(dirItems); menus = malloc(2 * sizeof(MENU *)); menus[0] = fileMenu; menus[1] = dirMenu; if (fileMenu == NULL || dirMenu == NULL) { fprintf(stderr, "Error creating menus\n"); } // Associate windows and menus set_menu_win(fileMenu, cursesWins[0]); set_menu_sub(fileMenu, derwin(cursesWins[0], LINES / 2, (COLS / 2) - 6, 3, 1)); set_menu_format(fileMenu, (LINES / 2), 1); set_menu_win(dirMenu, cursesWins[1]); set_menu_sub(dirMenu, derwin(cursesWins[1], LINES / 2, (COLS / 2) - 6, 3, 1)); set_menu_format(dirMenu, (LINES / 2), 1); post_menu(fileMenu); wrefresh(cursesWins[0]); post_menu(dirMenu); wrefresh(cursesWins[1]); }
void show_chooser_win(MENU *dirmenu, size_t items, char *buf) { int c = 0; size_t buflen, offset = 0; char *tmp; buflen = strlen(buf) - 1; set_menu_fore(dirmenu, A_REVERSE); returnval = set_menu_format(dirmenu, LINES, 1); post_menu(dirmenu); refresh(); while ((c = getch()) != 'q') { switch(c) { case 'j': case KEY_DOWN: menu_driver(dirmenu, REQ_DOWN_ITEM); break; case 'k': case KEY_UP: menu_driver(dirmenu, REQ_UP_ITEM); break; case KEY_NPAGE: menu_driver(dirmenu, REQ_SCR_DPAGE); break; case KEY_PPAGE: menu_driver(dirmenu, REQ_SCR_UPAGE); break; case KEY_END: menu_driver(dirmenu, REQ_LAST_ITEM); break; case KEY_HOME: menu_driver(dirmenu, REQ_FIRST_ITEM); break; case 10: /* Enter */ move(20, 0); clrtoeol(); tmp = (char *)item_name(current_item(dirmenu)); offset = strlcpy(buf, tmp, MAX_CHOICESIZE); if (offset >= MAX_CHOICESIZE) goto toolong; if (strlcpy(buf + offset, item_description(current_item(dirmenu)), MAX_CHOICESIZE - offset)) goto toolong; pos_menu_cursor(dirmenu); break; } } toolong: unpost_menu(dirmenu); fprintf(stdout, "shit happens\n"); fprintf(stdout, "VALUE WAS: %d\n", returnval); }
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; }
void displayMenu(int y, int x, char title[],int numOfOpt, char *options[], void (*p[])(void)){ int i,c; WINDOW *menuWindow; MENU *myMenu; ITEM **myOptions; ITEM *currentOption; initscr(); noecho(); cbreak(); keypad(stdscr,TRUE); init_pair(1,COLOR_CYAN,COLOR_BLACK); myOptions=(ITEM **)calloc(numOfOpt+1,sizeof(ITEM *)); for(i=0;i<numOfOpt;i++){ myOptions[i]=new_item(options[i]," "); set_item_userptr(myOptions[i],p[i]); } myOptions[numOfOpt]=(ITEM *)NULL; myMenu=new_menu(myOptions); menuWindow = newwin(8,20,(LINES-y)/2,(COLS-x)/2); keypad(menuWindow,TRUE); set_menu_win(myMenu,menuWindow); set_menu_sub(myMenu, derwin(menuWindow,y-4,x-2,3,1)); set_menu_format(myMenu,numOfOpt,1); menu_opts_off(myMenu, O_SHOWDESC); set_menu_mark(myMenu," * "); post_menu(myMenu); wrefresh(menuWindow); while((c=wgetch(menuWindow))!=KEY_F(2)){ switch(c){ case KEY_UP: menu_driver(myMenu,REQ_UP_ITEM); break; case KEY_DOWN: menu_driver(myMenu,REQ_DOWN_ITEM); break; case 10:{ ITEM *temp; temp=current_item(myMenu); void(*pointer)(void); pointer=item_userptr(temp); pointer(); pos_menu_cursor(myMenu); menu_driver(myMenu,REQ_DOWN_ITEM); break; } wrefresh(menuWindow); } } /*unpost_menu(myMenu);*/ /*for(i=0;i<numOfOpt;++i){*/ /*free_item(myOptions[i]);*/ /*}*/ /*free_menu(myMenu);*/ /*free(optionsNumbers);*/ }
/*--------------------------------------------------------------------------- | Facility : libnmenu | Function : bool _nc_Connect_Items(MENU *menu, ITEM **items) | | Description : Connect the items in the item array to the menu. | Decorate all the items with a number and a backward | pointer to the menu. | | Return Values : TRUE - successfull connection | FALSE - connection failed +--------------------------------------------------------------------------*/ bool _nc_Connect_Items(MENU *menu, ITEM **items) { ITEM **item; unsigned int ItemCount = 0; if ( menu && items ) { for(item=items; *item ; item++) { if ( (*item)->imenu ) { /* if a item is already connected, reject connection */ break; } } if (! (*item) ) /* we reached the end, so there was no connected item */ { for(item=items; *item ; item++) { if (menu->opt & O_ONEVALUE) { (*item)->value = FALSE; } (*item)->index = ItemCount++; (*item)->imenu = menu; } } } else return(FALSE); if (ItemCount != 0) { menu->items = items; menu->nitems = ItemCount; ComputeMaximum_NameDesc_Lengths(menu); if ( (menu->pattern = (char *)malloc( (unsigned)(1 + menu->namelen))) ) { Reset_Pattern(menu); set_menu_format(menu,menu->frows,menu->fcols); menu->curitem = *items; menu->toprow = 0; return(TRUE); } } /* If we fall through to this point, we have to reset all items connection and inform about a reject connection */ ResetConnectionInfo( menu, items ); return(FALSE); }
set_menu_opts(MENU * menu, Menu_Options opts) { T((T_CALLED("set_menu_opts(%p,%d)"), menu, opts)); opts &= ALL_MENU_OPTS; if (opts & ~ALL_MENU_OPTS) RETURN(E_BAD_ARGUMENT); if (menu) { if (menu->status & _POSTED) RETURN(E_POSTED); if ((opts & O_ROWMAJOR) != (menu->opt & O_ROWMAJOR)) { /* we need this only if the layout really changed ... */ if (menu->items && menu->items[0]) { menu->toprow = 0; menu->curitem = menu->items[0]; assert(menu->curitem); set_menu_format(menu, menu->frows, menu->fcols); } } menu->opt = opts; if (opts & O_ONEVALUE) { ITEM **item; if (((item = menu->items) != (ITEM **) 0)) for (; *item; item++) (*item)->value = FALSE; } if (opts & O_SHOWDESC) /* this also changes the geometry */ _nc_Calculate_Item_Length_and_Width(menu); } else _nc_Default_Menu.opt = opts; RETURN(E_OK); }
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); }
WINDOW *Napravi_menu(int *n_choices, ITEM **items, MENU *menu) { int i, height, width; WINDOW *menu_window; *n_choices = ARRAY_SIZE(choices); items = (ITEM **) calloc(*n_choices, sizeof(ITEM *)); for(i = 0; i < *n_choices; ++i) items[i] = new_item(choices[i], ""); menu = new_menu((ITEM **) items); height = 3; width = 9+7+6; menu_window = newwin(height, width, 16, COLS/2-width/2); //Validiraj_ncurses(keypad(menu_window, TRUE)); set_menu_win(menu, menu_window); set_menu_sub(menu, derwin(menu_window, height-1, width-1, 1, 1)); set_menu_mark(menu, ">"); set_menu_format(menu, 1, 7); menu_opts_off(menu, O_SHOWDESC); box(menu_window, 0, 0); post_menu(menu); Wrefresh(menu_window); return menu_window; }
int set_menu_opts(MENU *m, int opt) { ITEM **ip; if (m) { if (Posted(m)) { return (E_POSTED); } /* Check to see if the ROWMAJOR option is changing. If so, */ /* set top and current to 0. */ if ((opt & O_ROWMAJOR) != RowMajor(m)) { Top(m) = 0; Current(m) = IthItem(m, 0); (void) set_menu_format(m, FRows(m), FCols(m)); } /* if O_NONCYCLIC option changed, set bit to re-link items */ if ((opt & O_NONCYCLIC) != (Mopt(m) & O_NONCYCLIC)) { SetLink(m); } Mopt(m) = opt; if (OneValue(m) && Items(m)) { for (ip = Items(m); *ip; ip++) { /* Unset values if selection not allowed. */ Value(*ip) = FALSE; } } _scale(m); /* Redo sizing information */ } else { Mopt(Dfl_Menu) = opt; } return (E_OK); }
/* * Create and initialize a new popup. popup_btn_action *must* be filled before * this call. * @param rows The number of rows for win_body * @param cols The number of lines for win_body * @param posy Position of the top left corner on the y axis * @param posx Position of the top left corner on the x axis * @param requests An array of strings to put in the form. This can be null: * only the title and the buttons will be present. * @param title A string to print in the popup. */ void popup_new(int rows, int cols, int posy, int posx, char **requests, char *title) { int i, cury = 0, curx = 1, tmp, nb_buttons, nb_fields; WINDOW *inner; win_body = newwin(rows, cols, posy, posx); assert(win_body != NULL && popup_btn_action != NULL); box(win_body, 0, 0); for (nb_buttons = 0; popup_btn_action[nb_buttons]; nb_buttons++); popup_items = malloc(sizeof(ITEM *) * (nb_buttons+1)); assert(popup_items != NULL); assert(popup_btn_action != NULL); for (i = 0; popup_btn_action[i]; i++) { popup_items[i] = new_item(popup_btn_action[i]->key, ""); assert(popup_items[i] != NULL); } popup_items[i] = NULL; popup_menu = new_menu(popup_items); win_menu = derwin(win_body, 3, cols-2, rows-4, 1); assert(popup_menu != NULL && win_menu != NULL); box(win_menu, 0, 0); set_menu_win(popup_menu, win_menu); set_menu_format(popup_menu, 1, nb_buttons); tmp = popup_menu->fcols * (popup_menu->namelen + popup_menu->spc_rows); tmp--; inner = derwin(win_menu, 1, tmp, 1, (cols-3-tmp)/2); assert(inner != NULL); set_menu_sub(popup_menu, inner); set_menu_mark(popup_menu, ""); assert(post_menu(popup_menu) == E_OK); mvwprintw(win_body, 1, 2, "%s", title); for (nb_fields = 0; requests && requests[nb_fields]; nb_fields++); if (nb_fields == 0) { popup_fields = NULL; popup_form = NULL; is_on_button = true; return; } popup_fields = malloc(sizeof(FIELD *) * (nb_fields+1)); assert(popup_fields != NULL); for (i = 0; i < nb_fields && requests[i]; i++) { if (i % 2 == 1) { popup_fields[i] = new_field(1, 41, cury, curx, 0, 0); assert(popup_fields[i] != NULL); set_field_buffer(popup_fields[i], 0, strdup(requests[i])); cury = cury+1; curx = 1; field_opts_on(popup_fields[i], O_ACTIVE); field_opts_on(popup_fields[i], O_EDIT); field_opts_off(popup_fields[i], O_STATIC); set_field_back(popup_fields[i], A_UNDERLINE); } else { popup_fields[i] = new_field(1, 45, cury, curx, 0, 0); assert(popup_fields[i] != NULL); set_field_buffer(popup_fields[i], 0, strdup(requests[i])); curx = strlen(requests[i]) + 2; field_opts_off(popup_fields[i], O_ACTIVE); field_opts_off(popup_fields[i], O_EDIT); } } popup_fields[i] = NULL; popup_form = new_form(popup_fields); assert(popup_form != NULL); win_form = derwin(win_body, rows-6, cols-2, 1, 1); assert(popup_form != NULL && win_form != NULL); assert(set_form_win(popup_form, win_form) == E_OK); int diff_rows = popup_form->cols - win_form->_maxx-2; /* * There isn't enough rows for the form so we resize win_body and * win_form to fit the form. * This resize isn't needed for the lines (as there is always fery few * of them). */ if (diff_rows > 0) { wresize(win_body, win_body->_maxy, win_body->_maxx + diff_rows); wresize(win_form, win_form->_maxy, win_form->_maxx - 2 + diff_rows); } inner = derwin(win_form, win_form->_maxy-2, win_form->_maxx, 2, 0); assert(inner != NULL); set_form_sub(popup_form, inner); assert(post_form(popup_form) == E_OK); is_on_button = false; set_menu_fore(popup_menu, A_NORMAL); // "hide" the button pos_form_cursor(popup_form); }
/* returns 1 if yes, 0 if no */ int confirm(const char *title, const char *text, chtype forecolor, chtype backcolor, int def) { int retval = 0; ITEM **menu_items; MENU *confirm_menu; PANEL *my_panels[1]; WINDOW *confirm_win, *dw; ITEM *cur; int height = 7, width = 25, startx = 5, starty = 5, max_x = 0, max_y = 0; const char *choices[] = {STR_YES, STR_NO}; size_t n_choices = 2, i = 0; int ch, quit = 0; char *print_title; /* safety */ vrmr_fatal_if_null(title); vrmr_fatal_if_null(text); if (width - 4 < (int)StrLen(text)) width = (int)StrLen(text) + 4; if (width - 6 < (int)StrLen(title)) width = (int)StrLen(title) + 6; getmaxyx(stdscr, max_y, max_x); startx = (max_x - width) / 2; starty = (max_y - height) / 2; print_title = malloc(StrMemLen(title) + 3); vrmr_fatal_alloc("malloc", print_title); snprintf(print_title, StrMemLen(title) + 3, " %s ", title); menu_items = (ITEM **)calloc(n_choices + 1, sizeof(ITEM *)); vrmr_fatal_alloc("calloc", menu_items); for (i = 0; i < n_choices; ++i) { menu_items[i] = new_item(choices[i], NULL); } menu_items[n_choices] = (ITEM *)NULL; confirm_menu = new_menu((ITEM **)menu_items); vrmr_fatal_if_null(confirm_menu); confirm_win = newwin(height, width, starty, startx); wbkgd(confirm_win, backcolor); keypad(confirm_win, TRUE); wrefresh(confirm_win); my_panels[0] = new_panel(confirm_win); set_menu_win(confirm_menu, confirm_win); dw = derwin(confirm_win, height - 4, 10, 4, (width) / 2 - 5); set_menu_sub(confirm_menu, dw); set_menu_format(confirm_menu, height - 4, 2); box(confirm_win, 0, 0); print_in_middle(confirm_win, 0, 0, width, print_title, backcolor); print_in_middle(confirm_win, 2, 0, width, text, backcolor); set_menu_back(confirm_menu, backcolor); set_menu_fore(confirm_menu, forecolor); post_menu(confirm_menu); /* set the cursor to the 'no' position */ if (!def) { menu_driver(confirm_menu, REQ_RIGHT_ITEM); } update_panels(); doupdate(); while (quit == 0) { ch = wgetch(confirm_win); switch (ch) { case KEY_DOWN: menu_driver(confirm_menu, REQ_LEFT_ITEM); break; case KEY_UP: menu_driver(confirm_menu, REQ_RIGHT_ITEM); break; case KEY_LEFT: menu_driver(confirm_menu, REQ_LEFT_ITEM); break; case KEY_RIGHT: menu_driver(confirm_menu, REQ_RIGHT_ITEM); break; case 10: // enter { cur = current_item(confirm_menu); vrmr_fatal_if_null(cur); if (strcmp((char *)item_name(cur), STR_YES) == 0) { retval = 1; } quit = 1; break; } case 'y': case 'Y': retval = 1; quit = 1; break; case 'n': case 'N': retval = 0; quit = 1; break; case 27: case KEY_F(10): case 'q': case 'Q': quit = 1; break; } } unpost_menu(confirm_menu); free_menu(confirm_menu); for (i = 0; i < n_choices; ++i) free_item(menu_items[i]); free(menu_items); destroy_win(dw); del_panel(my_panels[0]); destroy_win(confirm_win); free(print_title); update_panels(); doupdate(); return (retval); }
/* * Create a menu of technologies: a selectable list of technologies. * @param jobj format of the json object: [ [ "\/net\/connman\/technology\/wifi", { "Name":"WiFi", "Type":"wifi", "Powered":true, "Connected":false, "Tethering":false } ], [ "\/net\/connman\/technology\/ethernet", { "Name":"Wired", "Type":"ethernet", "Powered":true, "Connected":true, "Tethering":false } ] ] */ static void renderers_technologies(struct json_object *jobj) { int i; char *desc_base = "%-20s Powered %-5s Connected %-5s"; char desc_base_sub[30]; const char *k_name, *k_type, *k_powered, *k_connected; char *desc, *tech_short_name; struct json_object *sub_array, *dbus_tech_name, *tech_dict; struct userptr_data *data; nb_items = json_object_array_length(jobj); main_items = malloc(sizeof(ITEM*) * (nb_items+1)); assert(main_items != NULL && nb_items > 0); for (i = 0; i < nb_items; i++) { sub_array = json_object_array_get_idx(jobj, i); if (!sub_array) continue; dbus_tech_name = json_object_array_get_idx(sub_array, 0); tech_dict = json_object_array_get_idx(sub_array, 1); json_object_object_foreach(tech_dict, key, val) { if (strcmp(key_serv_name, key) == 0) k_name = json_object_get_string(val); else if (strcmp("Type", key) == 0) k_type = json_object_get_string(val); else if (strcmp("Powered", key) == 0) k_powered = json_object_to_json_string(val); else if (strcmp("Connected", key) == 0) k_connected = json_object_to_json_string(val); } snprintf(desc_base_sub, 30, "%s (%s)", k_name, k_type); desc_base_sub[29] = '\0'; desc = malloc(RENDERERS_STRING_MAX_LEN); assert(desc != NULL); snprintf(desc, RENDERERS_STRING_MAX_LEN-1, desc_base, desc_base_sub, k_powered, k_connected); desc[RENDERERS_STRING_MAX_LEN-1] = '\0'; tech_short_name = extract_dbus_short_name(json_object_get_string(dbus_tech_name)); main_items[i] = new_item(tech_short_name, desc); data = malloc(sizeof(struct userptr_data)); assert(data != NULL); data->dbus_name = strdup(json_object_get_string(dbus_tech_name)); data->pretty_name = strdup(k_name); set_item_userptr(main_items[i], data); } main_items[nb_items] = NULL; main_menu = new_menu(main_items); set_menu_win(main_menu, win_body); set_menu_sub(main_menu, derwin(win_body, win_body_lines-2, COLS-4, 3, 2)); set_menu_mark(main_menu, ""); set_menu_format(main_menu, win_body_lines-3, 1); assert(post_menu(main_menu) == E_OK); refresh_home_msg(); wrefresh(win_header); wrefresh(win_body); repos_cursor(); }
void viewNewPlayer(FootBallGame::TeamNumber teamNumber) { const char *itemName; const ITEM *currentItem; const int window_nlines = 10, window_ncols = 90; char *choices[] = { "Add", "Cancel", }; for (;;) { // Create new window. WINDOW *window = newwin(window_nlines, window_ncols, headerWindow_begin_y + headerWindow_nlines + 1, 0); // Set new window options. keypad(window, TRUE); // Create the form fields FIELD *field[6]; for (unsigned i = 0; i < ARRAY_SIZE(field)-1; i++) field[i] = new_field(1, 26, i+2, 23, 0, 0); field[ARRAY_SIZE(field)-1] = NULL; // Set feild options for (unsigned i = 0; i < ARRAY_SIZE(field)-1; i++) { set_field_back(field[i], A_UNDERLINE); field_opts_off(field[i], O_AUTOSKIP); } // Set the field types set_field_type(field[0], TYPE_REGEXP, "^[A-Za-z ]*$"); set_field_type(field[1], TYPE_INTEGER, 0, 1, 999); set_field_type(field[2], TYPE_REGEXP, "^[A-Za-z ]*$"); set_field_type(field[3], TYPE_NUMERIC, 2, 1.00, 1500.00); set_field_type(field[4], TYPE_NUMERIC, 2, 1.00, 300.00); // Create the form FORM *form = new_form(field); set_form_win(form, window); set_form_sub(form, derwin(window, 10, 90, 0, 0)); // Setup the menu items int nChoices = ARRAY_SIZE(choices)+1; ITEM **items = new ITEM* [nChoices]; for (int i = 0; i < nChoices-1; i++) items[i] = new_item(choices[i], NULL); items[nChoices-1] = NULL; // Create the menu MENU *menu = new_menu(items); // Menu options set_menu_format(menu, 1, 2); set_menu_mark(menu, NULL); // Attach the menu to the window set_menu_win(menu, window); set_menu_sub(menu, derwin(window, 1, 20, 8, 17)); // Make window and menu visible; post_form(form); post_menu(menu); mvwprintw(window, 0, 10, "Player Properties: "); mvwprintw(window, 2, 10, "Name: "); mvwprintw(window, 3, 10, "Number: "); mvwprintw(window, 4, 10, "Position: "); mvwprintw(window, 5, 10, "weight (kg): "); mvwprintw(window, 6, 10, "height (cm): "); wrefresh(window); refresh(); // Start user interaction loop. int c; // The restart variable is used to tell the function to rebuild the // menu by starting at the top of the for(;;) loop above. bool restart = false; while (!restart && (c = wgetch(window))) { mvprintw(LINES-1, 0, " "); refresh(); switch(c) { case KEY_DOWN: case 0x09: // Go to next field form_driver(form, REQ_NEXT_FIELD); // GO to the end of the presend buffer // Leaves nicely at the last character form_driver(form, REQ_END_LINE); break; case KEY_UP: // Go to previous field form_driver(form, REQ_PREV_FIELD); form_driver(form, REQ_END_LINE); break; case 0x7F: form_driver(form, REQ_DEL_PREV); break; case KEY_LEFT: menu_driver(menu, REQ_LEFT_ITEM); break; case KEY_RIGHT: menu_driver(menu, REQ_RIGHT_ITEM); break; case 10: // When the user hits enter determine the currently selected // item and do nessary actions. currentItem = current_item(menu); itemName = item_name(currentItem); // Cancel if (strncmp(itemName, choices[1], strlen(choices[1])) == 0) { // Delete allocated data unpost_form(form); unpost_menu(menu); free_form(form); free_menu(menu); for (unsigned i = 0; i < ARRAY_SIZE(field)-1; i++) free_field(field[i]); for (int i = 0; i < nChoices; i++) free_item(items[i]); delete [] items; delwin(window); return; } else if (strncmp(itemName, choices[0], strlen(choices[0])) == 0) { form_driver(form, REQ_VALIDATION); bool invalid = false; for (unsigned i = 0; i < ARRAY_SIZE(field)-1; i++) if (field_status(field[i])==false) invalid = true;; if (invalid == false) { FootBallPlayer *player = new FootBallPlayer; player->setName(field_buffer(field[0], 0)); player->setNumber(atoi(field_buffer(field[1], 0))); player->setPosition(field_buffer(field[2], 0)); player->setWeight(strtof(field_buffer(field[3], 0), NULL)); player->setHeight(strtof(field_buffer(field[4], 0), NULL)); FootBallTeam *team = game.getFootBallTeam(teamNumber); if (team == NULL) { team = new FootBallTeam; game.setFootBallTeam(teamNumber, team); } team->addFootBallPlayer(player); // Delete allocated data unpost_form(form); unpost_menu(menu); free_form(form); free_menu(menu); for (unsigned i = 0; i < ARRAY_SIZE(field)-1; i++) free_field(field[i]); for (int i = 0; i < nChoices; i++) free_item(items[i]); delete [] items; delwin(window); return; } else { mvprintw(LINES-1, 0, "Fill out the form correctly!!"); refresh(); } } break; default: // If this is a normal character, it gets // printed form_driver(form, c); break; } } } }
void viewEditTeamProperties(FootBallGame::TeamNumber teamNumber) { const char *fieldBuffer; const ITEM *currentItem; const char *itemName; ITEM **items; const int window_nlines = 10, window_ncols = 90; char *choices[] = { "Ok", "Cancel", }; for(;;) { // Create new window. WINDOW *window = newwin(window_nlines, window_ncols, headerWindow_begin_y + headerWindow_nlines + 1, 0); // Set new window options. keypad(window, TRUE); // Team the team FootBallTeam *team = game.getFootBallTeam(teamNumber); // Create the form fields FIELD *field[2]; field[0] = new_field(1, 20, 2, 22, 0, 0); field[1] = NULL; // Set feild options set_field_back(field[0], A_UNDERLINE); field_opts_off(field[0], O_AUTOSKIP); set_field_type(field[0], TYPE_REGEXP, "^[A-Za-z ]*$"); if (team) { String teamName = team->getTeamName(); set_field_buffer(field[0], 0, teamName.c_str()); } // Create the form FORM *form = new_form(field); // Attach the form to the window set_form_win(form, window); set_form_sub(form, derwin(window, 4, 90, 0, 0)); // Setup the menu int nChoices = ARRAY_SIZE(choices)+1; items = new ITEM* [nChoices]; for (int i = 0; i < nChoices-1; i++) items[i] = new_item(choices[i], NULL); items[nChoices-1] = NULL; // Create the menu MENU *menu = new_menu(items); // Menu options set_menu_format(menu, 1, 2); set_menu_mark(menu, NULL); // Attach the menu to the window set_menu_win(menu, window); set_menu_sub(menu, derwin(window, 1, 20, 4, 17)); // Make window and menu visible; post_form(form); post_menu(menu); mvwprintw(window, 0, 10, "Team Properties: "); mvwprintw(window, 2, 10, "Team Name: "); wrefresh(window); refresh(); // Start user interaction loop. int c; // The restart variable is used to tell the function to rebuild the // menu by starting at the top of the for(;;) loop above. bool restart = false; while (!restart && (c = wgetch(window))) { switch(c) { case KEY_DOWN: case 0x09: // Go to next field form_driver(form, REQ_NEXT_FIELD); // GO to the end of the presend buffer // Leaves nicely at the last character form_driver(form, REQ_END_LINE); break; case KEY_UP: // Go to previous field form_driver(form, REQ_PREV_FIELD); form_driver(form, REQ_END_LINE); break; case 0x7F: form_driver(form, REQ_DEL_PREV); break; case KEY_LEFT: menu_driver(menu, REQ_LEFT_ITEM); break; case KEY_RIGHT: menu_driver(menu, REQ_RIGHT_ITEM); break; case 10: // Enter // When the user hits enter determine the currently selected // item and do nessary actions. currentItem = current_item(menu); itemName = item_name(currentItem); if (strcmp(itemName, choices[0]) == 0) { form_driver(form, REQ_VALIDATION); fieldBuffer = field_buffer(field[0], 0); if (fieldBuffer != NULL && strcmp(fieldBuffer, "") != 0) { if (team == NULL) { team = new FootBallTeam; game.setFootBallTeam(teamNumber, team); } team->setTeamName(fieldBuffer); } } // Delete allocated data delwin(window); unpost_form(form); free_form(form); unpost_menu(menu); free_menu(menu); for (unsigned i = 0; i < ARRAY_SIZE(field); i++) free_field(field[i]); for (int i = 0; i < nChoices-1; i++) free_item(items[i]); delete[] items; return; default: // If this is a normal character, it gets printed. form_driver(form, c); break; } } } }
static void prepare_for_new_results(Boolean clear) { results_not_found = False; const config_t *conf = config(); clear_menu(clear); choices_cnt = g_list_length(results); if (choices_cnt == 0) { no_results(); } list_items = (ITEM**) calloc(choices_cnt + 1, sizeof(ITEM*)); for (int i = 0; i < choices_cnt; i++) { if (results_not_found) { if (query_len == 0) { list_items[i] = new_item("Start typing to search", ""); } else { list_items[i] = new_item("No results, sorry", ""); } } else { GList *l = g_list_nth(results, i); char *path = l->data; char *name = g_path_get_basename(path); names = g_list_prepend(names, name); if (conf->section_main->numeric_shortcuts) { if (i < 10) { list_items[i] = new_item(digits[i], name); } else list_items[i] = new_item(" ", name); } else { list_items[i] = new_item(name, (char*) NULL); } } } list_items[choices_cnt] = new_item((char*) NULL, (char*) NULL); menu_list = new_menu((ITEM**) list_items); window = newwin( 30, // rows 30, // cols 2, 0 ); keypad(window, TRUE); /* nodelay(window, TRUE); */ set_menu_win(menu_list, window); set_menu_mark(menu_list, ""); set_menu_fore(menu_list, COLOR_PAIR(XS_COLOR_PAIR_1)); set_menu_format(menu_list, 10, 1); post_menu(menu_list); update_info_bar(); refresh(); }
int main() { ITEM **my_items; int c; MENU *my_menu; WINDOW *my_menu_win; int n_choices, i; /* Initialize curses */ initscr(); start_color(); cbreak(); noecho(); keypad(stdscr, TRUE); init_pair(1, COLOR_RED, COLOR_BLACK); init_pair(2, COLOR_CYAN, COLOR_BLACK); /* Create items */ n_choices = ARRAY_SIZE(choices); my_items = (ITEM **)calloc(n_choices, sizeof(ITEM *)); for(i = 0; i < n_choices; ++i) my_items[i] = new_item(choices[i], choices[i]); /* Crate menu */ my_menu = new_menu((ITEM **)my_items); /* Set menu option not to show the description */ menu_opts_off(my_menu, O_SHOWDESC); /* Create the window to be associated with the menu */ my_menu_win = newwin(10, 40, 4, 4); keypad(my_menu_win, TRUE); /* Set main window and sub window */ set_menu_win(my_menu, my_menu_win); set_menu_sub(my_menu, derwin(my_menu_win, 6, 30, 3, 1)); set_menu_format(my_menu, 5, 3); set_menu_mark(my_menu, " * "); /* Print a border around the main window and print a title */ box(my_menu_win, 0, 0); attron(COLOR_PAIR(2)); mvprintw(LINES - 3, 0, "Use PageUp and PageDown to scroll"); mvprintw(LINES - 2, 0, "Use Arrow Keys to navigate (F1 to Exit)"); attroff(COLOR_PAIR(2)); refresh(); /* Post the menu */ post_menu(my_menu); wrefresh(my_menu_win); while((c = wgetch(my_menu_win)) != 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 KEY_LEFT: menu_driver(my_menu, REQ_LEFT_ITEM); break; case KEY_RIGHT: menu_driver(my_menu, REQ_RIGHT_ITEM); break; case KEY_NPAGE: menu_driver(my_menu, REQ_SCR_DPAGE); break; case KEY_PPAGE: menu_driver(my_menu, REQ_SCR_UPAGE); break; } wrefresh(my_menu_win); } /* Unpost and free all the memory taken up */ unpost_menu(my_menu); free_menu(my_menu); for(i = 0; i < n_choices; ++i) free_item(my_items[i]); endwin(); }
void draw_menu(char ** menu_liste, void (*ptrfonction)(int,const char *, char *), char * folder, int taille_menu){ ITEM **my_items; int c; WINDOW *my_menu_win; MENU *my_menu; int i; ITEM *cur_item; my_items = (ITEM **)calloc(taille_menu + 1, sizeof(ITEM *)); int menu_alrdy_dlt = 0; //pour ne pas supprimer le menu 2 fois --> évite les erreur de segmentation lorsqu'on quitte char ** files; //pour le cas ou on utilise F2 (ouvrir un fichier) int num_choix; char choix[FILE_MAX]; for(i = 0; i < taille_menu; ++i){ my_items[i] = new_item(menu_liste[i], ""); //ajoute les éléments dans mon tableau d'item } //my_items[taille_menu+1] = (ITEM *)NULL; //ajoute un item vide à la fin du tableau my_menu = new_menu((ITEM **)my_items); //creer un menu contenan les items mvprintw(LINES - 2, 0, "F9 to close the menu"); //affiche un pied de page pour fermer le menu my_menu_win = newwin(10, 45, (LINES-10)/2, (COLS-45)/2); //créer une nouvelle fenetre keypad(my_menu_win, TRUE); //active le clavier pour le menu /* Set main window and sub window */ set_menu_win(my_menu, my_menu_win); //set main menu set_menu_sub(my_menu, derwin(my_menu_win, 6, 38, 3, 1)); // set sub window set_menu_format(my_menu, 5, 1); /* Set menu mark to the string " * " */ set_menu_mark(my_menu, " * "); /* Print a border around the main window and print a title */ box(my_menu_win, 0, 0); print_in_middle(my_menu_win, 1, 0, 45, "Menu Principal", COLOR_PAIR(1)); mvwaddch(my_menu_win, 2, 0, ACS_LTEE); mvwhline(my_menu_win, 2, 1, ACS_HLINE, 43); mvwaddch(my_menu_win, 2, 44, ACS_RTEE); refresh(); post_menu(my_menu); wrefresh(my_menu_win); while((c = getch()) != KEY_F(9) && c != 27) { switch(c) { case KEY_F(5): mvprintw(LINES-2, 0, "Exiting..."); endwin(); /* End curses mode */ exit(0); case KEY_F(2): files = list_file("", &i); clean_menu(my_menu); clean_window(my_menu_win); draw_menu(files, execute_file_menu, "", i); return; case KEY_DOWN: menu_driver(my_menu, REQ_DOWN_ITEM); break; case KEY_UP: menu_driver(my_menu, REQ_UP_ITEM); break; case KEY_NPAGE: menu_driver(my_menu, REQ_SCR_DPAGE); break; case KEY_PPAGE: menu_driver(my_menu, REQ_SCR_UPAGE); break; case 10: move(20, 0); clrtoeol(); num_choix = item_index(current_item(my_menu)); strcpy(choix, item_name(current_item(my_menu))); //mvprintw(5, 0, "Item selected is : %s", item_name(current_item(my_menu))); clean_menu(my_menu); menu_alrdy_dlt = 1; clean_window(my_menu_win); (*ptrfonction)(num_choix, choix, folder); pos_menu_cursor(my_menu); break; } wrefresh(my_menu_win); } if(menu_alrdy_dlt == 0) clean_menu(my_menu); clean_window(my_menu_win); }
void column_select_create(ui_t *ui) { int attr_id, column; MENU *menu; column_select_info_t *info; // Cerate a new indow for the panel and form ui_panel_create(ui, 20, 60); // Initialize Filter panel specific data info = sng_malloc(sizeof(column_select_info_t)); // Store it into panel userptr set_panel_userptr(ui->panel, (void*) info); // Initialize the fields info->fields[FLD_COLUMNS_ACCEPT] = new_field(1, 10, ui->height - 2, 13, 0, 0); info->fields[FLD_COLUMNS_SAVE] = new_field(1, 10, ui->height - 2, 25, 0, 0); info->fields[FLD_COLUMNS_CANCEL] = new_field(1, 10, ui->height - 2, 37, 0, 0); info->fields[FLD_COLUMNS_COUNT] = NULL; // Field Labels set_field_buffer(info->fields[FLD_COLUMNS_ACCEPT], 0, "[ Accept ]"); set_field_buffer(info->fields[FLD_COLUMNS_SAVE], 0, "[ Save ]"); set_field_buffer(info->fields[FLD_COLUMNS_CANCEL], 0, "[ Cancel ]"); // Create the form and post it info->form = new_form(info->fields); set_form_sub(info->form, ui->win); post_form(info->form); // Create a subwin for the menu area info->menu_win = derwin(ui->win, 10, ui->width - 2, 7, 0); // Initialize one field for each attribute for (attr_id = 0; attr_id < SIP_ATTR_COUNT; attr_id++) { // Create a new field for this column info->items[attr_id] = new_item("[ ]", sip_attr_get_description(attr_id)); set_item_userptr(info->items[attr_id], (void*) sip_attr_get_name(attr_id)); } info->items[SIP_ATTR_COUNT] = NULL; // Create the columns menu and post it info->menu = menu = new_menu(info->items); // Set current enabled fields // FIXME Stealing Call list columns :/ call_list_info_t *list_info = call_list_info(ui_find_by_type(PANEL_CALL_LIST)); // Enable current enabled fields and move them to the top for (column = 0; column < list_info->columncnt; column++) { const char *attr = list_info->columns[column].attr; for (attr_id = 0; attr_id < item_count(menu); attr_id++) { if (!strcmp(item_userptr(info->items[attr_id]), attr)) { column_select_toggle_item(ui, info->items[attr_id]); column_select_move_item(ui, info->items[attr_id], column); break; } } } // Set main window and sub window set_menu_win(menu, ui->win); set_menu_sub(menu, derwin(ui->win, 10, ui->width - 5, 7, 2)); set_menu_format(menu, 10, 1); set_menu_mark(menu, ""); set_menu_fore(menu, COLOR_PAIR(CP_DEF_ON_BLUE)); menu_opts_off(menu, O_ONEVALUE); post_menu(menu); // Draw a scrollbar to the right info->scroll = ui_set_scrollbar(info->menu_win, SB_VERTICAL, SB_RIGHT); info->scroll.max = item_count(menu) - 1; ui_scrollbar_draw(info->scroll); // Set the window title and boxes mvwprintw(ui->win, 1, ui->width / 2 - 14, "Call List columns selection"); wattron(ui->win, COLOR_PAIR(CP_BLUE_ON_DEF)); title_foot_box(ui->panel); mvwhline(ui->win, 6, 1, ACS_HLINE, ui->width - 1); mvwaddch(ui->win, 6, 0, ACS_LTEE); mvwaddch(ui->win, 6, ui->width - 1, ACS_RTEE); wattroff(ui->win, COLOR_PAIR(CP_BLUE_ON_DEF)); // Some brief explanation abotu what window shows wattron(ui->win, COLOR_PAIR(CP_CYAN_ON_DEF)); mvwprintw(ui->win, 3, 2, "This windows show the list of columns displayed on Call"); mvwprintw(ui->win, 4, 2, "List. You can enable/disable using Space Bar and reorder"); mvwprintw(ui->win, 5, 2, "them using + and - keys."); wattroff(ui->win, COLOR_PAIR(CP_CYAN_ON_DEF)); info->form_active = 0; }
void sfm_ncurses(void) { int x; sfm_ncurses_win *iface = malloc(sizeof(sfm_ncurses_win)); char root_items[FILENAME_MAX]; int user_input; WINDOW *current_window; ITEM **ncmenu_items = NULL; MENU *sfm_menu; initscr(); start_color(); noecho(); cbreak(); getmaxyx(stdscr, iface->lines, iface->cols); refresh(); iface->sfmncmenu = newwin(3, iface->cols-1, iface->lines-5, 0); keypad(iface->sfmncmenu, TRUE); wmove(iface->sfmncmenu, 1, 1); box(iface->sfmncmenu, 0, 0); ncmenu_items = malloc((menu_choices_n+1) * sizeof(ITEM *)); for (x = 0; x < menu_choices_n; x++) ncmenu_items[x] = new_item(menu_choices[x], menu_choices[x]); //ncmenu_items[menu_choices_n] = (ITEM *)NULL; sfm_menu = new_menu((ITEM **)ncmenu_items); menu_opts_off(sfm_menu, O_SHOWDESC); set_menu_format(sfm_menu, 1, menu_choices_n); set_menu_mark(sfm_menu, " "); set_menu_win(sfm_menu, iface->sfmncmenu); set_menu_sub(sfm_menu, derwin(iface->sfmncmenu, 1, iface->cols-2, 1, 1)); post_menu(sfm_menu); wrefresh(iface->sfmncmenu); iface->sfmnroot = newwin(iface->lines-6, iface->cols-4, 0, 0); snprintf(root_items, sizeof(root_items)-1, "%-40s . %-6s . %-4s . %-3s . %-10s", "FILENAME", "SIZE", "TYPE", "UID", "PERMISSIONS"); wattron(iface->sfmnroot, A_REVERSE|A_BOLD); wprintw(iface->sfmnroot, root_items); wattroff(iface->sfmnroot, A_REVERSE|A_BOLD); for (x = 1; x < (iface->lines - 6); x++) { snprintf(root_items, sizeof(root_items)-1, "Item line %2d . 55Kb . .PDF . 100 . -rw-r--r--", x); mvwprintw(iface->sfmnroot, x, 0, root_items); } wrefresh(iface->sfmnroot); iface->sfmnstatus = newwin(1, iface->cols-1, iface->lines-2, 1); wprintw(iface->sfmnstatus, ":. Hello! Welcome to .: %s :. lines:%d, cols:%d", SFM_VSN, iface->lines, iface->cols); wrefresh(iface->sfmnstatus); current_window = iface->sfmncmenu; while (1) { user_input = wgetch(current_window); switch (user_input) { case KEY_LEFT: menu_driver(sfm_menu, REQ_LEFT_ITEM); break; case KEY_RIGHT: menu_driver(sfm_menu, REQ_RIGHT_ITEM); break; case KEY_UP: break; case KEY_DOWN: break; case 9: if (current_window == iface->sfmncmenu) current_window = iface->sfmnroot; else current_window = iface->sfmncmenu; keypad(current_window, TRUE); break; case 10: { //ITEM *cur; //cur = current_item(sfm_menu); } break; case 'Q': case 'q': wclear(iface->sfmnstatus); wprintw(iface->sfmnstatus, ":. Are you sure you want to quit!? [Y/N] "); wrefresh(iface->sfmnstatus); user_input = wgetch(iface->sfmnstatus); switch (user_input) { case 'y': case 'Y': case 's': case 'S': wclear(iface->sfmnstatus); wprintw(iface->sfmnstatus, ":. Thanks for using SFM! :) Quitting..."); wrefresh(iface->sfmnstatus); sleep(1); goto sfm_ncurses_exit; default: break; } } wclear(iface->sfmnstatus); wprintw(iface->sfmnstatus, ":. status: %d", user_input); wrefresh(iface->sfmnstatus); } sfm_ncurses_exit: delwin(iface->sfmnroot); delwin(iface->sfmnstatus); delwin(iface->sfmncmenu); unpost_menu(sfm_menu); free_menu(sfm_menu); for (x = 0; x < menu_choices_n; x++) free_item(ncmenu_items[x]); free(ncmenu_items); free(iface); refresh(); endwin(); }
void createMenus() { int i; /* create menu items */ mainMenuItems = (ITEM**)calloc(5, sizeof(ITEM*)); mainMenuItems[0] = new_item("Operating Mode", ""); set_item_userptr(mainMenuItems[0], (void*)MENU_ITEM_OPMODE); mainMenuItems[1] = new_item("Spectra", ""); set_item_userptr(mainMenuItems[1], (void*)MENU_ITEM_SPECTRA); mainMenuItems[2] = new_item("Invariants", ""); set_item_userptr(mainMenuItems[2], (void*)MENU_ITEM_INVARIANTS); mainMenuItems[3] = new_item("Exit", ""); set_item_userptr(mainMenuItems[3], (void*)MENU_ITEM_EXIT); mainMenuItems[4] = new_item(NULL, NULL); opmodeMenuItems = (ITEM**)calloc(3, sizeof(ITEM*)); opmodeMenuItems[0] = new_item("Training", ""); set_item_userptr(opmodeMenuItems[0], (void*)MENU_ITEM_TRAINING); opmodeMenuItems[1] = new_item("Testing", ""); set_item_userptr(opmodeMenuItems[1], (void*)MENU_ITEM_TESTING); opmodeMenuItems[2] = new_item(NULL, NULL); spectraMenuItems = (ITEM**)calloc(guiProgramData->nSpectra+1, sizeof(ITEM*)); for(i=0; i<guiProgramData->nSpectra; i++) { char *spectrumInfo = (char*)malloc(64); sprintf(spectrumInfo, "%-20s | %5d", getSpectrum(guiProgramData, i)->name, getSpectrum(guiProgramData, i)->nComponents); spectraMenuItems[i] = new_item(spectrumInfo, ""); } spectraOpMenuItems = (ITEM**)calloc(3, sizeof(ITEM*)); spectraOpMenuItems[0] = new_item("Inspect data", ""); set_item_userptr(spectraOpMenuItems[0], (void*)MENU_ITEM_DATA); spectraOpMenuItems[1] = new_item("Perform SFL analysis", ""); set_item_userptr(spectraOpMenuItems[1], (void*)MENU_ITEM_SFL); spectraOpMenuItems[2] = new_item(NULL, NULL); sflCoeffMenuItems = (ITEM**)calloc(3, sizeof(ITEM*)); sflCoeffMenuItems[0] = new_item("Ochiai", ""); set_item_userptr(sflCoeffMenuItems[0], (void*)S_OCHIAI); sflCoeffMenuItems[1] = new_item("Jaccard", ""); set_item_userptr(sflCoeffMenuItems[1], (void*)S_JACCARD); sflCoeffMenuItems[2] = new_item("Tarantula", ""); set_item_userptr(sflCoeffMenuItems[1], (void*)S_TARANTULA); sflCoeffMenuItems[3] = new_item(NULL, NULL); invariantTypesMenuItems = (ITEM**)calloc(guiProgramData->nInvariantTypes+1, sizeof(ITEM*)); for(i=0; i<guiProgramData->nInvariantTypes; i++) { char *invariantTypeInfo = (char*)malloc(64); sprintf(invariantTypeInfo, "%-20s | %5d", getInvariantType(guiProgramData, i)->name, getInvariantType(guiProgramData, i)->nInvariants); invariantTypesMenuItems[i] = new_item(invariantTypeInfo, ""); } /*create actual menus*/ mainMenu = new_menu((ITEM**)mainMenuItems); set_menu_win(mainMenu, mainMenuWin); set_menu_sub(mainMenu, derwin(mainMenuWin, 10,16, 1,1)); set_menu_format(mainMenu, 10,1); box(mainMenuWin, 0, 0); post_menu(mainMenu); opmodeMenu = new_menu((ITEM**)opmodeMenuItems); set_menu_win(opmodeMenu, opmodeMenuWin); set_menu_format(opmodeMenu, 10,1); post_menu(opmodeMenu); spectraMenu = new_menu((ITEM**)spectraMenuItems); set_menu_win(spectraMenu, spectraMenuWin); set_menu_format(spectraMenu, 10,1); post_menu(spectraMenu); spectraOpMenu = new_menu((ITEM**)spectraOpMenuItems); set_menu_win(spectraOpMenu, spectraOpMenuWin); set_menu_format(spectraOpMenu, 10,1); post_menu(spectraOpMenu); sflCoeffMenu = new_menu((ITEM**)sflCoeffMenuItems); set_menu_win(sflCoeffMenu, sflCoeffMenuWin); set_menu_format(sflCoeffMenu, 10,1); post_menu(sflCoeffMenu); invariantTypesMenu = new_menu((ITEM**)invariantTypesMenuItems); set_menu_win(invariantTypesMenu, invariantTypesMenuWin); set_menu_format(invariantTypesMenu, 10,1); post_menu(invariantTypesMenu); }
void refreshInvariantsList() { if(guiSelectedInvariantType >= 0) { int i; _InvariantType *it; /* free existing menus */ if(invariantsMenuItemsScr) { i=0; while(item_name(invariantsMenuItemsScr[i]) != NULL) { free_item(invariantsMenuItemsScr[i]); i++; } free(invariantsMenuItemsScr); } if(invariantsMenuScr) { free_menu(invariantsMenuScr); } if(invariantsMenuItemsRng) { i=0; while(item_name(invariantsMenuItemsRng[i]) != NULL) { free_item(invariantsMenuItemsRng[i]); i++; } free(invariantsMenuItemsRng); } if(invariantsMenuRng) { free_menu(invariantsMenuRng); } if(invariantsMenuItemsBmsk) { i=0; while(item_name(invariantsMenuItemsBmsk[i]) != NULL) { free_item(invariantsMenuItemsBmsk[i]); i++; } free(invariantsMenuItemsBmsk); } if(invariantsMenuBmsk) { free_menu(invariantsMenuBmsk); } /* create new menus */ it = getInvariantType(guiProgramData, guiSelectedInvariantType); invariantsMenuItemsScr = (ITEM**)calloc(it->nInvariants+1, sizeof(ITEM*)); invariantsMenuItemsRng = (ITEM**)calloc(it->nInvariants+1, sizeof(ITEM*)); invariantsMenuItemsBmsk = (ITEM**)calloc(it->nInvariants+1, sizeof(ITEM*)); for(i=0; i<it->nInvariants; i++) { char *invariantInfoScr = (char*)malloc(512); char *invariantInfoRng = (char*)malloc(512); char *invariantInfoBmsk = (char*)malloc(512); sprintf(invariantInfoScr, "%5d ", i); sprintf(invariantInfoRng, "%5d ", i); sprintf(invariantInfoBmsk, "%5d ", i); invariantToString(&invariantInfoScr[7], &it->data[i], INV_MODE_SCREENER); invariantToString(&invariantInfoRng[7], &it->data[i], INV_MODE_RANGE); invariantToString(&invariantInfoBmsk[7], &it->data[i], INV_MODE_BITMASK); invariantsMenuItemsScr[i] = new_item(invariantInfoScr, ""); invariantsMenuItemsRng[i] = new_item(invariantInfoRng, ""); invariantsMenuItemsBmsk[i] = new_item(invariantInfoBmsk, ""); } invariantsMenuItemsScr[it->nInvariants] = new_item(NULL, NULL); invariantsMenuItemsRng[it->nInvariants] = new_item(NULL, NULL); invariantsMenuItemsBmsk[it->nInvariants] = new_item(NULL, NULL); invariantsMenuScr = new_menu((ITEM**)invariantsMenuItemsScr); invariantsMenuRng = new_menu((ITEM**)invariantsMenuItemsRng); invariantsMenuBmsk = new_menu((ITEM**)invariantsMenuItemsBmsk); set_menu_win(invariantsMenuScr, derwin(invariantsMenuWinScr, 10,54,1,1)); set_menu_win(invariantsMenuRng, derwin(invariantsMenuWinRng, 10,54,1,1)); set_menu_win(invariantsMenuBmsk, derwin(invariantsMenuWinBmsk, 10,54,1,1)); set_menu_format(invariantsMenuScr, 10,1); set_menu_format(invariantsMenuRng, 10,1); set_menu_format(invariantsMenuBmsk, 10,1); post_menu(invariantsMenuScr); post_menu(invariantsMenuRng); post_menu(invariantsMenuBmsk); } }
/* * Menu format get/set functions - menu_format(3X) man page */ static VALUE rbncurs_c_set_menu_format(VALUE rb_menu, VALUE rows, VALUE cols) { MENU *menu = get_menu(rb_menu); return INT2NUM(set_menu_format(menu, NUM2INT(rows), NUM2INT(cols))); }
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; }
int btn_dialog(WINDOW *main_window, const char *msg, int btn_num, ...) { va_list ap; char *btn; int btns_width = 0; int msg_lines = 0; int msg_width = 0; int total_width; int win_rows = 0; WINDOW *win; WINDOW *msg_win; WINDOW *menu_win; MENU *menu; ITEM *btns[btn_num+1]; int i, x, y; int res = -1; va_start(ap, btn_num); for (i = 0; i < btn_num; i++) { btn = va_arg(ap, char *); btns[i] = new_item(btn, ""); btns_width += strlen(btn)+1; } va_end(ap); btns[btn_num] = NULL; /* find the widest line of msg: */ msg_lines = get_line_no(msg); for (i = 0; i < msg_lines; i++) { const char *line = get_line(msg, i); int len = get_line_length(line); if (msg_width < len) msg_width = len; } total_width = max(msg_width, btns_width); /* place dialog in middle of screen */ y = (LINES-(msg_lines+4))/2; x = (COLS-(total_width+4))/2; /* create the windows */ if (btn_num > 0) win_rows = msg_lines+4; else win_rows = msg_lines+2; win = newwin(win_rows, total_width+4, y, x); keypad(win, TRUE); menu_win = derwin(win, 1, btns_width, win_rows-2, 1+(total_width+2-btns_width)/2); menu = new_menu(btns); msg_win = derwin(win, win_rows-2, msg_width, 1, 1+(total_width+2-msg_width)/2); set_menu_fore(menu, attributes[DIALOG_MENU_FORE]); set_menu_back(menu, attributes[DIALOG_MENU_BACK]); wattrset(win, attributes[DIALOG_BOX]); box(win, 0, 0); /* print message */ wattrset(msg_win, attributes[DIALOG_TEXT]); fill_window(msg_win, msg); set_menu_win(menu, win); set_menu_sub(menu, menu_win); set_menu_format(menu, 1, btn_num); menu_opts_off(menu, O_SHOWDESC); menu_opts_off(menu, O_SHOWMATCH); menu_opts_on(menu, O_ONEVALUE); menu_opts_on(menu, O_NONCYCLIC); set_menu_mark(menu, ""); post_menu(menu); touchwin(win); refresh_all_windows(main_window); while ((res = wgetch(win))) { switch (res) { case KEY_LEFT: menu_driver(menu, REQ_LEFT_ITEM); break; case KEY_RIGHT: menu_driver(menu, REQ_RIGHT_ITEM); break; case 10: /* ENTER */ case 27: /* ESCAPE */ case ' ': case KEY_F(F_BACK): case KEY_F(F_EXIT): break; } touchwin(win); refresh_all_windows(main_window); if (res == 10 || res == ' ') { res = item_index(current_item(menu)); break; } else if (res == 27 || res == KEY_F(F_BACK) || res == KEY_F(F_EXIT)) { res = KEY_EXIT; break; } } unpost_menu(menu); free_menu(menu); for (i = 0; i < btn_num; i++) free_item(btns[i]); delwin(win); return res; }
/* * 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); }
void display_execution(int num_instruction, mot * tab_mot_instruction, int nb_instruction, int* registres,int nb_reg, int PC, int SP, int SR){ ITEM *item_en_cour = NULL; char ** tab_instruction; // for instructions ITEM **instructions_items; int c; WINDOW *instructions_win; MENU *instruction_menu; int i; instructions_items = (ITEM **)calloc(nb_instruction + 1, sizeof(ITEM *)); int menu_instruction_alrdy_dlt = 0; //pour ne pas supprimer le menu 2 fois --> évite les erreur de segmentation lorsqu'on quitte char ** files; //in case of F2 // for register char ** tab_register; ITEM **register_items; WINDOW *register_win; MENU *register_menu; register_items = (ITEM **)calloc(nb_reg + 1 +3, sizeof(ITEM *)); //+3 pour PC SP et SR int menu_register_alrdy_dlt = 0; //pour ne pas supprimer le menu 2 fois --> évite les erreur de segmentation lorsqu'on quitte char dest_string[5]; char source_string[5]; char brut_string[10]; char pc_string[6], sp_string[6], sr_string[6]; int is_brut = 0; //si le mot précedent contient un mode direct, alors le mot suivant est un brut //si DIRIMM les 2 suivant sont des brut //allocation de mémoire pour les insctruction sous forme de chaine tab_instruction = (char**) malloc (nb_instruction* sizeof(char*)); //allocation de mémoire pour le tabeau de registre sous forme de string tab_register = (char**) malloc (nb_reg* sizeof(char *)); int num_choix; char * choix = NULL; for(i = 0; i < nb_instruction; ++i){ tab_instruction[i] = malloc(50 * sizeof(char)); //plus simple pour le moment, une instruction ne peut dépasser 50caractères ... a améliorer si assez de temps if(is_brut == 0){ sprintf(dest_string, "%d", tab_mot_instruction[i].codage.dest); sprintf(source_string, "%d", tab_mot_instruction[i].codage.source); //si l'instruction contient une source ou destination en mode immediat ou direct, la prochaine instruction sera un brut if(is_brut==2 || tab_mot_instruction[i].codage.mode == REGIMM || tab_mot_instruction[i].codage.mode == INDIMM || tab_mot_instruction[i].codage.mode == REGDIR || tab_mot_instruction[i].codage.mode == DIRREG){ is_brut = 1; } if(tab_mot_instruction[i].codage.mode == DIRIMM){ is_brut = 2; } strcpy(tab_instruction[i], codeop_tostring(tab_mot_instruction[i].codage.codeop) ); //on met tout les élément sous forme de string concaténé et espacé strcat(tab_instruction[i], " "); strcat(tab_instruction[i], mode_tostring(tab_mot_instruction[i].codage.mode)); strcat(tab_instruction[i], " "); strcat(tab_instruction[i], dest_string); strcat(tab_instruction[i], " "); strcat(tab_instruction[i], source_string); } else{ sprintf(brut_string, "%d", tab_mot_instruction[i].brut); strcpy(tab_instruction[i], brut_string ); if(is_brut == 2){ is_brut = 1; // cas du DIRIMM } else{ is_brut = 0; } } //mvprintw(i+2, 0, "%s", tab_instruction[i]); instructions_items[i] = new_item(tab_instruction[i], ""); //ajoute les éléments dans mon tableau d'item if(i == num_instruction){ //on sauvegarde l'adresse de l'item que l'on est entrain de traiter (celui donner par num_instruction) item_en_cour = instructions_items[i]; //n le desactive, cela permet de lui doonner une autre apparence pur le repérer item_opts_off(instructions_items[i], O_SELECTABLE); } } for(i = 0; i < nb_reg; ++i){ //contient le registre sous forme de string par exemple R1 ou PC tab_register[i] = malloc(3 * sizeof(char)); sprintf(tab_register[i], "R%i: %d",i, registres[i]); //mvprintw(i+2, 0, "%s", tab_instruction[i]); register_items[i] = new_item(tab_register[i], ""); //ajoute les éléments dans mon tableau d'item } sprintf(pc_string, "%d", PC); sprintf(sp_string, "%d", SP); sprintf(sr_string, "%d", SR); register_items[nb_reg] = new_item("PC:", pc_string); //register_items[8] register_items[nb_reg+1] = new_item("SP:", sp_string); //register_items[9] register_items[nb_reg+2] = new_item("SR:", sr_string); //register_items[10] //pour cacher la selection du premier registre item_opts_off(register_items[0], O_SELECTABLE); instruction_menu = new_menu((ITEM **)instructions_items); //creer un menu contenant les instructions register_menu = new_menu((ITEM **)register_items); //creer un menu contenant les registres mvprintw(LINES - 2, 0, "F9 to close the menu"); instructions_win = newwin((LINES-4)/2, 40 , 3, (COLS/2)- (COLS-4)/4); //créer une nouvelle fenetre pour les instructions register_win = newwin(16, 20 , 3, (COLS/2) + 10); //créer une nouvelle fenetre pour les registres keypad(instructions_win, TRUE); //active le clavier sur les instructions /* Set main window and sub window */ set_menu_win(instruction_menu, instructions_win); //set main menu set_menu_sub(instruction_menu, derwin(instructions_win, ((LINES-4)/2)-4, 38, 3, 1)); // set sub window set_menu_format(instruction_menu, ((LINES-4)/2)-4, 1); set_menu_win(register_menu, register_win); //set main menu set_menu_sub(register_menu, derwin(register_win, 13, 18, 3, 1)); // set sub window set_menu_format(register_menu, 13, 1); /* Set menu mark to the string " * " */ set_menu_mark(instruction_menu, " * "); set_menu_mark(register_menu, ""); /* Print a border around the main window and print a title */ box(instructions_win, 0, 0); print_in_middle(instructions_win, 1, 0, 40, "liste des instructions", COLOR_PAIR(1)); mvwaddch(instructions_win, 2, 0, ACS_LTEE); mvwhline(instructions_win, 2, 1, ACS_HLINE, 43); mvwaddch(instructions_win, 2, 39, ACS_RTEE); box(register_win, 0, 0); print_in_middle(register_win, 1, 0, 20, "Registres", COLOR_PAIR(1)); mvwaddch(register_win, 2, 0, ACS_LTEE); mvwhline(register_win, 2, 1, ACS_HLINE, 22); mvwaddch(register_win, 2, 19, ACS_RTEE); refresh(); post_menu(instruction_menu); post_menu(register_menu); //on se place sur l'instruction en cour set_current_item (instruction_menu, item_en_cour); wrefresh(instructions_win); wrefresh(register_win); while((c = getch()) != KEY_F(9) && c != 32) { switch(c) { case KEY_F(5): mvprintw(LINES-2, 0, "Exiting..."); endwin(); /* End curses mode */ exit(0); case KEY_F(2): files = list_file("", &i); draw_menu(files, execute_file_menu, "", i); case KEY_DOWN: menu_driver(instruction_menu, REQ_DOWN_ITEM); break; case KEY_UP: menu_driver(instruction_menu, REQ_UP_ITEM); break; //case KEY_NPAGE: // menu_driver(my_menu, REQ_SCR_DPAGE); // break; //case KEY_PPAGE: // menu_driver(my_menu, REQ_SCR_UPAGE); // break; case 10: move(20, 0); clrtoeol(); break; } wrefresh(instructions_win); } if(menu_instruction_alrdy_dlt == 0){ clean_menu(instruction_menu); clean_window(instructions_win); } if(menu_register_alrdy_dlt == 0){ clean_menu(register_menu); clean_window(register_win); } }
/* * 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; } }
void viewPlayer(FootBallTeam *team, const String &name, int pid) { const char *itemName; const ITEM *currentItem; String playerName, playerPosition; float height, weight; int number; const int window_nlines = 20, window_ncols = 90; char *choices[] = { "Ok", "Delete", }; for(;;) { FootBallPlayer *player = (FootBallPlayer*)team->getPlayer(name, pid); if (player) { player->getName(playerName); player->getPosition(playerPosition); height = player->getHeight(); weight = player->getWeight(); number = player->getNumber(); } else { playerName = ""; playerPosition = ""; height = -1; weight = -1; number = -1; } // Create new window. WINDOW *window = newwin(window_nlines, window_ncols, headerWindow_begin_y + headerWindow_nlines + 1, 0); // Set new window options. keypad(window, TRUE); // Setup the menu int nChoices = ARRAY_SIZE(choices)+1; ITEM **items = new ITEM* [nChoices]; for (int i = 0; i < nChoices; i++) items[i] = new_item(choices[i], NULL); items[nChoices-1] = NULL; // Create the menu MENU *menu = new_menu(items); // Menu options set_menu_format(menu, 1, 2); set_menu_mark(menu, NULL); // Attach the menu to the window set_menu_win(menu, window); set_menu_sub(menu, derwin(window, 1, 20, 7, 17)); // Make window and menu visible; post_menu(menu); mvwprintw(window, 0, 10, "Name: %s\n", playerName.c_str()); mvwprintw(window, 1, 10, "Number: %d\n", number); mvwprintw(window, 2, 10, "Position: %s\n", playerPosition.c_str()); mvwprintw(window, 3, 10, "Height: %.2fcm\n", height); mvwprintw(window, 4, 10, "Weight: %.2fkg\n", weight); wrefresh(window); refresh(); // Start user interaction loop. int c; // The restart variable is used to tell the function to rebuild the // menu by starting at the top of the for(;;) loop above. bool restart = false; while (!restart && (c = wgetch(window))) { switch(c) { case KEY_LEFT: menu_driver(menu, REQ_LEFT_ITEM); break; case KEY_RIGHT: menu_driver(menu, REQ_RIGHT_ITEM); break; case 10: currentItem = current_item(menu); itemName = item_name(currentItem); refresh(); if (strcmp(itemName, choices[1]) == 0) team->removePlayer(playerName, pid); // Delete allocated data unpost_menu(menu); free_menu(menu); for (int i = 0; i < nChoices; i++) free_item(items[i]); delete[] items; delwin(window); return; } } } }
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; }