/* * sends command to the menu */ static int wdg_file_driver(struct wdg_object *wo, int key, struct wdg_mouse_event *mouse) { WDG_WO_EXT(struct wdg_file_handle, ww); int c; struct stat buf; c = menu_driver(ww->m, wdg_file_virtualize(key) ); /* skip non selectable items */ if ( !(item_opts(current_item(ww->m)) & O_SELECTABLE) ) c = menu_driver(ww->m, wdg_file_virtualize(key) ); /* one item has been selected */ if (c == E_UNKNOWN_COMMAND) { /* the item is not selectable (probably selected with mouse) */ if ( !(item_opts(current_item(ww->m)) & O_SELECTABLE) ) return WDG_ESUCCESS; stat(item_name(current_item(ww->m)), &buf); /* if it is a directory, change to it */ if (S_ISDIR(buf.st_mode)) { chdir(item_name(current_item(ww->m))); return -WDG_ENOTHANDLED; } else { /* invoke the callback and return */ wdg_file_callback(wo, ww->curpath, (char *)item_name(current_item(ww->m))); return WDG_ESUCCESS; } } wnoutrefresh(ww->mwin); return WDG_ESUCCESS; }
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); }
static void load_values(struct regedit *regedit) { struct tree_node *node; node = item_userptr(current_item(regedit->keys->menu)); value_list_load(regedit->vl, node->key); }
int mainmenu(int height, int width) { int ret; ITEM **menu_items; MENU *main_menu; int n_choices, i; clean_main_menu(); build_main_menu(instance_path); n_choices = menu_size; menu_items = (ITEM **) calloc(n_choices + 1, sizeof (ITEM *)); for (i = 0; i < n_choices; ++i) { menu_items[i] = new_item(menu_values[i], menu_values[i]); set_item_userptr(menu_items[i], (void *) menu_selected); } menu_items[n_choices] = (ITEM *) NULL; main_menu = new_menu((ITEM **) menu_items); menu_opts_off(main_menu, O_SHOWDESC); set_menu_sub(main_menu, derwin(stdscr, 10, 50, 6, 10)); post_menu(main_menu); attron(A_BOLD); mvprintw(0, 0, name); mvprintw(0, width - strlen(vers), vers); attroff(A_BOLD); refresh(); pos_menu_cursor(main_menu); while ((i = getch()) != KEY_F(4)) { switch (i) { case KEY_DOWN: menu_driver(main_menu, REQ_DOWN_ITEM); break; case KEY_UP: menu_driver(main_menu, REQ_UP_ITEM); break; case 10: { ITEM *cur; int (*p)(char *); cur = current_item(main_menu); p = (int (*)(char *))item_userptr(cur); ret = p((char *) item_name(cur)); pos_menu_cursor(main_menu); goto menu_sel; } } } if (i == KEY_F(4)) { ret = menu_size - 1; } menu_sel: unpost_menu(main_menu); free_menu(main_menu); for (i = 0; i < n_choices; ++i) free_item(menu_items[i]); return ret; }
static void set_app_to_run(void) { ITEM *item = current_item(menu_list); if (item) { open_app_later(g_list_nth_data(results, item_index(item))); } }
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);*/ }
const char* test_list() { gc_list list; initialize_list(&list); for(long i = 1; i < 17; ++i) append_item((os_pointer)i, &list); gc_list_iterator itr; begin_list_iteration(&list, &itr); os_pointer item = 0; long expected = 1; while((item = current_item(&itr))) { if((long)item != expected) return "append item failed"; if((long)item % 2 == 0 || (long)item < 7) remove_item(&itr); advance_item(&itr); ++expected; } for(long i = 16; i < 19; ++i) append_item((os_pointer)i, &list); long expected2[] = {7, 9, 11, 13, 15, 16, 17, 18}; int expected2_idx = 0; begin_list_iteration(&list, &itr); while((item = current_item(&itr))) { if((long)item != expected2[expected2_idx++]) return "remove item failed"; advance_item(&itr); } finalize_list(&list); return "passed"; }
int main() { ITEM **my_items; int c; MENU *my_menu; int n_choices, i; ITEM *cur_item; initscr(); cbreak(); noecho(); keypad(stdscr, TRUE); 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; my_menu = new_menu((ITEM **)my_items); 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 */ cur_item = current_item(my_menu); move(LINES - 2, 0); clrtoeol(); mvprintw(LINES - 2, 0, "You have chosen %d item with name %s and description %s", item_index(cur_item) + 1, item_name(cur_item), item_description(cur_item)); refresh(); pos_menu_cursor(my_menu); break; } } free_item(my_items[0]); free_item(my_items[1]); free_menu(my_menu); endwin(); }
/* this function make sure that the user selection is valid--not a category or white space */ void vwm_menu_marshall(MENU *menu,gint32 key_vector) { gchar *item_text; if(key_vector!=REQ_UP_ITEM && key_vector!=REQ_DOWN_ITEM) return; do { item_text=(gchar*)item_name(current_item(menu)); if(memcmp(item_text,"..",2)==0) break; menu_driver(menu,key_vector); } while(1); return; }
static ITEM * search_menu_backwards (MENU * menu) { char *search_string = NULL; ITEM *result_item = NULL; /* the search string is stored in the menu user pointer */ search_string = (char *) menu_userptr (menu); if (NULL != search_string) { int i = -1; int current_index = -1; ITEM **items = NULL; int found = 0; bool done = FALSE; current_index = item_index (current_item (menu)); items = menu_items (menu); /* start search from the item immediately before the current item */ for (i = current_index - 1; i >= 0 && !found; i--) { found = strstr_nocase (item_description (items[i]), search_string); } if (!found) { int count = -1; count = item_count (menu); /* start search from the end (i.e. wrap around) */ for (i = count - 1; i >= current_index && !found; i--) { found = strstr_nocase (item_description (items[i]), search_string); } } if (found) { result_item = items[i + 1]; } } return result_item; }
//Update left window logic. If enter key was not pressed //return NULL. Otherwise return pointer to selected item. ITEM * main_menu_left(WINDOW * window, MENU * menu){ int c = wgetch(window); switch(c){ case KEY_DOWN: menu_driver(menu, REQ_DOWN_ITEM); wrefresh(window); break; case KEY_UP: menu_driver(menu, REQ_UP_ITEM); wrefresh(window); break; case 10: return current_item(menu); break; } return NULL; }
void column_select_update_menu(ui_t *ui) { // Get panel information column_select_info_t *info = column_select_info(ui); ITEM *current = current_item(info->menu); int top_idx = top_row(info->menu); // Remove the menu from the subwindow unpost_menu(info->menu); // Set menu items set_menu_items(info->menu, info->items); // Put the menu agin into its subwindow post_menu(info->menu); // Move until the current position is set set_top_row(info->menu, top_idx); set_current_item(info->menu, current); }
int main(int argc, char *argv[]) { int ch; initscr(); atexit(quit); clear(); noecho(); curs_set(0); nl(); keypad(stdscr, TRUE); it = (ITEM **)calloc(5, sizeof(ITEM *)); it[0] = new_item("M1", ""); it[1] = new_item("M2", ""); it[2] = new_item("M3", ""); it[3] = new_item("Ende", ""); it[4] = 0; me = new_menu(it); post_menu(me); mvaddstr(7, 3, "Programm mittels Menü oder F2-Funktionstaste beenden"); refresh(); while ((ch = getch()) != KEY_F(2)) { switch (ch) { case KEY_DOWN: menu_driver(me, REQ_DOWN_ITEM); break; case KEY_UP: menu_driver(me, REQ_UP_ITEM); break; case 0xA: if (item_index(current_item(me)) == 3) { exit(0); } break; } } return 0; }
void exec_action_context_services(int ch) { ITEM *item; switch (ch) { case KEY_DOWN: menu_driver(my_menu, REQ_DOWN_ITEM); break; case KEY_UP: menu_driver(my_menu, REQ_UP_ITEM); break; case KEY_ENTER: case 10: item = current_item(my_menu); exec_action(item_userptr(item)); break; } }
gint vwm_fmod_wndlist_ON_KEYSTROKE(gint32 keystroke,WINDOW *window) { MENU *menu=NULL; MEVENT mevent; ITEM *item; // guint32 window_state; menu=(MENU*)viper_window_get_userptr(window); if(keystroke==KEY_MOUSE) { menu_driver(menu,keystroke); getmouse(&mevent); if((mevent.bstate & BUTTON1_DOUBLE_CLICKED)==BUTTON1_DOUBLE_CLICKED) keystroke=KEY_CRLF; } viper_thread_enter(); if(keystroke==KEY_UP) menu_driver(menu,REQ_UP_ITEM); if(keystroke==KEY_DOWN) menu_driver(menu,REQ_DOWN_ITEM); if(keystroke==KEY_CRLF) { item=current_item(menu); /* viper_wnd=(VIPER_WND*)item_userptr(item); */ viper_window_destroy(window); /* if((viper_wnd->window_state & STATE_VISIBLE)==FALSE) viper_window_unhide(viper_wnd->window); viper_window_set_top(viper_wnd->window); viper_window_focus(TOPMOST_WINDOW); */ /* viper_screen_redraw(REDRAW_ALL); */ viper_thread_leave(); return 1; } viper_window_redraw(window); viper_thread_leave(); return 1; }
int item::getUpgradeResult() const { const itemdata& data=itemsbuf[id]; int nextItem=-1; if((data.flags&ITEM_COMBINE)!=0 && current_item(data.family)==data.fam_type) { for(int i=0; i<MAXITEMS; i++) { // Find the item in the same family with the least greater fam_type if(itemsbuf[i].family==data.family && itemsbuf[i].fam_type>data.fam_type) { if(nextItem==-1 || itemsbuf[i].fam_type<=itemsbuf[nextItem].fam_type) nextItem=i; } } } return nextItem; }
/* menu handler */ void menu_handler(void) { int c; keypad(sub_window,TRUE); /* enable keypad on the menu */ wtimeout(sub_window,-1); /* wait for input */ while((c=wgetch(sub_window))) { switch (c) { case KEY_MOUSE: menu_driver(menu_ptr,KEY_MOUSE); break; case 9: /* TAB */ case 'k': case KEY_DOWN: menu_driver(menu_ptr,REQ_DOWN_ITEM); break; case 'j': case KEY_UP: menu_driver(menu_ptr,REQ_UP_ITEM); break; case 27: /* ESC */ case 'q': delete_menu(); finish(0); break; case 13: case KEY_ENTER: case KEY_RIGHT: func_ptr = item_userptr(current_item(menu_ptr)); delete_menu(); return; default: break; } } return; }
static void update_info_bar(void) { if (! results_not_found) { GList *l = g_list_nth( results, item_index(current_item(menu_list)) ); char *path = l->data; clean_info_bar(); char status[100]; snprintf(status, 100, "Results: %d", choices_cnt); mvwprintw(window, MAX_Y - 1, 0, status); mvwprintw(window, MAX_Y, 0, path); } else { clean_info_bar(); } }
/* uh oh, someone hit enter on the files menu! */ int hgd_enter_on_files_menu(struct ui *u) { DPRINTF(HGD_D_INFO, "Selected item on files menu"); char *new_cwd = NULL; ITEM *item; struct dirent *dirent; if ((item = current_item(u->content_menus[HGD_WIN_FILES])) == NULL) { DPRINTF(HGD_D_WARN, "Could not get current item"); return (HGD_FAIL); } dirent = (struct dirent *) item_userptr(item); switch (dirent->d_type) { case DT_DIR: DPRINTF(HGD_D_INFO, "switch cwd: dirent->d_name"); if (strcmp(dirent->d_name, "..") == 0) new_cwd = xstrdup(dirname(u->cwd)); else xasprintf(&new_cwd, "%s/%s", u->cwd, dirent->d_name); free(u->cwd); u->cwd = new_cwd; break; default: hgd_ui_queue_track(u, dirent->d_name); break; }; return (HGD_OK); }
void viewMainMenu() { const int window_nlines = 10, window_ncols = 90; const char *choices[] = { "Team 1: ", "Team 2: ", "Exit", }; 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); // Get the teams (used in menu items). FootBallTeam *team[2]; team[0] = game.getFootBallTeam(FootBallGame::TEAM_ONE); team[1] = game.getFootBallTeam(FootBallGame::TEAM_TWO); String teamName[2]; // Create the menu items int nChoices = ARRAY_SIZE(choices) + 1; ITEM **items = new ITEM* [nChoices]; for (int i = 0; i < 2; i++ ) { if (team[i] == NULL) items[i] = new_item(choices[i], "Empty"); else { teamName[i] = team[i]->getTeamName(); items[i] = new_item(choices[i], teamName[i].c_str()); } } items[2] = new_item(choices[2], NULL); items[nChoices-1] = NULL; // Create the menu MENU *menu = new_menu(items); // Menu options set_menu_mark(menu, NULL); // Attach the menu to the window set_menu_win(menu, window); set_menu_sub(menu, derwin(window, 10, 80, 0, 10)); // Make window and menu visible; post_menu(menu); 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: menu_driver(menu, REQ_DOWN_ITEM); break; case KEY_UP: menu_driver(menu, REQ_UP_ITEM); break; case 10: // Enter // When the user hits enter determine the currently selected // item and do nessary actions. const ITEM *currentItem = current_item(menu); const char *itemName = item_name(currentItem); // Delete allocated data unpost_menu(menu); free_menu(menu); delwin(window); for (int i = 0; i < nChoices; i++) free_item(items[i]); delete[] items; if (strcmp(itemName, choices[2]) == 0) { return; // Edit/View Team 1 } else if (strcmp(itemName, choices[0]) == 0) { restart = true; viewTeam(FootBallGame::TEAM_ONE); // Edit/View Team 2 } else if (strcmp(itemName, choices[1]) == 0) { restart = true; viewTeam(FootBallGame::TEAM_TWO); } } } } }
int main_menu(void) { MENU *my_menu = NULL; ITEM **my_items = NULL; struct tool_instance *list = NULL; const char *ret_msg = NULL; // Init at refresh for first loop. int c = 'R'; do { switch (c) { // Navigate in the menu case KEY_DOWN: case KEY_RIGHT: menu_driver(my_menu, REQ_DOWN_ITEM); break ; case KEY_UP: case KEY_LEFT: menu_driver(my_menu, REQ_UP_ITEM); break ; // Select a migration to monitor case ' ': case 13: // Enter key { if (item_count(my_menu) > 0) { ITEM *curitem = current_item(my_menu); if (view_instance(item_description(curitem)) != EXIT_SUCCESS) { ret_msg = "An error occured while trying to display the tool's data."; } } } // No break here to allow refreshing the list // when coming out of the instance display. // Refresh the list. case 'r': case 'R': if (list) clear_instance_list(list); list = get_instance_list(); if (list == NULL) mvprintw(0, 0, "cloudmig-view: No cloudmig tool is running at the moment.\n"); if (my_menu) clear_menu(my_menu, my_items); my_items = NULL; my_menu = NULL; if (fill_menu(list, &my_items, &my_menu)) return EXIT_FAILURE; post_menu(my_menu); break; // Leave the monitor case 'q': case 'Q': break ; // Ignore the others default: break ; } mvprintw(LINES - 4, 0, "Use <SPACE> or <ENTER> to select the process to monitor."); mvprintw(LINES - 3, 0, " <q> or <Q> to quit this program."); mvprintw(LINES - 2, 0, " <r> or <R> to see refresh the list manually."); if (ret_msg) { mvprintw(LINES -6, 0, "%.*s", COLS, ret_msg); ret_msg = NULL; } refresh(); } while ((c = getch()) != 'q'); return EXIT_FAILURE; }
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; }
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); }
/* * This is called by main.c ncurses_action everytime a popup exists. * It's used to handle characters input in forms and button pressing. */ void popup_driver(int ch) { switch (ch) { case KEY_DOWN: if (is_on_button || !popup_form) break; if (popup_form->current == popup_fields[popup_form->maxfield-1]) switch_to_buttons(); else form_driver(popup_form, REQ_NEXT_FIELD); break; case KEY_UP: if (is_on_button) { if (!popup_form) break; is_on_button = false; set_menu_fore(popup_menu, A_NORMAL); // "hide" the button } else form_driver(popup_form, REQ_PREV_FIELD); break; case KEY_LEFT: if (is_on_button) menu_driver(popup_menu, REQ_LEFT_ITEM); else form_driver(popup_form, REQ_PREV_CHAR); break; case KEY_RIGHT: if (is_on_button) menu_driver(popup_menu, REQ_RIGHT_ITEM); else form_driver(popup_form, REQ_NEXT_CHAR); break; case 10: if (is_on_button) driver_buttons(current_item(popup_menu)); else switch_to_buttons(); break; // Delete the char before cursor case KEY_BACKSPACE: case 127: if (!is_on_button) form_driver(popup_form, REQ_DEL_PREV); break; // Delete the char under the cursor case KEY_DC: if (!is_on_button) form_driver(popup_form, REQ_DEL_CHAR); break; default: if (!is_on_button) form_driver(popup_form, ch); break; } if (popup_menu) { if (is_on_button) pos_menu_cursor(popup_menu); else pos_form_cursor(popup_form); } wrefresh(win_body); }
int main_giris() { ITEM **my_items; int c; MENU *my_menu; int n_choices, i; ITEM *cur_item; WINDOW *my_menu_win; char *anamenu[] = { _("Market ") , _("Current Module"), _("Cheque Module"), _("Stock Module"), _("Reports"), _("Configuration"), _("Help"), _("About"), _("Exit"), (char *)NULL, }; (int) signal (SIGINT, sonlandir); (int) signal (SIGILL, sonlandir); (int) signal (SIGTERM, sonlandir); //backup control yedek_kontrol_et(); initscr(); start_color(); cbreak(); noecho(); keypad(stdscr, TRUE); //sql configuration ayar_dosyasi_oku (); ana_win = newwin(LINES, 80, 0, 0); temizle_win=newwin(LINES, 80, 0, 0); init_pair(1, COLOR_WHITE, COLOR_RED); init_pair(2, COLOR_WHITE, COLOR_BLUE); terminal_kontrol_et(); if (irsaliye_gun_kontrol()) mesaj( _("Some bills not prepared. Don't forget.!") ); kullanici_onayla(); init_pair(1, COLOR_WHITE, COLOR_RED); init_pair(2, COLOR_WHITE, COLOR_BLUE); baslik_goruntule(); n_choices = ARRAY_SIZE(anamenu); my_items = (ITEM **)calloc(n_choices, sizeof(ITEM *)); for(i = 0; i < n_choices; ++i) my_items[i] = new_item(anamenu[i], " "); my_menu = new_menu((ITEM **)my_items); my_menu_win = newwin(15, 50, 5, 10); keypad(my_menu_win, TRUE); set_menu_win(my_menu, my_menu_win); set_menu_sub(my_menu, derwin(my_menu_win, 10, 40, 4, 2)); set_menu_mark(my_menu, mark); box(my_menu_win, 0, 0); print_in_middle(my_menu_win, 1, 0, 45, "Options", COLOR_PAIR(1)); mvwaddch(my_menu_win, 2, 0, ACS_LTEE); mvwhline(my_menu_win, 2, 1, ACS_HLINE, 48); mvwaddch(my_menu_win, 2, 49, ACS_RTEE); post_menu(my_menu); wrefresh(my_menu_win); while((c = wgetch(my_menu_win)) ) { 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: cur_item = current_item(my_menu); switch(item_index(cur_item) + 1) { case 1: /* Kasa satis */ //satis if ( haklari_kontrol_et(0)==1 ) market_ana_ekran(); else {mesaj(_("Access denied.!!!"));} baslik_goruntule(); touchwin(my_menu_win); wrefresh(my_menu_win); baslik_yaz(); refresh(); break; case 2: /*cari*/ //stok giris kontrolu if ( haklari_kontrol_et(0)==1 ) cari(); else {mesaj(_("Access denied.!!!"));} baslik_goruntule(); touchwin(my_menu_win); wrefresh(my_menu_win); baslik_yaz(); refresh(); break; case 3: /*ceksenet*/ //cari giris kontrolu if ( haklari_kontrol_et(1)==1 ) ceksenet(); else {mesaj(_("Access denied.!!!"));} baslik_goruntule(); touchwin(my_menu_win); wrefresh(my_menu_win); baslik_yaz(); refresh(); break; case 4: /*stok*/ //cari giris kontrolu if ( haklari_kontrol_et(1)==1 ) stok(); else {mesaj(_("Access denied.!!!"));} baslik_goruntule(); touchwin(my_menu_win); wrefresh(my_menu_win); baslik_yaz(); refresh(); break; case 5: /*raporlar*/ //rapor giris kontrolu if ( haklari_kontrol_et(2)==1 ) raporlar(); else {mesaj(_("Access denied.!!!"));} baslik_goruntule(); touchwin(my_menu_win); wrefresh(my_menu_win); baslik_yaz(); refresh(); break; case 6: /*ayarlar*/ ayarlar(); baslik_goruntule(); touchwin(my_menu_win); wrefresh(my_menu_win); baslik_yaz(); refresh(); break; case 7:/*yardým*/ yardim(); baslik_goruntule(); touchwin(my_menu_win); wrefresh(my_menu_win); baslik_yaz(); refresh(); break; case 8:/*hakkýnda*/ hakkinda(); baslik_goruntule(); touchwin(my_menu_win); wrefresh(my_menu_win); baslik_yaz(); refresh(); break; case 9:/*Kapat*/ donen_deger=onayla(cikis_onay); if (donen_deger==1) { // donen deger evet ise kapat beep(); touchwin(ana_win); wrefresh(ana_win); unpost_menu(my_menu); free_menu(my_menu); for(i = 0; i < n_choices; ++i) free_item(my_items[i]); endwin(); return; } touchwin(ana_win); wrefresh(ana_win); touchwin(my_menu_win); wrefresh(my_menu_win); break; } wrefresh(my_menu_win); pos_menu_cursor(my_menu); } wrefresh(my_menu_win); } }
/* 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); }
void Menu(int *value) { ITEM **my_items; int c; MENU *my_menu; WINDOW *my_menu_win; int n_choices, i; int output = 3; // Create Menu 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], ""); // Crate Menu my_menu = new_menu((ITEM **)my_items); // Create the window to be associated with the menu my_menu_win = newwin(15, 50, 4, 4); keypad(my_menu_win, TRUE); // Enable keyboard on that window // Set main window and sub window set_menu_win(my_menu, my_menu_win); set_menu_sub(my_menu, derwin(my_menu_win, 6, 38, 3, 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, 50, "THE GAME", COLOR_PAIR(1)); mvwaddch(my_menu_win, 2, 0, ACS_LTEE); mvwhline(my_menu_win, 2, 1, ACS_HLINE, 48); mvwaddch(my_menu_win, 2, 39, ACS_RTEE); /* Post the menu */ post_menu(my_menu); wrefresh(my_menu_win); // Refres the window bool done = false; while(!done && (c = wgetch(my_menu_win)) != 'q' ) { 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 was pressed if(item_index(current_item(my_menu)) == 0) { // First menu item was selected (Play) output = 1; done = true; } if(item_index(current_item(my_menu)) == 1) { // Second menu item was selected (Help)) output = 2; done = true; } if(item_index(current_item(my_menu)) == 2) { // Third menu item was selected (Exit) output = 3; done = true; } break; } wrefresh(my_menu_win); // Refres the window } // 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(); *value = output; }
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; } } } }
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; } } } }