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 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_top_row(VALUE rb_menu) { MENU *menu = get_menu(rb_menu); return INT2NUM(top_row(menu)); }
int column_select_handle_key_menu(ui_t *ui, int key) { MENU *menu; ITEM *current; int current_idx; int action = -1; // Get panel information column_select_info_t *info = column_select_info(ui); menu = info->menu; current = current_item(menu); current_idx = item_index(current); // Check actions for this key while ((action = key_find_action(key, action)) != ERR) { // Check if we handle this action switch (action) { case ACTION_DOWN: menu_driver(menu, REQ_DOWN_ITEM); break; case ACTION_UP: menu_driver(menu, REQ_UP_ITEM); break; case ACTION_NPAGE: menu_driver(menu, REQ_SCR_DPAGE); break; case ACTION_PPAGE: menu_driver(menu, REQ_SCR_UPAGE); break; case ACTION_SELECT: column_select_toggle_item(ui, current); column_select_update_menu(ui); break; case ACTION_COLUMN_MOVE_DOWN: column_select_move_item(ui, current, current_idx + 1); column_select_update_menu(ui); break; case ACTION_COLUMN_MOVE_UP: column_select_move_item(ui, current, current_idx - 1); column_select_update_menu(ui); break; case ACTION_NEXT_FIELD: info->form_active = 1; set_menu_fore(menu, COLOR_PAIR(CP_DEFAULT)); set_field_back(info->fields[FLD_COLUMNS_ACCEPT], A_REVERSE); form_driver(info->form, REQ_VALIDATION); break; case ACTION_CONFIRM: column_select_update_columns(ui); ui_destroy(ui); return KEY_HANDLED; default: // Parse next action continue; } // This panel has handled the key successfully break; } // Draw a scrollbar to the right info->scroll.pos = top_row(menu); ui_scrollbar_draw(info->scroll); wnoutrefresh(info->menu_win); // Return if this panel has handled or not the key return (action == ERR) ? KEY_NOT_HANDLED : KEY_HANDLED; }
PANEL * column_select_create() { int attr_id, column; PANEL *panel; WINDOW *win; MENU *menu; int height, width; column_select_info_t *info; // Calculate window dimensions height = 20; width = 60; // Cerate a new indow for the panel and form win = newwin(height, width, (LINES - height) / 2, (COLS - width) / 2); // Create a new panel panel = new_panel(win); // Initialize Filter panel specific data info = sng_malloc(sizeof(column_select_info_t)); // Store it into panel userptr set_panel_userptr(panel, (void*) info); // Initialize the fields info->fields[FLD_COLUMNS_ACCEPT] = new_field(1, 10, height - 2, 13, 0, 0); info->fields[FLD_COLUMNS_SAVE] = new_field(1, 10, height - 2, 25, 0, 0); info->fields[FLD_COLUMNS_CANCEL] = new_field(1, 10, 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, win); post_form(info->form); // Create a subwin for the menu area info->menu_win = derwin(win, 10, 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_get_panel(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(panel, info->items[attr_id]); column_select_move_item(panel, info->items[attr_id], column); break; } } } // Set main window and sub window set_menu_win(menu, win); set_menu_sub(menu, derwin(win, 10, 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 draw_vscrollbar(info->menu_win, top_row(menu), item_count(menu) - 1, 0); // Set the window title and boxes mvwprintw(win, 1, width / 2 - 14, "Call List columns selection"); wattron(win, COLOR_PAIR(CP_BLUE_ON_DEF)); title_foot_box(panel); mvwhline(win, 6, 1, ACS_HLINE, width - 1); mvwaddch(win, 6, 0, ACS_LTEE); mvwaddch(win, 6, width - 1, ACS_RTEE); wattroff(win, COLOR_PAIR(CP_BLUE_ON_DEF)); // Some brief explanation abotu what window shows wattron(win, COLOR_PAIR(CP_CYAN_ON_DEF)); mvwprintw(win, 3, 2, "This windows show the list of columns displayed on Call"); mvwprintw(win, 4, 2, "List. You can enable/disable using Space Bar and reorder"); mvwprintw(win, 5, 2, "them using + and - keys."); wattroff(win, COLOR_PAIR(CP_CYAN_ON_DEF)); info->form_active = 0; return panel; }