virtual BOOL on_key(HELEMENT he, HELEMENT target, UINT event_type, UINT code, UINT keyboardStates ) { if( event_type == KEY_DOWN ) { dom::element ctl = he; switch( code ) { case VK_DOWN: { dom::element c = ctl.find_first(":current"); int idx = c.is_valid()? (c.index() + 1):0; if( idx < (int)ctl.children_count() ) { dom::element nc = ctl.child(idx); set_current_item(ctl, nc); } } return TRUE; case VK_UP: { dom::element c = ctl.find_first(":current"); int idx = c.is_valid()? (c.index() - 1):(ctl.children_count() - 1); if( idx >= 0 ) { dom::element nc = ctl.child(idx); set_current_item(ctl, nc); } } return TRUE; } } return FALSE; }
void enable_find(struct NBT_Window* window) { move(LINES - 1, 0); clrtoeol(); printw("Search: "); refresh(); int ch = 0; char searchbuf[BUFSIZ]; bzero(searchbuf, sizeof(searchbuf)); const char* s = searchbuf; /* Begin pointer */ char* c = searchbuf; /* Current location */ const char* end = s + sizeof(searchbuf) - 1; /* Max location */ int found = -1; while((ch = getch()) != 27) { if (ch == KEY_BACKSPACE || isalnum(ch)) { if (ch == KEY_BACKSPACE) { *c = '\0'; if (c != s) c--; } else { if (c < end) *c++ = ch; } move(LINES - 1, 0); clrtoeol(); printw("Search: %s", searchbuf); found = search_item(searchbuf, 0, window); if (found >= 0) set_current_item(window->menu, window->items[found]); } else if (KEY_F(3)) { found = search_item(searchbuf, found + 1, window); if (found >= 0) set_current_item(window->menu, window->items[found]); else { move(LINES - 1, 0); clrtoeol(); printw("Search: %s [No more results]", searchbuf); } } refresh(); } };
virtual BOOL on_event (HELEMENT he, HELEMENT target, BEHAVIOR_EVENTS type, UINT_PTR reason ) { if( type == ACTIVATE_CHILD ) { dom::element item = target_item(dom::element(he), target); if(item.is_valid()) // click on the item caption { set_current_item(he, item); return TRUE; } } return FALSE; }
virtual BOOL on_mouse(HELEMENT he, HELEMENT target, UINT event_type, POINT pt, UINT mouseButtons, UINT keyboardStates ) { if( event_type != MOUSE_DOWN && event_type != MOUSE_DCLICK ) return false; if(mouseButtons != MAIN_MOUSE_BUTTON) return false; // el is presumably <li>; dom::element ctl = he; dom::element item = target_item(ctl, target); if(item.is_valid()) // click on the item caption set_current_item(ctl, item); return true; // as it is always ours then stop event bubbling }
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); }
static struct result get_selection(struct selection *selection) { while (true) { int ch = wgetch(selection->window); if (ERR == ch) return result_ncurses_err(); if (KEY_DOWN == ch) { int result = menu_driver(selection->menu, REQ_DOWN_ITEM); if (E_OK != result && E_REQUEST_DENIED != result) { return result_ncurses_error(result); } } if (KEY_UP == ch) { int result = menu_driver(selection->menu, REQ_UP_ITEM); if (E_OK != result && E_REQUEST_DENIED != result) { return result_ncurses_error(result); } } if ('\r' == ch) break; if (!isalnum(ch)) continue; for (int i = 0; i < selection->items_count; ++i) { char const *name = item_name(selection->items[i]); if (name && ch == name[0]) { set_current_item(selection->menu, selection->items[i]); return result_success(); } } } return result_success(); }
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); } }
static void cui_boot_editor_on_exit(struct cui *cui, struct pmenu_item *item, struct pb_boot_data *bd) { struct pmenu *menu = cui->main; struct cui_opt_data *cod; int idx, top, rows, cols; static int user_idx = 0; /* Was the edit cancelled? */ if (!bd) { cui_set_current(cui, &cui->main->scr); talloc_free(cui->boot_editor); cui->boot_editor = NULL; return; } /* Is this was a new item, we'll need to update the menu */ if (!item) { int insert_pt; cod = talloc_zero(NULL, struct cui_opt_data); cod->name = talloc_asprintf(cod, _("User item %u"), ++user_idx); item = pmenu_item_create(menu, cod->name); if (!item) { talloc_free(cod); goto out; } item->on_edit = cui_item_edit; item->on_execute = cui_boot; item->data = cod; talloc_steal(item, cod); /* Detach the items array. */ set_menu_items(menu->ncm, NULL); /* Insert new item at insert_pt. */ insert_pt = pmenu_grow(menu, 1); pmenu_item_insert(menu, item, insert_pt); /* Re-attach the items array. */ set_menu_items(menu->ncm, menu->items); /* If our index is above the current top row, align * us to the new top. Otherwise, align us to the new * bottom */ menu_format(cui->main->ncm, &rows, &cols); top = top_row(cui->main->ncm); idx = item_index(item->nci); if (top >= idx) top = idx; else top = idx < rows ? 0 : idx - rows + 1; set_top_row(cui->main->ncm, top); set_current_item(item->pmenu->ncm, item->nci); nc_scr_post(&menu->scr); } else {
static VALUE rbncurs_c_set_current_item(VALUE rb_menu, VALUE rb_item) { MENU *menu = get_menu(rb_menu); ITEM *item = get_item(rb_item); return INT2NUM(set_current_item(menu, item)); }