Beispiel #1
0
MENUPAN*
menu_pan_create(MENU *menu, int y, int x, int id)
{
    MENUPAN *menupan;


    assert(menu);

    menupan=(MENUPAN *)malloc(sizeof(MENUPAN));
    if(!menupan) {
        set_error(ERR_NOMEM);
        lpr_error("menu_pan_create");
    }

    menupan->id=id;
    menupan->menu=menu;
    menupan->win=new_panel(newwin(item_count(menu)+2, MSIZE, y, x));
    menupan->sub=new_panel(derwin(menupan->win->win,
                                  item_count(menu), MSIZE-2, 1, 1));
    wcolor_set(menupan->win->win, 1, NULL);
    set_menu_fore(menu, COLOR_PAIR(1) | A_REVERSE);
    set_menu_back(menu, COLOR_PAIR(1));
    set_menu_grey(menu, COLOR_PAIR(1));
    set_menu_win(menu, menupan->win->win);
    set_menu_sub(menu, menupan->sub->win);


    box(menupan->win->win, 0, 0);
    menupan_hide(menupan);

    return menupan;
}
Beispiel #2
0
void
column_select_update_columns(ui_t *ui)
{
    int column, attr_id;

    // Get panel information
    column_select_info_t *info = column_select_info(ui);

    // Set enabled fields
    ui_t *ui_list = ui_find_by_type(PANEL_CALL_LIST);
    call_list_info_t *list_info = call_list_info(ui_list);

    // Reset column count
    list_info->columncnt = 0;

    // Add all selected columns
    for (column = 0; column < item_count(info->menu); column++) {
        // If column is active
        if (!strncmp(item_name(info->items[column]), "[ ]", 3))
            continue;

        // Get column attribute
        attr_id = sip_attr_from_name(item_userptr(info->items[column]));
        // Add a new column to the list
        call_list_add_column(ui_list, attr_id, sip_attr_get_name(attr_id),
                             sip_attr_get_title(attr_id), sip_attr_get_width(attr_id));
    }
}
Beispiel #3
0
Ob Carrier::try_insert () const
{
    SharedLock lock(m_mutex);

    while (item_count() < item_dim()) {
        for (Ob ob = 1, end = item_dim(); ob <= end; ++ob) {
            Ob zero = 0;
            // This could be optimized using m_support iteration.
            // See DenseSet::try_insert for example low-level code.
            bool inserted = m_reps[ob].compare_exchange_strong(
                    zero,
                    ob,
                    std::memory_order_acq_rel,
                    std::memory_order_acquire);
            if (unlikely(inserted)) {
                m_support.insert(ob, std::memory_order_release);
                ++m_item_count;
                ++m_rep_count;
                if (m_insert_callback) {
                    m_insert_callback(ob);
                }
                // The following triggers a weird gcc bug or something
                // error: invalid memory model for ‘__atomic_load
                //POMAGMA_DEBUG1(m_item_count.load() << " obs after insert()");
                return ob;
            }
        }
    }

    return 0;
}
Beispiel #4
0
void Carrier::validate () const
{
    UniqueLock lock(m_mutex);

    POMAGMA_INFO("Validating Carrier");

    m_support.validate();

    size_t actual_item_count = 0;
    size_t actual_rep_count = 0;
    for (Ob i = 1; i <= item_dim(); ++i) {
        Ob rep = m_reps[i].load();
        if (contains(i)) {
            POMAGMA_ASSERT(rep, "supported object has no rep: " << i);
            POMAGMA_ASSERT(rep <= i, "rep out of order: " << rep << "," << i);
            ++actual_item_count;
            if (rep == i) {
                ++actual_rep_count;
            }
        } else {
            POMAGMA_ASSERT(rep == 0, "unsupported object has rep: " << i);
        }
    }
    POMAGMA_ASSERT_EQ(item_count(), actual_item_count);
    POMAGMA_ASSERT_EQ(rep_count(), actual_rep_count);
}
Beispiel #5
0
void TextItem::label (const char* context) {
    long c = item_count();
    for (long i = 0; i < c; ++i) {
        Item* ii = item(i);
        if (ii != nil) {
            ii->label(context);
        }
    }
}
Beispiel #6
0
void
free_menu_and_items(MENU *m)
{
	size_t	  i, n;
	ITEM	**items;

	items = menu_items(m);
	n = (size_t) item_count(m);

	for (i = 0; i < n; i++)
		free_item(items[i]);
	free_menu(m);
}
Beispiel #7
0
void TextItem::change (Item* component) {
    long c = item_count();
    for (long i = 0; i < c; ++i) {
        Item* ii = item(i);
        if (ii == component) {
            if (_view != nil) {
                long c = _view->count();
                for (long j = 0; j < c; ++j) {
                    TextViewInfo& info = _view->item_ref(j);
                    info._view->item_changed(i, 1);
                }
            }
        }
    }
    Item::change(component);
}
Beispiel #8
0
void
column_select_move_item(ui_t *ui, ITEM *item, int pos)
{
    // Get panel information
    column_select_info_t *info = column_select_info(ui);

    // Check we have a valid position
    if (pos == item_count(info->menu) || pos < 0)
        return;

    // Swap position with destination
    int item_pos = item_index(item);
    info->items[item_pos] = info->items[pos];
    info->items[item_pos]->index = item_pos;
    info->items[pos] = item;
    info->items[pos]->index = pos;
}
Beispiel #9
0
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;
}
Beispiel #10
0
int
hgd_unpost_and_free_content_menu(struct ui *u, int which)
{
	ITEM			**items;
	int			  n_items, i;

	if (u->content_menus[which] == NULL)
		return (HGD_OK);

	DPRINTF(HGD_D_INFO, "free menu: %s", window_names[which]);

	if ((n_items = item_count(u->content_menus[which])) == ERR) {
		DPRINTF(HGD_D_ERROR, "Couldn't get item count");
		return (HGD_FAIL);
	}

	if ((items = menu_items(u->content_menus[which])) == NULL) {
		DPRINTF(HGD_D_ERROR, "Got NULL items array");
		return (HGD_FAIL);
	}

	if (unpost_menu(u->content_menus[which]) != E_OK)
		DPRINTF(HGD_D_ERROR, "could not unpost menu %d", errno);

	/* must come before freeing items */
	if (free_menu(u->content_menus[which]) != E_OK)
		DPRINTF(HGD_D_ERROR, "could not free menu");

	for (i = 0; i < n_items; i++) {
		free((char *) item_name(items[i]));
		free((char *) item_description(items[i]));
		free(item_userptr(items[i]));
		if (free_item(items[i]) != OK)
			DPRINTF(HGD_D_ERROR, "can't free item");
	}

	free(items);
	u->content_menus[which] = NULL;

	return (HGD_OK);
}
Beispiel #11
0
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;
}
Beispiel #12
0
void
column_select_save_columns(ui_t *ui)
{
    int column;
    FILE *fi, *fo;
    char columnopt[128];
    char line[1024];
    char *home = getenv("HOME");
    char userconf[128], tmpfile[128];

    // No home dir...
    if (!home)
        return;

    // Read current $HOME/.sngreprc file
    sprintf(userconf, "%s/.sngreprc", home);
    sprintf(tmpfile, "%s/.sngreprc.old", home);

    // Remove old config file
    unlink(tmpfile);

    // Move home file to temporal dir
    rename(userconf, tmpfile);

    // Create a new user conf file
    if (!(fo = fopen(userconf, "w"))) {
        dialog_run("Unable to open %s: %s", userconf, strerror(errno));
        return;
    }

    // Read all lines of old sngreprc file
    if ((fi = fopen(tmpfile, "r"))) {

        // Read all configuration file
        while (fgets(line, 1024, fi) != NULL) {
            // Ignore lines starting with set (but keep settings)
            if (strncmp(line, "set ", 4) || strncmp(line, "set cl.column", 13)) {
                // Put everyting in new .sngreprc file
                fputs(line, fo);
            }
        }
        fclose(fi);
    }

    // Get panel information
    column_select_info_t *info = column_select_info(ui);

    // Add all selected columns
    for (column = 0; column < item_count(info->menu); column++) {
        // If column is active
        if (!strncmp(item_name(info->items[column]), "[ ]", 3))
            continue;

        // Add the columns settings
        sprintf(columnopt, "set cl.column%d %s\n", column, (const char*) item_userptr(info->items[column]));
        fputs(columnopt, fo);
    }
    fclose(fo);

    // Show a information dialog
    dialog_run("Column layout successfully saved to %s", userconf);
}
Beispiel #13
0
/*
 * Display a menu for choosing among a number of options
 */
int dialog_menu(const char *title, const char *prompt,
                const void *selected, int *s_scroll)
{
	int i, j, x, y, box_x, box_y;
	int height, width, menu_height;
	int key = 0, button = 0, scroll = 0, choice = 0;
	int first_item =  0, max_choice;
	WINDOW *dialog, *menu;

do_resize:
	height = getmaxy(stdscr);
	width = getmaxx(stdscr);
	if (height < 15 || width < 65)
		return -ERRDISPLAYTOOSMALL;

	height -= 4;
	width  -= 5;
	menu_height = height - 10;

	max_choice = MIN(menu_height, item_count());

	/* center dialog box on screen */
	x = (COLS - width) / 2;
	y = (LINES - height) / 2;

	draw_shadow(stdscr, y, x, height, width);

	dialog = newwin(height, width, y, x);
	keypad(dialog, TRUE);

	draw_box(dialog, 0, 0, height, width,
		 dlg.dialog.atr, dlg.border.atr);
	wattrset(dialog, dlg.border.atr);
	mvwaddch(dialog, height - 3, 0, ACS_LTEE);
	for (i = 0; i < width - 2; i++)
		waddch(dialog, ACS_HLINE);
	wattrset(dialog, dlg.dialog.atr);
	wbkgdset(dialog, dlg.dialog.atr & A_COLOR);
	waddch(dialog, ACS_RTEE);

	print_title(dialog, title, width);

	wattrset(dialog, dlg.dialog.atr);
	print_autowrap(dialog, prompt, width - 2, 1, 3);

	menu_width = width - 6;
	box_y = height - menu_height - 5;
	box_x = (width - menu_width) / 2 - 1;

	/* create new window for the menu */
	menu = subwin(dialog, menu_height, menu_width,
		      y + box_y + 1, x + box_x + 1);
	keypad(menu, TRUE);

	/* draw a box around the menu items */
	draw_box(dialog, box_y, box_x, menu_height + 2, menu_width + 2,
		 dlg.menubox_border.atr, dlg.menubox.atr);

	if (menu_width >= 80)
		item_x = (menu_width - 70) / 2;
	else
		item_x = 4;

	/* Set choice to default item */
	item_foreach()
		if (selected && (selected == item_data()))
			choice = item_n();
	/* get the saved scroll info */
	scroll = *s_scroll;
	if ((scroll <= choice) && (scroll + max_choice > choice) &&
	   (scroll >= 0) && (scroll + max_choice <= item_count())) {
		first_item = scroll;
		choice = choice - scroll;
	} else {
		scroll = 0;
	}
	if ((choice >= max_choice)) {
		if (choice >= item_count() - max_choice / 2)
			scroll = first_item = item_count() - max_choice;
		else
			scroll = first_item = choice - max_choice / 2;
		choice = choice - scroll;
	}

	/* Print the menu */
	for (i = 0; i < max_choice; i++) {
		print_item(first_item + i, i, i == choice);
	}

	wnoutrefresh(menu);

	print_arrows(dialog, item_count(), scroll,
		     box_y, box_x + item_x + 1, menu_height);

	print_buttons(dialog, height, width, 0);
	wmove(menu, choice, item_x + 1);
	wrefresh(menu);

	while (key != KEY_ESC) {
		key = wgetch(menu);

		if (key < 256 && isalpha(key))
			key = tolower(key);

		if (strchr("ynmh", key))
			i = max_choice;
		else {
			for (i = choice + 1; i < max_choice; i++) {
				item_set(scroll + i);
				j = first_alpha(item_str(), "YyNnMmHh");
				if (key == tolower(item_str()[j]))
					break;
			}
			if (i == max_choice)
				for (i = 0; i < max_choice; i++) {
					item_set(scroll + i);
					j = first_alpha(item_str(), "YyNnMmHh");
					if (key == tolower(item_str()[j]))
						break;
				}
		}

		if (i < max_choice ||
		    key == KEY_UP || key == KEY_DOWN ||
		    key == '-' || key == '+' ||
		    key == KEY_PPAGE || key == KEY_NPAGE) {
			/* Remove highligt of current item */
			print_item(scroll + choice, choice, FALSE);

			if (key == KEY_UP || key == '-') {
				if (choice < 2 && scroll) {
					/* Scroll menu down */
					do_scroll(menu, &scroll, -1);

					print_item(scroll, 0, FALSE);
				} else
					choice = MAX(choice - 1, 0);

			} else if (key == KEY_DOWN || key == '+') {
				print_item(scroll+choice, choice, FALSE);

				if ((choice > max_choice - 3) &&
				    (scroll + max_choice < item_count())) {
					/* Scroll menu up */
					do_scroll(menu, &scroll, 1);

					print_item(scroll+max_choice - 1,
						   max_choice - 1, FALSE);
				} else
					choice = MIN(choice + 1, max_choice - 1);

			} else if (key == KEY_PPAGE) {
				scrollok(menu, TRUE);
				for (i = 0; (i < max_choice); i++) {
					if (scroll > 0) {
						do_scroll(menu, &scroll, -1);
						print_item(scroll, 0, FALSE);
					} else {
						if (choice > 0)
							choice--;
					}
				}

			} else if (key == KEY_NPAGE) {
				for (i = 0; (i < max_choice); i++) {
					if (scroll + max_choice < item_count()) {
						do_scroll(menu, &scroll, 1);
						print_item(scroll+max_choice-1,
							   max_choice - 1, FALSE);
					} else {
						if (choice + 1 < max_choice)
							choice++;
					}
				}
			} else
				choice = i;

			print_item(scroll + choice, choice, TRUE);

			print_arrows(dialog, item_count(), scroll,
				     box_y, box_x + item_x + 1, menu_height);

			wnoutrefresh(dialog);
			wrefresh(menu);

			continue;	/* wait for another key press */
		}

		switch (key) {
		case KEY_LEFT:
		case TAB:
		case KEY_RIGHT:
			button = ((key == KEY_LEFT ? --button : ++button) < 0)
			    ? 2 : (button > 2 ? 0 : button);

			print_buttons(dialog, height, width, button);
			wrefresh(menu);
			break;
		case ' ':
		case 's':
		case 'y':
		case 'n':
		case 'm':
		case '/':
			/* save scroll info */
			*s_scroll = scroll;
			delwin(menu);
			delwin(dialog);
			item_set(scroll + choice);
			item_set_selected(1);
			switch (key) {
			case 's':
				return 3;
			case 'y':
				return 3;
			case 'n':
				return 4;
			case 'm':
				return 5;
			case ' ':
				return 6;
			case '/':
				return 7;
			}
			return 0;
		case 'h':
		case '?':
			button = 2;
		case '\n':
			*s_scroll = scroll;
			delwin(menu);
			delwin(dialog);
			item_set(scroll + choice);
			item_set_selected(1);
			return button;
		case 'e':
		case 'x':
			key = KEY_ESC;
			break;
		case KEY_ESC:
			key = on_key_esc(menu);
			break;
#ifdef NCURSES_VERSION
		case KEY_RESIZE:
			on_key_resize();
			delwin(menu);
			delwin(dialog);
			goto do_resize;
#endif
		}
	}
	delwin(menu);
	delwin(dialog);
	return key;		/* ESC pressed */
}
Beispiel #14
0
static void down_click_handler(ClickRecognizerRef recognizer, void *context) {
  s_item = (s_item + 1) % item_count();
  text_layer_set_text(s_title_layer, item_title(s_item));
  text_layer_set_text(s_subtitle_layer, item_subtitle(s_item));
  text_layer_set_text(s_description_layer, item_description(s_item));
}
Beispiel #15
0
static void up_click_handler(ClickRecognizerRef recognizer, void *context) {
  s_item = s_item == 0 ? item_count() -1 : s_item - 1;
  text_layer_set_text(s_title_layer, item_title(s_item));
  text_layer_set_text(s_subtitle_layer, item_subtitle(s_item));
  text_layer_set_text(s_description_layer, item_description(s_item));
}
Beispiel #16
0
int main()
{	ITEM **my_items;
	int c;				
	MENU *my_menu;
        int n_choices, i;
	ITEM *cur_item;
	
	/* Initialize curses */	
	initscr();
        cbreak();
        noecho();
	keypad(stdscr, TRUE);

	/* Initialize items */
        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);

	/* Make the menu multi valued */
	menu_opts_off(my_menu, O_ONEVALUE);

	mvprintw(LINES - 3, 0, "Use <SPACE> to select or unselect an item.");
	mvprintw(LINES - 2, 0, "<ENTER> to see presently selected items(F1 to Exit)");
	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 ' ':
				menu_driver(my_menu, REQ_TOGGLE_ITEM);
				break;
			case 10:	/* Enter */
			{	char temp[200];
				ITEM **items;

				items = menu_items(my_menu);
				temp[0] = '\0';
				for(i = 0; i < item_count(my_menu); ++i)
					if(item_value(items[i]) == TRUE)
					{	strcat(temp, item_name(items[i]));
						strcat(temp, " ");
					}
				move(20, 0);
				clrtoeol();
				mvprintw(20, 0, temp);
				refresh();
			}
			break;
		}
	}	

	free_item(my_items[0]);
        free_item(my_items[1]);
	free_menu(my_menu);
	endwin();
}
int dialog_checklist(const char *title, const char *prompt, int height,
		     int width, int list_height)
{
	int i, x, y, box_x, box_y;
	int key = 0, button = 0, choice = 0, scroll = 0, max_choice;
	WINDOW *dialog, *list;

	/*                         */
	item_foreach() {
		if (item_is_tag('X'))
			choice = item_n();
		if (item_is_selected()) {
			choice = item_n();
			break;
		}
	}

do_resize:
	if (getmaxy(stdscr) < (height + 6))
		return -ERRDISPLAYTOOSMALL;
	if (getmaxx(stdscr) < (width + 6))
		return -ERRDISPLAYTOOSMALL;

	max_choice = MIN(list_height, item_count());

	/*                             */
	x = (COLS - width) / 2;
	y = (LINES - height) / 2;

	draw_shadow(stdscr, y, x, height, width);

	dialog = newwin(height, width, y, x);
	keypad(dialog, TRUE);

	draw_box(dialog, 0, 0, height, width,
		 dlg.dialog.atr, dlg.border.atr);
	wattrset(dialog, dlg.border.atr);
	mvwaddch(dialog, height - 3, 0, ACS_LTEE);
	for (i = 0; i < width - 2; i++)
		waddch(dialog, ACS_HLINE);
	wattrset(dialog, dlg.dialog.atr);
	waddch(dialog, ACS_RTEE);

	print_title(dialog, title, width);

	wattrset(dialog, dlg.dialog.atr);
	print_autowrap(dialog, prompt, width - 2, 1, 3);

	list_width = width - 6;
	box_y = height - list_height - 5;
	box_x = (width - list_width) / 2 - 1;

	/*                                */
	list = subwin(dialog, list_height, list_width, y + box_y + 1,
	              x + box_x + 1);

	keypad(list, TRUE);

	/*                                  */
	draw_box(dialog, box_y, box_x, list_height + 2, list_width + 2,
	         dlg.menubox_border.atr, dlg.menubox.atr);

	/*                                                          */
	check_x = 0;
	item_foreach()
		check_x = MAX(check_x, strlen(item_str()) + 4);
	check_x = MIN(check_x, list_width);

	check_x = (list_width - check_x) / 2;
	item_x = check_x + 4;

	if (choice >= list_height) {
		scroll = choice - list_height + 1;
		choice -= scroll;
	}

	/*                */
	for (i = 0; i < max_choice; i++) {
		item_set(scroll + i);
		print_item(list, i, i == choice);
	}

	print_arrows(dialog, choice, item_count(), scroll,
		     box_y, box_x + check_x + 5, list_height);

	print_buttons(dialog, height, width, 0);

	wnoutrefresh(dialog);
	wnoutrefresh(list);
	doupdate();

	while (key != KEY_ESC) {
		key = wgetch(dialog);

		for (i = 0; i < max_choice; i++) {
			item_set(i + scroll);
			if (toupper(key) == toupper(item_str()[0]))
				break;
		}

		if (i < max_choice || key == KEY_UP || key == KEY_DOWN ||
		    key == '+' || key == '-') {
			if (key == KEY_UP || key == '-') {
				if (!choice) {
					if (!scroll)
						continue;
					/*                  */
					if (list_height > 1) {
						/*                                 */
						item_set(scroll);
						print_item(list, 0, FALSE);
						scrollok(list, TRUE);
						wscrl(list, -1);
						scrollok(list, FALSE);
					}
					scroll--;
					item_set(scroll);
					print_item(list, 0, TRUE);
					print_arrows(dialog, choice, item_count(),
						     scroll, box_y, box_x + check_x + 5, list_height);

					wnoutrefresh(dialog);
					wrefresh(list);

					continue;	/*                            */
				} else
					i = choice - 1;
			} else if (key == KEY_DOWN || key == '+') {
				if (choice == max_choice - 1) {
					if (scroll + choice >= item_count() - 1)
						continue;
					/*                */
					if (list_height > 1) {
						/*                                                    */
						item_set(scroll + max_choice - 1);
						print_item(list,
							    max_choice - 1,
							    FALSE);
						scrollok(list, TRUE);
						wscrl(list, 1);
						scrollok(list, FALSE);
					}
					scroll++;
					item_set(scroll + max_choice - 1);
					print_item(list, max_choice - 1, TRUE);

					print_arrows(dialog, choice, item_count(),
						     scroll, box_y, box_x + check_x + 5, list_height);

					wnoutrefresh(dialog);
					wrefresh(list);

					continue;	/*                            */
				} else
					i = choice + 1;
			}
			if (i != choice) {
				/*                           */
				item_set(scroll + choice);
				print_item(list, choice, FALSE);
				/*                    */
				choice = i;
				item_set(scroll + choice);
				print_item(list, choice, TRUE);
				wnoutrefresh(dialog);
				wrefresh(list);
			}
			continue;	/*                            */
		}
		switch (key) {
		case 'H':
		case 'h':
		case '?':
			button = 1;
			/*              */
		case 'S':
		case 's':
		case ' ':
		case '\n':
			item_foreach()
				item_set_selected(0);
			item_set(scroll + choice);
			item_set_selected(1);
			delwin(list);
			delwin(dialog);
			return button;
		case TAB:
		case KEY_LEFT:
		case KEY_RIGHT:
			button = ((key == KEY_LEFT ? --button : ++button) < 0)
			    ? 1 : (button > 1 ? 0 : button);

			print_buttons(dialog, height, width, button);
			wrefresh(dialog);
			break;
		case 'X':
		case 'x':
			key = KEY_ESC;
			break;
		case KEY_ESC:
			key = on_key_esc(dialog);
			break;
		case KEY_RESIZE:
			delwin(list);
			delwin(dialog);
			on_key_resize();
			goto do_resize;
		}

		/*                           */
		doupdate();
	}
	delwin(list);
	delwin(dialog);
	return key;		/*             */
}
Beispiel #18
0
int
column_select_handle_key_menu(PANEL *panel, int key)
{
    MENU *menu;
    ITEM *current;
    int current_idx;
    int action = -1;

    // Get panel information
    column_select_info_t *info = column_select_info(panel);

    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(panel, current);
                column_select_update_menu(panel);
                break;
            case ACTION_COLUMN_MOVE_DOWN:
                column_select_move_item(panel, current, current_idx + 1);
                column_select_update_menu(panel);
                break;
            case ACTION_COLUMN_MOVE_UP:
                column_select_move_item(panel, current, current_idx - 1);
                column_select_update_menu(panel);
                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(panel);
                return 27;
            default:
                // Parse next action
                continue;
        }

        // This panel has handled the key successfully
        break;
    }

    // Draw a scrollbar to the right
    draw_vscrollbar(info->menu_win, top_row(menu), item_count(menu) - 1, 0);
    wnoutrefresh(info->menu_win);
    // Return if this panel has handled or not the key
    return (action == ERR) ? key : 0;
}
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;
}
Beispiel #20
0
static VALUE rbncurs_c_item_count(VALUE rb_menu)
{
  MENU *menu = get_menu(rb_menu);
  return INT2NUM(item_count(menu));
}