Esempio n. 1
0
/* display current menu */
void display_menu() {
  
  int rows, cols, begin_y, begin_x;

  /* setup menu options */
  menu_opts_off(menu_ptr, O_ROWMAJOR);
  set_menu_fore(menu_ptr, COLOR_PAIR(MENU_PAIR) | A_STANDOUT);
  set_menu_back(menu_ptr, COLOR_PAIR(MENU_PAIR) | A_DIM | A_NORMAL);

  /* setup appropriate windows */
  set_menu_win(menu_ptr, stdscr);
  scale_menu(menu_ptr, &rows, &cols);

  /* locate menu in the center */
  getmaxyx(stdscr,LINES,COLS);
  begin_y = (LINES-rows) / 2;
  begin_x = (COLS-cols) / 2;

  /* create main menu window */
  sub_window = subwin(stdscr, rows, cols, begin_y, begin_x);
  set_menu_sub(menu_ptr, sub_window);

  /* display the menu */
  post_menu(menu_ptr);
  refresh();
  
}
Esempio n. 2
0
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;
}
Esempio n. 3
0
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);*/
}
Esempio n. 4
0
void NCRowMenu::setup()
{
	wbkgd(getWindow(),COLOR_PAIR(2));

	ITEM **my_items;
	MENU *my_menu;
    WINDOW *my_menu_win;
	int i;

	my_items = (ITEM **) calloc(choices.size()+2, sizeof(ITEM *));
    for(i = 0; i < choices.size(); ++i)
    	my_items[i] = new_item(choices[i].c_str(), "NULL");
	
	my_menu = new_menu((ITEM **) my_items);

	set_menu_grey(my_menu, COLOR_PAIR(2));
	set_menu_fore(my_menu, COLOR_PAIR(2));
	set_menu_back(my_menu, COLOR_PAIR(2));

	menu_opts_off(my_menu, O_SHOWDESC);

    my_menu_win = getWindow();
    keypad(my_menu_win, FALSE);

	/* Set main window and sub window */
    set_menu_win(my_menu, my_menu_win);
    //set_menu_sub(my_menu, derwin(my_menu_win, 10, 150, 3, 1));
	set_menu_format(my_menu, 1, 10);
	set_menu_mark(my_menu, " ");

    //box(my_menu_win, 0, 0);

	//wbkgdset(getWindow(), COLOR_PAIR(2));
	//wrefresh(getWindow());
	wrefresh(stdscr);
	
	refresh();

	/* Post the menu */
	post_menu(my_menu);
	wrefresh(my_menu_win);

	//setBorder(0, 0);
}
Esempio n. 5
0
WINDOW *Napravi_menu(int *n_choices, ITEM **items, MENU *menu) {
	int i, height, width;
	WINDOW *menu_window;
	
	*n_choices = ARRAY_SIZE(choices);
	items = (ITEM **) calloc(*n_choices, sizeof(ITEM *));
	for(i = 0; i < *n_choices; ++i)
        items[i] = new_item(choices[i], "");
	menu = new_menu((ITEM **) items);
	height = 3;
	width = 9+7+6;
	menu_window = newwin(height, width, 16, COLS/2-width/2);
	//Validiraj_ncurses(keypad(menu_window, TRUE));
	set_menu_win(menu, menu_window);
	set_menu_sub(menu, derwin(menu_window, height-1, width-1, 1, 1));
	set_menu_mark(menu, ">");
	set_menu_format(menu, 1, 7);
	menu_opts_off(menu, O_SHOWDESC);
	box(menu_window, 0, 0);
	post_menu(menu);
	Wrefresh(menu_window);
	return menu_window;
}
Esempio n. 6
0
//
// Demande à l'utilisateur s'il souhaite rejouer.
//
bool wantsToReplay(WINDOW *win, int top) {
    if(win == NULL || top < 0) return false;
    
    //variables pour l'affichage du menu
    ITEM **menuItems = NULL;
    MENU *menu = NULL;
    
    int i = 0, c;
    int nbChoices = 2;
    
    char *choices[] = {
        "Menu Principal",
        "Quitter"
    };
    
    int winWidth = POPUP_WINDOW_WIDTH;
    //largeur du menu = longueur du plus grand des choix possibles
    int menuWidth = 22;
    
    //on alloue de la mémoire pour initialiser les éléments du menu
    menuItems = (ITEM **) calloc(nbChoices + 1, sizeof(ITEM *));
    
    //on créé de nouveaux éléments à partir des choix fournis
    for(i = 0; i < nbChoices; i++) {
        menuItems[i] = new_item(choices[i], NULL);
    }
    
    //on met un élément nul à la fin du tableau
    menuItems[nbChoices] = (ITEM *) NULL;
    
    //on initialise le menu
    menu = new_menu((ITEM **) menuItems);
    
    //on lui précise bien que le menu fait 1 ligne et 2 colonnes
    set_menu_format(menu, 1, 2);
    
    //on associe le menu à une fenêtre et une sous-fenêtre
    set_menu_win(menu, win);
    //fenêtre hauteur largeur x y
    set_menu_sub(menu, derwin(win, nbChoices, menuWidth, top, (winWidth - menuWidth) / 2));
    
    menu_opts_off(menu, O_NONCYCLIC);
    set_menu_mark(menu, "");
    
    //et hop, on affiche le menu et on rafraîchit.
	post_menu(menu);
	
    refresh();
    wrefresh(win);
    
    curs_set(0);
    noecho();
    
    //boucle pour le menu
    while((c = getch())) {
        switch(c) {
            case KEY_LEFT:
            case KEY_UP:
                menu_driver(menu, REQ_LEFT_ITEM);
                break;
            case KEY_RIGHT:
            case KEY_DOWN:
                menu_driver(menu, REQ_RIGHT_ITEM);
                break;
            case KEY_MENU_ENTER: {
                int choice = item_index(current_item(menu));
                
                unpost_menu(menu);
                free_menu(menu);
                
                for(i = 0; i < nbChoices; ++i)
                    free_item(menuItems[i]);
                
                //si l'indice est 1 on renvoie 0 et vice-versa
                return !choice;
            }
        }
        
        wrefresh(win);
    }
    
    return false;
}
Esempio n. 7
0
int main()                                                                               
{       ITEM **my_items;                                                                 
		int c;                                                                           
		MENU *my_menu;                                                                   
		WINDOW *my_menu_win;                                                             
		int n_choices, i;                                                                

		/* Initialize curses */                                                          
		initscr();                                                                       
		start_color();                                                                   
		cbreak();                                                                        
		noecho();                                                                        
		keypad(stdscr, TRUE);                                                            
		init_pair(1, COLOR_RED, COLOR_BLACK);                                            
		init_pair(2, COLOR_CYAN, COLOR_BLACK);                                           

		/* Create 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], choices[i]);                          

		/* Crate menu */                                                                 
		my_menu = new_menu((ITEM **)my_items);                                           

		/* Set menu option not to show the description */                                
		menu_opts_off(my_menu, O_SHOWDESC);                                              

		/* Create the window to be associated with the menu */                           
		my_menu_win = newwin(10, 40, 4, 4);                                              
		keypad(my_menu_win, TRUE);                                                       

		/* Set main window and sub window */                                             
		set_menu_win(my_menu, my_menu_win);                                              
		set_menu_sub(my_menu, derwin(my_menu_win, 6, 30, 3, 1));                         
		set_menu_format(my_menu, 5, 3);                                                  
		set_menu_mark(my_menu, " * ");                                                   

		/* Print a border around the main window and print a title */                    
		box(my_menu_win, 0, 0);                                                          

		attron(COLOR_PAIR(2));                                                           
		mvprintw(LINES - 3, 0, "Use PageUp and PageDown to scroll");                     
		mvprintw(LINES - 2, 0, "Use Arrow Keys to navigate (F1 to Exit)");               
		attroff(COLOR_PAIR(2));                                                          
		refresh();                                                                       

		/* Post the menu */                                                              
		post_menu(my_menu);                                                              
		wrefresh(my_menu_win);                                                           

		while((c = wgetch(my_menu_win)) != 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 KEY_LEFT:                                                   
						menu_driver(my_menu, REQ_LEFT_ITEM);                     
						break;                                                   
						case KEY_RIGHT:                                                  
						menu_driver(my_menu, REQ_RIGHT_ITEM);                    
						break;                                                   
						case KEY_NPAGE:                                                  
						menu_driver(my_menu, REQ_SCR_DPAGE);                     
						break;                                                   
						case KEY_PPAGE:                                                  
						menu_driver(my_menu, REQ_SCR_UPAGE);                     
						break;                                                   
				}                                                                        
				wrefresh(my_menu_win);                                                   
		}                                                                                

		/* 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();                                                                        
}                                                
Esempio n. 8
0
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;
}
Esempio n. 9
0
void viewListPlayers(FootBallGame::TeamNumber teamNumber) {
  String teamName;
  int nChoices;
  ITEM **items;
  const char *itemName;
  const ITEM *currentItem;
  LinkedList<String*> names = LinkedList<String*>(deleteString);
  LinkedList<int*> pids = LinkedList<int*>(deleteInt);

  const int window_nlines = 10,
            window_ncols  = 90;

  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);

    // Set up the items of menu.
    FootBallTeam *team = game.getFootBallTeam(teamNumber);
    if (team != NULL) {
      nChoices = team->getPlayerCount() + 2;
      items = new ITEM* [nChoices];

      TeamIterator iterator, end;
      team->begin(iterator);
      team->end(end);
      for (int i = 0; iterator != end; i++, iterator++) {
        Player *player = *iterator;
        String *playerName = new String;
        int *pid = new int;
        player->getName(*playerName);
        *pid = player->getPid();
        names.append(playerName);
        pids.append(pid);
        items[i] = new_item(playerName->c_str(), NULL);
        set_item_userptr(items[i], pid);
      }
    } else  {
      nChoices = 2;
      items = new ITEM* [nChoices];
    }
    items[nChoices-2] = new_item("Exit", NULL);
    items[nChoices-1] = NULL;

    // Create the menu
    MENU *menu = new_menu((ITEM **)items);
    set_menu_win(menu, window);
    set_menu_sub(menu, derwin(window, 10, 80, 0, 10));
    set_menu_mark(menu, NULL);
    // Do not Show the item descritpions
    menu_opts_off(menu, O_SHOWDESC);

    post_menu(menu);
    wrefresh(window);
    refresh();
    
    int c;
    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
          currentItem = current_item(menu);
          itemName = item_name(currentItem);
          if (itemName != NULL) {
            if (strcmp(itemName, "Exit") == 0) {
              // Delete allocated data
              unpost_menu(menu);
              free_menu(menu); 
              for (int i = 0; i < nChoices-1; i++) 
                free_item(items[i]);
              delete[] items;
              delwin(window); 
              return;
            } else  {
              int *pid = (int*)item_userptr(currentItem);
              // Delete allocated data
              unpost_menu(menu);
              free_menu(menu); 
              for (int i = 0; i < nChoices-1; i++) 
                free_item(items[i]);
              delete[] items;
              delwin(window); 
              viewPlayer(team, itemName, *pid);
              restart = true;
            }
          }
      }
    }
  }
}
Esempio n. 10
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;
}
Esempio n. 11
0
void sfm_ncurses(void)
{
	int x;
	sfm_ncurses_win *iface = malloc(sizeof(sfm_ncurses_win));
	char root_items[FILENAME_MAX];
	int user_input;
	WINDOW *current_window;
	ITEM **ncmenu_items = NULL;
	MENU *sfm_menu;

	initscr();
	start_color();	
	noecho();
	cbreak();

	getmaxyx(stdscr, iface->lines, iface->cols);
	refresh();

	iface->sfmncmenu = newwin(3, iface->cols-1, iface->lines-5, 0);
	keypad(iface->sfmncmenu, TRUE);
	wmove(iface->sfmncmenu, 1, 1);
	box(iface->sfmncmenu, 0, 0);

	ncmenu_items = malloc((menu_choices_n+1) * sizeof(ITEM *));
	for (x = 0; x < menu_choices_n; x++)
		ncmenu_items[x] = new_item(menu_choices[x], menu_choices[x]);
	//ncmenu_items[menu_choices_n] = (ITEM *)NULL;

	sfm_menu = new_menu((ITEM **)ncmenu_items);
	menu_opts_off(sfm_menu, O_SHOWDESC);
	set_menu_format(sfm_menu, 1, menu_choices_n);
	set_menu_mark(sfm_menu, " ");
	set_menu_win(sfm_menu, iface->sfmncmenu);
	set_menu_sub(sfm_menu, derwin(iface->sfmncmenu, 1, iface->cols-2, 1, 1));
	post_menu(sfm_menu); 

	wrefresh(iface->sfmncmenu);

	iface->sfmnroot = newwin(iface->lines-6, iface->cols-4, 0, 0);
	snprintf(root_items, sizeof(root_items)-1, "%-40s . %-6s . %-4s . %-3s . %-10s", 
		"FILENAME", "SIZE", "TYPE", "UID", "PERMISSIONS");
	wattron(iface->sfmnroot, A_REVERSE|A_BOLD);
	wprintw(iface->sfmnroot, root_items);
	wattroff(iface->sfmnroot, A_REVERSE|A_BOLD);

	for (x = 1; x < (iface->lines - 6); x++) {
		snprintf(root_items, sizeof(root_items)-1, "Item line %2d                             . 55Kb   . .PDF . 100 . -rw-r--r--", x);
		mvwprintw(iface->sfmnroot, x, 0, root_items);
	}

	wrefresh(iface->sfmnroot);

	iface->sfmnstatus = newwin(1, iface->cols-1, iface->lines-2, 1);
	wprintw(iface->sfmnstatus, ":. Hello! Welcome to .: %s :. lines:%d, cols:%d", 
		SFM_VSN, iface->lines, iface->cols);
	wrefresh(iface->sfmnstatus); 

	current_window = iface->sfmncmenu;
	while (1) {
		user_input = wgetch(current_window);

		switch (user_input) {
		case KEY_LEFT:
			menu_driver(sfm_menu, REQ_LEFT_ITEM);
			break;
		case KEY_RIGHT:
			menu_driver(sfm_menu, REQ_RIGHT_ITEM);
			break; 
		case KEY_UP:
			break;
		case KEY_DOWN:
			break;
		case 9:
			if (current_window == iface->sfmncmenu)
				current_window = iface->sfmnroot;
			else
				current_window = iface->sfmncmenu;
		
			keypad(current_window, TRUE);
			break;
		case 10:
			{
				//ITEM *cur;
				
				//cur = current_item(sfm_menu);
				
			}
			break;
		case 'Q':
		case 'q':
			wclear(iface->sfmnstatus);
			wprintw(iface->sfmnstatus, ":. Are you sure you want to quit!? [Y/N] ");
			wrefresh(iface->sfmnstatus);

			user_input = wgetch(iface->sfmnstatus);
			switch (user_input) {
			case 'y': case 'Y':
			case 's': case 'S':
				wclear(iface->sfmnstatus);
				wprintw(iface->sfmnstatus, ":. Thanks for using SFM! :) Quitting...");
				wrefresh(iface->sfmnstatus);
				sleep(1);

				goto sfm_ncurses_exit;
			default:
				break;
			}
		}

		wclear(iface->sfmnstatus);
		wprintw(iface->sfmnstatus, ":. status: %d", user_input);
		wrefresh(iface->sfmnstatus);
	} 

	sfm_ncurses_exit:
	delwin(iface->sfmnroot);
	delwin(iface->sfmnstatus);
	delwin(iface->sfmncmenu);

	unpost_menu(sfm_menu);
	free_menu(sfm_menu); 

	for (x = 0; x < menu_choices_n; x++)
		free_item(ncmenu_items[x]);

	free(ncmenu_items);

	free(iface);

	refresh();
	endwin();
}
Esempio n. 12
0
static VALUE rbncurs_c_menu_opts_off(VALUE rb_menu, VALUE opts)
{
  MENU *menu = get_menu(rb_menu);
  return INT2NUM(menu_opts_off(menu, NUM2INT(opts)));
}
Esempio n. 13
0
int main(){

	WINDOW *my_win, *menu_win, *my_menu_win;
	ITEM **my_items;
	MENU *my_menu;
	list *FileBuffer;
	
	int height, width, startx, starty, exit = 0;
	int highlight = 1;
	int ch, c, choice = 0, i, j;
	char str[81];
	
	FileBuffer = (list *)malloc(sizeof(list));
	
	
	if (FileBuffer == NULL)
		return;
	
	InitialiseBuffer(FileBuffer);
	
	initscr();
	clear();
	noecho();
	cbreak();
	
	start_color();
	
	
	/*Checking whether the terminal supports colors*/
	if (has_colors() == FALSE){
		endwin();
		printf("Your terminal does not support colors\n");
	}
		
	
	keypad(stdscr, TRUE);
	
	height = 3;
	width = 10;
	starty = (LINES - height)/2;
	startx = (COLS - width) / 2;	

	refresh();
	
	my_win = Create_NewWindow(height, width, starty, startx);

	mvwhline(my_win, 5, 1,	ACS_HLINE, width - 1);
	
	init_pair(1, COLOR_RED, COLOR_BLACK);
	init_pair(2, COLOR_CYAN, COLOR_BLACK);
	
	/* Create items */
    my_items = (ITEM **)calloc(nchoices, sizeof(ITEM *));
    for(i = 0; i < nchoices; ++i)
    	my_items[i] = new_item(menu_options[i], menu_options[i]);

	/* Create menu */	
	my_menu = new_menu((ITEM **)my_items);

	/* Set menu option not to show the description */
	menu_opts_off(my_menu, O_SHOWDESC);

	/* Create the window to be associated with the menu */
    my_menu_win = newwin(0, 0, 0, 0);
    keypad(my_menu_win, TRUE);
     
	/* Set main window and sub window */
    set_menu_win(my_menu, my_menu_win);
	set_menu_sub(my_menu, derwin(my_menu_win, 0, 0, 0, 0));
 	set_menu_format(my_menu, 1, 6);
	set_menu_mark(my_menu, " * ");


	/* Post the menu */
	post_menu(my_menu);
	wrefresh(my_menu_win);
	
	i = 0;
		
	mvwhline(my_menu_win, 1, 0, ACS_HLINE, COLS);
	mvwprintw(my_menu_win, LINES - 1, 0, "Press F3 to go to the menu, F6 to exit", c);
	
	
	while(1){
		choice = ToggleMenu(my_menu_win, my_menu, i);
		i = choice;
		switch(choice){
			case 0:
				MenuOpen(FileBuffer, my_menu_win);
				break;
			case 1:
				MenuNew(FileBuffer, my_menu_win, my_menu);
				break;
			case 2:
				MenuSave(FileBuffer, my_menu_win);
				break;
			case 3:
				MenuSaveAs(FileBuffer, my_menu_win);
				break;
			case 4:
				MenuEdit(FileBuffer, my_menu_win);
				break;
			case 5:
				MenuExit(FileBuffer, my_menu_win);
				exit = 1;
				break;
			default:
				break;
		}
		if (exit)
			break;
	}
	/*Assertion: the user wants to exit the program*/
    
		
	/* Unpost and free all the memory taken up */
       unpost_menu(my_menu);
       free_menu(my_menu);
       for(j = 0; j < nchoices; ++j)
               free_item(my_items[j]);
                
	clrtoeol();
	refresh();	
	
	/*Ending curses mode*/
	
	endwin();		
	return 0;
}
Esempio n. 14
0
//
// Affiche une fenêtre de menu.
//
int displayMenu(char **choices, int nbChoices, char title[], bool logo) {
    if(choices == NULL || nbChoices < 1) return -1;
    
    //variables pour l'affichage du menu
    ITEM **menuItems = NULL;
    MENU *menu = NULL;
    WINDOW *menuWin = NULL;
    
    int i = 0, c;
    int winWidth = POPUP_WINDOW_WIDTH;
    //largeur du menu = longueur du plus grand des choix possibles
    int menuWidth = max_strlen(choices, nbChoices) + 2;
    
    //on alloue de la mémoire pour initialiser les éléments du menu
    menuItems = (ITEM **) calloc(nbChoices + 1, sizeof(ITEM *));
    
    //on créé de nouveaux éléments à partir des choix fournis
    for(i = 0; i < nbChoices; i++) {
        menuItems[i] = new_item(choices[i], NULL);
    }
    
    //on met un élément nul à la fin du tableau
    menuItems[nbChoices] = (ITEM *) NULL;
    
    while(true) {
        clear();
        
        menuWin = (logo) ? getMenuWindow(nbChoices, title) : getMenuWindowNoLogo(nbChoices, title, -1, -1);
        
        //on initialise le menu
        menu = new_menu((ITEM **) menuItems);
        
        //on lui précise bien que le menu fait N lignes et 1 colonne
        set_menu_format(menu, nbChoices, 1);
        
        menu_opts_off(menu, O_NONCYCLIC);
        set_menu_mark(menu, "> ");
        
        //on associe le menu à une fenêtre et une sous-fenêtre
        set_menu_win(menu, menuWin);
        //fenêtre hauteur largeur x y
        set_menu_sub(menu, derwin(menuWin, nbChoices, menuWidth, (logo) ? 15 : 4, (winWidth - menuWidth) / 2));
        
        //et hop, on affiche le menu et on rafraîchit.
        post_menu(menu);
        
        refresh();
        wrefresh(menuWin);
        
        curs_set(0);
        noecho();
        
        //boucle pour le menu
        while((c = getch())) {
            bool resized = false;
            
            switch(c) {
                case KEY_DOWN:
                    menu_driver(menu, REQ_DOWN_ITEM);
                    break;
                case KEY_UP:
                    menu_driver(menu, REQ_UP_ITEM);
                    break;
                case KEY_ESC_ALT:
                    return -1;
                case KEY_RESIZE:
                    //si on a redimensionné le terminal, on ré-exécute la boucle d'affichage
                    resized = true;
                    break;
                case KEY_MENU_ENTER: {
                    int choice = item_index(current_item(menu));
                    
                    //on libère la mémoire pour le menu, les choix, la fenêtre
                    unpost_menu(menu);
                    free_menu(menu);
                    
                    for(i = 0; i < nbChoices; ++i)
                        free_item(menuItems[i]);
                    
                    clear();
                    refresh();
                    
                    delwin(menuWin);
                    
                    //on réactive l'affichage des caractères tapés et du curseur
                    echo();
                    curs_set(1);
                    
                    return choice;
                }
            }
            
            if(resized) break;
            wrefresh(menuWin);
        }

    }
    
    return 0;
}
Esempio n. 15
0
char*  seleccionar_menu( Partida* par, int linea, int col ){

    ITEM ** items;
    MENU*   menu;
    WINDOW* menuwin;
    int cant = qg_partida_movidas_count( par );
    int i;
    char* ret;
    int  srow, scol;

    items = malloc( sizeof( ITEM ) * ( cant + 1 ) );
    for( i = 0; i < cant; i ++ ){
        Movdata  movd;
        assert( qg_partida_movidas_data( par, i, &movd ) );
        items[i] = new_item( strdup( movd.notacion ), NULL );
    }
    items[i] = NULL;
    menu = new_menu( items );
    set_menu_format( menu, 13, 3 );

    scale_menu( menu, &srow, &scol );

    menuwin = newwin( srow + 2, scol + 2, linea, col );
    set_menu_win( menu, menuwin );
    set_menu_sub( menu, derwin( menuwin, srow, scol, 1, 1 ) );
    menu_opts_off( menu, O_SHOWDESC );
    box( menuwin, 0, 0 );
    keypad(menuwin, TRUE);

    post_menu( menu );

    ITEM* selected = NULL;

    while(!selected){
        wrefresh( menuwin );
        switch( getch() ){
            case  27:
                selected = (ITEM*)-1;
                break;
            case KEY_DOWN:
                menu_driver(menu, REQ_DOWN_ITEM);
                break;
            case KEY_UP:
                menu_driver(menu, REQ_UP_ITEM);
                break;
            case KEY_LEFT:
                menu_driver(menu, REQ_LEFT_ITEM);
                break;
            case KEY_RIGHT:
                menu_driver(menu, REQ_RIGHT_ITEM);
                break;
            case KEY_NPAGE:
                menu_driver(menu, REQ_SCR_DPAGE);
                break;
            case KEY_PPAGE:
                menu_driver(menu, REQ_SCR_UPAGE);
                break;
            case 10:
                selected = current_item(menu);
                break;
        }
    }

    if( selected != (ITEM*)-1 ){
        ret = strdup( item_name(selected ) );
    } else {
        ret = NULL;
    }

    for( i = 0; i < cant; i ++ ){
        free( (void*)item_name(items[i]) );
        free( items[i] );
    }
    unpost_menu( menu );
    free_menu( menu );
    borrar_win( menuwin );

    return ret;
}
Esempio n. 16
0
WINDOW* vwm_main_menu(void)
{
   extern WINDOW  *SCREEN_WINDOW;
	MENU           *menu=NULL;
	WINDOW 		   *window;
	gint			   width=0,height=0;
   gint           screen_height;

	VWM_MODULE	   *vwm_module;
	GSList		   *category_list=NULL;
	GSList		   *module_list=NULL;
	GSList		   *node1;
	GSList		   *node2;

	gchar			   **item_list;
   gint           idx=0;

   /* allocate storage for 128 menu items    */
   item_list=(gchar**)g_malloc0(sizeof(gchar*)*(MAX_MENU_ITEMS+1));

   item_list[idx]=g_strdup_printf(" ");
   idx++;
	category_list=vwm_modules_list_categories();
   node1=category_list;
   while(node1!=NULL && idx<MAX_MENU_ITEMS)
   {
      /* skip screensavers */
      if(strcmp((gchar*)node1->data,VWM_SCREENSAVER)==0)
      {
         node1=node1->next;
         continue;
      }

      /* add the category  */
      item_list[idx]=g_strdup_printf("%s",(gchar*)node1->data);
      idx++;
      if(idx==MAX_MENU_ITEMS) break;

      module_list=vwm_modules_list((gchar*)node1->data);
      node2=module_list;
      while(node2!=NULL)
      {
         if(idx==MAX_MENU_ITEMS) break;
         vwm_module=(VWM_MODULE*)node2->data;
         item_list[idx]=g_strdup_printf("..%s",vwm_module->title);
         idx++;
         node2=node2->next;
      }

      /* add a space before the next menu category  */
      if(idx<MAX_MENU_ITEMS)
      {
         item_list[idx]=g_strdup_printf(" ");
         idx++;
      }

      if(module_list!=NULL) g_slist_free(module_list);
      node1=node1->next;
   }
   if(category_list!=NULL) g_slist_free(category_list);

   menu=viper_menu_create(item_list);
   while(idx!=-1)
   {
      g_free(item_list[idx]);
      idx--;
   }
   g_free(item_list);

	/* hide character mark on left hand side */
	set_menu_mark(menu," ");

   window_get_size_scaled(SCREEN_WINDOW,NULL,&screen_height,0,0.80);

	scale_menu(menu,&height,&width);
	width++;
	if(width<16) width=16;
 	/* override the default of 1 column X 16 entries per row */
   if(height>(screen_height-4)) height=screen_height-4;
	set_menu_format(menu,height,1);

	viper_thread_enter();
	window=viper_window_create(" Menu ",1,2,width,height,TRUE);
   /* todo:  it would be nice if the user could resize the window (especially
      in the horizonal direction) and add more columns to the display.  right
      now, it's not a priority (but it would be easy to implement).  just need
      a few lines of code for the event window-resized.  for now, just don't
      allow it */
	set_menu_win(menu,window);
	set_menu_fore(menu,VIPER_COLORS(COLOR_WHITE,COLOR_BLUE) | A_BOLD);
	set_menu_back(menu,VIPER_COLORS(COLOR_BLACK,COLOR_WHITE));
	menu_opts_off(menu,O_NONCYCLIC);
	post_menu(menu);
   vwm_menu_marshall(menu,REQ_DOWN_ITEM);

	/* viper_event_set(window,"window-activate",vwm_main_menu_ON_ACTIVATE,NULL); */
	viper_event_set(window,"window-close",vwm_main_menu_ON_CLOSE,
		(gpointer)menu);
	viper_window_set_key_func(window,vwm_main_menu_ON_KEYSTROKE);
	viper_window_set_userptr(window,(gpointer)menu);

	viper_thread_leave();
	return window;
}
Esempio n. 17
0
WINDOW* vwm_main_menu(void)
{
    extern WINDOW   *SCREEN_WINDOW;
	MENU            *menu = NULL;
	WINDOW 		    *window;
	int			    width = 0,height = 0;
    int             screen_height;

	vwm_module_t	*vwm_module;
    char            buf[NAME_MAX];

    gchar			**item_list;
    int             idx = 0;
    int             i;

    // allocate storage for a total of MAX_MENU_ITEMS
    item_list = (gchar**)g_malloc0(sizeof(gchar*) * (MAX_MENU_ITEMS + 1));

    item_list[idx] = g_strdup_printf(" ");
    idx++;

    // iterate through the categories defined in modules.def
    for(i = 0;i < VWM_MOD_TYPE_MAX;i++)
    {
        // skip screensaver type modules.  they are a special class.
        if(i == VWM_MOD_TYPE_SCREENSAVER) continue;

        // print the menu category (type) to the window
        item_list[idx] = g_strdup_printf("%s",modtype_desc[i]);
        idx++;

        vwm_module = NULL;

        do
        {
            if(idx == MAX_MENU_ITEMS) break;

            vwm_module = vwm_module_find_by_type(vwm_module,i);
            if(vwm_module == NULL) break;

            vwm_module_get_title(vwm_module,buf,sizeof(buf) - 1);
            item_list[idx] = g_strdup_printf("..%s",buf);
            idx++;
        }
        while(vwm_module != NULL);

        // add a space before the next menu category
        if(idx < MAX_MENU_ITEMS)
        {
            item_list[idx] = g_strdup_printf(" ");
            idx++;
        }
    }

    menu = viper_menu_create(item_list);
    while(idx != -1)
    {
        g_free(item_list[idx]);
        idx--;
    }
    g_free(item_list);

	// hide character mark on left hand side
	set_menu_mark(menu," ");

    window_get_size_scaled(SCREEN_WINDOW,NULL,&screen_height,0,0.80);

	scale_menu(menu,&height,&width);
	width++;
	if(width < 16) width = 16;

 	// override the default of 1 column X 16 entries per row
    if(height>(screen_height-4)) height=screen_height-4;
	set_menu_format(menu,height,1);

	viper_thread_enter();
	window = viper_window_create(" Menu ",1,2,width,height,TRUE);
    /*
        todo:   it would be nice if the user could resize the menu
                (especially in the horizonal direction) and add more
                columns to the display.  right now, it's not a priority
                (but it would be easy to implement).  just need a few
                lines of code for the event window-resized.  for now,
                just don't allow it
    */
	set_menu_win(menu,window);
	set_menu_fore(menu,VIPER_COLORS(COLOR_WHITE,COLOR_BLUE) | A_BOLD);
	set_menu_back(menu,VIPER_COLORS(COLOR_BLACK,COLOR_WHITE));
	menu_opts_off(menu,O_NONCYCLIC);
	post_menu(menu);
    vwm_menu_marshall(menu,REQ_DOWN_ITEM);

	/* viper_event_set(window,"window-activate",vwm_main_menu_ON_ACTIVATE,NULL); */
	viper_event_set(window,"window-close",vwm_main_menu_ON_CLOSE,
		(gpointer)menu);
	viper_window_set_key_func(window,vwm_main_menu_ON_KEYSTROKE);
	viper_window_set_userptr(window,(gpointer)menu);

	viper_thread_leave();
	return window;
}
Esempio n. 18
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();
}