Exemple #1
0
int popup_param_t::find_index_for_string( const std::string& s) const
{
    for( int i = 0; i < menu_items().size(); ++i)
    {
        if( menu_items()[i] == s)
            return i;
    }

    return -1;
}
Exemple #2
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);
}
Exemple #3
0
static VALUE rbncurs_c_menu_items(VALUE rb_menu)
{
  MENU *menu = get_menu(rb_menu);
  ITEM **items = menu_items(menu);
  VALUE arr = Qundef;
  int i;

  if (items == NULL)
    rb_raise(rb_eRuntimeError, "Error retrieving menu items");
  arr = rb_ary_new();
  i=0;
  while (items[i] != NULL)
    rb_ary_push(arr, wrap_item(items[i++]));
  return arr;
}
Exemple #4
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;
}
Exemple #5
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);
}
Exemple #6
0
int main()
{
	float SueldoAnualProfesional[LEGAJO] = {0};
	float SueldoMes[MES + 1] = {0};
	int TotalHorasExtra[LEGAJO] = {0};
   
	bool validated = false;
	int menu_item;
   
	system("clear"); //system("cls")
	if(login_request()) // nos logeamos
	{
		while(menu_item != 5) // repetimos el switch hasta salir del menu
		{
			menu_item = menu_items(); // llamamos al menu para introducir items
		     
		 	if(validated == false && menu_item == 0) // opcion 0 usable solo si no introducimos nada
			{
				menu_data(&validated, SueldoAnualProfesional, SueldoMes, TotalHorasExtra); // introducimos datos
			}
			else if(validated == true) // si ya introducimos datos habilitamos las otras opciones
			{
				switch(menu_item) // opciones despues de introducir datos
				{
				case 0:
					system("clear"); //system("cls");
					getchar();
					printf("Solo se puede introducir los datos una vez\n");
					getchar();
					break;
				case 1:
					system("clear"); //system("cls");
					getchar();
					data_processing(menu_item, SueldoAnualProfesional, 0);
					break;
				case 2:
					system("clear"); //system("cls");
					getchar();
					data_processing(menu_item, SueldoMes, 0);
					break;
				case 3:
					system("clear"); //system("cls");
					getchar();
					data_processing(menu_item, SueldoAnualProfesional, 0);
					break;
				case 4:
					system("clear"); //system("cls");
					getchar();
					data_processing(menu_item, SueldoAnualProfesional, TotalHorasExtra);
					break;
				}
			}
			else if(menu_item == 5) // terminamos el loop
			{
				return 0;
			}
			else // si tratamos de usar el menu sin introducir datos nos tira error
			{
				system("clear"); //system("cls");
				getchar();
				printf("Debes introducir los datos antes de usar el menu\n");
				getchar();
			}
		}
	}
	return 0;
}
Exemple #7
0
void popup_param_t::do_write( serialization::yaml_oarchive_t& out) const
{
    int v = get_value<int>( *this);
    out << YAML::Key << "value" << YAML::Value;
    out << YAML::DoubleQuoted << menu_items()[v];
}
Exemple #8
0
void popup_param_t::do_add_to_hash( hash::generator_t& hash_gen) const
{
    hash_gen << menu_items()[ get_value<int>( *this)];
}
Exemple #9
0
boost::python::object popup_param_t::to_python( const poly_param_value_t& v) const
{
    std::string str = menu_items()[v.cast<int>()];
    return boost::python::object( str);
}
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();
}